From c71830c3b63568566cf5f006165e51ffaee0c704 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Nov 1999 17:23:29 +0000 Subject: [PATCH 1/1] wxMotif compiles (and runs minimal sample) again after wxMenu changes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4311 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/spinctlg.h | 32 ++- include/wx/motif/menu.h | 203 ++++++----------- include/wx/motif/menuitem.h | 5 +- src/motif/menu.cpp | 399 ++++++++-------------------------- src/motif/menuitem.cpp | 24 +- src/motif/window.cpp | 2 +- 6 files changed, 211 insertions(+), 454 deletions(-) diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index 8d791d1106..288758c6f0 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -21,10 +21,38 @@ class WXDLLEXPORT wxSpinCtrl : public wxTextCtrl { public: - wxSpinCtrlBase() { Init(); } + wxSpinCtrl() { Init(); } + + wxSpinCtrl(wxWindow *parent, + wxWindowID id = -1, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxSP_ARROW_KEYS, + int min = 0, int max = 100, int initial = 0, + const wxString& name = _T("wxSpinCtrl")) + { + Create(parent, id, value, pos, size, style, min, max, initial, name); + } + + bool Create(wxWindow *parent, + wxWindowID id = -1, + const wxString& value = wxEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxSP_ARROW_KEYS, + int min = 0, int max = 100, int initial = 0, + const wxString& name = _T("wxSpinCtrl")) + { + SetValue(initial); + SetRange(min, max); + + return wxTextCtrl::Create(parent, id, value, pos, size, style, + wxDefaultValidator, name); + } // accessors - int GetValue() const + int GetValue(int WXUNUSED(dummy) = 1) const { int n; if ( (wxSscanf(wxTextCtrl::GetValue(), wxT("%d"), &n) != 1) ) diff --git a/include/wx/motif/menu.h b/include/wx/motif/menu.h index 97c694329e..90fc70ed35 100644 --- a/include/wx/motif/menu.h +++ b/include/wx/motif/menu.h @@ -25,162 +25,93 @@ class wxFrame; // Menu // ---------------------------------------------------------------------------- -class wxMenu : public wxEvtHandler +class wxMenu : public wxMenuBase { - DECLARE_DYNAMIC_CLASS(wxMenu) - public: - // ctor & dtor -#ifdef WXWIN_COMPATIBILITY - wxMenu( const wxString& title, const wxFunction func) - { - Init(title, 0, func); - } -#endif // WXWIN_COMPATIBILITY - wxMenu( const wxString& title = wxEmptyString, long style = 0 ) + // ctors & dtor + wxMenu(const wxString& title, long style = 0) + : wxMenuBase(title, style) { Init(); } + + wxMenu(long style = 0) : wxMenuBase(style) { Init(); } + + virtual ~wxMenu(); + + // implement base class virtuals + virtual bool DoAppend(wxMenuItem *item); + virtual bool DoInsert(size_t pos, wxMenuItem *item); + virtual wxMenuItem *DoRemove(wxMenuItem *item); + + virtual void Break(); + + virtual void SetTitle(const wxString& title); + + bool ProcessCommand(wxCommandEvent& event); + +#if WXWIN_COMPATIBILITY + wxMenu(const wxString& title, const wxFunction func) + : wxMenuBase(title) { - Init(title, style); + Callback(func); } - virtual ~wxMenu(); - - // construct menu - // append items to the menu - // separator line - void AppendSeparator(); - // normal item - void Append(int id, const wxString& Label, const wxString& helpString = wxEmptyString, - bool checkable = FALSE); - // a submenu - void Append(int id, const wxString& Label, wxMenu *SubMenu, - const wxString& helpString = wxEmptyString); - // the most generic form (create wxMenuItem first and use it's functions) - void Append(wxMenuItem *pItem); - // insert a break in the menu - void Break(); - // delete an item - void Delete(int id); - - // menu item control - void Enable(int id, bool Flag); - bool Enabled(int id) const; - bool IsEnabled(int id) const { return Enabled(id); }; - void Check(int id, bool Flag); - bool Checked(int id) const; - bool IsChecked(int id) const { return IsChecked(id); }; - - // Client data - void SetClientData(void* clientData) { m_clientData = clientData; } - void* GetClientData() const { return m_clientData; } - - // item properties - // title - void SetTitle(const wxString& label); - const wxString GetTitle() const; - // label - void SetLabel(int id, const wxString& label); - wxString GetLabel(int id) const; - // help string - virtual void SetHelpString(int id, const wxString& helpString); - virtual wxString GetHelpString(int id) const ; - - // find item - // Finds the item id matching the given string, -1 if not found. - virtual int FindItem(const wxString& itemString) const ; - // Find wxMenuItem by ID, and item's menu too if itemMenu is !NULL. - wxMenuItem *FindItemForId(int itemId, wxMenu **itemMenu = NULL) const; - - // Updates the UI for 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 UpdateUI(wxEvtHandler* source = (wxEvtHandler*) NULL); - - void ProcessCommand(wxCommandEvent& event); - -#ifdef WXWIN_COMPATIBILITY - void Callback(const wxFunction func) { m_callback = func; } #endif // WXWIN_COMPATIBILITY - void SetEventHandler(wxEvtHandler *handler) { m_eventHandler = handler; } - wxEvtHandler *GetEventHandler() { return m_eventHandler; } + //// Motif-specific + WXWidget GetButtonWidget() const { return m_buttonWidget; } + void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } - wxList& GetItems() const { return (wxList&) m_menuItems; } + WXWidget GetMainWidget() const { return m_menuWidget; } - void SetInvokingWindow(wxWindow *pWin) { m_pInvokingWindow = pWin; } - wxWindow *GetInvokingWindow() const { return m_pInvokingWindow; } + int GetId() const { return m_menuId; } + void SetId(int id) { m_menuId = id; } - //// Motif-specific - WXWidget GetButtonWidget() const { return m_buttonWidget; } - void SetButtonWidget(WXWidget buttonWidget) { m_buttonWidget = buttonWidget; } - WXWidget GetMainWidget() const { return m_menuWidget; } - wxMenu* GetParent() const { return m_menuParent; } - int GetId() const { return m_menuId; } - void SetId(int id) { m_menuId = id; } - void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } - wxMenuBar* GetMenuBar() const { return m_menuBar; } + void SetMenuBar(wxMenuBar* menuBar) { m_menuBar = menuBar; } + wxMenuBar* GetMenuBar() const { return m_menuBar; } - void CreatePopup (WXWidget logicalParent, int x, int y); - void DestroyPopup (void); - void ShowPopup (int x, int y); - void HidePopup (void); + void CreatePopup(WXWidget logicalParent, int x, int y); + void DestroyPopup(); + void ShowPopup(int x, int y); + void HidePopup(); - WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu, - const wxString& title = "", bool isPulldown = FALSE); + WXWidget CreateMenu(wxMenuBar *menuBar, WXWidget parent, wxMenu *topMenu, + const wxString& title = wxEmptyString, + bool isPulldown = FALSE); - // For popups, need to destroy, then recreate menu for a different (or - // possibly same) window, since the parent may change. - void DestroyMenu(bool full); - WXWidget FindMenuItem(int id, wxMenuItem **it = NULL) const; + // For popups, need to destroy, then recreate menu for a different (or + // possibly same) window, since the parent may change. + void DestroyMenu(bool full); + WXWidget FindMenuItem(int id, wxMenuItem **it = NULL) const; - const wxColour& GetBackgroundColour() const { return m_backgroundColour; } - const wxColour& GetForegroundColour() const { return m_foregroundColour; } - const wxFont& GetFont() const { return m_font; } + const wxColour& GetBackgroundColour() const { return m_backgroundColour; } + const wxColour& GetForegroundColour() const { return m_foregroundColour; } + const wxFont& GetFont() const { return m_font; } - void SetBackgroundColour(const wxColour& colour); - void SetForegroundColour(const wxColour& colour); - void SetFont(const wxFont& colour); - void ChangeFont(bool keepOriginalSize = FALSE); + void SetBackgroundColour(const wxColour& colour); + void SetForegroundColour(const wxColour& colour); + void SetFont(const wxFont& colour); + void ChangeFont(bool keepOriginalSize = FALSE); - // implementation from now on - WXWidget GetHandle() const { return m_menuWidget; } - bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; } + WXWidget GetHandle() const { return m_menuWidget; } -public: -#ifdef WXWIN_COMPATIBILITY - wxFunction m_callback; -#endif // WXWIN_COMPATIBILITY + bool IsTearOff() const { return (m_style & wxMENU_TEAROFF) != 0; } - int m_noItems; - wxString m_title; - wxMenuBar * m_menuBar; - wxList m_menuItems; - wxEvtHandler * m_eventHandler; - void* m_clientData; - wxWindow* m_pInvokingWindow; - - long m_style; - - //// Motif-specific - int m_numColumns; - WXWidget m_menuWidget; - WXWidget m_popupShell; // For holding the popup shell widget - WXWidget m_buttonWidget; // The actual string, so we can grey it etc. - int m_menuId; - wxMenu* m_topLevelMenu ; - wxMenu* m_menuParent; - bool m_ownedByMenuBar; - wxColour m_foregroundColour; - wxColour m_backgroundColour; - wxFont m_font; +public: + // Motif-specific data + int m_numColumns; + WXWidget m_menuWidget; + WXWidget m_popupShell; // For holding the popup shell widget + WXWidget m_buttonWidget; // The actual string, so we can grey it etc. + int m_menuId; + wxMenu* m_topLevelMenu ; + bool m_ownedByMenuBar; + wxColour m_foregroundColour; + wxColour m_backgroundColour; + wxFont m_font; private: // common code for both constructors: - void Init( const wxString& title, - long style -#ifdef WXWIN_COMPATIBILITY - , const wxFunction func = (wxFunction) NULL -#endif - ); + void Init(); + + DECLARE_DYNAMIC_CLASS(wxMenu) }; // ---------------------------------------------------------------------------- diff --git a/include/wx/motif/menuitem.h b/include/wx/motif/menuitem.h index 75649d9f30..4822d8013c 100644 --- a/include/wx/motif/menuitem.h +++ b/include/wx/motif/menuitem.h @@ -16,11 +16,13 @@ #pragma interface "menuitem.h" #endif +class WXDLLEXPORT wxMenuBar; + // ---------------------------------------------------------------------------- // wxMenuItem: an item in the menu, optionally implements owner-drawn behaviour // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxMenuItem: public wxMenuItemBase +class wxMenuItem : public wxMenuItemBase { public: // ctor & dtor @@ -34,6 +36,7 @@ public: // accessors (some more are inherited from wxOwnerDrawn or are below) virtual void SetText(const wxString& label); + virtual wxString GetLabel() const; virtual void Enable(bool enable = TRUE); virtual void Check(bool check = TRUE); diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index 4e0b3af8eb..7fa4d9f93b 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -59,21 +59,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) // ---------------------------------------------------------------------------- // Construct a menu with optional title (then use append) -void wxMenu::Init(const wxString& title, - long style -#ifdef WXWIN_COMPATIBILITY - , const wxFunction func -#endif - ) +void wxMenu::Init() { - m_title = title; - m_eventHandler = this; - m_noItems = 0; - m_menuBar = NULL; - m_pInvokingWindow = NULL; - m_style = style; - - //// Motif-specific members + // Motif-specific members m_numColumns = 1; m_menuWidget = (WXWidget) NULL; m_popupShell = (WXWidget) NULL; @@ -81,21 +69,16 @@ void wxMenu::Init(const wxString& title, m_menuId = 0; m_topLevelMenu = (wxMenu*) NULL; m_ownedByMenuBar = FALSE; - m_menuParent = (wxMenu*) NULL; - m_clientData = (void*) NULL; - if (m_title != "") + if ( !!m_title ) { - Append(ID_SEPARATOR, m_title) ; + Append(wxID_SEPARATOR, m_title) ; AppendSeparator() ; } + m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU); m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT); m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); - -#ifdef WXWIN_COMPATIBILITY - Callback(func); -#endif } // The wxWindow destructor will take care of deleting the submenus. @@ -115,273 +98,78 @@ wxMenu::~wxMenu() m_menuParent = NULL; // m_menuBar = NULL; } - - wxNode *node = m_menuItems.First(); - while (node) - { - wxMenuItem *item = (wxMenuItem *)node->Data(); - - /* - if (item->GetSubMenu()) - item->DeleteSubMenu(); - */ - - wxNode *next = node->Next(); - delete item; - delete node; - node = next; - } } void wxMenu::Break() { - m_numColumns ++; + m_numColumns++; } // function appends a new item or submenu to the menu -void wxMenu::Append(wxMenuItem *pItem) +bool wxMenu::DoAppend(wxMenuItem *pItem) { - wxCHECK_RET( pItem != NULL, "can't append NULL item to the menu" ); - - m_menuItems.Append(pItem); - if (m_menuWidget) - pItem->CreateItem (m_menuWidget, m_menuBar, m_topLevelMenu); // this is a dynamic Append - - m_noItems++; -} - -void wxMenu::AppendSeparator() -{ - Append(new wxMenuItem(this, ID_SEPARATOR)); -} - -// Pullright item -// N.B.: difference between old and new code. -// Old code stores subMenu in 'children' for later deletion, -// as well as in m_menuItems, whereas we only store it in -// m_menuItems here. What implications does this have? - -void wxMenu::Append(int id, const wxString& label, wxMenu *subMenu, - const wxString& helpString) -{ - Append(new wxMenuItem(this, id, label, helpString, FALSE, subMenu)); - - subMenu->m_topLevelMenu = m_topLevelMenu; -} - -// Ordinary menu item -void wxMenu::Append(int id, const wxString& label, - const wxString& helpString, bool checkable) -{ - // 'checkable' parameter is useless for Windows. - Append(new wxMenuItem(this, id, label, helpString, checkable)); -} - -void wxMenu::Delete(int id) -{ - wxNode *node; - wxMenuItem *item; - int pos; - - for (pos = 0, node = m_menuItems.First(); node; node = node->Next(), pos++) { - item = (wxMenuItem *)node->Data(); - if (item->GetId() == id) - break; + // this is a dynamic Append + pItem->CreateItem(m_menuWidget, m_menuBar, m_topLevelMenu); } - if (!node) - return; - - item->DestroyItem(TRUE); - - // See also old code - don't know if this is needed (seems redundant). - /* - if (item->GetSubMenu()) { - item->subMenu->top_level_menu = item->GetSubMenu(); - item->subMenu->window_parent = NULL; - children->DeleteObject(item->GetSubMenu()); + if ( pItem->IsSubMenu() ) + { + pItem->GetSubMenu()->m_topLevelMenu = m_topLevelMenu; } - */ - - m_menuItems.DeleteNode(node); - delete item; -} - -void wxMenu::Enable(int id, bool flag) -{ - wxMenuItem *item = FindItemForId(id); - wxCHECK_RET( item != NULL, "can't enable non-existing menu item" ); - item->Enable(flag); + return wxMenuBase::DoAppend(pItem); } -bool wxMenu::Enabled(int Id) const +wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) { - wxMenuItem *item = FindItemForId(Id); - wxCHECK( item != NULL, FALSE ); + item->DestroyItem(TRUE); - return item->IsEnabled(); + return wxMenuBase::DoRemove(item); } -void wxMenu::Check(int Id, bool Flag) +bool wxMenu::DoInsert(size_t pos, wxMenuItem *item) { - wxMenuItem *item = FindItemForId(Id); - wxCHECK_RET( item != NULL, "can't get status of non-existing menu item" ); - - item->Check(Flag); -} + if ( !wxMenuBase::DoInsert(pos, item) ) + return FALSE; -bool wxMenu::Checked(int id) const -{ - wxMenuItem *item = FindItemForId(id); - wxCHECK( item != NULL, FALSE ); + wxFAIL_MSG(wxT("not implemented")); - return item->IsChecked(); + return FALSE; } void wxMenu::SetTitle(const wxString& label) { - m_title = label ; + m_title = label; - wxNode *node = m_menuItems.First (); - if (!node) + wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + if ( !node ) return; - wxMenuItem *item = (wxMenuItem *) node->Data (); + wxMenuItem *item = node->GetData (); Widget widget = (Widget) item->GetButtonWidget(); - if (!widget) - return; - - XmString title_str = XmStringCreateSimple ((char*) (const char*) label); - XtVaSetValues (widget, - XmNlabelString, title_str, - NULL); - // TODO: should we delete title_str now? -} - -const wxString wxMenu::GetTitle() const -{ - return m_title; -} - -void wxMenu::SetLabel(int id, const wxString& label) -{ - wxMenuItem *item = FindItemForId(id); - if (item == (wxMenuItem*) NULL) + if ( !widget ) return; - item->SetText(label); + wxXmString title_str(label); + XtVaSetValues(widget, + XmNlabelString, title_str(), + NULL); } -wxString wxMenu::GetLabel(int id) const -{ - wxMenuItem *it = NULL; - WXWidget w = FindMenuItem (id, &it); - if (w) - { - XmString text; - char *s; - XtVaGetValues ((Widget) w, - XmNlabelString, &text, - NULL); - - if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s)) - { - wxString str(s); - XtFree (s); - return str; - } - else - { - XmStringFree (text); - return wxEmptyString; - } - } - else - return wxEmptyString; -} - -// Finds the item id matching the given string, -1 if not found. -int wxMenu::FindItem (const wxString& itemString) const -{ - char buf1[200]; - char buf2[200]; - wxStripMenuCodes ((char *)(const char *)itemString, buf1); - - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) - { - wxMenuItem *item = (wxMenuItem *) node->Data (); - if (item->GetSubMenu()) - { - int ans = item->GetSubMenu()->FindItem(itemString); - if (ans > -1) - return ans; - } - if ( !item->IsSeparator() ) - { - wxStripMenuCodes((char *)item->GetName().c_str(), buf2); - if (strcmp(buf1, buf2) == 0) - return item->GetId(); - } - } - - return -1; -} - -wxMenuItem *wxMenu::FindItemForId(int itemId, wxMenu ** itemMenu) const -{ - if (itemMenu) - *itemMenu = NULL; - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) - { - wxMenuItem *item = (wxMenuItem *) node->Data (); - - if (item->GetId() == itemId) - { - if (itemMenu) - *itemMenu = (wxMenu *) this; - return item; - } - - if (item->GetSubMenu()) - { - wxMenuItem *ans = item->GetSubMenu()->FindItemForId (itemId, itemMenu); - if (ans) - return ans; - } - } - - if (itemMenu) - *itemMenu = NULL; - return NULL; -} - -void wxMenu::SetHelpString(int itemId, const wxString& helpString) -{ - wxMenuItem *item = FindItemForId (itemId); - if (item) - item->SetHelp(helpString); -} - -wxString wxMenu::GetHelpString (int itemId) const -{ - wxMenuItem *item = FindItemForId (itemId); - wxString str(""); - return (item == NULL) ? str : item->GetHelp(); -} - -void wxMenu::ProcessCommand(wxCommandEvent & event) +bool wxMenu::ProcessCommand(wxCommandEvent & event) { bool processed = FALSE; +#if WXWIN_COMPATIBILITY // Try a callback if (m_callback) { (void) (*(m_callback)) (*this, event); processed = TRUE; } +#endif // WXWIN_COMPATIBILITY // Try the menu's event handler if ( !processed && GetEventHandler()) @@ -391,47 +179,9 @@ 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); -} - -// 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(); - } + processed = GetInvokingWindow()->ProcessEvent(event); + + return processed; } // ---------------------------------------------------------------------------- @@ -596,7 +346,7 @@ wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const wxMenuItem *item = NULL; size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) - if ((item = m_menus[i]->FindItemForId (id, itemMenu))) + if ((item = m_menus[i]->FindItem(id, itemMenu))) return item; return NULL; } @@ -691,16 +441,31 @@ int PostDeletionOfMenu( XtPointer* clientData ) XtRemoveWorkProc(WorkProcMenuId); wxMenu *menu = (wxMenu *)clientData; - if (menu->GetMainWidget()) { - if (menu->GetParent()) + if (menu->GetMainWidget()) + { + wxMenu *menuParent = menu->GetParent(); + if ( menuParent ) { - wxList& list = menu->GetParent()->GetItems(); - list.DeleteObject(menu); + wxMenuItemList::Node *node = menuParent->GetMenuItems().GetFirst(); + while ( node ) + { + if ( node->GetData()->GetSubMenu() == menu ) + { + menuParent->GetMenuItems().DeleteNode(node); + + break; + } + + node = node->GetNext(); + } } + menu->DestroyMenu(TRUE); } - /* Mark as no longer popped up */ + + // Mark as no longer popped up menu->m_menuId = -1; + return TRUE; } @@ -774,10 +539,13 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM m_menuBar = menuBar; m_topLevelMenu = topMenu; - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) + for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuItem *item = (wxMenuItem *) node->Data (); - item->CreateItem (menu, menuBar, topMenu); + wxMenuItem *item = node->GetData(); + + item->CreateItem(menu, menuBar, topMenu); } SetBackgroundColour(m_backgroundColour); @@ -792,13 +560,15 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM // do a CreateMenu again. void wxMenu::DestroyMenu (bool full) { - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) + for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuItem *item = (wxMenuItem *) node->Data (); + wxMenuItem *item = node->GetData(); item->SetMenuBar((wxMenuBar*) NULL); item->DestroyItem(full); - }// for() + } if (m_buttonWidget) { @@ -825,9 +595,11 @@ WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const return m_buttonWidget; } - for (wxNode * node = m_menuItems.First (); node; node = node->Next ()) + for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuItem *item = (wxMenuItem *) node->Data (); + wxMenuItem *item = node->GetData (); if (item->GetId() == id) { if (it) @@ -843,7 +615,7 @@ WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const return w; } } - }// for() + } if (it) *it = (wxMenuItem*) NULL; @@ -858,10 +630,11 @@ void wxMenu::SetBackgroundColour(const wxColour& col) if (m_buttonWidget) wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, TRUE); - wxNode* node = m_menuItems.First(); - while (node) + for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuItem* item = (wxMenuItem*) node->Data(); + wxMenuItem* item = node->GetData(); if (item->GetButtonWidget()) { // This crashes because it uses gadgets @@ -869,7 +642,6 @@ void wxMenu::SetBackgroundColour(const wxColour& col) } if (item->GetSubMenu()) item->GetSubMenu()->SetBackgroundColour((wxColour&) col); - node = node->Next(); } } @@ -881,10 +653,11 @@ void wxMenu::SetForegroundColour(const wxColour& col) if (m_buttonWidget) wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col); - wxNode* node = m_menuItems.First(); - while (node) + for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuItem* item = (wxMenuItem*) node->Data(); + wxMenuItem* item = node->GetData(); if (item->GetButtonWidget()) { // This crashes because it uses gadgets @@ -892,7 +665,6 @@ void wxMenu::SetForegroundColour(const wxColour& col) } if (item->GetSubMenu()) item->GetSubMenu()->SetForegroundColour((wxColour&) col); - node = node->Next(); } } @@ -914,10 +686,12 @@ void wxMenu::ChangeFont(bool keepOriginalSize) XmNfontList, fontList, NULL); } - wxNode* node = m_menuItems.First(); - while (node) + + for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + node; + node = node->GetNext() ) { - wxMenuItem* item = (wxMenuItem*) node->Data(); + wxMenuItem* item = node->GetData(); if (m_menuWidget && item->GetButtonWidget() && m_font.Ok()) { XtVaSetValues ((Widget) item->GetButtonWidget(), @@ -926,7 +700,6 @@ void wxMenu::ChangeFont(bool keepOriginalSize) } if (item->GetSubMenu()) item->GetSubMenu()->ChangeFont(keepOriginalSize); - node = node->Next(); } #endif } diff --git a/src/motif/menuitem.cpp b/src/motif/menuitem.cpp index 577cf2f7ab..2bd43ebf94 100644 --- a/src/motif/menuitem.cpp +++ b/src/motif/menuitem.cpp @@ -150,7 +150,29 @@ void wxMenuItem::Check(bool bDoCheck) } } -//// Motif-specific +wxString wxMenuItem::GetLabel() const +{ + return wxStripMenuCodes(m_text); +} + + +// ---------------------------------------------------------------------------- +// wxMenuItemBase +// ---------------------------------------------------------------------------- + +wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, + int id, + const wxString& name, + const wxString& help, + bool isCheckable, + wxMenu *subMenu) +{ + return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu); +} + +// ---------------------------------------------------------------------------- +// Motif-specific +// ---------------------------------------------------------------------------- void wxMenuItem::CreateItem (WXWidget menu, wxMenuBar * menuBar, wxMenu * topMenu) { diff --git a/src/motif/window.cpp b/src/motif/window.cpp index ac82518a24..3dd230e4e3 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -1657,7 +1657,7 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event) // Try for a menu command if (frame->GetMenuBar()) { - wxMenuItem* item = frame->GetMenuBar()->FindItemForId(entry->GetCommand()); + wxMenuItem* item = frame->GetMenuBar()->FindItem(entry->GetCommand()); if (item) { wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, entry->GetCommand()); -- 2.45.2