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