X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b8d3a4f1a1a74b90394576d5828b8fdd8aeef277..cb6827a8c645a883a2d2a7b117a50609d706ccce:/src/msw/menu.cpp diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 570d92e727..a24f0f419d 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -9,21 +9,8 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// wxWindows headers -// ----------------- - #ifdef __GNUG__ - #pragma implementation "menu.h" - #pragma implementation "menuitem.h" +#pragma implementation "menu.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -86,6 +73,8 @@ wxMenu::wxMenu(const wxString& Title, const wxFunction func) m_hMenu = (WXHMENU) CreatePopupMenu(); m_savehMenu = 0 ; m_topLevelMenu = this; + m_clientData = (void*) NULL; + if (m_title != "") { Append(idMenuTitle, m_title) ; @@ -242,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) @@ -321,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"); } @@ -343,16 +332,28 @@ 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 + // 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"); + } + } } const wxString wxMenu::GetTitle() const @@ -400,8 +401,9 @@ void wxMenu::SetLabel(int Id, const wxString& label) item->SetName(label); } -wxString wxMenu::GetLabel(int Id) const +wxString wxMenu::GetLabel(int id) const { +/* static char tmp[128] ; int len; if (m_hMenu) @@ -412,16 +414,30 @@ wxString wxMenu::GetLabel(int Id) const len = 0 ; tmp[len] = '\0' ; return wxString(tmp) ; + +*/ + wxMenuItem *pItem = FindItemForId(id) ; + if (pItem) + return pItem->GetName() ; + else + return wxEmptyString; } 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. @@ -489,8 +505,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) @@ -513,13 +531,14 @@ void wxMenu::ProcessCommand(wxCommandEvent & event) // Try the window the menu was popped up from (and up // through the hierarchy) if ( !processed && GetInvokingWindow()) - processed = GetInvokingWindow()->ProcessEvent(event); + processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); } 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; @@ -670,7 +689,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) ; @@ -895,8 +914,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; } @@ -943,3 +965,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(); + } +}