1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/menu.cpp
3 // Purpose: implementation of wxMenuBar and wxMenu classes for wxGTK
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
21 #include "wx/bitmap.h"
26 #include "wx/stockitem.h"
27 #include "wx/gtk/private.h"
28 #include "wx/gtk/private/mnemonics.h"
30 // FIXME: is this right? somehow I don't think so (VZ)
32 #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
33 #define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
34 //#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
36 #define ACCEL_OBJECT GtkWindow
37 #define ACCEL_OBJECTS(a) (a)->acceleratables
38 #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
40 // we use normal item but with a special id for the menu title
41 static const int wxGTK_TITLE_ID
= -3;
43 // forward declare it as it's used by wxMenuBar too when using Hildon
46 static void gtk_menu_clicked_callback(GtkWidget
*widget
, wxMenu
*menu
);
50 static bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
);
51 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
54 //-----------------------------------------------------------------------------
55 // activate message from GTK
56 //-----------------------------------------------------------------------------
58 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
60 event
.SetEventObject( menu
);
62 wxEvtHandler
* handler
= menu
->GetEventHandler();
63 if (handler
&& handler
->SafelyProcessEvent(event
))
66 wxWindow
*win
= menu
->GetInvokingWindow();
68 win
->HandleWindowEvent( event
);
74 gtk_menu_open_callback(GtkWidget
* WXUNUSED(widget
), wxMenu
*menu
)
76 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
78 DoCommonMenuCallbackCode(menu
, event
);
82 gtk_menu_close_callback(GtkWidget
* WXUNUSED(widget
), wxMenuBar
*menubar
)
84 if ( !menubar
->GetMenuCount() )
86 // if menubar is empty we can't call GetMenu(0) below
90 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
92 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
97 //-----------------------------------------------------------------------------
99 //-----------------------------------------------------------------------------
101 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
103 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
106 m_invokingWindow
= NULL
;
109 // Hildon window uses a single menu instead of a menu bar, so wxMenuBar is
110 // the same as menu in this case
112 m_menubar
= gtk_menu_new();
113 #else // !wxUSE_LIBHILDON
114 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
115 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
117 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
121 m_menubar
= gtk_menu_bar_new();
123 if (style
& wxMB_DOCKABLE
)
125 m_widget
= gtk_handle_box_new();
126 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
127 gtk_widget_show(m_menubar
);
131 m_widget
= m_menubar
;
137 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
139 for (size_t i
= 0; i
< n
; ++i
)
140 Append(menus
[i
], titles
[i
]);
142 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
143 // don't get it when the menu is dismissed by clicking outside the
144 // toolbar) so we connect to the global one, even if it means that we
145 // can't pass the menu which was closed in wxMenuEvent object
146 g_signal_connect (m_menubar
, "deactivate",
147 G_CALLBACK (gtk_menu_close_callback
), this);
150 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
152 Init(n
, menus
, titles
, style
);
155 wxMenuBar::wxMenuBar(long style
)
157 Init(0, NULL
, NULL
, style
);
160 wxMenuBar::wxMenuBar()
162 Init(0, NULL
, NULL
, 0);
165 wxMenuBar::~wxMenuBar()
169 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
171 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
173 wxWindow
*top_frame
= win
;
174 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
175 top_frame
= top_frame
->GetParent();
177 // support for native hot keys
178 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
179 if ( menu
->m_accel
&& g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
180 gtk_accel_group_detach( menu
->m_accel
, obj
);
182 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
185 wxMenuItem
*menuitem
= node
->GetData();
186 if (menuitem
->IsSubMenu())
187 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
188 node
= node
->GetNext();
192 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
194 menu
->SetInvokingWindow( win
);
196 wxWindow
*top_frame
= win
;
197 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
198 top_frame
= top_frame
->GetParent();
200 // support for native hot keys
201 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
202 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
203 gtk_accel_group_attach( menu
->m_accel
, obj
);
205 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
208 wxMenuItem
*menuitem
= node
->GetData();
209 if (menuitem
->IsSubMenu())
210 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
211 node
= node
->GetNext();
215 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
217 m_invokingWindow
= win
;
218 wxWindow
*top_frame
= win
;
219 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
220 top_frame
= top_frame
->GetParent();
222 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
225 wxMenu
*menu
= node
->GetData();
226 wxMenubarSetInvokingWindow( menu
, win
);
227 node
= node
->GetNext();
231 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
233 if ( dir
== wxLayout_Default
)
235 const wxWindow
*const frame
= GetFrame();
238 // inherit layout from frame.
239 dir
= frame
->GetLayoutDirection();
241 else // use global layout
243 dir
= wxTheApp
->GetLayoutDirection();
247 if ( dir
== wxLayout_Default
)
250 GTKSetLayout(m_menubar
, dir
);
252 // also set the layout of all menus we already have (new ones will inherit
253 // the current layout)
254 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
256 node
= node
->GetNext() )
258 wxMenu
*const menu
= node
->GetData();
259 menu
->SetLayoutDirection(dir
);
263 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
265 return GTKGetLayout(m_menubar
);
268 void wxMenuBar::Attach(wxFrame
*frame
)
270 wxMenuBarBase::Attach(frame
);
272 SetLayoutDirection(wxLayout_Default
);
275 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
277 m_invokingWindow
= (wxWindow
*) NULL
;
278 wxWindow
*top_frame
= win
;
279 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
280 top_frame
= top_frame
->GetParent();
282 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
285 wxMenu
*menu
= node
->GetData();
286 wxMenubarUnsetInvokingWindow( menu
, win
);
287 node
= node
->GetNext();
291 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
293 if ( !wxMenuBarBase::Append( menu
, title
) )
296 return GtkAppend(menu
, title
);
299 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
301 menu
->SetLayoutDirection(GetLayoutDirection());
304 // if the menu has only one item, append it directly to the top level menu
305 // instead of inserting a useless submenu
306 if ( menu
->GetMenuItemCount() == 1 )
308 wxMenuItem
* const item
= menu
->FindItemByPosition(0);
310 // remove both mnemonics and accelerator: neither is useful under Maemo
311 const wxString
str(wxStripMenuCodes(item
->GetItemLabel()));
313 if ( item
->IsSubMenu() )
314 return GtkAppend(item
->GetSubMenu(), str
, pos
);
316 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
318 g_signal_connect(menu
->m_owner
, "activate",
319 G_CALLBACK(gtk_menu_clicked_callback
), menu
);
320 item
->SetMenuItem(menu
->m_owner
);
323 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
325 const wxString
str(wxConvertMnemonicsToGTK(title
));
327 // This doesn't have much effect right now.
328 menu
->SetTitle( str
);
330 // The "m_owner" is the "menu item"
331 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
333 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
336 gtk_widget_show( menu
->m_owner
);
339 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
341 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
343 g_signal_connect (menu
->m_owner
, "activate",
344 G_CALLBACK (gtk_menu_open_callback
),
347 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
348 // addings menu later on.
349 if (m_invokingWindow
)
350 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
355 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
357 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
362 if ( !GtkAppend(menu
, title
, (int)pos
) )
368 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
370 // remove the old item and insert a new one
371 wxMenu
*menuOld
= Remove(pos
);
372 if ( menuOld
&& !Insert(pos
, menu
, title
) )
374 return (wxMenu
*) NULL
;
377 // either Insert() succeeded or Remove() failed and menuOld is NULL
381 wxMenu
*wxMenuBar::Remove(size_t pos
)
383 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
385 return (wxMenu
*) NULL
;
387 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
388 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
390 gtk_widget_destroy( menu
->m_owner
);
391 menu
->m_owner
= NULL
;
393 if (m_invokingWindow
)
394 wxMenubarUnsetInvokingWindow( menu
, m_invokingWindow
);
399 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
401 if (wxMenuItem::GetLabelText(wxConvertMnemonicsFromGTK(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
403 int res
= menu
->FindItem( itemString
);
404 if (res
!= wxNOT_FOUND
)
408 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
411 wxMenuItem
*item
= node
->GetData();
412 if (item
->IsSubMenu())
413 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
415 node
= node
->GetNext();
421 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
423 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
426 wxMenu
*menu
= node
->GetData();
427 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
430 node
= node
->GetNext();
436 // Find a wxMenuItem using its id. Recurses down into sub-menus
437 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
439 wxMenuItem
* result
= menu
->FindChildItem(id
);
441 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
442 while ( node
&& result
== NULL
)
444 wxMenuItem
*item
= node
->GetData();
445 if (item
->IsSubMenu())
447 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
449 node
= node
->GetNext();
455 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
457 wxMenuItem
* result
= 0;
458 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
459 while (node
&& result
== 0)
461 wxMenu
*menu
= node
->GetData();
462 result
= FindMenuItemByIdRecursive( menu
, id
);
463 node
= node
->GetNext();
468 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
474 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
476 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
478 wxCHECK_RET( node
, wxT("menu not found") );
480 wxMenu
* menu
= node
->GetData();
483 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
486 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
488 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
490 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
492 wxMenu
* menu
= node
->GetData();
494 return wxConvertMnemonicsFromGTK(menu
->GetTitle());
497 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
499 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
501 wxCHECK_RET( node
, wxT("menu not found") );
503 wxMenu
* menu
= node
->GetData();
505 const wxString
str(wxConvertMnemonicsToGTK(label
));
507 menu
->SetTitle( str
);
510 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
513 //-----------------------------------------------------------------------------
515 //-----------------------------------------------------------------------------
518 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
520 int id
= menu
->FindMenuIdByMenuItem(widget
);
522 /* should find it for normal (not popup) menu */
523 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
524 _T("menu item not found in gtk_menu_clicked_callback") );
526 if (!menu
->IsEnabled(id
))
529 wxMenuItem
* item
= menu
->FindChildItem( id
);
530 wxCHECK_RET( item
, wxT("error in menu item callback") );
532 if ( item
->GetId() == wxGTK_TITLE_ID
)
534 // ignore events from the menu title
538 if (item
->IsCheckable())
540 bool isReallyChecked
= item
->IsChecked(),
541 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
543 // ensure that the internal state is always consistent with what is
544 // shown on the screen
545 item
->wxMenuItemBase::Check(isReallyChecked
);
547 // we must not report the events for the radio button going up nor the
548 // events resulting from the calls to wxMenuItem::Check()
549 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
550 (isInternallyChecked
== isReallyChecked
) )
557 // Is this menu on a menubar? (possibly nested)
558 wxFrame
* frame
= NULL
;
559 if(menu
->IsAttached())
560 frame
= menu
->GetMenuBar()->GetFrame();
562 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
563 // normally wxMenu::SendEvent() should be enough, if it doesn't work
564 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
565 // should be fixed instead of working around it here...
568 // If it is attached then let the frame send the event.
569 // Don't call frame->ProcessCommand(id) because it toggles
570 // checkable items and we've already done that above.
571 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
572 commandEvent
.SetEventObject(frame
);
573 if (item
->IsCheckable())
574 commandEvent
.SetInt(item
->IsChecked());
576 frame
->HandleWindowEvent(commandEvent
);
580 // otherwise let the menu have it
581 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
586 //-----------------------------------------------------------------------------
588 //-----------------------------------------------------------------------------
591 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
593 int id
= menu
->FindMenuIdByMenuItem(widget
);
595 wxASSERT( id
!= -1 ); // should find it!
597 if (!menu
->IsEnabled(id
))
600 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
601 event
.SetEventObject( menu
);
603 wxEvtHandler
* handler
= menu
->GetEventHandler();
604 if (handler
&& handler
->SafelyProcessEvent(event
))
607 wxWindow
*win
= menu
->GetInvokingWindow();
608 if (win
) win
->HandleWindowEvent( event
);
612 //-----------------------------------------------------------------------------
614 //-----------------------------------------------------------------------------
617 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
619 int id
= menu
->FindMenuIdByMenuItem(widget
);
621 wxASSERT( id
!= -1 ); // should find it!
623 if (!menu
->IsEnabled(id
))
626 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
627 event
.SetEventObject( menu
);
629 wxEvtHandler
* handler
= menu
->GetEventHandler();
630 if (handler
&& handler
->SafelyProcessEvent(event
))
633 wxWindow
*win
= menu
->GetInvokingWindow();
635 win
->HandleWindowEvent( event
);
639 //-----------------------------------------------------------------------------
641 //-----------------------------------------------------------------------------
643 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
645 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
647 const wxString
& name
,
648 const wxString
& help
,
652 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
655 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
657 const wxString
& text
,
658 const wxString
& help
,
661 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
666 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
668 const wxString
& text
,
669 const wxString
& help
,
672 : wxMenuItemBase(parentMenu
, id
, text
, help
,
673 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
678 void wxMenuItem::Init(const wxString
& text
)
680 m_labelWidget
= (GtkWidget
*) NULL
;
681 m_menuItem
= (GtkWidget
*) NULL
;
686 wxMenuItem::~wxMenuItem()
688 // don't delete menu items, the menus take care of that
691 // return the menu item text without any menu accels
694 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
696 // The argument to this function will now always be in wxWidgets standard label
697 // format, not GTK+ format, so we do what the other ports do.
699 return wxStripMenuCodes(text
);
704 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
706 if ( *pc
== wxT('\t'))
709 if ( *pc
== wxT('_') )
711 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
717 if ( *pc
== wxT('\\') )
719 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
725 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
728 // "&" is doubled to indicate "&" instead of accelerator
735 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
741 wxString
wxMenuItem::GetItemLabel() const
743 wxString label
= wxConvertMnemonicsFromGTK(m_text
);
744 if (!m_hotKey
.IsEmpty())
745 label
<< "\t" << m_hotKey
;
749 void wxMenuItem::SetItemLabel( const wxString
& str
)
751 // cache some data which must be used later
752 bool isstock
= wxIsStockID(GetId());
753 const char *stockid
= NULL
;
755 stockid
= wxGetStockGtkID(GetId());
757 // Some optimization to avoid flicker
758 wxString oldLabel
= m_text
;
759 oldLabel
= wxStripMenuCodes(oldLabel
);
760 oldLabel
.Replace(wxT("_"), wxT(""));
761 wxString label1
= wxStripMenuCodes(str
);
763 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
764 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
765 #endif // wxUSE_ACCEL
770 if (oldLabel
== label1
&&
771 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
778 label
= (GtkLabel
*) m_labelWidget
;
780 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
782 // stock menu items can have empty labels:
783 wxString text
= m_text
;
784 if (text
.IsEmpty() && !IsSeparator())
786 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
787 text
= wxGetStockLabel(GetId());
789 // need & => _ conversion
790 text
= GTKProcessMenuItemLabel(text
, NULL
);
793 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
796 // remove old accelerator from our parent's accelerator group, if present
798 GdkModifierType accel_mods
;
799 if (oldbuf
[(size_t)0] != '\0')
801 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
804 gtk_widget_remove_accelerator(m_menuItem
,
805 m_parentMenu
->m_accel
,
812 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
813 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
814 gtk_widget_remove_accelerator( m_menuItem
,
815 m_parentMenu
->m_accel
,
820 // add new accelerator to our parent's accelerator group
821 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
822 if (buf
[(size_t)0] != '\0')
824 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
827 gtk_widget_add_accelerator( m_menuItem
,
829 m_parentMenu
->m_accel
,
837 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
838 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
839 gtk_widget_remove_accelerator( m_menuItem
,
840 m_parentMenu
->m_accel
,
844 #endif // wxUSE_ACCEL
847 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
848 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
849 // so there's no real code duplication
850 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
854 // '\t' is the deliminator indicating a hot key
855 wxString::const_iterator pc
= str
.begin();
856 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
860 wxString::const_iterator next
= pc
+ 1;
861 if (next
!= str
.end() && *next
== wxT('&'))
863 // "&" is doubled to indicate "&" instead of accelerator
872 else if ( *pc
== wxT('_') ) // escape underscores
889 hotKey
->assign(pc
, str
.end());
896 // it's valid for this function to be called even if m_menuItem == NULL
897 void wxMenuItem::DoSetText( const wxString
& str
)
900 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
905 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
913 // accelerator parsing code looks for them after a TAB, so insert a dummy
916 label
<< wxT('\t') << GetHotKey();
918 return wxAcceleratorEntry::Create(label
);
921 #endif // wxUSE_ACCEL
923 void wxMenuItem::Check( bool check
)
925 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
927 if (check
== m_isChecked
)
930 wxMenuItemBase::Check( check
);
936 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
940 wxFAIL_MSG( _T("can't check this item") );
944 void wxMenuItem::Enable( bool enable
)
946 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
948 gtk_widget_set_sensitive( m_menuItem
, enable
);
949 wxMenuItemBase::Enable( enable
);
952 bool wxMenuItem::IsChecked() const
954 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
956 wxCHECK_MSG( IsCheckable(), false,
957 wxT("can't get state of uncheckable item!") );
959 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
962 //-----------------------------------------------------------------------------
964 //-----------------------------------------------------------------------------
966 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
970 m_accel
= gtk_accel_group_new();
971 m_menu
= gtk_menu_new();
972 // NB: keep reference to the menu so that it is not destroyed behind
973 // our back by GTK+ e.g. when it is removed from menubar:
974 gtk_widget_ref(m_menu
);
976 m_owner
= (GtkWidget
*) NULL
;
978 // Tearoffs are entries, just like separators. So if we want this
979 // menu to be a tear-off one, we just append a tearoff entry
981 if ( m_style
& wxMENU_TEAROFF
)
983 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
985 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
990 // append the title as the very first entry if we have it
991 if ( !m_title
.empty() )
993 Append(wxGTK_TITLE_ID
, m_title
);
1000 if ( GTK_IS_WIDGET( m_menu
))
1003 gtk_widget_unref( m_menu
);
1004 g_object_unref( m_accel
);
1006 // if the menu is inserted in another menu at this time, there was
1007 // one more reference to it:
1009 gtk_widget_destroy( m_menu
);
1012 // This must come after we release GTK resources above. Otherwise, GTK will
1013 // give warnings/errors when attempting to free accelerator resources from
1014 // child items that just were destroyed (the m_menu widget can contain
1015 // references to accelerators in child items. Problem detected when removing
1016 // a menu from a wxMenuBar, and the removed menu had submenus with accelerators.)
1017 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1020 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1023 wxWindow::GTKSetLayout(m_owner
, dir
);
1024 //else: will be called later by wxMenuBar again
1027 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1029 return wxWindow::GTKGetLayout(m_owner
);
1032 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1034 GtkWidget
*menuItem
;
1036 // cache some data used later
1037 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1038 int id
= mitem
->GetId();
1039 bool isstock
= wxIsStockID(id
);
1040 const char *stockid
= NULL
;
1042 stockid
= wxGetStockGtkID(mitem
->GetId());
1044 // stock menu items can have an empty label
1045 if (text
.IsEmpty() && !mitem
->IsSeparator())
1047 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1048 text
= wxGetStockLabel(id
);
1050 // need & => _ conversion
1051 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1054 if ( mitem
->IsSeparator() )
1056 menuItem
= gtk_separator_menu_item_new();
1059 else if ( mitem
->GetBitmap().Ok() ||
1060 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1062 wxBitmap
bitmap(mitem
->GetBitmap());
1064 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1069 // use stock bitmap for this item if available on the assumption
1070 // that it never hurts to follow GTK+ conventions more closely
1071 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1074 else // we have a custom bitmap
1076 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1077 _T("only normal menu items can have bitmaps") );
1079 if ( bitmap
.HasPixbuf() )
1081 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1085 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1086 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1087 bitmap
.GetMask()->GetBitmap() :
1089 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1095 gtk_widget_show(image
);
1097 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1102 else // a normal item
1104 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1107 switch ( mitem
->GetKind() )
1111 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1118 GSList
*group
= NULL
;
1119 if ( m_prevRadio
== NULL
)
1121 // start of a new radio group
1122 m_prevRadio
= menuItem
=
1123 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1125 else // continue the radio group
1127 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1128 m_prevRadio
= menuItem
=
1129 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1135 wxFAIL_MSG( _T("unexpected menu item kind") );
1140 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1150 GdkModifierType accel_mods
;
1151 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1153 if (buf
[(size_t)0] != '\0')
1155 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1158 gtk_widget_add_accelerator (menuItem
,
1168 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1169 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1170 gtk_widget_add_accelerator( menuItem
,
1177 #endif // wxUSE_ACCEL
1180 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1182 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1184 gtk_widget_show( menuItem
);
1186 if ( !mitem
->IsSeparator() )
1188 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1190 g_signal_connect (menuItem
, "select",
1191 G_CALLBACK (gtk_menu_hilight_callback
), this);
1192 g_signal_connect (menuItem
, "deselect",
1193 G_CALLBACK (gtk_menu_nolight_callback
), this);
1195 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1197 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1199 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1201 // if adding a submenu to a menu already existing in the menu bar, we
1202 // must set invoking window to allow processing events from this
1204 if ( m_invokingWindow
)
1205 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1209 g_signal_connect (menuItem
, "activate",
1210 G_CALLBACK (gtk_menu_clicked_callback
),
1215 mitem
->SetMenuItem(menuItem
);
1219 // This doesn't even exist!
1220 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1226 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1228 if (!GtkAppend(mitem
))
1231 return wxMenuBase::DoAppend(mitem
);
1234 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1236 if ( !wxMenuBase::DoInsert(pos
, item
) )
1240 if ( !GtkAppend(item
, (int)pos
) )
1246 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1248 if ( !wxMenuBase::DoRemove(item
) )
1251 GtkWidget
* const mitem
= item
->GetMenuItem();
1252 if ( m_prevRadio
== mitem
)
1254 // deleting an item starts a new radio group (has to as we shouldn't
1255 // keep a deleted pointer anyhow)
1259 // TODO: this code doesn't delete the item factory item and this seems
1260 // impossible as of GTK 1.2.6.
1261 gtk_widget_destroy( mitem
);
1266 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1268 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1271 wxMenuItem
*item
= node
->GetData();
1272 if (item
->GetMenuItem() == menuItem
)
1273 return item
->GetId();
1274 node
= node
->GetNext();
1280 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1282 wxMenuBase::Attach(menubar
);
1284 // inherit layout direction from menubar.
1285 SetLayoutDirection(menubar
->GetLayoutDirection());
1288 // ----------------------------------------------------------------------------
1290 // ----------------------------------------------------------------------------
1294 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1298 wxAcceleratorEntry
*accel
= item
.GetAccel();
1301 int flags
= accel
->GetFlags();
1302 if ( flags
& wxACCEL_ALT
)
1303 hotkey
+= wxT("<alt>");
1304 if ( flags
& wxACCEL_CTRL
)
1305 hotkey
+= wxT("<control>");
1306 if ( flags
& wxACCEL_SHIFT
)
1307 hotkey
+= wxT("<shift>");
1309 int code
= accel
->GetKeyCode();
1336 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1339 // TODO: we should use gdk_keyval_name() (a.k.a.
1340 // XKeysymToString) here as well as hardcoding the keysym
1341 // names this might be not portable
1343 hotkey
<< wxT("Insert" );
1346 hotkey
<< wxT("Delete" );
1349 hotkey
<< wxT("Up" );
1352 hotkey
<< wxT("Down" );
1355 hotkey
<< wxT("Page_Up" );
1358 hotkey
<< wxT("Page_Down" );
1361 hotkey
<< wxT("Left" );
1364 hotkey
<< wxT("Right" );
1367 hotkey
<< wxT("Home" );
1370 hotkey
<< wxT("End" );
1373 hotkey
<< wxT("Return" );
1376 hotkey
<< wxT("BackSpace" );
1379 hotkey
<< wxT("Tab" );
1382 hotkey
<< wxT("Esc" );
1385 hotkey
<< wxT("space" );
1388 hotkey
<< wxT("Multiply" );
1391 hotkey
<< wxT("Add" );
1394 hotkey
<< wxT("Separator" );
1397 hotkey
<< wxT("Subtract" );
1400 hotkey
<< wxT("Decimal" );
1403 hotkey
<< wxT("Divide" );
1406 hotkey
<< wxT("Cancel" );
1409 hotkey
<< wxT("Clear" );
1412 hotkey
<< wxT("Menu" );
1415 hotkey
<< wxT("Pause" );
1418 hotkey
<< wxT("Capital" );
1421 hotkey
<< wxT("Select" );
1424 hotkey
<< wxT("Print" );
1427 hotkey
<< wxT("Execute" );
1430 hotkey
<< wxT("Snapshot" );
1433 hotkey
<< wxT("Help" );
1436 hotkey
<< wxT("Num_Lock" );
1439 hotkey
<< wxT("Scroll_Lock" );
1441 case WXK_NUMPAD_INSERT
:
1442 hotkey
<< wxT("KP_Insert" );
1444 case WXK_NUMPAD_DELETE
:
1445 hotkey
<< wxT("KP_Delete" );
1447 case WXK_NUMPAD_SPACE
:
1448 hotkey
<< wxT("KP_Space" );
1450 case WXK_NUMPAD_TAB
:
1451 hotkey
<< wxT("KP_Tab" );
1453 case WXK_NUMPAD_ENTER
:
1454 hotkey
<< wxT("KP_Enter" );
1456 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1458 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1460 case WXK_NUMPAD_HOME
:
1461 hotkey
<< wxT("KP_Home" );
1463 case WXK_NUMPAD_LEFT
:
1464 hotkey
<< wxT("KP_Left" );
1467 hotkey
<< wxT("KP_Up" );
1469 case WXK_NUMPAD_RIGHT
:
1470 hotkey
<< wxT("KP_Right" );
1472 case WXK_NUMPAD_DOWN
:
1473 hotkey
<< wxT("KP_Down" );
1475 case WXK_NUMPAD_PAGEUP
:
1476 hotkey
<< wxT("KP_Page_Up" );
1478 case WXK_NUMPAD_PAGEDOWN
:
1479 hotkey
<< wxT("KP_Page_Down" );
1481 case WXK_NUMPAD_END
:
1482 hotkey
<< wxT("KP_End" );
1484 case WXK_NUMPAD_BEGIN
:
1485 hotkey
<< wxT("KP_Begin" );
1487 case WXK_NUMPAD_EQUAL
:
1488 hotkey
<< wxT("KP_Equal" );
1490 case WXK_NUMPAD_MULTIPLY
:
1491 hotkey
<< wxT("KP_Multiply" );
1493 case WXK_NUMPAD_ADD
:
1494 hotkey
<< wxT("KP_Add" );
1496 case WXK_NUMPAD_SEPARATOR
:
1497 hotkey
<< wxT("KP_Separator" );
1499 case WXK_NUMPAD_SUBTRACT
:
1500 hotkey
<< wxT("KP_Subtract" );
1502 case WXK_NUMPAD_DECIMAL
:
1503 hotkey
<< wxT("KP_Decimal" );
1505 case WXK_NUMPAD_DIVIDE
:
1506 hotkey
<< wxT("KP_Divide" );
1508 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1509 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1510 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1511 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1513 case WXK_WINDOWS_LEFT
:
1514 hotkey
<< wxT("Super_L" );
1516 case WXK_WINDOWS_RIGHT
:
1517 hotkey
<< wxT("Super_R" );
1519 case WXK_WINDOWS_MENU
:
1520 hotkey
<< wxT("Menu" );
1523 hotkey
<< wxT("Command" );
1525 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1526 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1527 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1528 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1529 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1530 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1531 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1534 // if there are any other keys wxAcceleratorEntry::Create() may
1535 // return, we should process them here
1541 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1542 if ( !name
.empty() )
1549 wxFAIL_MSG( wxT("unknown keyboard accel") );
1558 #endif // wxUSE_ACCEL
1560 // ----------------------------------------------------------------------------
1561 // Pop-up menu stuff
1562 // ----------------------------------------------------------------------------
1564 #if wxUSE_MENUS_NATIVE
1566 extern "C" WXDLLIMPEXP_CORE
1567 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1569 *is_waiting
= false;
1572 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1574 menu
->SetInvokingWindow( win
);
1576 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1579 wxMenuItem
*menuitem
= node
->GetData();
1580 if (menuitem
->IsSubMenu())
1582 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1585 node
= node
->GetNext();
1589 extern "C" WXDLLIMPEXP_CORE
1590 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1592 gboolean
* WXUNUSED(whatever
),
1593 gpointer user_data
)
1595 // ensure that the menu appears entirely on screen
1597 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1599 wxSize sizeScreen
= wxGetDisplaySize();
1600 wxPoint
*pos
= (wxPoint
*)user_data
;
1602 gint xmax
= sizeScreen
.x
- req
.width
,
1603 ymax
= sizeScreen
.y
- req
.height
;
1605 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1606 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1609 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1611 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1613 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1615 // NOTE: if you change this code, you need to update
1616 // the same code in taskbar.cpp as well. This
1617 // is ugly code duplication, I know.
1619 SetInvokingWindow( menu
, this );
1623 bool is_waiting
= true;
1625 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1626 G_CALLBACK (gtk_pop_hide_callback
),
1631 GtkMenuPositionFunc posfunc
;
1632 if ( x
== -1 && y
== -1 )
1634 // use GTK's default positioning algorithm
1640 pos
= ClientToScreen(wxPoint(x
, y
));
1642 posfunc
= wxPopupMenuPositionCallback
;
1645 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1646 DoCommonMenuCallbackCode(menu
, eventOpen
);
1649 GTK_MENU(menu
->m_menu
),
1650 (GtkWidget
*) NULL
, // parent menu shell
1651 (GtkWidget
*) NULL
, // parent menu item
1652 posfunc
, // function to position it
1653 userdata
, // client data
1654 0, // button used to activate it
1655 gtk_get_current_event_time()
1660 gtk_main_iteration();
1663 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1665 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1666 DoCommonMenuCallbackCode(menu
, eventClose
);
1671 #endif // wxUSE_MENUS_NATIVE
1673 #include <gtk/gtk.h>
1675 const char *wxGetStockGtkID(wxWindowID id
)
1677 #define STOCKITEM(wx,gtk) \
1681 #define STOCKITEM_MISSING(wx) \
1685 #if GTK_CHECK_VERSION(2,4,0)
1686 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1688 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1691 #if GTK_CHECK_VERSION(2,6,0)
1692 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1694 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1697 #if GTK_CHECK_VERSION(2,10,0)
1698 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1700 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1706 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1707 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1708 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1709 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1710 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1711 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1712 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1713 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1714 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1715 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1716 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1717 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1718 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1719 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1720 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1721 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1722 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1723 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1724 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1725 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1726 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1727 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1728 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1729 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1730 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1731 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1732 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1733 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1734 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1735 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1736 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1737 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1738 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1739 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1740 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1741 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1742 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1743 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1744 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1745 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1746 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1747 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1748 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1749 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1750 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1751 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1752 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1753 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1754 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1755 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1756 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1757 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1758 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1759 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1762 wxFAIL_MSG( _T("invalid stock item ID") );
1773 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1778 GtkStockItem stock_item
;
1779 if (gtk_stock_lookup (id
, &stock_item
))
1781 if (key
) *key
= stock_item
.keyval
;
1782 if (mod
) *mod
= stock_item
.modifier
;
1784 // some GTK stock items have zero values for the keyval;
1785 // it means that they do not have an accelerator...
1786 if (stock_item
.keyval
)
1792 #endif // wxUSE_ACCEL
1794 #endif // wxUSE_MENUS