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