]> git.saurik.com Git - wxWidgets.git/blame - src/motif/menu.cpp
need wxUSE_WCHAR_T around wxConvLocal
[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
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
c71830c3 117bool 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
c71830c3 140bool wxMenu::DoInsert(size_t pos, wxMenuItem *item)
4bb6408c 141{
c71830c3
VZ
142 if ( !wxMenuBase::DoInsert(pos, item) )
143 return FALSE;
4bb6408c 144
c71830c3 145 wxFAIL_MSG(wxT("not implemented"));
bf6c2b35 146
c71830c3 147 return FALSE;
4bb6408c
JS
148}
149
150void wxMenu::SetTitle(const wxString& label)
151{
c71830c3 152 m_title = label;
bf6c2b35 153
c71830c3
VZ
154 wxMenuItemList::Node *node = GetMenuItems().GetFirst();
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
4bb6408c
JS
209wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[])
210{
9874b4ee 211 Init();
4bb6408c 212
9874b4ee 213 for ( int 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 250 wxString str;
bf6c2b35 251
9874b4ee
VZ
252 wxMenu *menu = GetMenu(pos);
253 if ( menu )
254 {
255 Widget w = (Widget)menu->GetButtonWidget();
256 if (w)
257 {
258 XmString text;
259 XtVaGetValues(w,
260 XmNlabelString, &text,
261 NULL);
4bb6408c 262
9874b4ee
VZ
263 char *s;
264 if ( XmStringGetLtoR(text, XmSTRING_DEFAULT_CHARSET, &s) )
265 {
266 str = s;
bf6c2b35 267
9874b4ee
VZ
268 XtFree(s);
269 }
270 }
271 }
bf6c2b35 272
9874b4ee 273 return str;
4bb6408c
JS
274}
275
9874b4ee 276bool wxMenuBar::Append(wxMenu * menu, const wxString& title)
4bb6408c 277{
9874b4ee
VZ
278 wxCHECK_MSG( menu, FALSE, wxT("invalid menu") );
279 wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), FALSE,
280 wxT("menu already appended") );
bf6c2b35 281
9874b4ee 282 if ( m_menuBarFrame )
50414e24 283 {
9874b4ee
VZ
284 WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu, title, TRUE);
285 wxCHECK_MSG( w, FALSE, wxT("failed to create menu") );
286 menu->SetButtonWidget(w);
50414e24 287 }
bf6c2b35 288
9806a47c 289 //menu->SetMenuBar(this);
4bb6408c 290
9874b4ee 291 m_titles.Add(title);
bf6c2b35 292
9874b4ee 293 return wxMenuBarBase::Append(menu, title);
4bb6408c
JS
294}
295
9874b4ee 296bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 297{
9874b4ee 298 if ( !wxMenuBarBase::Insert(pos, menu, title) )
50414e24 299 return FALSE;
bf6c2b35 300
9874b4ee 301 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 302
9874b4ee 303 return FALSE;
4bb6408c
JS
304}
305
9874b4ee 306wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
4bb6408c 307{
9874b4ee
VZ
308 if ( !wxMenuBarBase::Replace(pos, menu, title) )
309 return FALSE;
bf6c2b35 310
9874b4ee 311 wxFAIL_MSG(wxT("TODO"));
bf6c2b35 312
9874b4ee 313 return NULL;
4bb6408c
JS
314}
315
9874b4ee 316wxMenu *wxMenuBar::Remove(size_t pos)
4bb6408c 317{
9874b4ee
VZ
318 wxMenu *menu = wxMenuBarBase::Remove(pos);
319 if ( !menu )
320 return NULL;
bf6c2b35 321
9874b4ee
VZ
322 if ( m_menuBarFrame )
323 menu->DestroyMenu(TRUE);
bf6c2b35 324
9874b4ee 325 menu->SetMenuBar(NULL);
bf6c2b35 326
9874b4ee 327 m_titles.Remove(pos);
bf6c2b35 328
9874b4ee 329 return menu;
4bb6408c
JS
330}
331
332// Find the menu menuString, item itemString, and return the item id.
333// Returns -1 if none found.
334int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemString) const
335{
336 char buf1[200];
337 char buf2[200];
338 wxStripMenuCodes ((char *)(const char *)menuString, buf1);
9874b4ee
VZ
339
340 size_t menuCount = GetMenuCount();
341 for (size_t i = 0; i < menuCount; i++)
4bb6408c
JS
342 {
343 wxStripMenuCodes ((char *)(const char *)m_titles[i], buf2);
344 if (strcmp (buf1, buf2) == 0)
345 return m_menus[i]->FindItem (itemString);
346 }
347 return -1;
348}
349
9874b4ee 350wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const
4bb6408c
JS
351{
352 if (itemMenu)
353 *itemMenu = NULL;
bf6c2b35 354
4bb6408c 355 wxMenuItem *item = NULL;
9874b4ee
VZ
356 size_t menuCount = GetMenuCount();
357 for (size_t i = 0; i < menuCount; i++)
c71830c3 358 if ((item = m_menus[i]->FindItem(id, itemMenu)))
4bb6408c 359 return item;
2d120f83 360 return NULL;
4bb6408c
JS
361}
362
621793f4
JS
363// Create menubar
364bool wxMenuBar::CreateMenuBar(wxFrame* parent)
365{
2d120f83 366 if (m_mainWidget)
621793f4 367 {
1c4f8f8d 368 XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
2d120f83
JS
369 /*
370 if (!XtIsManaged((Widget) m_mainWidget))
371 XtManageChild((Widget) m_mainWidget);
372 */
373 XtMapWidget((Widget) m_mainWidget);
374 return TRUE;
621793f4 375 }
bf6c2b35 376
1c4f8f8d 377 Widget menuBarW = XmCreateMenuBar ((Widget) parent->GetMainWidget(), "MenuBar", NULL, 0);
2d120f83 378 m_mainWidget = (WXWidget) menuBarW;
bf6c2b35 379
9874b4ee
VZ
380 size_t menuCount = GetMenuCount();
381 for (size_t i = 0; i < menuCount; i++)
2d120f83
JS
382 {
383 wxMenu *menu = GetMenu(i);
384 wxString title(m_titles[i]);
385 menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, title, TRUE));
bf6c2b35 386
31528cd3 387 if (strcmp (wxStripMenuCodes(title), "Help") == 0)
2d120f83 388 XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL);
ee31c392
VZ
389
390 // tear off menu support
391#if (XmVersion >= 1002)
392 if ( menu->IsTearOff() )
393 {
394 XtVaSetValues(GetWidget(menu),
395 XmNtearOffModel, XmTEAR_OFF_ENABLED,
396 NULL);
6adaedf0
JS
397 Widget tearOff = XmGetTearOffControl(GetWidget(menu));
398 wxDoChangeForegroundColour((Widget) tearOff, m_foregroundColour);
399 wxDoChangeBackgroundColour((Widget) tearOff, m_backgroundColour, TRUE);
ee31c392
VZ
400#endif
401 }
2d120f83 402 }
bf6c2b35 403
2d120f83
JS
404 SetBackgroundColour(m_backgroundColour);
405 SetForegroundColour(m_foregroundColour);
406 SetFont(m_font);
bf6c2b35 407
1c4f8f8d 408 XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
2d120f83
JS
409 XtRealizeWidget ((Widget) menuBarW);
410 XtManageChild ((Widget) menuBarW);
411 SetMenuBarFrame(parent);
bf6c2b35 412
2d120f83 413 return TRUE;
621793f4
JS
414}
415
416// Destroy menubar, but keep data structures intact so we can recreate it.
417bool wxMenuBar::DestroyMenuBar()
418{
2d120f83 419 if (!m_mainWidget)
621793f4 420 {
2d120f83
JS
421 SetMenuBarFrame((wxFrame*) NULL);
422 return FALSE;
621793f4 423 }
bf6c2b35 424
2d120f83
JS
425 XtUnmanageChild ((Widget) m_mainWidget);
426 XtUnrealizeWidget ((Widget) m_mainWidget);
bf6c2b35 427
9874b4ee
VZ
428 size_t menuCount = GetMenuCount();
429 for (size_t i = 0; i < menuCount; i++)
2d120f83
JS
430 {
431 wxMenu *menu = GetMenu(i);
432 menu->DestroyMenu(TRUE);
bf6c2b35 433
2d120f83
JS
434 }
435 XtDestroyWidget((Widget) m_mainWidget);
436 m_mainWidget = (WXWidget) 0;
bf6c2b35 437
2d120f83 438 SetMenuBarFrame((wxFrame*) NULL);
bf6c2b35 439
2d120f83 440 return TRUE;
621793f4
JS
441}
442
50414e24 443//// Motif-specific
50414e24
JS
444static XtWorkProcId WorkProcMenuId;
445
446/* Since PopupMenu under Motif stills grab right mouse button events
2d120f83
JS
447* after it was closed, we need to delete the associated widgets to
448* allow next PopUpMenu to appear...
449*/
50414e24
JS
450
451int PostDeletionOfMenu( XtPointer* clientData )
452{
2d120f83
JS
453 XtRemoveWorkProc(WorkProcMenuId);
454 wxMenu *menu = (wxMenu *)clientData;
bf6c2b35 455
c71830c3
VZ
456 if (menu->GetMainWidget())
457 {
458 wxMenu *menuParent = menu->GetParent();
459 if ( menuParent )
2d120f83 460 {
c71830c3
VZ
461 wxMenuItemList::Node *node = menuParent->GetMenuItems().GetFirst();
462 while ( node )
463 {
464 if ( node->GetData()->GetSubMenu() == menu )
465 {
466 menuParent->GetMenuItems().DeleteNode(node);
467
468 break;
469 }
470
471 node = node->GetNext();
472 }
2d120f83 473 }
c71830c3 474
2d120f83 475 menu->DestroyMenu(TRUE);
7fe7d506 476 }
c71830c3
VZ
477
478 // Mark as no longer popped up
2d120f83 479 menu->m_menuId = -1;
c71830c3 480
2d120f83 481 return TRUE;
50414e24
JS
482}
483
bf6c2b35 484void
af111fc3
JS
485wxMenuPopdownCallback(Widget WXUNUSED(w), XtPointer clientData,
486 XtPointer WXUNUSED(ptr))
50414e24 487{
2d120f83 488 wxMenu *menu = (wxMenu *)clientData;
bf6c2b35 489
2d120f83
JS
490 // Added by JOREL Jean-Charles <jjorel@silr.ireste.fr>
491 /* Since Callbacks of MenuItems are not yet processed, we put a
492 * background job which will be done when system will be idle.
493 * What awful hack!! :(
494 */
bf6c2b35
VZ
495
496 WorkProcMenuId = XtAppAddWorkProc(
497 (XtAppContext) wxTheApp->GetAppContext(),
2d120f83
JS
498 (XtWorkProc) PostDeletionOfMenu,
499 (XtPointer) menu );
500 // Apparently not found in Motif headers
501 // XtVaSetValues( w, XmNpopupEnabled, XmPOPUP_DISABLED, NULL );
50414e24
JS
502}
503
504/*
2d120f83
JS
505* Create a popup or pulldown menu.
506* Submenus of a popup will be pulldown.
507*
508*/
50414e24
JS
509
510WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topMenu, const wxString& title, bool pullDown)
511{
2d120f83
JS
512 Widget menu = (Widget) 0;
513 Widget buttonWidget = (Widget) 0;
514 Arg args[5];
515 XtSetArg (args[0], XmNnumColumns, m_numColumns);
516 XtSetArg (args[1], XmNpacking, XmPACK_COLUMN);
bf6c2b35 517
2d120f83 518 if (!pullDown)
50414e24 519 {
2d120f83
JS
520 menu = XmCreatePopupMenu ((Widget) parent, "popup", args, 2);
521 XtAddCallback(menu,
bf6c2b35 522 XmNunmapCallback,
2d120f83
JS
523 (XtCallbackProc)wxMenuPopdownCallback,
524 (XtPointer)this);
50414e24 525 }
2d120f83 526 else
50414e24 527 {
2d120f83 528 char mnem = wxFindMnemonic (title);
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