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 wxMenu::wxMenu(const wxString
& title
, const wxFunction func
)
64 m_parent
= (wxEvtHandler
*) NULL
;
65 m_eventHandler
= this;
69 //// Motif-specific members
71 m_menuWidget
= (WXWidget
) NULL
;
72 m_popupShell
= (WXWidget
) NULL
;
73 m_buttonWidget
= (WXWidget
) NULL
;
75 m_topLevelMenu
= (wxMenu
*) NULL
;
76 m_ownedByMenuBar
= FALSE
;
77 m_menuParent
= (wxMenu
*) NULL
;
78 m_clientData
= (void*) NULL
;
82 Append(ID_SEPARATOR
, m_title
) ;
85 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU
);
86 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT
);
87 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
92 // The wxWindow destructor will take care of deleting the submenus.
103 // Not sure if this is right
104 if (m_menuParent
&& m_menuBar
)
110 wxNode
*node
= m_menuItems
.First();
113 wxMenuItem
*item
= (wxMenuItem
*)node
->Data();
116 if (item->GetSubMenu())
117 item->DeleteSubMenu();
120 wxNode
*next
= node
->Next();
132 // function appends a new item or submenu to the menu
133 void wxMenu::Append(wxMenuItem
*pItem
)
135 wxCHECK_RET( pItem
!= NULL
, "can't append NULL item to the menu" );
137 m_menuItems
.Append(pItem
);
140 pItem
->CreateItem (m_menuWidget
, m_menuBar
, m_topLevelMenu
); // this is a dynamic Append
145 void wxMenu::AppendSeparator()
147 Append(new wxMenuItem(this, ID_SEPARATOR
));
151 // N.B.: difference between old and new code.
152 // Old code stores subMenu in 'children' for later deletion,
153 // as well as in m_menuItems, whereas we only store it in
154 // m_menuItems here. What implications does this have?
156 void wxMenu::Append(int id
, const wxString
& label
, wxMenu
*subMenu
,
157 const wxString
& helpString
)
159 Append(new wxMenuItem(this, id
, label
, helpString
, FALSE
, subMenu
));
161 subMenu
->m_topLevelMenu
= m_topLevelMenu
;
164 // Ordinary menu item
165 void wxMenu::Append(int id
, const wxString
& label
,
166 const wxString
& helpString
, bool checkable
)
168 // 'checkable' parameter is useless for Windows.
169 Append(new wxMenuItem(this, id
, label
, helpString
, checkable
));
172 void wxMenu::Delete(int id
)
178 for (pos
= 0, node
= m_menuItems
.First(); node
; node
= node
->Next(), pos
++)
180 item
= (wxMenuItem
*)node
->Data();
181 if (item
->GetId() == id
)
188 item
->DestroyItem(TRUE
);
190 // See also old code - don't know if this is needed (seems redundant).
192 if (item->GetSubMenu()) {
193 item->subMenu->top_level_menu = item->GetSubMenu();
194 item->subMenu->window_parent = NULL;
195 children->DeleteObject(item->GetSubMenu());
199 m_menuItems
.DeleteNode(node
);
203 void wxMenu::Enable(int id
, bool flag
)
205 wxMenuItem
*item
= FindItemForId(id
);
206 wxCHECK_RET( item
!= NULL
, "can't enable non-existing menu item" );
211 bool wxMenu::Enabled(int Id
) const
213 wxMenuItem
*item
= FindItemForId(Id
);
214 wxCHECK( item
!= NULL
, FALSE
);
216 return item
->IsEnabled();
219 void wxMenu::Check(int Id
, bool Flag
)
221 wxMenuItem
*item
= FindItemForId(Id
);
222 wxCHECK_RET( item
!= NULL
, "can't get status of non-existing menu item" );
227 bool wxMenu::Checked(int id
) const
229 wxMenuItem
*item
= FindItemForId(id
);
230 wxCHECK( item
!= NULL
, FALSE
);
232 return item
->IsChecked();
235 void wxMenu::SetTitle(const wxString
& label
)
239 wxNode
*node
= m_menuItems
.First ();
243 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
244 Widget widget
= (Widget
) item
->GetButtonWidget();
248 XmString title_str
= XmStringCreateSimple ((char*) (const char*) label
);
249 XtVaSetValues (widget
,
250 XmNlabelString
, title_str
,
252 // TODO: should we delete title_str now?
255 const wxString
wxMenu::GetTitle() const
260 void wxMenu::SetLabel(int id
, const wxString
& label
)
262 wxMenuItem
*item
= FindItemForId(id
);
263 if (item
== (wxMenuItem
*) NULL
)
266 item
->SetLabel(label
);
269 wxString
wxMenu::GetLabel(int id
) const
271 wxMenuItem
*it
= NULL
;
272 WXWidget w
= FindMenuItem (id
, &it
);
277 XtVaGetValues ((Widget
) w
,
278 XmNlabelString
, &text
,
281 if (XmStringGetLtoR (text
, XmSTRING_DEFAULT_CHARSET
, &s
))
290 return wxEmptyString
;
294 return wxEmptyString
;
297 // Finds the item id matching the given string, -1 if not found.
298 int wxMenu::FindItem (const wxString
& itemString
) const
302 wxStripMenuCodes ((char *)(const char *)itemString
, buf1
);
304 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
306 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
307 if (item
->GetSubMenu())
309 int ans
= item
->GetSubMenu()->FindItem(itemString
);
313 if ( !item
->IsSeparator() )
315 wxStripMenuCodes((char *)item
->GetName().c_str(), buf2
);
316 if (strcmp(buf1
, buf2
) == 0)
317 return item
->GetId();
324 wxMenuItem
*wxMenu::FindItemForId(int itemId
, wxMenu
** itemMenu
) const
328 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
330 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
332 if (item
->GetId() == itemId
)
335 *itemMenu
= (wxMenu
*) this;
339 if (item
->GetSubMenu())
341 wxMenuItem
*ans
= item
->GetSubMenu()->FindItemForId (itemId
, itemMenu
);
352 void wxMenu::SetHelpString(int itemId
, const wxString
& helpString
)
354 wxMenuItem
*item
= FindItemForId (itemId
);
356 item
->SetHelp(helpString
);
359 wxString
wxMenu::GetHelpString (int itemId
) const
361 wxMenuItem
*item
= FindItemForId (itemId
);
363 return (item
== NULL
) ? str
: item
->GetHelp();
366 void wxMenu::ProcessCommand(wxCommandEvent
& event
)
368 bool processed
= FALSE
;
373 (void) (*(m_callback
)) (*this, event
);
377 // Try the menu's event handler
378 if ( !processed
&& GetEventHandler())
380 processed
= GetEventHandler()->ProcessEvent(event
);
383 // Try the window the menu was popped up from (and up
384 // through the hierarchy)
385 if ( !processed && GetInvokingWindow())
386 processed = GetInvokingWindow()->ProcessEvent(event);
390 bool wxWindow::PopupMenu(wxMenu
*menu
, int x
, int y
)
392 Widget widget
= (Widget
) GetMainWidget();
394 /* The menuId field seems to be usused, so we'll use it to
395 indicate whether a menu is popped up or not:
396 0: Not currently created as a popup
397 -1: Created as a popup, but not active
401 if (menu
->GetParent() && (menu
->GetId() != -1))
404 if (menu
->GetMainWidget()) {
405 menu
->DestroyMenu(TRUE
);
408 wxWindow
*parent
= this;
410 menu
->SetId(1); /* Mark as popped-up */
411 menu
->CreateMenu(NULL
, widget
, menu
);
412 // menu->SetParent(parent);
413 // parent->children->Append(menu); // Store menu for later deletion
415 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
423 if (this->IsKindOf(CLASSINFO(wxCanvas)))
425 wxCanvas *canvas = (wxCanvas *) this;
426 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
427 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
431 Display
*display
= XtDisplay (widget
);
432 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
433 Window thisWindow
= XtWindow (widget
);
435 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
436 &rootX
, &rootY
, &childWindow
);
438 XButtonPressedEvent event
;
439 event
.type
= ButtonPress
;
445 event
.x_root
= rootX
;
446 event
.y_root
= rootY
;
448 XmMenuPosition (menuWidget
, &event
);
449 XtManageChild (menuWidget
);
455 wxMenuBar::wxMenuBar()
457 m_eventHandler
= this;
461 m_menuBarFrame
= NULL
;
462 m_mainWidget
= (WXWidget
) NULL
;
463 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU
);
464 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT
);
465 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
468 wxMenuBar::wxMenuBar(int n
, wxMenu
*menus
[], const wxString titles
[])
470 m_eventHandler
= this;
473 m_titles
= new wxString
[n
];
475 for ( i
= 0; i
< n
; i
++ )
476 m_titles
[i
] = titles
[i
];
477 m_menuBarFrame
= NULL
;
478 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU
);
479 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT
);
480 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
483 wxMenuBar::~wxMenuBar()
486 for (i
= 0; i
< m_menuCount
; i
++)
494 // Must only be used AFTER menu has been attached to frame,
495 // otherwise use individual menus to enable/disable items
496 void wxMenuBar::Enable(int id
, bool flag
)
498 wxMenu
*itemMenu
= NULL
;
499 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
505 void wxMenuBar::EnableTop(int pos
, bool flag
)
510 // Must only be used AFTER menu has been attached to frame,
511 // otherwise use individual menus
512 void wxMenuBar::Check(int id
, bool flag
)
514 wxMenu
*itemMenu
= NULL
;
515 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
519 if (!item
->IsCheckable())
525 bool wxMenuBar::Checked(int id
) const
527 wxMenu
*itemMenu
= NULL
;
528 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
532 return item
->IsChecked();
535 bool wxMenuBar::Enabled(int id
) const
537 wxMenu
*itemMenu
= NULL
;
538 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
542 return item
->IsEnabled();
545 void wxMenuBar::SetLabel(int id
, const wxString
& label
)
547 wxMenu
*itemMenu
= NULL
;
548 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
553 item
->SetLabel(label
);
556 wxString
wxMenuBar::GetLabel(int id
) const
558 wxMenu
*itemMenu
= NULL
;
559 wxMenuItem
*item
= FindItemForId(id
, &itemMenu
) ;
564 return item
->GetLabel();
567 void wxMenuBar::SetLabelTop(int pos
, const wxString
& label
)
569 wxASSERT( (pos
< m_menuCount
) );
571 Widget w
= (Widget
) m_menus
[pos
]->GetButtonWidget();
574 XmString label_str
= XmStringCreateSimple ((char*) (const char*) label
);
576 XmNlabelString
, label_str
,
578 XmStringFree (label_str
);
582 wxString
wxMenuBar::GetLabelTop(int pos
) const
584 wxASSERT( (pos
< m_menuCount
) );
586 Widget w
= (Widget
) m_menus
[pos
]->GetButtonWidget();
592 XmNlabelString
, &text
,
595 if (XmStringGetLtoR (text
, XmSTRING_DEFAULT_CHARSET
, &s
))
603 return wxEmptyString
;
607 return wxEmptyString
;
611 bool wxMenuBar::OnDelete(wxMenu
*menu
, int pos
)
613 // Only applies to dynamic deletion (when set in frame)
617 menu
->DestroyMenu(TRUE
);
621 bool wxMenuBar::OnAppend(wxMenu
*menu
, const char *title
)
623 // Only applies to dynamic append (when set in frame)
627 // Probably should be an assert here
628 if (menu
->GetParent())
631 // Has already been appended
632 if (menu
->GetButtonWidget())
635 WXWidget w
= menu
->CreateMenu(this, GetMainWidget(), menu
, title
, TRUE
);
636 menu
->SetButtonWidget(w
);
641 void wxMenuBar::Append (wxMenu
* menu
, const wxString
& title
)
643 if (!OnAppend(menu
, title
))
647 wxMenu
**new_menus
= new wxMenu
*[m_menuCount
];
648 wxString
*new_titles
= new wxString
[m_menuCount
];
651 for (i
= 0; i
< m_menuCount
- 1; i
++)
653 new_menus
[i
] = m_menus
[i
];
655 new_titles
[i
] = m_titles
[i
];
664 m_titles
= new_titles
;
666 m_menus
[m_menuCount
- 1] = (wxMenu
*)menu
;
667 m_titles
[m_menuCount
- 1] = title
;
669 menu
->SetMenuBar(this);
670 menu
->SetParent(this);
673 void wxMenuBar::Delete(wxMenu
* menu
, int i
)
680 for (ii
= 0; ii
< m_menuCount
; ii
++)
682 if (m_menus
[ii
] == menu
)
685 if (ii
>= m_menuCount
)
689 if (ii
< 0 || ii
>= m_menuCount
)
694 if (!OnDelete(menu
, ii
))
697 menu
->SetParent((wxEvtHandler
*) NULL
);
700 for (j
= ii
; j
< m_menuCount
; j
++)
702 m_menus
[j
] = m_menus
[j
+ 1];
703 m_titles
[j
] = m_titles
[j
+ 1];
707 // Find the menu menuString, item itemString, and return the item id.
708 // Returns -1 if none found.
709 int wxMenuBar::FindMenuItem (const wxString
& menuString
, const wxString
& itemString
) const
713 wxStripMenuCodes ((char *)(const char *)menuString
, buf1
);
715 for (i
= 0; i
< m_menuCount
; i
++)
717 wxStripMenuCodes ((char *)(const char *)m_titles
[i
], buf2
);
718 if (strcmp (buf1
, buf2
) == 0)
719 return m_menus
[i
]->FindItem (itemString
);
724 wxMenuItem
*wxMenuBar::FindItemForId (int id
, wxMenu
** itemMenu
) const
729 wxMenuItem
*item
= NULL
;
731 for (i
= 0; i
< m_menuCount
; i
++)
732 if ((item
= m_menus
[i
]->FindItemForId (id
, itemMenu
)))
737 void wxMenuBar::SetHelpString (int id
, const wxString
& helpString
)
740 for (i
= 0; i
< m_menuCount
; i
++)
742 if (m_menus
[i
]->FindItemForId (id
))
744 m_menus
[i
]->SetHelpString (id
, helpString
);
750 wxString
wxMenuBar::GetHelpString (int id
) const
753 for (i
= 0; i
< m_menuCount
; i
++)
755 if (m_menus
[i
]->FindItemForId (id
))
756 return wxString(m_menus
[i
]->GetHelpString (id
));
762 bool wxMenuBar::CreateMenuBar(wxFrame
* parent
)
766 XtVaSetValues((Widget
) parent
->GetMainWindowWidget(), XmNmenuBar
, (Widget
) m_mainWidget
, NULL
);
768 if (!XtIsManaged((Widget) m_mainWidget))
769 XtManageChild((Widget) m_mainWidget);
771 XtMapWidget((Widget
) m_mainWidget
);
775 Widget menuBarW
= XmCreateMenuBar ((Widget
) parent
->GetMainWindowWidget(), "MenuBar", NULL
, 0);
776 m_mainWidget
= (WXWidget
) menuBarW
;
779 for (i
= 0; i
< GetMenuCount(); i
++)
781 wxMenu
*menu
= GetMenu(i
);
782 wxString
title(m_titles
[i
]);
783 menu
->SetButtonWidget(menu
->CreateMenu (this, menuBarW
, menu
, title
, TRUE
));
786 * COMMENT THIS OUT IF YOU DON'T LIKE A RIGHT-JUSTIFIED HELP MENU
788 wxStripMenuCodes ((char*) (const char*) title
, wxBuffer
);
790 if (strcmp (wxBuffer
, "Help") == 0)
791 XtVaSetValues ((Widget
) menuBarW
, XmNmenuHelpWidget
, (Widget
) menu
->GetButtonWidget(), NULL
);
794 SetBackgroundColour(m_backgroundColour
);
795 SetForegroundColour(m_foregroundColour
);
798 XtVaSetValues((Widget
) parent
->GetMainWindowWidget(), XmNmenuBar
, (Widget
) m_mainWidget
, NULL
);
799 XtRealizeWidget ((Widget
) menuBarW
);
800 XtManageChild ((Widget
) menuBarW
);
801 SetMenuBarFrame(parent
);
806 // Destroy menubar, but keep data structures intact so we can recreate it.
807 bool wxMenuBar::DestroyMenuBar()
811 SetMenuBarFrame((wxFrame
*) NULL
);
815 XtUnmanageChild ((Widget
) m_mainWidget
);
816 XtUnrealizeWidget ((Widget
) m_mainWidget
);
819 for (i
= 0; i
< GetMenuCount(); i
++)
821 wxMenu
*menu
= GetMenu(i
);
822 menu
->DestroyMenu(TRUE
);
825 XtDestroyWidget((Widget
) m_mainWidget
);
826 m_mainWidget
= (WXWidget
) 0;
828 SetMenuBarFrame((wxFrame
*) NULL
);
835 extern wxApp
*wxTheApp
;
836 static XtWorkProcId WorkProcMenuId
;
838 /* Since PopupMenu under Motif stills grab right mouse button events
839 * after it was closed, we need to delete the associated widgets to
840 * allow next PopUpMenu to appear...
843 int PostDeletionOfMenu( XtPointer
* clientData
)
845 XtRemoveWorkProc(WorkProcMenuId
);
846 wxMenu
*menu
= (wxMenu
*)clientData
;
848 if (menu
->GetMainWidget()) {
849 if (menu
->GetParent())
851 wxList
& list
= menu
->GetParent()->GetItems();
852 list
.DeleteObject(menu
);
854 menu
->DestroyMenu(TRUE
);
856 /* Mark as no longer popped up */
862 wxMenuPopdownCallback(Widget w
, XtPointer clientData
,
865 wxMenu
*menu
= (wxMenu
*)clientData
;
867 // Added by JOREL Jean-Charles <jjorel@silr.ireste.fr>
868 /* Since Callbacks of MenuItems are not yet processed, we put a
869 * background job which will be done when system will be idle.
870 * What awful hack!! :(
873 WorkProcMenuId
= XtAppAddWorkProc(
874 (XtAppContext
) wxTheApp
->GetAppContext(),
875 (XtWorkProc
) PostDeletionOfMenu
,
877 // Apparently not found in Motif headers
878 // XtVaSetValues( w, XmNpopupEnabled, XmPOPUP_DISABLED, NULL );
882 * Create a popup or pulldown menu.
883 * Submenus of a popup will be pulldown.
887 WXWidget
wxMenu::CreateMenu (wxMenuBar
* menuBar
, WXWidget parent
, wxMenu
* topMenu
, const wxString
& title
, bool pullDown
)
889 Widget menu
= (Widget
) 0;
890 Widget buttonWidget
= (Widget
) 0;
892 XtSetArg (args
[0], XmNnumColumns
, m_numColumns
);
893 XtSetArg (args
[1], XmNpacking
, XmPACK_COLUMN
);
897 menu
= XmCreatePopupMenu ((Widget
) parent
, "popup", args
, 2);
900 (XtCallbackProc
)wxMenuPopdownCallback
,
905 char mnem
= wxFindMnemonic (title
);
906 wxStripMenuCodes ((char*) (const char*) title
, wxBuffer
);
908 menu
= XmCreatePulldownMenu ((Widget
) parent
, "pulldown", args
, 2);
910 XmString label_str
= XmStringCreateSimple (wxBuffer
);
911 buttonWidget
= XtVaCreateManagedWidget (wxBuffer
,
913 xmCascadeButtonGadgetClass
, (Widget
) parent
,
915 xmCascadeButtonWidgetClass
, (Widget
) parent
,
917 XmNlabelString
, label_str
,
922 XtVaSetValues (buttonWidget
, XmNmnemonic
, mnem
, NULL
);
924 XmStringFree (label_str
);
927 m_menuWidget
= (WXWidget
) menu
;
930 m_topLevelMenu
= topMenu
;
932 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
934 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
935 item
->CreateItem (menu
, menuBar
, topMenu
);
938 SetBackgroundColour(m_backgroundColour
);
939 SetForegroundColour(m_foregroundColour
);
945 // Destroys the Motif implementation of the menu,
946 // but maintains the wxWindows data structures so we can
947 // do a CreateMenu again.
948 void wxMenu::DestroyMenu (bool full
)
950 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
952 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
953 item
->SetMenuBar((wxMenuBar
*) NULL
);
955 item
->DestroyItem(full
);
962 XtVaSetValues((Widget
) m_buttonWidget
, XmNsubMenuId
, NULL
, NULL
);
963 XtDestroyWidget ((Widget
) m_buttonWidget
);
964 m_buttonWidget
= (WXWidget
) 0;
967 if (m_menuWidget
&& full
)
969 XtDestroyWidget((Widget
) m_menuWidget
);
970 m_menuWidget
= (WXWidget
) NULL
;
974 WXWidget
wxMenu::FindMenuItem (int id
, wxMenuItem
** it
) const
979 *it
= (wxMenuItem
*) NULL
;
980 return m_buttonWidget
;
983 for (wxNode
* node
= m_menuItems
.First (); node
; node
= node
->Next ())
985 wxMenuItem
*item
= (wxMenuItem
*) node
->Data ();
986 if (item
->GetId() == id
)
990 return item
->GetButtonWidget();
993 if (item
->GetSubMenu())
995 WXWidget w
= item
->GetSubMenu()->FindMenuItem (id
, it
);
1004 *it
= (wxMenuItem
*) NULL
;
1005 return (WXWidget
) NULL
;
1008 void wxMenu::SetBackgroundColour(const wxColour
& col
)
1010 m_backgroundColour
= col
;
1012 wxDoChangeBackgroundColour(m_menuWidget
, (wxColour
&) col
);
1014 wxDoChangeBackgroundColour(m_buttonWidget
, (wxColour
&) col
, TRUE
);
1016 wxNode
* node
= m_menuItems
.First();
1019 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1020 if (item
->GetButtonWidget())
1022 // This crashes because it uses gadgets
1023 // wxDoChangeBackgroundColour(item->GetButtonWidget(), (wxColour&) col, TRUE);
1025 if (item
->GetSubMenu())
1026 item
->GetSubMenu()->SetBackgroundColour((wxColour
&) col
);
1027 node
= node
->Next();
1031 void wxMenu::SetForegroundColour(const wxColour
& col
)
1033 m_foregroundColour
= col
;
1035 wxDoChangeForegroundColour(m_menuWidget
, (wxColour
&) col
);
1037 wxDoChangeForegroundColour(m_buttonWidget
, (wxColour
&) col
);
1039 wxNode
* node
= m_menuItems
.First();
1042 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1043 if (item
->GetButtonWidget())
1045 // This crashes because it uses gadgets
1046 // wxDoChangeForegroundColour(item->GetButtonWidget(), (wxColour&) col);
1048 if (item
->GetSubMenu())
1049 item
->GetSubMenu()->SetForegroundColour((wxColour
&) col
);
1050 node
= node
->Next();
1054 void wxMenu::ChangeFont(bool keepOriginalSize
)
1056 // lesstif 0.87 hangs when setting XmNfontList
1057 #ifndef LESSTIF_VERSION
1058 if (!m_font
.Ok() || !m_menuWidget
)
1061 XmFontList fontList
= (XmFontList
) m_font
.GetFontList(1.0, XtDisplay((Widget
) m_menuWidget
));
1063 XtVaSetValues ((Widget
) m_menuWidget
,
1064 XmNfontList
, fontList
,
1068 XtVaSetValues ((Widget
) m_buttonWidget
,
1069 XmNfontList
, fontList
,
1072 wxNode
* node
= m_menuItems
.First();
1075 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
1076 if (m_menuWidget
&& item
->GetButtonWidget() && m_font
.Ok())
1078 XtVaSetValues ((Widget
) item
->GetButtonWidget(),
1079 XmNfontList
, fontList
,
1082 if (item
->GetSubMenu())
1083 item
->GetSubMenu()->ChangeFont(keepOriginalSize
);
1084 node
= node
->Next();
1089 void wxMenu::SetFont(const wxFont
& font
)
1095 void wxMenuBar::SetBackgroundColour(const wxColour
& col
)
1098 m_backgroundColour
= col
;
1100 wxDoChangeBackgroundColour(m_mainWidget
, (wxColour
&) col
);
1102 for (i
= 0; i
< m_menuCount
; i
++)
1103 m_menus
[i
]->SetBackgroundColour((wxColour
&) col
);
1106 void wxMenuBar::SetForegroundColour(const wxColour
& col
)
1108 m_foregroundColour
= col
;
1110 wxDoChangeForegroundColour(m_mainWidget
, (wxColour
&) col
);
1113 for (i
= 0; i
< m_menuCount
; i
++)
1114 m_menus
[i
]->SetForegroundColour((wxColour
&) col
);
1117 void wxMenuBar::ChangeFont(bool keepOriginalSize
)
1119 // Nothing to do for menubar, fonts are kept in wxMenus
1122 void wxMenuBar::SetFont(const wxFont
& font
)
1128 for (i
= 0; i
< m_menuCount
; i
++)
1129 m_menus
[i
]->SetFont(font
);