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