1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar, wxMenuItem
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // ============================================================================
14 // headers & declarations
15 // ============================================================================
21 #pragma implementation "menu.h"
22 #pragma implementation "menuitem.h"
26 #include "wx/menuitem.h"
31 #include "wx/settings.h"
34 #include <Xm/LabelG.h>
35 #include <Xm/CascadeBG.h>
36 #include <Xm/CascadeB.h>
37 #include <Xm/SeparatoG.h>
38 #include <Xm/PushBG.h>
39 #include <Xm/ToggleB.h>
40 #include <Xm/ToggleBG.h>
41 #include <Xm/RowColumn.h>
43 #include "wx/motif/private.h"
45 // other standard headers
46 // ----------------------
49 #if !USE_SHARED_LIBRARY
50 IMPLEMENT_DYNAMIC_CLASS(wxMenu
, wxEvtHandler
)
51 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
, wxEvtHandler
)
54 // ============================================================================
56 // ============================================================================
60 // Construct a menu with optional title (then use append)
61 void wxMenu::Init(const wxString
& title
,
63 #ifdef WXWIN_COMPATIBILITY
64 , const wxFunction func
69 m_parent
= (wxEvtHandler
*) NULL
;
70 m_eventHandler
= this;
73 m_pInvokingWindow
= NULL
;
76 //// Motif-specific members
78 m_menuWidget
= (WXWidget
) NULL
;
79 m_popupShell
= (WXWidget
) NULL
;
80 m_buttonWidget
= (WXWidget
) NULL
;
82 m_topLevelMenu
= (wxMenu
*) NULL
;
83 m_ownedByMenuBar
= FALSE
;
84 m_menuParent
= (wxMenu
*) NULL
;
85 m_clientData
= (void*) NULL
;
89 Append(ID_SEPARATOR
, m_title
) ;
92 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU
);
93 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT
);
94 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
96 #ifdef WXWIN_COMPATIBILITY
101 // The wxWindow destructor will take care of deleting the submenus.
112 // Not sure if this is right
113 if (m_menuParent
&& m_menuBar
)
119 wxNode
*node
= m_menuItems
.First();
122 wxMenuItem
*item
= (wxMenuItem
*)node
->Data();
125 if (item->GetSubMenu())
126 item->DeleteSubMenu();
129 wxNode
*next
= node
->Next();
141 // function appends a new item or submenu to the menu
142 void wxMenu::Append(wxMenuItem
*pItem
)
144 wxCHECK_RET( pItem
!= NULL
, "can't append NULL item to the menu" );
146 m_menuItems
.Append(pItem
);
149 pItem
->CreateItem (m_menuWidget
, m_menuBar
, m_topLevelMenu
); // this is a dynamic Append
154 void wxMenu::AppendSeparator()
156 Append(new wxMenuItem(this, ID_SEPARATOR
));
160 // N.B.: difference between old and new code.
161 // Old code stores subMenu in 'children' for later deletion,
162 // as well as in m_menuItems, whereas we only store it in
163 // m_menuItems here. What implications does this have?
165 void wxMenu::Append(int id
, const wxString
& label
, wxMenu
*subMenu
,
166 const wxString
& helpString
)
168 Append(new wxMenuItem(this, id
, label
, helpString
, FALSE
, subMenu
));
170 subMenu
->m_topLevelMenu
= m_topLevelMenu
;
173 // Ordinary menu item
174 void wxMenu::Append(int id
, const wxString
& label
,
175 const wxString
& helpString
, bool checkable
)
177 // 'checkable' parameter is useless for Windows.
178 Append(new wxMenuItem(this, id
, label
, helpString
, checkable
));
181 void wxMenu::Delete(int id
)
187 for (pos
= 0, node
= m_menuItems
.First(); node
; node
= node
->Next(), pos
++)
189 item
= (wxMenuItem
*)node
->Data();
190 if (item
->GetId() == id
)
197 item
->DestroyItem(TRUE
);
199 // See also old code - don't know if this is needed (seems redundant).
201 if (item->GetSubMenu()) {
202 item->subMenu->top_level_menu = item->GetSubMenu();
203 item->subMenu->window_parent = NULL;
204 children->DeleteObject(item->GetSubMenu());
208 m_menuItems
.DeleteNode(node
);
212 void wxMenu::Enable(int id
, bool flag
)
214 wxMenuItem
*item
= FindItemForId(id
);
215 wxCHECK_RET( item
!= NULL
, "can't enable non-existing menu item" );
220 bool wxMenu::Enabled(int Id
) const
222 wxMenuItem
*item
= FindItemForId(Id
);
223 wxCHECK( item
!= NULL
, FALSE
);
225 return item
->IsEnabled();
228 void wxMenu::Check(int Id
, bool Flag
)
230 wxMenuItem
*item
= FindItemForId(Id
);
231 wxCHECK_RET( item
!= NULL
, "can't get status of non-existing menu item" );
236 bool wxMenu::Checked(int id
) const
238 wxMenuItem
*item
= FindItemForId(id
);
239 wxCHECK( item
!= NULL
, FALSE
);
241 return item
->IsChecked();
244 void wxMenu::SetTitle(const wxString
& label
)
248 wxNode
*node
= m_menuItems
.First ();
252 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
253 Widget widget
= (Widget
) item
->GetButtonWidget();
257 XmString title_str
= XmStringCreateSimple ((char*) (const char*) label
);
258 XtVaSetValues (widget
,
259 XmNlabelString
, title_str
,
261 // TODO: should we delete title_str now?
264 const wxString
wxMenu::GetTitle() const
269 void wxMenu::SetLabel(int id
, const wxString
& label
)
271 wxMenuItem
*item
= FindItemForId(id
);
272 if (item
== (wxMenuItem
*) NULL
)
275 item
->SetLabel(label
);
278 wxString
wxMenu::GetLabel(int id
) const
280 wxMenuItem
*it
= NULL
;
281 WXWidget w
= FindMenuItem (id
, &it
);
286 XtVaGetValues ((Widget
) w
,
287 XmNlabelString
, &text
,
290 if (XmStringGetLtoR (text
, XmSTRING_DEFAULT_CHARSET
, &s
))
299 return wxEmptyString
;
303 return wxEmptyString
;
306 // Finds the item id matching the given string, -1 if not found.
307 int wxMenu::FindItem (const wxString
& itemString
) const
311 wxStripMenuCodes ((char *)(const char *)itemString
, buf1
);
313 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
315 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
316 if (item
->GetSubMenu())
318 int ans
= item
->GetSubMenu()->FindItem(itemString
);
322 if ( !item
->IsSeparator() )
324 wxStripMenuCodes((char *)item
->GetName().c_str(), buf2
);
325 if (strcmp(buf1
, buf2
) == 0)
326 return item
->GetId();
333 wxMenuItem
*wxMenu::FindItemForId(int itemId
, wxMenu
** itemMenu
) const
337 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
339 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
341 if (item
->GetId() == itemId
)
344 *itemMenu
= (wxMenu
*) this;
348 if (item
->GetSubMenu())
350 wxMenuItem
*ans
= item
->GetSubMenu()->FindItemForId (itemId
, itemMenu
);
361 void wxMenu::SetHelpString(int itemId
, const wxString
& helpString
)
363 wxMenuItem
*item
= FindItemForId (itemId
);
365 item
->SetHelp(helpString
);
368 wxString
wxMenu::GetHelpString (int itemId
) const
370 wxMenuItem
*item
= FindItemForId (itemId
);
372 return (item
== NULL
) ? str
: item
->GetHelp();
375 void wxMenu::ProcessCommand(wxCommandEvent
& event
)
377 bool processed
= FALSE
;
382 (void) (*(m_callback
)) (*this, event
);
386 // Try the menu's event handler
387 if ( !processed
&& GetEventHandler())
389 processed
= GetEventHandler()->ProcessEvent(event
);
391 // Try the window the menu was popped up from (and up
392 // through the hierarchy)
393 if ( !processed
&& GetInvokingWindow())
394 processed
= GetInvokingWindow()->ProcessEvent(event
);
397 // Update a menu and all submenus recursively.
398 // source is the object that has the update event handlers
399 // defined for it. If NULL, the menu or associated window
401 void wxMenu::UpdateUI(wxEvtHandler
* source
)
403 if (!source
&& GetInvokingWindow())
404 source
= GetInvokingWindow()->GetEventHandler();
406 source
= GetEventHandler();
410 wxNode
* node
= GetItems().First();
413 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
414 if ( !item
->IsSeparator() )
416 wxWindowID id
= item
->GetId();
417 wxUpdateUIEvent
event(id
);
418 event
.SetEventObject( source
);
420 if (source
->ProcessEvent(event
))
422 if (event
.GetSetText())
423 SetLabel(id
, event
.GetText());
424 if (event
.GetSetChecked())
425 Check(id
, event
.GetChecked());
426 if (event
.GetSetEnabled())
427 Enable(id
, event
.GetEnabled());
430 if (item
->GetSubMenu())
431 item
->GetSubMenu()->UpdateUI(source
);
438 wxMenuBar::wxMenuBar()
440 m_eventHandler
= this;
444 m_menuBarFrame
= NULL
;
445 m_mainWidget
= (WXWidget
) NULL
;
446 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU
);
447 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT
);
448 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
451 wxMenuBar::wxMenuBar(long WXUNUSED(style
))
453 m_eventHandler
= this;
457 m_menuBarFrame
= NULL
;
458 m_mainWidget
= (WXWidget
) NULL
;
459 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU
);
460 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT
);
461 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
464 wxMenuBar::wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[])
466 m_eventHandler
= this;
469 m_titles
= new wxString
[n
];
471 for ( i
= 0; i
< n
; i
++ )
472 m_titles
[i
] = titles
[i
];
473 m_menuBarFrame
= NULL
;
474 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU
);
475 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT
);
476 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
479 wxMenuBar::~wxMenuBar()
482 for (i
= 0; i
< m_menuCount
; i
++)
490 // Must only be used AFTER menu has been attached to frame,
491 // otherwise use individual menus to enable/disable items
492 void wxMenuBar::Enable(int id
, bool flag
)
494 wxMenu
*itemMenu
= NULL
;
495 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
501 void wxMenuBar::EnableTop(int pos
, bool flag
)
506 // Must only be used AFTER menu has been attached to frame,
507 // otherwise use individual menus
508 void wxMenuBar::Check(int id
, bool flag
)
510 wxMenu
*itemMenu
= NULL
;
511 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
515 if (!item
->IsCheckable())
521 bool wxMenuBar::Checked(int id
) const
523 wxMenu
*itemMenu
= NULL
;
524 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
528 return item
->IsChecked();
531 bool wxMenuBar::Enabled(int id
) const
533 wxMenu
*itemMenu
= NULL
;
534 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
538 return item
->IsEnabled();
541 void wxMenuBar::SetLabel(int id
, const wxString
& label
)
543 wxMenu
*itemMenu
= NULL
;
544 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
549 item
->SetLabel(label
);
552 wxString
wxMenuBar::GetLabel(int id
) const
554 wxMenu
*itemMenu
= NULL
;
555 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
560 return item
->GetLabel();
563 void wxMenuBar::SetLabelTop(int pos
, const wxString
& label
)
565 wxASSERT( (pos
< m_menuCount
) );
567 Widget w
= (Widget
) m_menus
[pos
]->GetButtonWidget();
570 XmString label_str
= XmStringCreateSimple ((char*) (const char*) label
);
572 XmNlabelString
, label_str
,
574 XmStringFree (label_str
);
578 wxString
wxMenuBar::GetLabelTop(int pos
) const
580 wxASSERT( (pos
< m_menuCount
) );
582 Widget w
= (Widget
) m_menus
[pos
]->GetButtonWidget();
588 XmNlabelString
, &text
,
591 if (XmStringGetLtoR (text
, XmSTRING_DEFAULT_CHARSET
, &s
))
599 return wxEmptyString
;
603 return wxEmptyString
;
607 bool wxMenuBar::OnDelete(wxMenu
*menu
, int pos
)
609 // Only applies to dynamic deletion (when set in frame)
613 menu
->DestroyMenu(TRUE
);
617 bool wxMenuBar::OnAppend(wxMenu
*menu
, const char *title
)
619 // Only applies to dynamic append (when set in frame)
623 // Probably should be an assert here
624 if (menu
->GetParent())
627 // Has already been appended
628 if (menu
->GetButtonWidget())
631 WXWidget w
= menu
->CreateMenu(this, GetMainWidget(), menu
, title
, TRUE
);
632 menu
->SetButtonWidget(w
);
637 void wxMenuBar::Append (wxMenu
* menu
, const wxString
& title
)
639 if (!OnAppend(menu
, title
))
643 wxMenu
**new_menus
= new wxMenu
*[m_menuCount
];
644 wxString
*new_titles
= new wxString
[m_menuCount
];
647 for (i
= 0; i
< m_menuCount
- 1; i
++)
649 new_menus
[i
] = m_menus
[i
];
651 new_titles
[i
] = m_titles
[i
];
660 m_titles
= new_titles
;
662 m_menus
[m_menuCount
- 1] = (wxMenu
*)menu
;
663 m_titles
[m_menuCount
- 1] = title
;
665 menu
->SetMenuBar(this);
666 menu
->SetParent(this);
669 void wxMenuBar::Delete(wxMenu
* menu
, int i
)
676 for (ii
= 0; ii
< m_menuCount
; ii
++)
678 if (m_menus
[ii
] == menu
)
681 if (ii
>= m_menuCount
)
685 if (ii
< 0 || ii
>= m_menuCount
)
690 if (!OnDelete(menu
, ii
))
693 menu
->SetParent((wxEvtHandler
*) NULL
);
696 for (j
= ii
; j
< m_menuCount
; j
++)
698 m_menus
[j
] = m_menus
[j
+ 1];
699 m_titles
[j
] = m_titles
[j
+ 1];
703 // Find the menu menuString, item itemString, and return the item id.
704 // Returns -1 if none found.
705 int wxMenuBar::FindMenuItem (const wxString
& menuString
, const wxString
& itemString
) const
709 wxStripMenuCodes ((char *)(const char *)menuString
, buf1
);
711 for (i
= 0; i
< m_menuCount
; i
++)
713 wxStripMenuCodes ((char *)(const char *)m_titles
[i
], buf2
);
714 if (strcmp (buf1
, buf2
) == 0)
715 return m_menus
[i
]->FindItem (itemString
);
720 wxMenuItem
*wxMenuBar::FindItemForId (int id
, wxMenu
** itemMenu
) const
725 wxMenuItem
*item
= NULL
;
727 for (i
= 0; i
< m_menuCount
; i
++)
728 if ((item
= m_menus
[i
]->FindItemForId (id
, itemMenu
)))
733 void wxMenuBar::SetHelpString (int id
, const wxString
& helpString
)
736 for (i
= 0; i
< m_menuCount
; i
++)
738 if (m_menus
[i
]->FindItemForId (id
))
740 m_menus
[i
]->SetHelpString (id
, helpString
);
746 wxString
wxMenuBar::GetHelpString (int id
) const
749 for (i
= 0; i
< m_menuCount
; i
++)
751 if (m_menus
[i
]->FindItemForId (id
))
752 return wxString(m_menus
[i
]->GetHelpString (id
));
758 bool wxMenuBar::CreateMenuBar(wxFrame
* parent
)
762 XtVaSetValues((Widget
) parent
->GetMainWindowWidget(), XmNmenuBar
, (Widget
) m_mainWidget
, NULL
);
764 if (!XtIsManaged((Widget) m_mainWidget))
765 XtManageChild((Widget) m_mainWidget);
767 XtMapWidget((Widget
) m_mainWidget
);
771 Widget menuBarW
= XmCreateMenuBar ((Widget
) parent
->GetMainWindowWidget(), "MenuBar", NULL
, 0);
772 m_mainWidget
= (WXWidget
) menuBarW
;
775 for (i
= 0; i
< GetMenuCount(); i
++)
777 wxMenu
*menu
= GetMenu(i
);
778 wxString
title(m_titles
[i
]);
779 menu
->SetButtonWidget(menu
->CreateMenu (this, menuBarW
, menu
, title
, TRUE
));
781 wxStripMenuCodes ((char*) (const char*) title
, wxBuffer
);
783 if (strcmp (wxBuffer
, "Help") == 0)
784 XtVaSetValues ((Widget
) menuBarW
, XmNmenuHelpWidget
, (Widget
) menu
->GetButtonWidget(), NULL
);
786 // tear off menu support
787 #if (XmVersion >= 1002)
788 if ( menu
->IsTearOff() )
790 XtVaSetValues(GetWidget(menu
),
791 XmNtearOffModel
, XmTEAR_OFF_ENABLED
,
797 SetBackgroundColour(m_backgroundColour
);
798 SetForegroundColour(m_foregroundColour
);
801 XtVaSetValues((Widget
) parent
->GetMainWindowWidget(), XmNmenuBar
, (Widget
) m_mainWidget
, NULL
);
802 XtRealizeWidget ((Widget
) menuBarW
);
803 XtManageChild ((Widget
) menuBarW
);
804 SetMenuBarFrame(parent
);
809 // Destroy menubar, but keep data structures intact so we can recreate it.
810 bool wxMenuBar::DestroyMenuBar()
814 SetMenuBarFrame((wxFrame
*) NULL
);
818 XtUnmanageChild ((Widget
) m_mainWidget
);
819 XtUnrealizeWidget ((Widget
) m_mainWidget
);
822 for (i
= 0; i
< GetMenuCount(); i
++)
824 wxMenu
*menu
= GetMenu(i
);
825 menu
->DestroyMenu(TRUE
);
828 XtDestroyWidget((Widget
) m_mainWidget
);
829 m_mainWidget
= (WXWidget
) 0;
831 SetMenuBarFrame((wxFrame
*) NULL
);
838 extern wxApp
*wxTheApp
;
839 static XtWorkProcId WorkProcMenuId
;
841 /* Since PopupMenu under Motif stills grab right mouse button events
842 * after it was closed, we need to delete the associated widgets to
843 * allow next PopUpMenu to appear...
846 int PostDeletionOfMenu( XtPointer
* clientData
)
848 XtRemoveWorkProc(WorkProcMenuId
);
849 wxMenu
*menu
= (wxMenu
*)clientData
;
851 if (menu
->GetMainWidget()) {
852 if (menu
->GetParent())
854 wxList
& list
= menu
->GetParent()->GetItems();
855 list
.DeleteObject(menu
);
857 menu
->DestroyMenu(TRUE
);
859 /* Mark as no longer popped up */
865 wxMenuPopdownCallback(Widget w
, XtPointer clientData
,
868 wxMenu
*menu
= (wxMenu
*)clientData
;
870 // Added by JOREL Jean-Charles <jjorel@silr.ireste.fr>
871 /* Since Callbacks of MenuItems are not yet processed, we put a
872 * background job which will be done when system will be idle.
873 * What awful hack!! :(
876 WorkProcMenuId
= XtAppAddWorkProc(
877 (XtAppContext
) wxTheApp
->GetAppContext(),
878 (XtWorkProc
) PostDeletionOfMenu
,
880 // Apparently not found in Motif headers
881 // XtVaSetValues( w, XmNpopupEnabled, XmPOPUP_DISABLED, NULL );
885 * Create a popup or pulldown menu.
886 * Submenus of a popup will be pulldown.
890 WXWidget
wxMenu::CreateMenu (wxMenuBar
* menuBar
, WXWidget parent
, wxMenu
* topMenu
, const wxString
& title
, bool pullDown
)
892 Widget menu
= (Widget
) 0;
893 Widget buttonWidget
= (Widget
) 0;
895 XtSetArg (args
[0], XmNnumColumns
, m_numColumns
);
896 XtSetArg (args
[1], XmNpacking
, XmPACK_COLUMN
);
900 menu
= XmCreatePopupMenu ((Widget
) parent
, "popup", args
, 2);
903 (XtCallbackProc
)wxMenuPopdownCallback
,
908 char mnem
= wxFindMnemonic (title
);
909 wxStripMenuCodes ((char*) (const char*) title
, wxBuffer
);
911 menu
= XmCreatePulldownMenu ((Widget
) parent
, "pulldown", args
, 2);
913 XmString label_str
= XmStringCreateSimple (wxBuffer
);
914 buttonWidget
= XtVaCreateManagedWidget (wxBuffer
,
916 xmCascadeButtonGadgetClass
, (Widget
) parent
,
918 xmCascadeButtonWidgetClass
, (Widget
) parent
,
920 XmNlabelString
, label_str
,
925 XtVaSetValues (buttonWidget
, XmNmnemonic
, mnem
, NULL
);
927 XmStringFree (label_str
);
930 m_menuWidget
= (WXWidget
) menu
;
933 m_topLevelMenu
= topMenu
;
935 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
937 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
938 item
->CreateItem (menu
, menuBar
, topMenu
);
941 SetBackgroundColour(m_backgroundColour
);
942 SetForegroundColour(m_foregroundColour
);
948 // Destroys the Motif implementation of the menu,
949 // but maintains the wxWindows data structures so we can
950 // do a CreateMenu again.
951 void wxMenu::DestroyMenu (bool full
)
953 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
955 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
956 item
->SetMenuBar((wxMenuBar
*) NULL
);
958 item
->DestroyItem(full
);
965 XtVaSetValues((Widget
) m_buttonWidget
, XmNsubMenuId
, NULL
, NULL
);
966 XtDestroyWidget ((Widget
) m_buttonWidget
);
967 m_buttonWidget
= (WXWidget
) 0;
970 if (m_menuWidget
&& full
)
972 XtDestroyWidget((Widget
) m_menuWidget
);
973 m_menuWidget
= (WXWidget
) NULL
;
977 WXWidget
wxMenu::FindMenuItem (int id
, wxMenuItem
** it
) const
982 *it
= (wxMenuItem
*) NULL
;
983 return m_buttonWidget
;
986 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
988 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
989 if (item
->GetId() == id
)
993 return item
->GetButtonWidget();
996 if (item
->GetSubMenu())
998 WXWidget w
= item
->GetSubMenu()->FindMenuItem (id
, it
);
1007 *it
= (wxMenuItem
*) NULL
;
1008 return (WXWidget
) NULL
;
1011 void wxMenu::SetBackgroundColour(const wxColour
& col
)
1013 m_backgroundColour
= col
;
1015 wxDoChangeBackgroundColour(m_menuWidget
, (wxColour
&) col
);
1017 wxDoChangeBackgroundColour(m_buttonWidget
, (wxColour
&) col
, TRUE
);
1019 wxNode
* node
= m_menuItems
.First();
1022 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1023 if (item
->GetButtonWidget())
1025 // This crashes because it uses gadgets
1026 // wxDoChangeBackgroundColour(item->GetButtonWidget(), (wxColour&) col, TRUE);
1028 if (item
->GetSubMenu())
1029 item
->GetSubMenu()->SetBackgroundColour((wxColour
&) col
);
1030 node
= node
->Next();
1034 void wxMenu::SetForegroundColour(const wxColour
& col
)
1036 m_foregroundColour
= col
;
1038 wxDoChangeForegroundColour(m_menuWidget
, (wxColour
&) col
);
1040 wxDoChangeForegroundColour(m_buttonWidget
, (wxColour
&) col
);
1042 wxNode
* node
= m_menuItems
.First();
1045 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1046 if (item
->GetButtonWidget())
1048 // This crashes because it uses gadgets
1049 // wxDoChangeForegroundColour(item->GetButtonWidget(), (wxColour&) col);
1051 if (item
->GetSubMenu())
1052 item
->GetSubMenu()->SetForegroundColour((wxColour
&) col
);
1053 node
= node
->Next();
1057 void wxMenu::ChangeFont(bool keepOriginalSize
)
1059 // lesstif 0.87 hangs when setting XmNfontList
1060 #ifndef LESSTIF_VERSION
1061 if (!m_font
.Ok() || !m_menuWidget
)
1064 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay((Widget
) m_menuWidget
));
1066 XtVaSetValues ((Widget
) m_menuWidget
,
1067 XmNfontList
, fontList
,
1071 XtVaSetValues ((Widget
) m_buttonWidget
,
1072 XmNfontList
, fontList
,
1075 wxNode
* node
= m_menuItems
.First();
1078 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1079 if (m_menuWidget
&& item
->GetButtonWidget() && m_font
.Ok())
1081 XtVaSetValues ((Widget
) item
->GetButtonWidget(),
1082 XmNfontList
, fontList
,
1085 if (item
->GetSubMenu())
1086 item
->GetSubMenu()->ChangeFont(keepOriginalSize
);
1087 node
= node
->Next();
1092 void wxMenu::SetFont(const wxFont
& font
)
1098 void wxMenuBar::SetBackgroundColour(const wxColour
& col
)
1101 m_backgroundColour
= col
;
1103 wxDoChangeBackgroundColour(m_mainWidget
, (wxColour
&) col
);
1105 for (i
= 0; i
< m_menuCount
; i
++)
1106 m_menus
[i
]->SetBackgroundColour((wxColour
&) col
);
1109 void wxMenuBar::SetForegroundColour(const wxColour
& col
)
1111 m_foregroundColour
= col
;
1113 wxDoChangeForegroundColour(m_mainWidget
, (wxColour
&) col
);
1116 for (i
= 0; i
< m_menuCount
; i
++)
1117 m_menus
[i
]->SetForegroundColour((wxColour
&) col
);
1120 void wxMenuBar::ChangeFont(bool keepOriginalSize
)
1122 // Nothing to do for menubar, fonts are kept in wxMenus
1125 void wxMenuBar::SetFont(const wxFont
& font
)
1131 for (i
= 0; i
< m_menuCount
; i
++)
1132 m_menus
[i
]->SetFont(font
);