]>
Commit | Line | Data |
---|---|---|
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 |
58 | IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) |
59 | IMPLEMENT_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 | 70 | void 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. | |
93 | wxMenu::~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 | ||
111 | void wxMenu::Break() | |
112 | { | |
c71830c3 | 113 | m_numColumns++; |
4bb6408c JS |
114 | } |
115 | ||
116 | // function appends a new item or submenu to the menu | |
c71830c3 | 117 | bool 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 | 133 | wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) |
4bb6408c | 134 | { |
c71830c3 | 135 | item->DestroyItem(TRUE); |
bf6c2b35 | 136 | |
c71830c3 | 137 | return wxMenuBase::DoRemove(item); |
4bb6408c JS |
138 | } |
139 | ||
c71830c3 | 140 | bool wxMenu::DoInsert(size_t pos, wxMenuItem *item) |
4bb6408c | 141 | { |
2b5f62a0 VZ |
142 | if ( wxMenuBase::DoInsert(pos, item) ) |
143 | return TRUE; | |
4bb6408c | 144 | |
2b5f62a0 | 145 | wxFAIL_MSG(wxT("DoInsert not implemented; or error in wxMenuBase::DoInsert")); |
bf6c2b35 | 146 | |
c71830c3 | 147 | return FALSE; |
4bb6408c JS |
148 | } |
149 | ||
150 | void 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 | 169 | bool 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 | 199 | void 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 |
209 | wxMenuBar::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 | 220 | wxMenuBar::~wxMenuBar() |
4bb6408c | 221 | { |
9874b4ee | 222 | // nothing to do: wxMenuBarBase will delete the menus |
4bb6408c JS |
223 | } |
224 | ||
9874b4ee | 225 | void 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 | 231 | void 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 | 248 | wxString wxMenuBar::GetLabelTop(size_t pos) const |
4bb6408c | 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 | |
da494b40 | 261 | return wxXmStringToString( text ); |
9874b4ee VZ |
262 | } |
263 | } | |
bf6c2b35 | 264 | |
da494b40 | 265 | return wxEmptyString; |
4bb6408c JS |
266 | } |
267 | ||
9874b4ee | 268 | bool wxMenuBar::Append(wxMenu * menu, const wxString& title) |
4bb6408c | 269 | { |
9874b4ee VZ |
270 | wxCHECK_MSG( menu, FALSE, wxT("invalid menu") ); |
271 | wxCHECK_MSG( !menu->GetParent() && !menu->GetButtonWidget(), FALSE, | |
272 | wxT("menu already appended") ); | |
bf6c2b35 | 273 | |
9874b4ee | 274 | if ( m_menuBarFrame ) |
50414e24 | 275 | { |
9874b4ee VZ |
276 | WXWidget w = menu->CreateMenu(this, GetMainWidget(), menu, title, TRUE); |
277 | wxCHECK_MSG( w, FALSE, wxT("failed to create menu") ); | |
278 | menu->SetButtonWidget(w); | |
50414e24 | 279 | } |
bf6c2b35 | 280 | |
9806a47c | 281 | //menu->SetMenuBar(this); |
4bb6408c | 282 | |
9874b4ee | 283 | m_titles.Add(title); |
bf6c2b35 | 284 | |
9874b4ee | 285 | return wxMenuBarBase::Append(menu, title); |
4bb6408c JS |
286 | } |
287 | ||
9874b4ee | 288 | bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) |
4bb6408c | 289 | { |
9874b4ee | 290 | if ( !wxMenuBarBase::Insert(pos, menu, title) ) |
50414e24 | 291 | return FALSE; |
bf6c2b35 | 292 | |
9874b4ee | 293 | wxFAIL_MSG(wxT("TODO")); |
bf6c2b35 | 294 | |
9874b4ee | 295 | return FALSE; |
4bb6408c JS |
296 | } |
297 | ||
9874b4ee | 298 | wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) |
4bb6408c | 299 | { |
9874b4ee | 300 | if ( !wxMenuBarBase::Replace(pos, menu, title) ) |
81b29996 | 301 | return NULL; |
bf6c2b35 | 302 | |
9874b4ee | 303 | wxFAIL_MSG(wxT("TODO")); |
bf6c2b35 | 304 | |
9874b4ee | 305 | return NULL; |
4bb6408c JS |
306 | } |
307 | ||
9874b4ee | 308 | wxMenu *wxMenuBar::Remove(size_t pos) |
4bb6408c | 309 | { |
9874b4ee VZ |
310 | wxMenu *menu = wxMenuBarBase::Remove(pos); |
311 | if ( !menu ) | |
312 | return NULL; | |
bf6c2b35 | 313 | |
9874b4ee VZ |
314 | if ( m_menuBarFrame ) |
315 | menu->DestroyMenu(TRUE); | |
bf6c2b35 | 316 | |
9874b4ee | 317 | menu->SetMenuBar(NULL); |
bf6c2b35 | 318 | |
9874b4ee | 319 | m_titles.Remove(pos); |
bf6c2b35 | 320 | |
9874b4ee | 321 | return menu; |
4bb6408c JS |
322 | } |
323 | ||
324 | // Find the menu menuString, item itemString, and return the item id. | |
325 | // Returns -1 if none found. | |
326 | int wxMenuBar::FindMenuItem (const wxString& menuString, const wxString& itemString) const | |
327 | { | |
328 | char buf1[200]; | |
329 | char buf2[200]; | |
d3a80c92 | 330 | wxStripMenuCodes (wxConstCast(menuString.c_str(), char), buf1); |
9874b4ee VZ |
331 | |
332 | size_t menuCount = GetMenuCount(); | |
333 | for (size_t i = 0; i < menuCount; i++) | |
4bb6408c | 334 | { |
d3a80c92 | 335 | wxStripMenuCodes (wxConstCast(m_titles[i].c_str(), char), buf2); |
4bb6408c JS |
336 | if (strcmp (buf1, buf2) == 0) |
337 | return m_menus[i]->FindItem (itemString); | |
338 | } | |
339 | return -1; | |
340 | } | |
341 | ||
9874b4ee | 342 | wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const |
4bb6408c JS |
343 | { |
344 | if (itemMenu) | |
345 | *itemMenu = NULL; | |
bf6c2b35 | 346 | |
4bb6408c | 347 | wxMenuItem *item = NULL; |
9874b4ee VZ |
348 | size_t menuCount = GetMenuCount(); |
349 | for (size_t i = 0; i < menuCount; i++) | |
c71830c3 | 350 | if ((item = m_menus[i]->FindItem(id, itemMenu))) |
4bb6408c | 351 | return item; |
2d120f83 | 352 | return NULL; |
4bb6408c JS |
353 | } |
354 | ||
621793f4 JS |
355 | // Create menubar |
356 | bool wxMenuBar::CreateMenuBar(wxFrame* parent) | |
357 | { | |
2d120f83 | 358 | if (m_mainWidget) |
621793f4 | 359 | { |
1c4f8f8d | 360 | XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL); |
2d120f83 JS |
361 | /* |
362 | if (!XtIsManaged((Widget) m_mainWidget)) | |
363 | XtManageChild((Widget) m_mainWidget); | |
364 | */ | |
365 | XtMapWidget((Widget) m_mainWidget); | |
366 | return TRUE; | |
621793f4 | 367 | } |
bf6c2b35 | 368 | |
1c4f8f8d | 369 | Widget menuBarW = XmCreateMenuBar ((Widget) parent->GetMainWidget(), "MenuBar", NULL, 0); |
2d120f83 | 370 | m_mainWidget = (WXWidget) menuBarW; |
bf6c2b35 | 371 | |
9874b4ee VZ |
372 | size_t menuCount = GetMenuCount(); |
373 | for (size_t i = 0; i < menuCount; i++) | |
2d120f83 JS |
374 | { |
375 | wxMenu *menu = GetMenu(i); | |
376 | wxString title(m_titles[i]); | |
377 | menu->SetButtonWidget(menu->CreateMenu (this, menuBarW, menu, title, TRUE)); | |
bf6c2b35 | 378 | |
31528cd3 | 379 | if (strcmp (wxStripMenuCodes(title), "Help") == 0) |
2d120f83 | 380 | XtVaSetValues ((Widget) menuBarW, XmNmenuHelpWidget, (Widget) menu->GetButtonWidget(), NULL); |
ee31c392 VZ |
381 | |
382 | // tear off menu support | |
383 | #if (XmVersion >= 1002) | |
384 | if ( menu->IsTearOff() ) | |
385 | { | |
386 | XtVaSetValues(GetWidget(menu), | |
387 | XmNtearOffModel, XmTEAR_OFF_ENABLED, | |
388 | NULL); | |
6adaedf0 JS |
389 | Widget tearOff = XmGetTearOffControl(GetWidget(menu)); |
390 | wxDoChangeForegroundColour((Widget) tearOff, m_foregroundColour); | |
391 | wxDoChangeBackgroundColour((Widget) tearOff, m_backgroundColour, TRUE); | |
ee31c392 VZ |
392 | #endif |
393 | } | |
2d120f83 | 394 | } |
bf6c2b35 | 395 | |
2d120f83 JS |
396 | SetBackgroundColour(m_backgroundColour); |
397 | SetForegroundColour(m_foregroundColour); | |
398 | SetFont(m_font); | |
bf6c2b35 | 399 | |
1c4f8f8d | 400 | XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL); |
2d120f83 JS |
401 | XtRealizeWidget ((Widget) menuBarW); |
402 | XtManageChild ((Widget) menuBarW); | |
403 | SetMenuBarFrame(parent); | |
bf6c2b35 | 404 | |
2d120f83 | 405 | return TRUE; |
621793f4 JS |
406 | } |
407 | ||
408 | // Destroy menubar, but keep data structures intact so we can recreate it. | |
409 | bool wxMenuBar::DestroyMenuBar() | |
410 | { | |
2d120f83 | 411 | if (!m_mainWidget) |
621793f4 | 412 | { |
2d120f83 JS |
413 | SetMenuBarFrame((wxFrame*) NULL); |
414 | return FALSE; | |
621793f4 | 415 | } |
bf6c2b35 | 416 | |
2d120f83 JS |
417 | XtUnmanageChild ((Widget) m_mainWidget); |
418 | XtUnrealizeWidget ((Widget) m_mainWidget); | |
bf6c2b35 | 419 | |
9874b4ee VZ |
420 | size_t menuCount = GetMenuCount(); |
421 | for (size_t i = 0; i < menuCount; i++) | |
2d120f83 JS |
422 | { |
423 | wxMenu *menu = GetMenu(i); | |
424 | menu->DestroyMenu(TRUE); | |
bf6c2b35 | 425 | |
2d120f83 JS |
426 | } |
427 | XtDestroyWidget((Widget) m_mainWidget); | |
428 | m_mainWidget = (WXWidget) 0; | |
bf6c2b35 | 429 | |
2d120f83 | 430 | SetMenuBarFrame((wxFrame*) NULL); |
bf6c2b35 | 431 | |
2d120f83 | 432 | return TRUE; |
621793f4 JS |
433 | } |
434 | ||
7e1bcfa8 MB |
435 | // Since PopupMenu under Motif stills grab right mouse button events |
436 | // after it was closed, we need to delete the associated widgets to | |
437 | // allow next PopUpMenu to appear... | |
438 | void wxMenu::DestroyWidgetAndDetach() | |
50414e24 | 439 | { |
7e1bcfa8 | 440 | if (GetMainWidget()) |
c71830c3 | 441 | { |
7e1bcfa8 | 442 | wxMenu *menuParent = GetParent(); |
c71830c3 | 443 | if ( menuParent ) |
2d120f83 | 444 | { |
c71830c3 VZ |
445 | wxMenuItemList::Node *node = menuParent->GetMenuItems().GetFirst(); |
446 | while ( node ) | |
447 | { | |
7e1bcfa8 | 448 | if ( node->GetData()->GetSubMenu() == this ) |
c71830c3 VZ |
449 | { |
450 | menuParent->GetMenuItems().DeleteNode(node); | |
451 | ||
452 | break; | |
453 | } | |
454 | ||
455 | node = node->GetNext(); | |
456 | } | |
2d120f83 | 457 | } |
c71830c3 | 458 | |
7e1bcfa8 | 459 | DestroyMenu(TRUE); |
7fe7d506 | 460 | } |
c71830c3 VZ |
461 | |
462 | // Mark as no longer popped up | |
7e1bcfa8 | 463 | m_menuId = -1; |
50414e24 JS |
464 | } |
465 | ||
466 | /* | |
2d120f83 JS |
467 | * Create a popup or pulldown menu. |
468 | * Submenus of a popup will be pulldown. | |
469 | * | |
470 | */ | |
50414e24 JS |
471 | |
472 | WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, WXWidget parent, wxMenu * topMenu, const wxString& title, bool pullDown) | |
473 | { | |
2d120f83 JS |
474 | Widget menu = (Widget) 0; |
475 | Widget buttonWidget = (Widget) 0; | |
476 | Arg args[5]; | |
477 | XtSetArg (args[0], XmNnumColumns, m_numColumns); | |
4464ec9e | 478 | XtSetArg (args[1], XmNpacking, (m_numColumns > 1) ? XmPACK_COLUMN : XmPACK_TIGHT); |
bf6c2b35 | 479 | |
2d120f83 | 480 | if (!pullDown) |
50414e24 | 481 | { |
2d120f83 | 482 | menu = XmCreatePopupMenu ((Widget) parent, "popup", args, 2); |
7e1bcfa8 | 483 | #if 0 |
2d120f83 | 484 | XtAddCallback(menu, |
bf6c2b35 | 485 | XmNunmapCallback, |
2d120f83 JS |
486 | (XtCallbackProc)wxMenuPopdownCallback, |
487 | (XtPointer)this); | |
7e1bcfa8 | 488 | #endif |
50414e24 | 489 | } |
2d120f83 | 490 | else |
50414e24 | 491 | { |
2d120f83 | 492 | char mnem = wxFindMnemonic (title); |
2d120f83 | 493 | menu = XmCreatePulldownMenu ((Widget) parent, "pulldown", args, 2); |
bf6c2b35 | 494 | |
31528cd3 VZ |
495 | wxString title2(wxStripMenuCodes(title)); |
496 | wxXmString label_str(title2); | |
497 | buttonWidget = XtVaCreateManagedWidget(title2, | |
47d67540 | 498 | #if wxUSE_GADGETS |
2d120f83 | 499 | xmCascadeButtonGadgetClass, (Widget) parent, |
50414e24 | 500 | #else |
2d120f83 | 501 | xmCascadeButtonWidgetClass, (Widget) parent, |
50414e24 | 502 | #endif |
193fe989 | 503 | XmNlabelString, label_str(), |
2d120f83 JS |
504 | XmNsubMenuId, menu, |
505 | NULL); | |
bf6c2b35 | 506 | |
2d120f83 JS |
507 | if (mnem != 0) |
508 | XtVaSetValues (buttonWidget, XmNmnemonic, mnem, NULL); | |
50414e24 | 509 | } |
bf6c2b35 | 510 | |
2d120f83 | 511 | m_menuWidget = (WXWidget) menu; |
bf6c2b35 | 512 | |
2d120f83 JS |
513 | m_menuBar = menuBar; |
514 | m_topLevelMenu = topMenu; | |
bf6c2b35 | 515 | |
c71830c3 VZ |
516 | for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); |
517 | node; | |
518 | node = node->GetNext() ) | |
50414e24 | 519 | { |
c71830c3 VZ |
520 | wxMenuItem *item = node->GetData(); |
521 | ||
522 | item->CreateItem(menu, menuBar, topMenu); | |
50414e24 | 523 | } |
bf6c2b35 | 524 | |
2d120f83 JS |
525 | SetBackgroundColour(m_backgroundColour); |
526 | SetForegroundColour(m_foregroundColour); | |
527 | SetFont(m_font); | |
bf6c2b35 | 528 | |
2d120f83 | 529 | return buttonWidget; |
50414e24 JS |
530 | } |
531 | ||
532 | // Destroys the Motif implementation of the menu, | |
533 | // but maintains the wxWindows data structures so we can | |
bf6c2b35 | 534 | // do a CreateMenu again. |
50414e24 JS |
535 | void wxMenu::DestroyMenu (bool full) |
536 | { | |
c71830c3 VZ |
537 | for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); |
538 | node; | |
539 | node = node->GetNext() ) | |
50414e24 | 540 | { |
c71830c3 | 541 | wxMenuItem *item = node->GetData(); |
2d120f83 | 542 | item->SetMenuBar((wxMenuBar*) NULL); |
bf6c2b35 | 543 | |
2d120f83 | 544 | item->DestroyItem(full); |
c71830c3 | 545 | } |
bf6c2b35 | 546 | |
2d120f83 | 547 | if (m_buttonWidget) |
50414e24 | 548 | { |
2d120f83 JS |
549 | if (full) |
550 | { | |
551 | XtVaSetValues((Widget) m_buttonWidget, XmNsubMenuId, NULL, NULL); | |
552 | XtDestroyWidget ((Widget) m_buttonWidget); | |
553 | m_buttonWidget = (WXWidget) 0; | |
554 | } | |
50414e24 | 555 | } |
2d120f83 | 556 | if (m_menuWidget && full) |
50414e24 | 557 | { |
2d120f83 JS |
558 | XtDestroyWidget((Widget) m_menuWidget); |
559 | m_menuWidget = (WXWidget) NULL; | |
50414e24 JS |
560 | } |
561 | } | |
562 | ||
563 | WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const | |
564 | { | |
2d120f83 | 565 | if (id == m_menuId) |
50414e24 | 566 | { |
2d120f83 JS |
567 | if (it) |
568 | *it = (wxMenuItem*) NULL; | |
569 | return m_buttonWidget; | |
50414e24 | 570 | } |
bf6c2b35 | 571 | |
c71830c3 VZ |
572 | for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); |
573 | node; | |
574 | node = node->GetNext() ) | |
50414e24 | 575 | { |
c71830c3 | 576 | wxMenuItem *item = node->GetData (); |
2d120f83 JS |
577 | if (item->GetId() == id) |
578 | { | |
579 | if (it) | |
580 | *it = item; | |
581 | return item->GetButtonWidget(); | |
582 | } | |
bf6c2b35 | 583 | |
2d120f83 JS |
584 | if (item->GetSubMenu()) |
585 | { | |
586 | WXWidget w = item->GetSubMenu()->FindMenuItem (id, it); | |
587 | if (w) | |
588 | { | |
589 | return w; | |
590 | } | |
591 | } | |
c71830c3 | 592 | } |
bf6c2b35 | 593 | |
2d120f83 JS |
594 | if (it) |
595 | *it = (wxMenuItem*) NULL; | |
596 | return (WXWidget) NULL; | |
50414e24 | 597 | } |
94b49b93 JS |
598 | |
599 | void wxMenu::SetBackgroundColour(const wxColour& col) | |
600 | { | |
601 | m_backgroundColour = col; | |
602 | if (m_menuWidget) | |
2d120f83 | 603 | wxDoChangeBackgroundColour(m_menuWidget, (wxColour&) col); |
94b49b93 | 604 | if (m_buttonWidget) |
2d120f83 | 605 | wxDoChangeBackgroundColour(m_buttonWidget, (wxColour&) col, TRUE); |
bf6c2b35 | 606 | |
c71830c3 VZ |
607 | for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); |
608 | node; | |
609 | node = node->GetNext() ) | |
94b49b93 | 610 | { |
c71830c3 | 611 | wxMenuItem* item = node->GetData(); |
94b49b93 JS |
612 | if (item->GetButtonWidget()) |
613 | { | |
2d120f83 JS |
614 | // This crashes because it uses gadgets |
615 | // wxDoChangeBackgroundColour(item->GetButtonWidget(), (wxColour&) col, TRUE); | |
94b49b93 JS |
616 | } |
617 | if (item->GetSubMenu()) | |
2d120f83 | 618 | item->GetSubMenu()->SetBackgroundColour((wxColour&) col); |
94b49b93 JS |
619 | } |
620 | } | |
621 | ||
622 | void wxMenu::SetForegroundColour(const wxColour& col) | |
623 | { | |
624 | m_foregroundColour = col; | |
625 | if (m_menuWidget) | |
2d120f83 | 626 | wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col); |
94b49b93 | 627 | if (m_buttonWidget) |
2d120f83 | 628 | wxDoChangeForegroundColour(m_buttonWidget, (wxColour&) col); |
bf6c2b35 | 629 | |
c71830c3 VZ |
630 | for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst(); |
631 | node; | |
632 | node = node->GetNext() ) | |
94b49b93 | 633 | { |
c71830c3 | 634 | wxMenuItem* item = node->GetData(); |
94b49b93 JS |
635 | if (item->GetButtonWidget()) |
636 | { | |
2d120f83 JS |
637 | // This crashes because it uses gadgets |
638 | // wxDoChangeForegroundColour(item->GetButtonWidget(), (wxColour&) col); | |
94b49b93 JS |
639 | } |
640 | if (item->GetSubMenu()) | |
2d120f83 | 641 | item->GetSubMenu()->SetForegroundColour((wxColour&) col); |
94b49b93 JS |
642 | } |
643 | } | |
644 | ||
645 | void wxMenu::ChangeFont(bool keepOriginalSize) | |
646 | { | |
da494b40 MB |
647 | // Lesstif 0.87 hangs here, but 0.93 does not |
648 | #if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 ) | |
94b49b93 JS |
649 | if (!m_font.Ok() || !m_menuWidget) |
650 | return; | |
bf6c2b35 | 651 | |
da494b40 | 652 | WXFontType fontType = m_font.GetFontType(XtDisplay((Widget) m_menuWidget)); |
bf6c2b35 | 653 | |
94b49b93 | 654 | XtVaSetValues ((Widget) m_menuWidget, |
da494b40 MB |
655 | wxFont::GetFontTag(), fontType, |
656 | NULL); | |
94b49b93 JS |
657 | if (m_buttonWidget) |
658 | { | |
2d120f83 | 659 | XtVaSetValues ((Widget) m_buttonWidget, |
da494b40 MB |
660 | wxFont::GetFontTag(), fontType, |
661 | NULL); | |
94b49b93 | 662 | } |
c71830c3 VZ |
663 | |
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 (m_menuWidget && item->GetButtonWidget() && m_font.Ok()) |
670 | { | |
2d120f83 | 671 | XtVaSetValues ((Widget) item->GetButtonWidget(), |
da494b40 MB |
672 | wxFont::GetFontTag(), fontType, |
673 | NULL); | |
94b49b93 JS |
674 | } |
675 | if (item->GetSubMenu()) | |
2d120f83 | 676 | item->GetSubMenu()->ChangeFont(keepOriginalSize); |
94b49b93 JS |
677 | } |
678 | #endif | |
679 | } | |
680 | ||
681 | void wxMenu::SetFont(const wxFont& font) | |
682 | { | |
683 | m_font = font; | |
684 | ChangeFont(); | |
685 | } | |
686 | ||
9874b4ee | 687 | bool wxMenuBar::SetBackgroundColour(const wxColour& col) |
94b49b93 | 688 | { |
94b49b93 JS |
689 | m_backgroundColour = col; |
690 | if (m_mainWidget) | |
2d120f83 | 691 | wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col); |
9874b4ee VZ |
692 | |
693 | size_t menuCount = GetMenuCount(); | |
694 | for (size_t i = 0; i < menuCount; i++) | |
2d120f83 | 695 | m_menus[i]->SetBackgroundColour((wxColour&) col); |
9874b4ee VZ |
696 | |
697 | return TRUE; | |
94b49b93 JS |
698 | } |
699 | ||
9874b4ee | 700 | bool wxMenuBar::SetForegroundColour(const wxColour& col) |
94b49b93 JS |
701 | { |
702 | m_foregroundColour = col; | |
703 | if (m_mainWidget) | |
2d120f83 | 704 | wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col); |
bf6c2b35 | 705 | |
9874b4ee VZ |
706 | size_t menuCount = GetMenuCount(); |
707 | for (size_t i = 0; i < menuCount; i++) | |
2d120f83 | 708 | m_menus[i]->SetForegroundColour((wxColour&) col); |
9874b4ee VZ |
709 | |
710 | return TRUE; | |
94b49b93 JS |
711 | } |
712 | ||
af111fc3 | 713 | void wxMenuBar::ChangeFont(bool WXUNUSED(keepOriginalSize)) |
94b49b93 | 714 | { |
2d120f83 | 715 | // Nothing to do for menubar, fonts are kept in wxMenus |
94b49b93 JS |
716 | } |
717 | ||
9874b4ee | 718 | bool wxMenuBar::SetFont(const wxFont& font) |
94b49b93 JS |
719 | { |
720 | m_font = font; | |
721 | ChangeFont(); | |
bf6c2b35 | 722 | |
9874b4ee VZ |
723 | size_t menuCount = GetMenuCount(); |
724 | for (size_t i = 0; i < menuCount; i++) | |
2d120f83 | 725 | m_menus[i]->SetFont(font); |
9874b4ee VZ |
726 | |
727 | return TRUE; | |
94b49b93 JS |
728 | } |
729 |