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