X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c36d477458df6ffe02aef30fc31efb1ae2522a49..dbe0872fc80f7fc9ac37235ab1f8ba8224b0bfa5:/src/common/menucmn.cpp diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 2b65f80845..9e5d1e8715 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -58,7 +58,8 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu, wxItemKind kind, wxMenu *subMenu) { - wxASSERT_MSG( parentMenu != NULL, wxT("menuitem should have a menu") ); + // notice that parentMenu can be NULL: the item can be attached to the menu + // later with SetMenu() m_parentMenu = parentMenu; m_subMenu = subMenu; @@ -67,11 +68,11 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu, m_id = id; m_kind = kind; if (m_id == wxID_ANY) - m_id = wxNewId(); + m_id = wxWindow::NewControlId(); if (m_id == wxID_SEPARATOR) m_kind = wxITEM_SEPARATOR; - SetText(text); + SetItemLabel(text); SetHelp(help); } @@ -84,7 +85,7 @@ wxMenuItemBase::~wxMenuItemBase() wxAcceleratorEntry *wxMenuItemBase::GetAccel() const { - return wxAcceleratorEntry::Create(GetText()); + return wxAcceleratorEntry::Create(GetItemLabel()); } void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel) @@ -96,12 +97,12 @@ void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel) text += accel->ToString(); } - SetText(text); + SetItemLabel(text); } #endif // wxUSE_ACCEL -void wxMenuItemBase::SetText(const wxString& str) +void wxMenuItemBase::SetItemLabel(const wxString& str) { m_text = str; @@ -125,6 +126,20 @@ void wxMenuItemBase::SetHelp(const wxString& str) } } +#ifndef __WXPM__ +wxString wxMenuItemBase::GetLabelText(const wxString& text) +{ + return wxStripMenuCodes(text); +} +#endif + +#if WXWIN_COMPATIBILITY_2_8 +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +{ + return GetLabelText(text); +} +#endif + bool wxMenuBase::ms_locked = true; // ---------------------------------------------------------------------------- @@ -133,20 +148,18 @@ bool wxMenuBase::ms_locked = true; void wxMenuBase::Init(long style) { - m_menuBar = (wxMenuBar *)NULL; - m_menuParent = (wxMenu *)NULL; + m_menuBar = NULL; + m_menuParent = NULL; - m_invokingWindow = (wxWindow *)NULL; + m_invokingWindow = NULL; m_style = style; - m_clientData = (void *)NULL; + m_clientData = NULL; m_eventHandler = this; } wxMenuBase::~wxMenuBase() { WX_CLEAR_LIST(wxMenuItemList, m_items); - - // Actually, in GTK, the submenus have to get deleted first. } // ---------------------------------------------------------------------------- @@ -227,11 +240,11 @@ wxMenuItem *wxMenuBase::DoRemove(wxMenuItem *item) m_items.Erase(node); // item isn't attached to anything any more - item->SetMenu((wxMenu *)NULL); + item->SetMenu(NULL); wxMenu *submenu = item->GetSubMenu(); if ( submenu ) { - submenu->SetParent((wxMenu *)NULL); + submenu->SetParent(NULL); if ( submenu->IsAttached() ) submenu->Detach(); } @@ -252,7 +265,7 @@ bool wxMenuBase::DoDelete(wxMenuItem *item) wxCHECK_MSG( item2, false, wxT("failed to delete menu item") ); // don't delete the submenu - item2->SetSubMenu((wxMenu *)NULL); + item2->SetSubMenu(NULL); delete item2; @@ -283,7 +296,7 @@ bool wxMenuBase::DoDestroy(wxMenuItem *item) // Finds the item id matching the given string, wxNOT_FOUND if not found. int wxMenuBase::FindItem(const wxString& text) const { - wxString label = wxMenuItem::GetLabelFromText(text); + wxString label = wxMenuItem::GetLabelText(text); for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst(); node; node = node->GetNext() ) @@ -300,7 +313,7 @@ int wxMenuBase::FindItem(const wxString& text) const // name just like the ordinary items if ( !item->IsSeparator() ) { - if ( item->GetLabel() == label ) + if ( item->GetItemLabelText() == label ) return item->GetId(); } } @@ -343,7 +356,7 @@ wxMenuItem *wxMenuBase::FindItem(int itemId, wxMenu **itemMenu) const // non recursive search wxMenuItem *wxMenuBase::FindChildItem(int id, size_t *ppos) const { - wxMenuItem *item = (wxMenuItem *)NULL; + wxMenuItem *item = NULL; wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); size_t pos; @@ -445,7 +458,7 @@ bool wxMenuBase::SendEvent(int id, int checked) { wxEvtHandler *handler = GetEventHandler(); if ( handler ) - processed = handler->ProcessEvent(event); + processed = handler->SafelyProcessEvent(event); } // Try the window the menu was popped up from (and up through the @@ -458,7 +471,7 @@ bool wxMenuBase::SendEvent(int id, int checked) wxWindow *win = menu->GetInvokingWindow(); if ( win ) { - processed = win->GetEventHandler()->ProcessEvent(event); + processed = win->HandleWindowEvent(event); break; } @@ -545,7 +558,7 @@ void wxMenuBase::SetLabel( int id, const wxString &label ) wxCHECK_RET( item, wxT("wxMenu::SetLabel: no such item") ); - item->SetText(label); + item->SetItemLabel(label); } wxString wxMenuBase::GetLabel( int id ) const @@ -554,7 +567,7 @@ wxString wxMenuBase::GetLabel( int id ) const wxCHECK_MSG( item, wxEmptyString, wxT("wxMenu::GetLabel: no such item") ); - return item->GetText(); + return item->GetItemLabel(); } void wxMenuBase::SetHelpString( int id, const wxString& helpString ) @@ -665,14 +678,14 @@ wxMenu *wxMenuBarBase::Remove(size_t pos) int wxMenuBarBase::FindMenu(const wxString& title) const { - wxString label = wxMenuItem::GetLabelFromText(title); + wxString label = wxMenuItem::GetLabelText(title); size_t count = GetMenuCount(); for ( size_t i = 0; i < count; i++ ) { - wxString title2 = GetLabelTop(i); + wxString title2 = GetMenuLabel(i); if ( (title2 == title) || - (wxMenuItem::GetLabelFromText(title2) == label) ) + (wxMenuItem::GetLabelText(title2) == label) ) { // found return (int)i; @@ -723,13 +736,13 @@ wxMenuItem *wxMenuBarBase::FindItem(int id, wxMenu **menu) const int wxMenuBarBase::FindMenuItem(const wxString& menu, const wxString& item) const { - wxString label = wxMenuItem::GetLabelFromText(menu); + wxString label = wxMenuItem::GetLabelText(menu); int i = 0; wxMenuList::compatibility_iterator node; for ( node = m_menus.GetFirst(); node; node = node->GetNext(), i++ ) { - if ( label == wxMenuItem::GetLabelFromText(GetLabelTop(i)) ) + if ( label == wxMenuItem::GetLabelText(GetMenuLabel(i)) ) return node->GetData()->FindItem(item); } @@ -783,7 +796,7 @@ void wxMenuBarBase::SetLabel(int id, const wxString& label) wxCHECK_RET( item, wxT("wxMenuBar::SetLabel(): no such item") ); - item->SetText(label); + item->SetItemLabel(label); } wxString wxMenuBarBase::GetLabel(int id) const @@ -793,7 +806,7 @@ wxString wxMenuBarBase::GetLabel(int id) const wxCHECK_MSG( item, wxEmptyString, wxT("wxMenuBar::GetLabel(): no such item") ); - return item->GetText(); + return item->GetItemLabel(); } void wxMenuBarBase::SetHelpString(int id, const wxString& helpString) @@ -815,7 +828,7 @@ wxString wxMenuBarBase::GetHelpString(int id) const return item->GetHelp(); } -void wxMenuBarBase::UpdateMenus( void ) +void wxMenuBarBase::UpdateMenus() { wxEvtHandler* source; wxMenu* menu; @@ -832,4 +845,17 @@ void wxMenuBarBase::UpdateMenus( void ) } } +#if WXWIN_COMPATIBILITY_2_8 +// get or change the label of the menu at given position +void wxMenuBarBase::SetLabelTop(size_t pos, const wxString& label) +{ + SetMenuLabel(pos, label); +} + +wxString wxMenuBarBase::GetLabelTop(size_t pos) const +{ + return GetMenuLabelText(pos); +} +#endif + #endif // wxUSE_MENUS