]> git.saurik.com Git - wxWidgets.git/blame - src/motif/menu.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / motif / menu.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: menu.cpp
3// Purpose: wxMenu, wxMenuBar, wxMenuItem
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
bf6c2b35 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
12
13// ============================================================================
9874b4ee 14// declarations
4bb6408c
JS
15// ============================================================================
16
4bb6408c 17#ifdef __GNUG__
9874b4ee 18 #pragma implementation "menu.h"
4bb6408c
JS
19#endif
20
9874b4ee
VZ
21// ----------------------------------------------------------------------------
22// headers
23// ----------------------------------------------------------------------------
24
4bb6408c
JS
25#include "wx/menu.h"
26#include "wx/menuitem.h"
27#include "wx/log.h"
28#include "wx/utils.h"
50414e24
JS
29#include "wx/app.h"
30#include "wx/frame.h"
94b49b93 31#include "wx/settings.h"
4bb6408c
JS
32
33#include <Xm/Label.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>
42
50414e24
JS
43#include "wx/motif/private.h"
44
4bb6408c 45// other standard headers
4bb6408c
JS
46#include <string.h>
47
4bb6408c
JS
48#if !USE_SHARED_LIBRARY
49IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
50IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
51#endif
52
53// ============================================================================
54// implementation
55// ============================================================================
56
9874b4ee 57// ----------------------------------------------------------------------------
4bb6408c 58// Menus
9874b4ee 59// ----------------------------------------------------------------------------
4bb6408c
JS
60
61// Construct a menu with optional title (then use append)
c71830c3 62void wxMenu::Init()
4bb6408c 63{
c71830c3 64 // Motif-specific members
4bb6408c
JS
65 m_numColumns = 1;
66 m_menuWidget = (WXWidget) NULL;
67 m_popupShell = (WXWidget) NULL;
68 m_buttonWidget = (WXWidget) NULL;
69 m_menuId = 0;
50414e24 70 m_topLevelMenu = (wxMenu*) NULL;
4bb6408c 71 m_ownedByMenuBar = FALSE;
bf6c2b35 72
c71830c3 73 if ( !!m_title )
4bb6408c 74 {
c71830c3 75 Append(wxID_SEPARATOR, m_title) ;
4bb6408c
JS
76 AppendSeparator() ;
77 }
c71830c3 78
94b49b93
JS
79 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU);
80 m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT);
81 m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
4bb6408c
JS
82}
83
84// The wxWindow destructor will take care of deleting the submenus.
85wxMenu::~wxMenu()
86{
50414e24
JS
87 if (m_menuWidget)
88 {
2d120f83
JS
89 if (m_menuParent)
90 DestroyMenu(TRUE);
91 else
92 DestroyMenu(FALSE);
50414e24 93 }
bf6c2b35 94
50414e24
JS
95 // Not sure if this is right
96 if (m_menuParent && m_menuBar)
97 {
2d120f83
JS
98 m_menuParent = NULL;
99 // m_menuBar = NULL;
50414e24 100 }
4bb6408c
JS
101}
102
103void wxMenu::Break()
104{
c71830c3 105 m_numColumns++;
4bb6408c
JS
106}
107
108// function appends a new item or submenu to the menu
c71830c3 109bool wxMenu::DoAppend(wxMenuItem *pItem)
4bb6408c 110{
50414e24 111 if (m_menuWidget)
50414e24 112 {
c71830c3
VZ
113 // this is a dynamic Append
114 pItem->CreateItem(m_menuWidget, m_menuBar, m_topLevelMenu);
4bb6408c 115 }
bf6c2b35 116
c71830c3
VZ
117 if ( pItem->IsSubMenu() )
118 {
119 pItem->GetSubMenu()->m_topLevelMenu = m_topLevelMenu;
2d120f83 120 }
bf6c2b35 121
c71830c3 122 return wxMenuBase::DoAppend(pItem);
4bb6408c
JS
123}
124
c71830c3 125wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
4bb6408c 126{
c71830c3 127 item->DestroyItem(TRUE);
bf6c2b35 128
c71830c3 129 return wxMenuBase::DoRemove(item);
4bb6408c
JS
130}
131
c71830c3 132bool wxMenu::DoInsert(size_t pos, wxMenuItem *item)
4bb6408c 133{
c71830c3
VZ
134 if ( !wxMenuBase::DoInsert(pos, item) )
135 return FALSE;
4bb6408c 136
c71830c3 137 wxFAIL_MSG(wxT("not implemented"));
bf6c2b35 138
c71830c3 139 return FALSE;
4bb6408c
JS
140}
141
142void wxMenu::SetTitle(const wxString& label)
143{
c71830c3 144 m_title = label;
bf6c2b35 145
c71830c3
VZ
146 wxMenuItemList::Node *node = GetMenuItems().GetFirst();
147 if ( !node )
2d120f83 148 return;
bf6c2b35 149
c71830c3 150 wxMenuItem *item = node->GetData ();
50414e24 151 Widget widget = (Widget) item->GetButtonWidget();
c71830c3 152 if ( !widget )
2d120f83 153 return;
bf6c2b35 154
c71830c3
VZ
155 wxXmString title_str(label);
156 XtVaSetValues(widget,
157 XmNlabelString, title_str(),
158 NULL);
4bb6408c
JS
159}
160
c71830c3 161bool wxMenu::ProcessCommand(wxCommandEvent & event)
4bb6408c
JS
162{
163 bool processed = FALSE;
bf6c2b35 164
9739d9ee 165#if wxUSE_MENU_CALLBACK
4bb6408c
JS
166 // Try a callback
167 if (m_callback)
168 {
2d120f83
JS
169 (void) (*(m_callback)) (*this, event);
170 processed = TRUE;
4bb6408c 171 }
9739d9ee 172#endif // wxUSE_MENU_CALLBACK
bf6c2b35 173
4bb6408c
JS
174 // Try the menu's event handler
175 if ( !processed && GetEventHandler())
176 {
2d120f83 177 processed = GetEventHandler()->ProcessEvent(event);
4bb6408c 178 }
4bb6408c
JS
179 // Try the window the menu was popped up from (and up
180 // through the hierarchy)
181 if ( !processed && GetInvokingWindow())
c71830c3 182 processed = GetInvokingWindow()->ProcessEvent(event);
631f1bfe 183
c71830c3 184 return processed;
4bb6408c
JS
185}
186
9874b4ee 187// ----------------------------------------------------------------------------
4bb6408c 188// Menu Bar
9874b4ee 189// ----------------------------------------------------------------------------
4bb6408c 190
9874b4ee 191void wxMenuBar::Init()
cba2db0c
JS
192{
193 m_eventHandler = this;
cba2db0c
JS
194 m_menuBarFrame = NULL;
195 m_mainWidget = (WXWidget) NULL;
196 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENU);
197 m_foregroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_MENUTEXT);
198 m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
199}
200
4bb6408c
JS
201wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[])
202{
9874b4ee 203 Init();
4bb6408c 204
9874b4ee 205 for ( int i = 0; i < n; i++ )
4bb6408c 206 {
9874b4ee
VZ
207 m_menus.Append(menus[i]);
208 m_titles.Add(titles[i]);
4bb6408c 209 }
4bb6408c
JS
210}
211
9874b4ee 212wxMenuBar::~wxMenuBar()
4bb6408c 213{
9874b4ee 214 // nothing to do: wxMenuBarBase will delete the menus
4bb6408c
JS
215}
216
9874b4ee 217void wxMenuBar::EnableTop(size_t WXUNUSED(pos), bool WXUNUSED(flag))
4bb6408c 218{
6adaedf0 219 // wxFAIL_MSG("TODO");
23a8562d 220// wxLogWarning("wxMenuBar::EnableTop not yet implemented.");
4bb6408c
JS
221}
222
9874b4ee 223void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
4bb6408c 224{
9874b4ee
VZ
225 wxMenu *menu = GetMenu(pos);
226 if ( !menu )
4bb6408c 227 return;
bf6c2b35 228
9874b4ee
VZ
229 Widget w = (Widget)menu->GetButtonWidget();
230 if (w)
231 {
232 wxXmString label_str(label);
bf6c2b35 233
9874b4ee
VZ
234 XtVaSetValues(w,
235 XmNlabelString, label_str(),
236 NULL);
237 }
4bb6408c
JS
238}
239
9874b4ee 240wxString wxMenuBar::GetLabelTop(size_t pos) const
4bb6408c 241{
9874b4ee 242 wxString str;
bf6c2b35 243
9874b4ee
VZ
244 wxMenu *menu = GetMenu(pos);
245 if ( menu )
246 {
247 Widget w = (Widget)menu->GetButtonWidget();
248 if (w)
249 {
250 XmString text;
251 XtVaGetValues(w,
252 XmNlabelString, &text,
253 NULL);
4bb6408c 254
9874b4ee
VZ
255 char *s;
256 if ( XmStringGetLtoR(text, XmSTRING_DEFAULT_CHARSET, &s) )
257 {
258 str = s;
bf6c2b35 259
9874b4ee
VZ
260 XtFree(s);
261 }
262 }
263 }
bf6c2b35 264
9874b4ee 265 return str;
4bb6408c
JS
266}
267
9874b4ee 268bool wxMenuBar::Append(wxMenu * menu, const wxString& title)
4bb6408c 269{
9874b4ee
VZ
270 wxCHECK_MSG( menu, FALSE, wxT("invalid menu") );
271 wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), FALSE,
272 wxT("menu already appended") );
bf6c2b35 273
9874b4ee 274 if ( m_menuBarFrame )
50414e24 275 {
9874b4ee
VZ
276 WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu, title, TRUE);
277 wxCHECK_MSG( w, FALSE, wxT("failed to create menu") );
278 menu->SetButtonWidget(w);
50414e24 279 }
bf6c2b35 280
9874b4ee 281 menu->SetMenuBar(this);
4bb6408c 282
9874b4ee 283 m_titles.Add(title);
bf6c2b35 284
9874b4ee 285 return wxMenuBarBase::Append(menu, title);
4bb6408c
JS
286}
287
9874b4ee 288bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 289{
9874b4ee 290 if ( !wxMenuBarBase::Insert(pos, menu, title) )
50414e24 291 return FALSE;
bf6c2b35 292
9874b4ee 293 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 294
9874b4ee 295 return FALSE;
4bb6408c
JS
296}
297
9874b4ee 298wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 299{
9874b4ee
VZ
300 if ( !wxMenuBarBase::Replace(pos, menu, title) )
301 return FALSE;
bf6c2b35 302
9874b4ee 303 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 304
9874b4ee 305 return NULL;
4bb6408c
JS
306}
307
9874b4ee 308wxMenu *wxMenuBar::Remove(size_t pos)
4bb6408c 309{
9874b4ee
VZ
310 wxMenu *menu = wxMenuBarBase::Remove(pos);
311 if ( !menu )
312 return NULL;
bf6c2b35 313
9874b4ee
VZ
314 if ( m_menuBarFrame )
315 menu->DestroyMenu(TRUE);
bf6c2b35 316
9874b4ee 317 menu->SetMenuBar(NULL);
bf6c2b35 318
9874b4ee 319 m_titles.Remove(pos);
bf6c2b35 320
9874b4ee 321 return menu;
4bb6408c
JS
322}
323
324// Find the menu menuString, item itemString, and return the item id.
325// Returns -1 if none found.
326int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemString) const
327{
328 char buf1[200];
329 char buf2[200];
330 wxStripMenuCodes ((char *)(const char *)menuString, buf1);
9874b4ee
VZ
331
332 size_t menuCount = GetMenuCount();
333 for (size_t i = 0; i < menuCount; i++)
4bb6408c
JS
334 {
335 wxStripMenuCodes ((char *)(const char *)m_titles[i], buf2);
336 if (strcmp (buf1, buf2) == 0)
337 return m_menus[i]->FindItem (itemString);
338 }
339 return -1;
340}
341
9874b4ee 342wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const
4bb6408c
JS
343{
344 if (itemMenu)
345 *itemMenu = NULL;
bf6c2b35 346
4bb6408c 347 wxMenuItem *item = NULL;
9874b4ee
VZ
348 size_t menuCount = GetMenuCount();
349 for (size_t i = 0; i < menuCount; i++)
c71830c3 350 if ((item = m_menus[i]->FindItem(id, itemMenu)))
4bb6408c 351 return item;
2d120f83 352 return NULL;
4bb6408c
JS
353}
354
621793f4
JS
355// Create menubar
356bool wxMenuBar::CreateMenuBar(wxFrame* parent)
357{
2d120f83 358 if (m_mainWidget)
621793f4 359 {
2d120f83
JS
360 XtVaSetValues((Widget) parent->GetMainWindowWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
361 /*
362 if (!XtIsManaged((Widget) m_mainWidget))
363 XtManageChild((Widget) m_mainWidget);
364 */
365 XtMapWidget((Widget) m_mainWidget);
366 return TRUE;
621793f4 367 }
bf6c2b35 368
2d120f83
JS
369 Widget menuBarW = XmCreateMenuBar ((Widget) parent->GetMainWindowWidget(), "MenuBar", NULL, 0);
370 m_mainWidget = (WXWidget) menuBarW;
bf6c2b35 371
9874b4ee
VZ
372 size_t menuCount = GetMenuCount();
373 for (size_t i = 0; i < menuCount; i++)
2d120f83
JS
374 {
375 wxMenu *menu = GetMenu(i);
376 wxString title(m_titles[i]);
377 menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, title, TRUE));
bf6c2b35 378
31528cd3 379 if (strcmp (wxStripMenuCodes(title), "Help") == 0)
2d120f83 380 XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL);
ee31c392
VZ
381
382 // tear off menu support
383#if (XmVersion >= 1002)
384 if ( menu->IsTearOff() )
385 {
386 XtVaSetValues(GetWidget(menu),
387 XmNtearOffModel, XmTEAR_OFF_ENABLED,
388 NULL);
6adaedf0
JS
389 Widget tearOff = XmGetTearOffControl(GetWidget(menu));
390 wxDoChangeForegroundColour((Widget) tearOff, m_foregroundColour);
391 wxDoChangeBackgroundColour((Widget) tearOff, m_backgroundColour, TRUE);
ee31c392
VZ
392#endif
393 }
2d120f83 394 }
bf6c2b35 395
2d120f83
JS
396 SetBackgroundColour(m_backgroundColour);
397 SetForegroundColour(m_foregroundColour);
398 SetFont(m_font);
bf6c2b35 399
2d120f83
JS
400 XtVaSetValues((Widget) parent->GetMainWindowWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
401 XtRealizeWidget ((Widget) menuBarW);
402 XtManageChild ((Widget) menuBarW);
403 SetMenuBarFrame(parent);
bf6c2b35 404
2d120f83 405 return TRUE;
621793f4
JS
406}
407
408// Destroy menubar, but keep data structures intact so we can recreate it.
409bool wxMenuBar::DestroyMenuBar()
410{
2d120f83 411 if (!m_mainWidget)
621793f4 412 {
2d120f83
JS
413 SetMenuBarFrame((wxFrame*) NULL);
414 return FALSE;
621793f4 415 }
bf6c2b35 416
2d120f83
JS
417 XtUnmanageChild ((Widget) m_mainWidget);
418 XtUnrealizeWidget ((Widget) m_mainWidget);
bf6c2b35 419
9874b4ee
VZ
420 size_t menuCount = GetMenuCount();
421 for (size_t i = 0; i < menuCount; i++)
2d120f83
JS
422 {
423 wxMenu *menu = GetMenu(i);
424 menu->DestroyMenu(TRUE);
bf6c2b35 425
2d120f83
JS
426 }
427 XtDestroyWidget((Widget) m_mainWidget);
428 m_mainWidget = (WXWidget) 0;
bf6c2b35 429
2d120f83 430 SetMenuBarFrame((wxFrame*) NULL);
bf6c2b35 431
2d120f83 432 return TRUE;
621793f4
JS
433}
434
50414e24 435//// Motif-specific
50414e24
JS
436static XtWorkProcId WorkProcMenuId;
437
438/* Since PopupMenu under Motif stills grab right mouse button events
2d120f83
JS
439* after it was closed, we need to delete the associated widgets to
440* allow next PopUpMenu to appear...
441*/
50414e24
JS
442
443int PostDeletionOfMenu( XtPointer* clientData )
444{
2d120f83
JS
445 XtRemoveWorkProc(WorkProcMenuId);
446 wxMenu *menu = (wxMenu *)clientData;
bf6c2b35 447
c71830c3
VZ
448 if (menu->GetMainWidget())
449 {
450 wxMenu *menuParent = menu->GetParent();
451 if ( menuParent )
2d120f83 452 {
c71830c3
VZ
453 wxMenuItemList::Node *node = menuParent->GetMenuItems().GetFirst();
454 while ( node )
455 {
456 if ( node->GetData()->GetSubMenu() == menu )
457 {
458 menuParent->GetMenuItems().DeleteNode(node);
459
460 break;
461 }
462
463 node = node->GetNext();
464 }
2d120f83 465 }
c71830c3 466
2d120f83 467 menu->DestroyMenu(TRUE);
7fe7d506 468 }
c71830c3
VZ
469
470 // Mark as no longer popped up
2d120f83 471 menu->m_menuId = -1;
c71830c3 472
2d120f83 473 return TRUE;
50414e24
JS
474}
475
bf6c2b35 476void
af111fc3
JS
477wxMenuPopdownCallback(Widget WXUNUSED(w), XtPointer clientData,
478 XtPointer WXUNUSED(ptr))
50414e24 479{
2d120f83 480 wxMenu *menu = (wxMenu *)clientData;
bf6c2b35 481
2d120f83
JS
482 // Added by JOREL Jean-Charles <jjorel@silr.ireste.fr>
483 /* Since Callbacks of MenuItems are not yet processed, we put a
484 * background job which will be done when system will be idle.
485 * What awful hack!! :(
486 */
bf6c2b35
VZ
487
488 WorkProcMenuId = XtAppAddWorkProc(
489 (XtAppContext) wxTheApp->GetAppContext(),
2d120f83
JS
490 (XtWorkProc) PostDeletionOfMenu,
491 (XtPointer) menu );
492 // Apparently not found in Motif headers
493 // XtVaSetValues( w, XmNpopupEnabled, XmPOPUP_DISABLED, NULL );
50414e24
JS
494}
495
496/*
2d120f83
JS
497* Create a popup or pulldown menu.
498* Submenus of a popup will be pulldown.
499*
500*/
50414e24
JS
501
502WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topMenu, const wxString& title, bool pullDown)
503{
2d120f83
JS
504 Widget menu = (Widget) 0;
505 Widget buttonWidget = (Widget) 0;
506 Arg args[5];
507 XtSetArg (args[0], XmNnumColumns, m_numColumns);
508 XtSetArg (args[1], XmNpacking, XmPACK_COLUMN);
bf6c2b35 509
2d120f83 510 if (!pullDown)
50414e24 511 {
2d120f83
JS
512 menu = XmCreatePopupMenu ((Widget) parent, "popup", args, 2);
513 XtAddCallback(menu,
bf6c2b35 514 XmNunmapCallback,
2d120f83
JS
515 (XtCallbackProc)wxMenuPopdownCallback,
516 (XtPointer)this);
50414e24 517 }
2d120f83 518 else
50414e24 519 {
2d120f83
JS
520 char mnem = wxFindMnemonic (title);
521 wxStripMenuCodes ((char*) (const char*) title, wxBuffer);
bf6c2b35 522
2d120f83 523 menu = XmCreatePulldownMenu ((Widget) parent, "pulldown", args, 2);
bf6c2b35 524
31528cd3
VZ
525 wxString title2(wxStripMenuCodes(title));
526 wxXmString label_str(title2);
527 buttonWidget = XtVaCreateManagedWidget(title2,
47d67540 528#if wxUSE_GADGETS
2d120f83 529 xmCascadeButtonGadgetClass, (Widget) parent,
50414e24 530#else
2d120f83 531 xmCascadeButtonWidgetClass, (Widget) parent,
50414e24 532#endif
193fe989 533 XmNlabelString, label_str(),
2d120f83
JS
534 XmNsubMenuId, menu,
535 NULL);
bf6c2b35 536
2d120f83
JS
537 if (mnem != 0)
538 XtVaSetValues (buttonWidget, XmNmnemonic, mnem, NULL);
50414e24 539 }
bf6c2b35 540
2d120f83 541 m_menuWidget = (WXWidget) menu;
bf6c2b35 542
2d120f83
JS
543 m_menuBar = menuBar;
544 m_topLevelMenu = topMenu;
bf6c2b35 545
c71830c3
VZ
546 for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
547 node;
548 node = node->GetNext() )
50414e24 549 {
c71830c3
VZ
550 wxMenuItem *item = node->GetData();
551
552 item->CreateItem(menu, menuBar, topMenu);
50414e24 553 }
bf6c2b35 554
2d120f83
JS
555 SetBackgroundColour(m_backgroundColour);
556 SetForegroundColour(m_foregroundColour);
557 SetFont(m_font);
bf6c2b35 558
2d120f83 559 return buttonWidget;
50414e24
JS
560}
561
562// Destroys the Motif implementation of the menu,
563// but maintains the wxWindows data structures so we can
bf6c2b35 564// do a CreateMenu again.
50414e24
JS
565void wxMenu::DestroyMenu (bool full)
566{
c71830c3
VZ
567 for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
568 node;
569 node = node->GetNext() )
50414e24 570 {
c71830c3 571 wxMenuItem *item = node->GetData();
2d120f83 572 item->SetMenuBar((wxMenuBar*) NULL);
bf6c2b35 573
2d120f83 574 item->DestroyItem(full);
c71830c3 575 }
bf6c2b35 576
2d120f83 577 if (m_buttonWidget)
50414e24 578 {
2d120f83
JS
579 if (full)
580 {
581 XtVaSetValues((Widget) m_buttonWidget, XmNsubMenuId, NULL, NULL);
582 XtDestroyWidget ((Widget) m_buttonWidget);
583 m_buttonWidget = (WXWidget) 0;
584 }
50414e24 585 }
2d120f83 586 if (m_menuWidget && full)
50414e24 587 {
2d120f83
JS
588 XtDestroyWidget((Widget) m_menuWidget);
589 m_menuWidget = (WXWidget) NULL;
50414e24
JS
590 }
591}
592
593WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const
594{
2d120f83 595 if (id == m_menuId)
50414e24 596 {
2d120f83
JS
597 if (it)
598 *it = (wxMenuItem*) NULL;
599 return m_buttonWidget;
50414e24 600 }
bf6c2b35 601
c71830c3
VZ
602 for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
603 node;
604 node = node->GetNext() )
50414e24 605 {
c71830c3 606 wxMenuItem *item = node->GetData ();
2d120f83
JS
607 if (item->GetId() == id)
608 {
609 if (it)
610 *it = item;
611 return item->GetButtonWidget();
612 }
bf6c2b35 613
2d120f83
JS
614 if (item->GetSubMenu())
615 {
616 WXWidget w = item->GetSubMenu()->FindMenuItem (id, it);
617 if (w)
618 {
619 return w;
620 }
621 }
c71830c3 622 }
bf6c2b35 623
2d120f83
JS
624 if (it)
625 *it = (wxMenuItem*) NULL;
626 return (WXWidget) NULL;
50414e24 627}
94b49b93
JS
628
629void wxMenu::SetBackgroundColour(const wxColour& col)
630{
631 m_backgroundColour = col;
632 if (m_menuWidget)
2d120f83 633 wxDoChangeBackgroundColour(m_menuWidget, (wxColour&) col);
94b49b93 634 if (m_buttonWidget)
2d120f83 635 wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, TRUE);
bf6c2b35 636
c71830c3
VZ
637 for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
638 node;
639 node = node->GetNext() )
94b49b93 640 {
c71830c3 641 wxMenuItem* item = node->GetData();
94b49b93
JS
642 if (item->GetButtonWidget())
643 {
2d120f83
JS
644 // This crashes because it uses gadgets
645 // wxDoChangeBackgroundColour(item->GetButtonWidget(), (wxColour&) col, TRUE);
94b49b93
JS
646 }
647 if (item->GetSubMenu())
2d120f83 648 item->GetSubMenu()->SetBackgroundColour((wxColour&) col);
94b49b93
JS
649 }
650}
651
652void wxMenu::SetForegroundColour(const wxColour& col)
653{
654 m_foregroundColour = col;
655 if (m_menuWidget)
2d120f83 656 wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col);
94b49b93 657 if (m_buttonWidget)
2d120f83 658 wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col);
bf6c2b35 659
c71830c3
VZ
660 for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
661 node;
662 node = node->GetNext() )
94b49b93 663 {
c71830c3 664 wxMenuItem* item = node->GetData();
94b49b93
JS
665 if (item->GetButtonWidget())
666 {
2d120f83
JS
667 // This crashes because it uses gadgets
668 // wxDoChangeForegroundColour(item->GetButtonWidget(), (wxColour&) col);
94b49b93
JS
669 }
670 if (item->GetSubMenu())
2d120f83 671 item->GetSubMenu()->SetForegroundColour((wxColour&) col);
94b49b93
JS
672 }
673}
674
675void wxMenu::ChangeFont(bool keepOriginalSize)
676{
2d120f83 677 // lesstif 0.87 hangs when setting XmNfontList
bf6c2b35 678#ifndef LESSTIF_VERSION
94b49b93
JS
679 if (!m_font.Ok() || !m_menuWidget)
680 return;
bf6c2b35 681
94b49b93 682 XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_menuWidget));
bf6c2b35 683
94b49b93 684 XtVaSetValues ((Widget) m_menuWidget,
2d120f83
JS
685 XmNfontList, fontList,
686 NULL);
94b49b93
JS
687 if (m_buttonWidget)
688 {
2d120f83
JS
689 XtVaSetValues ((Widget) m_buttonWidget,
690 XmNfontList, fontList,
691 NULL);
94b49b93 692 }
c71830c3
VZ
693
694 for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
695 node;
696 node = node->GetNext() )
94b49b93 697 {
c71830c3 698 wxMenuItem* item = node->GetData();
94b49b93
JS
699 if (m_menuWidget && item->GetButtonWidget() && m_font.Ok())
700 {
2d120f83
JS
701 XtVaSetValues ((Widget) item->GetButtonWidget(),
702 XmNfontList, fontList,
703 NULL);
94b49b93
JS
704 }
705 if (item->GetSubMenu())
2d120f83 706 item->GetSubMenu()->ChangeFont(keepOriginalSize);
94b49b93
JS
707 }
708#endif
709}
710
711void wxMenu::SetFont(const wxFont& font)
712{
713 m_font = font;
714 ChangeFont();
715}
716
9874b4ee 717bool wxMenuBar::SetBackgroundColour(const wxColour& col)
94b49b93 718{
94b49b93
JS
719 m_backgroundColour = col;
720 if (m_mainWidget)
2d120f83 721 wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col);
9874b4ee
VZ
722
723 size_t menuCount = GetMenuCount();
724 for (size_t i = 0; i < menuCount; i++)
2d120f83 725 m_menus[i]->SetBackgroundColour((wxColour&) col);
9874b4ee
VZ
726
727 return TRUE;
94b49b93
JS
728}
729
9874b4ee 730bool wxMenuBar::SetForegroundColour(const wxColour& col)
94b49b93
JS
731{
732 m_foregroundColour = col;
733 if (m_mainWidget)
2d120f83 734 wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col);
bf6c2b35 735
9874b4ee
VZ
736 size_t menuCount = GetMenuCount();
737 for (size_t i = 0; i < menuCount; i++)
2d120f83 738 m_menus[i]->SetForegroundColour((wxColour&) col);
9874b4ee
VZ
739
740 return TRUE;
94b49b93
JS
741}
742
af111fc3 743void wxMenuBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
94b49b93 744{
2d120f83 745 // Nothing to do for menubar, fonts are kept in wxMenus
94b49b93
JS
746}
747
9874b4ee 748bool wxMenuBar::SetFont(const wxFont& font)
94b49b93
JS
749{
750 m_font = font;
751 ChangeFont();
bf6c2b35 752
9874b4ee
VZ
753 size_t menuCount = GetMenuCount();
754 for (size_t i = 0; i < menuCount; i++)
2d120f83 755 m_menus[i]->SetFont(font);
9874b4ee
VZ
756
757 return TRUE;
94b49b93
JS
758}
759