X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3dd4e4e05cc46ffc653730715e527af7b18b9caf..71b8c213cb2c676b4715ef37e6155da3601f7881:/src/msw/menu.cpp diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 5c0c4cc9d4..77923bb06a 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -231,10 +231,10 @@ void wxMenu::Append(int Id, const wxString& label, void wxMenu::Delete(int id) { wxNode *node; - wxMenuItem *item; int pos; HMENU menu; + wxMenuItem *item = NULL; for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) { item = (wxMenuItem *)node->Data(); if (item->GetId() == id) @@ -310,9 +310,9 @@ void wxMenu::SetTitle(const wxString& label) { if ( !label.IsEmpty() ) { - if ( !InsertMenu(hMenu, 0, MF_BYPOSITION | MF_STRING, - idMenuTitle, m_title) || - !InsertMenu(hMenu, 1, MF_BYPOSITION, -1, NULL) ) + if ( !InsertMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING, + (unsigned)idMenuTitle, m_title) || + !InsertMenu(hMenu, 1u, MF_BYPOSITION, (unsigned)-1, NULL) ) { wxLogLastError("InsertMenu"); } @@ -332,16 +332,30 @@ void wxMenu::SetTitle(const wxString& label) else { // modify the title - if ( !ModifyMenu(hMenu, 0, + if ( !ModifyMenu(hMenu, 0u, MF_BYPOSITION | MF_STRING, - idMenuTitle, m_title) ) + (unsigned)idMenuTitle, m_title) ) { wxLogLastError("ModifyMenu"); } } } - // TODO use SetMenuItemInfo(MFS_DEFAULT) to put it in bold face +#ifndef __WIN16__ + // put the title string in bold face + if ( !m_title.IsEmpty() ) + { + MENUITEMINFO mii; + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_STATE; + mii.fState = MFS_DEFAULT; + + if ( !SetMenuItemInfo(hMenu, (unsigned)idMenuTitle, FALSE, &mii) ) + { + wxLogLastError("SetMenuItemInfo"); + } + } +#endif } const wxString wxMenu::GetTitle() const @@ -413,12 +427,19 @@ wxString wxMenu::GetLabel(int id) const bool wxMenu::MSWCommand(WXUINT WXUNUSED(param), WXWORD id) { - wxCommandEvent event(wxEVENT_TYPE_MENU_COMMAND); - event.SetEventObject( this ); - event.SetId( id ); - event.SetInt( id ); - ProcessCommand(event); - return TRUE; + // ignore commands from the menu title + + // NB: VC++ generates wrong assembler for `if ( id != idMenuTitle )'!! + if ( id != (WXWORD)idMenuTitle ) + { + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED); + event.SetEventObject( this ); + event.SetId( id ); + event.SetInt( id ); + ProcessCommand(event); + } + + return TRUE; } // Finds the item id matching the given string, -1 if not found. @@ -486,8 +507,10 @@ void wxMenu::SetHelpString(int itemId, const wxString& helpString) wxString wxMenu::GetHelpString (int itemId) const { wxMenuItem *item = FindItemForId (itemId); - wxString str(""); - return (item == NULL) ? str : item->GetHelp(); + if (item) + return item->GetHelp(); + else + return wxEmptyString; } void wxMenu::ProcessCommand(wxCommandEvent & event) @@ -517,6 +540,7 @@ extern wxMenu *wxCurrentPopupMenu; bool wxWindow::PopupMenu(wxMenu *menu, int x, int y) { menu->SetInvokingWindow(this); + menu->UpdateUI(); HWND hWnd = (HWND) GetHWND(); HMENU hMenu = (HMENU)menu->m_hMenu; @@ -538,7 +562,16 @@ bool wxWindow::PopupMenu(wxMenu *menu, int x, int y) wxMenuBar::wxMenuBar() { m_eventHandler = this; + m_menuCount = 0; + m_menus = NULL; + m_titles = NULL; + m_menuBarFrame = NULL; + m_hMenu = 0; +} +wxMenuBar::wxMenuBar( long WXUNUSED(style) ) +{ + m_eventHandler = this; m_menuCount = 0; m_menus = NULL; m_titles = NULL; @@ -667,7 +700,7 @@ bool wxMenuBar::Checked(int Id) const if (!item) return FALSE; - int Flag ; + int Flag = 0; if (itemMenu->m_hMenu) Flag=GetMenuState((HMENU)itemMenu->m_hMenu, Id, MF_BYCOMMAND) ; @@ -892,8 +925,11 @@ wxMenuItem *wxMenuBar::FindItemForId (int Id, wxMenu ** itemMenu) const wxMenuItem *item = NULL; int i; for (i = 0; i < m_menuCount; i++) - if ((item = m_menus[i]->FindItemForId (Id, itemMenu))) + { + item = m_menus[i]->FindItemForId (Id, itemMenu); + if (item) return item; + } return NULL; } @@ -940,3 +976,42 @@ WXHMENU wxMenu::GetHMenu() const return 0; } +// Update a menu and all submenus recursively. +// source is the object that has the update event handlers +// defined for it. If NULL, the menu or associated window +// will be used. +void wxMenu::UpdateUI(wxEvtHandler* source) +{ + if (!source && GetInvokingWindow()) + source = GetInvokingWindow()->GetEventHandler(); + if (!source) + source = GetEventHandler(); + if (!source) + source = this; + + wxNode* node = GetItems().First(); + while (node) + { + wxMenuItem* item = (wxMenuItem*) node->Data(); + if ( !item->IsSeparator() ) + { + wxWindowID id = item->GetId(); + wxUpdateUIEvent event(id); + event.SetEventObject( source ); + + if (source->ProcessEvent(event)) + { + if (event.GetSetText()) + SetLabel(id, event.GetText()); + if (event.GetSetChecked()) + Check(id, event.GetChecked()); + if (event.GetSetEnabled()) + Enable(id, event.GetEnabled()); + } + + if (item->GetSubMenu()) + item->GetSubMenu()->UpdateUI(source); + } + node = node->Next(); + } +}