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