示例#1
0
HWND WRECreateMDIClientWindow( HWND win, HINSTANCE app_inst )
{
    CLIENTCREATESTRUCT ccs;
    RECT               rect;
    HWND               client;
    int                ribbon_depth;
    int                stat_depth;

    ribbon_depth = WREGetRibbonHeight();

    stat_depth = WREGetStatusDepth();

    GetClientRect( win, &rect );

    ccs.hWindowMenu = GetSubMenu( GetMenu( win ), 3 );
    ccs.idFirstChild = WRE_MDI_FIRST;

    /* attempt to create the main application edit window */
    client = CreateWindow( "MDIClient", "",
                           WS_CLIPCHILDREN | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL,
                           0, ribbon_depth,
                           rect.right - rect.left,
                           rect.bottom - (rect.top + stat_depth + ribbon_depth),
                           win, (HMENU)NULL, app_inst, &ccs );

    /* if the window could not be created return FALSE */
    if( client == NULL ) {
        WREDisplayErrorMsg( WRE_MOCREATEMDICLIENT );
        return( FALSE );
    }

    return( client );
}
示例#2
0
Bool WREProcessArgs( char **argv, int argc )
{
    int     i;
    Bool    ok;

    ok = TRUE;

    for( i = 1; i < argc; i++ ) {
        if( !stricmp( argv[i], CREATE_NEW_FLAG ) ) {
            WRECreateNewFiles = TRUE;
        } else if( !stricmp( argv[i], NO_IFACE_FLAG ) ) {
            WRENoInterface = TRUE;
        } else {
            if( WRFileExists( argv[i] ) ) {
                ok = WREOpenResource( argv[i] ) && ok;
            } else if( WRECreateNewFiles ) {
                ok = (WRECreateNewResource( argv[i] ) != NULL && ok);
            } else {
                ok = FALSE;
            }
        }
    }

    if( !ok ) {
        WREDisplayErrorMsg( WRE_INPUTFILESNOTLOADED );
    }

    return( ok );
}
示例#3
0
bool WREGetClipData( WREClipFormat *fmt, void **data, uint_32 *dsize )
{
    bool        ok;
    HANDLE      hclipdata;
    void        *mem;

    hclipdata = (HANDLE)NULL;
    mem = NULL;
    ok = (fmt != NULL && fmt->fmt != 0 && data != NULL && dsize != 0);

    if( ok ) {
        hclipdata = GetClipboardData( fmt->fmt );
        ok = (hclipdata != NULL);
    }

    if( ok ) {
        mem = GlobalLock( hclipdata );
        ok = (mem != NULL);
    }

    if( ok ) {
        *dsize = (uint_32)GlobalSize( hclipdata );
        ok = (*dsize != 0);
    }

    if( ok ) {
        if( *dsize >= INT_MAX ) {
            WREDisplayErrorMsg( WRE_RESTOOLARGETOPASTE );
            ok = false;
        }
    }

    if( ok ) {
        *data = WRMemAlloc( *dsize );
        ok = (*data != NULL);
    }

    if( ok ) {
        memcpy( *data, mem, *dsize );
    }

    if( !ok ) {
        if( *data ) {
            WRMemFree( *data );
            *data = NULL;
            *dsize = 0;
        }
    }

    if( mem != NULL ) {
        GlobalUnlock( hclipdata );
    }

    return( ok );
}
示例#4
0
Bool WREOpenResource( char *fn )
{
    char                *name;
    WREResInfo          *res_info;
    WREGetFileStruct    gf;
    Bool                ok, got_name;

    res_info = NULL;
    name = NULL;
    got_name = FALSE;

    if( fn != NULL ) {
        if( WRFileExists( fn ) ) {
            ok = ((name = WREStrDup( fn )) != NULL);
        } else {
            ok = FALSE;
        }
    } else {
        gf.file_name = NULL;
        gf.title = WREResOpenTitle;
        gf.filter = WREResFilter;
        gf.save_ext = TRUE;
        ok = ((name = WREGetOpenFileName( &gf )) != NULL);
    }

    if( ok ) {
        got_name = TRUE;
        ok = ((res_info = WRELoadResource( name )) != NULL);
    }

    if( ok ) {
        WREFindAndLoadSymbols( res_info );
        ok = WRECreateResourceWindow( res_info );
    }

    if( ok ) {
        ListAddElt( &WREResList, (void *)res_info );
    } else {
        if( res_info != NULL ) {
            WREFreeResInfo( res_info );
            res_info = NULL;
        }
        if( got_name ) {
            WREDisplayErrorMsg( WRE_RESOURCESNOTLOADED );
        }
    }

    if( name != NULL ) {
        WREMemFree( name );
    }

    return( ok );
}
示例#5
0
bool SaveObjectInto( WRECurrentResInfo *curr, void *rdata )
{
    bool                ok;
    char                *fname;
    WREGetFileStruct    gf;
    WRSaveIntoData      idata;
    bool                dup;
    uint_32             size;

    fname = NULL;
    dup = false;

    ok = (curr != NULL && rdata != NULL);

    if( ok ) {
        gf.file_name = NULL;
        gf.title = WREResSaveIntoTitle;
        gf.filter = WREResFilter;
        gf.save_ext = TRUE;
        fname = WREGetOpenFileName( &gf );
        ok = (fname != NULL && *fname != '\0');
    }

    if( ok ) {
        size = curr->lang->Info.Length;
        idata.next = NULL;
        idata.info = curr->info->info;
        idata.type = &curr->type->Info.TypeName;
        idata.name = &curr->res->Info.ResName;
        idata.data = rdata;
        idata.lang = curr->lang->Info.lang;
        idata.size = size;
        idata.MemFlags = curr->lang->Info.MemoryFlags;
        ok = WRSaveObjectInto( fname, &idata, &dup ) && !dup;
    }

    if( dup ) {
        WREDisplayErrorMsg( WRE_DUPRESNAME );
    }

    if( fname != NULL ) {
        WRMemFree( fname );
    }

    return( ok );
}
示例#6
0
bool SaveObject( bool save_into )
{
    WRECurrentResInfo   curr;
    void                *rdata;
    bool                ok;

    WRESetWaitCursor( TRUE );

    rdata = NULL;

    ok = WREGetCurrentResource( &curr );

    if( ok ) {
        ok = (curr.lang->Info.Length != 0);
        if( !ok ) {
            WREDisplayErrorMsg( WRE_UPDATEBEFORESAVE1 );
        }
    }

    if( ok ) {
        ok = ((rdata = WREGetCurrentResData( &curr )) != NULL);
    }

    if( ok ) {
        if( save_into ) {
            ok = SaveObjectInto( &curr, rdata );
        } else {
            ok = SaveObjectAs( &curr, rdata );
        }
    }

    if( rdata != NULL ) {
        WRMemFree( rdata );
    }

    WRESetWaitCursor( FALSE );

    return( ok );
}
示例#7
0
static char *WRELoadSymbols( WRHashTable **table, char *file_name, bool prompt )
{
    char                *name;
    int                 c;
    unsigned            flags;
    char                *inc_path;
    WREGetFileStruct    gf;
    unsigned            pp_count;
    unsigned            busy_count;
    char                busy_str[2];
    bool                ret;
    bool                ok;

    name = NULL;

    ok = (table != NULL);

    if( ok ) {
        WRESetStatusText( NULL, "", FALSE );
        WRESetStatusByID( WRE_LOADINGSYMBOLS, -1 );
    }

    if( ok ) {
        if( file_name == NULL || prompt ) {
            gf.file_name = file_name;
            gf.title = WRESymLoadTitle;
            gf.filter = WRESymSaveFilter;
            gf.save_ext = FALSE;
            name = WREGetOpenFileName( &gf );
        } else {
            name = WREStrDup( file_name );
        }
        ok = (name != NULL);
    }

    WRESetWaitCursor( TRUE );

    if( ok ) {
        flags = PPFLAG_IGNORE_INCLUDE | PPFLAG_EMIT_LINE;
        inc_path = NULL;
        ret = setjmp( SymEnv );
        if( ret ) {
            PP_Fini();
            WREDisplayErrorMsg( WRE_SYMOUTOFMEM );
            ok = false;
        }
    }

    if( ok ) {
        ok = !PP_Init( name, flags, inc_path );
        if( !ok ) {
            WREDisplayErrorMsg( WRE_NOLOADHEADERFILE );
        }
    }

    if( ok ) {
        pp_count = 0;
        busy_count = 0;
        busy_str[1] = '\0';
        do {
            pp_count++;
            c = PP_Char();
            if( pp_count == MAX_PP_CHARS ) {
                busy_count++;
                busy_str[0] = WREBusyChars[busy_count % 4];
                WRESetStatusText( NULL, busy_str, TRUE );
                pp_count = 0;
            }
        } while( c != EOF );
        if( *table == NULL ) {
            *table = WRInitHashTable();
        }
        WREAddSymbols( *table );
        WRMakeHashTableClean( *table );
        PP_Fini();
        WRESetStatusText( NULL, " ", TRUE );
    }

    if( !ok ) {
        if( name != NULL ) {
            WRMemFree( name );
            name = NULL;
        }
    }

    WRESetWaitCursor( FALSE );

    WRESetStatusReadyText();

    return( name );
}
示例#8
0
char *WREGetFileName( WREGetFileStruct *gf, DWORD flags, WREGetFileAction action )
{
    OPENFILENAME  wreofn;
    HWND          owner_window;
    Bool          ret;
    DWORD         error;
    int           len;
    char          fn_drive[_MAX_DRIVE];
    char          fn_dir[_MAX_DIR];
    char          fn_name[_MAX_FNAME];
    char          fn_ext[_MAX_EXT + 1];
    HINSTANCE     app_inst;

    if( gf == NULL ) {
        return( NULL );
    }

    owner_window = WREGetMainWindowHandle();
    app_inst = WREGetAppInstance();

    if( app_inst == NULL || owner_window == NULL ) {
        return( NULL );
    }

    if( gf->title != NULL ) {
        len = strlen( gf->title );
        if( len < _MAX_PATH ) {
            memcpy( wrefntitle, gf->title, len + 1 );
        } else {
            memcpy( wrefntitle, gf->title, _MAX_PATH );
            wrefntitle[_MAX_PATH - 1] = 0;
        }
    } else {
        wrefntitle[0] = 0;
    }

    if( gf->file_name != NULL && *gf->file_name != '\0' ) {
        _splitpath( gf->file_name, fn_drive, fn_dir, fn_name, fn_ext );
        if( *fn_drive != '\0' || *fn_dir != '\0' ) {
            _makepath( wre_initial_dir, fn_drive, fn_dir, NULL, NULL );
        }
        _makepath( wre_file_name, NULL, NULL, fn_name, fn_ext );
    } else {
        wre_file_name[0] = 0;
    }

    /* set the initial directory */
    if( *wre_initial_dir == '\0' ) {
        getcwd( wre_initial_dir, _MAX_PATH );
    }

#if !defined ( __NT__ )
    // CTL3D no longer requires this
    flags |= OFN_ENABLEHOOK;
#endif

    /* initialize the OPENFILENAME struct */
    memset( &wreofn, 0, sizeof( OPENFILENAME ) );

    /* fill in non-variant fields of OPENFILENAME struct */
    wreofn.lStructSize = sizeof( OPENFILENAME );
    wreofn.hwndOwner = owner_window;
    wreofn.hInstance = app_inst;
    wreofn.lpstrFilter = gf->filter;
    wreofn.lpstrCustomFilter = NULL;
    wreofn.nMaxCustFilter = 0;
    wreofn.nFilterIndex = WREFindFileFilterIndex( gf->filter );
    wreofn.lpstrFile = wre_file_name;
    wreofn.nMaxFile = _MAX_PATH;
    wreofn.lpstrFileTitle = wrefntitle;
    wreofn.nMaxFileTitle = _MAX_PATH;
    wreofn.lpstrInitialDir = wre_initial_dir;
    wreofn.lpstrTitle = wrefntitle;
    wreofn.Flags = flags;
    wreofn.lpfnHook = (LPVOID)MakeProcInstance( (LPVOID)WREOpenHookProc, app_inst );

#if 0
    wreofn.nFileOffset = 0L;
    wreofn.nFileExtension = 0L;
    wreofn.lpstrDefExt = NULL;
    wreofn.lCustData = NULL;
    wreofn.lpTemplateName = NULL;
#endif

    if( action == OPENFILE ) {
        ret = GetOpenFileName( (LPOPENFILENAME)&wreofn );
    } else if( action == SAVEFILE ) {
        ret = GetSaveFileName( (LPOPENFILENAME)&wreofn );
    } else {
        return( NULL );
    }

#ifndef __NT__
    if( wreofn.lpfnHook != NULL ) {
        FreeProcInstance( (FARPROC)wreofn.lpfnHook );
    }
#endif

    if( !ret ) {
        error = CommDlgExtendedError();
        if( error ) {
            WREDisplayErrorMsg( WRE_ERRORSELECTINGFILE );
        }
        return( NULL );
    } else {
        memcpy( wre_initial_dir, wre_file_name, wreofn.nFileOffset );
        if( wre_initial_dir[wreofn.nFileOffset - 1] == '\\' &&
            wre_initial_dir[wreofn.nFileOffset - 2] != ':' ) {
            wre_initial_dir[wreofn.nFileOffset - 1] = '\0';
        } else {
            wre_initial_dir[wreofn.nFileOffset] = '\0';
        }
        if( gf->save_ext ) {
            _splitpath( wre_file_name, NULL, NULL, NULL, fn_ext + 1 );
            if( fn_ext[1] != '\0' ) {
                fn_ext[0] = '*';
                WRESetFileFilter( fn_ext );
            } else {
                char *out_ext;
                out_ext = WREFindFileFilterFromIndex( gf->filter, wreofn.nFilterIndex );
                if( out_ext[2] != '*' ) {
                    strcat( wre_file_name, &out_ext[1] );
                }
            }
        }
    }

    UpdateWindow( WREGetMainWindowHandle() );

    return( WREStrDup( wre_file_name ) );
}
示例#9
0
/* Function to initialize all instances of WRE */
Bool WREInitInst( HINSTANCE app_inst )
{
    RECT        r, screen, t;
    char        *title;
    DWORD       style;

    if( !WRERegisterClipFormats( app_inst ) ) {
        WREDisplayErrorMsg( WRE_NOREGISTERCLIPFORMATS );
        return( FALSE );
    }

    if( !JDialogInit() ) {
        return( FALSE );
    }

    WRECtl3DInit( app_inst );
    WREInitOpts();
    WREInitRibbon( app_inst );
    WREInitTypeNames();
    WREInitTotalText();

    if( !WREInitResources( app_inst ) ) {
        return( FALSE );
    }

    /* load the accelerator table */
    WREAccel = LoadAccelerators( app_inst, "WREAccelTable" );

    /* if the window could not be created return FALSE */
    if( WREAccel == NULL ) {
        WREDisplayErrorMsg( WRE_NOLOADACCELTABLE );
        return( FALSE );
    }

    WREGetScreenPosOption( &r );
    GetWindowRect( GetDesktopWindow(), &screen );
    IntersectRect( &t, &screen, &r );

    title = WREAllocRCString( WRE_APPNAME );

    /* attempt to create the main application window */
    style = WS_OVERLAPPEDWINDOW;
    if( IsRectEmpty( &r ) ) {
        WREMainWin = CreateWindow( WREMainClass, title, style,
                                   CW_USEDEFAULT, CW_USEDEFAULT,
                                   CW_USEDEFAULT, CW_USEDEFAULT,
                                   (HWND)NULL, (HMENU)NULL, app_inst, NULL );
    } else {
        WREMainWin = CreateWindow( WREMainClass, title, style,
                                   r.left, r.top, r.right - r.left, r.bottom - r.top,
                                   (HWND)NULL, (HMENU)NULL, app_inst, NULL );
    }

    if( title != NULL ) {
        WREFreeRCString( title );
    }

    /* if the window could not be created return FALSE */
    if( WREMainWin == NULL ) {
        WREDisplayErrorMsg( WRE_NOCREATEAPPWINDOW );
        return( FALSE );
    }

    WREMDIWin = WRECreateMDIClientWindow( WREMainWin, app_inst );

    /* attempt to create the main application ribbon */
    if( !WRECreateRibbon( WREMainWin ) ) {
        WREDisplayErrorMsg( WRE_NOCREATETOOLRIBBON );
        return( FALSE );
    }

    if( !WRECreateStatusLine( WREMainWin, app_inst ) ) {
        WREDisplayErrorMsg( WRE_NOCREATESTATUSLINE );
        return( FALSE );
    }

    WREMenu = GetMenu( WREMainWin );
    if( WREMenu != (HMENU)NULL ) {
        EnableMenuItem( WREMenu, IDM_CUT, MF_GRAYED );
        EnableMenuItem( WREMenu, IDM_COPY, MF_GRAYED );
        EnableMenuItem( WREMenu, IDM_OPTIONS, MF_GRAYED );
    }

    WREEnableMenus( FALSE );

    if( !WREInitHints() ) {
        WREDisplayErrorMsg( WRE_NOINITHINTS );
        return( FALSE );
    }

    /* if the window was created Show and Update it */
    if( !WRENoInterface ) {
        if( WREGetOption( WREOptScreenMax ) ) {
            ShowWindow( WREMainWin, SW_SHOWMAXIMIZED );
        } else {
            ShowWindow( WREMainWin, SW_SHOWNORMAL );
        }
        UpdateWindow( WREMainWin );

        WREDisplaySplashScreen( WREInst, WREMainWin, 1250 );
    }

    return( TRUE );
}
示例#10
0
int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
                    LPSTR lpszCmdLine, int nCmdShow )
{
    extern char **_argv;
    extern int  _argc;
    MSG         msg;
    Bool        ret;

    /* touch unused vars to get rid of warning */
    _wre_touch( lpszCmdLine );
    _wre_touch( nCmdShow );
#ifdef __NT__
    _wre_touch( hinstPrevious );
#endif

    WRInit();
    WAccelInit();
    WMenuInit();
    WStringInit();
    WREInitDisplayError( hinstCurrent );

    /* store the handle to this instance of WRE in a static variable */
    WREInst = hinstCurrent;

    peekArgs( _argv, _argc );

    /* is this the first instance of the application? */
#ifndef __NT__
    if( hinstPrevious == NULL ) {
#endif
        /* if so call the routine to initialize the application */
        if( !WREInit( hinstCurrent ) ) {
            return( FALSE );
        }
#ifndef __NT__
    }
#endif

    if( !WREInitInst( hinstCurrent ) ) {
        WREDisplayErrorMsg( WRE_INITFAILED );
        return( FALSE );
    }

    if( !WREDDEStart( hinstCurrent ) ) {
        WREDisplayErrorMsg( WRE_DDEINITFAILED );
        return( FALSE );
    }

    ret = WREProcessArgs( _argv, _argc );

    startEditors();

    // create a new empty res if none have been created at this point
    if( ret && WREGetNumRes() == 0 ) {
        WRECreateNewResource( NULL );
    }

    /* create the message loop */
    while( GetMessage( &msg, (HWND)NULL, 0, 0 ) ) {
        if( !WREIsEditWindowDialogMessage( &msg ) &&
                !WREWasAcceleratorHandled( &msg ) &&
                !WREIsResInfoWinMsg( &msg ) &&
                !WRIsWRDialogMsg( &msg ) ) {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
    }

    WREDDEEnd();
    WStringFini();
    WMenuFini();
    WAccelFini();
    WRFini();

    return( msg.wParam );
}
示例#11
0
static void startEditors( void )
{
    WRFileType  ftype;
    WREResInfo  *res_info;
    Bool        editor_started;
    Bool        ret;
    int         num_types;
    uint_16     type;

    if( WREGetNumRes() != 1 ) {
        if( WRENoInterface ) {
            WREDisplayErrorMsg( WRE_INVALIDINPUTFILE );
            PostMessage( WREMainWin, WM_CLOSE, 0, 0 );
        }
        return;
    }

    editor_started = FALSE;
    num_types = 0;
    res_info = WREGetCurrentRes();
    ftype = res_info->info->file_type;
    if( res_info->info->file_name == NULL ) {
        ftype = WRIdentifyFile( res_info->info->save_name );
    } else {
        num_types = res_info->info->dir->NumTypes;
    }

    if( ftype != WR_WIN_RC_STR && ftype != WR_WIN_RC_MENU && ftype != WR_WIN_RC_ACCEL ) {
        if( WRENoInterface ) {
            if( !editor_started ) {
                WREDisplayErrorMsg( WRE_INVALIDINPUTFILE );
                PostMessage( WREMainWin, WM_CLOSE, 0, 0 );
            }
        }
        return;
    }

    if( num_types == 1 || num_types == 2 ) {
        ret = FALSE;
        type = 0;
        if( ftype == WR_WIN_RC_STR ) {
            type = (uint_16)RT_STRING;
        } else if( ftype == WR_WIN_RC_MENU ) {
            type = (uint_16)RT_MENU;
        } else if( ftype == WR_WIN_RC_ACCEL ) {
            type = (uint_16)RT_ACCELERATOR;
        }
        if( type != 0 && WREFindTypeNode( res_info->info->dir, type, NULL ) ) {
            ret = WRESetResNamesFromType( res_info, type, FALSE, NULL, 0 );
            if( ret ) {
                editor_started = WREHandleResEdit();
            }
        }
    } else if( num_types == 0 ) {
        if( ftype == WR_WIN_RC_STR ) {
            editor_started = WRENewStringResource();
        } else if( ftype == WR_WIN_RC_MENU ) {
            editor_started = WRENewMenuResource();
        } else if( ftype == WR_WIN_RC_ACCEL ) {
            editor_started = WRENewAccelResource();
        }
    }

    if( WRENoInterface ) {
        if( !editor_started ) {
            WREDisplayErrorMsg( WRE_INVALIDINPUTFILE );
            PostMessage( WREMainWin, WM_CLOSE, 0, 0 );
        }
    }
}
示例#12
0
Bool WRESaveResource( WREResInfo *res_info, Bool get_name )
{
    char                *fn;
    WREGetFileStruct    gf;
    int                 fn_offset;
    Bool                got_name;
    Bool                ok;

    fn_offset = 0;
    got_name = FALSE;

    ok = (res_info != NULL && res_info->info != NULL);

    if( ok ) {
        ok = (WRCountZeroLengthResources( res_info->info->dir ) == 0);
        if( !ok ) {
            WREDisplayErrorMsg( WRE_UPDATEBEFORESAVE );
        }
    }

    if( ok ) {
        if( res_info->info->save_name != NULL ) {
            fn = res_info->info->save_name;
        } else {
            res_info->info->save_type = res_info->info->file_type;
            fn = WREStrDup( res_info->info->file_name );
            got_name = TRUE;
        }

        if( get_name || fn == NULL || *fn == '\0' ) {
            gf.file_name = fn;
            gf.title = WREResSaveTitle;
            gf.filter = WREResFilter;
            gf.save_ext = TRUE;
            fn = WREGetSaveFileName( &gf );
            got_name = TRUE;
            res_info->info->save_type = WR_DONT_KNOW;
        }

        ok = (fn != NULL && *fn != '\0');
    }

    if( ok ) {
        if( got_name && res_info->info->save_name != NULL ) {
            WREMemFree( res_info->info->save_name );
        }
        res_info->info->save_name = fn;
        if( res_info->info->save_type == WR_DONT_KNOW ) {
            res_info->info->save_type = WRESelectFileType( fn, res_info->is32bit );
        }
        ok = (res_info->info->save_type != WR_DONT_KNOW);
    }

    if( ok ) {
        if( WRIsHashTableDirty( res_info->symbol_table ) ) {
            if( res_info->symbol_file == NULL ) {
                res_info->symbol_file = WRECreateSymName( fn );
            }
        }
    }

    if( ok ) {
        WRECreateDLGInclude( &res_info->info->dir, res_info->symbol_file );
        ok = WRESaveResourceToFile( res_info );
        if( !ok ) {
            WREDisplayErrorMsg( WRE_SAVEFAILED );
        }
    }

    if( ok ) {
        if( get_name || WRIsHashTableDirty( res_info->symbol_table ) ) {
            ok = WRESaveSymbols( res_info->symbol_table, &res_info->symbol_file, get_name );
        }
    }

    if( ok ) {
        //fn_offset = WRFindFnOffset( fn );
        SendMessage( res_info->res_win, WM_SETTEXT, 0, (LPARAM)(LPSTR)&fn[fn_offset] );
    }

    return( ok );
}
示例#13
0
bool WREAddAccelToDir( WRECurrentResInfo *curr )
{
    WResLangType    lang;
    bool            dup;
    int             num_retries;
    WResID          *rname, *tname;
    bool            ok, tname_alloc;

    ok = true;
    tname_alloc = false;

    WREGetCurrentResource( curr );

    if( curr->info == NULL ) {
        curr->info = WRECreateNewResource( NULL );
        ok = (curr->info != NULL);
    }

    if( ok ) {
        if( curr->info->current_type == RESOURCE2INT( RT_ACCELERATOR ) ) {
            tname = &curr->type->Info.TypeName;
        } else {
            tname = WResIDFromNum( RESOURCE2INT( RT_ACCELERATOR ) );
            tname_alloc = true;
        }
        lang.lang = DEF_LANG;
        lang.sublang = DEF_SUBLANG;
    }

    if( ok ) {
        dup = true;
        num_retries = 0;
        rname = NULL;
        while( ok && dup && num_retries <= MAX_RETRIES ) {
            rname = WRECreateAccTitle();
            ok = (rname != NULL);
            if( ok ) {
                ok = WRENewResource( curr, tname, rname, DEF_MEMFLAGS, 0, 0,
                                     &lang, &dup, RESOURCE2INT( RT_ACCELERATOR ),
                                     tname_alloc );
                if( !ok && dup ) {
                    ok = true;
                }
                num_retries++;
            }
            if( rname != NULL ) {
                WRMemFree( rname );
            }
        }
        if( dup ) {
            WREDisplayErrorMsg( WRE_CANTFINDUNUSEDNAME );
        }
    }

    if( ok ) {
        curr->info->modified = true;
    }

    if( tname_alloc ) {
        WRMemFree( tname );
    }

    return( ok );
}
示例#14
0
bool WRECreateStatusLine( HWND main, HINSTANCE inst )
{
    RECT                rect;
    LOGFONT             lf;
    TEXTMETRIC          tm;
    HFONT               old_font;
    HDC                 dc;
    status_block_desc   sbd;
    char                *font_facename;
    char                *cp;
    int                 font_pointsize;
    bool                use_default;

    memset( &lf, 0, sizeof( LOGFONT ) );
    dc = GetDC( main );
    lf.lfWeight = FW_BOLD;
    use_default = true;

    font_facename = AllocRCString( WRE_STATUSFONT );
    if( font_facename != NULL ) {
        cp = (char *)_mbschr( (unsigned char const *)font_facename, '.' );
        if( cp != NULL ) {
            *cp = '\0';
            strcpy( lf.lfFaceName, font_facename );
            cp++;
            font_pointsize = atoi( cp );
            use_default = false;
        }
        FreeRCString( font_facename );
    }

    if( use_default ) {
        strcpy( lf.lfFaceName, STATUS_FONTFACENAME );
        font_pointsize = STATUS_FONTPOINTSIZE;
    }

    lf.lfHeight = -MulDiv( font_pointsize, GetDeviceCaps( dc, LOGPIXELSY ), 72 );
    WREStatusFont = CreateFontIndirect( &lf );
    old_font = SelectObject( dc, WREStatusFont );
    GetTextMetrics( dc, &tm );
    SelectObject( dc, old_font );
    ReleaseDC( main, dc );

    GetClientRect( main, &rect );

    WREStatusDepth = tm.tmHeight + STATUS_LINE_PAD + VERT_BORDER * 2;
    rect.top = rect.bottom - WREStatusDepth;

    StatusWndInit( inst, WREStatusHookProc, 0, (HCURSOR)NULL );
    WREStatusBar = StatusWndStart();

    sbd.separator_width = STATUS_LINE_PAD;
    sbd.width = STATUS1_WIDTH;
    sbd.width_is_percent = FALSE;
    sbd.width_is_pixels = TRUE;

    StatusWndSetSeparators( WREStatusBar, 1, &sbd );

    WREStatusWindow = StatusWndCreate( WREStatusBar, main, &rect, inst, NULL );

    if( WREStatusWindow == NULL ) {
        WREDisplayErrorMsg( WRE_NOCREATESTATUS );
        return( false );
    }

    /* set the text in the status window */
    WRESetStatusReadyText();

    GetWindowRect( WREStatusWindow, &rect );
    WREStatusDepth = rect.bottom - rect.top;

    return( true );
}