X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1c4f8f8d180afa03110f52eb95f9b083088f5c03..36308e0e02bc392eaf9bdb34dbfec048b0d13c9f:/src/motif/menu.cpp?ds=sidebyside diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index 192264a201..c0ab807012 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -22,6 +22,8 @@ // headers // ---------------------------------------------------------------------------- +#include "wx/defs.h" + #include "wx/menu.h" #include "wx/menuitem.h" #include "wx/log.h" @@ -32,6 +34,8 @@ #ifdef __VMS__ #pragma message disable nosimpint +#define XtDisplay XTDISPLAY +#define XtWindow XTWINDOW #endif #include #include @@ -51,10 +55,8 @@ // other standard headers #include -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) -#endif // ============================================================================ // implementation @@ -82,9 +84,9 @@ void wxMenu::Init() AppendSeparator() ; } - m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU); - m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT); - m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); + m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU); + m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT); + m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); } // The wxWindow destructor will take care of deleting the submenus. @@ -137,10 +139,10 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) bool wxMenu::DoInsert(size_t pos, wxMenuItem *item) { - if ( !wxMenuBase::DoInsert(pos, item) ) - return FALSE; + if ( wxMenuBase::DoInsert(pos, item) ) + return TRUE; - wxFAIL_MSG(wxT("not implemented")); + wxFAIL_MSG(wxT("DoInsert not implemented; or error in wxMenuBase::DoInsert")); return FALSE; } @@ -149,7 +151,7 @@ void wxMenu::SetTitle(const wxString& label) { m_title = label; - wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); if ( !node ) return; @@ -199,9 +201,9 @@ void wxMenuBar::Init() m_eventHandler = this; m_menuBarFrame = NULL; m_mainWidget = (WXWidget) NULL; - m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU); - m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT); - m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); + m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU); + m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT); + m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); } wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[]) @@ -245,8 +247,6 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) wxString wxMenuBar::GetLabelTop(size_t pos) const { - wxString str; - wxMenu *menu = GetMenu(pos); if ( menu ) { @@ -258,17 +258,11 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const XmNlabelString, &text, NULL); - char *s; - if ( XmStringGetLtoR(text, XmSTRING_DEFAULT_CHARSET, &s) ) - { - str = s; - - XtFree(s); - } + return wxXmStringToString( text ); } } - return str; + return wxEmptyString; } bool wxMenuBar::Append(wxMenu * menu, const wxString& title) @@ -284,7 +278,7 @@ bool wxMenuBar::Append(wxMenu * menu, const wxString& title) menu->SetButtonWidget(w); } - menu->SetMenuBar(this); + //menu->SetMenuBar(this); m_titles.Add(title); @@ -304,7 +298,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) { if ( !wxMenuBarBase::Replace(pos, menu, title) ) - return FALSE; + return NULL; wxFAIL_MSG(wxT("TODO")); @@ -322,7 +316,7 @@ wxMenu *wxMenuBar::Remove(size_t pos) menu->SetMenuBar(NULL); - m_titles.Remove(pos); + m_titles.RemoveAt(pos); return menu; } @@ -333,14 +327,14 @@ int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemStr { char buf1[200]; char buf2[200]; - wxStripMenuCodes ((char *)(const char *)menuString, buf1); + wxStripMenuCodes (wxConstCast(menuString.c_str(), char), buf1); size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) { - wxStripMenuCodes ((char *)(const char *)m_titles[i], buf2); + wxStripMenuCodes (wxConstCast(m_titles[i].c_str(), char), buf2); if (strcmp (buf1, buf2) == 0) - return m_menus[i]->FindItem (itemString); + return m_menus.Item(i)->GetData()->FindItem (itemString); } return -1; } @@ -353,7 +347,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]->FindItem(id, itemMenu))) + if ((item = m_menus.Item(i)->GetData()->FindItem(id, itemMenu))) return item; return NULL; } @@ -438,30 +432,23 @@ bool wxMenuBar::DestroyMenuBar() return TRUE; } -//// Motif-specific -static XtWorkProcId WorkProcMenuId; - -/* Since PopupMenu under Motif stills grab right mouse button events -* after it was closed, we need to delete the associated widgets to -* allow next PopUpMenu to appear... -*/ - -int PostDeletionOfMenu( XtPointer* clientData ) +// Since PopupMenu under Motif stills grab right mouse button events +// after it was closed, we need to delete the associated widgets to +// allow next PopUpMenu to appear... +void wxMenu::DestroyWidgetAndDetach() { - XtRemoveWorkProc(WorkProcMenuId); - wxMenu *menu = (wxMenu *)clientData; - - if (menu->GetMainWidget()) + if (GetMainWidget()) { - wxMenu *menuParent = menu->GetParent(); + wxMenu *menuParent = GetParent(); if ( menuParent ) { - wxMenuItemList::Node *node = menuParent->GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = menuParent->GetMenuItems().GetFirst(); while ( node ) { - if ( node->GetData()->GetSubMenu() == menu ) + if ( node->GetData()->GetSubMenu() == this ) { - menuParent->GetMenuItems().DeleteNode(node); + delete node->GetData(); + menuParent->GetMenuItems().Erase(node); break; } @@ -470,33 +457,11 @@ int PostDeletionOfMenu( XtPointer* clientData ) } } - menu->DestroyMenu(TRUE); + DestroyMenu(TRUE); } // Mark as no longer popped up - menu->m_menuId = -1; - - return TRUE; -} - -void -wxMenuPopdownCallback(Widget WXUNUSED(w), XtPointer clientData, - XtPointer WXUNUSED(ptr)) -{ - wxMenu *menu = (wxMenu *)clientData; - - // Added by JOREL Jean-Charles - /* Since Callbacks of MenuItems are not yet processed, we put a - * background job which will be done when system will be idle. - * What awful hack!! :( - */ - - WorkProcMenuId = XtAppAddWorkProc( - (XtAppContext) wxTheApp->GetAppContext(), - (XtWorkProc) PostDeletionOfMenu, - (XtPointer) menu ); - // Apparently not found in Motif headers - // XtVaSetValues( w, XmNpopupEnabled, XmPOPUP_DISABLED, NULL ); + m_menuId = -1; } /* @@ -511,21 +476,21 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM Widget buttonWidget = (Widget) 0; Arg args[5]; XtSetArg (args[0], XmNnumColumns, m_numColumns); - XtSetArg (args[1], XmNpacking, XmPACK_COLUMN); + XtSetArg (args[1], XmNpacking, (m_numColumns > 1) ? XmPACK_COLUMN : XmPACK_TIGHT); if (!pullDown) { menu = XmCreatePopupMenu ((Widget) parent, "popup", args, 2); +#if 0 XtAddCallback(menu, XmNunmapCallback, (XtCallbackProc)wxMenuPopdownCallback, (XtPointer)this); +#endif } else { char mnem = wxFindMnemonic (title); - wxStripMenuCodes ((char*) (const char*) title, wxBuffer); - menu = XmCreatePulldownMenu ((Widget) parent, "pulldown", args, 2); wxString title2(wxStripMenuCodes(title)); @@ -549,7 +514,7 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM m_menuBar = menuBar; m_topLevelMenu = topMenu; - for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { @@ -570,7 +535,7 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM // do a CreateMenu again. void wxMenu::DestroyMenu (bool full) { - for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { @@ -605,7 +570,7 @@ WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const return m_buttonWidget; } - for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { @@ -640,7 +605,7 @@ void wxMenu::SetBackgroundColour(const wxColour& col) if (m_buttonWidget) wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, TRUE); - for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { @@ -663,7 +628,7 @@ void wxMenu::SetForegroundColour(const wxColour& col) if (m_buttonWidget) wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col); - for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { @@ -680,24 +645,24 @@ void wxMenu::SetForegroundColour(const wxColour& col) void wxMenu::ChangeFont(bool keepOriginalSize) { - // lesstif 0.87 hangs when setting XmNfontList -#ifndef LESSTIF_VERSION + // Lesstif 0.87 hangs here, but 0.93 does not +#if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 ) if (!m_font.Ok() || !m_menuWidget) return; - XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_menuWidget)); + WXFontType fontType = m_font.GetFontType(XtDisplay((Widget) m_menuWidget)); XtVaSetValues ((Widget) m_menuWidget, - XmNfontList, fontList, - NULL); + wxFont::GetFontTag(), fontType, + NULL); if (m_buttonWidget) { XtVaSetValues ((Widget) m_buttonWidget, - XmNfontList, fontList, - NULL); + wxFont::GetFontTag(), fontType, + NULL); } - for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { @@ -705,8 +670,8 @@ void wxMenu::ChangeFont(bool keepOriginalSize) if (m_menuWidget && item->GetButtonWidget() && m_font.Ok()) { XtVaSetValues ((Widget) item->GetButtonWidget(), - XmNfontList, fontList, - NULL); + wxFont::GetFontTag(), fontType, + NULL); } if (item->GetSubMenu()) item->GetSubMenu()->ChangeFont(keepOriginalSize); @@ -728,7 +693,7 @@ bool wxMenuBar::SetBackgroundColour(const wxColour& col) size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) - m_menus[i]->SetBackgroundColour((wxColour&) col); + m_menus.Item(i)->GetData()->SetBackgroundColour((wxColour&) col); return TRUE; } @@ -741,7 +706,7 @@ bool wxMenuBar::SetForegroundColour(const wxColour& col) size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) - m_menus[i]->SetForegroundColour((wxColour&) col); + m_menus.Item(i)->GetData()->SetForegroundColour((wxColour&) col); return TRUE; } @@ -758,7 +723,7 @@ bool wxMenuBar::SetFont(const wxFont& font) size_t menuCount = GetMenuCount(); for (size_t i = 0; i < menuCount; i++) - m_menus[i]->SetFont(font); + m_menus.Item(i)->GetData()->SetFont(font); return TRUE; }