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
;
178 // Hildon window uses a single menu instead of a menu bar, so wxMenuBar is
179 // the same as menu in this case
181 m_menubar
= gtk_menu_new();
182 #else // !wxUSE_LIBHILDON
183 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
184 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
186 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
190 m_menubar
= gtk_menu_bar_new();
192 if (style
& wxMB_DOCKABLE
)
194 m_widget
= gtk_handle_box_new();
195 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
196 gtk_widget_show(m_menubar
);
200 m_widget
= m_menubar
;
206 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
208 for (size_t i
= 0; i
< n
; ++i
)
209 Append(menus
[i
], titles
[i
]);
211 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
212 // don't get it when the menu is dismissed by clicking outside the
213 // toolbar) so we connect to the global one, even if it means that we
214 // can't pass the menu which was closed in wxMenuEvent object
215 g_signal_connect (m_menubar
, "deactivate",
216 G_CALLBACK (gtk_menu_close_callback
), this);
219 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
221 Init(n
, menus
, titles
, style
);
224 wxMenuBar::wxMenuBar(long style
)
226 Init(0, NULL
, NULL
, style
);
229 wxMenuBar::wxMenuBar()
231 Init(0, NULL
, NULL
, 0);
234 wxMenuBar::~wxMenuBar()
238 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
240 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
242 wxWindow
*top_frame
= win
;
243 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
244 top_frame
= top_frame
->GetParent();
246 // support for native hot keys
247 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
248 if ( menu
->m_accel
&& g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
249 gtk_accel_group_detach( menu
->m_accel
, obj
);
251 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
254 wxMenuItem
*menuitem
= node
->GetData();
255 if (menuitem
->IsSubMenu())
256 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
257 node
= node
->GetNext();
261 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
263 menu
->SetInvokingWindow( win
);
265 wxWindow
*top_frame
= win
;
266 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
267 top_frame
= top_frame
->GetParent();
269 // support for native hot keys
270 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
271 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
272 gtk_accel_group_attach( menu
->m_accel
, obj
);
274 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
277 wxMenuItem
*menuitem
= node
->GetData();
278 if (menuitem
->IsSubMenu())
279 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
280 node
= node
->GetNext();
284 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
286 m_invokingWindow
= win
;
287 wxWindow
*top_frame
= win
;
288 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
289 top_frame
= top_frame
->GetParent();
291 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
294 wxMenu
*menu
= node
->GetData();
295 wxMenubarSetInvokingWindow( menu
, win
);
296 node
= node
->GetNext();
300 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
302 if ( dir
== wxLayout_Default
)
304 const wxWindow
*const frame
= GetFrame();
307 // inherit layout from frame.
308 dir
= frame
->GetLayoutDirection();
310 else // use global layout
312 dir
= wxTheApp
->GetLayoutDirection();
316 if ( dir
== wxLayout_Default
)
319 GTKSetLayout(m_menubar
, dir
);
321 // also set the layout of all menus we already have (new ones will inherit
322 // the current layout)
323 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
325 node
= node
->GetNext() )
327 wxMenu
*const menu
= node
->GetData();
328 menu
->SetLayoutDirection(dir
);
332 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
334 return GTKGetLayout(m_menubar
);
337 void wxMenuBar::Attach(wxFrame
*frame
)
339 wxMenuBarBase::Attach(frame
);
341 SetLayoutDirection(wxLayout_Default
);
344 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
346 m_invokingWindow
= (wxWindow
*) NULL
;
347 wxWindow
*top_frame
= win
;
348 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
349 top_frame
= top_frame
->GetParent();
351 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
354 wxMenu
*menu
= node
->GetData();
355 wxMenubarUnsetInvokingWindow( menu
, win
);
356 node
= node
->GetNext();
360 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
362 if ( !wxMenuBarBase::Append( menu
, title
) )
365 return GtkAppend(menu
, title
);
368 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
370 wxString
str( wxReplaceUnderscore( title
) );
372 // This doesn't have much effect right now.
373 menu
->SetTitle( str
);
375 // The "m_owner" is the "menu item"
376 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
377 menu
->SetLayoutDirection(GetLayoutDirection());
379 gtk_widget_show( menu
->m_owner
);
381 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
384 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
386 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
388 g_signal_connect (menu
->m_owner
, "activate",
389 G_CALLBACK (gtk_menu_open_callback
),
392 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
393 // addings menu later on.
394 if (m_invokingWindow
)
395 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
400 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
402 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
407 if ( !GtkAppend(menu
, title
, (int)pos
) )
413 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
415 // remove the old item and insert a new one
416 wxMenu
*menuOld
= Remove(pos
);
417 if ( menuOld
&& !Insert(pos
, menu
, title
) )
419 return (wxMenu
*) NULL
;
422 // either Insert() succeeded or Remove() failed and menuOld is NULL
426 wxMenu
*wxMenuBar::Remove(size_t pos
)
428 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
430 return (wxMenu
*) NULL
;
432 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
433 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
435 gtk_widget_destroy( menu
->m_owner
);
436 menu
->m_owner
= NULL
;
438 if (m_invokingWindow
)
439 wxMenubarUnsetInvokingWindow( menu
, m_invokingWindow
);
444 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
446 if (wxMenuItem::GetLabelText(wxConvertFromGTKToWXLabel(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
448 int res
= menu
->FindItem( itemString
);
449 if (res
!= wxNOT_FOUND
)
453 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
456 wxMenuItem
*item
= node
->GetData();
457 if (item
->IsSubMenu())
458 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
460 node
= node
->GetNext();
466 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
468 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
471 wxMenu
*menu
= node
->GetData();
472 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
475 node
= node
->GetNext();
481 // Find a wxMenuItem using its id. Recurses down into sub-menus
482 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
484 wxMenuItem
* result
= menu
->FindChildItem(id
);
486 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
487 while ( node
&& result
== NULL
)
489 wxMenuItem
*item
= node
->GetData();
490 if (item
->IsSubMenu())
492 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
494 node
= node
->GetNext();
500 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
502 wxMenuItem
* result
= 0;
503 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
504 while (node
&& result
== 0)
506 wxMenu
*menu
= node
->GetData();
507 result
= FindMenuItemByIdRecursive( menu
, id
);
508 node
= node
->GetNext();
513 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
519 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
521 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
523 wxCHECK_RET( node
, wxT("menu not found") );
525 wxMenu
* menu
= node
->GetData();
528 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
531 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
533 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
535 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
537 wxMenu
* menu
= node
->GetData();
539 return wxConvertFromGTKToWXLabel(menu
->GetTitle());
542 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
544 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
546 wxCHECK_RET( node
, wxT("menu not found") );
548 wxMenu
* menu
= node
->GetData();
550 const wxString
str( wxReplaceUnderscore( label
) );
552 menu
->SetTitle( str
);
555 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
558 //-----------------------------------------------------------------------------
560 //-----------------------------------------------------------------------------
563 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
565 int id
= menu
->FindMenuIdByMenuItem(widget
);
567 /* should find it for normal (not popup) menu */
568 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
569 _T("menu item not found in gtk_menu_clicked_callback") );
571 if (!menu
->IsEnabled(id
))
574 wxMenuItem
* item
= menu
->FindChildItem( id
);
575 wxCHECK_RET( item
, wxT("error in menu item callback") );
577 if ( item
->GetId() == wxGTK_TITLE_ID
)
579 // ignore events from the menu title
583 if (item
->IsCheckable())
585 bool isReallyChecked
= item
->IsChecked(),
586 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
588 // ensure that the internal state is always consistent with what is
589 // shown on the screen
590 item
->wxMenuItemBase::Check(isReallyChecked
);
592 // we must not report the events for the radio button going up nor the
593 // events resulting from the calls to wxMenuItem::Check()
594 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
595 (isInternallyChecked
== isReallyChecked
) )
602 // Is this menu on a menubar? (possibly nested)
603 wxFrame
* frame
= NULL
;
604 if(menu
->IsAttached())
605 frame
= menu
->GetMenuBar()->GetFrame();
607 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
608 // normally wxMenu::SendEvent() should be enough, if it doesn't work
609 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
610 // should be fixed instead of working around it here...
613 // If it is attached then let the frame send the event.
614 // Don't call frame->ProcessCommand(id) because it toggles
615 // checkable items and we've already done that above.
616 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
617 commandEvent
.SetEventObject(frame
);
618 if (item
->IsCheckable())
619 commandEvent
.SetInt(item
->IsChecked());
621 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
625 // otherwise let the menu have it
626 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
631 //-----------------------------------------------------------------------------
633 //-----------------------------------------------------------------------------
636 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
638 int id
= menu
->FindMenuIdByMenuItem(widget
);
640 wxASSERT( id
!= -1 ); // should find it!
642 if (!menu
->IsEnabled(id
))
645 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
646 event
.SetEventObject( menu
);
648 wxEvtHandler
* handler
= menu
->GetEventHandler();
649 if (handler
&& handler
->ProcessEvent(event
))
652 wxWindow
*win
= menu
->GetInvokingWindow();
653 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
657 //-----------------------------------------------------------------------------
659 //-----------------------------------------------------------------------------
662 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
664 int id
= menu
->FindMenuIdByMenuItem(widget
);
666 wxASSERT( id
!= -1 ); // should find it!
668 if (!menu
->IsEnabled(id
))
671 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
672 event
.SetEventObject( menu
);
674 wxEvtHandler
* handler
= menu
->GetEventHandler();
675 if (handler
&& handler
->ProcessEvent(event
))
678 wxWindow
*win
= menu
->GetInvokingWindow();
680 win
->GetEventHandler()->ProcessEvent( event
);
684 //-----------------------------------------------------------------------------
686 //-----------------------------------------------------------------------------
688 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
690 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
692 const wxString
& name
,
693 const wxString
& help
,
697 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
700 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
702 const wxString
& text
,
703 const wxString
& help
,
706 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
711 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
713 const wxString
& text
,
714 const wxString
& help
,
717 : wxMenuItemBase(parentMenu
, id
, text
, help
,
718 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
723 void wxMenuItem::Init(const wxString
& text
)
725 m_labelWidget
= (GtkWidget
*) NULL
;
726 m_menuItem
= (GtkWidget
*) NULL
;
731 wxMenuItem::~wxMenuItem()
733 // don't delete menu items, the menus take care of that
736 // return the menu item text without any menu accels
739 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
741 // The argument to this function will now always be in wxWidgets standard label
742 // format, not GTK+ format, so we do what the other ports do.
744 return wxStripMenuCodes(text
);
749 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
751 if ( *pc
== wxT('\t'))
754 if ( *pc
== wxT('_') )
756 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
762 if ( *pc
== wxT('\\') )
764 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
770 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
773 // "&" is doubled to indicate "&" instead of accelerator
780 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
786 wxString
wxMenuItem::GetItemLabel() const
788 wxString label
= wxConvertFromGTKToWXLabel(m_text
);
789 if (!m_hotKey
.IsEmpty())
790 label
= label
+ wxT("\t") + m_hotKey
;
794 void wxMenuItem::SetItemLabel( const wxString
& str
)
796 // cache some data which must be used later
797 bool isstock
= wxIsStockID(GetId());
798 const char *stockid
= NULL
;
800 stockid
= wxGetStockGtkID(GetId());
802 // Some optimization to avoid flicker
803 wxString oldLabel
= m_text
;
804 oldLabel
= wxStripMenuCodes(oldLabel
);
805 oldLabel
.Replace(wxT("_"), wxT(""));
806 wxString label1
= wxStripMenuCodes(str
);
808 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
809 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
810 #endif // wxUSE_ACCEL
815 if (oldLabel
== label1
&&
816 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
823 label
= (GtkLabel
*) m_labelWidget
;
825 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
827 // stock menu items can have empty labels:
828 wxString text
= m_text
;
829 if (text
.IsEmpty() && !IsSeparator())
831 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
832 text
= wxGetStockLabel(GetId());
834 // need & => _ conversion
835 text
= GTKProcessMenuItemLabel(text
, NULL
);
838 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
841 // remove old accelerator from our parent's accelerator group, if present
843 GdkModifierType accel_mods
;
844 if (oldbuf
[(size_t)0] != '\0')
846 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
849 gtk_widget_remove_accelerator(m_menuItem
,
850 m_parentMenu
->m_accel
,
857 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
858 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
859 gtk_widget_remove_accelerator( m_menuItem
,
860 m_parentMenu
->m_accel
,
865 // add new accelerator to our parent's accelerator group
866 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
867 if (buf
[(size_t)0] != '\0')
869 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
872 gtk_widget_add_accelerator( m_menuItem
,
874 m_parentMenu
->m_accel
,
882 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
883 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
884 gtk_widget_remove_accelerator( m_menuItem
,
885 m_parentMenu
->m_accel
,
889 #endif // wxUSE_FILECTRL
892 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
893 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
894 // so there's no real code duplication
895 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
899 // '\t' is the deliminator indicating a hot key
900 wxString::const_iterator pc
= str
.begin();
901 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
905 wxString::const_iterator next
= pc
+ 1;
906 if (next
!= str
.end() && *next
== wxT('&'))
908 // "&" is doubled to indicate "&" instead of accelerator
917 else if ( *pc
== wxT('_') ) // escape underscores
934 hotKey
->assign(pc
, str
.end());
941 // it's valid for this function to be called even if m_menuItem == NULL
942 void wxMenuItem::DoSetText( const wxString
& str
)
945 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
950 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
958 // accelerator parsing code looks for them after a TAB, so insert a dummy
961 label
<< wxT('\t') << GetHotKey();
963 return wxAcceleratorEntry::Create(label
);
966 #endif // wxUSE_ACCEL
968 void wxMenuItem::Check( bool check
)
970 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
972 if (check
== m_isChecked
)
975 wxMenuItemBase::Check( check
);
981 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
985 wxFAIL_MSG( _T("can't check this item") );
989 void wxMenuItem::Enable( bool enable
)
991 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
993 gtk_widget_set_sensitive( m_menuItem
, enable
);
994 wxMenuItemBase::Enable( enable
);
997 bool wxMenuItem::IsChecked() const
999 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
1001 wxCHECK_MSG( IsCheckable(), false,
1002 wxT("can't get state of uncheckable item!") );
1004 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
1007 //-----------------------------------------------------------------------------
1009 //-----------------------------------------------------------------------------
1011 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
1015 m_accel
= gtk_accel_group_new();
1016 m_menu
= gtk_menu_new();
1017 // NB: keep reference to the menu so that it is not destroyed behind
1018 // our back by GTK+ e.g. when it is removed from menubar:
1019 gtk_widget_ref(m_menu
);
1021 m_owner
= (GtkWidget
*) NULL
;
1023 // Tearoffs are entries, just like separators. So if we want this
1024 // menu to be a tear-off one, we just append a tearoff entry
1026 if ( m_style
& wxMENU_TEAROFF
)
1028 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
1030 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
1035 // append the title as the very first entry if we have it
1036 if ( !m_title
.empty() )
1038 Append(wxGTK_TITLE_ID
, m_title
);
1045 if ( GTK_IS_WIDGET( m_menu
))
1048 gtk_widget_unref( m_menu
);
1049 g_object_unref( m_accel
);
1051 // if the menu is inserted in another menu at this time, there was
1052 // one more reference to it:
1054 gtk_widget_destroy( m_menu
);
1057 // This must come after we release GTK resources above. Otherwise, GTK will
1058 // give warnings/errors when attempting to free accelerator resources from
1059 // child items that just were destroyed (the m_menu widget can contain
1060 // references to accelerators in child items. Problem detected when removing
1061 // a menu from a wxMenuBar, and the removed menu had submenus with accelerators.)
1062 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1065 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1068 wxWindow::GTKSetLayout(m_owner
, dir
);
1069 //else: will be called later by wxMenuBar again
1072 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1074 return wxWindow::GTKGetLayout(m_owner
);
1077 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1079 GtkWidget
*menuItem
;
1081 // cache some data used later
1082 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1083 int id
= mitem
->GetId();
1084 bool isstock
= wxIsStockID(id
);
1085 const char *stockid
= NULL
;
1087 stockid
= wxGetStockGtkID(mitem
->GetId());
1089 // stock menu items can have an empty label
1090 if (text
.IsEmpty() && !mitem
->IsSeparator())
1092 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1093 text
= wxGetStockLabel(id
);
1095 // need & => _ conversion
1096 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1099 if ( mitem
->IsSeparator() )
1101 menuItem
= gtk_separator_menu_item_new();
1103 else if ( mitem
->GetBitmap().Ok() ||
1104 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1106 wxBitmap
bitmap(mitem
->GetBitmap());
1108 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1113 // use stock bitmap for this item if available on the assumption
1114 // that it never hurts to follow GTK+ conventions more closely
1115 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1118 else // we have a custom bitmap
1120 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1121 _T("only normal menu items can have bitmaps") );
1123 if ( bitmap
.HasPixbuf() )
1125 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1129 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1130 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1131 bitmap
.GetMask()->GetBitmap() :
1133 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1139 gtk_widget_show(image
);
1141 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1146 else // a normal item
1148 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1151 switch ( mitem
->GetKind() )
1155 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1162 GSList
*group
= NULL
;
1163 if ( m_prevRadio
== NULL
)
1165 // start of a new radio group
1166 m_prevRadio
= menuItem
=
1167 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1169 else // continue the radio group
1171 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1172 m_prevRadio
= menuItem
=
1173 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1179 wxFAIL_MSG( _T("unexpected menu item kind") );
1184 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1194 GdkModifierType accel_mods
;
1195 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1197 if (buf
[(size_t)0] != '\0')
1199 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1202 gtk_widget_add_accelerator (menuItem
,
1212 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1213 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1214 gtk_widget_add_accelerator( menuItem
,
1221 #endif // wxUSE_FILECTRL
1224 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1226 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1228 gtk_widget_show( menuItem
);
1230 if ( !mitem
->IsSeparator() )
1232 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1234 g_signal_connect (menuItem
, "select",
1235 G_CALLBACK (gtk_menu_hilight_callback
), this);
1236 g_signal_connect (menuItem
, "deselect",
1237 G_CALLBACK (gtk_menu_nolight_callback
), this);
1239 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1241 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1243 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1245 // if adding a submenu to a menu already existing in the menu bar, we
1246 // must set invoking window to allow processing events from this
1248 if ( m_invokingWindow
)
1249 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1253 g_signal_connect (menuItem
, "activate",
1254 G_CALLBACK (gtk_menu_clicked_callback
),
1259 mitem
->SetMenuItem(menuItem
);
1263 // This doesn't even exist!
1264 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1270 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1272 if (!GtkAppend(mitem
))
1275 return wxMenuBase::DoAppend(mitem
);
1278 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1280 if ( !wxMenuBase::DoInsert(pos
, item
) )
1284 if ( !GtkAppend(item
, (int)pos
) )
1290 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1292 if ( !wxMenuBase::DoRemove(item
) )
1293 return (wxMenuItem
*)NULL
;
1295 // TODO: this code doesn't delete the item factory item and this seems
1296 // impossible as of GTK 1.2.6.
1297 gtk_widget_destroy( item
->GetMenuItem() );
1302 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1304 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1307 wxMenuItem
*item
= node
->GetData();
1308 if (item
->GetMenuItem() == menuItem
)
1309 return item
->GetId();
1310 node
= node
->GetNext();
1316 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1318 wxMenuBase::Attach(menubar
);
1320 // inherit layout direction from menubar.
1321 SetLayoutDirection(menubar
->GetLayoutDirection());
1324 // ----------------------------------------------------------------------------
1326 // ----------------------------------------------------------------------------
1330 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1334 wxAcceleratorEntry
*accel
= item
.GetAccel();
1337 int flags
= accel
->GetFlags();
1338 if ( flags
& wxACCEL_ALT
)
1339 hotkey
+= wxT("<alt>");
1340 if ( flags
& wxACCEL_CTRL
)
1341 hotkey
+= wxT("<control>");
1342 if ( flags
& wxACCEL_SHIFT
)
1343 hotkey
+= wxT("<shift>");
1345 int code
= accel
->GetKeyCode();
1372 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1375 // TODO: we should use gdk_keyval_name() (a.k.a.
1376 // XKeysymToString) here as well as hardcoding the keysym
1377 // names this might be not portable
1379 hotkey
<< wxT("Insert" );
1382 hotkey
<< wxT("Delete" );
1385 hotkey
<< wxT("Up" );
1388 hotkey
<< wxT("Down" );
1391 hotkey
<< wxT("Page_Up" );
1394 hotkey
<< wxT("Page_Down" );
1397 hotkey
<< wxT("Left" );
1400 hotkey
<< wxT("Right" );
1403 hotkey
<< wxT("Home" );
1406 hotkey
<< wxT("End" );
1409 hotkey
<< wxT("Return" );
1412 hotkey
<< wxT("BackSpace" );
1415 hotkey
<< wxT("Tab" );
1418 hotkey
<< wxT("Esc" );
1421 hotkey
<< wxT("space" );
1424 hotkey
<< wxT("Multiply" );
1427 hotkey
<< wxT("Add" );
1430 hotkey
<< wxT("Separator" );
1433 hotkey
<< wxT("Subtract" );
1436 hotkey
<< wxT("Decimal" );
1439 hotkey
<< wxT("Divide" );
1442 hotkey
<< wxT("Cancel" );
1445 hotkey
<< wxT("Clear" );
1448 hotkey
<< wxT("Menu" );
1451 hotkey
<< wxT("Pause" );
1454 hotkey
<< wxT("Capital" );
1457 hotkey
<< wxT("Select" );
1460 hotkey
<< wxT("Print" );
1463 hotkey
<< wxT("Execute" );
1466 hotkey
<< wxT("Snapshot" );
1469 hotkey
<< wxT("Help" );
1472 hotkey
<< wxT("Num_Lock" );
1475 hotkey
<< wxT("Scroll_Lock" );
1477 case WXK_NUMPAD_INSERT
:
1478 hotkey
<< wxT("KP_Insert" );
1480 case WXK_NUMPAD_DELETE
:
1481 hotkey
<< wxT("KP_Delete" );
1483 case WXK_NUMPAD_SPACE
:
1484 hotkey
<< wxT("KP_Space" );
1486 case WXK_NUMPAD_TAB
:
1487 hotkey
<< wxT("KP_Tab" );
1489 case WXK_NUMPAD_ENTER
:
1490 hotkey
<< wxT("KP_Enter" );
1492 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1494 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1496 case WXK_NUMPAD_HOME
:
1497 hotkey
<< wxT("KP_Home" );
1499 case WXK_NUMPAD_LEFT
:
1500 hotkey
<< wxT("KP_Left" );
1503 hotkey
<< wxT("KP_Up" );
1505 case WXK_NUMPAD_RIGHT
:
1506 hotkey
<< wxT("KP_Right" );
1508 case WXK_NUMPAD_DOWN
:
1509 hotkey
<< wxT("KP_Down" );
1511 case WXK_NUMPAD_PAGEUP
:
1512 hotkey
<< wxT("KP_Page_Up" );
1514 case WXK_NUMPAD_PAGEDOWN
:
1515 hotkey
<< wxT("KP_Page_Down" );
1517 case WXK_NUMPAD_END
:
1518 hotkey
<< wxT("KP_End" );
1520 case WXK_NUMPAD_BEGIN
:
1521 hotkey
<< wxT("KP_Begin" );
1523 case WXK_NUMPAD_EQUAL
:
1524 hotkey
<< wxT("KP_Equal" );
1526 case WXK_NUMPAD_MULTIPLY
:
1527 hotkey
<< wxT("KP_Multiply" );
1529 case WXK_NUMPAD_ADD
:
1530 hotkey
<< wxT("KP_Add" );
1532 case WXK_NUMPAD_SEPARATOR
:
1533 hotkey
<< wxT("KP_Separator" );
1535 case WXK_NUMPAD_SUBTRACT
:
1536 hotkey
<< wxT("KP_Subtract" );
1538 case WXK_NUMPAD_DECIMAL
:
1539 hotkey
<< wxT("KP_Decimal" );
1541 case WXK_NUMPAD_DIVIDE
:
1542 hotkey
<< wxT("KP_Divide" );
1544 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1545 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1546 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1547 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1549 case WXK_WINDOWS_LEFT
:
1550 hotkey
<< wxT("Super_L" );
1552 case WXK_WINDOWS_RIGHT
:
1553 hotkey
<< wxT("Super_R" );
1555 case WXK_WINDOWS_MENU
:
1556 hotkey
<< wxT("Menu" );
1559 hotkey
<< wxT("Command" );
1561 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1562 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1563 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1564 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1565 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1566 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1567 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1570 // if there are any other keys wxAcceleratorEntry::Create() may
1571 // return, we should process them here
1577 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1578 if ( !name
.empty() )
1585 wxFAIL_MSG( wxT("unknown keyboard accel") );
1594 #endif // wxUSE_ACCEL
1596 // ----------------------------------------------------------------------------
1597 // Pop-up menu stuff
1598 // ----------------------------------------------------------------------------
1600 #if wxUSE_MENUS_NATIVE
1602 extern "C" WXDLLIMPEXP_CORE
1603 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1605 *is_waiting
= false;
1608 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1610 menu
->SetInvokingWindow( win
);
1612 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1615 wxMenuItem
*menuitem
= node
->GetData();
1616 if (menuitem
->IsSubMenu())
1618 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1621 node
= node
->GetNext();
1625 extern "C" WXDLLIMPEXP_CORE
1626 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1628 gboolean
* WXUNUSED(whatever
),
1629 gpointer user_data
)
1631 // ensure that the menu appears entirely on screen
1633 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1635 wxSize sizeScreen
= wxGetDisplaySize();
1636 wxPoint
*pos
= (wxPoint
*)user_data
;
1638 gint xmax
= sizeScreen
.x
- req
.width
,
1639 ymax
= sizeScreen
.y
- req
.height
;
1641 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1642 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1645 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1647 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1649 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1651 // NOTE: if you change this code, you need to update
1652 // the same code in taskbar.cpp as well. This
1653 // is ugly code duplication, I know.
1655 SetInvokingWindow( menu
, this );
1659 bool is_waiting
= true;
1661 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1662 G_CALLBACK (gtk_pop_hide_callback
),
1667 GtkMenuPositionFunc posfunc
;
1668 if ( x
== -1 && y
== -1 )
1670 // use GTK's default positioning algorithm
1676 pos
= ClientToScreen(wxPoint(x
, y
));
1678 posfunc
= wxPopupMenuPositionCallback
;
1681 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1682 DoCommonMenuCallbackCode(menu
, eventOpen
);
1685 GTK_MENU(menu
->m_menu
),
1686 (GtkWidget
*) NULL
, // parent menu shell
1687 (GtkWidget
*) NULL
, // parent menu item
1688 posfunc
, // function to position it
1689 userdata
, // client data
1690 0, // button used to activate it
1691 gtk_get_current_event_time()
1696 gtk_main_iteration();
1699 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1701 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1702 DoCommonMenuCallbackCode(menu
, eventClose
);
1707 #endif // wxUSE_MENUS_NATIVE
1709 #include <gtk/gtk.h>
1711 const char *wxGetStockGtkID(wxWindowID id
)
1713 #define STOCKITEM(wx,gtk) \
1717 #define STOCKITEM_MISSING(wx) \
1721 #if GTK_CHECK_VERSION(2,4,0)
1722 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1724 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1727 #if GTK_CHECK_VERSION(2,6,0)
1728 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1730 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1733 #if GTK_CHECK_VERSION(2,10,0)
1734 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1736 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1742 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1743 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1744 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1745 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1746 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1747 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1748 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1749 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1750 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1751 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1752 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1753 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1754 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1755 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1756 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1757 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1758 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1759 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1760 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1761 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1762 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1763 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1764 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1765 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1766 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1767 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1768 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1769 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1770 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1771 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1772 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1773 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1774 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1775 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1776 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1777 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1778 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1779 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1780 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1781 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1782 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1783 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1784 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1785 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1786 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1787 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1788 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1789 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1790 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1791 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1792 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1793 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1794 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1795 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1798 wxFAIL_MSG( _T("invalid stock item ID") );
1807 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1812 GtkStockItem stock_item
;
1813 if (gtk_stock_lookup (id
, &stock_item
))
1815 if (key
) *key
= stock_item
.keyval
;
1816 if (mod
) *mod
= stock_item
.modifier
;
1818 // some GTK stock items have zero values for the keyval;
1819 // it means that they do not have an accelerator...
1820 if (stock_item
.keyval
)
1827 #endif // wxUSE_MENUS