fix crash in wxWindowGTK::GTKHandleUnrealize(), closes #14752
[wxWidgets.git] / src / gtk / menu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/menu.cpp
3 // Purpose: implementation of wxMenuBar and wxMenu classes for wxGTK
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #if wxUSE_MENUS
14
15 #include "wx/menu.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/log.h"
20 #include "wx/frame.h"
21 #include "wx/bitmap.h"
22 #include "wx/app.h"
23 #endif
24
25 #include "wx/accel.h"
26 #include "wx/stockitem.h"
27
28 #include <gtk/gtk.h>
29 #include "wx/gtk/private.h"
30 #include "wx/gtk/private/gtk2-compat.h"
31 #include "wx/gtk/private/mnemonics.h"
32
33 // we use normal item but with a special id for the menu title
34 static const int wxGTK_TITLE_ID = -3;
35
36 // forward declare it as it's used by wxMenuBar too when using Hildon
37 extern "C"
38 {
39 static void menuitem_activate(GtkWidget*, wxMenuItem* item);
40 }
41
42 #if wxUSE_ACCEL
43 static void wxGetGtkAccel(const wxMenuItem*, guint*, GdkModifierType*);
44 #endif
45
46 static void DoCommonMenuCallbackCode(wxMenu *menu, wxMenuEvent& event)
47 {
48 event.SetEventObject( menu );
49
50 wxEvtHandler* handler = menu->GetEventHandler();
51 if (handler && handler->SafelyProcessEvent(event))
52 return;
53
54 wxWindow *win = menu->GetWindow();
55 wxCHECK_RET( win, "event for a menu without associated window?" );
56
57 win->HandleWindowEvent( event );
58 }
59
60 //-----------------------------------------------------------------------------
61 // wxMenuBar
62 //-----------------------------------------------------------------------------
63
64 wxMenuBar::~wxMenuBar()
65 {
66 if (m_widget && IsAttached())
67 {
68 // Work around a probable bug in Ubuntu 12.04 which causes a warning if
69 // gtk_widget_destroy() is called on a wxMenuBar attached to a frame
70 GtkWidget* widget = m_widget;
71 m_focusWidget =
72 m_widget = NULL;
73 g_signal_handlers_disconnect_matched(widget,
74 GSignalMatchType(G_SIGNAL_MATCH_DATA), 0, 0, NULL, NULL, this);
75 g_object_unref(widget);
76 }
77 }
78
79 void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long style)
80 {
81 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
82 // Hildon window uses a single menu instead of a menu bar, so wxMenuBar is
83 // the same as menu in this case
84 m_widget =
85 m_menubar = gtk_menu_new();
86 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
87 if (!PreCreation( NULL, wxDefaultPosition, wxDefaultSize ) ||
88 !CreateBase( NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
89 {
90 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
91 return;
92 }
93
94 m_menubar = gtk_menu_bar_new();
95
96 if (style & wxMB_DOCKABLE)
97 {
98 m_widget = gtk_handle_box_new();
99 gtk_container_add(GTK_CONTAINER(m_widget), m_menubar);
100 gtk_widget_show(m_menubar);
101 }
102 else
103 {
104 m_widget = m_menubar;
105 }
106
107 PostCreation();
108
109 GTKApplyWidgetStyle();
110 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
111
112 g_object_ref_sink(m_widget);
113
114 for (size_t i = 0; i < n; ++i )
115 Append(menus[i], titles[i]);
116 }
117
118 wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style)
119 {
120 Init(n, menus, titles, style);
121 }
122
123 wxMenuBar::wxMenuBar(long style)
124 {
125 Init(0, NULL, NULL, style);
126 }
127
128 wxMenuBar::wxMenuBar()
129 {
130 Init(0, NULL, NULL, 0);
131 }
132
133 // recursive helpers for wxMenuBar::Attach() and Detach(): they are called to
134 // associate the menus with the frame they belong to or dissociate them from it
135 namespace
136 {
137
138 void
139 DetachFromFrame(wxMenu* menu, wxFrame* frame)
140 {
141 // support for native hot keys
142 if (menu->m_accel)
143 {
144 // Note that wxGetTopLevelParent() is really needed because this frame
145 // can be an MDI child frame which is a fake frame and not a TLW at all
146 GtkWindow * const tlw = GTK_WINDOW(wxGetTopLevelParent(frame)->m_widget);
147 if (g_slist_find(gtk_accel_groups_from_object(G_OBJECT(tlw)), menu->m_accel))
148 gtk_window_remove_accel_group(tlw, menu->m_accel);
149 }
150
151 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
152 while (node)
153 {
154 wxMenuItem *menuitem = node->GetData();
155 if (menuitem->IsSubMenu())
156 DetachFromFrame(menuitem->GetSubMenu(), frame);
157 node = node->GetNext();
158 }
159 }
160
161 void
162 AttachToFrame(wxMenu* menu, wxFrame* frame)
163 {
164 // support for native hot keys
165 if (menu->m_accel)
166 {
167 GtkWindow * const tlw = GTK_WINDOW(wxGetTopLevelParent(frame)->m_widget);
168 if (!g_slist_find(gtk_accel_groups_from_object(G_OBJECT(tlw)), menu->m_accel))
169 gtk_window_add_accel_group(tlw, menu->m_accel);
170 }
171
172 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
173 while (node)
174 {
175 wxMenuItem *menuitem = node->GetData();
176 if (menuitem->IsSubMenu())
177 AttachToFrame(menuitem->GetSubMenu(), frame);
178 node = node->GetNext();
179 }
180 }
181
182 } // anonymous namespace
183
184 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir)
185 {
186 if ( dir == wxLayout_Default )
187 {
188 const wxWindow *const frame = GetFrame();
189 if ( frame )
190 {
191 // inherit layout from frame.
192 dir = frame->GetLayoutDirection();
193 }
194 else // use global layout
195 {
196 dir = wxTheApp->GetLayoutDirection();
197 }
198 }
199
200 if ( dir == wxLayout_Default )
201 return;
202
203 GTKSetLayout(m_menubar, dir);
204
205 // also set the layout of all menus we already have (new ones will inherit
206 // the current layout)
207 for ( wxMenuList::compatibility_iterator node = m_menus.GetFirst();
208 node;
209 node = node->GetNext() )
210 {
211 wxMenu *const menu = node->GetData();
212 menu->SetLayoutDirection(dir);
213 }
214 }
215
216 wxLayoutDirection wxMenuBar::GetLayoutDirection() const
217 {
218 return GTKGetLayout(m_menubar);
219 }
220
221 void wxMenuBar::Attach(wxFrame *frame)
222 {
223 wxMenuBarBase::Attach(frame);
224
225 wxMenuList::compatibility_iterator node = m_menus.GetFirst();
226 while (node)
227 {
228 wxMenu *menu = node->GetData();
229 AttachToFrame( menu, frame );
230 node = node->GetNext();
231 }
232
233 SetLayoutDirection(wxLayout_Default);
234 }
235
236 void wxMenuBar::Detach()
237 {
238 wxMenuList::compatibility_iterator node = m_menus.GetFirst();
239 while (node)
240 {
241 wxMenu *menu = node->GetData();
242 DetachFromFrame( menu, m_menuBarFrame );
243 node = node->GetNext();
244 }
245
246 wxMenuBarBase::Detach();
247 }
248
249 bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
250 {
251 if (wxMenuBarBase::Append(menu, title))
252 {
253 GtkAppend(menu, title);
254 return true;
255 }
256 return false;
257 }
258
259 void wxMenuBar::GtkAppend(wxMenu* menu, const wxString& title, int pos)
260 {
261 menu->SetLayoutDirection(GetLayoutDirection());
262
263 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
264 // if the menu has only one item, append it directly to the top level menu
265 // instead of inserting a useless submenu
266 if ( menu->GetMenuItemCount() == 1 )
267 {
268 wxMenuItem * const item = menu->FindItemByPosition(0);
269
270 // remove both mnemonics and accelerator: neither is useful under Maemo
271 const wxString str(wxStripMenuCodes(item->GetItemLabel()));
272
273 if ( item->IsSubMenu() )
274 {
275 GtkAppend(item->GetSubMenu(), str, pos);
276 return;
277 }
278
279 menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) );
280
281 g_signal_connect(menu->m_owner, "activate",
282 G_CALLBACK(menuitem_activate), item);
283 item->SetMenuItem(menu->m_owner);
284 }
285 else
286 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
287 {
288 const wxString str(wxConvertMnemonicsToGTK(title));
289
290 // This doesn't have much effect right now.
291 menu->SetTitle( str );
292
293 // The "m_owner" is the "menu item"
294 menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) );
295
296 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
297 }
298
299 gtk_widget_show( menu->m_owner );
300
301 if (pos == -1)
302 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar), menu->m_owner );
303 else
304 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar), menu->m_owner, pos );
305
306 if ( m_menuBarFrame )
307 AttachToFrame( menu, m_menuBarFrame );
308 }
309
310 bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
311 {
312 if (wxMenuBarBase::Insert(pos, menu, title))
313 {
314 GtkAppend(menu, title, int(pos));
315 return true;
316 }
317 return false;
318 }
319
320 wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
321 {
322 // remove the old item and insert a new one
323 wxMenu *menuOld = Remove(pos);
324 if ( menuOld && !Insert(pos, menu, title) )
325 {
326 return NULL;
327 }
328
329 // either Insert() succeeded or Remove() failed and menuOld is NULL
330 return menuOld;
331 }
332
333 wxMenu *wxMenuBar::Remove(size_t pos)
334 {
335 wxMenu *menu = wxMenuBarBase::Remove(pos);
336 if ( !menu )
337 return NULL;
338
339 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu->m_owner), NULL);
340 gtk_container_remove(GTK_CONTAINER(m_menubar), menu->m_owner);
341
342 gtk_widget_destroy( menu->m_owner );
343 menu->m_owner = NULL;
344
345 if ( m_menuBarFrame )
346 DetachFromFrame( menu, m_menuBarFrame );
347
348 return menu;
349 }
350
351 static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
352 {
353 if (wxMenuItem::GetLabelText(menu->GetTitle()) == wxMenuItem::GetLabelText(menuString))
354 {
355 int res = menu->FindItem( itemString );
356 if (res != wxNOT_FOUND)
357 return res;
358 }
359
360 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
361 while (node)
362 {
363 wxMenuItem *item = node->GetData();
364 if (item->IsSubMenu())
365 return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
366
367 node = node->GetNext();
368 }
369
370 return wxNOT_FOUND;
371 }
372
373 int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
374 {
375 wxMenuList::compatibility_iterator node = m_menus.GetFirst();
376 while (node)
377 {
378 wxMenu *menu = node->GetData();
379 int res = FindMenuItemRecursive( menu, menuString, itemString);
380 if (res != -1)
381 return res;
382 node = node->GetNext();
383 }
384
385 return wxNOT_FOUND;
386 }
387
388 // Find a wxMenuItem using its id. Recurses down into sub-menus
389 static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id)
390 {
391 wxMenuItem* result = menu->FindChildItem(id);
392
393 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
394 while ( node && result == NULL )
395 {
396 wxMenuItem *item = node->GetData();
397 if (item->IsSubMenu())
398 {
399 result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
400 }
401 node = node->GetNext();
402 }
403
404 return result;
405 }
406
407 wxMenuItem* wxMenuBar::FindItem( int id, wxMenu **menuForItem ) const
408 {
409 wxMenuItem* result = 0;
410 wxMenuList::compatibility_iterator node = m_menus.GetFirst();
411 while (node && result == 0)
412 {
413 wxMenu *menu = node->GetData();
414 result = FindMenuItemByIdRecursive( menu, id );
415 node = node->GetNext();
416 }
417
418 if ( menuForItem )
419 {
420 *menuForItem = result ? result->GetMenu() : NULL;
421 }
422
423 return result;
424 }
425
426 void wxMenuBar::EnableTop( size_t pos, bool flag )
427 {
428 wxMenuList::compatibility_iterator node = m_menus.Item( pos );
429
430 wxCHECK_RET( node, wxT("menu not found") );
431
432 wxMenu* menu = node->GetData();
433
434 if (menu->m_owner)
435 gtk_widget_set_sensitive( menu->m_owner, flag );
436 }
437
438 bool wxMenuBar::IsEnabledTop(size_t pos) const
439 {
440 wxMenuList::compatibility_iterator node = m_menus.Item( pos );
441 wxCHECK_MSG( node, false, wxS("invalid index in IsEnabledTop") );
442 wxMenu* const menu = node->GetData();
443 wxCHECK_MSG( menu->m_owner, true, wxS("no menu owner?") );
444 return gtk_widget_get_sensitive( menu->m_owner ) != 0;
445 }
446
447 wxString wxMenuBar::GetMenuLabel( size_t pos ) const
448 {
449 wxMenuList::compatibility_iterator node = m_menus.Item( pos );
450
451 wxCHECK_MSG( node, wxT("invalid"), wxT("menu not found") );
452
453 wxMenu* menu = node->GetData();
454
455 return menu->GetTitle();
456 }
457
458 void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label )
459 {
460 wxMenuList::compatibility_iterator node = m_menus.Item( pos );
461
462 wxCHECK_RET( node, wxT("menu not found") );
463
464 wxMenu* menu = node->GetData();
465
466 const wxString str(wxConvertMnemonicsToGTK(label));
467
468 menu->SetTitle( str );
469
470 if (menu->m_owner)
471 gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menu->m_owner))), wxGTK_CONV(str));
472 }
473
474 //-----------------------------------------------------------------------------
475 // "activate"
476 //-----------------------------------------------------------------------------
477
478 extern "C" {
479 static void menuitem_activate(GtkWidget*, wxMenuItem* item)
480 {
481 if (!item->IsEnabled())
482 return;
483
484 int id = item->GetId();
485 if (id == wxGTK_TITLE_ID)
486 {
487 // ignore events from the menu title
488 return;
489 }
490
491 if (item->IsCheckable())
492 {
493 bool isReallyChecked = item->IsChecked(),
494 isInternallyChecked = item->wxMenuItemBase::IsChecked();
495
496 // ensure that the internal state is always consistent with what is
497 // shown on the screen
498 item->wxMenuItemBase::Check(isReallyChecked);
499
500 // we must not report the events for the radio button going up nor the
501 // events resulting from the calls to wxMenuItem::Check()
502 if ( (item->GetKind() == wxITEM_RADIO && !isReallyChecked) ||
503 (isInternallyChecked == isReallyChecked) )
504 {
505 return;
506 }
507 }
508
509 wxMenu* menu = item->GetMenu();
510 menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
511 }
512 }
513
514 //-----------------------------------------------------------------------------
515 // "select"
516 //-----------------------------------------------------------------------------
517
518 extern "C" {
519 static void menuitem_select(GtkWidget*, wxMenuItem* item)
520 {
521 if (!item->IsEnabled())
522 return;
523
524 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item->GetId());
525 DoCommonMenuCallbackCode(item->GetMenu(), event);
526 }
527 }
528
529 //-----------------------------------------------------------------------------
530 // "deselect"
531 //-----------------------------------------------------------------------------
532
533 extern "C" {
534 static void menuitem_deselect(GtkWidget*, wxMenuItem* item)
535 {
536 if (!item->IsEnabled())
537 return;
538
539 wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
540 DoCommonMenuCallbackCode(item->GetMenu(), event);
541 }
542 }
543
544 //-----------------------------------------------------------------------------
545 // wxMenuItem
546 //-----------------------------------------------------------------------------
547
548 wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
549 int id,
550 const wxString& name,
551 const wxString& help,
552 wxItemKind kind,
553 wxMenu *subMenu)
554 {
555 return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
556 }
557
558 wxMenuItem::wxMenuItem(wxMenu *parentMenu,
559 int id,
560 const wxString& text,
561 const wxString& help,
562 wxItemKind kind,
563 wxMenu *subMenu)
564 : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
565 {
566 m_menuItem = NULL;
567 }
568
569 #if WXWIN_COMPATIBILITY_2_8
570 wxMenuItem::wxMenuItem(wxMenu *parentMenu,
571 int id,
572 const wxString& text,
573 const wxString& help,
574 bool isCheckable,
575 wxMenu *subMenu)
576 : wxMenuItemBase(parentMenu, id, text, help,
577 isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu)
578 {
579 m_menuItem = NULL;
580 }
581 #endif
582
583 wxMenuItem::~wxMenuItem()
584 {
585 // don't delete menu items, the menus take care of that
586 }
587
588 void wxMenuItem::SetItemLabel( const wxString& str )
589 {
590 #if wxUSE_ACCEL
591 if (m_menuItem)
592 {
593 // remove old accelerator
594 guint accel_key;
595 GdkModifierType accel_mods;
596 wxGetGtkAccel(this, &accel_key, &accel_mods);
597 if (accel_key)
598 {
599 gtk_widget_remove_accelerator(
600 m_menuItem, m_parentMenu->m_accel, accel_key, accel_mods);
601 }
602 }
603 #endif // wxUSE_ACCEL
604 wxMenuItemBase::SetItemLabel(str);
605 if (m_menuItem)
606 SetGtkLabel();
607 }
608
609 void wxMenuItem::SetGtkLabel()
610 {
611 const wxString text = wxConvertMnemonicsToGTK(m_text.BeforeFirst('\t'));
612 GtkLabel* label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(m_menuItem)));
613 gtk_label_set_text_with_mnemonic(label, wxGTK_CONV_SYS(text));
614 #if wxUSE_ACCEL
615 guint accel_key;
616 GdkModifierType accel_mods;
617 wxGetGtkAccel(this, &accel_key, &accel_mods);
618 if (accel_key)
619 {
620 gtk_widget_add_accelerator(
621 m_menuItem, "activate", m_parentMenu->m_accel,
622 accel_key, accel_mods, GTK_ACCEL_VISIBLE);
623 }
624 #endif // wxUSE_ACCEL
625 }
626
627 void wxMenuItem::SetBitmap(const wxBitmap& bitmap)
628 {
629 if (m_kind == wxITEM_NORMAL)
630 m_bitmap = bitmap;
631 else
632 {
633 wxFAIL_MSG("only normal menu items can have bitmaps");
634 }
635 }
636
637 void wxMenuItem::Check( bool check )
638 {
639 wxCHECK_RET( m_menuItem, wxT("invalid menu item") );
640
641 if (check == m_isChecked)
642 return;
643
644 wxMenuItemBase::Check( check );
645
646 switch ( GetKind() )
647 {
648 case wxITEM_CHECK:
649 case wxITEM_RADIO:
650 gtk_check_menu_item_set_active( (GtkCheckMenuItem*)m_menuItem, (gint)check );
651 break;
652
653 default:
654 wxFAIL_MSG( wxT("can't check this item") );
655 }
656 }
657
658 void wxMenuItem::Enable( bool enable )
659 {
660 wxCHECK_RET( m_menuItem, wxT("invalid menu item") );
661
662 gtk_widget_set_sensitive( m_menuItem, enable );
663 wxMenuItemBase::Enable( enable );
664 }
665
666 bool wxMenuItem::IsChecked() const
667 {
668 wxCHECK_MSG( m_menuItem, false, wxT("invalid menu item") );
669
670 wxCHECK_MSG( IsCheckable(), false,
671 wxT("can't get state of uncheckable item!") );
672
673 return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(m_menuItem)) != 0;
674 }
675
676 //-----------------------------------------------------------------------------
677 // wxMenu
678 //-----------------------------------------------------------------------------
679
680 extern "C" {
681 // "map" from m_menu
682 static void menu_map(GtkWidget*, wxMenu* menu)
683 {
684 wxMenuEvent event(wxEVT_MENU_OPEN, menu->m_popupShown ? -1 : 0, menu);
685 DoCommonMenuCallbackCode(menu, event);
686 }
687
688 // "hide" from m_menu
689 static void menu_hide(GtkWidget*, wxMenu* menu)
690 {
691 // When using Ubuntu Unity desktop environment we get "hide" signal even
692 // when the window is not shown yet because Unity hides all the menus to
693 // show them only in the global menu bar. Just ignore this even instead of
694 // crashing in DoCommonMenuCallbackCode().
695 if ( !menu->GetWindow() )
696 return;
697
698 wxMenuEvent event(wxEVT_MENU_CLOSE, menu->m_popupShown ? -1 : 0, menu);
699 menu->m_popupShown = false;
700 DoCommonMenuCallbackCode(menu, event);
701 }
702 }
703
704 // "can_activate_accel" from menu item
705 extern "C" {
706 static gboolean can_activate_accel(GtkWidget*, guint, wxMenu* menu)
707 {
708 menu->UpdateUI();
709 // always allow our "activate" handler to be called
710 return true;
711 }
712 }
713
714 void wxMenu::Init()
715 {
716 m_popupShown = false;
717
718 m_accel = gtk_accel_group_new();
719 m_menu = gtk_menu_new();
720 // NB: keep reference to the menu so that it is not destroyed behind
721 // our back by GTK+ e.g. when it is removed from menubar:
722 g_object_ref_sink(m_menu);
723
724 m_owner = NULL;
725
726 // Tearoffs are entries, just like separators. So if we want this
727 // menu to be a tear-off one, we just append a tearoff entry
728 // immediately.
729 if ( m_style & wxMENU_TEAROFF )
730 {
731 GtkWidget *tearoff = gtk_tearoff_menu_item_new();
732
733 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), tearoff);
734 }
735
736 // append the title as the very first entry if we have it
737 if ( !m_title.empty() )
738 {
739 Append(wxGTK_TITLE_ID, m_title);
740 AppendSeparator();
741 }
742
743 // "show" occurs for sub-menus which are not showing, so use "map" instead
744 g_signal_connect(m_menu, "map", G_CALLBACK(menu_map), this);
745 g_signal_connect(m_menu, "hide", G_CALLBACK(menu_hide), this);
746 }
747
748 wxMenu::~wxMenu()
749 {
750 // Destroying a menu generates a "hide" signal even if it's not shown
751 // currently, so disconnect it to avoid dummy wxEVT_MENU_CLOSE events
752 // generation.
753 g_signal_handlers_disconnect_by_func(m_menu, (gpointer)menu_hide, this);
754
755 // see wxMenu::Init
756 g_object_unref(m_menu);
757
758 // if the menu is inserted in another menu at this time, there was
759 // one more reference to it:
760 if (m_owner)
761 gtk_widget_destroy(m_menu);
762
763 g_object_unref(m_accel);
764 }
765
766 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir)
767 {
768 if ( m_owner )
769 wxWindow::GTKSetLayout(m_owner, dir);
770 //else: will be called later by wxMenuBar again
771 }
772
773 wxLayoutDirection wxMenu::GetLayoutDirection() const
774 {
775 return wxWindow::GTKGetLayout(m_owner);
776 }
777
778 wxString wxMenu::GetTitle() const
779 {
780 return wxConvertMnemonicsFromGTK(wxMenuBase::GetTitle());
781 }
782
783 void wxMenu::GtkAppend(wxMenuItem* mitem, int pos)
784 {
785 GtkWidget *menuItem;
786 switch (mitem->GetKind())
787 {
788 case wxITEM_SEPARATOR:
789 menuItem = gtk_separator_menu_item_new();
790 break;
791 case wxITEM_CHECK:
792 menuItem = gtk_check_menu_item_new_with_label("");
793 break;
794 case wxITEM_RADIO:
795 {
796 // See if we need to create a new radio group for this item or
797 // add it to an existing one.
798 wxMenuItem* radioGroupItem = NULL;
799
800 const size_t numItems = GetMenuItemCount();
801 const size_t n = pos == -1 ? numItems - 1 : size_t(pos);
802
803 if (n != 0)
804 {
805 wxMenuItem* const itemPrev = FindItemByPosition(n - 1);
806 if ( itemPrev->GetKind() == wxITEM_RADIO )
807 {
808 // Appending an item after an existing radio item puts
809 // it into the same radio group.
810 radioGroupItem = itemPrev;
811 }
812 }
813
814 if (radioGroupItem == NULL && n != numItems - 1)
815 {
816 wxMenuItem* const itemNext = FindItemByPosition(n + 1);
817 if ( itemNext->GetKind() == wxITEM_RADIO )
818 {
819 // Inserting an item before an existing radio item
820 // also puts it into the existing radio group.
821 radioGroupItem = itemNext;
822 }
823 }
824
825 GSList* group = NULL;
826 if ( radioGroupItem )
827 {
828 group = gtk_radio_menu_item_get_group(
829 GTK_RADIO_MENU_ITEM(radioGroupItem->GetMenuItem())
830 );
831 }
832
833 menuItem = gtk_radio_menu_item_new_with_label(group, "");
834 }
835 break;
836 default:
837 wxFAIL_MSG("unexpected menu item kind");
838 // fall through
839 case wxITEM_NORMAL:
840 const wxBitmap& bitmap = mitem->GetBitmap();
841 const char* stockid;
842 if (bitmap.IsOk())
843 {
844 // always use pixbuf, because pixmap mask does not
845 // work with disabled images in some themes
846 GtkWidget* image = gtk_image_new_from_pixbuf(bitmap.GetPixbuf());
847 menuItem = gtk_image_menu_item_new_with_label("");
848 gtk_widget_show(image);
849 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuItem), image);
850 }
851 else if ((stockid = wxGetStockGtkID(mitem->GetId())) != NULL)
852 // use stock bitmap for this item if available on the assumption
853 // that it never hurts to follow GTK+ conventions more closely
854 menuItem = gtk_image_menu_item_new_from_stock(stockid, NULL);
855 else
856 menuItem = gtk_menu_item_new_with_label("");
857 break;
858 }
859 mitem->SetMenuItem(menuItem);
860
861 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos);
862
863 gtk_widget_show( menuItem );
864
865 if ( !mitem->IsSeparator() )
866 {
867 mitem->SetGtkLabel();
868 g_signal_connect (menuItem, "select",
869 G_CALLBACK(menuitem_select), mitem);
870 g_signal_connect (menuItem, "deselect",
871 G_CALLBACK(menuitem_deselect), mitem);
872
873 if ( mitem->IsSubMenu() && mitem->GetKind() != wxITEM_RADIO && mitem->GetKind() != wxITEM_CHECK )
874 {
875 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
876
877 gtk_widget_show( mitem->GetSubMenu()->m_menu );
878 }
879 else
880 {
881 g_signal_connect(menuItem, "can_activate_accel",
882 G_CALLBACK(can_activate_accel), this);
883 g_signal_connect (menuItem, "activate",
884 G_CALLBACK(menuitem_activate),
885 mitem);
886 }
887 }
888 }
889
890 wxMenuItem* wxMenu::DoAppend(wxMenuItem *mitem)
891 {
892 if (wxMenuBase::DoAppend(mitem))
893 {
894 GtkAppend(mitem);
895 return mitem;
896 }
897 return NULL;
898 }
899
900 wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
901 {
902 if (wxMenuBase::DoInsert(pos, item))
903 {
904 GtkAppend(item, int(pos));
905 return item;
906 }
907 return NULL;
908 }
909
910 wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
911 {
912 if ( !wxMenuBase::DoRemove(item) )
913 return NULL;
914
915 GtkWidget * const mitem = item->GetMenuItem();
916 #ifdef __WXGTK3__
917 gtk_menu_item_set_submenu(GTK_MENU_ITEM(mitem), NULL);
918 #else
919 if (!gtk_check_version(2,12,0))
920 {
921 // gtk_menu_item_remove_submenu() is deprecated since 2.12, but
922 // gtk_menu_item_set_submenu() can now be used with NULL submenu now so
923 // just do use it.
924 gtk_menu_item_set_submenu(GTK_MENU_ITEM(mitem), NULL);
925 }
926 else // GTK+ < 2.12
927 {
928 // In 2.10 calling gtk_menu_item_set_submenu() with NULL submenu
929 // results in critical GTK+ error messages so use the old function
930 // instead.
931 gtk_menu_item_remove_submenu(GTK_MENU_ITEM(mitem));
932 }
933 #endif
934
935 gtk_widget_destroy(mitem);
936 item->SetMenuItem(NULL);
937
938 return item;
939 }
940
941 void wxMenu::Attach(wxMenuBarBase *menubar)
942 {
943 wxMenuBase::Attach(menubar);
944
945 // inherit layout direction from menubar.
946 SetLayoutDirection(menubar->GetLayoutDirection());
947 }
948
949 // ----------------------------------------------------------------------------
950 // helpers
951 // ----------------------------------------------------------------------------
952
953 #if wxUSE_ACCEL
954
955 static wxString GetGtkHotKey( const wxMenuItem& item )
956 {
957 wxString hotkey;
958
959 wxAcceleratorEntry *accel = item.GetAccel();
960 if ( accel )
961 {
962 int flags = accel->GetFlags();
963 if ( flags & wxACCEL_ALT )
964 hotkey += wxT("<alt>");
965 if ( flags & wxACCEL_CTRL )
966 hotkey += wxT("<control>");
967 if ( flags & wxACCEL_SHIFT )
968 hotkey += wxT("<shift>");
969
970 int code = accel->GetKeyCode();
971 switch ( code )
972 {
973 case WXK_F1:
974 case WXK_F2:
975 case WXK_F3:
976 case WXK_F4:
977 case WXK_F5:
978 case WXK_F6:
979 case WXK_F7:
980 case WXK_F8:
981 case WXK_F9:
982 case WXK_F10:
983 case WXK_F11:
984 case WXK_F12:
985 case WXK_F13:
986 case WXK_F14:
987 case WXK_F15:
988 case WXK_F16:
989 case WXK_F17:
990 case WXK_F18:
991 case WXK_F19:
992 case WXK_F20:
993 case WXK_F21:
994 case WXK_F22:
995 case WXK_F23:
996 case WXK_F24:
997 hotkey += wxString::Format(wxT("F%d"), code - WXK_F1 + 1);
998 break;
999
1000 // TODO: we should use gdk_keyval_name() (a.k.a.
1001 // XKeysymToString) here as well as hardcoding the keysym
1002 // names this might be not portable
1003 case WXK_INSERT:
1004 hotkey << wxT("Insert" );
1005 break;
1006 case WXK_DELETE:
1007 hotkey << wxT("Delete" );
1008 break;
1009 case WXK_UP:
1010 hotkey << wxT("Up" );
1011 break;
1012 case WXK_DOWN:
1013 hotkey << wxT("Down" );
1014 break;
1015 case WXK_PAGEUP:
1016 hotkey << wxT("Page_Up" );
1017 break;
1018 case WXK_PAGEDOWN:
1019 hotkey << wxT("Page_Down" );
1020 break;
1021 case WXK_LEFT:
1022 hotkey << wxT("Left" );
1023 break;
1024 case WXK_RIGHT:
1025 hotkey << wxT("Right" );
1026 break;
1027 case WXK_HOME:
1028 hotkey << wxT("Home" );
1029 break;
1030 case WXK_END:
1031 hotkey << wxT("End" );
1032 break;
1033 case WXK_RETURN:
1034 hotkey << wxT("Return" );
1035 break;
1036 case WXK_BACK:
1037 hotkey << wxT("BackSpace" );
1038 break;
1039 case WXK_TAB:
1040 hotkey << wxT("Tab" );
1041 break;
1042 case WXK_ESCAPE:
1043 hotkey << wxT("Esc" );
1044 break;
1045 case WXK_SPACE:
1046 hotkey << wxT("space" );
1047 break;
1048 case WXK_MULTIPLY:
1049 hotkey << wxT("Multiply" );
1050 break;
1051 case WXK_ADD:
1052 hotkey << wxT("Add" );
1053 break;
1054 case WXK_SEPARATOR:
1055 hotkey << wxT("Separator" );
1056 break;
1057 case WXK_SUBTRACT:
1058 hotkey << wxT("Subtract" );
1059 break;
1060 case WXK_DECIMAL:
1061 hotkey << wxT("Decimal" );
1062 break;
1063 case WXK_DIVIDE:
1064 hotkey << wxT("Divide" );
1065 break;
1066 case WXK_CANCEL:
1067 hotkey << wxT("Cancel" );
1068 break;
1069 case WXK_CLEAR:
1070 hotkey << wxT("Clear" );
1071 break;
1072 case WXK_MENU:
1073 hotkey << wxT("Menu" );
1074 break;
1075 case WXK_PAUSE:
1076 hotkey << wxT("Pause" );
1077 break;
1078 case WXK_CAPITAL:
1079 hotkey << wxT("Capital" );
1080 break;
1081 case WXK_SELECT:
1082 hotkey << wxT("Select" );
1083 break;
1084 case WXK_PRINT:
1085 hotkey << wxT("Print" );
1086 break;
1087 case WXK_EXECUTE:
1088 hotkey << wxT("Execute" );
1089 break;
1090 case WXK_SNAPSHOT:
1091 hotkey << wxT("Snapshot" );
1092 break;
1093 case WXK_HELP:
1094 hotkey << wxT("Help" );
1095 break;
1096 case WXK_NUMLOCK:
1097 hotkey << wxT("Num_Lock" );
1098 break;
1099 case WXK_SCROLL:
1100 hotkey << wxT("Scroll_Lock" );
1101 break;
1102 case WXK_NUMPAD_INSERT:
1103 hotkey << wxT("KP_Insert" );
1104 break;
1105 case WXK_NUMPAD_DELETE:
1106 hotkey << wxT("KP_Delete" );
1107 break;
1108 case WXK_NUMPAD_SPACE:
1109 hotkey << wxT("KP_Space" );
1110 break;
1111 case WXK_NUMPAD_TAB:
1112 hotkey << wxT("KP_Tab" );
1113 break;
1114 case WXK_NUMPAD_ENTER:
1115 hotkey << wxT("KP_Enter" );
1116 break;
1117 case WXK_NUMPAD_F1: case WXK_NUMPAD_F2: case WXK_NUMPAD_F3:
1118 case WXK_NUMPAD_F4:
1119 hotkey += wxString::Format(wxT("KP_F%d"), code - WXK_NUMPAD_F1 + 1);
1120 break;
1121 case WXK_NUMPAD_HOME:
1122 hotkey << wxT("KP_Home" );
1123 break;
1124 case WXK_NUMPAD_LEFT:
1125 hotkey << wxT("KP_Left" );
1126 break;
1127 case WXK_NUMPAD_UP:
1128 hotkey << wxT("KP_Up" );
1129 break;
1130 case WXK_NUMPAD_RIGHT:
1131 hotkey << wxT("KP_Right" );
1132 break;
1133 case WXK_NUMPAD_DOWN:
1134 hotkey << wxT("KP_Down" );
1135 break;
1136 case WXK_NUMPAD_PAGEUP:
1137 hotkey << wxT("KP_Page_Up" );
1138 break;
1139 case WXK_NUMPAD_PAGEDOWN:
1140 hotkey << wxT("KP_Page_Down" );
1141 break;
1142 case WXK_NUMPAD_END:
1143 hotkey << wxT("KP_End" );
1144 break;
1145 case WXK_NUMPAD_BEGIN:
1146 hotkey << wxT("KP_Begin" );
1147 break;
1148 case WXK_NUMPAD_EQUAL:
1149 hotkey << wxT("KP_Equal" );
1150 break;
1151 case WXK_NUMPAD_MULTIPLY:
1152 hotkey << wxT("KP_Multiply" );
1153 break;
1154 case WXK_NUMPAD_ADD:
1155 hotkey << wxT("KP_Add" );
1156 break;
1157 case WXK_NUMPAD_SEPARATOR:
1158 hotkey << wxT("KP_Separator" );
1159 break;
1160 case WXK_NUMPAD_SUBTRACT:
1161 hotkey << wxT("KP_Subtract" );
1162 break;
1163 case WXK_NUMPAD_DECIMAL:
1164 hotkey << wxT("KP_Decimal" );
1165 break;
1166 case WXK_NUMPAD_DIVIDE:
1167 hotkey << wxT("KP_Divide" );
1168 break;
1169 case WXK_NUMPAD0: case WXK_NUMPAD1: case WXK_NUMPAD2:
1170 case WXK_NUMPAD3: case WXK_NUMPAD4: case WXK_NUMPAD5:
1171 case WXK_NUMPAD6: case WXK_NUMPAD7: case WXK_NUMPAD8: case WXK_NUMPAD9:
1172 hotkey += wxString::Format(wxT("KP_%d"), code - WXK_NUMPAD0);
1173 break;
1174 case WXK_WINDOWS_LEFT:
1175 hotkey << wxT("Super_L" );
1176 break;
1177 case WXK_WINDOWS_RIGHT:
1178 hotkey << wxT("Super_R" );
1179 break;
1180 case WXK_WINDOWS_MENU:
1181 hotkey << wxT("Menu" );
1182 break;
1183 case WXK_COMMAND:
1184 hotkey << wxT("Command" );
1185 break;
1186 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1187 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1188 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1189 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1190 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1191 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1192 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1193 break;
1194 */
1195 // if there are any other keys wxAcceleratorEntry::Create() may
1196 // return, we should process them here
1197
1198 default:
1199 if ( code < 127 )
1200 {
1201 const wxString
1202 name = wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint)code));
1203 if ( !name.empty() )
1204 {
1205 hotkey << name;
1206 break;
1207 }
1208 }
1209
1210 wxFAIL_MSG( wxT("unknown keyboard accel") );
1211 }
1212
1213 delete accel;
1214 }
1215
1216 return hotkey;
1217 }
1218
1219 static void
1220 wxGetGtkAccel(const wxMenuItem* item, guint* accel_key, GdkModifierType* accel_mods)
1221 {
1222 *accel_key = 0;
1223 const wxString string = GetGtkHotKey(*item);
1224 if (!string.empty())
1225 gtk_accelerator_parse(wxGTK_CONV_SYS(string), accel_key, accel_mods);
1226 else
1227 {
1228 GtkStockItem stock_item;
1229 const char* stockid = wxGetStockGtkID(item->GetId());
1230 if (stockid && gtk_stock_lookup(stockid, &stock_item))
1231 {
1232 *accel_key = stock_item.keyval;
1233 *accel_mods = stock_item.modifier;
1234 }
1235 }
1236 }
1237 #endif // wxUSE_ACCEL
1238
1239 const char *wxGetStockGtkID(wxWindowID id)
1240 {
1241 #define STOCKITEM(wx,gtk) \
1242 case wx: \
1243 return gtk;
1244
1245 #if GTK_CHECK_VERSION(2,8,0)
1246 #define STOCKITEM_28(wx,gtk) STOCKITEM(wx,gtk)
1247 #else
1248 #define STOCKITEM_28(wx,gtk)
1249 #endif
1250
1251 #if GTK_CHECK_VERSION(2,10,0)
1252 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1253 #else
1254 #define STOCKITEM_210(wx,gtk)
1255 #endif
1256
1257
1258 switch (id)
1259 {
1260 STOCKITEM(wxID_ABOUT, GTK_STOCK_ABOUT)
1261 STOCKITEM(wxID_ADD, GTK_STOCK_ADD)
1262 STOCKITEM(wxID_APPLY, GTK_STOCK_APPLY)
1263 STOCKITEM(wxID_BACKWARD, GTK_STOCK_GO_BACK)
1264 STOCKITEM(wxID_BOLD, GTK_STOCK_BOLD)
1265 STOCKITEM(wxID_BOTTOM, GTK_STOCK_GOTO_BOTTOM)
1266 STOCKITEM(wxID_CANCEL, GTK_STOCK_CANCEL)
1267 STOCKITEM(wxID_CDROM, GTK_STOCK_CDROM)
1268 STOCKITEM(wxID_CLEAR, GTK_STOCK_CLEAR)
1269 STOCKITEM(wxID_CLOSE, GTK_STOCK_CLOSE)
1270 STOCKITEM(wxID_CONVERT, GTK_STOCK_CONVERT)
1271 STOCKITEM(wxID_COPY, GTK_STOCK_COPY)
1272 STOCKITEM(wxID_CUT, GTK_STOCK_CUT)
1273 STOCKITEM(wxID_DELETE, GTK_STOCK_DELETE)
1274 STOCKITEM(wxID_DOWN, GTK_STOCK_GO_DOWN)
1275 STOCKITEM(wxID_EDIT, GTK_STOCK_EDIT)
1276 STOCKITEM(wxID_EXECUTE, GTK_STOCK_EXECUTE)
1277 STOCKITEM(wxID_EXIT, GTK_STOCK_QUIT)
1278 STOCKITEM(wxID_FILE, GTK_STOCK_FILE)
1279 STOCKITEM(wxID_FIND, GTK_STOCK_FIND)
1280 STOCKITEM(wxID_FIRST, GTK_STOCK_GOTO_FIRST)
1281 STOCKITEM(wxID_FLOPPY, GTK_STOCK_FLOPPY)
1282 STOCKITEM(wxID_FORWARD, GTK_STOCK_GO_FORWARD)
1283 STOCKITEM(wxID_HARDDISK, GTK_STOCK_HARDDISK)
1284 STOCKITEM(wxID_HELP, GTK_STOCK_HELP)
1285 STOCKITEM(wxID_HOME, GTK_STOCK_HOME)
1286 STOCKITEM(wxID_INDENT, GTK_STOCK_INDENT)
1287 STOCKITEM(wxID_INDEX, GTK_STOCK_INDEX)
1288 STOCKITEM_28(wxID_INFO, GTK_STOCK_INFO)
1289 STOCKITEM(wxID_ITALIC, GTK_STOCK_ITALIC)
1290 STOCKITEM(wxID_JUMP_TO, GTK_STOCK_JUMP_TO)
1291 STOCKITEM(wxID_JUSTIFY_CENTER, GTK_STOCK_JUSTIFY_CENTER)
1292 STOCKITEM(wxID_JUSTIFY_FILL, GTK_STOCK_JUSTIFY_FILL)
1293 STOCKITEM(wxID_JUSTIFY_LEFT, GTK_STOCK_JUSTIFY_LEFT)
1294 STOCKITEM(wxID_JUSTIFY_RIGHT, GTK_STOCK_JUSTIFY_RIGHT)
1295 STOCKITEM(wxID_LAST, GTK_STOCK_GOTO_LAST)
1296 STOCKITEM(wxID_NETWORK, GTK_STOCK_NETWORK)
1297 STOCKITEM(wxID_NEW, GTK_STOCK_NEW)
1298 STOCKITEM(wxID_NO, GTK_STOCK_NO)
1299 STOCKITEM(wxID_OK, GTK_STOCK_OK)
1300 STOCKITEM(wxID_OPEN, GTK_STOCK_OPEN)
1301 STOCKITEM(wxID_PASTE, GTK_STOCK_PASTE)
1302 STOCKITEM(wxID_PREFERENCES, GTK_STOCK_PREFERENCES)
1303 STOCKITEM(wxID_PREVIEW, GTK_STOCK_PRINT_PREVIEW)
1304 STOCKITEM(wxID_PRINT, GTK_STOCK_PRINT)
1305 STOCKITEM(wxID_PROPERTIES, GTK_STOCK_PROPERTIES)
1306 STOCKITEM(wxID_REDO, GTK_STOCK_REDO)
1307 STOCKITEM(wxID_REFRESH, GTK_STOCK_REFRESH)
1308 STOCKITEM(wxID_REMOVE, GTK_STOCK_REMOVE)
1309 STOCKITEM(wxID_REPLACE, GTK_STOCK_FIND_AND_REPLACE)
1310 STOCKITEM(wxID_REVERT_TO_SAVED, GTK_STOCK_REVERT_TO_SAVED)
1311 STOCKITEM(wxID_SAVE, GTK_STOCK_SAVE)
1312 STOCKITEM(wxID_SAVEAS, GTK_STOCK_SAVE_AS)
1313 STOCKITEM_210(wxID_SELECTALL, GTK_STOCK_SELECT_ALL)
1314 STOCKITEM(wxID_SELECT_COLOR, GTK_STOCK_SELECT_COLOR)
1315 STOCKITEM(wxID_SELECT_FONT, GTK_STOCK_SELECT_FONT)
1316 STOCKITEM(wxID_SORT_ASCENDING, GTK_STOCK_SORT_ASCENDING)
1317 STOCKITEM(wxID_SORT_DESCENDING, GTK_STOCK_SORT_DESCENDING)
1318 STOCKITEM(wxID_SPELL_CHECK, GTK_STOCK_SPELL_CHECK)
1319 STOCKITEM(wxID_STOP, GTK_STOCK_STOP)
1320 STOCKITEM(wxID_STRIKETHROUGH, GTK_STOCK_STRIKETHROUGH)
1321 STOCKITEM(wxID_TOP, GTK_STOCK_GOTO_TOP)
1322 STOCKITEM(wxID_UNDELETE, GTK_STOCK_UNDELETE)
1323 STOCKITEM(wxID_UNDERLINE, GTK_STOCK_UNDERLINE)
1324 STOCKITEM(wxID_UNDO, GTK_STOCK_UNDO)
1325 STOCKITEM(wxID_UNINDENT, GTK_STOCK_UNINDENT)
1326 STOCKITEM(wxID_UP, GTK_STOCK_GO_UP)
1327 STOCKITEM(wxID_YES, GTK_STOCK_YES)
1328 STOCKITEM(wxID_ZOOM_100, GTK_STOCK_ZOOM_100)
1329 STOCKITEM(wxID_ZOOM_FIT, GTK_STOCK_ZOOM_FIT)
1330 STOCKITEM(wxID_ZOOM_IN, GTK_STOCK_ZOOM_IN)
1331 STOCKITEM(wxID_ZOOM_OUT, GTK_STOCK_ZOOM_OUT)
1332
1333 default:
1334 break;
1335 };
1336
1337 #undef STOCKITEM
1338
1339 return NULL;
1340 }
1341
1342 #endif // wxUSE_MENUS