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"
29 // FIXME: is this right? somehow I don't think so (VZ)
31 #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
32 #define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
33 //#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
35 #define ACCEL_OBJECT GtkWindow
36 #define ACCEL_OBJECTS(a) (a)->acceleratables
37 #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
39 // we use normal item but with a special id for the menu title
40 static const int wxGTK_TITLE_ID
= -3;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
47 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 static wxString
wxReplaceUnderscore( const wxString
& title
)
56 // GTK 1.2 wants to have "_" instead of "&" for accelerators
59 for ( wxString::const_iterator pc
= title
.begin(); pc
!= title
.end(); ++pc
)
61 if ((*pc
== wxT('&')) && (pc
+1 != title
.end()) && (*(pc
+1) == wxT('&')))
63 // "&" is doubled to indicate "&" instead of accelerator
67 else if (*pc
== wxT('&'))
73 if ( *pc
== wxT('_') )
75 // underscores must be doubled to prevent them from being
76 // interpreted as accelerator character prefix by GTK
84 // wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() );
89 static wxString
wxConvertFromGTKToWXLabel(const wxString
& gtkLabel
)
92 for ( const wxChar
*pc
= gtkLabel
.c_str(); *pc
; pc
++ )
94 // '_' is the escape character for GTK+.
96 if ( *pc
== wxT('_') && *(pc
+1) == wxT('_'))
98 // An underscore was escaped.
102 else if ( *pc
== wxT('_') )
104 // Convert GTK+ hotkey symbol to wxWidgets/Windows standard
107 else if ( *pc
== wxT('&') )
109 // Double the ampersand to escape it as far as wxWidgets is concerned
114 // don't remove ampersands '&' since if we have them in the menu title
115 // it means that they were doubled to indicate "&" instead of accelerator
123 //-----------------------------------------------------------------------------
124 // activate message from GTK
125 //-----------------------------------------------------------------------------
127 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
129 event
.SetEventObject( menu
);
131 wxEvtHandler
* handler
= menu
->GetEventHandler();
132 if (handler
&& handler
->ProcessEvent(event
))
135 wxWindow
*win
= menu
->GetInvokingWindow();
137 win
->GetEventHandler()->ProcessEvent( event
);
143 gtk_menu_open_callback(GtkWidget
* WXUNUSED(widget
), wxMenu
*menu
)
145 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
147 DoCommonMenuCallbackCode(menu
, event
);
151 gtk_menu_close_callback(GtkWidget
* WXUNUSED(widget
), wxMenuBar
*menubar
)
153 if ( !menubar
->GetMenuCount() )
155 // if menubar is empty we can't call GetMenu(0) below
159 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
161 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
166 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
170 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
172 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
175 m_invokingWindow
= NULL
;
177 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
178 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
180 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
184 m_menubar
= gtk_menu_bar_new();
186 if (style
& wxMB_DOCKABLE
)
188 m_widget
= gtk_handle_box_new();
189 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
190 gtk_widget_show(m_menubar
);
194 m_widget
= m_menubar
;
201 for (size_t i
= 0; i
< n
; ++i
)
202 Append(menus
[i
], titles
[i
]);
204 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
205 // don't get it when the menu is dismissed by clicking outside the
206 // toolbar) so we connect to the global one, even if it means that we
207 // can't pass the menu which was closed in wxMenuEvent object
208 g_signal_connect (m_menubar
, "deactivate",
209 G_CALLBACK (gtk_menu_close_callback
), this);
213 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
215 Init(n
, menus
, titles
, style
);
218 wxMenuBar::wxMenuBar(long style
)
220 Init(0, NULL
, NULL
, style
);
223 wxMenuBar::wxMenuBar()
225 Init(0, NULL
, NULL
, 0);
228 wxMenuBar::~wxMenuBar()
232 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
234 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
236 wxWindow
*top_frame
= win
;
237 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
238 top_frame
= top_frame
->GetParent();
240 // support for native hot keys
241 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
242 if ( menu
->m_accel
&& g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
243 gtk_accel_group_detach( menu
->m_accel
, obj
);
245 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
248 wxMenuItem
*menuitem
= node
->GetData();
249 if (menuitem
->IsSubMenu())
250 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
251 node
= node
->GetNext();
255 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
257 menu
->SetInvokingWindow( win
);
259 wxWindow
*top_frame
= win
;
260 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
261 top_frame
= top_frame
->GetParent();
263 // support for native hot keys
264 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
265 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
266 gtk_accel_group_attach( menu
->m_accel
, obj
);
268 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
271 wxMenuItem
*menuitem
= node
->GetData();
272 if (menuitem
->IsSubMenu())
273 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
274 node
= node
->GetNext();
278 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
280 m_invokingWindow
= win
;
281 wxWindow
*top_frame
= win
;
282 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
283 top_frame
= top_frame
->GetParent();
285 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
288 wxMenu
*menu
= node
->GetData();
289 wxMenubarSetInvokingWindow( menu
, win
);
290 node
= node
->GetNext();
294 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
296 if ( dir
== wxLayout_Default
)
298 const wxWindow
*const frame
= GetFrame();
301 // inherit layout from frame.
302 dir
= frame
->GetLayoutDirection();
304 else // use global layout
306 dir
= wxTheApp
->GetLayoutDirection();
310 if ( dir
== wxLayout_Default
)
313 GTKSetLayout(m_menubar
, dir
);
315 // also set the layout of all menus we already have (new ones will inherit
316 // the current layout)
317 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
319 node
= node
->GetNext() )
321 wxMenu
*const menu
= node
->GetData();
322 menu
->SetLayoutDirection(dir
);
326 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
328 return GTKGetLayout(m_menubar
);
331 void wxMenuBar::Attach(wxFrame
*frame
)
333 wxMenuBarBase::Attach(frame
);
335 SetLayoutDirection(wxLayout_Default
);
338 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
340 m_invokingWindow
= (wxWindow
*) NULL
;
341 wxWindow
*top_frame
= win
;
342 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
343 top_frame
= top_frame
->GetParent();
345 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
348 wxMenu
*menu
= node
->GetData();
349 wxMenubarUnsetInvokingWindow( menu
, win
);
350 node
= node
->GetNext();
354 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
356 if ( !wxMenuBarBase::Append( menu
, title
) )
359 return GtkAppend(menu
, title
);
362 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
364 wxString
str( wxReplaceUnderscore( title
) );
366 // This doesn't have much effect right now.
367 menu
->SetTitle( str
);
369 // The "m_owner" is the "menu item"
370 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
371 menu
->SetLayoutDirection(GetLayoutDirection());
373 gtk_widget_show( menu
->m_owner
);
375 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
378 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
380 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
382 g_signal_connect (menu
->m_owner
, "activate",
383 G_CALLBACK (gtk_menu_open_callback
),
386 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
387 // addings menu later on.
388 if (m_invokingWindow
)
389 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
394 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
396 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
401 if ( !GtkAppend(menu
, title
, (int)pos
) )
407 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
409 // remove the old item and insert a new one
410 wxMenu
*menuOld
= Remove(pos
);
411 if ( menuOld
&& !Insert(pos
, menu
, title
) )
413 return (wxMenu
*) NULL
;
416 // either Insert() succeeded or Remove() failed and menuOld is NULL
420 wxMenu
*wxMenuBar::Remove(size_t pos
)
422 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
424 return (wxMenu
*) NULL
;
426 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
427 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
429 gtk_widget_destroy( menu
->m_owner
);
430 menu
->m_owner
= NULL
;
432 if (m_invokingWindow
)
433 wxMenubarUnsetInvokingWindow( menu
, m_invokingWindow
);
438 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
440 if (wxMenuItem::GetLabelText(wxConvertFromGTKToWXLabel(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
442 int res
= menu
->FindItem( itemString
);
443 if (res
!= wxNOT_FOUND
)
447 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
450 wxMenuItem
*item
= node
->GetData();
451 if (item
->IsSubMenu())
452 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
454 node
= node
->GetNext();
460 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
462 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
465 wxMenu
*menu
= node
->GetData();
466 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
469 node
= node
->GetNext();
475 // Find a wxMenuItem using its id. Recurses down into sub-menus
476 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
478 wxMenuItem
* result
= menu
->FindChildItem(id
);
480 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
481 while ( node
&& result
== NULL
)
483 wxMenuItem
*item
= node
->GetData();
484 if (item
->IsSubMenu())
486 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
488 node
= node
->GetNext();
494 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
496 wxMenuItem
* result
= 0;
497 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
498 while (node
&& result
== 0)
500 wxMenu
*menu
= node
->GetData();
501 result
= FindMenuItemByIdRecursive( menu
, id
);
502 node
= node
->GetNext();
507 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
513 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
515 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
517 wxCHECK_RET( node
, wxT("menu not found") );
519 wxMenu
* menu
= node
->GetData();
522 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
525 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
527 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
529 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
531 wxMenu
* menu
= node
->GetData();
533 return wxConvertFromGTKToWXLabel(menu
->GetTitle());
536 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
538 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
540 wxCHECK_RET( node
, wxT("menu not found") );
542 wxMenu
* menu
= node
->GetData();
544 const wxString
str( wxReplaceUnderscore( label
) );
546 menu
->SetTitle( str
);
549 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
552 //-----------------------------------------------------------------------------
554 //-----------------------------------------------------------------------------
557 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
559 int id
= menu
->FindMenuIdByMenuItem(widget
);
561 /* should find it for normal (not popup) menu */
562 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
563 _T("menu item not found in gtk_menu_clicked_callback") );
565 if (!menu
->IsEnabled(id
))
568 wxMenuItem
* item
= menu
->FindChildItem( id
);
569 wxCHECK_RET( item
, wxT("error in menu item callback") );
571 if ( item
->GetId() == wxGTK_TITLE_ID
)
573 // ignore events from the menu title
577 if (item
->IsCheckable())
579 bool isReallyChecked
= item
->IsChecked(),
580 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
582 // ensure that the internal state is always consistent with what is
583 // shown on the screen
584 item
->wxMenuItemBase::Check(isReallyChecked
);
586 // we must not report the events for the radio button going up nor the
587 // events resulting from the calls to wxMenuItem::Check()
588 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
589 (isInternallyChecked
== isReallyChecked
) )
596 // Is this menu on a menubar? (possibly nested)
597 wxFrame
* frame
= NULL
;
598 if(menu
->IsAttached())
599 frame
= menu
->GetMenuBar()->GetFrame();
601 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
602 // normally wxMenu::SendEvent() should be enough, if it doesn't work
603 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
604 // should be fixed instead of working around it here...
607 // If it is attached then let the frame send the event.
608 // Don't call frame->ProcessCommand(id) because it toggles
609 // checkable items and we've already done that above.
610 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
611 commandEvent
.SetEventObject(frame
);
612 if (item
->IsCheckable())
613 commandEvent
.SetInt(item
->IsChecked());
614 commandEvent
.SetEventObject(menu
);
616 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
620 // otherwise let the menu have it
621 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
626 //-----------------------------------------------------------------------------
628 //-----------------------------------------------------------------------------
631 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
633 int id
= menu
->FindMenuIdByMenuItem(widget
);
635 wxASSERT( id
!= -1 ); // should find it!
637 if (!menu
->IsEnabled(id
))
640 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
641 event
.SetEventObject( menu
);
643 wxEvtHandler
* handler
= menu
->GetEventHandler();
644 if (handler
&& handler
->ProcessEvent(event
))
647 wxWindow
*win
= menu
->GetInvokingWindow();
648 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
652 //-----------------------------------------------------------------------------
654 //-----------------------------------------------------------------------------
657 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
659 int id
= menu
->FindMenuIdByMenuItem(widget
);
661 wxASSERT( id
!= -1 ); // should find it!
663 if (!menu
->IsEnabled(id
))
666 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
667 event
.SetEventObject( menu
);
669 wxEvtHandler
* handler
= menu
->GetEventHandler();
670 if (handler
&& handler
->ProcessEvent(event
))
673 wxWindow
*win
= menu
->GetInvokingWindow();
675 win
->GetEventHandler()->ProcessEvent( event
);
679 //-----------------------------------------------------------------------------
681 //-----------------------------------------------------------------------------
683 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
685 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
687 const wxString
& name
,
688 const wxString
& help
,
692 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
695 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
697 const wxString
& text
,
698 const wxString
& help
,
701 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
706 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
708 const wxString
& text
,
709 const wxString
& help
,
712 : wxMenuItemBase(parentMenu
, id
, text
, help
,
713 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
718 void wxMenuItem::Init(const wxString
& text
)
720 m_labelWidget
= (GtkWidget
*) NULL
;
721 m_menuItem
= (GtkWidget
*) NULL
;
726 wxMenuItem::~wxMenuItem()
728 // don't delete menu items, the menus take care of that
731 // return the menu item text without any menu accels
734 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
736 // The argument to this function will now always be in wxWidgets standard label
737 // format, not GTK+ format, so we do what the other ports do.
739 return wxStripMenuCodes(text
);
744 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
746 if ( *pc
== wxT('\t'))
749 if ( *pc
== wxT('_') )
751 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
757 if ( *pc
== wxT('\\') )
759 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
765 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
768 // "&" is doubled to indicate "&" instead of accelerator
775 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
781 wxString
wxMenuItem::GetItemLabel() const
783 wxString label
= wxConvertFromGTKToWXLabel(m_text
);
784 if (!m_hotKey
.IsEmpty())
785 label
= label
+ wxT("\t") + m_hotKey
;
789 void wxMenuItem::SetItemLabel( const wxString
& str
)
791 // cache some data which must be used later
792 bool isstock
= wxIsStockID(GetId());
793 const char *stockid
= NULL
;
795 stockid
= wxGetStockGtkID(GetId());
797 // Some optimization to avoid flicker
798 wxString oldLabel
= m_text
;
799 oldLabel
= wxStripMenuCodes(oldLabel
);
800 oldLabel
.Replace(wxT("_"), wxT(""));
801 wxString label1
= wxStripMenuCodes(str
);
802 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
803 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
807 if (oldLabel
== label1
&&
808 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
815 label
= (GtkLabel
*) m_labelWidget
;
817 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
819 // stock menu items can have empty labels:
820 wxString text
= m_text
;
821 if (text
.IsEmpty() && !IsSeparator())
823 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
824 text
= wxGetStockLabel(GetId());
826 // need & => _ conversion
827 text
= GTKProcessMenuItemLabel(text
, NULL
);
830 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
833 // remove old accelerator from our parent's accelerator group, if present
835 GdkModifierType accel_mods
;
836 if (oldbuf
[(size_t)0] != '\0')
838 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
841 gtk_widget_remove_accelerator(m_menuItem
,
842 m_parentMenu
->m_accel
,
849 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
850 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
851 gtk_widget_remove_accelerator( m_menuItem
,
852 m_parentMenu
->m_accel
,
857 // add new accelerator to our parent's accelerator group
858 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
859 if (buf
[(size_t)0] != '\0')
861 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
864 gtk_widget_add_accelerator( m_menuItem
,
866 m_parentMenu
->m_accel
,
874 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
875 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
876 gtk_widget_remove_accelerator( m_menuItem
,
877 m_parentMenu
->m_accel
,
883 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
884 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
885 // so there's no real code duplication
886 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
890 // '\t' is the deliminator indicating a hot key
891 wxString::const_iterator pc
= str
.begin();
892 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
896 wxString::const_iterator next
= pc
+ 1;
897 if (next
!= str
.end() && *next
== wxT('&'))
899 // "&" is doubled to indicate "&" instead of accelerator
908 else if ( *pc
== wxT('_') ) // escape underscores
925 hotKey
->assign(pc
, str
.end());
932 // it's valid for this function to be called even if m_menuItem == NULL
933 void wxMenuItem::DoSetText( const wxString
& str
)
936 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
941 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
949 // accelerator parsing code looks for them after a TAB, so insert a dummy
952 label
<< wxT('\t') << GetHotKey();
954 return wxAcceleratorEntry::Create(label
);
957 #endif // wxUSE_ACCEL
959 void wxMenuItem::Check( bool check
)
961 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
963 if (check
== m_isChecked
)
966 wxMenuItemBase::Check( check
);
972 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
976 wxFAIL_MSG( _T("can't check this item") );
980 void wxMenuItem::Enable( bool enable
)
982 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
984 gtk_widget_set_sensitive( m_menuItem
, enable
);
985 wxMenuItemBase::Enable( enable
);
988 bool wxMenuItem::IsChecked() const
990 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
992 wxCHECK_MSG( IsCheckable(), false,
993 wxT("can't get state of uncheckable item!") );
995 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
998 //-----------------------------------------------------------------------------
1000 //-----------------------------------------------------------------------------
1002 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
1006 m_accel
= gtk_accel_group_new();
1007 m_menu
= gtk_menu_new();
1008 // NB: keep reference to the menu so that it is not destroyed behind
1009 // our back by GTK+ e.g. when it is removed from menubar:
1010 gtk_widget_ref(m_menu
);
1012 m_owner
= (GtkWidget
*) NULL
;
1014 // Tearoffs are entries, just like separators. So if we want this
1015 // menu to be a tear-off one, we just append a tearoff entry
1017 if ( m_style
& wxMENU_TEAROFF
)
1019 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
1021 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
1026 // append the title as the very first entry if we have it
1027 if ( !m_title
.empty() )
1029 Append(wxGTK_TITLE_ID
, m_title
);
1036 if ( GTK_IS_WIDGET( m_menu
))
1039 gtk_widget_unref( m_menu
);
1040 g_object_unref( m_accel
);
1042 // if the menu is inserted in another menu at this time, there was
1043 // one more reference to it:
1045 gtk_widget_destroy( m_menu
);
1048 // This must come after we release GTK resources above. Otherwise, GTK will
1049 // give warnings/errors when attempting to free accelerator resources from
1050 // child items that just were destroyed (the m_menu widget can contain
1051 // references to accelerators in child items. Problem detected when removing
1052 // a menu from a wxMenuBar, and the removed menu had submenus with accelerators.)
1053 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1056 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1059 wxWindow::GTKSetLayout(m_owner
, dir
);
1060 //else: will be called later by wxMenuBar again
1063 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1065 return wxWindow::GTKGetLayout(m_owner
);
1068 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1070 GtkWidget
*menuItem
;
1072 // cache some data used later
1073 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1074 int id
= mitem
->GetId();
1075 bool isstock
= wxIsStockID(id
);
1076 const char *stockid
= NULL
;
1078 stockid
= wxGetStockGtkID(mitem
->GetId());
1080 // stock menu items can have an empty label
1081 if (text
.IsEmpty() && !mitem
->IsSeparator())
1083 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1084 text
= wxGetStockLabel(id
);
1086 // need & => _ conversion
1087 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1090 if ( mitem
->IsSeparator() )
1092 menuItem
= gtk_separator_menu_item_new();
1094 else if ( mitem
->GetBitmap().Ok() ||
1095 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1097 wxBitmap
bitmap(mitem
->GetBitmap());
1099 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1104 // use stock bitmap for this item if available on the assumption
1105 // that it never hurts to follow GTK+ conventions more closely
1106 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1109 else // we have a custom bitmap
1111 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1112 _T("only normal menu items can have bitmaps") );
1114 if ( bitmap
.HasPixbuf() )
1116 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1120 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1121 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1122 bitmap
.GetMask()->GetBitmap() :
1124 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1130 gtk_widget_show(image
);
1132 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1137 else // a normal item
1139 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1142 switch ( mitem
->GetKind() )
1146 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1153 GSList
*group
= NULL
;
1154 if ( m_prevRadio
== NULL
)
1156 // start of a new radio group
1157 m_prevRadio
= menuItem
=
1158 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1160 else // continue the radio group
1162 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1163 m_prevRadio
= menuItem
=
1164 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1170 wxFAIL_MSG( _T("unexpected menu item kind") );
1175 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1184 GdkModifierType accel_mods
;
1185 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1187 // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetItemLabel().c_str(), GetGtkHotKey(*mitem).c_str() );
1188 if (buf
[(size_t)0] != '\0')
1190 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1193 gtk_widget_add_accelerator (menuItem
,
1203 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1204 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1205 gtk_widget_add_accelerator( menuItem
,
1214 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1216 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1218 gtk_widget_show( menuItem
);
1220 if ( !mitem
->IsSeparator() )
1222 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1224 g_signal_connect (menuItem
, "select",
1225 G_CALLBACK (gtk_menu_hilight_callback
), this);
1226 g_signal_connect (menuItem
, "deselect",
1227 G_CALLBACK (gtk_menu_nolight_callback
), this);
1229 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1231 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1233 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1235 // if adding a submenu to a menu already existing in the menu bar, we
1236 // must set invoking window to allow processing events from this
1238 if ( m_invokingWindow
)
1239 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1243 g_signal_connect (menuItem
, "activate",
1244 G_CALLBACK (gtk_menu_clicked_callback
),
1249 mitem
->SetMenuItem(menuItem
);
1253 // This doesn't even exist!
1254 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1260 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1262 if (!GtkAppend(mitem
))
1265 return wxMenuBase::DoAppend(mitem
);
1268 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1270 if ( !wxMenuBase::DoInsert(pos
, item
) )
1274 if ( !GtkAppend(item
, (int)pos
) )
1280 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1282 if ( !wxMenuBase::DoRemove(item
) )
1283 return (wxMenuItem
*)NULL
;
1285 // TODO: this code doesn't delete the item factory item and this seems
1286 // impossible as of GTK 1.2.6.
1287 gtk_widget_destroy( item
->GetMenuItem() );
1292 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1294 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1297 wxMenuItem
*item
= node
->GetData();
1298 if (item
->GetMenuItem() == menuItem
)
1299 return item
->GetId();
1300 node
= node
->GetNext();
1306 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1308 wxMenuBase::Attach(menubar
);
1310 // inherit layout direction from menubar.
1311 SetLayoutDirection(menubar
->GetLayoutDirection());
1314 // ----------------------------------------------------------------------------
1316 // ----------------------------------------------------------------------------
1320 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1324 wxAcceleratorEntry
*accel
= item
.GetAccel();
1327 int flags
= accel
->GetFlags();
1328 if ( flags
& wxACCEL_ALT
)
1329 hotkey
+= wxT("<alt>");
1330 if ( flags
& wxACCEL_CTRL
)
1331 hotkey
+= wxT("<control>");
1332 if ( flags
& wxACCEL_SHIFT
)
1333 hotkey
+= wxT("<shift>");
1335 int code
= accel
->GetKeyCode();
1362 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1365 // TODO: we should use gdk_keyval_name() (a.k.a.
1366 // XKeysymToString) here as well as hardcoding the keysym
1367 // names this might be not portable
1369 hotkey
<< wxT("Insert" );
1372 hotkey
<< wxT("Delete" );
1375 hotkey
<< wxT("Up" );
1378 hotkey
<< wxT("Down" );
1381 hotkey
<< wxT("Page_Up" );
1384 hotkey
<< wxT("Page_Down" );
1387 hotkey
<< wxT("Left" );
1390 hotkey
<< wxT("Right" );
1393 hotkey
<< wxT("Home" );
1396 hotkey
<< wxT("End" );
1399 hotkey
<< wxT("Return" );
1402 hotkey
<< wxT("BackSpace" );
1405 hotkey
<< wxT("Tab" );
1408 hotkey
<< wxT("Esc" );
1411 hotkey
<< wxT("space" );
1414 hotkey
<< wxT("Multiply" );
1417 hotkey
<< wxT("Add" );
1420 hotkey
<< wxT("Separator" );
1423 hotkey
<< wxT("Subtract" );
1426 hotkey
<< wxT("Decimal" );
1429 hotkey
<< wxT("Divide" );
1432 hotkey
<< wxT("Cancel" );
1435 hotkey
<< wxT("Clear" );
1438 hotkey
<< wxT("Menu" );
1441 hotkey
<< wxT("Pause" );
1444 hotkey
<< wxT("Capital" );
1447 hotkey
<< wxT("Select" );
1450 hotkey
<< wxT("Print" );
1453 hotkey
<< wxT("Execute" );
1456 hotkey
<< wxT("Snapshot" );
1459 hotkey
<< wxT("Help" );
1462 hotkey
<< wxT("Num_Lock" );
1465 hotkey
<< wxT("Scroll_Lock" );
1467 case WXK_NUMPAD_INSERT
:
1468 hotkey
<< wxT("KP_Insert" );
1470 case WXK_NUMPAD_DELETE
:
1471 hotkey
<< wxT("KP_Delete" );
1473 case WXK_NUMPAD_SPACE
:
1474 hotkey
<< wxT("KP_Space" );
1476 case WXK_NUMPAD_TAB
:
1477 hotkey
<< wxT("KP_Tab" );
1479 case WXK_NUMPAD_ENTER
:
1480 hotkey
<< wxT("KP_Enter" );
1482 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1484 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1486 case WXK_NUMPAD_HOME
:
1487 hotkey
<< wxT("KP_Home" );
1489 case WXK_NUMPAD_LEFT
:
1490 hotkey
<< wxT("KP_Left" );
1493 hotkey
<< wxT("KP_Up" );
1495 case WXK_NUMPAD_RIGHT
:
1496 hotkey
<< wxT("KP_Right" );
1498 case WXK_NUMPAD_DOWN
:
1499 hotkey
<< wxT("KP_Down" );
1501 case WXK_NUMPAD_PAGEUP
:
1502 hotkey
<< wxT("KP_Page_Up" );
1504 case WXK_NUMPAD_PAGEDOWN
:
1505 hotkey
<< wxT("KP_Page_Down" );
1507 case WXK_NUMPAD_END
:
1508 hotkey
<< wxT("KP_End" );
1510 case WXK_NUMPAD_BEGIN
:
1511 hotkey
<< wxT("KP_Begin" );
1513 case WXK_NUMPAD_EQUAL
:
1514 hotkey
<< wxT("KP_Equal" );
1516 case WXK_NUMPAD_MULTIPLY
:
1517 hotkey
<< wxT("KP_Multiply" );
1519 case WXK_NUMPAD_ADD
:
1520 hotkey
<< wxT("KP_Add" );
1522 case WXK_NUMPAD_SEPARATOR
:
1523 hotkey
<< wxT("KP_Separator" );
1525 case WXK_NUMPAD_SUBTRACT
:
1526 hotkey
<< wxT("KP_Subtract" );
1528 case WXK_NUMPAD_DECIMAL
:
1529 hotkey
<< wxT("KP_Decimal" );
1531 case WXK_NUMPAD_DIVIDE
:
1532 hotkey
<< wxT("KP_Divide" );
1534 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1535 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1536 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1537 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1539 case WXK_WINDOWS_LEFT
:
1540 hotkey
<< wxT("Super_L" );
1542 case WXK_WINDOWS_RIGHT
:
1543 hotkey
<< wxT("Super_R" );
1545 case WXK_WINDOWS_MENU
:
1546 hotkey
<< wxT("Menu" );
1549 hotkey
<< wxT("Command" );
1551 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1552 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1553 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1554 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1555 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1556 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1557 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1560 // if there are any other keys wxAcceleratorEntry::Create() may
1561 // return, we should process them here
1567 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1568 if ( !name
.empty() )
1575 wxFAIL_MSG( wxT("unknown keyboard accel") );
1584 #endif // wxUSE_ACCEL
1586 // ----------------------------------------------------------------------------
1587 // Pop-up menu stuff
1588 // ----------------------------------------------------------------------------
1590 #if wxUSE_MENUS_NATIVE
1592 extern "C" WXDLLIMPEXP_CORE
1593 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1595 *is_waiting
= false;
1598 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1600 menu
->SetInvokingWindow( win
);
1602 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1605 wxMenuItem
*menuitem
= node
->GetData();
1606 if (menuitem
->IsSubMenu())
1608 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1611 node
= node
->GetNext();
1615 extern "C" WXDLLIMPEXP_CORE
1616 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1618 gboolean
* WXUNUSED(whatever
),
1619 gpointer user_data
)
1621 // ensure that the menu appears entirely on screen
1623 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1625 wxSize sizeScreen
= wxGetDisplaySize();
1626 wxPoint
*pos
= (wxPoint
*)user_data
;
1628 gint xmax
= sizeScreen
.x
- req
.width
,
1629 ymax
= sizeScreen
.y
- req
.height
;
1631 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1632 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1635 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1637 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1639 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1641 // NOTE: if you change this code, you need to update
1642 // the same code in taskbar.cpp as well. This
1643 // is ugly code duplication, I know.
1645 SetInvokingWindow( menu
, this );
1649 bool is_waiting
= true;
1651 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1652 G_CALLBACK (gtk_pop_hide_callback
),
1657 GtkMenuPositionFunc posfunc
;
1658 if ( x
== -1 && y
== -1 )
1660 // use GTK's default positioning algorithm
1666 pos
= ClientToScreen(wxPoint(x
, y
));
1668 posfunc
= wxPopupMenuPositionCallback
;
1671 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1672 DoCommonMenuCallbackCode(menu
, eventOpen
);
1675 GTK_MENU(menu
->m_menu
),
1676 (GtkWidget
*) NULL
, // parent menu shell
1677 (GtkWidget
*) NULL
, // parent menu item
1678 posfunc
, // function to position it
1679 userdata
, // client data
1680 0, // button used to activate it
1681 gtk_get_current_event_time()
1686 gtk_main_iteration();
1689 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1691 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1692 DoCommonMenuCallbackCode(menu
, eventClose
);
1697 #endif // wxUSE_MENUS_NATIVE
1701 #include <gtk/gtk.h>
1703 const char *wxGetStockGtkID(wxWindowID id
)
1705 #define STOCKITEM(wx,gtk) \
1709 #define STOCKITEM_MISSING(wx) \
1713 #if GTK_CHECK_VERSION(2,4,0)
1714 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1716 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1719 #if GTK_CHECK_VERSION(2,6,0)
1720 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1722 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1725 #if GTK_CHECK_VERSION(2,10,0)
1726 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1728 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1734 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1735 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1736 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1737 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1738 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1739 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1740 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1741 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1742 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1743 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1744 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1745 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1746 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1747 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1748 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1749 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1750 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1751 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1752 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1753 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1754 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1755 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1756 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1757 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1758 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1759 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1760 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1761 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1762 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1763 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1764 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1765 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1766 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1767 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1768 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1769 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1770 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1771 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1772 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1773 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1774 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1775 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1776 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1777 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1778 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1779 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1780 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1781 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1782 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1783 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1784 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1785 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1786 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1787 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1790 wxFAIL_MSG( _T("invalid stock item ID") );
1799 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1804 GtkStockItem stock_item
;
1805 if (gtk_stock_lookup (id
, &stock_item
))
1807 if (key
) *key
= stock_item
.keyval
;
1808 if (mod
) *mod
= stock_item
.modifier
;
1810 // some GTK stock items have zero values for the keyval;
1811 // it means that they do not have an accelerator...
1812 if (stock_item
.keyval
)
1819 #endif // __WXGTK20__
1821 #endif // wxUSE_MENUS