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