}
}
- // 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
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.
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)
bool wxWindow::PopupMenu(wxMenu *menu, int x, int y)
{
menu->SetInvokingWindow(this);
+ menu->UpdateUI();
HWND hWnd = (HWND) GetHWND();
HMENU hMenu = (HMENU)menu->m_hMenu;
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();
+ }
+}