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