📄 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 "wstring.h"
#include "winst.h"
#include "wmem.h"
#include "wmemf.h"
#include "wrename.h"
#include "wnewitem.h"
#include "wdel.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 "wstr2rc.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 WSTR_MINTRACKX 545
#define WSTR_MINTRACKY 500
/****************************************************************************/
/* 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 WStringInfo *WStringGetEInfo ( WStringHandle, Bool );
static Bool WRegisterMainClass ( HINSTANCE );
static Bool WCreateEditWindow ( HINSTANCE, WStringEditInfo * );
static void WHandleMemFlags ( WStringEditInfo *einfo );
static void WUpdateScreenPosOpt ( HWND );
static void WDisplayAboutBox ( HINSTANCE, HWND, UINT );
static Bool WCleanup ( WStringEditInfo * );
static Bool WQuerySave ( WStringEditInfo *, Bool );
static Bool WQuerySaveRes ( WStringEditInfo *, Bool );
static Bool WQuerySaveSym ( WStringEditInfo *, Bool );
static Bool WHandleWM_CLOSE ( WStringEditInfo *, Bool );
static void WHandleClear ( WStringEditInfo * );
/****************************************************************************/
/* static variables */
/****************************************************************************/
static WStringEditInfo *WCurrEditInfo = NULL;
static char WMainClass[] = "WStrMainClass";
static char WMainMenuName[] = "WMainMenu";
static char WMainSOMenuName[] = "WSOMenu";
static char WProfileName[_MAX_PATH] = WATCOM_INI;
static char WSectionName[] = "wstring";
static char WItemClipbdFmt[] = "WSTRING_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 WStringInit ( void )
{
HINSTANCE inst;
inst = WGetEditInstance();
if( AccelTable == (HACCEL)NULL ) {
AccelTable = LoadAccelerators( inst, "WStringAccelTable");
}
if( !ref_count ) {
WRInit();
WInitDisplayError( inst );
WInit( inst );
}
ref_count++;
}
void WINEXPORT WStringFini( void )
{
ref_count--;
if( !ref_count ) {
WFini();
WRFini();
}
}
WStringHandle WINEXPORT WRStringStartEdit( WStringInfo *info )
{
int ok;
WStringEditInfo *einfo;
einfo = NULL;
ok = ( info && info->parent && info->inst );
if ( ok ) {
if( appWidth == -1 ) {
WInitEditDlg( WGetEditInstance(), info->parent );
}
ok = ( ( einfo = WAllocStringEInfo( ) ) != NULL );
}
if ( ok ) {
einfo->info = info;
einfo->tbl = WMakeStringTableFromInfo( 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 = WResolveStringTable( einfo );
}
if ( ok ) {
ok = WCreateEditWindow( WGetEditInstance(), einfo );
}
if ( ok ) {
einfo->hndl = WRegisterEditSession ( einfo );
ok = ( einfo->hndl != 0 );
}
if ( !ok ) {
if ( einfo ) {
WFreeStringEInfo ( einfo );
}
return ( 0 );
}
return ( einfo->hndl );
}
int WINEXPORT WStringIsModified( WStringHandle hndl )
{
WStringEditInfo *einfo;
einfo = (WStringEditInfo *) WGetEditSessionInfo( hndl );
return( einfo->info->modified );
}
void WINEXPORT WStringShowWindow( WStringHandle hndl, int show )
{
WStringEditInfo *einfo;
einfo = (WStringEditInfo *) WGetEditSessionInfo ( hndl );
if( einfo && einfo->win != (HWND)NULL ) {
if( show ) {
ShowWindow( einfo->win, SW_SHOWNA );
} else {
ShowWindow( einfo->win, SW_HIDE );
}
}
}
void WINEXPORT WStringBringToFront( WStringHandle hndl )
{
WStringEditInfo *einfo;
einfo = (WStringEditInfo *) WGetEditSessionInfo ( hndl );
if( einfo && einfo->win != (HWND)NULL ) {
ShowWindow( einfo->win, SW_RESTORE );
BringWindowToTop( einfo->win );
}
}
int WINEXPORT WStringIsDlgMsg( MSG *msg )
{
return( WIsStringDialogMessage( msg, AccelTable ) );
}
WStringInfo * WINEXPORT WStringEndEdit ( WStringHandle hndl )
{
return ( WStringGetEInfo ( hndl, FALSE ) );
}
WStringInfo * WINEXPORT WStringGetEditInfo ( WStringHandle hndl )
{
return ( WStringGetEInfo ( hndl, TRUE ) );
}
int WINEXPORT WStringCloseSession( WStringHandle hndl, int force_exit )
{
WStringEditInfo *einfo;
einfo = (WStringEditInfo *) WGetEditSessionInfo ( hndl );
if( ( einfo != NULL ) && ( einfo->info != NULL ) ) {
if( SendMessage( einfo->win, WM_CLOSE, (WPARAM)force_exit, 0 ) != 0 ) {
return( FALSE );
}
}
return( TRUE );
}
WStringInfo *WStringGetEInfo ( WStringHandle hndl, Bool keep )
{
WStringEditInfo *einfo;
WStringInfo *info;
int ok;
info = NULL;
einfo = (WStringEditInfo *) WGetEditSessionInfo ( hndl );
ok = ( einfo != NULL );
if ( ok ) {
info = einfo->info;
ok = ( info != NULL );
}
if ( ok ) {
if ( einfo->info->modified ) {
WFreeStringNodes( info );
info->tables = WMakeStringNodes( einfo->tbl );
}
if ( !keep ) {
WUnRegisterEditSession ( hndl );
WFreeStringEInfo ( 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_STRING );
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(WStringEditInfo *);
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -