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