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