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