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