]> git.saurik.com Git - wxWidgets.git/blame - src/motif/menu.cpp
build fix
[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"
e4db172a
WS
31#endif
32
4bb6408c 33#include "wx/menuitem.h"
4bb6408c 34
338dd992
JJ
35#ifdef __VMS__
36#pragma message disable nosimpint
4dff3400
JJ
37#define XtDisplay XTDISPLAY
38#define XtWindow XTWINDOW
338dd992 39#endif
4bb6408c
JS
40#include <Xm/Label.h>
41#include <Xm/LabelG.h>
42#include <Xm/CascadeBG.h>
43#include <Xm/CascadeB.h>
44#include <Xm/SeparatoG.h>
45#include <Xm/PushBG.h>
46#include <Xm/ToggleB.h>
47#include <Xm/ToggleBG.h>
48#include <Xm/RowColumn.h>
338dd992
JJ
49#ifdef __VMS__
50#pragma message enable nosimpint
51#endif
4bb6408c 52
50414e24
JS
53#include "wx/motif/private.h"
54
4bb6408c 55// other standard headers
4bb6408c
JS
56#include <string.h>
57
4bb6408c
JS
58IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler)
59IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler)
4bb6408c
JS
60
61// ============================================================================
62// implementation
63// ============================================================================
64
9874b4ee 65// ----------------------------------------------------------------------------
4bb6408c 66// Menus
9874b4ee 67// ----------------------------------------------------------------------------
4bb6408c
JS
68
69// Construct a menu with optional title (then use append)
c71830c3 70void wxMenu::Init()
4bb6408c 71{
c71830c3 72 // Motif-specific members
4bb6408c
JS
73 m_numColumns = 1;
74 m_menuWidget = (WXWidget) NULL;
75 m_popupShell = (WXWidget) NULL;
76 m_buttonWidget = (WXWidget) NULL;
77 m_menuId = 0;
50414e24 78 m_topLevelMenu = (wxMenu*) NULL;
96be256b 79 m_ownedByMenuBar = false;
bf6c2b35 80
12cca26a 81 if ( !m_title.empty() )
4bb6408c 82 {
15b845f2 83 Append(-3, m_title) ;
4bb6408c
JS
84 AppendSeparator() ;
85 }
c71830c3 86
a756f210
VS
87 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
88 m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
89 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
4bb6408c
JS
90}
91
92// The wxWindow destructor will take care of deleting the submenus.
93wxMenu::~wxMenu()
94{
50414e24
JS
95 if (m_menuWidget)
96 {
2d120f83 97 if (m_menuParent)
96be256b 98 DestroyMenu(true);
2d120f83 99 else
96be256b 100 DestroyMenu(false);
50414e24 101 }
bf6c2b35 102
50414e24
JS
103 // Not sure if this is right
104 if (m_menuParent && m_menuBar)
105 {
2d120f83
JS
106 m_menuParent = NULL;
107 // m_menuBar = NULL;
50414e24 108 }
4bb6408c
JS
109}
110
111void wxMenu::Break()
112{
c71830c3 113 m_numColumns++;
4bb6408c
JS
114}
115
116// function appends a new item or submenu to the menu
9add9367 117wxMenuItem* wxMenu::DoAppend(wxMenuItem *pItem)
4bb6408c 118{
51c9a5db 119 return DoInsert(GetMenuItemCount(), pItem);
4bb6408c
JS
120}
121
c71830c3 122wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
4bb6408c 123{
96be256b 124 item->DestroyItem(true);
bf6c2b35 125
c71830c3 126 return wxMenuBase::DoRemove(item);
4bb6408c
JS
127}
128
9add9367 129wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
4bb6408c 130{
51c9a5db
MB
131 if (m_menuWidget)
132 {
133 // this is a dynamic Append
134#ifndef XmNpositionIndex
135 wxCHECK_MSG( pos == GetMenuItemCount(), -1, wxT("insert not implemented"));
136#endif
137 item->CreateItem(m_menuWidget, GetMenuBar(), m_topLevelMenu, pos);
138 }
4bb6408c 139
51c9a5db
MB
140 if ( item->IsSubMenu() )
141 {
142 item->GetSubMenu()->m_topLevelMenu = m_topLevelMenu;
143 }
bf6c2b35 144
355b4d3d 145 return pos == GetMenuItemCount() ? wxMenuBase::DoAppend(item) :
51c9a5db 146 wxMenuBase::DoInsert(pos, item);
4bb6408c
JS
147}
148
149void wxMenu::SetTitle(const wxString& label)
150{
c71830c3 151 m_title = label;
bf6c2b35 152
ac32ba44 153 wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3 154 if ( !node )
2d120f83 155 return;
bf6c2b35 156
c71830c3 157 wxMenuItem *item = node->GetData ();
50414e24 158 Widget widget = (Widget) item->GetButtonWidget();
c71830c3 159 if ( !widget )
2d120f83 160 return;
bf6c2b35 161
c71830c3
VZ
162 wxXmString title_str(label);
163 XtVaSetValues(widget,
164 XmNlabelString, title_str(),
165 NULL);
4bb6408c
JS
166}
167
c71830c3 168bool wxMenu::ProcessCommand(wxCommandEvent & event)
4bb6408c 169{
96be256b 170 bool processed = false;
bf6c2b35 171
4bb6408c
JS
172 // Try the menu's event handler
173 if ( !processed && GetEventHandler())
174 {
2d120f83 175 processed = GetEventHandler()->ProcessEvent(event);
4bb6408c 176 }
4bb6408c
JS
177 // Try the window the menu was popped up from (and up
178 // through the hierarchy)
179 if ( !processed && GetInvokingWindow())
c71830c3 180 processed = GetInvokingWindow()->ProcessEvent(event);
631f1bfe 181
c71830c3 182 return processed;
4bb6408c
JS
183}
184
9874b4ee 185// ----------------------------------------------------------------------------
4bb6408c 186// Menu Bar
9874b4ee 187// ----------------------------------------------------------------------------
4bb6408c 188
9874b4ee 189void wxMenuBar::Init()
cba2db0c
JS
190{
191 m_eventHandler = this;
cba2db0c
JS
192 m_menuBarFrame = NULL;
193 m_mainWidget = (WXWidget) NULL;
a756f210
VS
194 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
195 m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
196 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
cba2db0c
JS
197}
198
294ea16d 199wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxArrayString& titles, long WXUNUSED(style))
584ad2a3 200{
12cca26a 201 wxASSERT( n == titles.GetCount() );
584ad2a3
MB
202
203 Init();
204
205 m_titles = titles;
12cca26a 206 for ( size_t i = 0; i < n; i++ )
584ad2a3
MB
207 m_menus.Append(menus[i]);
208}
209
294ea16d 210wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long WXUNUSED(style))
4bb6408c 211{
9874b4ee 212 Init();
4bb6408c 213
d2103c8c 214 for ( size_t i = 0; i < n; i++ )
4bb6408c 215 {
9874b4ee
VZ
216 m_menus.Append(menus[i]);
217 m_titles.Add(titles[i]);
4bb6408c 218 }
4bb6408c
JS
219}
220
9874b4ee 221wxMenuBar::~wxMenuBar()
4bb6408c 222{
9874b4ee 223 // nothing to do: wxMenuBarBase will delete the menus
4bb6408c
JS
224}
225
9874b4ee 226void wxMenuBar::EnableTop(size_t WXUNUSED(pos), bool WXUNUSED(flag))
4bb6408c 227{
6adaedf0 228 // wxFAIL_MSG("TODO");
23a8562d 229// wxLogWarning("wxMenuBar::EnableTop not yet implemented.");
4bb6408c
JS
230}
231
9874b4ee 232void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
4bb6408c 233{
9874b4ee
VZ
234 wxMenu *menu = GetMenu(pos);
235 if ( !menu )
4bb6408c 236 return;
bf6c2b35 237
9874b4ee
VZ
238 Widget w = (Widget)menu->GetButtonWidget();
239 if (w)
240 {
241 wxXmString label_str(label);
bf6c2b35 242
9874b4ee
VZ
243 XtVaSetValues(w,
244 XmNlabelString, label_str(),
245 NULL);
246 }
4bb6408c
JS
247}
248
9874b4ee 249wxString wxMenuBar::GetLabelTop(size_t pos) const
4bb6408c 250{
9874b4ee
VZ
251 wxMenu *menu = GetMenu(pos);
252 if ( menu )
253 {
254 Widget w = (Widget)menu->GetButtonWidget();
255 if (w)
256 {
257 XmString text;
258 XtVaGetValues(w,
259 XmNlabelString, &text,
260 NULL);
4bb6408c 261
da494b40 262 return wxXmStringToString( text );
9874b4ee
VZ
263 }
264 }
bf6c2b35 265
da494b40 266 return wxEmptyString;
4bb6408c
JS
267}
268
9874b4ee 269bool wxMenuBar::Append(wxMenu * menu, const wxString& title)
4bb6408c 270{
51c9a5db
MB
271 return Insert(GetMenuCount(), menu, title);
272}
273
274bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
275{
276 wxCHECK_MSG( pos <= GetMenuCount(), false, wxT("invalid position") );
96be256b
MB
277 wxCHECK_MSG( menu, false, wxT("invalid menu") );
278 wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), false,
9874b4ee 279 wxT("menu already appended") );
bf6c2b35 280
9874b4ee 281 if ( m_menuBarFrame )
50414e24 282 {
51c9a5db
MB
283 WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu,
284 pos, title, true);
96be256b 285 wxCHECK_MSG( w, false, wxT("failed to create menu") );
9874b4ee 286 menu->SetButtonWidget(w);
50414e24 287 }
bf6c2b35 288
51c9a5db 289 m_titles.Insert(title, pos);
bf6c2b35 290
51c9a5db 291 return wxMenuBarBase::Insert(pos, menu, title);
4bb6408c
JS
292}
293
9874b4ee 294wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 295{
9874b4ee 296 if ( !wxMenuBarBase::Replace(pos, menu, title) )
81b29996 297 return NULL;
bf6c2b35 298
9874b4ee 299 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 300
9874b4ee 301 return NULL;
4bb6408c
JS
302}
303
9874b4ee 304wxMenu *wxMenuBar::Remove(size_t pos)
4bb6408c 305{
9874b4ee
VZ
306 wxMenu *menu = wxMenuBarBase::Remove(pos);
307 if ( !menu )
308 return NULL;
bf6c2b35 309
9874b4ee 310 if ( m_menuBarFrame )
96be256b 311 menu->DestroyMenu(true);
bf6c2b35 312
9874b4ee 313 menu->SetMenuBar(NULL);
bf6c2b35 314
ba8c1601 315 m_titles.RemoveAt(pos);
bf6c2b35 316
9874b4ee 317 return menu;
4bb6408c
JS
318}
319
320// Find the menu menuString, item itemString, and return the item id.
321// Returns -1 if none found.
322int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemString) const
323{
324 char buf1[200];
325 char buf2[200];
d3a80c92 326 wxStripMenuCodes (wxConstCast(menuString.c_str(), char), buf1);
9874b4ee
VZ
327
328 size_t menuCount = GetMenuCount();
329 for (size_t i = 0; i < menuCount; i++)
4bb6408c 330 {
d3a80c92 331 wxStripMenuCodes (wxConstCast(m_titles[i].c_str(), char), buf2);
4bb6408c 332 if (strcmp (buf1, buf2) == 0)
ac32ba44 333 return m_menus.Item(i)->GetData()->FindItem (itemString);
4bb6408c
JS
334 }
335 return -1;
336}
337
9874b4ee 338wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const
4bb6408c
JS
339{
340 if (itemMenu)
341 *itemMenu = NULL;
bf6c2b35 342
9874b4ee
VZ
343 size_t menuCount = GetMenuCount();
344 for (size_t i = 0; i < menuCount; i++)
355b4d3d
WS
345 {
346 wxMenuItem *item = m_menus.Item(i)->GetData()->FindItem(id, itemMenu);
347 if (item) return item;
348 }
349
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]);
51c9a5db 376 menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, i, 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 471
355b4d3d
WS
472WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar,
473 WXWidget parent,
474 wxMenu * topMenu,
475 size_t WXUNUSED(index),
476 const wxString& title,
477 bool pullDown)
50414e24 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
51c9a5db 520 size_t i = 0;
ac32ba44 521 for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3 522 node;
51c9a5db 523 node = node->GetNext(), ++i )
50414e24 524 {
c71830c3
VZ
525 wxMenuItem *item = node->GetData();
526
51c9a5db 527 item->CreateItem(menu, menuBar, topMenu, i);
50414e24 528 }
bf6c2b35 529
2d120f83
JS
530 SetBackgroundColour(m_backgroundColour);
531 SetForegroundColour(m_foregroundColour);
532 SetFont(m_font);
bf6c2b35 533
2d120f83 534 return buttonWidget;
50414e24
JS
535}
536
537// Destroys the Motif implementation of the menu,
77ffb593 538// but maintains the wxWidgets data structures so we can
bf6c2b35 539// do a CreateMenu again.
50414e24
JS
540void wxMenu::DestroyMenu (bool full)
541{
ac32ba44 542 for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3
VZ
543 node;
544 node = node->GetNext() )
50414e24 545 {
c71830c3 546 wxMenuItem *item = node->GetData();
2d120f83 547 item->SetMenuBar((wxMenuBar*) NULL);
bf6c2b35 548
2d120f83 549 item->DestroyItem(full);
c71830c3 550 }
bf6c2b35 551
2d120f83 552 if (m_buttonWidget)
50414e24 553 {
2d120f83
JS
554 if (full)
555 {
556 XtVaSetValues((Widget) m_buttonWidget, XmNsubMenuId, NULL, NULL);
557 XtDestroyWidget ((Widget) m_buttonWidget);
558 m_buttonWidget = (WXWidget) 0;
559 }
50414e24 560 }
2d120f83 561 if (m_menuWidget && full)
50414e24 562 {
2d120f83
JS
563 XtDestroyWidget((Widget) m_menuWidget);
564 m_menuWidget = (WXWidget) NULL;
50414e24
JS
565 }
566}
567
568WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const
569{
2d120f83 570 if (id == m_menuId)
50414e24 571 {
2d120f83
JS
572 if (it)
573 *it = (wxMenuItem*) NULL;
574 return m_buttonWidget;
50414e24 575 }
bf6c2b35 576
ac32ba44 577 for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3
VZ
578 node;
579 node = node->GetNext() )
50414e24 580 {
c71830c3 581 wxMenuItem *item = node->GetData ();
2d120f83
JS
582 if (item->GetId() == id)
583 {
584 if (it)
585 *it = item;
586 return item->GetButtonWidget();
587 }
bf6c2b35 588
2d120f83
JS
589 if (item->GetSubMenu())
590 {
591 WXWidget w = item->GetSubMenu()->FindMenuItem (id, it);
592 if (w)
593 {
594 return w;
595 }
596 }
c71830c3 597 }
bf6c2b35 598
2d120f83
JS
599 if (it)
600 *it = (wxMenuItem*) NULL;
601 return (WXWidget) NULL;
50414e24 602}
94b49b93
JS
603
604void wxMenu::SetBackgroundColour(const wxColour& col)
605{
606 m_backgroundColour = col;
607 if (m_menuWidget)
2d120f83 608 wxDoChangeBackgroundColour(m_menuWidget, (wxColour&) col);
94b49b93 609 if (m_buttonWidget)
96be256b 610 wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, true);
bf6c2b35 611
ac32ba44 612 for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3
VZ
613 node;
614 node = node->GetNext() )
94b49b93 615 {
c71830c3 616 wxMenuItem* item = node->GetData();
94b49b93
JS
617 if (item->GetButtonWidget())
618 {
2d120f83 619 // This crashes because it uses gadgets
96be256b 620 // wxDoChangeBackgroundColour(item->GetButtonWidget(), (wxColour&) col, true);
94b49b93
JS
621 }
622 if (item->GetSubMenu())
2d120f83 623 item->GetSubMenu()->SetBackgroundColour((wxColour&) col);
94b49b93
JS
624 }
625}
626
627void wxMenu::SetForegroundColour(const wxColour& col)
628{
629 m_foregroundColour = col;
630 if (m_menuWidget)
2d120f83 631 wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col);
94b49b93 632 if (m_buttonWidget)
2d120f83 633 wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col);
bf6c2b35 634
ac32ba44 635 for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3
VZ
636 node;
637 node = node->GetNext() )
94b49b93 638 {
c71830c3 639 wxMenuItem* item = node->GetData();
94b49b93
JS
640 if (item->GetButtonWidget())
641 {
2d120f83
JS
642 // This crashes because it uses gadgets
643 // wxDoChangeForegroundColour(item->GetButtonWidget(), (wxColour&) col);
94b49b93
JS
644 }
645 if (item->GetSubMenu())
2d120f83 646 item->GetSubMenu()->SetForegroundColour((wxColour&) col);
94b49b93
JS
647 }
648}
649
650void wxMenu::ChangeFont(bool keepOriginalSize)
651{
101b4778
MB
652 // Lesstif 0.87 hangs here, but 0.93 does not; MBN: sometimes it does
653#if !wxCHECK_LESSTIF() // || wxCHECK_LESSTIF_VERSION( 0, 93 )
94b49b93
JS
654 if (!m_font.Ok() || !m_menuWidget)
655 return;
bf6c2b35 656
73608949 657 Display* dpy = XtDisplay((Widget) m_menuWidget);
bf6c2b35 658
94b49b93 659 XtVaSetValues ((Widget) m_menuWidget,
73608949 660 wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
da494b40 661 NULL);
94b49b93
JS
662 if (m_buttonWidget)
663 {
2d120f83 664 XtVaSetValues ((Widget) m_buttonWidget,
73608949 665 wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
da494b40 666 NULL);
94b49b93 667 }
c71830c3 668
ac32ba44 669 for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3
VZ
670 node;
671 node = node->GetNext() )
94b49b93 672 {
c71830c3 673 wxMenuItem* item = node->GetData();
94b49b93
JS
674 if (m_menuWidget && item->GetButtonWidget() && m_font.Ok())
675 {
2d120f83 676 XtVaSetValues ((Widget) item->GetButtonWidget(),
73608949 677 wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
da494b40 678 NULL);
94b49b93
JS
679 }
680 if (item->GetSubMenu())
2d120f83 681 item->GetSubMenu()->ChangeFont(keepOriginalSize);
94b49b93 682 }
355b4d3d
WS
683#else
684 wxUnusedVar(keepOriginalSize);
94b49b93
JS
685#endif
686}
687
688void wxMenu::SetFont(const wxFont& font)
689{
690 m_font = font;
691 ChangeFont();
692}
693
9874b4ee 694bool wxMenuBar::SetBackgroundColour(const wxColour& col)
94b49b93 695{
94b49b93
JS
696 m_backgroundColour = col;
697 if (m_mainWidget)
2d120f83 698 wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col);
9874b4ee
VZ
699
700 size_t menuCount = GetMenuCount();
701 for (size_t i = 0; i < menuCount; i++)
ac32ba44 702 m_menus.Item(i)->GetData()->SetBackgroundColour((wxColour&) col);
9874b4ee 703
96be256b 704 return true;
94b49b93
JS
705}
706
9874b4ee 707bool wxMenuBar::SetForegroundColour(const wxColour& col)
94b49b93
JS
708{
709 m_foregroundColour = col;
710 if (m_mainWidget)
2d120f83 711 wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col);
bf6c2b35 712
9874b4ee
VZ
713 size_t menuCount = GetMenuCount();
714 for (size_t i = 0; i < menuCount; i++)
ac32ba44 715 m_menus.Item(i)->GetData()->SetForegroundColour((wxColour&) col);
9874b4ee 716
96be256b 717 return true;
94b49b93
JS
718}
719
af111fc3 720void wxMenuBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
94b49b93 721{
2d120f83 722 // Nothing to do for menubar, fonts are kept in wxMenus
94b49b93
JS
723}
724
9874b4ee 725bool wxMenuBar::SetFont(const wxFont& font)
94b49b93
JS
726{
727 m_font = font;
728 ChangeFont();
bf6c2b35 729
9874b4ee
VZ
730 size_t menuCount = GetMenuCount();
731 for (size_t i = 0; i < menuCount; i++)
ac32ba44 732 m_menus.Item(i)->GetData()->SetFont(font);
9874b4ee 733
96be256b 734 return true;
94b49b93 735}