1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/menu.cpp
3 // Purpose: implementation of wxMenuBar and wxMenu classes for wxGTK
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
21 #include "wx/bitmap.h"
26 #include "wx/stockitem.h"
27 #include "wx/gtk/private.h"
28 #include "wx/gtk/private/mnemonics.h"
30 // FIXME: is this right? somehow I don't think so (VZ)
32 #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
33 #define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
34 //#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
36 #define ACCEL_OBJECT GtkWindow
37 #define ACCEL_OBJECTS(a) (a)->acceleratables
38 #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
40 // we use normal item but with a special id for the menu title
41 static const int wxGTK_TITLE_ID
= -3;
43 extern "C" static void gtk_menu_clicked_callback(GtkWidget
*widget
, wxMenu
*menu
);
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
50 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
53 //-----------------------------------------------------------------------------
54 // activate message from GTK
55 //-----------------------------------------------------------------------------
57 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
59 event
.SetEventObject( menu
);
61 wxEvtHandler
* handler
= menu
->GetEventHandler();
62 if (handler
&& handler
->ProcessEvent(event
))
65 wxWindow
*win
= menu
->GetInvokingWindow();
67 win
->GetEventHandler()->ProcessEvent( event
);
73 gtk_menu_open_callback(GtkWidget
* WXUNUSED(widget
), wxMenu
*menu
)
75 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
77 DoCommonMenuCallbackCode(menu
, event
);
81 gtk_menu_close_callback(GtkWidget
* WXUNUSED(widget
), wxMenuBar
*menubar
)
83 if ( !menubar
->GetMenuCount() )
85 // if menubar is empty we can't call GetMenu(0) below
89 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
91 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
96 //-----------------------------------------------------------------------------
98 //-----------------------------------------------------------------------------
100 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
102 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
105 m_invokingWindow
= NULL
;
108 // Hildon window uses a single menu instead of a menu bar, so wxMenuBar is
109 // the same as menu in this case
111 m_menubar
= gtk_menu_new();
112 #else // !wxUSE_LIBHILDON
113 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
114 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
116 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
120 m_menubar
= gtk_menu_bar_new();
122 if (style
& wxMB_DOCKABLE
)
124 m_widget
= gtk_handle_box_new();
125 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
126 gtk_widget_show(m_menubar
);
130 m_widget
= m_menubar
;
136 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
138 for (size_t i
= 0; i
< n
; ++i
)
139 Append(menus
[i
], titles
[i
]);
141 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
142 // don't get it when the menu is dismissed by clicking outside the
143 // toolbar) so we connect to the global one, even if it means that we
144 // can't pass the menu which was closed in wxMenuEvent object
145 g_signal_connect (m_menubar
, "deactivate",
146 G_CALLBACK (gtk_menu_close_callback
), this);
149 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
151 Init(n
, menus
, titles
, style
);
154 wxMenuBar::wxMenuBar(long style
)
156 Init(0, NULL
, NULL
, style
);
159 wxMenuBar::wxMenuBar()
161 Init(0, NULL
, NULL
, 0);
164 wxMenuBar::~wxMenuBar()
168 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
170 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
172 wxWindow
*top_frame
= win
;
173 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
174 top_frame
= top_frame
->GetParent();
176 // support for native hot keys
177 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
178 if ( menu
->m_accel
&& g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
179 gtk_accel_group_detach( menu
->m_accel
, obj
);
181 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
184 wxMenuItem
*menuitem
= node
->GetData();
185 if (menuitem
->IsSubMenu())
186 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
187 node
= node
->GetNext();
191 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
193 menu
->SetInvokingWindow( win
);
195 wxWindow
*top_frame
= win
;
196 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
197 top_frame
= top_frame
->GetParent();
199 // support for native hot keys
200 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
201 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
202 gtk_accel_group_attach( menu
->m_accel
, obj
);
204 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
207 wxMenuItem
*menuitem
= node
->GetData();
208 if (menuitem
->IsSubMenu())
209 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
210 node
= node
->GetNext();
214 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
216 m_invokingWindow
= win
;
217 wxWindow
*top_frame
= win
;
218 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
219 top_frame
= top_frame
->GetParent();
221 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
224 wxMenu
*menu
= node
->GetData();
225 wxMenubarSetInvokingWindow( menu
, win
);
226 node
= node
->GetNext();
230 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
232 if ( dir
== wxLayout_Default
)
234 const wxWindow
*const frame
= GetFrame();
237 // inherit layout from frame.
238 dir
= frame
->GetLayoutDirection();
240 else // use global layout
242 dir
= wxTheApp
->GetLayoutDirection();
246 if ( dir
== wxLayout_Default
)
249 GTKSetLayout(m_menubar
, dir
);
251 // also set the layout of all menus we already have (new ones will inherit
252 // the current layout)
253 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
255 node
= node
->GetNext() )
257 wxMenu
*const menu
= node
->GetData();
258 menu
->SetLayoutDirection(dir
);
262 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
264 return GTKGetLayout(m_menubar
);
267 void wxMenuBar::Attach(wxFrame
*frame
)
269 wxMenuBarBase::Attach(frame
);
271 SetLayoutDirection(wxLayout_Default
);
274 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
276 m_invokingWindow
= (wxWindow
*) NULL
;
277 wxWindow
*top_frame
= win
;
278 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
279 top_frame
= top_frame
->GetParent();
281 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
284 wxMenu
*menu
= node
->GetData();
285 wxMenubarUnsetInvokingWindow( menu
, win
);
286 node
= node
->GetNext();
290 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
292 if ( !wxMenuBarBase::Append( menu
, title
) )
295 return GtkAppend(menu
, title
);
298 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
300 menu
->SetLayoutDirection(GetLayoutDirection());
303 // if the menu has only one item, append it directly to the top level menu
304 // instead of inserting a useless submenu
305 if ( menu
->GetMenuItemCount() == 1 )
307 wxMenuItem
* const item
= menu
->FindItemByPosition(0);
309 // remove both mnemonics and accelerator: neither is useful under Maemo
310 const wxString
str(wxStripMenuCodes(item
->GetItemLabel()));
312 if ( item
->IsSubMenu() )
313 return GtkAppend(item
->GetSubMenu(), str
, pos
);
315 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
317 g_signal_connect(menu
->m_owner
, "activate",
318 G_CALLBACK(gtk_menu_clicked_callback
), menu
);
319 item
->SetMenuItem(menu
->m_owner
);
322 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
324 const wxString
str(wxConvertMnemonicsToGTK(title
));
326 // This doesn't have much effect right now.
327 menu
->SetTitle( str
);
329 // The "m_owner" is the "menu item"
330 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
332 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
335 gtk_widget_show( menu
->m_owner
);
338 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
340 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
342 g_signal_connect (menu
->m_owner
, "activate",
343 G_CALLBACK (gtk_menu_open_callback
),
346 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
347 // addings menu later on.
348 if (m_invokingWindow
)
349 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
354 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
356 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
361 if ( !GtkAppend(menu
, title
, (int)pos
) )
367 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
369 // remove the old item and insert a new one
370 wxMenu
*menuOld
= Remove(pos
);
371 if ( menuOld
&& !Insert(pos
, menu
, title
) )
373 return (wxMenu
*) NULL
;
376 // either Insert() succeeded or Remove() failed and menuOld is NULL
380 wxMenu
*wxMenuBar::Remove(size_t pos
)
382 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
384 return (wxMenu
*) NULL
;
386 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
387 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
389 gtk_widget_destroy( menu
->m_owner
);
390 menu
->m_owner
= NULL
;
392 if (m_invokingWindow
)
393 wxMenubarUnsetInvokingWindow( menu
, m_invokingWindow
);
398 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
400 if (wxMenuItem::GetLabelText(wxConvertMnemonicsFromGTK(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
402 int res
= menu
->FindItem( itemString
);
403 if (res
!= wxNOT_FOUND
)
407 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
410 wxMenuItem
*item
= node
->GetData();
411 if (item
->IsSubMenu())
412 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
414 node
= node
->GetNext();
420 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
422 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
425 wxMenu
*menu
= node
->GetData();
426 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
429 node
= node
->GetNext();
435 // Find a wxMenuItem using its id. Recurses down into sub-menus
436 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
438 wxMenuItem
* result
= menu
->FindChildItem(id
);
440 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
441 while ( node
&& result
== NULL
)
443 wxMenuItem
*item
= node
->GetData();
444 if (item
->IsSubMenu())
446 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
448 node
= node
->GetNext();
454 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
456 wxMenuItem
* result
= 0;
457 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
458 while (node
&& result
== 0)
460 wxMenu
*menu
= node
->GetData();
461 result
= FindMenuItemByIdRecursive( menu
, id
);
462 node
= node
->GetNext();
467 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
473 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
475 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
477 wxCHECK_RET( node
, wxT("menu not found") );
479 wxMenu
* menu
= node
->GetData();
482 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
485 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
487 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
489 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
491 wxMenu
* menu
= node
->GetData();
493 return wxConvertMnemonicsFromGTK(menu
->GetTitle());
496 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
498 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
500 wxCHECK_RET( node
, wxT("menu not found") );
502 wxMenu
* menu
= node
->GetData();
504 const wxString
str(wxConvertMnemonicsToGTK(label
));
506 menu
->SetTitle( str
);
509 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
512 //-----------------------------------------------------------------------------
514 //-----------------------------------------------------------------------------
517 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
519 int id
= menu
->FindMenuIdByMenuItem(widget
);
521 /* should find it for normal (not popup) menu */
522 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
523 _T("menu item not found in gtk_menu_clicked_callback") );
525 if (!menu
->IsEnabled(id
))
528 wxMenuItem
* item
= menu
->FindChildItem( id
);
529 wxCHECK_RET( item
, wxT("error in menu item callback") );
531 if ( item
->GetId() == wxGTK_TITLE_ID
)
533 // ignore events from the menu title
537 if (item
->IsCheckable())
539 bool isReallyChecked
= item
->IsChecked(),
540 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
542 // ensure that the internal state is always consistent with what is
543 // shown on the screen
544 item
->wxMenuItemBase::Check(isReallyChecked
);
546 // we must not report the events for the radio button going up nor the
547 // events resulting from the calls to wxMenuItem::Check()
548 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
549 (isInternallyChecked
== isReallyChecked
) )
556 // Is this menu on a menubar? (possibly nested)
557 wxFrame
* frame
= NULL
;
558 if(menu
->IsAttached())
559 frame
= menu
->GetMenuBar()->GetFrame();
561 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
562 // normally wxMenu::SendEvent() should be enough, if it doesn't work
563 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
564 // should be fixed instead of working around it here...
567 // If it is attached then let the frame send the event.
568 // Don't call frame->ProcessCommand(id) because it toggles
569 // checkable items and we've already done that above.
570 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
571 commandEvent
.SetEventObject(frame
);
572 if (item
->IsCheckable())
573 commandEvent
.SetInt(item
->IsChecked());
575 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
579 // otherwise let the menu have it
580 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
585 //-----------------------------------------------------------------------------
587 //-----------------------------------------------------------------------------
590 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
592 int id
= menu
->FindMenuIdByMenuItem(widget
);
594 wxASSERT( id
!= -1 ); // should find it!
596 if (!menu
->IsEnabled(id
))
599 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
600 event
.SetEventObject( menu
);
602 wxEvtHandler
* handler
= menu
->GetEventHandler();
603 if (handler
&& handler
->ProcessEvent(event
))
606 wxWindow
*win
= menu
->GetInvokingWindow();
607 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
611 //-----------------------------------------------------------------------------
613 //-----------------------------------------------------------------------------
616 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
618 int id
= menu
->FindMenuIdByMenuItem(widget
);
620 wxASSERT( id
!= -1 ); // should find it!
622 if (!menu
->IsEnabled(id
))
625 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
626 event
.SetEventObject( menu
);
628 wxEvtHandler
* handler
= menu
->GetEventHandler();
629 if (handler
&& handler
->ProcessEvent(event
))
632 wxWindow
*win
= menu
->GetInvokingWindow();
634 win
->GetEventHandler()->ProcessEvent( event
);
638 //-----------------------------------------------------------------------------
640 //-----------------------------------------------------------------------------
642 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
644 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
646 const wxString
& name
,
647 const wxString
& help
,
651 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
654 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
656 const wxString
& text
,
657 const wxString
& help
,
660 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
665 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
667 const wxString
& text
,
668 const wxString
& help
,
671 : wxMenuItemBase(parentMenu
, id
, text
, help
,
672 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
677 void wxMenuItem::Init(const wxString
& text
)
679 m_labelWidget
= (GtkWidget
*) NULL
;
680 m_menuItem
= (GtkWidget
*) NULL
;
685 wxMenuItem::~wxMenuItem()
687 // don't delete menu items, the menus take care of that
690 // return the menu item text without any menu accels
693 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
695 // The argument to this function will now always be in wxWidgets standard label
696 // format, not GTK+ format, so we do what the other ports do.
698 return wxStripMenuCodes(text
);
703 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
705 if ( *pc
== wxT('\t'))
708 if ( *pc
== wxT('_') )
710 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
716 if ( *pc
== wxT('\\') )
718 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
724 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
727 // "&" is doubled to indicate "&" instead of accelerator
734 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
740 wxString
wxMenuItem::GetItemLabel() const
742 wxString label
= wxConvertMnemonicsFromGTK(m_text
);
743 if (!m_hotKey
.IsEmpty())
744 label
<< "\t" << m_hotKey
;
748 void wxMenuItem::SetItemLabel( const wxString
& str
)
750 // cache some data which must be used later
751 bool isstock
= wxIsStockID(GetId());
752 const char *stockid
= NULL
;
754 stockid
= wxGetStockGtkID(GetId());
756 // Some optimization to avoid flicker
757 wxString oldLabel
= m_text
;
758 oldLabel
= wxStripMenuCodes(oldLabel
);
759 oldLabel
.Replace(wxT("_"), wxT(""));
760 wxString label1
= wxStripMenuCodes(str
);
762 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
763 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
764 #endif // wxUSE_ACCEL
769 if (oldLabel
== label1
&&
770 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
777 label
= (GtkLabel
*) m_labelWidget
;
779 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
781 // stock menu items can have empty labels:
782 wxString text
= m_text
;
783 if (text
.IsEmpty() && !IsSeparator())
785 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
786 text
= wxGetStockLabel(GetId());
788 // need & => _ conversion
789 text
= GTKProcessMenuItemLabel(text
, NULL
);
792 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
795 // remove old accelerator from our parent's accelerator group, if present
797 GdkModifierType accel_mods
;
798 if (oldbuf
[(size_t)0] != '\0')
800 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
803 gtk_widget_remove_accelerator(m_menuItem
,
804 m_parentMenu
->m_accel
,
811 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
812 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
813 gtk_widget_remove_accelerator( m_menuItem
,
814 m_parentMenu
->m_accel
,
819 // add new accelerator to our parent's accelerator group
820 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
821 if (buf
[(size_t)0] != '\0')
823 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
826 gtk_widget_add_accelerator( m_menuItem
,
828 m_parentMenu
->m_accel
,
836 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
837 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
838 gtk_widget_remove_accelerator( m_menuItem
,
839 m_parentMenu
->m_accel
,
843 #endif // wxUSE_FILECTRL
846 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
847 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
848 // so there's no real code duplication
849 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
853 // '\t' is the deliminator indicating a hot key
854 wxString::const_iterator pc
= str
.begin();
855 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
859 wxString::const_iterator next
= pc
+ 1;
860 if (next
!= str
.end() && *next
== wxT('&'))
862 // "&" is doubled to indicate "&" instead of accelerator
871 else if ( *pc
== wxT('_') ) // escape underscores
888 hotKey
->assign(pc
, str
.end());
895 // it's valid for this function to be called even if m_menuItem == NULL
896 void wxMenuItem::DoSetText( const wxString
& str
)
899 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
904 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
912 // accelerator parsing code looks for them after a TAB, so insert a dummy
915 label
<< wxT('\t') << GetHotKey();
917 return wxAcceleratorEntry::Create(label
);
920 #endif // wxUSE_ACCEL
922 void wxMenuItem::Check( bool check
)
924 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
926 if (check
== m_isChecked
)
929 wxMenuItemBase::Check( check
);
935 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
939 wxFAIL_MSG( _T("can't check this item") );
943 void wxMenuItem::Enable( bool enable
)
945 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
947 gtk_widget_set_sensitive( m_menuItem
, enable
);
948 wxMenuItemBase::Enable( enable
);
951 bool wxMenuItem::IsChecked() const
953 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
955 wxCHECK_MSG( IsCheckable(), false,
956 wxT("can't get state of uncheckable item!") );
958 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
961 //-----------------------------------------------------------------------------
963 //-----------------------------------------------------------------------------
965 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
969 m_accel
= gtk_accel_group_new();
970 m_menu
= gtk_menu_new();
971 // NB: keep reference to the menu so that it is not destroyed behind
972 // our back by GTK+ e.g. when it is removed from menubar:
973 gtk_widget_ref(m_menu
);
975 m_owner
= (GtkWidget
*) NULL
;
977 // Tearoffs are entries, just like separators. So if we want this
978 // menu to be a tear-off one, we just append a tearoff entry
980 if ( m_style
& wxMENU_TEAROFF
)
982 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
984 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
989 // append the title as the very first entry if we have it
990 if ( !m_title
.empty() )
992 Append(wxGTK_TITLE_ID
, m_title
);
999 if ( GTK_IS_WIDGET( m_menu
))
1002 gtk_widget_unref( m_menu
);
1003 g_object_unref( m_accel
);
1005 // if the menu is inserted in another menu at this time, there was
1006 // one more reference to it:
1008 gtk_widget_destroy( m_menu
);
1011 // This must come after we release GTK resources above. Otherwise, GTK will
1012 // give warnings/errors when attempting to free accelerator resources from
1013 // child items that just were destroyed (the m_menu widget can contain
1014 // references to accelerators in child items. Problem detected when removing
1015 // a menu from a wxMenuBar, and the removed menu had submenus with accelerators.)
1016 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1019 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1022 wxWindow::GTKSetLayout(m_owner
, dir
);
1023 //else: will be called later by wxMenuBar again
1026 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1028 return wxWindow::GTKGetLayout(m_owner
);
1031 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1033 GtkWidget
*menuItem
;
1035 // cache some data used later
1036 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1037 int id
= mitem
->GetId();
1038 bool isstock
= wxIsStockID(id
);
1039 const char *stockid
= NULL
;
1041 stockid
= wxGetStockGtkID(mitem
->GetId());
1043 // stock menu items can have an empty label
1044 if (text
.IsEmpty() && !mitem
->IsSeparator())
1046 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1047 text
= wxGetStockLabel(id
);
1049 // need & => _ conversion
1050 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1053 if ( mitem
->IsSeparator() )
1055 menuItem
= gtk_separator_menu_item_new();
1057 else if ( mitem
->GetBitmap().Ok() ||
1058 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1060 wxBitmap
bitmap(mitem
->GetBitmap());
1062 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1067 // use stock bitmap for this item if available on the assumption
1068 // that it never hurts to follow GTK+ conventions more closely
1069 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1072 else // we have a custom bitmap
1074 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1075 _T("only normal menu items can have bitmaps") );
1077 if ( bitmap
.HasPixbuf() )
1079 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1083 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1084 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1085 bitmap
.GetMask()->GetBitmap() :
1087 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1093 gtk_widget_show(image
);
1095 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1100 else // a normal item
1102 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1105 switch ( mitem
->GetKind() )
1109 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1116 GSList
*group
= NULL
;
1117 if ( m_prevRadio
== NULL
)
1119 // start of a new radio group
1120 m_prevRadio
= menuItem
=
1121 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1123 else // continue the radio group
1125 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1126 m_prevRadio
= menuItem
=
1127 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1133 wxFAIL_MSG( _T("unexpected menu item kind") );
1138 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1148 GdkModifierType accel_mods
;
1149 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1151 if (buf
[(size_t)0] != '\0')
1153 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1156 gtk_widget_add_accelerator (menuItem
,
1166 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1167 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1168 gtk_widget_add_accelerator( menuItem
,
1175 #endif // wxUSE_FILECTRL
1178 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1180 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1182 gtk_widget_show( menuItem
);
1184 if ( !mitem
->IsSeparator() )
1186 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1188 g_signal_connect (menuItem
, "select",
1189 G_CALLBACK (gtk_menu_hilight_callback
), this);
1190 g_signal_connect (menuItem
, "deselect",
1191 G_CALLBACK (gtk_menu_nolight_callback
), this);
1193 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1195 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1197 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1199 // if adding a submenu to a menu already existing in the menu bar, we
1200 // must set invoking window to allow processing events from this
1202 if ( m_invokingWindow
)
1203 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1207 g_signal_connect (menuItem
, "activate",
1208 G_CALLBACK (gtk_menu_clicked_callback
),
1213 mitem
->SetMenuItem(menuItem
);
1217 // This doesn't even exist!
1218 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1224 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1226 if (!GtkAppend(mitem
))
1229 return wxMenuBase::DoAppend(mitem
);
1232 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1234 if ( !wxMenuBase::DoInsert(pos
, item
) )
1238 if ( !GtkAppend(item
, (int)pos
) )
1244 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1246 if ( !wxMenuBase::DoRemove(item
) )
1247 return (wxMenuItem
*)NULL
;
1249 // TODO: this code doesn't delete the item factory item and this seems
1250 // impossible as of GTK 1.2.6.
1251 gtk_widget_destroy( item
->GetMenuItem() );
1256 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1258 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1261 wxMenuItem
*item
= node
->GetData();
1262 if (item
->GetMenuItem() == menuItem
)
1263 return item
->GetId();
1264 node
= node
->GetNext();
1270 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1272 wxMenuBase::Attach(menubar
);
1274 // inherit layout direction from menubar.
1275 SetLayoutDirection(menubar
->GetLayoutDirection());
1278 // ----------------------------------------------------------------------------
1280 // ----------------------------------------------------------------------------
1284 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1288 wxAcceleratorEntry
*accel
= item
.GetAccel();
1291 int flags
= accel
->GetFlags();
1292 if ( flags
& wxACCEL_ALT
)
1293 hotkey
+= wxT("<alt>");
1294 if ( flags
& wxACCEL_CTRL
)
1295 hotkey
+= wxT("<control>");
1296 if ( flags
& wxACCEL_SHIFT
)
1297 hotkey
+= wxT("<shift>");
1299 int code
= accel
->GetKeyCode();
1326 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1329 // TODO: we should use gdk_keyval_name() (a.k.a.
1330 // XKeysymToString) here as well as hardcoding the keysym
1331 // names this might be not portable
1333 hotkey
<< wxT("Insert" );
1336 hotkey
<< wxT("Delete" );
1339 hotkey
<< wxT("Up" );
1342 hotkey
<< wxT("Down" );
1345 hotkey
<< wxT("Page_Up" );
1348 hotkey
<< wxT("Page_Down" );
1351 hotkey
<< wxT("Left" );
1354 hotkey
<< wxT("Right" );
1357 hotkey
<< wxT("Home" );
1360 hotkey
<< wxT("End" );
1363 hotkey
<< wxT("Return" );
1366 hotkey
<< wxT("BackSpace" );
1369 hotkey
<< wxT("Tab" );
1372 hotkey
<< wxT("Esc" );
1375 hotkey
<< wxT("space" );
1378 hotkey
<< wxT("Multiply" );
1381 hotkey
<< wxT("Add" );
1384 hotkey
<< wxT("Separator" );
1387 hotkey
<< wxT("Subtract" );
1390 hotkey
<< wxT("Decimal" );
1393 hotkey
<< wxT("Divide" );
1396 hotkey
<< wxT("Cancel" );
1399 hotkey
<< wxT("Clear" );
1402 hotkey
<< wxT("Menu" );
1405 hotkey
<< wxT("Pause" );
1408 hotkey
<< wxT("Capital" );
1411 hotkey
<< wxT("Select" );
1414 hotkey
<< wxT("Print" );
1417 hotkey
<< wxT("Execute" );
1420 hotkey
<< wxT("Snapshot" );
1423 hotkey
<< wxT("Help" );
1426 hotkey
<< wxT("Num_Lock" );
1429 hotkey
<< wxT("Scroll_Lock" );
1431 case WXK_NUMPAD_INSERT
:
1432 hotkey
<< wxT("KP_Insert" );
1434 case WXK_NUMPAD_DELETE
:
1435 hotkey
<< wxT("KP_Delete" );
1437 case WXK_NUMPAD_SPACE
:
1438 hotkey
<< wxT("KP_Space" );
1440 case WXK_NUMPAD_TAB
:
1441 hotkey
<< wxT("KP_Tab" );
1443 case WXK_NUMPAD_ENTER
:
1444 hotkey
<< wxT("KP_Enter" );
1446 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1448 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1450 case WXK_NUMPAD_HOME
:
1451 hotkey
<< wxT("KP_Home" );
1453 case WXK_NUMPAD_LEFT
:
1454 hotkey
<< wxT("KP_Left" );
1457 hotkey
<< wxT("KP_Up" );
1459 case WXK_NUMPAD_RIGHT
:
1460 hotkey
<< wxT("KP_Right" );
1462 case WXK_NUMPAD_DOWN
:
1463 hotkey
<< wxT("KP_Down" );
1465 case WXK_NUMPAD_PAGEUP
:
1466 hotkey
<< wxT("KP_Page_Up" );
1468 case WXK_NUMPAD_PAGEDOWN
:
1469 hotkey
<< wxT("KP_Page_Down" );
1471 case WXK_NUMPAD_END
:
1472 hotkey
<< wxT("KP_End" );
1474 case WXK_NUMPAD_BEGIN
:
1475 hotkey
<< wxT("KP_Begin" );
1477 case WXK_NUMPAD_EQUAL
:
1478 hotkey
<< wxT("KP_Equal" );
1480 case WXK_NUMPAD_MULTIPLY
:
1481 hotkey
<< wxT("KP_Multiply" );
1483 case WXK_NUMPAD_ADD
:
1484 hotkey
<< wxT("KP_Add" );
1486 case WXK_NUMPAD_SEPARATOR
:
1487 hotkey
<< wxT("KP_Separator" );
1489 case WXK_NUMPAD_SUBTRACT
:
1490 hotkey
<< wxT("KP_Subtract" );
1492 case WXK_NUMPAD_DECIMAL
:
1493 hotkey
<< wxT("KP_Decimal" );
1495 case WXK_NUMPAD_DIVIDE
:
1496 hotkey
<< wxT("KP_Divide" );
1498 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1499 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1500 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1501 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1503 case WXK_WINDOWS_LEFT
:
1504 hotkey
<< wxT("Super_L" );
1506 case WXK_WINDOWS_RIGHT
:
1507 hotkey
<< wxT("Super_R" );
1509 case WXK_WINDOWS_MENU
:
1510 hotkey
<< wxT("Menu" );
1513 hotkey
<< wxT("Command" );
1515 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1516 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1517 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1518 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1519 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1520 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1521 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1524 // if there are any other keys wxAcceleratorEntry::Create() may
1525 // return, we should process them here
1531 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1532 if ( !name
.empty() )
1539 wxFAIL_MSG( wxT("unknown keyboard accel") );
1548 #endif // wxUSE_ACCEL
1550 // ----------------------------------------------------------------------------
1551 // Pop-up menu stuff
1552 // ----------------------------------------------------------------------------
1554 #if wxUSE_MENUS_NATIVE
1556 extern "C" WXDLLIMPEXP_CORE
1557 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1559 *is_waiting
= false;
1562 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1564 menu
->SetInvokingWindow( win
);
1566 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1569 wxMenuItem
*menuitem
= node
->GetData();
1570 if (menuitem
->IsSubMenu())
1572 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1575 node
= node
->GetNext();
1579 extern "C" WXDLLIMPEXP_CORE
1580 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1582 gboolean
* WXUNUSED(whatever
),
1583 gpointer user_data
)
1585 // ensure that the menu appears entirely on screen
1587 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1589 wxSize sizeScreen
= wxGetDisplaySize();
1590 wxPoint
*pos
= (wxPoint
*)user_data
;
1592 gint xmax
= sizeScreen
.x
- req
.width
,
1593 ymax
= sizeScreen
.y
- req
.height
;
1595 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1596 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1599 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1601 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1603 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1605 // NOTE: if you change this code, you need to update
1606 // the same code in taskbar.cpp as well. This
1607 // is ugly code duplication, I know.
1609 SetInvokingWindow( menu
, this );
1613 bool is_waiting
= true;
1615 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1616 G_CALLBACK (gtk_pop_hide_callback
),
1621 GtkMenuPositionFunc posfunc
;
1622 if ( x
== -1 && y
== -1 )
1624 // use GTK's default positioning algorithm
1630 pos
= ClientToScreen(wxPoint(x
, y
));
1632 posfunc
= wxPopupMenuPositionCallback
;
1635 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1636 DoCommonMenuCallbackCode(menu
, eventOpen
);
1639 GTK_MENU(menu
->m_menu
),
1640 (GtkWidget
*) NULL
, // parent menu shell
1641 (GtkWidget
*) NULL
, // parent menu item
1642 posfunc
, // function to position it
1643 userdata
, // client data
1644 0, // button used to activate it
1645 gtk_get_current_event_time()
1650 gtk_main_iteration();
1653 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1655 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1656 DoCommonMenuCallbackCode(menu
, eventClose
);
1661 #endif // wxUSE_MENUS_NATIVE
1663 #include <gtk/gtk.h>
1665 const char *wxGetStockGtkID(wxWindowID id
)
1667 #define STOCKITEM(wx,gtk) \
1671 #define STOCKITEM_MISSING(wx) \
1675 #if GTK_CHECK_VERSION(2,4,0)
1676 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1678 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1681 #if GTK_CHECK_VERSION(2,6,0)
1682 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1684 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1687 #if GTK_CHECK_VERSION(2,10,0)
1688 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1690 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1696 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1697 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1698 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1699 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1700 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1701 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1702 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1703 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1704 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1705 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1706 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1707 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1708 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1709 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1710 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1711 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1712 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1713 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1714 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1715 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1716 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1717 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1718 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1719 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1720 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1721 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1722 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1723 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1724 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1725 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1726 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1727 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1728 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1729 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1730 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1731 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1732 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1733 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1734 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1735 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1736 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1737 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1738 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1739 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1740 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1741 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1742 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1743 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1744 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1745 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1746 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1747 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1748 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1749 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1752 wxFAIL_MSG( _T("invalid stock item ID") );
1761 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1766 GtkStockItem stock_item
;
1767 if (gtk_stock_lookup (id
, &stock_item
))
1769 if (key
) *key
= stock_item
.keyval
;
1770 if (mod
) *mod
= stock_item
.modifier
;
1772 // some GTK stock items have zero values for the keyval;
1773 // it means that they do not have an accelerator...
1774 if (stock_item
.keyval
)
1781 #endif // wxUSE_MENUS