X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/93cf77c076b699e8e0b3b0049bd4f80de15997dd..2a31049201e9c1ff9f515eb9d144ae392f4b4e5a:/src/stubs/menu.cpp diff --git a/src/stubs/menu.cpp b/src/stubs/menu.cpp index 217e6c8b88..32188c4b4a 100644 --- a/src/stubs/menu.cpp +++ b/src/stubs/menu.cpp @@ -25,15 +25,14 @@ #include "wx/menu.h" #include "wx/menuitem.h" #include "wx/log.h" +#include "wx/utils.h" // other standard headers // ---------------------- #include -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) -#endif // ============================================================================ // implementation @@ -49,6 +48,7 @@ wxMenu::wxMenu(const wxString& title, const wxFunction func) m_eventHandler = this; m_noItems = 0; m_menuBar = NULL; + m_clientData = (void*) NULL; if (m_title != "") { Append(-2, m_title) ; @@ -180,7 +180,7 @@ void wxMenu::SetTitle(const wxString& label) // TODO } -const wxString& wxMenu::GetTitle() const +const wxString wxMenu::GetTitle() const { return m_title; } @@ -293,15 +293,59 @@ void wxMenu::ProcessCommand(wxCommandEvent & event) { processed = GetEventHandler()->ProcessEvent(event); } - +/* TODO // Try the window the menu was popped up from (and up // through the hierarchy) if ( !processed && GetInvokingWindow()) processed = GetInvokingWindow()->ProcessEvent(event); +*/ +} + +// 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(); + } } bool wxWindow::PopupMenu(wxMenu *menu, int x, int y) { + menu->SetInvokingWindow(this); + menu->UpdateUI(); + // TODO return FALSE; } @@ -318,7 +362,7 @@ wxMenuBar::wxMenuBar() // TODO } -wxMenuBar::wxMenuBar(int n, wxMenu *Mmnus[], const wxString titles[]) +wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[]) { m_eventHandler = this; m_menuCount = n; @@ -560,7 +604,7 @@ wxString wxMenuBar::GetHelpString (int Id) const for (i = 0; i < m_menuCount; i++) { if (m_menus[i]->FindItemForId (Id)) - eturn wxString(m_menus[i]->GetHelpString (Id)); + return wxString(m_menus[i]->GetHelpString (Id)); } return wxString(""); }