HMENU GUICreateSubMenu( gui_window *wnd, int num, gui_menu_struct *menu, hint_type type ) { HMENU hmenu; int i; HMENU submenu; unsigned menu_flags; unsigned attr_flags; hmenu = _wpi_createpopupmenu(); if( hmenu == NULLHANDLE ) { return( NULLHANDLE ); } for( i = 0; i < num; i++ ) { GUICreateMenuFlags( menu[i].style, &menu_flags, &attr_flags ); if( menu[i].num_child_menus ) { submenu = GUICreateSubMenu( wnd, menu[i].num_child_menus, menu[i].child, type ); _wpi_appendmenu( hmenu, MF_POPUP | menu_flags, attr_flags, menu[i].id, submenu, menu[i].label ); InsertPopup( wnd, menu[i].id, submenu, type ); } else { _wpi_appendmenu( hmenu, menu_flags, attr_flags, menu[i].id, (HMENU)NULL, menu[i].label ); } } return( hmenu ); }
bool GUIAddToSystemMenu( gui_window *wnd, HWND hwnd, int num_menus, gui_menu_struct *menu, gui_create_styles style ) { HMENU system; gui_ctl_idx num; if( !( style & GUI_SYSTEM_MENU ) ) { return( true ); } system = _wpi_getsystemmenu( hwnd ); if( system == NULLHANDLE ) { return( false ); } if( GUIMDI && ( _wpi_getparent( hwnd ) != NULLHANDLE ) ) { num = _wpi_getmenuitemcount( system ); #ifndef __OS2_PM__ ModifyMenu( system, num - 1, MF_STRING | MF_BYPOSITION | MF_GRAYED, SC_NEXTWINDOW, LIT( NexXt ) ); // add \tCtrl+F6" ); ModifyMenu( system, num - 3, MF_STRING | MF_BYPOSITION | MF_ENABLED, SC_CLOSE, LIT( XClose ) ); // add \tctrl+f4" ); #endif } if( !( style & GUI_CLOSEABLE ) ) { _wpi_enablemenuitem( system, SC_CLOSE, FALSE, FALSE ); } if( style & GUI_CHANGEABLE_FONT ) { if( _wpi_appendmenu( system, MF_SEPARATOR, 0, 0, NULLHANDLE, NULL ) ) { _wpi_appendmenu( system, MF_STRING, MF_ENABLED, GUIHint[GUI_MENU_FONT].id, NULLHANDLE, GUIHint[GUI_MENU_FONT].label ); } } if( num_menus > 0 ) { if( _wpi_appendmenu( system, MF_SEPARATOR, 0, 0, NULLHANDLE, NULL ) ) { return( AppendMenus( wnd, system, num_menus, menu ) ); } } return( true ); }
/* * duplicateMenu - create a duplicate copy of a menu */ static HMENU duplicateMenu( HMENU orig ) { WPI_MENUSTATE mstate; int num; unsigned menu_flags; unsigned attr_flags; UINT id; char name[MAX_STR]; int i; HMENU copy; HMENU sub; if( orig != NULLHANDLE ) { copy = _wpi_createpopupmenu(); if( copy == NULLHANDLE ) { return( NULLHANDLE ); } num = (int)_wpi_getmenuitemcount( orig ); for( i = 0; i < num; i++ ) { if( _wpi_getmenustate( orig, i, &mstate, TRUE ) ) { _wpi_getmenuflagsfromstate( &mstate, &menu_flags, &attr_flags ); if( _wpi_ismenuseparatorfromstate( &mstate ) ) { _wpi_appendmenu( copy, menu_flags, attr_flags, 0, NULLHANDLE, NULL ); } else if( _wpi_ismenupopupfromstate( &mstate ) ) { sub = duplicateMenu( _wpi_getsubmenu( orig, i ) ); name[0] = 0; _wpi_getmenutext( orig, i, name, MAX_STR - 1, TRUE ); _wpi_appendmenu( copy, menu_flags, attr_flags, 0, sub, name ); } else { id = _wpi_getmenuitemid( orig, i ); _wpi_getmenutext( orig, i, name, MAX_STR - 1, TRUE ); _wpi_appendmenu( copy, menu_flags, attr_flags, id, NULLHANDLE, name ); } } } } return( copy ); } /* duplicateMenu */
static bool AppendMenus( gui_window *wnd, HMENU main, int num, gui_menu_struct *menu ) { int i; HMENU hmenu; for( i = 0; i < num; i++ ) { hmenu = GUICreateSubMenu( wnd, menu[i].num_child_menus, menu[i].child, MENU_HINT ); if( hmenu != NULLHANDLE ) { _wpi_appendmenu( main, MF_STRING | MF_POPUP, MF_ENABLED, menu[i].id, hmenu, menu[i].label ); InsertPopup( wnd, menu[i].id, hmenu, MENU_HINT ); } } return( true ); }
static bool AddMenu( HMENU hmenu, gui_window *wnd, gui_menu_struct *menu, bool insert, gui_ctl_id id_position, bool by_position, hint_type type ) { unsigned menu_flags; unsigned attr_flags; gui_ctl_id newitem; HMENU submenu; submenu = (HMENU)NULL; newitem = menu->id; if( hmenu == NULLHANDLE ) { return( false ); } if( menu->num_child_menus == 0 ) { GUICreateMenuFlags( menu->style, &menu_flags, &attr_flags ); } else { submenu = GUICreateSubMenu( wnd, menu->num_child_menus, menu->child, type ); if( submenu == NULLHANDLE ) { return( false ); } else { GUICreateMenuFlags( menu->style, &menu_flags, &attr_flags ); menu_flags |= MF_POPUP; InsertPopup( wnd, newitem, submenu, type ); } } if( insert ) { if( by_position ) { if( ( (gui_ctl_idx)id_position != -1 ) && GUIMDIUpdatedMenu() ) { id_position++; } } _wpi_insertmenu( hmenu, id_position, menu_flags, attr_flags, newitem, submenu, menu->label, ( by_position ) ? TRUE : FALSE ); } else { _wpi_appendmenu( hmenu, menu_flags, attr_flags, newitem, submenu, menu->label ); } GUIAppendHintText( wnd, menu, type ); GUIMDIResetMenus( wnd, wnd->parent, 1, menu ); if( ( type != FLOAT_HINT ) && ( hmenu == GUIGetHMENU( wnd ) ) ) { GUIDrawMenuBar( wnd ); } return( true ); }
/* * modifyChildSystemMenu - adjust system menu to make it a child system menu */ static HMENU modifyChildSystemMenu( HMENU sys_menu ) { if( sys_menu == NULLHANDLE ) { return( NULLHANDLE ); } /* fix hotkey designation for close */ _wpi_setmenutext( sys_menu, SC_CLOSE, "&Close\tCtrl+F4", FALSE ); /* remove task switch option */ _wpi_deletemenu( sys_menu, SC_TASKLIST, FALSE ); /* add next window option */ _wpi_appendmenu( sys_menu, MF_STRING, 0, SC_NEXTWINDOW, NULLHANDLE, "Nex&t\tCtrl+F6" ); return( sys_menu ); } /* modifyChildSystemMenu */
static bool guiToolBarProc( HWND hwnd, WPI_MSG msg, WPI_PARAM1 wparam, WPI_PARAM2 lparam ) { gui_window *wnd; toolbarinfo *tbar; HMENU hmenu; gui_ctl_id id; wnd = GetToolWnd( hwnd ); if( wnd == NULL ) { return( false ); } tbar = wnd->tbinfo; if( tbar == NULL ) { return( false ); } switch( msg ) { case WM_CREATE : hwnd = _wpi_getframe( hwnd ); hmenu = _wpi_getsystemmenu( hwnd ); if( hmenu != NULLHANDLE ) { if( _wpi_appendmenu( hmenu, MF_SEPARATOR, 0, 0, NULLHANDLE, NULL ) ) { _wpi_appendmenu( hmenu, MF_ENABLED|MF_SYSMENU, 0, GUIHint[GUI_MENU_FIX_TOOLBAR].id, NULLHANDLE, GUIHint[GUI_MENU_FIX_TOOLBAR].label ); } } break; #ifdef __OS2_PM__ case WM_CHAR : case WM_TRANSLATEACCEL : #else case WM_SYSKEYDOWN : case WM_SYSKEYUP : case WM_KEYUP : case WM_KEYDOWN : #endif return( GUIProcesskey( hwnd, msg, wparam, lparam ) != 0 ); case WM_MENUSELECT : GUIProcessMenuSelect( wnd, hwnd, msg, wparam, lparam ); return( true ); case WM_SYSCOMMAND : id = _wpi_getid( wparam ); switch( id ) { case GUI_FIX_TOOLBAR : GUIChangeToolBar( wnd ); } break; #ifndef __OS2_PM__ case WM_NCLBUTTONDBLCLK : #endif case WM_RBUTTONDBLCLK : case WM_LBUTTONDBLCLK : /* flip the current state of the toolbar - * if we are fixed then start to float or vice versa */ if( !HasToolAtPoint( tbar->hdl, wparam, lparam ) ) { #ifdef __OS2_PM__ // Hack: For some reason we will get here with bogus coords, // we need to ignore the event. Should really find out where // the message is coming from. if( (ULONG)wparam != 0x0FFFFFFF ) GUIChangeToolBar( wnd ); #else GUIChangeToolBar( wnd ); #endif return( true ); } break; case WM_MOVE: case WM_SIZE: // Whenever we are moved or sized as a floating toolbar, we remember our position // so that we can restore it when dbl. clicked if( tbar->info.style == TOOLBAR_FLOAT_STYLE ) { hwnd = _wpi_getframe( hwnd ); _wpi_getwindowrect( hwnd, &tbar->floatrect ); } break; case WM_GETMINMAXINFO: { #ifdef __WINDOWS_386__ WPI_MINMAXINFO __far *minmax= (WPI_MINMAXINFO __far *)MK_FP32( (void *)lparam ); #else WPI_MINMAXINFO *minmax = (WPI_MINMAXINFO *)lparam; #endif _wpi_setmintracksize( minmax, ( tbar->info.border_size.x + _wpi_getsystemmetrics( SM_CXFRAME ) ) * 2 + tbar->info.button_size.x, ( tbar->info.border_size.y + _wpi_getsystemmetrics( SM_CYFRAME ) ) * 2 + tbar->info.button_size.y + _wpi_getsystemmetrics( SM_CYCAPTION ) ); } break; case WM_CLOSE : GUICloseToolBar( wnd ); return( true ); break; } return( false ); }