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 // we use normal item but with a special id for the menu title
31 static const int wxGTK_TITLE_ID
= -3;
33 // forward declare it as it's used by wxMenuBar too when using Hildon
36 static void gtk_menu_clicked_callback(GtkWidget
*widget
, wxMenu
*menu
);
40 static bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
);
41 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
44 //-----------------------------------------------------------------------------
45 // activate message from GTK
46 //-----------------------------------------------------------------------------
48 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
50 event
.SetEventObject( menu
);
52 wxEvtHandler
* handler
= menu
->GetEventHandler();
53 if (handler
&& handler
->SafelyProcessEvent(event
))
56 wxWindow
*win
= menu
->GetInvokingWindow();
58 win
->HandleWindowEvent( event
);
64 gtk_menu_open_callback(GtkWidget
* WXUNUSED(widget
), wxMenu
*menu
)
66 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
68 DoCommonMenuCallbackCode(menu
, event
);
72 gtk_menu_close_callback(GtkWidget
* WXUNUSED(widget
), wxMenuBar
*menubar
)
74 if ( !menubar
->GetMenuCount() )
76 // if menubar is empty we can't call GetMenu(0) below
80 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
82 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
87 //-----------------------------------------------------------------------------
89 //-----------------------------------------------------------------------------
91 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
93 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
95 m_invokingWindow
= NULL
;
98 // Hildon window uses a single menu instead of a menu bar, so wxMenuBar is
99 // the same as menu in this case
101 m_menubar
= gtk_menu_new();
102 #else // !wxUSE_LIBHILDON
103 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
104 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
106 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
110 m_menubar
= gtk_menu_bar_new();
112 if (style
& wxMB_DOCKABLE
)
114 m_widget
= gtk_handle_box_new();
115 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
116 gtk_widget_show(m_menubar
);
120 m_widget
= m_menubar
;
126 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
128 for (size_t i
= 0; i
< n
; ++i
)
129 Append(menus
[i
], titles
[i
]);
131 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
132 // don't get it when the menu is dismissed by clicking outside the
133 // toolbar) so we connect to the global one, even if it means that we
134 // can't pass the menu which was closed in wxMenuEvent object
135 g_signal_connect (m_menubar
, "deactivate",
136 G_CALLBACK (gtk_menu_close_callback
), this);
139 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
141 Init(n
, menus
, titles
, style
);
144 wxMenuBar::wxMenuBar(long style
)
146 Init(0, NULL
, NULL
, style
);
149 wxMenuBar::wxMenuBar()
151 Init(0, NULL
, NULL
, 0);
154 wxMenuBar::~wxMenuBar()
158 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
160 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
162 wxWindow
*top_frame
= win
;
163 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
164 top_frame
= top_frame
->GetParent();
166 // support for native hot keys
167 if (menu
->m_accel
&& g_slist_find(menu
->m_accel
->acceleratables
, top_frame
->m_widget
))
168 gtk_window_remove_accel_group(GTK_WINDOW(top_frame
->m_widget
), menu
->m_accel
);
170 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
173 wxMenuItem
*menuitem
= node
->GetData();
174 if (menuitem
->IsSubMenu())
175 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
176 node
= node
->GetNext();
180 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
182 menu
->SetInvokingWindow( win
);
184 wxWindow
*top_frame
= win
;
185 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
186 top_frame
= top_frame
->GetParent();
188 // support for native hot keys
189 if (menu
->m_accel
&& !g_slist_find(menu
->m_accel
->acceleratables
, top_frame
->m_widget
))
190 gtk_window_add_accel_group(GTK_WINDOW(top_frame
->m_widget
), menu
->m_accel
);
192 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
195 wxMenuItem
*menuitem
= node
->GetData();
196 if (menuitem
->IsSubMenu())
197 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
198 node
= node
->GetNext();
202 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
204 m_invokingWindow
= win
;
205 wxWindow
*top_frame
= win
;
206 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
207 top_frame
= top_frame
->GetParent();
209 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
212 wxMenu
*menu
= node
->GetData();
213 wxMenubarSetInvokingWindow( menu
, win
);
214 node
= node
->GetNext();
218 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
220 if ( dir
== wxLayout_Default
)
222 const wxWindow
*const frame
= GetFrame();
225 // inherit layout from frame.
226 dir
= frame
->GetLayoutDirection();
228 else // use global layout
230 dir
= wxTheApp
->GetLayoutDirection();
234 if ( dir
== wxLayout_Default
)
237 GTKSetLayout(m_menubar
, dir
);
239 // also set the layout of all menus we already have (new ones will inherit
240 // the current layout)
241 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
243 node
= node
->GetNext() )
245 wxMenu
*const menu
= node
->GetData();
246 menu
->SetLayoutDirection(dir
);
250 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
252 return GTKGetLayout(m_menubar
);
255 void wxMenuBar::Attach(wxFrame
*frame
)
257 wxMenuBarBase::Attach(frame
);
259 SetLayoutDirection(wxLayout_Default
);
262 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
264 m_invokingWindow
= (wxWindow
*) NULL
;
265 wxWindow
*top_frame
= win
;
266 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
267 top_frame
= top_frame
->GetParent();
269 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
272 wxMenu
*menu
= node
->GetData();
273 wxMenubarUnsetInvokingWindow( menu
, win
);
274 node
= node
->GetNext();
278 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
280 if ( !wxMenuBarBase::Append( menu
, title
) )
283 return GtkAppend(menu
, title
);
286 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
288 menu
->SetLayoutDirection(GetLayoutDirection());
291 // if the menu has only one item, append it directly to the top level menu
292 // instead of inserting a useless submenu
293 if ( menu
->GetMenuItemCount() == 1 )
295 wxMenuItem
* const item
= menu
->FindItemByPosition(0);
297 // remove both mnemonics and accelerator: neither is useful under Maemo
298 const wxString
str(wxStripMenuCodes(item
->GetItemLabel()));
300 if ( item
->IsSubMenu() )
301 return GtkAppend(item
->GetSubMenu(), str
, pos
);
303 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
305 g_signal_connect(menu
->m_owner
, "activate",
306 G_CALLBACK(gtk_menu_clicked_callback
), menu
);
307 item
->SetMenuItem(menu
->m_owner
);
310 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
312 const wxString
str(wxConvertMnemonicsToGTK(title
));
314 // This doesn't have much effect right now.
315 menu
->SetTitle( str
);
317 // The "m_owner" is the "menu item"
318 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
320 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
323 gtk_widget_show( menu
->m_owner
);
326 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
328 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
330 g_signal_connect (menu
->m_owner
, "activate",
331 G_CALLBACK (gtk_menu_open_callback
),
334 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
335 // addings menu later on.
336 if (m_invokingWindow
)
337 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
342 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
344 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
349 if ( !GtkAppend(menu
, title
, (int)pos
) )
355 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
357 // remove the old item and insert a new one
358 wxMenu
*menuOld
= Remove(pos
);
359 if ( menuOld
&& !Insert(pos
, menu
, title
) )
361 return (wxMenu
*) NULL
;
364 // either Insert() succeeded or Remove() failed and menuOld is NULL
368 wxMenu
*wxMenuBar::Remove(size_t pos
)
370 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
372 return (wxMenu
*) NULL
;
374 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu
->m_owner
), NULL
);
375 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
377 gtk_widget_destroy( menu
->m_owner
);
378 menu
->m_owner
= NULL
;
380 if (m_invokingWindow
)
381 wxMenubarUnsetInvokingWindow( menu
, m_invokingWindow
);
386 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
388 if (wxMenuItem::GetLabelText(wxConvertMnemonicsFromGTK(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
390 int res
= menu
->FindItem( itemString
);
391 if (res
!= wxNOT_FOUND
)
395 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
398 wxMenuItem
*item
= node
->GetData();
399 if (item
->IsSubMenu())
400 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
402 node
= node
->GetNext();
408 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
410 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
413 wxMenu
*menu
= node
->GetData();
414 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
417 node
= node
->GetNext();
423 // Find a wxMenuItem using its id. Recurses down into sub-menus
424 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
426 wxMenuItem
* result
= menu
->FindChildItem(id
);
428 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
429 while ( node
&& result
== NULL
)
431 wxMenuItem
*item
= node
->GetData();
432 if (item
->IsSubMenu())
434 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
436 node
= node
->GetNext();
442 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
444 wxMenuItem
* result
= 0;
445 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
446 while (node
&& result
== 0)
448 wxMenu
*menu
= node
->GetData();
449 result
= FindMenuItemByIdRecursive( menu
, id
);
450 node
= node
->GetNext();
455 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
461 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
463 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
465 wxCHECK_RET( node
, wxT("menu not found") );
467 wxMenu
* menu
= node
->GetData();
470 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
473 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
475 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
477 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
479 wxMenu
* menu
= node
->GetData();
481 return wxConvertMnemonicsFromGTK(menu
->GetTitle());
484 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
486 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
488 wxCHECK_RET( node
, wxT("menu not found") );
490 wxMenu
* menu
= node
->GetData();
492 const wxString
str(wxConvertMnemonicsToGTK(label
));
494 menu
->SetTitle( str
);
497 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
500 //-----------------------------------------------------------------------------
502 //-----------------------------------------------------------------------------
505 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
507 int id
= menu
->FindMenuIdByMenuItem(widget
);
509 /* should find it for normal (not popup) menu */
510 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
511 _T("menu item not found in gtk_menu_clicked_callback") );
513 if (!menu
->IsEnabled(id
))
516 wxMenuItem
* item
= menu
->FindChildItem( id
);
517 wxCHECK_RET( item
, wxT("error in menu item callback") );
519 if ( item
->GetId() == wxGTK_TITLE_ID
)
521 // ignore events from the menu title
525 if (item
->IsCheckable())
527 bool isReallyChecked
= item
->IsChecked(),
528 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
530 // ensure that the internal state is always consistent with what is
531 // shown on the screen
532 item
->wxMenuItemBase::Check(isReallyChecked
);
534 // we must not report the events for the radio button going up nor the
535 // events resulting from the calls to wxMenuItem::Check()
536 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
537 (isInternallyChecked
== isReallyChecked
) )
544 // Is this menu on a menubar? (possibly nested)
545 wxFrame
* frame
= NULL
;
546 if(menu
->IsAttached())
547 frame
= menu
->GetMenuBar()->GetFrame();
549 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
550 // normally wxMenu::SendEvent() should be enough, if it doesn't work
551 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
552 // should be fixed instead of working around it here...
555 // If it is attached then let the frame send the event.
556 // Don't call frame->ProcessCommand(id) because it toggles
557 // checkable items and we've already done that above.
558 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
559 commandEvent
.SetEventObject(frame
);
560 if (item
->IsCheckable())
561 commandEvent
.SetInt(item
->IsChecked());
563 frame
->HandleWindowEvent(commandEvent
);
567 // otherwise let the menu have it
568 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
573 //-----------------------------------------------------------------------------
575 //-----------------------------------------------------------------------------
578 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
580 int id
= menu
->FindMenuIdByMenuItem(widget
);
582 wxASSERT( id
!= -1 ); // should find it!
584 if (!menu
->IsEnabled(id
))
587 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
588 event
.SetEventObject( menu
);
590 wxEvtHandler
* handler
= menu
->GetEventHandler();
591 if (handler
&& handler
->SafelyProcessEvent(event
))
594 wxWindow
*win
= menu
->GetInvokingWindow();
595 if (win
) win
->HandleWindowEvent( event
);
599 //-----------------------------------------------------------------------------
601 //-----------------------------------------------------------------------------
604 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
606 int id
= menu
->FindMenuIdByMenuItem(widget
);
608 wxASSERT( id
!= -1 ); // should find it!
610 if (!menu
->IsEnabled(id
))
613 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
614 event
.SetEventObject( menu
);
616 wxEvtHandler
* handler
= menu
->GetEventHandler();
617 if (handler
&& handler
->SafelyProcessEvent(event
))
620 wxWindow
*win
= menu
->GetInvokingWindow();
622 win
->HandleWindowEvent( event
);
626 //-----------------------------------------------------------------------------
628 //-----------------------------------------------------------------------------
630 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
632 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
634 const wxString
& name
,
635 const wxString
& help
,
639 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
642 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
644 const wxString
& text
,
645 const wxString
& help
,
648 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
653 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
655 const wxString
& text
,
656 const wxString
& help
,
659 : wxMenuItemBase(parentMenu
, id
, text
, help
,
660 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
665 void wxMenuItem::Init(const wxString
& text
)
667 m_labelWidget
= (GtkWidget
*) NULL
;
668 m_menuItem
= (GtkWidget
*) NULL
;
673 wxMenuItem::~wxMenuItem()
675 // don't delete menu items, the menus take care of that
678 // return the menu item text without any menu accels
681 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
683 // The argument to this function will now always be in wxWidgets standard label
684 // format, not GTK+ format, so we do what the other ports do.
686 return wxStripMenuCodes(text
);
691 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
693 if ( *pc
== wxT('\t'))
696 if ( *pc
== wxT('_') )
698 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
704 if ( *pc
== wxT('\\') )
706 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
712 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
715 // "&" is doubled to indicate "&" instead of accelerator
722 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
728 wxString
wxMenuItem::GetItemLabel() const
730 wxString label
= wxConvertMnemonicsFromGTK(m_text
);
731 if (!m_hotKey
.IsEmpty())
732 label
<< "\t" << m_hotKey
;
736 void wxMenuItem::SetItemLabel( const wxString
& str
)
738 // cache some data which must be used later
739 bool isstock
= wxIsStockID(GetId());
740 const char *stockid
= NULL
;
742 stockid
= wxGetStockGtkID(GetId());
744 // Some optimization to avoid flicker
745 wxString oldLabel
= m_text
;
746 oldLabel
= wxStripMenuCodes(oldLabel
);
747 oldLabel
.Replace(wxT("_"), wxT(""));
748 wxString label1
= wxStripMenuCodes(str
);
750 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
751 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
752 #endif // wxUSE_ACCEL
757 if (oldLabel
== label1
&&
758 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
765 label
= (GtkLabel
*) m_labelWidget
;
767 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
769 // stock menu items can have empty labels:
770 wxString text
= m_text
;
771 if (text
.IsEmpty() && !IsSeparator())
773 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
774 text
= wxGetStockLabel(GetId());
776 // need & => _ conversion
777 text
= GTKProcessMenuItemLabel(text
, NULL
);
780 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
783 // remove old accelerator from our parent's accelerator group, if present
785 GdkModifierType accel_mods
;
786 if (oldbuf
[(size_t)0] != '\0')
788 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
791 gtk_widget_remove_accelerator(m_menuItem
,
792 m_parentMenu
->m_accel
,
799 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
800 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
801 gtk_widget_remove_accelerator( m_menuItem
,
802 m_parentMenu
->m_accel
,
807 // add new accelerator to our parent's accelerator group
808 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
809 if (buf
[(size_t)0] != '\0')
811 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
814 gtk_widget_add_accelerator( m_menuItem
,
816 m_parentMenu
->m_accel
,
824 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
825 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
826 gtk_widget_remove_accelerator( m_menuItem
,
827 m_parentMenu
->m_accel
,
831 #endif // wxUSE_ACCEL
834 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
835 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
836 // so there's no real code duplication
837 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
841 // '\t' is the deliminator indicating a hot key
842 wxString::const_iterator pc
= str
.begin();
843 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
847 wxString::const_iterator next
= pc
+ 1;
848 if (next
!= str
.end() && *next
== wxT('&'))
850 // "&" is doubled to indicate "&" instead of accelerator
859 else if ( *pc
== wxT('_') ) // escape underscores
876 hotKey
->assign(pc
, str
.end());
883 // it's valid for this function to be called even if m_menuItem == NULL
884 void wxMenuItem::DoSetText( const wxString
& str
)
887 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
892 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
900 // accelerator parsing code looks for them after a TAB, so insert a dummy
903 label
<< wxT('\t') << GetHotKey();
905 return wxAcceleratorEntry::Create(label
);
908 #endif // wxUSE_ACCEL
910 void wxMenuItem::Check( bool check
)
912 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
914 if (check
== m_isChecked
)
917 wxMenuItemBase::Check( check
);
923 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
927 wxFAIL_MSG( _T("can't check this item") );
931 void wxMenuItem::Enable( bool enable
)
933 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
935 gtk_widget_set_sensitive( m_menuItem
, enable
);
936 wxMenuItemBase::Enable( enable
);
939 bool wxMenuItem::IsChecked() const
941 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
943 wxCHECK_MSG( IsCheckable(), false,
944 wxT("can't get state of uncheckable item!") );
946 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
949 //-----------------------------------------------------------------------------
951 //-----------------------------------------------------------------------------
953 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
957 m_accel
= gtk_accel_group_new();
958 m_menu
= gtk_menu_new();
959 // NB: keep reference to the menu so that it is not destroyed behind
960 // our back by GTK+ e.g. when it is removed from menubar:
961 g_object_ref(m_menu
);
962 gtk_object_sink(GTK_OBJECT(m_menu
));
964 m_owner
= (GtkWidget
*) NULL
;
966 // Tearoffs are entries, just like separators. So if we want this
967 // menu to be a tear-off one, we just append a tearoff entry
969 if ( m_style
& wxMENU_TEAROFF
)
971 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
973 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
978 // append the title as the very first entry if we have it
979 if ( !m_title
.empty() )
981 Append(wxGTK_TITLE_ID
, m_title
);
988 if ( GTK_IS_WIDGET( m_menu
))
991 g_object_unref(m_menu
);
993 // if the menu is inserted in another menu at this time, there was
994 // one more reference to it:
996 gtk_widget_destroy( m_menu
);
998 g_object_unref(m_accel
);
1002 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1005 wxWindow::GTKSetLayout(m_owner
, dir
);
1006 //else: will be called later by wxMenuBar again
1009 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1011 return wxWindow::GTKGetLayout(m_owner
);
1014 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1016 GtkWidget
*menuItem
;
1018 // cache some data used later
1019 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1020 int id
= mitem
->GetId();
1021 bool isstock
= wxIsStockID(id
);
1022 const char *stockid
= NULL
;
1024 stockid
= wxGetStockGtkID(mitem
->GetId());
1026 // stock menu items can have an empty label
1027 if (text
.IsEmpty() && !mitem
->IsSeparator())
1029 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1030 text
= wxGetStockLabel(id
);
1032 // need & => _ conversion
1033 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1036 if ( mitem
->IsSeparator() )
1038 menuItem
= gtk_separator_menu_item_new();
1041 else if ( mitem
->GetBitmap().Ok() ||
1042 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1044 wxBitmap
bitmap(mitem
->GetBitmap());
1046 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1051 // use stock bitmap for this item if available on the assumption
1052 // that it never hurts to follow GTK+ conventions more closely
1053 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1056 else // we have a custom bitmap
1058 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1059 _T("only normal menu items can have bitmaps") );
1061 if ( bitmap
.HasPixbuf() )
1063 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1067 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1068 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1069 bitmap
.GetMask()->GetBitmap() :
1071 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1077 gtk_widget_show(image
);
1079 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1084 else // a normal item
1086 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1089 switch ( mitem
->GetKind() )
1093 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1100 GSList
*group
= NULL
;
1101 if ( m_prevRadio
== NULL
)
1103 // start of a new radio group
1104 m_prevRadio
= menuItem
=
1105 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1107 else // continue the radio group
1109 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1110 m_prevRadio
= menuItem
=
1111 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1117 wxFAIL_MSG( _T("unexpected menu item kind") );
1122 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1132 GdkModifierType accel_mods
;
1133 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1135 if (buf
[(size_t)0] != '\0')
1137 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1140 gtk_widget_add_accelerator (menuItem
,
1150 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1151 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1152 gtk_widget_add_accelerator( menuItem
,
1159 #endif // wxUSE_ACCEL
1162 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1164 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1166 gtk_widget_show( menuItem
);
1168 if ( !mitem
->IsSeparator() )
1170 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1172 g_signal_connect (menuItem
, "select",
1173 G_CALLBACK (gtk_menu_hilight_callback
), this);
1174 g_signal_connect (menuItem
, "deselect",
1175 G_CALLBACK (gtk_menu_nolight_callback
), this);
1177 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1179 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1181 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1183 // if adding a submenu to a menu already existing in the menu bar, we
1184 // must set invoking window to allow processing events from this
1186 if ( m_invokingWindow
)
1187 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1191 g_signal_connect (menuItem
, "activate",
1192 G_CALLBACK (gtk_menu_clicked_callback
),
1197 mitem
->SetMenuItem(menuItem
);
1201 // This doesn't even exist!
1202 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1208 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1210 if (!GtkAppend(mitem
))
1213 return wxMenuBase::DoAppend(mitem
);
1216 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1218 if ( !wxMenuBase::DoInsert(pos
, item
) )
1222 if ( !GtkAppend(item
, (int)pos
) )
1228 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1230 if ( !wxMenuBase::DoRemove(item
) )
1233 GtkWidget
* const mitem
= item
->GetMenuItem();
1234 if ( m_prevRadio
== mitem
)
1236 // deleting an item starts a new radio group (has to as we shouldn't
1237 // keep a deleted pointer anyhow)
1241 // TODO: this code doesn't delete the item factory item and this seems
1242 // impossible as of GTK 1.2.6.
1243 gtk_widget_destroy( mitem
);
1248 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1250 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1253 wxMenuItem
*item
= node
->GetData();
1254 if (item
->GetMenuItem() == menuItem
)
1255 return item
->GetId();
1256 node
= node
->GetNext();
1262 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1264 wxMenuBase::Attach(menubar
);
1266 // inherit layout direction from menubar.
1267 SetLayoutDirection(menubar
->GetLayoutDirection());
1270 // ----------------------------------------------------------------------------
1272 // ----------------------------------------------------------------------------
1276 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1280 wxAcceleratorEntry
*accel
= item
.GetAccel();
1283 int flags
= accel
->GetFlags();
1284 if ( flags
& wxACCEL_ALT
)
1285 hotkey
+= wxT("<alt>");
1286 if ( flags
& wxACCEL_CTRL
)
1287 hotkey
+= wxT("<control>");
1288 if ( flags
& wxACCEL_SHIFT
)
1289 hotkey
+= wxT("<shift>");
1291 int code
= accel
->GetKeyCode();
1318 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1321 // TODO: we should use gdk_keyval_name() (a.k.a.
1322 // XKeysymToString) here as well as hardcoding the keysym
1323 // names this might be not portable
1325 hotkey
<< wxT("Insert" );
1328 hotkey
<< wxT("Delete" );
1331 hotkey
<< wxT("Up" );
1334 hotkey
<< wxT("Down" );
1337 hotkey
<< wxT("Page_Up" );
1340 hotkey
<< wxT("Page_Down" );
1343 hotkey
<< wxT("Left" );
1346 hotkey
<< wxT("Right" );
1349 hotkey
<< wxT("Home" );
1352 hotkey
<< wxT("End" );
1355 hotkey
<< wxT("Return" );
1358 hotkey
<< wxT("BackSpace" );
1361 hotkey
<< wxT("Tab" );
1364 hotkey
<< wxT("Esc" );
1367 hotkey
<< wxT("space" );
1370 hotkey
<< wxT("Multiply" );
1373 hotkey
<< wxT("Add" );
1376 hotkey
<< wxT("Separator" );
1379 hotkey
<< wxT("Subtract" );
1382 hotkey
<< wxT("Decimal" );
1385 hotkey
<< wxT("Divide" );
1388 hotkey
<< wxT("Cancel" );
1391 hotkey
<< wxT("Clear" );
1394 hotkey
<< wxT("Menu" );
1397 hotkey
<< wxT("Pause" );
1400 hotkey
<< wxT("Capital" );
1403 hotkey
<< wxT("Select" );
1406 hotkey
<< wxT("Print" );
1409 hotkey
<< wxT("Execute" );
1412 hotkey
<< wxT("Snapshot" );
1415 hotkey
<< wxT("Help" );
1418 hotkey
<< wxT("Num_Lock" );
1421 hotkey
<< wxT("Scroll_Lock" );
1423 case WXK_NUMPAD_INSERT
:
1424 hotkey
<< wxT("KP_Insert" );
1426 case WXK_NUMPAD_DELETE
:
1427 hotkey
<< wxT("KP_Delete" );
1429 case WXK_NUMPAD_SPACE
:
1430 hotkey
<< wxT("KP_Space" );
1432 case WXK_NUMPAD_TAB
:
1433 hotkey
<< wxT("KP_Tab" );
1435 case WXK_NUMPAD_ENTER
:
1436 hotkey
<< wxT("KP_Enter" );
1438 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1440 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1442 case WXK_NUMPAD_HOME
:
1443 hotkey
<< wxT("KP_Home" );
1445 case WXK_NUMPAD_LEFT
:
1446 hotkey
<< wxT("KP_Left" );
1449 hotkey
<< wxT("KP_Up" );
1451 case WXK_NUMPAD_RIGHT
:
1452 hotkey
<< wxT("KP_Right" );
1454 case WXK_NUMPAD_DOWN
:
1455 hotkey
<< wxT("KP_Down" );
1457 case WXK_NUMPAD_PAGEUP
:
1458 hotkey
<< wxT("KP_Page_Up" );
1460 case WXK_NUMPAD_PAGEDOWN
:
1461 hotkey
<< wxT("KP_Page_Down" );
1463 case WXK_NUMPAD_END
:
1464 hotkey
<< wxT("KP_End" );
1466 case WXK_NUMPAD_BEGIN
:
1467 hotkey
<< wxT("KP_Begin" );
1469 case WXK_NUMPAD_EQUAL
:
1470 hotkey
<< wxT("KP_Equal" );
1472 case WXK_NUMPAD_MULTIPLY
:
1473 hotkey
<< wxT("KP_Multiply" );
1475 case WXK_NUMPAD_ADD
:
1476 hotkey
<< wxT("KP_Add" );
1478 case WXK_NUMPAD_SEPARATOR
:
1479 hotkey
<< wxT("KP_Separator" );
1481 case WXK_NUMPAD_SUBTRACT
:
1482 hotkey
<< wxT("KP_Subtract" );
1484 case WXK_NUMPAD_DECIMAL
:
1485 hotkey
<< wxT("KP_Decimal" );
1487 case WXK_NUMPAD_DIVIDE
:
1488 hotkey
<< wxT("KP_Divide" );
1490 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1491 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1492 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1493 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1495 case WXK_WINDOWS_LEFT
:
1496 hotkey
<< wxT("Super_L" );
1498 case WXK_WINDOWS_RIGHT
:
1499 hotkey
<< wxT("Super_R" );
1501 case WXK_WINDOWS_MENU
:
1502 hotkey
<< wxT("Menu" );
1505 hotkey
<< wxT("Command" );
1507 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1508 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1509 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1510 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1511 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1512 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1513 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1516 // if there are any other keys wxAcceleratorEntry::Create() may
1517 // return, we should process them here
1523 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1524 if ( !name
.empty() )
1531 wxFAIL_MSG( wxT("unknown keyboard accel") );
1540 #endif // wxUSE_ACCEL
1542 // ----------------------------------------------------------------------------
1543 // Pop-up menu stuff
1544 // ----------------------------------------------------------------------------
1546 #if wxUSE_MENUS_NATIVE
1548 extern "C" WXDLLIMPEXP_CORE
1549 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1551 *is_waiting
= false;
1554 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1556 menu
->SetInvokingWindow( win
);
1558 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1561 wxMenuItem
*menuitem
= node
->GetData();
1562 if (menuitem
->IsSubMenu())
1564 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1567 node
= node
->GetNext();
1571 extern "C" WXDLLIMPEXP_CORE
1572 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1574 gboolean
* WXUNUSED(whatever
),
1575 gpointer user_data
)
1577 // ensure that the menu appears entirely on screen
1579 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1581 wxSize sizeScreen
= wxGetDisplaySize();
1582 wxPoint
*pos
= (wxPoint
*)user_data
;
1584 gint xmax
= sizeScreen
.x
- req
.width
,
1585 ymax
= sizeScreen
.y
- req
.height
;
1587 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1588 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1591 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1593 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1595 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1597 // NOTE: if you change this code, you need to update
1598 // the same code in taskbar.cpp as well. This
1599 // is ugly code duplication, I know.
1601 SetInvokingWindow( menu
, this );
1605 bool is_waiting
= true;
1607 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1608 G_CALLBACK (gtk_pop_hide_callback
),
1613 GtkMenuPositionFunc posfunc
;
1614 if ( x
== -1 && y
== -1 )
1616 // use GTK's default positioning algorithm
1622 pos
= ClientToScreen(wxPoint(x
, y
));
1624 posfunc
= wxPopupMenuPositionCallback
;
1627 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1628 DoCommonMenuCallbackCode(menu
, eventOpen
);
1631 GTK_MENU(menu
->m_menu
),
1632 (GtkWidget
*) NULL
, // parent menu shell
1633 (GtkWidget
*) NULL
, // parent menu item
1634 posfunc
, // function to position it
1635 userdata
, // client data
1636 0, // button used to activate it
1637 gtk_get_current_event_time()
1642 gtk_main_iteration();
1645 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1647 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1648 DoCommonMenuCallbackCode(menu
, eventClose
);
1653 #endif // wxUSE_MENUS_NATIVE
1655 #include <gtk/gtk.h>
1657 const char *wxGetStockGtkID(wxWindowID id
)
1659 #define STOCKITEM(wx,gtk) \
1663 #define STOCKITEM_MISSING(wx) \
1667 #if GTK_CHECK_VERSION(2,4,0)
1668 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1670 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1673 #if GTK_CHECK_VERSION(2,6,0)
1674 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1676 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1679 #if GTK_CHECK_VERSION(2,10,0)
1680 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1682 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1688 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1689 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1690 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1691 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1692 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1693 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1694 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1695 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1696 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1697 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1698 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1699 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1700 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1701 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1702 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1703 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1704 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1705 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1706 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1707 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1708 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1709 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1710 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1711 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1712 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1713 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1714 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1715 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1716 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1717 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1718 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1719 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1720 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1721 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1722 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1723 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1724 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1725 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1726 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1727 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1728 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1729 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1730 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1731 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1732 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1733 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1734 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1735 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1736 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1737 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1738 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1739 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1740 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1741 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1744 wxFAIL_MSG( _T("invalid stock item ID") );
1755 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1760 GtkStockItem stock_item
;
1761 if (gtk_stock_lookup (id
, &stock_item
))
1763 if (key
) *key
= stock_item
.keyval
;
1764 if (mod
) *mod
= stock_item
.modifier
;
1766 // some GTK stock items have zero values for the keyval;
1767 // it means that they do not have an accelerator...
1768 if (stock_item
.keyval
)
1774 #endif // wxUSE_ACCEL
1776 #endif // wxUSE_MENUS