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"
30 #include <gdk/gdktypes.h>
33 // FIXME: is this right? somehow I don't think so (VZ)
35 #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
36 //#define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
37 //#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
39 #define ACCEL_OBJECT GtkWindow
40 #define ACCEL_OBJECTS(a) (a)->acceleratables
41 #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
43 // we use normal item but with a special id for the menu title
44 static const int wxGTK_TITLE_ID
= -3;
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
51 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 static wxString
wxReplaceUnderscore( const wxString
& title
)
60 // GTK 1.2 wants to have "_" instead of "&" for accelerators
63 for ( wxString::const_iterator pc
= title
.begin(); pc
!= title
.end(); ++pc
)
65 if ((*pc
== wxT('&')) && (pc
+1 != title
.end()) && (*(pc
+1) == wxT('&')))
67 // "&" is doubled to indicate "&" instead of accelerator
71 else if (*pc
== wxT('&'))
77 if ( *pc
== wxT('_') )
79 // underscores must be doubled to prevent them from being
80 // interpreted as accelerator character prefix by GTK
88 // wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() );
93 static wxString
wxConvertFromGTKToWXLabel(const wxString
& gtkLabel
)
96 for ( const wxChar
*pc
= gtkLabel
.c_str(); *pc
; pc
++ )
98 // '_' is the escape character for GTK+.
100 if ( *pc
== wxT('_') && *(pc
+1) == wxT('_'))
102 // An underscore was escaped.
106 else if ( *pc
== wxT('_') )
108 // Convert GTK+ hotkey symbol to wxWidgets/Windows standard
111 else if ( *pc
== wxT('&') )
113 // Double the ampersand to escape it as far as wxWidgets is concerned
118 // don't remove ampersands '&' since if we have them in the menu title
119 // it means that they were doubled to indicate "&" instead of accelerator
127 //-----------------------------------------------------------------------------
128 // activate message from GTK
129 //-----------------------------------------------------------------------------
131 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
133 event
.SetEventObject( menu
);
135 wxEvtHandler
* handler
= menu
->GetEventHandler();
136 if (handler
&& handler
->ProcessEvent(event
))
139 wxWindow
*win
= menu
->GetInvokingWindow();
141 win
->GetEventHandler()->ProcessEvent( event
);
146 static void gtk_menu_open_callback( GtkWidget
*widget
, wxMenu
*menu
)
148 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
150 DoCommonMenuCallbackCode(menu
, event
);
153 static void gtk_menu_close_callback( GtkWidget
*widget
, wxMenuBar
*menubar
)
155 if ( !menubar
->GetMenuCount() )
157 // if menubar is empty we can't call GetMenu(0) below
161 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
163 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
168 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
172 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
174 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
177 m_invokingWindow
= NULL
;
179 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
180 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
182 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
186 m_menubar
= gtk_menu_bar_new();
188 if (style
& wxMB_DOCKABLE
)
190 m_widget
= gtk_handle_box_new();
191 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
192 gtk_widget_show(m_menubar
);
196 m_widget
= m_menubar
;
203 for (size_t i
= 0; i
< n
; ++i
)
204 Append(menus
[i
], titles
[i
]);
206 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
207 // don't get it when the menu is dismissed by clicking outside the
208 // toolbar) so we connect to the global one, even if it means that we
209 // can't pass the menu which was closed in wxMenuEvent object
210 g_signal_connect (m_menubar
, "deactivate",
211 G_CALLBACK (gtk_menu_close_callback
), this);
215 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
217 Init(n
, menus
, titles
, style
);
220 wxMenuBar::wxMenuBar(long style
)
222 Init(0, NULL
, NULL
, style
);
225 wxMenuBar::wxMenuBar()
227 Init(0, NULL
, NULL
, 0);
230 wxMenuBar::~wxMenuBar()
234 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
236 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
238 wxWindow
*top_frame
= win
;
239 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
240 top_frame
= top_frame
->GetParent();
242 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
245 wxMenuItem
*menuitem
= node
->GetData();
246 if (menuitem
->IsSubMenu())
247 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
248 node
= node
->GetNext();
252 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
254 menu
->SetInvokingWindow( win
);
256 wxWindow
*top_frame
= win
;
257 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
258 top_frame
= top_frame
->GetParent();
260 // support for native hot keys
261 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
262 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
263 gtk_accel_group_attach( menu
->m_accel
, obj
);
265 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
268 wxMenuItem
*menuitem
= node
->GetData();
269 if (menuitem
->IsSubMenu())
270 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
271 node
= node
->GetNext();
275 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
277 m_invokingWindow
= win
;
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 wxMenubarSetInvokingWindow( menu
, win
);
287 node
= node
->GetNext();
291 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
293 if ( dir
== wxLayout_Default
)
295 const wxWindow
*const frame
= GetFrame();
298 // inherit layout from frame.
299 dir
= frame
->GetLayoutDirection();
301 else // use global layout
303 dir
= wxTheApp
->GetLayoutDirection();
307 if ( dir
== wxLayout_Default
)
310 GTKSetLayout(m_menubar
, dir
);
312 // also set the layout of all menus we already have (new ones will inherit
313 // the current layout)
314 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
316 node
= node
->GetNext() )
318 wxMenu
*const menu
= node
->GetData();
319 menu
->SetLayoutDirection(dir
);
323 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
325 return GTKGetLayout(m_menubar
);
328 void wxMenuBar::Attach(wxFrame
*frame
)
330 wxMenuBarBase::Attach(frame
);
332 SetLayoutDirection(wxLayout_Default
);
335 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
337 m_invokingWindow
= (wxWindow
*) NULL
;
338 wxWindow
*top_frame
= win
;
339 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
340 top_frame
= top_frame
->GetParent();
342 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
345 wxMenu
*menu
= node
->GetData();
346 wxMenubarUnsetInvokingWindow( menu
, win
);
347 node
= node
->GetNext();
351 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
353 if ( !wxMenuBarBase::Append( menu
, title
) )
356 return GtkAppend(menu
, title
);
359 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
361 wxString
str( wxReplaceUnderscore( title
) );
363 // This doesn't have much effect right now.
364 menu
->SetTitle( str
);
366 // The "m_owner" is the "menu item"
367 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
368 menu
->SetLayoutDirection(GetLayoutDirection());
370 gtk_widget_show( menu
->m_owner
);
372 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
375 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
377 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
379 g_signal_connect (menu
->m_owner
, "activate",
380 G_CALLBACK (gtk_menu_open_callback
),
383 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
384 // addings menu later on.
385 if (m_invokingWindow
)
387 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
389 // OPTIMISE ME: we should probably cache this, or pass it
390 // directly, but for now this is a minimal
391 // change to validate the new dynamic sizing.
392 // see (and refactor :) similar code in Remove
395 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
398 frame
->UpdateMenuBarSize();
404 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
406 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
411 if ( !GtkAppend(menu
, title
, (int)pos
) )
417 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
419 // remove the old item and insert a new one
420 wxMenu
*menuOld
= Remove(pos
);
421 if ( menuOld
&& !Insert(pos
, menu
, title
) )
423 return (wxMenu
*) NULL
;
426 // either Insert() succeeded or Remove() failed and menuOld is NULL
430 wxMenu
*wxMenuBar::Remove(size_t pos
)
432 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
434 return (wxMenu
*) NULL
;
436 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
437 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
439 gtk_widget_destroy( menu
->m_owner
);
440 menu
->m_owner
= NULL
;
442 if (m_invokingWindow
)
444 // OPTIMISE ME: see comment in GtkAppend
445 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
448 frame
->UpdateMenuBarSize();
454 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
456 if (wxMenuItem::GetLabelText(wxConvertFromGTKToWXLabel(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
458 int res
= menu
->FindItem( itemString
);
459 if (res
!= wxNOT_FOUND
)
463 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
466 wxMenuItem
*item
= node
->GetData();
467 if (item
->IsSubMenu())
468 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
470 node
= node
->GetNext();
476 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
478 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
481 wxMenu
*menu
= node
->GetData();
482 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
485 node
= node
->GetNext();
491 // Find a wxMenuItem using its id. Recurses down into sub-menus
492 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
494 wxMenuItem
* result
= menu
->FindChildItem(id
);
496 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
497 while ( node
&& result
== NULL
)
499 wxMenuItem
*item
= node
->GetData();
500 if (item
->IsSubMenu())
502 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
504 node
= node
->GetNext();
510 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
512 wxMenuItem
* result
= 0;
513 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
514 while (node
&& result
== 0)
516 wxMenu
*menu
= node
->GetData();
517 result
= FindMenuItemByIdRecursive( menu
, id
);
518 node
= node
->GetNext();
523 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
529 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
531 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
533 wxCHECK_RET( node
, wxT("menu not found") );
535 wxMenu
* menu
= node
->GetData();
538 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
541 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
543 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
545 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
547 wxMenu
* menu
= node
->GetData();
549 return wxConvertFromGTKToWXLabel(menu
->GetTitle());
552 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
554 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
556 wxCHECK_RET( node
, wxT("menu not found") );
558 wxMenu
* menu
= node
->GetData();
560 const wxString
str( wxReplaceUnderscore( label
) );
562 menu
->SetTitle( str
);
565 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
568 //-----------------------------------------------------------------------------
570 //-----------------------------------------------------------------------------
573 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
575 int id
= menu
->FindMenuIdByMenuItem(widget
);
577 /* should find it for normal (not popup) menu */
578 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
579 _T("menu item not found in gtk_menu_clicked_callback") );
581 if (!menu
->IsEnabled(id
))
584 wxMenuItem
* item
= menu
->FindChildItem( id
);
585 wxCHECK_RET( item
, wxT("error in menu item callback") );
587 if ( item
->GetId() == wxGTK_TITLE_ID
)
589 // ignore events from the menu title
593 if (item
->IsCheckable())
595 bool isReallyChecked
= item
->IsChecked(),
596 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
598 // ensure that the internal state is always consistent with what is
599 // shown on the screen
600 item
->wxMenuItemBase::Check(isReallyChecked
);
602 // we must not report the events for the radio button going up nor the
603 // events resulting from the calls to wxMenuItem::Check()
604 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
605 (isInternallyChecked
== isReallyChecked
) )
612 // Is this menu on a menubar? (possibly nested)
613 wxFrame
* frame
= NULL
;
614 if(menu
->IsAttached())
615 frame
= menu
->GetMenuBar()->GetFrame();
617 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
618 // normally wxMenu::SendEvent() should be enough, if it doesn't work
619 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
620 // should be fixed instead of working around it here...
623 // If it is attached then let the frame send the event.
624 // Don't call frame->ProcessCommand(id) because it toggles
625 // checkable items and we've already done that above.
626 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
627 commandEvent
.SetEventObject(frame
);
628 if (item
->IsCheckable())
629 commandEvent
.SetInt(item
->IsChecked());
630 commandEvent
.SetEventObject(menu
);
632 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
636 // otherwise let the menu have it
637 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
642 //-----------------------------------------------------------------------------
644 //-----------------------------------------------------------------------------
647 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
649 int id
= menu
->FindMenuIdByMenuItem(widget
);
651 wxASSERT( id
!= -1 ); // should find it!
653 if (!menu
->IsEnabled(id
))
656 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
657 event
.SetEventObject( menu
);
659 wxEvtHandler
* handler
= menu
->GetEventHandler();
660 if (handler
&& handler
->ProcessEvent(event
))
663 wxWindow
*win
= menu
->GetInvokingWindow();
664 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
668 //-----------------------------------------------------------------------------
670 //-----------------------------------------------------------------------------
673 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
675 int id
= menu
->FindMenuIdByMenuItem(widget
);
677 wxASSERT( id
!= -1 ); // should find it!
679 if (!menu
->IsEnabled(id
))
682 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
683 event
.SetEventObject( menu
);
685 wxEvtHandler
* handler
= menu
->GetEventHandler();
686 if (handler
&& handler
->ProcessEvent(event
))
689 wxWindow
*win
= menu
->GetInvokingWindow();
691 win
->GetEventHandler()->ProcessEvent( event
);
695 //-----------------------------------------------------------------------------
697 //-----------------------------------------------------------------------------
699 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
701 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
703 const wxString
& name
,
704 const wxString
& help
,
708 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
711 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
713 const wxString
& text
,
714 const wxString
& help
,
717 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
722 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
724 const wxString
& text
,
725 const wxString
& help
,
728 : wxMenuItemBase(parentMenu
, id
, text
, help
,
729 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
734 void wxMenuItem::Init(const wxString
& text
)
736 m_labelWidget
= (GtkWidget
*) NULL
;
737 m_menuItem
= (GtkWidget
*) NULL
;
742 wxMenuItem::~wxMenuItem()
744 // don't delete menu items, the menus take care of that
747 // return the menu item text without any menu accels
750 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
752 // The argument to this function will now always be in wxWidgets standard label
753 // format, not GTK+ format, so we do what the other ports do.
755 return wxStripMenuCodes(text
);
760 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
762 if ( *pc
== wxT('\t'))
765 if ( *pc
== wxT('_') )
767 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
773 if ( *pc
== wxT('\\') )
775 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
781 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
784 // "&" is doubled to indicate "&" instead of accelerator
791 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
797 wxString
wxMenuItem::GetItemLabel() const
799 wxString label
= wxConvertFromGTKToWXLabel(m_text
);
800 if (!m_hotKey
.IsEmpty())
801 label
= label
+ wxT("\t") + m_hotKey
;
805 void wxMenuItem::SetItemLabel( const wxString
& str
)
807 // cache some data which must be used later
808 bool isstock
= wxIsStockID(GetId());
809 const char *stockid
= NULL
;
811 stockid
= wxGetStockGtkID(GetId());
813 // Some optimization to avoid flicker
814 wxString oldLabel
= m_text
;
815 oldLabel
= wxStripMenuCodes(oldLabel
);
816 oldLabel
.Replace(wxT("_"), wxT(""));
817 wxString label1
= wxStripMenuCodes(str
);
818 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
819 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
823 if (oldLabel
== label1
&&
824 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
831 label
= (GtkLabel
*) m_labelWidget
;
833 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
835 // stock menu items can have empty labels:
836 wxString text
= m_text
;
837 if (text
.IsEmpty() && !IsSeparator())
839 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
840 text
= wxGetStockLabel(GetId());
842 // need & => _ conversion
843 text
= GTKProcessMenuItemLabel(text
, NULL
);
846 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
849 // remove old accelerator from our parent's accelerator group, if present
851 GdkModifierType accel_mods
;
852 if (oldbuf
[(size_t)0] != '\0')
854 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
857 gtk_widget_remove_accelerator(m_menuItem
,
858 m_parentMenu
->m_accel
,
865 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
866 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
867 gtk_widget_remove_accelerator( m_menuItem
,
868 m_parentMenu
->m_accel
,
873 // add new accelerator to our parent's accelerator group
874 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
875 if (buf
[(size_t)0] != '\0')
877 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
880 gtk_widget_add_accelerator( m_menuItem
,
882 m_parentMenu
->m_accel
,
890 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
891 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
892 gtk_widget_remove_accelerator( m_menuItem
,
893 m_parentMenu
->m_accel
,
899 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
900 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
901 // so there's no real code duplication
902 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
906 // '\t' is the deliminator indicating a hot key
907 wxString::const_iterator pc
= str
.begin();
908 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
912 wxString::const_iterator next
= pc
+ 1;
913 if (next
!= str
.end() && *next
== wxT('&'))
915 // "&" is doubled to indicate "&" instead of accelerator
924 else if ( *pc
== wxT('_') ) // escape underscores
941 hotKey
->assign(pc
, str
.end());
948 // it's valid for this function to be called even if m_menuItem == NULL
949 void wxMenuItem::DoSetText( const wxString
& str
)
952 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
957 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
965 // accelerator parsing code looks for them after a TAB, so insert a dummy
968 label
<< wxT('\t') << GetHotKey();
970 return wxAcceleratorEntry::Create(label
);
973 #endif // wxUSE_ACCEL
975 void wxMenuItem::Check( bool check
)
977 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
979 if (check
== m_isChecked
)
982 wxMenuItemBase::Check( check
);
988 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
992 wxFAIL_MSG( _T("can't check this item") );
996 void wxMenuItem::Enable( bool enable
)
998 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
1000 gtk_widget_set_sensitive( m_menuItem
, enable
);
1001 wxMenuItemBase::Enable( enable
);
1004 bool wxMenuItem::IsChecked() const
1006 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
1008 wxCHECK_MSG( IsCheckable(), false,
1009 wxT("can't get state of uncheckable item!") );
1011 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
1014 //-----------------------------------------------------------------------------
1016 //-----------------------------------------------------------------------------
1018 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
1022 m_accel
= gtk_accel_group_new();
1023 m_menu
= gtk_menu_new();
1024 // NB: keep reference to the menu so that it is not destroyed behind
1025 // our back by GTK+ e.g. when it is removed from menubar:
1026 gtk_widget_ref(m_menu
);
1028 m_owner
= (GtkWidget
*) NULL
;
1030 // Tearoffs are entries, just like separators. So if we want this
1031 // menu to be a tear-off one, we just append a tearoff entry
1033 if ( m_style
& wxMENU_TEAROFF
)
1035 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
1037 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
1042 // append the title as the very first entry if we have it
1043 if ( !m_title
.empty() )
1045 Append(wxGTK_TITLE_ID
, m_title
);
1052 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1054 if ( GTK_IS_WIDGET( m_menu
))
1057 gtk_widget_unref( m_menu
);
1058 g_object_unref( m_accel
);
1060 // if the menu is inserted in another menu at this time, there was
1061 // one more reference to it:
1063 gtk_widget_destroy( m_menu
);
1067 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1070 wxWindow::GTKSetLayout(m_owner
, dir
);
1071 //else: will be called later by wxMenuBar again
1074 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1076 return wxWindow::GTKGetLayout(m_owner
);
1079 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1081 GtkWidget
*menuItem
;
1083 // cache some data used later
1084 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1085 int id
= mitem
->GetId();
1086 bool isstock
= wxIsStockID(id
);
1087 const char *stockid
= NULL
;
1089 stockid
= wxGetStockGtkID(mitem
->GetId());
1091 // stock menu items can have an empty label
1092 if (text
.IsEmpty() && !mitem
->IsSeparator())
1094 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1095 text
= wxGetStockLabel(id
);
1097 // need & => _ conversion
1098 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1101 if ( mitem
->IsSeparator() )
1103 menuItem
= gtk_separator_menu_item_new();
1105 else if ( mitem
->GetBitmap().Ok() ||
1106 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1108 wxBitmap
bitmap(mitem
->GetBitmap());
1110 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1115 // use stock bitmap for this item if available on the assumption
1116 // that it never hurts to follow GTK+ conventions more closely
1117 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1120 else // we have a custom bitmap
1122 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1123 _T("only normal menu items can have bitmaps") );
1125 if ( bitmap
.HasPixbuf() )
1127 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1131 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1132 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1133 bitmap
.GetMask()->GetBitmap() :
1135 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1141 gtk_widget_show(image
);
1143 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1148 else // a normal item
1150 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1153 switch ( mitem
->GetKind() )
1157 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1164 GSList
*group
= NULL
;
1165 if ( m_prevRadio
== NULL
)
1167 // start of a new radio group
1168 m_prevRadio
= menuItem
=
1169 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1171 else // continue the radio group
1173 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1174 m_prevRadio
= menuItem
=
1175 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1181 wxFAIL_MSG( _T("unexpected menu item kind") );
1186 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1195 GdkModifierType accel_mods
;
1196 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1198 // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetItemLabel().c_str(), GetGtkHotKey(*mitem).c_str() );
1199 if (buf
[(size_t)0] != '\0')
1201 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1204 gtk_widget_add_accelerator (menuItem
,
1214 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1215 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1216 gtk_widget_add_accelerator( menuItem
,
1225 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1227 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1229 gtk_widget_show( menuItem
);
1231 if ( !mitem
->IsSeparator() )
1233 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1235 g_signal_connect (menuItem
, "select",
1236 G_CALLBACK (gtk_menu_hilight_callback
), this);
1237 g_signal_connect (menuItem
, "deselect",
1238 G_CALLBACK (gtk_menu_nolight_callback
), this);
1240 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1242 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1244 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1246 // if adding a submenu to a menu already existing in the menu bar, we
1247 // must set invoking window to allow processing events from this
1249 if ( m_invokingWindow
)
1250 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1254 g_signal_connect (menuItem
, "activate",
1255 G_CALLBACK (gtk_menu_clicked_callback
),
1260 mitem
->SetMenuItem(menuItem
);
1264 // This doesn't even exist!
1265 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1271 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1273 if (!GtkAppend(mitem
))
1276 return wxMenuBase::DoAppend(mitem
);
1279 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1281 if ( !wxMenuBase::DoInsert(pos
, item
) )
1285 if ( !GtkAppend(item
, (int)pos
) )
1291 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1293 if ( !wxMenuBase::DoRemove(item
) )
1294 return (wxMenuItem
*)NULL
;
1296 // TODO: this code doesn't delete the item factory item and this seems
1297 // impossible as of GTK 1.2.6.
1298 gtk_widget_destroy( item
->GetMenuItem() );
1303 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1305 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1308 wxMenuItem
*item
= node
->GetData();
1309 if (item
->GetMenuItem() == menuItem
)
1310 return item
->GetId();
1311 node
= node
->GetNext();
1317 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1319 wxMenuBase::Attach(menubar
);
1321 // inherit layout direction from menubar.
1322 SetLayoutDirection(menubar
->GetLayoutDirection());
1325 // ----------------------------------------------------------------------------
1327 // ----------------------------------------------------------------------------
1331 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1335 wxAcceleratorEntry
*accel
= item
.GetAccel();
1338 int flags
= accel
->GetFlags();
1339 if ( flags
& wxACCEL_ALT
)
1340 hotkey
+= wxT("<alt>");
1341 if ( flags
& wxACCEL_CTRL
)
1342 hotkey
+= wxT("<control>");
1343 if ( flags
& wxACCEL_SHIFT
)
1344 hotkey
+= wxT("<shift>");
1346 int code
= accel
->GetKeyCode();
1373 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1376 // TODO: we should use gdk_keyval_name() (a.k.a.
1377 // XKeysymToString) here as well as hardcoding the keysym
1378 // names this might be not portable
1380 hotkey
<< wxT("Insert" );
1383 hotkey
<< wxT("Delete" );
1386 hotkey
<< wxT("Up" );
1389 hotkey
<< wxT("Down" );
1392 hotkey
<< wxT("Page_Up" );
1395 hotkey
<< wxT("Page_Down" );
1398 hotkey
<< wxT("Left" );
1401 hotkey
<< wxT("Right" );
1404 hotkey
<< wxT("Home" );
1407 hotkey
<< wxT("End" );
1410 hotkey
<< wxT("Return" );
1413 hotkey
<< wxT("BackSpace" );
1416 hotkey
<< wxT("Tab" );
1419 hotkey
<< wxT("Esc" );
1422 hotkey
<< wxT("space" );
1425 hotkey
<< wxT("Multiply" );
1428 hotkey
<< wxT("Add" );
1431 hotkey
<< wxT("Separator" );
1434 hotkey
<< wxT("Subtract" );
1437 hotkey
<< wxT("Decimal" );
1440 hotkey
<< wxT("Divide" );
1443 hotkey
<< wxT("Cancel" );
1446 hotkey
<< wxT("Clear" );
1449 hotkey
<< wxT("Menu" );
1452 hotkey
<< wxT("Pause" );
1455 hotkey
<< wxT("Capital" );
1458 hotkey
<< wxT("Select" );
1461 hotkey
<< wxT("Print" );
1464 hotkey
<< wxT("Execute" );
1467 hotkey
<< wxT("Snapshot" );
1470 hotkey
<< wxT("Help" );
1473 hotkey
<< wxT("Num_Lock" );
1476 hotkey
<< wxT("Scroll_Lock" );
1478 case WXK_NUMPAD_INSERT
:
1479 hotkey
<< wxT("KP_Insert" );
1481 case WXK_NUMPAD_DELETE
:
1482 hotkey
<< wxT("KP_Delete" );
1484 case WXK_NUMPAD_SPACE
:
1485 hotkey
<< wxT("KP_Space" );
1487 case WXK_NUMPAD_TAB
:
1488 hotkey
<< wxT("KP_Tab" );
1490 case WXK_NUMPAD_ENTER
:
1491 hotkey
<< wxT("KP_Enter" );
1493 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1495 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1497 case WXK_NUMPAD_HOME
:
1498 hotkey
<< wxT("KP_Home" );
1500 case WXK_NUMPAD_LEFT
:
1501 hotkey
<< wxT("KP_Left" );
1504 hotkey
<< wxT("KP_Up" );
1506 case WXK_NUMPAD_RIGHT
:
1507 hotkey
<< wxT("KP_Right" );
1509 case WXK_NUMPAD_DOWN
:
1510 hotkey
<< wxT("KP_Down" );
1512 case WXK_NUMPAD_PAGEUP
:
1513 hotkey
<< wxT("KP_Page_Up" );
1515 case WXK_NUMPAD_PAGEDOWN
:
1516 hotkey
<< wxT("KP_Page_Down" );
1518 case WXK_NUMPAD_END
:
1519 hotkey
<< wxT("KP_End" );
1521 case WXK_NUMPAD_BEGIN
:
1522 hotkey
<< wxT("KP_Begin" );
1524 case WXK_NUMPAD_EQUAL
:
1525 hotkey
<< wxT("KP_Equal" );
1527 case WXK_NUMPAD_MULTIPLY
:
1528 hotkey
<< wxT("KP_Multiply" );
1530 case WXK_NUMPAD_ADD
:
1531 hotkey
<< wxT("KP_Add" );
1533 case WXK_NUMPAD_SEPARATOR
:
1534 hotkey
<< wxT("KP_Separator" );
1536 case WXK_NUMPAD_SUBTRACT
:
1537 hotkey
<< wxT("KP_Subtract" );
1539 case WXK_NUMPAD_DECIMAL
:
1540 hotkey
<< wxT("KP_Decimal" );
1542 case WXK_NUMPAD_DIVIDE
:
1543 hotkey
<< wxT("KP_Divide" );
1545 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1546 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1547 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1548 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1550 case WXK_WINDOWS_LEFT
:
1551 hotkey
<< wxT("Super_L" );
1553 case WXK_WINDOWS_RIGHT
:
1554 hotkey
<< wxT("Super_R" );
1556 case WXK_WINDOWS_MENU
:
1557 hotkey
<< wxT("Menu" );
1560 hotkey
<< wxT("Command" );
1562 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1563 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1564 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1565 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1566 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1567 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1568 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1571 // if there are any other keys wxAcceleratorEntry::Create() may
1572 // return, we should process them here
1578 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1579 if ( !name
.empty() )
1586 wxFAIL_MSG( wxT("unknown keyboard accel") );
1595 #endif // wxUSE_ACCEL
1597 // ----------------------------------------------------------------------------
1598 // Pop-up menu stuff
1599 // ----------------------------------------------------------------------------
1601 #if wxUSE_MENUS_NATIVE
1603 extern "C" WXDLLIMPEXP_CORE
1604 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1606 *is_waiting
= false;
1609 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1611 menu
->SetInvokingWindow( win
);
1613 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1616 wxMenuItem
*menuitem
= node
->GetData();
1617 if (menuitem
->IsSubMenu())
1619 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1622 node
= node
->GetNext();
1626 extern "C" WXDLLIMPEXP_CORE
1627 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1629 gboolean
* WXUNUSED(whatever
),
1630 gpointer user_data
)
1632 // ensure that the menu appears entirely on screen
1634 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1636 wxSize sizeScreen
= wxGetDisplaySize();
1637 wxPoint
*pos
= (wxPoint
*)user_data
;
1639 gint xmax
= sizeScreen
.x
- req
.width
,
1640 ymax
= sizeScreen
.y
- req
.height
;
1642 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1643 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1646 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1648 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1650 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1652 // NOTE: if you change this code, you need to update
1653 // the same code in taskbar.cpp as well. This
1654 // is ugly code duplication, I know.
1656 SetInvokingWindow( menu
, this );
1660 bool is_waiting
= true;
1662 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1663 G_CALLBACK (gtk_pop_hide_callback
),
1668 GtkMenuPositionFunc posfunc
;
1669 if ( x
== -1 && y
== -1 )
1671 // use GTK's default positioning algorithm
1677 pos
= ClientToScreen(wxPoint(x
, y
));
1679 posfunc
= wxPopupMenuPositionCallback
;
1682 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1683 DoCommonMenuCallbackCode(menu
, eventOpen
);
1686 GTK_MENU(menu
->m_menu
),
1687 (GtkWidget
*) NULL
, // parent menu shell
1688 (GtkWidget
*) NULL
, // parent menu item
1689 posfunc
, // function to position it
1690 userdata
, // client data
1691 0, // button used to activate it
1692 gtk_get_current_event_time()
1697 gtk_main_iteration();
1700 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1702 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1703 DoCommonMenuCallbackCode(menu
, eventClose
);
1708 #endif // wxUSE_MENUS_NATIVE
1712 #include <gtk/gtk.h>
1714 const char *wxGetStockGtkID(wxWindowID id
)
1716 #define STOCKITEM(wx,gtk) \
1720 #define STOCKITEM_MISSING(wx) \
1724 #if GTK_CHECK_VERSION(2,4,0)
1725 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1727 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1730 #if GTK_CHECK_VERSION(2,6,0)
1731 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1733 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1736 #if GTK_CHECK_VERSION(2,10,0)
1737 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1739 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1745 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1746 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1747 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1748 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1749 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1750 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1751 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1752 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1753 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1754 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1755 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1756 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1757 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1758 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1759 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1760 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1761 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1762 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1763 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1764 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1765 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1766 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1767 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1768 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1769 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1770 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1771 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1772 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1773 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1774 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1775 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1776 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1777 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1778 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1779 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1780 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1781 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1782 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1783 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1784 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1785 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1786 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1787 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1788 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1789 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1790 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1791 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1792 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1793 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1794 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1795 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1796 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1797 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1798 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1801 wxFAIL_MSG( _T("invalid stock item ID") );
1810 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1815 GtkStockItem stock_item
;
1816 if (gtk_stock_lookup (id
, &stock_item
))
1818 if (key
) *key
= stock_item
.keyval
;
1819 if (mod
) *mod
= stock_item
.modifier
;
1821 // some GTK stock items have zero values for the keyval;
1822 // it means that they do not have an accelerator...
1823 if (stock_item
.keyval
)
1830 #endif // __WXGTK20__
1832 #endif // wxUSE_MENUS