📄 wmain.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <io.h>
#include "win1632.h"
#include "wresall.h"
#include "wglbl.h"
#include "wrglbl.h"
#include "waccel.h"
#include "winst.h"
#include "wmem.h"
#include "wmemf.h"
#include "wrename.h"
#include "wnewitem.h"
#include "wdel.h"
#include "wkey.h"
#include "wmsg.h"
#include "wedit.h"
#include "wstat.h"
#include "wribbon.h"
#include "whints.h"
#include "wopts.h"
#include "whndl.h"
#include "sys_rc.h"
#include "wctl3d.h"
#include "wsvobj.h"
#include "wsetedit.h"
#include "wmain.h"
#include "wmsgfile.gh"
#include "wacc2rc.h"
#include "weditsym.h"
#include "wstrdup.h"
#include "wrdll.h"
#include "wrutil.h"
#include "wwinhelp.h"
#include "jdlg.h"
#include "watini.h"
#include "inipath.h"
/****************************************************************************/
/* macro definitions */
/****************************************************************************/
#define WTIMER 666
#define ABOUT_TIMER WTIMER
#define CLOSE_TIMER WTIMER
#define WACC_MINTRACKX 495
#define WACC_MINTRACKY 485
/****************************************************************************/
/* external function prototypes */
/****************************************************************************/
extern LRESULT WINEXPORT WMainWndProc ( HWND, UINT, WPARAM, LPARAM );
extern Bool WINEXPORT WAbout ( HWND, WORD, WPARAM, LPARAM );
/****************************************************************************/
/* static function prototypes */
/****************************************************************************/
static Bool WInit ( HINSTANCE );
static void WFini ( void );
static WAccelInfo *WAccelGetEInfo ( WAccelHandle, Bool );
static Bool WRegisterMainClass ( HINSTANCE );
static Bool WCreateEditWindow ( HINSTANCE, WAccelEditInfo * );
static void WUpdateScreenPosOpt ( HWND );
static void WDisplayAboutBox ( HINSTANCE, HWND, UINT );
static Bool WCleanup ( WAccelEditInfo * );
static Bool WQuerySave ( WAccelEditInfo *, Bool );
static Bool WQuerySaveRes ( WAccelEditInfo *, Bool );
static Bool WQuerySaveSym ( WAccelEditInfo *, Bool );
static Bool WHandleWM_CLOSE ( WAccelEditInfo *, Bool );
static void WHandleClear ( WAccelEditInfo * );
/****************************************************************************/
/* static variables */
/****************************************************************************/
static WAccelEditInfo *WCurrEditInfo = NULL;
static char WMainClass[] = "WAccMainClass";
static char WMainMenuName[] = "WMainMenu";
static char WMainSOMenuName[] = "WSOMenu";
static char WProfileName[_MAX_PATH] = WATCOM_INI;
static char WSectionName[] = "waccel";
static char WItemClipbdFmt[] = "WACCEL_ITEM_CLIPFMT";
static int ref_count = 0;
static HACCEL AccelTable = NULL;
UINT WClipbdFormat = 0;
UINT WItemClipbdFormat = 0;
extern int appWidth;
extern int appHeight;
/* set the WRES library to use compatible functions */
WResSetRtns(open,close,read,write,lseek,tell,WMemAlloc,WMemFree);
#ifdef __NT__
int WINAPI LibMain ( HANDLE inst, DWORD dwReason, LPVOID lpReserved )
{
int ret;
_wtouch(lpReserved);
ret = TRUE;
switch ( dwReason ) {
case DLL_PROCESS_ATTACH:
ref_count = 0;
WSetEditInstance( inst );
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
/* do nothing here */
break;
}
return ( ret );
}
#else
int WINAPI LibMain ( HINSTANCE inst, WORD dataseg,
WORD heapsize, LPSTR cmdline )
{
_wtouch(dataseg);
_wtouch(heapsize);
_wtouch(cmdline);
__win_alloc_flags = GMEM_MOVEABLE | GMEM_SHARE;
__win_realloc_flags = GMEM_MOVEABLE | GMEM_SHARE;
ref_count = 0;
WSetEditInstance( inst );
return ( TRUE );
}
int WINAPI WEP ( int parm )
{
_wtouch(parm);
return( TRUE );
}
#endif
void WINEXPORT WAccelInit( void )
{
HINSTANCE inst;
inst = WGetEditInstance();
if( AccelTable == (HACCEL)NULL ) {
AccelTable = LoadAccelerators( inst, "WAccelAccelTable");
}
if( !ref_count ) {
WRInit();
WInitDisplayError( inst );
WInit( inst );
}
ref_count++;
}
void WINEXPORT WAccelFini( void )
{
ref_count--;
if( !ref_count ) {
WFini();
WRFini();
}
}
WAccelHandle WINEXPORT WAccelStartEdit( WAccelInfo *info )
{
int ok;
WAccelEditInfo *einfo;
einfo = NULL;
ok = ( info && info->parent && info->inst );
if( ok ) {
if( appWidth == -1 ) {
WInitEditDlg( WGetEditInstance(), info->parent );
}
ok = ( ( einfo = WAllocAccelEInfo() ) != NULL );
}
if ( ok ) {
einfo->info = info;
einfo->tbl = WMakeAccelTableFromInfo( info );
ok = ( einfo->tbl != NULL );
}
if( ok ) {
if( einfo->info->file_name ) {
einfo->file_name = WStrDup( einfo->info->file_name );
ok = ( einfo->file_name != NULL );
if( ok ) {
einfo->file_type = WRIdentifyFile( einfo->file_name );
ok = ( einfo->file_type != WR_DONT_KNOW );
}
}
}
if( ok ) {
ok = WResolveAllEntrySymbols( einfo );
}
if( ok ) {
ok = WCreateEditWindow( WGetEditInstance(), einfo );
}
if( ok ) {
einfo->hndl = WRegisterEditSession( einfo );
ok = ( einfo->hndl != 0 );
}
if( !ok ) {
if( einfo ) {
WFreeAccelEInfo( einfo );
}
return( 0 );
}
return( einfo->hndl );
}
void WINEXPORT WAccelShowWindow( WAccelHandle hndl, int show )
{
WAccelEditInfo *einfo;
einfo = (WAccelEditInfo *) WGetEditSessionInfo ( hndl );
if( einfo && einfo->win != (HWND)NULL ) {
if( show ) {
ShowWindow( einfo->win, SW_SHOWNA );
} else {
ShowWindow( einfo->win, SW_HIDE );
}
}
}
void WINEXPORT WAccelBringToFront( WAccelHandle hndl )
{
WAccelEditInfo *einfo;
einfo = (WAccelEditInfo *) WGetEditSessionInfo ( hndl );
if( einfo && einfo->win != (HWND)NULL ) {
ShowWindow( einfo->win, SW_RESTORE );
BringWindowToTop( einfo->win );
}
}
int WINEXPORT WAccelIsDlgMsg ( MSG *msg )
{
return( WIsAccelDialogMessage( msg, AccelTable ) );
}
WAccelInfo * WINEXPORT WAccelEndEdit ( WAccelHandle hndl )
{
return ( WAccelGetEInfo ( hndl, FALSE ) );
}
WAccelInfo * WINEXPORT WAccelGetEditInfo ( WAccelHandle hndl )
{
return ( WAccelGetEInfo ( hndl, TRUE ) );
}
int WINEXPORT WAccelCloseSession( WAccelHandle hndl, int force_exit )
{
WAccelEditInfo *einfo;
einfo = (WAccelEditInfo *) WGetEditSessionInfo ( hndl );
if( ( einfo != NULL ) && ( einfo->info != NULL ) ) {
if( SendMessage( einfo->win, WM_CLOSE, (WPARAM)force_exit, 0 ) != 0 ) {
return( FALSE );
}
}
return( TRUE );
}
WAccelInfo *WAccelGetEInfo ( WAccelHandle hndl, Bool keep )
{
WAccelEditInfo *einfo;
WAccelInfo *info;
int ok;
info = NULL;
einfo = (WAccelEditInfo *) WGetEditSessionInfo ( hndl );
ok = ( einfo != NULL );
if ( ok ) {
info = einfo->info;
ok = ( info != NULL );
}
if ( ok ) {
if ( einfo->info->modified ) {
if ( info->data ) {
WMemFree ( info->data );
}
info->data = NULL;
info->data_size = 0;
WMakeDataFromAccelTable ( einfo->tbl, &info->data,
&info->data_size );
}
if ( !keep ) {
WUnRegisterEditSession ( hndl );
WFreeAccelEInfo ( einfo );
}
}
return ( info );
}
Bool WInit( HINSTANCE inst )
{
Bool ok;
ok = ( inst != (HINSTANCE) NULL );
if( ok ) {
WCtl3DInit ( inst );
ok = JDialogInit();
}
if( ok ) {
ok = WRegisterMainClass ( inst );
}
if( ok ) {
ok = WInitStatusLines ( inst );
}
if( ok ) {
WClipbdFormat = RegisterClipboardFormat( WR_CLIPBD_ACCEL );
ok = ( WClipbdFormat != 0 );
}
if( ok ) {
WItemClipbdFormat = RegisterClipboardFormat( WItemClipbdFmt );
ok = ( WItemClipbdFormat != 0 );
}
if( ok ) {
GetConfigFilePath( WProfileName, sizeof(WProfileName) );
strcat( WProfileName, "\\" WATCOM_INI );
WInitOpts( WProfileName, WSectionName );
WInitEditWindows( inst );
ok = WInitRibbons( inst );
}
return( ok );
}
void WFini ( void )
{
HINSTANCE inst;
inst = WGetEditInstance();
WFiniStatusLines ();
WOptsShutdown ();
WShutdownRibbons ();
WShutdownToolBars ();
WFiniEditWindows ();
WCtl3DFini ( inst );
UnregisterClass ( WMainClass, inst );
JDialogFini();
}
Bool WRegisterMainClass ( HINSTANCE inst )
{
WNDCLASS wc;
/* fill in the WINDOW CLASS structure for the main window */
wc.style = CS_DBLCLKS | CS_GLOBALCLASS;
wc.lpfnWndProc = WMainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(WAccelEditInfo *);
wc.hInstance = inst;
wc.hIcon = LoadIcon ( inst, "WMainIcon" );
wc.hCursor = LoadCursor ( (HINSTANCE) NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = WMainMenuName;
wc.lpszClassName = WMainClass;
return ( RegisterClass ( &wc ) );
}
char *WCreateEditTitle( WAccelEditInfo *einfo )
{
char *title;
char *fname;
char *text;
int offset, len;
title = NULL;
fname = NULL;
if( !einfo ) {
return( NULL );
}
if( !einfo->file_name ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -