⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmain.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************
*
*                            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 "wmenu.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 "wprev.h"
#include "wmen2rc.h"
#include "wsetedit.h"
#include "wmain.h"
#include "wmsgfile.gh"
#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 WMENU_MINTRACKX 580
#define WMENU_MINTRACKY 600

/****************************************************************************/
/* 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 WMenuInfo  *WMenuGetEInfo       ( WMenuHandle, Bool );
static Bool        WRegisterMainClass  ( HINSTANCE );
static Bool        WCreateEditWindow   ( HINSTANCE, WMenuEditInfo * );
static void        WUpdateScreenPosOpt ( HWND );
static void        WDisplayAboutBox    ( HINSTANCE, HWND, UINT );
static Bool        WCleanup            ( WMenuEditInfo * );
static Bool        WQuerySave          ( WMenuEditInfo *, Bool );
static Bool        WQuerySaveRes       ( WMenuEditInfo *, Bool );
static Bool        WQuerySaveSym       ( WMenuEditInfo *, Bool );
static Bool        WHandleWM_CLOSE     ( WMenuEditInfo *, Bool );
static void        WHandleClear        ( WMenuEditInfo * );
static void        WToggleInsertBitmap ( WMenuEditInfo *einfo );
static void        WToggleInsertSubitems( WMenuEditInfo *einfo );

/****************************************************************************/
/* static variables                                                         */
/****************************************************************************/
static WMenuEditInfo  *WCurrEditInfo     = NULL;
static char            WMainClass[]      = "WMenuMainClass";
static char            WMainMenuName[]   = "WMainMenu";
static char            WMainSOMenuName[] = "WSOMenu";
static char            WProfileName[_MAX_PATH] = WATCOM_INI;
static char            WSectionName[]    = "wmenu";
static char            WItemClipbdFmt[]  = "WMENU_ITEM_CLIPFMT";

static int      ref_count    = 0;
static HACCEL   AccelTable   = NULL;
static HBITMAP  InsertBefore = NULL;
static HBITMAP  InsertAfter  = NULL;
static HBITMAP  InsertSub    = NULL;
static HBITMAP  InsertNoSub  = 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 WMenuInit ( void )
{
    HINSTANCE   inst;

    inst = WGetEditInstance();
    if( AccelTable == (HACCEL)NULL ) {
        AccelTable = LoadAccelerators( inst, "WMenuAccelTable");
    }
    if( InsertBefore == (HBITMAP)NULL ) {
        InsertBefore = LoadBitmap( inst, "InsertBefore");
    }
    if( InsertAfter == (HBITMAP)NULL ) {
        InsertAfter = LoadBitmap( inst, "InsertAfter");
    }
    if( InsertSub == (HBITMAP)NULL ) {
        InsertSub = LoadBitmap( inst, "InsertSub");
    }
    if( InsertNoSub == (HBITMAP)NULL ) {
        InsertNoSub = LoadBitmap( inst, "InsertNoSub");
    }
    if( !ref_count ) {
        WRInit();
        WInitDisplayError( inst );
        WInit( inst );
        WInitDummyMenuEntry();
    }
    ref_count++;
}

void WINEXPORT WMenuFini ( void )
{
    ref_count--;
    if( !ref_count ) {
        WFiniDummyMenuEntry();
        WFini();
        WRFini();
    }
}

WMenuHandle WINEXPORT WRMenuStartEdit ( WMenuInfo *info )
{
    int             ok;
    WMenuEditInfo   *einfo;

    einfo = NULL;

    ok = ( info && info->parent && info->inst );

    if( ok ) {
        if( appWidth == -1 ) {
            WInitEditDlg( WGetEditInstance(), info->parent );
        }
        ok = ( ( einfo = WAllocMenuEInfo() ) != NULL );
    }

    if( ok ) {
        einfo->info = info;
        einfo->menu = WMakeMenuFromInfo( info );
        ok = ( einfo->menu != 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 = WResolveMenuEntries( einfo );
    }

    if( ok ) {
        ok = WCreateEditWindow( WGetEditInstance(), einfo );
    }

    if ( ok ) {
        einfo->hndl = WRegisterEditSession ( einfo );
        ok = ( einfo->hndl != 0 );
    }

    if( !ok ) {
        if ( einfo ) {
            WFreeMenuEInfo ( einfo );
        }
        return ( 0 );
    }

    return ( einfo->hndl );
}

int WINEXPORT WMenuIsModified ( WMenuHandle hndl )
{
    WMenuEditInfo *einfo;

    einfo = (WMenuEditInfo *) WGetEditSessionInfo ( hndl );

    return ( einfo->info->modified );
}

void WINEXPORT WMenuShowWindow( WMenuHandle hndl, int show )
{
    WMenuEditInfo *einfo;

    einfo = (WMenuEditInfo *) WGetEditSessionInfo ( hndl );

    if( einfo && einfo->win != (HWND)NULL ) {
        if( show ) {
            ShowWindow( einfo->win, SW_SHOWNA );
        } else {
            ShowWindow( einfo->win, SW_HIDE );
        }
    }
}

void WINEXPORT WMenuBringToFront( WMenuHandle hndl )
{
    WMenuEditInfo *einfo;

    einfo = (WMenuEditInfo *) WGetEditSessionInfo ( hndl );

    if( einfo && einfo->win != (HWND)NULL ) {
        ShowWindow( einfo->win, SW_RESTORE );
        BringWindowToTop( einfo->win );
    }
}

int WINEXPORT WMenuIsDlgMsg ( MSG *msg )
{
    return( WIsMenuDialogMessage( msg, AccelTable ) );
}

WMenuInfo * WINEXPORT WMenuEndEdit ( WMenuHandle hndl )
{
    return ( WMenuGetEInfo ( hndl, FALSE ) );
}

WMenuInfo * WINEXPORT WMenuGetEditInfo ( WMenuHandle hndl )
{
    return ( WMenuGetEInfo ( hndl, TRUE ) );
}

int WINEXPORT WMenuCloseSession( WMenuHandle hndl, int force_exit )
{
    WMenuEditInfo *einfo;

    einfo = (WMenuEditInfo *) WGetEditSessionInfo ( hndl );

    if( ( einfo != NULL ) && ( einfo->info != NULL ) ) {
        if( SendMessage( einfo->win, WM_CLOSE, (WPARAM)force_exit, 0 ) != 0 ) {
            return( FALSE );
        }
    }

    return( TRUE );
}

WMenuInfo *WMenuGetEInfo ( WMenuHandle hndl, Bool keep )
{
    WMenuEditInfo *einfo;
    WMenuInfo     *info;
    int             ok;

    info = NULL;

    einfo = (WMenuEditInfo *) 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;
            WMakeDataFromMenu ( einfo->menu, &info->data, &info->data_size );
        }
        if ( !keep ) {
            WUnRegisterEditSession ( hndl );
            WFreeMenuEInfo ( 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 = WRegisterPrevClass( inst );
    }

    if( ok ) {
        ok = WInitStatusLines ( inst );
    }

    if( ok ) {
        WClipbdFormat = RegisterClipboardFormat( WR_CLIPBD_MENU );
        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 );
    WUnRegisterPrevClass( inst );

    if( InsertBefore != (HBITMAP)NULL ) {
        DeleteObject( InsertBefore );
        InsertBefore = (HBITMAP)NULL;
    }
    if( InsertAfter != (HBITMAP)NULL ) {
        DeleteObject( InsertAfter );
        InsertAfter = (HBITMAP)NULL;
    }
    if( InsertSub != (HBITMAP)NULL ) {
        DeleteObject( InsertSub );
        InsertSub = (HBITMAP)NULL;
    }
    if( InsertNoSub != (HBITMAP)NULL ) {
        DeleteObject( InsertNoSub );
        InsertNoSub = (HBITMAP)NULL;
    }
    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(WMenuEditInfo *);
    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( WMenuEditInfo *einfo )
{
    char        *title;
    char        *fname;
    char        *text;
    int         offset, len;

    title = NULL;
    fname = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -