]> git.saurik.com Git - wxWidgets.git/blame - src/motif/menu.cpp
[ 1577675 ] Fix for GTK warnings in wxNotebook::DoRemovePage
[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 }
c71830c3 85
a756f210
VS
86 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
87 m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
88 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
4bb6408c
JS
89}
90
91// The wxWindow destructor will take care of deleting the submenus.
92wxMenu::~wxMenu()
93{
50414e24
JS
94 if (m_menuWidget)
95 {
2d120f83 96 if (m_menuParent)
96be256b 97 DestroyMenu(true);
2d120f83 98 else
96be256b 99 DestroyMenu(false);
50414e24 100 }
bf6c2b35 101
50414e24
JS
102 // Not sure if this is right
103 if (m_menuParent && m_menuBar)
104 {
2d120f83
JS
105 m_menuParent = NULL;
106 // m_menuBar = NULL;
50414e24 107 }
4bb6408c
JS
108}
109
110void wxMenu::Break()
111{
c71830c3 112 m_numColumns++;
4bb6408c
JS
113}
114
115// function appends a new item or submenu to the menu
9add9367 116wxMenuItem* wxMenu::DoAppend(wxMenuItem *pItem)
4bb6408c 117{
51c9a5db 118 return DoInsert(GetMenuItemCount(), pItem);
4bb6408c
JS
119}
120
c71830c3 121wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
4bb6408c 122{
96be256b 123 item->DestroyItem(true);
bf6c2b35 124
c71830c3 125 return wxMenuBase::DoRemove(item);
4bb6408c
JS
126}
127
9add9367 128wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
4bb6408c 129{
51c9a5db
MB
130 if (m_menuWidget)
131 {
132 // this is a dynamic Append
133#ifndef XmNpositionIndex
134 wxCHECK_MSG( pos == GetMenuItemCount(), -1, wxT("insert not implemented"));
135#endif
136 item->CreateItem(m_menuWidget, GetMenuBar(), m_topLevelMenu, pos);
137 }
4bb6408c 138
51c9a5db
MB
139 if ( item->IsSubMenu() )
140 {
141 item->GetSubMenu()->m_topLevelMenu = m_topLevelMenu;
142 }
bf6c2b35 143
355b4d3d 144 return pos == GetMenuItemCount() ? wxMenuBase::DoAppend(item) :
51c9a5db 145 wxMenuBase::DoInsert(pos, item);
4bb6408c
JS
146}
147
148void wxMenu::SetTitle(const wxString& label)
149{
c71830c3 150 m_title = label;
bf6c2b35 151
ac32ba44 152 wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
c71830c3 153 if ( !node )
2d120f83 154 return;
bf6c2b35 155
c71830c3 156 wxMenuItem *item = node->GetData ();
50414e24 157 Widget widget = (Widget) item->GetButtonWidget();
c71830c3 158 if ( !widget )
2d120f83 159 return;
bf6c2b35 160
c71830c3
VZ
161 wxXmString title_str(label);
162 XtVaSetValues(widget,
163 XmNlabelString, title_str(),
164 NULL);
4bb6408c
JS
165}
166
c71830c3 167bool wxMenu::ProcessCommand(wxCommandEvent & event)
4bb6408c 168{
96be256b 169 bool processed = false;
bf6c2b35 170
4bb6408c
JS
171 // Try the menu's event handler
172 if ( !processed && GetEventHandler())
173 {
2d120f83 174 processed = GetEventHandler()->ProcessEvent(event);
4bb6408c 175 }
4bb6408c
JS
176 // Try the window the menu was popped up from (and up
177 // through the hierarchy)
178 if ( !processed && GetInvokingWindow())
c71830c3 179 processed = GetInvokingWindow()->ProcessEvent(event);
631f1bfe 180
c71830c3 181 return processed;
4bb6408c
JS
182}
183
9874b4ee 184// ----------------------------------------------------------------------------
4bb6408c 185// Menu Bar
9874b4ee 186// ----------------------------------------------------------------------------
4bb6408c 187
9874b4ee 188void wxMenuBar::Init()
cba2db0c
JS
189{
190 m_eventHandler = this;
cba2db0c
JS
191 m_menuBarFrame = NULL;
192 m_mainWidget = (WXWidget) NULL;
a756f210
VS
193 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
194 m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
195 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
cba2db0c
JS
196}
197
294ea16d 198wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxArrayString& titles, long WXUNUSED(style))
584ad2a3 199{
12cca26a 200 wxASSERT( n == titles.GetCount() );
584ad2a3
MB
201
202 Init();
203
204 m_titles = titles;
12cca26a 205 for ( size_t i = 0; i < n; i++ )
584ad2a3
MB
206 m_menus.Append(menus[i]);
207}
208
294ea16d 209wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long WXUNUSED(style))
4bb6408c 210{
9874b4ee 211 Init();
4bb6408c 212
d2103c8c 213 for ( size_t 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{
51c9a5db
MB
270 return Insert(GetMenuCount(), menu, title);
271}
272
273bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
274{
275 wxCHECK_MSG( pos <= GetMenuCount(), false, wxT("invalid position") );
96be256b
MB
276 wxCHECK_MSG( menu, false, wxT("invalid menu") );
277 wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), false,
9874b4ee 278 wxT("menu already appended") );
bf6c2b35 279
9874b4ee 280 if ( m_menuBarFrame )
50414e24 281 {
51c9a5db
MB
282 WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu,
283 pos, title, true);
96be256b 284 wxCHECK_MSG( w, false, wxT("failed to create menu") );
9874b4ee 285 menu->SetButtonWidget(w);
50414e24 286 }
bf6c2b35 287
51c9a5db 288 m_titles.Insert(title, pos);
bf6c2b35 289
51c9a5db 290 return wxMenuBarBase::Insert(pos, menu, title);
4bb6408c
JS
291}
292
9874b4ee 293wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 294{
9874b4ee 295 if ( !wxMenuBarBase::Replace(pos, menu, title) )
81b29996 296 return NULL;
bf6c2b35 297
9874b4ee 298 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 299
9874b4ee 300 return NULL;
4bb6408c
JS
301}
302
9874b4ee 303wxMenu *wxMenuBar::Remove(size_t pos)
4bb6408c 304{
9874b4ee
VZ
305 wxMenu *menu = wxMenuBarBase::Remove(pos);
306 if ( !menu )
307 return NULL;
bf6c2b35 308
9874b4ee 309 if ( m_menuBarFrame )
96be256b 310 menu->DestroyMenu(true);
bf6c2b35 311
9874b4ee 312 menu->SetMenuBar(NULL);
bf6c2b35 313
ba8c1601 314 m_titles.RemoveAt(pos);
bf6c2b35 315
9874b4ee 316 return menu;
4bb6408c
JS
317}
318
319// Find the menu menuString, item itemString, and return the item id.
320// Returns -1 if none found.
db927071 321int wxMenuBar::FindMenuItem(const wxString& menuString, const wxString& itemString) const
4bb6408c 322{
db927071 323 const wxString stripped = wxStripMenuCodes(menuString);
9874b4ee
VZ
324
325 size_t menuCount = GetMenuCount();
326 for (size_t i = 0; i < menuCount; i++)
4bb6408c 327 {
db927071 328 if ( wxStripMenuCodes(m_titles[i]) == stripped )
ac32ba44 329 return m_menus.Item(i)->GetData()->FindItem (itemString);
4bb6408c 330 }
db927071 331 return wxNOT_FOUND;
4bb6408c
JS
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}