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