Example #1
0
WINEXPORT LRESULT CALLBACK WMainWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    HMENU               menu;
#if 0
    HWND                win;
#endif
    LRESULT             ret;
    Bool                pass_to_def;
    WMenuEditInfo       *einfo;
    WORD                wp;
    MINMAXINFO          *minmax;
    about_info          ai;

    pass_to_def = TRUE;
    ret = FALSE;
    einfo = (WMenuEditInfo *)GET_WNDLONGPTR( hWnd, 0 );
    WSetCurrentEditInfo( einfo );

    switch( message ) {
    case WM_ACTIVATE:
        if( GET_WM_ACTIVATE_FACTIVE( wParam, lParam ) &&
            !GET_WM_ACTIVATE_FMINIMIZED( wParam, lParam ) &&
            einfo != NULL && einfo->edit_dlg != (HWND)NULL ) {
            SetFocus( einfo->edit_dlg );
            pass_to_def = FALSE;
        }
        break;

    case WM_INITMENU:
        if( wParam == (WPARAM)GetMenu( hWnd ) ) {
            // set the cut and copy menu items
            ret = SendDlgItemMessage( einfo->edit_dlg, IDM_MENUEDLIST, LB_GETCURSEL, 0, 0 );
            if( ret != LB_ERR ) {
                EnableMenuItem( (HMENU)wParam, IDM_MENU_CUT, MF_ENABLED );
                EnableMenuItem( (HMENU)wParam, IDM_MENU_COPY, MF_ENABLED );
            } else {
                EnableMenuItem( (HMENU)wParam, IDM_MENU_CUT, MF_GRAYED );
                EnableMenuItem( (HMENU)wParam, IDM_MENU_COPY, MF_GRAYED );
            }
            // set the paste menu item
            if( OpenClipboard( hWnd ) ) {
                if( //IsClipboardFormatAvailable( WClipbdFormat ) ||
                    IsClipboardFormatAvailable( WItemClipbdFormat ) ) {
                    EnableMenuItem( (HMENU)wParam, IDM_MENU_PASTE, MF_ENABLED );
                } else {
                    EnableMenuItem( (HMENU)wParam, IDM_MENU_PASTE, MF_GRAYED );
                }
                CloseClipboard();
            }
            ret = FALSE;
        }
        break;

    case WM_CREATE:
        einfo = ((CREATESTRUCT *)lParam)->lpCreateParams;
        SET_WNDLONGPTR( hWnd, 0, (LONG_PTR)einfo );
        break;

    case WM_MENUSELECT:
        if( einfo != NULL ) {
            menu = WGetMenuHandle( einfo );
            WHandleMenuSelect( einfo->wsb, menu, wParam, lParam );
        }
        break;

    case WM_GETMINMAXINFO:
        minmax = (MINMAXINFO *)lParam;
        minmax->ptMinTrackSize.x = appWidth;
        minmax->ptMinTrackSize.y = appHeight;
        break;

    case WM_MOVE:
        if( einfo != NULL ) {
            if( IsZoomed( hWnd ) ) {
                WSetOption( WOptScreenMax, TRUE );
            } else if( !IsIconic( hWnd ) ) {
                WUpdateScreenPosOpt( hWnd );
                WSetOption( WOptScreenMax, FALSE );
            }
            WMovePrevWindow( einfo );
        }
        break;

    case WM_SETFOCUS:
        if( einfo != NULL && einfo->preview_window != (HWND)NULL ) {
            SendMessage( einfo->preview_window, WM_NCACTIVATE, (WPARAM)TRUE, (LPARAM)NULL );
        }
        break;

    case WM_SHOWWINDOW:
        if( wParam ) {
            ShowWindow( einfo->preview_window, SW_SHOWNA );
        } else {
            ShowWindow( einfo->preview_window, SW_HIDE );
        }
        break;

    case WM_SIZE:
        if( einfo != NULL ) {
            if( wParam == SIZE_MAXIMIZED ) {
                WSetOption( WOptScreenMax, TRUE );
            } else if ( wParam != SIZE_MINIMIZED ) {
                WUpdateScreenPosOpt( hWnd );
                WSetOption( WOptScreenMax, FALSE );
            }
            if( einfo->preview_window != (HWND)NULL ) {
                if( wParam == SIZE_MINIMIZED ) {
                    ShowWindow( einfo->preview_window, SW_HIDE );
                } else {
                    ShowWindow( einfo->preview_window, SW_SHOWNA );
                }
            }
            if( wParam != SIZE_MINIMIZED ) {
                WResizeWindows( einfo );
            }
        }
        break;

#if 0
    case WM_ACTIVATE:
        if( GET_WM_ACTIVATE_FACTIVE( wParam, lParam ) != WA_INACTIVE ) {
            win = GET_WM_ACTIVATE_HWND( wParam, lParam );
            einfo = (WMenuEditInfo *)GET_WNDLONGPTR( win, 0 );
            WSetCurrentEditInfo( einfo );
        } else {
            WSetCurrentEditInfo( NULL );
        }
        break;
#endif

    case WM_COMMAND:
        wp = LOWORD( wParam );
        switch( wp ) {
        case IDM_MENU_CLEAR:
            WHandleClear( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_UPDATE:
            SendMessage( einfo->info->parent, MENU_PLEASE_SAVEME, 0,
                         (LPARAM)einfo->hndl );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_OPEN:
            pass_to_def = FALSE;
            if( einfo->info->modified ) {
                ret = WQuerySave( einfo, FALSE );
                if( !ret ) {
                    break;
                }
            }
            ret = SendMessage( einfo->info->parent, MENU_PLEASE_OPENME, 0,
                               (LPARAM)einfo->hndl );
            ret = FALSE;
            break;

        case IDM_MENU_SAVE:
            WSaveObject( einfo, FALSE, FALSE );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_SAVEAS:
            WSaveObject( einfo, TRUE, FALSE );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_SAVEINTO:
            WSaveObject( einfo, TRUE, TRUE );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_EXIT:
            /* clean up before we exit */
            PostMessage( einfo->win, WM_CLOSE, 0, 0 );
            break;

        case IDM_MENU_PASTE:
            WPasteMenuItem( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_CUT:
        case IDM_MENU_COPY:
            WClipMenuItem( einfo, wp == IDM_MENU_CUT );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_DELETE:
            WDeleteMenuEntry( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_INSERTSUBITEMS:
            WToggleInsertSubitems( einfo );
            break;

        case IDM_MENU_INSERTBEFORE:
            if( !einfo->insert_before ) {
                WToggleInsertBitmap( einfo );
            }
            break;

        case IDM_MENU_INSERTAFTER:
            if( einfo->insert_before ) {
                WToggleInsertBitmap( einfo );
            }
            break;

        case IDM_MENU_INSERTTOGGLE:
            WToggleInsertBitmap( einfo );
            break;

#if 0
        case IDM_MENU_NEWITEM:
            WInsertNewMenuEntry( einfo, FALSE, FALSE );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_NEWPOPUP:
            WInsertNewMenuEntry( einfo, TRUE, FALSE );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_NEWSEPARATOR:
            WInsertNewMenuEntry( einfo, FALSE, TRUE );
            pass_to_def = FALSE;
            break;
#else
        case IDM_MENU_NEWITEM:
            WInsertNew( einfo );
            pass_to_def = FALSE;
            break;
#endif

        case IDM_MENU_SYMBOLS:
            handleSymbols( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_LOAD_SYMBOLS:
            handleLoadSymbols( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_SHOWRIBBON:
            menu = WGetMenuHandle( einfo );
            WShowRibbon( einfo, menu );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_MEM_FLAGS:
            WSetStatusByID( einfo->wsb, W_CHANGEMENUMEMFLAGS, -1 );
            einfo->info->modified |= WChangeMemFlags( einfo->win, &einfo->info->MemFlags,
                                                      einfo->info->res_name,
                                                      WGetEditInstance(),
                                                      WMenuHelpRoutine );
            WSetStatusReadyText( einfo->wsb );
            pass_to_def = FALSE;
            break;

        case IDM_MENU_RENAME:
            WHandleRename( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_HELP:
            WMenuHelpRoutine();
            pass_to_def = FALSE;
            break;

        case IDM_HELP_SEARCH:
            WMenuHelpSearchRoutine();
            pass_to_def = FALSE;
            break;

        case IDM_HELP_ON_HELP:
            WMenuHelpOnHelpRoutine();
            pass_to_def = FALSE;
            break;

        case IDM_MENU_ABOUT:
            ai.owner = hWnd;
            ai.inst = WGetEditInstance();
            ai.name = AllocRCString( W_ABOUT_NAME );
            ai.version = AllocRCString( W_ABOUT_VERSION );
            ai.first_cr_year = "2002";
            ai.title = AllocRCString( W_ABOUT_TITLE );
            DoAbout( &ai );
            FreeRCString( ai.name );
            FreeRCString( ai.version );
            FreeRCString( ai.title );
            pass_to_def = FALSE;
            break;
        }
        break;

    case WM_DESTROY:
        WWinHelp( hWnd, "resmnu.hlp", HELP_QUIT, 0 );
        WCleanup( einfo );
        break;

    case WM_CLOSE:
        ret = TRUE;
        pass_to_def = WHandleWM_CLOSE( einfo, (Bool)wParam );
        wParam = 0;
        break;
    }

    if( pass_to_def ) {
        ret = DefWindowProc( hWnd, message, wParam, lParam );
    }

    return( ret );
}
Example #2
0
WINEXPORT LRESULT CALLBACK WMainWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    HMENU           menu;
#if 0
    HWND            win;
#endif
    LRESULT         ret;
    bool            pass_to_def;
    WAccelEditInfo  *einfo;
    WORD            wp;
    MINMAXINFO      *minmax;
    about_info      ai;

    pass_to_def = TRUE;
    ret = FALSE;
    einfo = (WAccelEditInfo *)GET_WNDLONGPTR( hWnd, 0 );
    WSetCurrentEditInfo( einfo );

    if( einfo != NULL && einfo->getting_key ) {
        if( WGetKeyPressProc( einfo, message, wParam, lParam ) ) {
            einfo->getting_key = FALSE;
            DestroyWindow( einfo->key_info.text_win );
            ReleaseCapture();
            WHandleChange( einfo );
            pass_to_def = FALSE;
        }
    }

    switch( message ) {
    case WM_ACTIVATE:
        if( GET_WM_ACTIVATE_FACTIVE( wParam, lParam ) &&
            !GET_WM_ACTIVATE_FMINIMIZED( wParam, lParam ) &&
            einfo != NULL && einfo->edit_dlg != (HWND)NULL ) {
            SetFocus( einfo->edit_dlg );
            pass_to_def = FALSE;
        }
        break;

    case WM_INITMENU:
        if( wParam == (WPARAM)GetMenu( hWnd ) ) {
            // set the cut and copy menu items
            if( SendDlgItemMessage( einfo->edit_dlg, IDM_ACCEDLIST, LB_GETCURSEL, 0, 0 ) != LB_ERR ) {
                EnableMenuItem( (HMENU)wParam, IDM_ACC_CUT, MF_ENABLED );
                EnableMenuItem( (HMENU)wParam, IDM_ACC_COPY, MF_ENABLED );
            } else {
                EnableMenuItem( (HMENU)wParam, IDM_ACC_CUT, MF_GRAYED );
                EnableMenuItem( (HMENU)wParam, IDM_ACC_COPY, MF_GRAYED );
            }
            // set the paste menu item
            if( OpenClipboard( hWnd ) ) {
                if( //IsClipboardFormatAvailable( WClipbdFormat ) ||
                    IsClipboardFormatAvailable( WItemClipbdFormat ) ) {
                    EnableMenuItem( (HMENU)wParam, IDM_ACC_PASTE, MF_ENABLED );
                } else {
                    EnableMenuItem( (HMENU)wParam, IDM_ACC_PASTE, MF_GRAYED );
                }
                CloseClipboard();
            }
        }
        break;

    case WM_CREATE:
        einfo = ((CREATESTRUCT *)lParam)->lpCreateParams;
        SET_WNDLONGPTR( hWnd, 0, (LONG_PTR)einfo );
        break;

    case WM_MENUSELECT:
        if( einfo != NULL ) {
            menu = WGetMenuHandle( einfo );
            WHandleMenuSelect( einfo->wsb, menu, wParam, lParam );
            setLastMenuSelect( einfo, wParam, lParam );
        }
        break;

    case WM_GETMINMAXINFO:
        minmax = (MINMAXINFO *)lParam;
        minmax->ptMinTrackSize.x = appWidth;
        minmax->ptMinTrackSize.y = appHeight;
        break;

    case WM_MOVE:
        if( einfo != NULL ) {
            if( IsZoomed( hWnd ) ) {
                WSetOption( WOptScreenMax, TRUE );
            } else if( !IsIconic( hWnd ) ) {
                WUpdateScreenPosOpt( hWnd );
                WSetOption( WOptScreenMax, FALSE );
            }
        }
        break;

    case WM_SIZE:
        if( einfo != NULL ) {
            if( wParam == SIZE_MAXIMIZED ) {
                WSetOption( WOptScreenMax, TRUE );
            } else if( wParam != SIZE_MINIMIZED ) {
                WUpdateScreenPosOpt( hWnd );
                WSetOption( WOptScreenMax, FALSE );
            }
            WResizeWindows( einfo );
        }
        break;

#if 0
    case WM_ACTIVATE:
        if( GET_WM_ACTIVATE_FACTIVE( wParam, lParam ) != WA_INACTIVE ) {
            einfo = (WAccelEditInfo *)GET_WNDLONGPTR( hWnd, 0 );
            if( einfo != NULL && einfo->edit_dlg != (HWND)NULL ) {
                SetFocus( einfo->edit_dlg );
            }
            WSetCurrentEditInfo( einfo );
        } else {
            WSetCurrentEditInfo( NULL );
        }
        break;
#endif

    case WM_COMMAND:
        wp = LOWORD( wParam );
        switch( wp ) {
        case IDM_ACC_CLEAR:
            WHandleClear( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_UPDATE:
            SendMessage( einfo->info->parent, ACCEL_PLEASE_SAVEME, 0, (LPARAM)einfo->hndl );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_OPEN:
            pass_to_def = FALSE;
            if( einfo->info->modified ) {
                ret = WQuerySave( einfo, FALSE );
                if( !ret ) {
                    break;
                }
            }
            ret = SendMessage( einfo->info->parent, ACCEL_PLEASE_OPENME, 0,
                               (LPARAM)einfo->hndl );
            ret = FALSE;
            break;

        case IDM_ACC_SAVE:
            WSaveObject( einfo, FALSE, FALSE );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_SAVEAS:
            WSaveObject( einfo, TRUE, FALSE );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_SAVEINTO:
            WSaveObject( einfo, TRUE, TRUE );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_EXIT:
            /* clean up before we exit */
            PostMessage( einfo->win, WM_CLOSE, 0, 0 );
            break;

        case IDM_ACC_PASTE:
            WPasteAccelItem( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_COPY:
        case IDM_ACC_CUT:
            WClipAccelItem( einfo, wp == IDM_ACC_CUT );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_DELETE:
            WDeleteAccelEntry( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_NEWITEM:
            WInsertAccelEntry( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_KEYVALUE:
            WSetStatusByID( einfo->wsb, W_GETTINGKEYS, -1 );
            WHandleGetKeyValue( einfo, einfo->last_menu_select == IDM_ACC_KEYVALUE );
            WSetStatusReadyText( einfo->wsb );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_SYMBOLS:
            handleSymbols( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_LOAD_SYMBOLS:
            handleLoadSymbols( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_SHOWRIBBON:
            menu = WGetMenuHandle( einfo );
            WShowRibbon( einfo, menu );
            pass_to_def = FALSE;
            break;

        case IDM_ACC_MEM_FLAGS:
            WSetStatusByID( einfo->wsb, W_CHANGEACCELMEMFLAGS, -1 );
            einfo->info->modified |= WChangeMemFlags( einfo->win, &einfo->info->MemFlags,
                                                      einfo->info->res_name,
                                                      WGetEditInstance(),
                                                      WAccHelpRoutine );
            pass_to_def = FALSE;
            WSetStatusReadyText( einfo->wsb );
            break;

        case IDM_ACC_RENAME:
            WHandleRename( einfo );
            pass_to_def = FALSE;
            break;

        case IDM_HELP:
            WAccHelpRoutine();
            pass_to_def = FALSE;
            break;

        case IDM_HELP_SEARCH:
            WAccHelpSearchRoutine();
            pass_to_def = FALSE;
            break;

        case IDM_HELP_ON_HELP:
            WAccHelpOnHelpRoutine();
            pass_to_def = FALSE;
            break;

        case IDM_ACC_ABOUT:
            ai.owner = hWnd;
            ai.inst = WGetEditInstance();
            ai.name = AllocRCString( W_ABOUT_NAME );
            ai.version = AllocRCString( W_ABOUT_VERSION );
            ai.first_cr_year = "2002";
            ai.title = AllocRCString( W_ABOUT_TITLE );
            DoAbout( &ai );
            FreeRCString( ai.name );
            FreeRCString( ai.version );
            FreeRCString( ai.title );
            pass_to_def = FALSE;
            break;
        }
        break;

    case WM_DESTROY:
        WWinHelp( hWnd, "resacc.hlp", HELP_QUIT, 0 );
        WCleanup( einfo );
        break;

    case WM_CLOSE:
        ret = TRUE;
        pass_to_def = WHandleWM_CLOSE( einfo, wParam != 0 );
        wParam = 0;
        break;
    }

    if( pass_to_def ) {
        ret = DefWindowProc( hWnd, message, wParam, lParam );
    }

    return( ret );
}