]> git.saurik.com Git - wxWidgets.git/blame - src/motif/menu.cpp
[ 1509599 ] 'Split pickers page in widgets sample' with more icons and rebaking.
[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
4bb6408c 23#include "wx/menu.h"
e4db172a
WS
24
25#ifndef WX_PRECOMP
26 #include "wx/log.h"
670f9935 27 #include "wx/app.h"
de6185e2 28 #include "wx/utils.h"
76b49cf4 29 #include "wx/frame.h"
9eddec69 30 #include "wx/settings.h"
25466131 31 #include "wx/menuitem.h"
e4db172a
WS
32#endif
33
338dd992
JJ
34#ifdef __VMS__
35#pragma message disable nosimpint
4dff3400
JJ
36#define XtDisplay XTDISPLAY
37#define XtWindow XTWINDOW
338dd992 38#endif
4bb6408c
JS
39#include <Xm/Label.h>
40#include <Xm/LabelG.h>
41#include <Xm/CascadeBG.h>
42#include <Xm/CascadeB.h>
43#include <Xm/SeparatoG.h>
44#include <Xm/PushBG.h>
45#include <Xm/ToggleB.h>
46#include <Xm/ToggleBG.h>
47#include <Xm/RowColumn.h>
338dd992
JJ
48#ifdef __VMS__
49#pragma message enable nosimpint
50#endif
4bb6408c 51
50414e24
JS
52#include "wx/motif/private.h"
53
4bb6408c 54// other standard headers
4bb6408c
JS
55#include <string.h>
56
4bb6408c
JS
57IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
58IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
4bb6408c
JS
59
60// ============================================================================
61// implementation
62// ============================================================================
63
9874b4ee 64// ----------------------------------------------------------------------------
4bb6408c 65// Menus
9874b4ee 66// ----------------------------------------------------------------------------
4bb6408c
JS
67
68// Construct a menu with optional title (then use append)
c71830c3 69void wxMenu::Init()
4bb6408c 70{
c71830c3 71 // Motif-specific members
4bb6408c
JS
72 m_numColumns = 1;
73 m_menuWidget = (WXWidget) NULL;
74 m_popupShell = (WXWidget) NULL;
75 m_buttonWidget = (WXWidget) NULL;
76 m_menuId = 0;
50414e24 77 m_topLevelMenu = (wxMenu*) NULL;
96be256b 78 m_ownedByMenuBar = false;
bf6c2b35 79
12cca26a 80 if ( !m_title.empty() )
4bb6408c 81 {
15b845f2 82 Append(-3, m_title) ;
4bb6408c
JS
83 AppendSeparator() ;
84 }
c71830c3 85
a756f210
VS
86 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
87 m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
88 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
4bb6408c
JS
89}
90
91// The wxWindow destructor will take care of deleting the submenus.
92wxMenu::~wxMenu()
93{
50414e24
JS
94 if (m_menuWidget)
95 {
2d120f83 96 if (m_menuParent)
96be256b 97 DestroyMenu(true);
2d120f83 98 else
96be256b 99 DestroyMenu(false);
50414e24 100 }
bf6c2b35 101
50414e24
JS
102 // Not sure if this is right
103 if (m_menuParent && m_menuBar)
104 {
2d120f83
JS
105 m_menuParent = NULL;
106 // m_menuBar = NULL;
50414e24 107 }
4bb6408c
JS
108}
109
110void wxMenu::Break()
111{
c71830c3 112 m_numColumns++;
4bb6408c
JS
113}
114
115// function appends a new item or submenu to the menu
9add9367 116wxMenuItem* wxMenu::DoAppend(wxMenuItem *pItem)
4bb6408c 117{
51c9a5db 118 return DoInsert(GetMenuItemCount(), pItem);
4bb6408c
JS
119}
120
c71830c3 121wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
4bb6408c 122{
96be256b 123 item->DestroyItem(true);
bf6c2b35 124
c71830c3 125 return wxMenuBase::DoRemove(item);
4bb6408c
JS
126}
127
9add9367 128wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
4bb6408c 129{
51c9a5db
MB
130 if (m_menuWidget)
131 {
132 // this is a dynamic Append
133#ifndef XmNpositionIndex
134 wxCHECK_MSG( pos == GetMenuItemCount(), -1, wxT("insert not implemented"));
135#endif
136 item->CreateItem(m_menuWidget, GetMenuBar(), m_topLevelMenu, pos);
137 }
4bb6408c 138
51c9a5db
MB
139 if ( item->IsSubMenu() )
140 {
141 item->GetSubMenu()->m_topLevelMenu = m_topLevelMenu;
142 }
bf6c2b35 143
355b4d3d 144 return pos == GetMenuItemCount() ? wxMenuBase::DoAppend(item) :
51c9a5db 145 wxMenuBase::DoInsert(pos, item);
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{
51c9a5db
MB
270 return Insert(GetMenuCount(), menu, title);
271}
272
273bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
274{
275 wxCHECK_MSG( pos <= GetMenuCount(), false, wxT("invalid position") );
96be256b
MB
276 wxCHECK_MSG( menu, false, wxT("invalid menu") );
277 wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), false,
9874b4ee 278 wxT("menu already appended") );
bf6c2b35 279
9874b4ee 280 if ( m_menuBarFrame )
50414e24 281 {
51c9a5db
MB
282 WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu,
283 pos, title, true);
96be256b 284 wxCHECK_MSG( w, false, wxT("failed to create menu") );
9874b4ee 285 menu->SetButtonWidget(w);
50414e24 286 }
bf6c2b35 287
51c9a5db 288 m_titles.Insert(title, pos);
bf6c2b35 289
51c9a5db 290 return wxMenuBarBase::Insert(pos, menu, title);
4bb6408c
JS
291}
292
9874b4ee 293wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 294{
9874b4ee 295 if ( !wxMenuBarBase::Replace(pos, menu, title) )
81b29996 296 return NULL;
bf6c2b35 297
9874b4ee 298 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 299
9874b4ee 300 return NULL;
4bb6408c
JS
301}
302
9874b4ee 303wxMenu *wxMenuBar::Remove(size_t pos)
4bb6408c 304{
9874b4ee
VZ
305 wxMenu *menu = wxMenuBarBase::Remove(pos);
306 if ( !menu )
307 return NULL;
bf6c2b35 308
9874b4ee 309 if ( m_menuBarFrame )
96be256b 310 menu->DestroyMenu(true);
bf6c2b35 311
9874b4ee 312 menu->SetMenuBar(NULL);
bf6c2b35 313
ba8c1601 314 m_titles.RemoveAt(pos);
bf6c2b35 315
9874b4ee 316 return menu;
4bb6408c
JS
317}
318
319// Find the menu menuString, item itemString, and return the item id.
320// Returns -1 if none found.
321int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemString) const
322{
323 char buf1[200];
324 char buf2[200];
d3a80c92 325 wxStripMenuCodes (wxConstCast(menuString.c_str(), char), buf1);
9874b4ee
VZ
326
327 size_t menuCount = GetMenuCount();
328 for (size_t i = 0; i < menuCount; i++)
4bb6408c 329 {
d3a80c92 330 wxStripMenuCodes (wxConstCast(m_titles[i].c_str(), char), buf2);
4bb6408c 331 if (strcmp (buf1, buf2) == 0)
ac32ba44 332 return m_menus.Item(i)->GetData()->FindItem (itemString);
4bb6408c
JS
333 }
334 return -1;
335}
336
9874b4ee 337wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const
4bb6408c
JS
338{
339 if (itemMenu)
340 *itemMenu = NULL;
bf6c2b35 341
9874b4ee
VZ
342 size_t menuCount = GetMenuCount();
343 for (size_t i = 0; i < menuCount; i++)
355b4d3d
WS
344 {
345 wxMenuItem *item = m_menus.Item(i)->GetData()->FindItem(id, itemMenu);
346 if (item) return item;
347 }
348
349 return NULL;
4bb6408c
JS
350}
351
621793f4
JS
352// Create menubar
353bool wxMenuBar::CreateMenuBar(wxFrame* parent)
354{
2d120f83 355 if (m_mainWidget)
621793f4 356 {
1c4f8f8d 357 XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
2d120f83
JS
358 /*
359 if (!XtIsManaged((Widget) m_mainWidget))
360 XtManageChild((Widget) m_mainWidget);
361 */
362 XtMapWidget((Widget) m_mainWidget);
96be256b 363 return true;
621793f4 364 }
bf6c2b35 365
f1db433a
VZ
366 Widget menuBarW = XmCreateMenuBar ((Widget) parent->GetMainWidget(),
367 wxMOTIF_STR("MenuBar"), NULL, 0);
2d120f83 368 m_mainWidget = (WXWidget) menuBarW;
bf6c2b35 369
9874b4ee
VZ
370 size_t menuCount = GetMenuCount();
371 for (size_t i = 0; i < menuCount; i++)
2d120f83
JS
372 {
373 wxMenu *menu = GetMenu(i);
374 wxString title(m_titles[i]);
51c9a5db 375 menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, i, title, true));
bf6c2b35 376
31528cd3 377 if (strcmp (wxStripMenuCodes(title), "Help") == 0)
2d120f83 378 XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL);
ee31c392
VZ
379
380 // tear off menu support
381#if (XmVersion >= 1002)
382 if ( menu->IsTearOff() )
383 {
384 XtVaSetValues(GetWidget(menu),
385 XmNtearOffModel, XmTEAR_OFF_ENABLED,
386 NULL);
6adaedf0
JS
387 Widget tearOff = XmGetTearOffControl(GetWidget(menu));
388 wxDoChangeForegroundColour((Widget) tearOff, m_foregroundColour);
96be256b 389 wxDoChangeBackgroundColour((Widget) tearOff, m_backgroundColour, true);
ee31c392
VZ
390#endif
391 }
2d120f83 392 }
bf6c2b35 393
2d120f83
JS
394 SetBackgroundColour(m_backgroundColour);
395 SetForegroundColour(m_foregroundColour);
396 SetFont(m_font);
bf6c2b35 397
1c4f8f8d 398 XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
2d120f83
JS
399 XtRealizeWidget ((Widget) menuBarW);
400 XtManageChild ((Widget) menuBarW);
401 SetMenuBarFrame(parent);
bf6c2b35 402
96be256b 403 return true;
621793f4
JS
404}
405
406// Destroy menubar, but keep data structures intact so we can recreate it.
407bool wxMenuBar::DestroyMenuBar()
408{
2d120f83 409 if (!m_mainWidget)
621793f4 410 {
2d120f83 411 SetMenuBarFrame((wxFrame*) NULL);
96be256b 412 return false;
621793f4 413 }
bf6c2b35 414
2d120f83
JS
415 XtUnmanageChild ((Widget) m_mainWidget);
416 XtUnrealizeWidget ((Widget) m_mainWidget);
bf6c2b35 417
9874b4ee
VZ
418 size_t menuCount = GetMenuCount();
419 for (size_t i = 0; i < menuCount; i++)
2d120f83
JS
420 {
421 wxMenu *menu = GetMenu(i);
96be256b 422 menu->DestroyMenu(true);
bf6c2b35 423
2d120f83
JS
424 }
425 XtDestroyWidget((Widget) m_mainWidget);
426 m_mainWidget = (WXWidget) 0;
bf6c2b35 427
2d120f83 428 SetMenuBarFrame((wxFrame*) NULL);
bf6c2b35 429
96be256b 430 return true;
621793f4
JS
431}
432
7e1bcfa8
MB
433// Since PopupMenu under Motif stills grab right mouse button events
434// after it was closed, we need to delete the associated widgets to
435// allow next PopUpMenu to appear...
436void wxMenu::DestroyWidgetAndDetach()
50414e24 437{
7e1bcfa8 438 if (GetMainWidget())
c71830c3 439 {
7e1bcfa8 440 wxMenu *menuParent = GetParent();
c71830c3 441 if ( menuParent )
2d120f83 442 {
ac32ba44 443 wxMenuItemList::compatibility_iterator node = menuParent->GetMenuItems().GetFirst();
c71830c3
VZ
444 while ( node )
445 {
7e1bcfa8 446 if ( node->GetData()->GetSubMenu() == this )
c71830c3 447 {
ac32ba44
MB
448 delete node->GetData();
449 menuParent->GetMenuItems().Erase(node);
c71830c3
VZ
450
451 break;
452 }
453
454 node = node->GetNext();
455 }
2d120f83 456 }
c71830c3 457
96be256b 458 DestroyMenu(true);
7fe7d506 459 }
c71830c3
VZ
460
461 // Mark as no longer popped up
7e1bcfa8 462 m_menuId = -1;
50414e24
JS
463}
464
465/*
2d120f83
JS
466* Create a popup or pulldown menu.
467* Submenus of a popup will be pulldown.
468*
469*/
50414e24 470
355b4d3d
WS
471WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar,
472 WXWidget parent,
473 wxMenu * topMenu,
474 size_t WXUNUSED(index),
475 const wxString& title,
476 bool pullDown)
50414e24 477{
2d120f83
JS
478 Widget menu = (Widget) 0;
479 Widget buttonWidget = (Widget) 0;
480 Arg args[5];
481 XtSetArg (args[0], XmNnumColumns, m_numColumns);
4464ec9e 482 XtSetArg (args[1], XmNpacking, (m_numColumns > 1) ? XmPACK_COLUMN : XmPACK_TIGHT);
bf6c2b35 483
2d120f83 484 if (!pullDown)
50414e24 485 {
f1db433a 486 menu = XmCreatePopupMenu ((Widget) parent, wxMOTIF_STR("popup"), args, 2);
7e1bcfa8 487#if 0
2d120f83 488 XtAddCallback(menu,
bf6c2b35 489 XmNunmapCallback,
2d120f83
JS
490 (XtCallbackProc)wxMenuPopdownCallback,
491 (XtPointer)this);
7e1bcfa8 492#endif
50414e24 493 }
2d120f83 494 else
50414e24 495 {
2d120f83 496 char mnem = wxFindMnemonic (title);
f1db433a 497 menu = XmCreatePulldownMenu ((Widget) parent, wxMOTIF_STR("pulldown"), args, 2);
bf6c2b35 498
31528cd3
VZ
499 wxString title2(wxStripMenuCodes(title));
500 wxXmString label_str(title2);
501 buttonWidget = XtVaCreateManagedWidget(title2,
47d67540 502#if wxUSE_GADGETS
2d120f83 503 xmCascadeButtonGadgetClass, (Widget) parent,
50414e24 504#else
2d120f83 505 xmCascadeButtonWidgetClass, (Widget) parent,
50414e24 506#endif
193fe989 507 XmNlabelString, label_str(),
2d120f83
JS
508 XmNsubMenuId, menu,
509 NULL);
bf6c2b35 510
2d120f83
JS
511 if (mnem != 0)
512 XtVaSetValues (buttonWidget, XmNmnemonic, mnem, NULL);
50414e24 513 }
bf6c2b35 514
2d120f83 515 m_menuWidget = (WXWidget) menu;
bf6c2b35 516
2d120f83 517 m_topLevelMenu = topMenu;
bf6c2b35 518
51c9a5db 519 size_t i = 0;
ac32ba44 520 for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3 521 node;
51c9a5db 522 node = node->GetNext(), ++i )
50414e24 523 {
c71830c3
VZ
524 wxMenuItem *item = node->GetData();
525
51c9a5db 526 item->CreateItem(menu, menuBar, topMenu, i);
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 681 }
355b4d3d
WS
682#else
683 wxUnusedVar(keepOriginalSize);
94b49b93
JS
684#endif
685}
686
687void wxMenu::SetFont(const wxFont& font)
688{
689 m_font = font;
690 ChangeFont();
691}
692
9874b4ee 693bool wxMenuBar::SetBackgroundColour(const wxColour& col)
94b49b93 694{
94b49b93
JS
695 m_backgroundColour = col;
696 if (m_mainWidget)
2d120f83 697 wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col);
9874b4ee
VZ
698
699 size_t menuCount = GetMenuCount();
700 for (size_t i = 0; i < menuCount; i++)
ac32ba44 701 m_menus.Item(i)->GetData()->SetBackgroundColour((wxColour&) col);
9874b4ee 702
96be256b 703 return true;
94b49b93
JS
704}
705
9874b4ee 706bool wxMenuBar::SetForegroundColour(const wxColour& col)
94b49b93
JS
707{
708 m_foregroundColour = col;
709 if (m_mainWidget)
2d120f83 710 wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col);
bf6c2b35 711
9874b4ee
VZ
712 size_t menuCount = GetMenuCount();
713 for (size_t i = 0; i < menuCount; i++)
ac32ba44 714 m_menus.Item(i)->GetData()->SetForegroundColour((wxColour&) col);
9874b4ee 715
96be256b 716 return true;
94b49b93
JS
717}
718
af111fc3 719void wxMenuBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
94b49b93 720{
2d120f83 721 // Nothing to do for menubar, fonts are kept in wxMenus
94b49b93
JS
722}
723
9874b4ee 724bool wxMenuBar::SetFont(const wxFont& font)
94b49b93
JS
725{
726 m_font = font;
727 ChangeFont();
bf6c2b35 728
9874b4ee
VZ
729 size_t menuCount = GetMenuCount();
730 for (size_t i = 0; i < menuCount; i++)
ac32ba44 731 m_menus.Item(i)->GetData()->SetFont(font);
9874b4ee 732
96be256b 733 return true;
94b49b93 734}