]> git.saurik.com Git - wxWidgets.git/blame - src/motif/menu.cpp
attemps to make wxStreamToTextRedirector work with more (broken) compilers
[wxWidgets.git] / src / motif / menu.cpp
CommitLineData
4bb6408c
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: menu.cpp
3// Purpose: wxMenu, wxMenuBar, wxMenuItem
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
bf6c2b35 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
12
13// ============================================================================
9874b4ee 14// declarations
4bb6408c
JS
15// ============================================================================
16
14f355c2 17#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
9874b4ee 18 #pragma implementation "menu.h"
4bb6408c
JS
19#endif
20
9874b4ee
VZ
21// ----------------------------------------------------------------------------
22// headers
23// ----------------------------------------------------------------------------
24
f6045f99
GD
25#include "wx/defs.h"
26
4bb6408c
JS
27#include "wx/menu.h"
28#include "wx/menuitem.h"
29#include "wx/log.h"
30#include "wx/utils.h"
50414e24
JS
31#include "wx/app.h"
32#include "wx/frame.h"
94b49b93 33#include "wx/settings.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;
4bb6408c 79 m_ownedByMenuBar = FALSE;
bf6c2b35 80
c71830c3 81 if ( !!m_title )
4bb6408c 82 {
c71830c3 83 Append(wxID_SEPARATOR, 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
JS
97 if (m_menuParent)
98 DestroyMenu(TRUE);
99 else
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
c71830c3 117bool wxMenu::DoAppend(wxMenuItem *pItem)
4bb6408c 118{
50414e24 119 if (m_menuWidget)
50414e24 120 {
c71830c3
VZ
121 // this is a dynamic Append
122 pItem->CreateItem(m_menuWidget, m_menuBar, m_topLevelMenu);
4bb6408c 123 }
bf6c2b35 124
c71830c3
VZ
125 if ( pItem->IsSubMenu() )
126 {
127 pItem->GetSubMenu()->m_topLevelMenu = m_topLevelMenu;
2d120f83 128 }
bf6c2b35 129
c71830c3 130 return wxMenuBase::DoAppend(pItem);
4bb6408c
JS
131}
132
c71830c3 133wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
4bb6408c 134{
c71830c3 135 item->DestroyItem(TRUE);
bf6c2b35 136
c71830c3 137 return wxMenuBase::DoRemove(item);
4bb6408c
JS
138}
139
c71830c3 140bool wxMenu::DoInsert(size_t pos, wxMenuItem *item)
4bb6408c 141{
2b5f62a0
VZ
142 if ( wxMenuBase::DoInsert(pos, item) )
143 return TRUE;
4bb6408c 144
2b5f62a0 145 wxFAIL_MSG(wxT("DoInsert not implemented; or error in wxMenuBase::DoInsert"));
bf6c2b35 146
c71830c3 147 return FALSE;
4bb6408c
JS
148}
149
150void wxMenu::SetTitle(const wxString& label)
151{
c71830c3 152 m_title = label;
bf6c2b35 153
ac32ba44 154 wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3 155 if ( !node )
2d120f83 156 return;
bf6c2b35 157
c71830c3 158 wxMenuItem *item = node->GetData ();
50414e24 159 Widget widget = (Widget) item->GetButtonWidget();
c71830c3 160 if ( !widget )
2d120f83 161 return;
bf6c2b35 162
c71830c3
VZ
163 wxXmString title_str(label);
164 XtVaSetValues(widget,
165 XmNlabelString, title_str(),
166 NULL);
4bb6408c
JS
167}
168
c71830c3 169bool wxMenu::ProcessCommand(wxCommandEvent & event)
4bb6408c
JS
170{
171 bool processed = FALSE;
bf6c2b35 172
9739d9ee 173#if wxUSE_MENU_CALLBACK
4bb6408c
JS
174 // Try a callback
175 if (m_callback)
176 {
2d120f83
JS
177 (void) (*(m_callback)) (*this, event);
178 processed = TRUE;
4bb6408c 179 }
9739d9ee 180#endif // wxUSE_MENU_CALLBACK
bf6c2b35 181
4bb6408c
JS
182 // Try the menu's event handler
183 if ( !processed && GetEventHandler())
184 {
2d120f83 185 processed = GetEventHandler()->ProcessEvent(event);
4bb6408c 186 }
4bb6408c
JS
187 // Try the window the menu was popped up from (and up
188 // through the hierarchy)
189 if ( !processed && GetInvokingWindow())
c71830c3 190 processed = GetInvokingWindow()->ProcessEvent(event);
631f1bfe 191
c71830c3 192 return processed;
4bb6408c
JS
193}
194
9874b4ee 195// ----------------------------------------------------------------------------
4bb6408c 196// Menu Bar
9874b4ee 197// ----------------------------------------------------------------------------
4bb6408c 198
9874b4ee 199void wxMenuBar::Init()
cba2db0c
JS
200{
201 m_eventHandler = this;
cba2db0c
JS
202 m_menuBarFrame = NULL;
203 m_mainWidget = (WXWidget) NULL;
a756f210
VS
204 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
205 m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
206 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
cba2db0c
JS
207}
208
4bb6408c
JS
209wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[])
210{
9874b4ee 211 Init();
4bb6408c 212
9874b4ee 213 for ( int 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{
9874b4ee
VZ
270 wxCHECK_MSG( menu, FALSE, wxT("invalid menu") );
271 wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), FALSE,
272 wxT("menu already appended") );
bf6c2b35 273
9874b4ee 274 if ( m_menuBarFrame )
50414e24 275 {
9874b4ee
VZ
276 WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu, title, TRUE);
277 wxCHECK_MSG( w, FALSE, wxT("failed to create menu") );
278 menu->SetButtonWidget(w);
50414e24 279 }
bf6c2b35 280
9806a47c 281 //menu->SetMenuBar(this);
4bb6408c 282
9874b4ee 283 m_titles.Add(title);
bf6c2b35 284
9874b4ee 285 return wxMenuBarBase::Append(menu, title);
4bb6408c
JS
286}
287
9874b4ee 288bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 289{
9874b4ee 290 if ( !wxMenuBarBase::Insert(pos, menu, title) )
50414e24 291 return FALSE;
bf6c2b35 292
9874b4ee 293 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 294
9874b4ee 295 return FALSE;
4bb6408c
JS
296}
297
9874b4ee 298wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 299{
9874b4ee 300 if ( !wxMenuBarBase::Replace(pos, menu, title) )
81b29996 301 return NULL;
bf6c2b35 302
9874b4ee 303 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 304
9874b4ee 305 return NULL;
4bb6408c
JS
306}
307
9874b4ee 308wxMenu *wxMenuBar::Remove(size_t pos)
4bb6408c 309{
9874b4ee
VZ
310 wxMenu *menu = wxMenuBarBase::Remove(pos);
311 if ( !menu )
312 return NULL;
bf6c2b35 313
9874b4ee
VZ
314 if ( m_menuBarFrame )
315 menu->DestroyMenu(TRUE);
bf6c2b35 316
9874b4ee 317 menu->SetMenuBar(NULL);
bf6c2b35 318
ba8c1601 319 m_titles.RemoveAt(pos);
bf6c2b35 320
9874b4ee 321 return menu;
4bb6408c
JS
322}
323
324// Find the menu menuString, item itemString, and return the item id.
325// Returns -1 if none found.
326int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemString) const
327{
328 char buf1[200];
329 char buf2[200];
d3a80c92 330 wxStripMenuCodes (wxConstCast(menuString.c_str(), char), buf1);
9874b4ee
VZ
331
332 size_t menuCount = GetMenuCount();
333 for (size_t i = 0; i < menuCount; i++)
4bb6408c 334 {
d3a80c92 335 wxStripMenuCodes (wxConstCast(m_titles[i].c_str(), char), buf2);
4bb6408c 336 if (strcmp (buf1, buf2) == 0)
ac32ba44 337 return m_menus.Item(i)->GetData()->FindItem (itemString);
4bb6408c
JS
338 }
339 return -1;
340}
341
9874b4ee 342wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const
4bb6408c
JS
343{
344 if (itemMenu)
345 *itemMenu = NULL;
bf6c2b35 346
4bb6408c 347 wxMenuItem *item = NULL;
9874b4ee
VZ
348 size_t menuCount = GetMenuCount();
349 for (size_t i = 0; i < menuCount; i++)
ac32ba44 350 if ((item = m_menus.Item(i)->GetData()->FindItem(id, itemMenu)))
4bb6408c 351 return item;
2d120f83 352 return NULL;
4bb6408c
JS
353}
354
621793f4
JS
355// Create menubar
356bool wxMenuBar::CreateMenuBar(wxFrame* parent)
357{
2d120f83 358 if (m_mainWidget)
621793f4 359 {
1c4f8f8d 360 XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
2d120f83
JS
361 /*
362 if (!XtIsManaged((Widget) m_mainWidget))
363 XtManageChild((Widget) m_mainWidget);
364 */
365 XtMapWidget((Widget) m_mainWidget);
366 return TRUE;
621793f4 367 }
bf6c2b35 368
1c4f8f8d 369 Widget menuBarW = XmCreateMenuBar ((Widget) parent->GetMainWidget(), "MenuBar", NULL, 0);
2d120f83 370 m_mainWidget = (WXWidget) menuBarW;
bf6c2b35 371
9874b4ee
VZ
372 size_t menuCount = GetMenuCount();
373 for (size_t i = 0; i < menuCount; i++)
2d120f83
JS
374 {
375 wxMenu *menu = GetMenu(i);
376 wxString title(m_titles[i]);
377 menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, title, TRUE));
bf6c2b35 378
31528cd3 379 if (strcmp (wxStripMenuCodes(title), "Help") == 0)
2d120f83 380 XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL);
ee31c392
VZ
381
382 // tear off menu support
383#if (XmVersion >= 1002)
384 if ( menu->IsTearOff() )
385 {
386 XtVaSetValues(GetWidget(menu),
387 XmNtearOffModel, XmTEAR_OFF_ENABLED,
388 NULL);
6adaedf0
JS
389 Widget tearOff = XmGetTearOffControl(GetWidget(menu));
390 wxDoChangeForegroundColour((Widget) tearOff, m_foregroundColour);
391 wxDoChangeBackgroundColour((Widget) tearOff, m_backgroundColour, TRUE);
ee31c392
VZ
392#endif
393 }
2d120f83 394 }
bf6c2b35 395
2d120f83
JS
396 SetBackgroundColour(m_backgroundColour);
397 SetForegroundColour(m_foregroundColour);
398 SetFont(m_font);
bf6c2b35 399
1c4f8f8d 400 XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
2d120f83
JS
401 XtRealizeWidget ((Widget) menuBarW);
402 XtManageChild ((Widget) menuBarW);
403 SetMenuBarFrame(parent);
bf6c2b35 404
2d120f83 405 return TRUE;
621793f4
JS
406}
407
408// Destroy menubar, but keep data structures intact so we can recreate it.
409bool wxMenuBar::DestroyMenuBar()
410{
2d120f83 411 if (!m_mainWidget)
621793f4 412 {
2d120f83
JS
413 SetMenuBarFrame((wxFrame*) NULL);
414 return FALSE;
621793f4 415 }
bf6c2b35 416
2d120f83
JS
417 XtUnmanageChild ((Widget) m_mainWidget);
418 XtUnrealizeWidget ((Widget) m_mainWidget);
bf6c2b35 419
9874b4ee
VZ
420 size_t menuCount = GetMenuCount();
421 for (size_t i = 0; i < menuCount; i++)
2d120f83
JS
422 {
423 wxMenu *menu = GetMenu(i);
424 menu->DestroyMenu(TRUE);
bf6c2b35 425
2d120f83
JS
426 }
427 XtDestroyWidget((Widget) m_mainWidget);
428 m_mainWidget = (WXWidget) 0;
bf6c2b35 429
2d120f83 430 SetMenuBarFrame((wxFrame*) NULL);
bf6c2b35 431
2d120f83 432 return TRUE;
621793f4
JS
433}
434
7e1bcfa8
MB
435// Since PopupMenu under Motif stills grab right mouse button events
436// after it was closed, we need to delete the associated widgets to
437// allow next PopUpMenu to appear...
438void wxMenu::DestroyWidgetAndDetach()
50414e24 439{
7e1bcfa8 440 if (GetMainWidget())
c71830c3 441 {
7e1bcfa8 442 wxMenu *menuParent = GetParent();
c71830c3 443 if ( menuParent )
2d120f83 444 {
ac32ba44 445 wxMenuItemList::compatibility_iterator node = menuParent->GetMenuItems().GetFirst();
c71830c3
VZ
446 while ( node )
447 {
7e1bcfa8 448 if ( node->GetData()->GetSubMenu() == this )
c71830c3 449 {
ac32ba44
MB
450 delete node->GetData();
451 menuParent->GetMenuItems().Erase(node);
c71830c3
VZ
452
453 break;
454 }
455
456 node = node->GetNext();
457 }
2d120f83 458 }
c71830c3 459
7e1bcfa8 460 DestroyMenu(TRUE);
7fe7d506 461 }
c71830c3
VZ
462
463 // Mark as no longer popped up
7e1bcfa8 464 m_menuId = -1;
50414e24
JS
465}
466
467/*
2d120f83
JS
468* Create a popup or pulldown menu.
469* Submenus of a popup will be pulldown.
470*
471*/
50414e24
JS
472
473WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topMenu, const wxString& title, bool pullDown)
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 {
2d120f83 483 menu = XmCreatePopupMenu ((Widget) parent, "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);
2d120f83 494 menu = XmCreatePulldownMenu ((Widget) parent, "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
JS
514 m_menuBar = menuBar;
515 m_topLevelMenu = topMenu;
bf6c2b35 516
ac32ba44 517 for ( wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3
VZ
518 node;
519 node = node->GetNext() )
50414e24 520 {
c71830c3
VZ
521 wxMenuItem *item = node->GetData();
522
523 item->CreateItem(menu, menuBar, topMenu);
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,
534// but maintains the wxWindows 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)
2d120f83 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
JS
615 // This crashes because it uses gadgets
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{
da494b40
MB
648 // Lesstif 0.87 hangs here, but 0.93 does not
649#if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 )
94b49b93
JS
650 if (!m_font.Ok() || !m_menuWidget)
651 return;
bf6c2b35 652
da494b40 653 WXFontType fontType = m_font.GetFontType(XtDisplay((Widget) m_menuWidget));
bf6c2b35 654
94b49b93 655 XtVaSetValues ((Widget) m_menuWidget,
da494b40
MB
656 wxFont::GetFontTag(), fontType,
657 NULL);
94b49b93
JS
658 if (m_buttonWidget)
659 {
2d120f83 660 XtVaSetValues ((Widget) m_buttonWidget,
da494b40
MB
661 wxFont::GetFontTag(), fontType,
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(),
da494b40
MB
673 wxFont::GetFontTag(), fontType,
674 NULL);
94b49b93
JS
675 }
676 if (item->GetSubMenu())
2d120f83 677 item->GetSubMenu()->ChangeFont(keepOriginalSize);
94b49b93
JS
678 }
679#endif
680}
681
682void wxMenu::SetFont(const wxFont& font)
683{
684 m_font = font;
685 ChangeFont();
686}
687
9874b4ee 688bool wxMenuBar::SetBackgroundColour(const wxColour& col)
94b49b93 689{
94b49b93
JS
690 m_backgroundColour = col;
691 if (m_mainWidget)
2d120f83 692 wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col);
9874b4ee
VZ
693
694 size_t menuCount = GetMenuCount();
695 for (size_t i = 0; i < menuCount; i++)
ac32ba44 696 m_menus.Item(i)->GetData()->SetBackgroundColour((wxColour&) col);
9874b4ee
VZ
697
698 return TRUE;
94b49b93
JS
699}
700
9874b4ee 701bool wxMenuBar::SetForegroundColour(const wxColour& col)
94b49b93
JS
702{
703 m_foregroundColour = col;
704 if (m_mainWidget)
2d120f83 705 wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col);
bf6c2b35 706
9874b4ee
VZ
707 size_t menuCount = GetMenuCount();
708 for (size_t i = 0; i < menuCount; i++)
ac32ba44 709 m_menus.Item(i)->GetData()->SetForegroundColour((wxColour&) col);
9874b4ee
VZ
710
711 return TRUE;
94b49b93
JS
712}
713
af111fc3 714void wxMenuBar::ChangeFont(bool WXUNUSED(keepOriginalSize))
94b49b93 715{
2d120f83 716 // Nothing to do for menubar, fonts are kept in wxMenus
94b49b93
JS
717}
718
9874b4ee 719bool wxMenuBar::SetFont(const wxFont& font)
94b49b93
JS
720{
721 m_font = font;
722 ChangeFont();
bf6c2b35 723
9874b4ee
VZ
724 size_t menuCount = GetMenuCount();
725 for (size_t i = 0; i < menuCount; i++)
ac32ba44 726 m_menus.Item(i)->GetData()->SetFont(font);
9874b4ee
VZ
727
728 return TRUE;
94b49b93
JS
729}
730