X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e1bcfa80e19ac853b8bc7084075fe3b01e63f03..2461cfa0d9b786a26a783237bca38c920efecb51:/src/motif/menu.cpp diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index 8a42ba4f1d..82cea51b4c 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -14,7 +14,7 @@ // declarations // ============================================================================ -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "menu.h" #endif @@ -22,6 +22,9 @@ // headers // ---------------------------------------------------------------------------- +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + #include "wx/defs.h" #include "wx/menu.h" @@ -80,7 +83,7 @@ void wxMenu::Init() if ( !!m_title ) { - Append(wxID_SEPARATOR, m_title) ; + Append(-3, m_title) ; AppendSeparator() ; } @@ -114,12 +117,12 @@ void wxMenu::Break() } // function appends a new item or submenu to the menu -bool wxMenu::DoAppend(wxMenuItem *pItem) +wxMenuItem* wxMenu::DoAppend(wxMenuItem *pItem) { if (m_menuWidget) { // this is a dynamic Append - pItem->CreateItem(m_menuWidget, m_menuBar, m_topLevelMenu); + pItem->CreateItem(m_menuWidget, GetMenuBar(), m_topLevelMenu); } if ( pItem->IsSubMenu() ) @@ -137,21 +140,21 @@ wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) return wxMenuBase::DoRemove(item); } -bool wxMenu::DoInsert(size_t pos, wxMenuItem *item) +wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item) { if ( wxMenuBase::DoInsert(pos, item) ) - return TRUE; + return item; wxFAIL_MSG(wxT("DoInsert not implemented; or error in wxMenuBase::DoInsert")); - return FALSE; + return NULL; } void wxMenu::SetTitle(const wxString& label) { m_title = label; - wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); if ( !node ) return; @@ -206,6 +209,17 @@ void wxMenuBar::Init() m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); } +wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxArrayString& titles) +{ + wxASSERT( size_t(n) == titles.GetCount() ); + + Init(); + + m_titles = titles; + for ( int i = 0; i < n; i++ ) + m_menus.Append(menus[i]); +} + wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[]) { Init(); @@ -247,8 +261,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 ) { @@ -260,17 +272,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) @@ -286,8 +292,6 @@ bool wxMenuBar::Append(wxMenu * menu, const wxString& title) menu->SetButtonWidget(w); } - //menu->SetMenuBar(this); - m_titles.Add(title); return wxMenuBarBase::Append(menu, title); @@ -324,7 +328,7 @@ wxMenu *wxMenuBar::Remove(size_t pos) menu->SetMenuBar(NULL); - m_titles.Remove(pos); + m_titles.RemoveAt(pos); return menu; } @@ -335,14 +339,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; } @@ -355,7 +359,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; } @@ -450,12 +454,13 @@ void wxMenu::DestroyWidgetAndDetach() wxMenu *menuParent = GetParent(); if ( menuParent ) { - wxMenuItemList::Node *node = menuParent->GetMenuItems().GetFirst(); + wxMenuItemList::compatibility_iterator node = menuParent->GetMenuItems().GetFirst(); while ( node ) { if ( node->GetData()->GetSubMenu() == this ) { - menuParent->GetMenuItems().DeleteNode(node); + delete node->GetData(); + menuParent->GetMenuItems().Erase(node); break; } @@ -518,10 +523,9 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM m_menuWidget = (WXWidget) menu; - m_menuBar = menuBar; m_topLevelMenu = topMenu; - for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); + for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); node; node = node->GetNext() ) { @@ -538,11 +542,11 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topM } // Destroys the Motif implementation of the menu, -// but maintains the wxWindows data structures so we can +// but maintains the wxWidgets data structures so we can // 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() ) { @@ -577,7 +581,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() ) { @@ -612,7 +616,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() ) { @@ -635,7 +639,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() ) { @@ -652,24 +656,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() ) { @@ -677,8 +681,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); @@ -700,7 +704,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; } @@ -713,7 +717,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; } @@ -730,7 +734,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; }