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()
159 wxMenubarUnsetInvokingWindow(wxMenu
* menu
, wxWindow
* win
, GtkWindow
* tlw
= NULL
)
161 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
163 // support for native hot keys
167 tlw
= GTK_WINDOW(wxGetTopLevelParent(win
)->m_widget
);
168 if (g_slist_find(menu
->m_accel
->acceleratables
, tlw
))
169 gtk_window_remove_accel_group(tlw
, menu
->m_accel
);
172 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
175 wxMenuItem
*menuitem
= node
->GetData();
176 if (menuitem
->IsSubMenu())
177 wxMenubarUnsetInvokingWindow(menuitem
->GetSubMenu(), win
, tlw
);
178 node
= node
->GetNext();
183 wxMenubarSetInvokingWindow(wxMenu
* menu
, wxWindow
* win
, GtkWindow
* tlw
= NULL
)
185 menu
->SetInvokingWindow( win
);
187 // support for native hot keys
191 tlw
= GTK_WINDOW(wxGetTopLevelParent(win
)->m_widget
);
192 if (!g_slist_find(menu
->m_accel
->acceleratables
, tlw
))
193 gtk_window_add_accel_group(tlw
, menu
->m_accel
);
196 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
199 wxMenuItem
*menuitem
= node
->GetData();
200 if (menuitem
->IsSubMenu())
201 wxMenubarSetInvokingWindow(menuitem
->GetSubMenu(), win
, tlw
);
202 node
= node
->GetNext();
206 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
208 m_invokingWindow
= win
;
210 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
213 wxMenu
*menu
= node
->GetData();
214 wxMenubarSetInvokingWindow( menu
, win
);
215 node
= node
->GetNext();
219 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
221 if ( dir
== wxLayout_Default
)
223 const wxWindow
*const frame
= GetFrame();
226 // inherit layout from frame.
227 dir
= frame
->GetLayoutDirection();
229 else // use global layout
231 dir
= wxTheApp
->GetLayoutDirection();
235 if ( dir
== wxLayout_Default
)
238 GTKSetLayout(m_menubar
, dir
);
240 // also set the layout of all menus we already have (new ones will inherit
241 // the current layout)
242 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
244 node
= node
->GetNext() )
246 wxMenu
*const menu
= node
->GetData();
247 menu
->SetLayoutDirection(dir
);
251 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
253 return GTKGetLayout(m_menubar
);
256 void wxMenuBar::Attach(wxFrame
*frame
)
258 wxMenuBarBase::Attach(frame
);
260 SetLayoutDirection(wxLayout_Default
);
263 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
265 m_invokingWindow
= (wxWindow
*) NULL
;
267 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
270 wxMenu
*menu
= node
->GetData();
271 wxMenubarUnsetInvokingWindow( menu
, win
);
272 node
= node
->GetNext();
276 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
278 if ( !wxMenuBarBase::Append( menu
, title
) )
281 return GtkAppend(menu
, title
);
284 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
286 menu
->SetLayoutDirection(GetLayoutDirection());
289 // if the menu has only one item, append it directly to the top level menu
290 // instead of inserting a useless submenu
291 if ( menu
->GetMenuItemCount() == 1 )
293 wxMenuItem
* const item
= menu
->FindItemByPosition(0);
295 // remove both mnemonics and accelerator: neither is useful under Maemo
296 const wxString
str(wxStripMenuCodes(item
->GetItemLabel()));
298 if ( item
->IsSubMenu() )
299 return GtkAppend(item
->GetSubMenu(), str
, pos
);
301 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
303 g_signal_connect(menu
->m_owner
, "activate",
304 G_CALLBACK(gtk_menu_clicked_callback
), menu
);
305 item
->SetMenuItem(menu
->m_owner
);
308 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
310 const wxString
str(wxConvertMnemonicsToGTK(title
));
312 // This doesn't have much effect right now.
313 menu
->SetTitle( str
);
315 // The "m_owner" is the "menu item"
316 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
318 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
321 gtk_widget_show( menu
->m_owner
);
324 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
326 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
328 g_signal_connect (menu
->m_owner
, "activate",
329 G_CALLBACK (gtk_menu_open_callback
),
332 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
333 // addings menu later on.
334 if (m_invokingWindow
)
335 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
340 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
342 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
347 if ( !GtkAppend(menu
, title
, (int)pos
) )
353 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
355 // remove the old item and insert a new one
356 wxMenu
*menuOld
= Remove(pos
);
357 if ( menuOld
&& !Insert(pos
, menu
, title
) )
359 return (wxMenu
*) NULL
;
362 // either Insert() succeeded or Remove() failed and menuOld is NULL
366 wxMenu
*wxMenuBar::Remove(size_t pos
)
368 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
370 return (wxMenu
*) NULL
;
372 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu
->m_owner
), NULL
);
373 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
375 gtk_widget_destroy( menu
->m_owner
);
376 menu
->m_owner
= NULL
;
378 if (m_invokingWindow
)
379 wxMenubarUnsetInvokingWindow( menu
, m_invokingWindow
);
384 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
386 if (wxMenuItem::GetLabelText(wxConvertMnemonicsFromGTK(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
388 int res
= menu
->FindItem( itemString
);
389 if (res
!= wxNOT_FOUND
)
393 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
396 wxMenuItem
*item
= node
->GetData();
397 if (item
->IsSubMenu())
398 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
400 node
= node
->GetNext();
406 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
408 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
411 wxMenu
*menu
= node
->GetData();
412 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
415 node
= node
->GetNext();
421 // Find a wxMenuItem using its id. Recurses down into sub-menus
422 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
424 wxMenuItem
* result
= menu
->FindChildItem(id
);
426 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
427 while ( node
&& result
== NULL
)
429 wxMenuItem
*item
= node
->GetData();
430 if (item
->IsSubMenu())
432 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
434 node
= node
->GetNext();
440 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
442 wxMenuItem
* result
= 0;
443 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
444 while (node
&& result
== 0)
446 wxMenu
*menu
= node
->GetData();
447 result
= FindMenuItemByIdRecursive( menu
, id
);
448 node
= node
->GetNext();
453 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
459 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
461 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
463 wxCHECK_RET( node
, wxT("menu not found") );
465 wxMenu
* menu
= node
->GetData();
468 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
471 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
473 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
475 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
477 wxMenu
* menu
= node
->GetData();
479 return wxConvertMnemonicsFromGTK(menu
->GetTitle());
482 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
484 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
486 wxCHECK_RET( node
, wxT("menu not found") );
488 wxMenu
* menu
= node
->GetData();
490 const wxString
str(wxConvertMnemonicsToGTK(label
));
492 menu
->SetTitle( str
);
495 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
498 //-----------------------------------------------------------------------------
500 //-----------------------------------------------------------------------------
503 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
505 int id
= menu
->FindMenuIdByMenuItem(widget
);
507 /* should find it for normal (not popup) menu */
508 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
509 _T("menu item not found in gtk_menu_clicked_callback") );
511 if (!menu
->IsEnabled(id
))
514 wxMenuItem
* item
= menu
->FindChildItem( id
);
515 wxCHECK_RET( item
, wxT("error in menu item callback") );
517 if ( item
->GetId() == wxGTK_TITLE_ID
)
519 // ignore events from the menu title
523 if (item
->IsCheckable())
525 bool isReallyChecked
= item
->IsChecked(),
526 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
528 // ensure that the internal state is always consistent with what is
529 // shown on the screen
530 item
->wxMenuItemBase::Check(isReallyChecked
);
532 // we must not report the events for the radio button going up nor the
533 // events resulting from the calls to wxMenuItem::Check()
534 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
535 (isInternallyChecked
== isReallyChecked
) )
542 // Is this menu on a menubar? (possibly nested)
543 wxFrame
* frame
= NULL
;
544 if(menu
->IsAttached())
545 frame
= menu
->GetMenuBar()->GetFrame();
547 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
548 // normally wxMenu::SendEvent() should be enough, if it doesn't work
549 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
550 // should be fixed instead of working around it here...
553 // If it is attached then let the frame send the event.
554 // Don't call frame->ProcessCommand(id) because it toggles
555 // checkable items and we've already done that above.
556 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
557 commandEvent
.SetEventObject(frame
);
558 if (item
->IsCheckable())
559 commandEvent
.SetInt(item
->IsChecked());
561 frame
->HandleWindowEvent(commandEvent
);
565 // otherwise let the menu have it
566 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
571 //-----------------------------------------------------------------------------
573 //-----------------------------------------------------------------------------
576 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
578 int id
= menu
->FindMenuIdByMenuItem(widget
);
580 wxASSERT( id
!= -1 ); // should find it!
582 if (!menu
->IsEnabled(id
))
585 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
586 event
.SetEventObject( menu
);
588 wxEvtHandler
* handler
= menu
->GetEventHandler();
589 if (handler
&& handler
->SafelyProcessEvent(event
))
592 wxWindow
*win
= menu
->GetInvokingWindow();
593 if (win
) win
->HandleWindowEvent( event
);
597 //-----------------------------------------------------------------------------
599 //-----------------------------------------------------------------------------
602 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
604 int id
= menu
->FindMenuIdByMenuItem(widget
);
606 wxASSERT( id
!= -1 ); // should find it!
608 if (!menu
->IsEnabled(id
))
611 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
612 event
.SetEventObject( menu
);
614 wxEvtHandler
* handler
= menu
->GetEventHandler();
615 if (handler
&& handler
->SafelyProcessEvent(event
))
618 wxWindow
*win
= menu
->GetInvokingWindow();
620 win
->HandleWindowEvent( event
);
624 //-----------------------------------------------------------------------------
626 //-----------------------------------------------------------------------------
628 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
630 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
632 const wxString
& name
,
633 const wxString
& help
,
637 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
640 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
642 const wxString
& text
,
643 const wxString
& help
,
646 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
651 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
653 const wxString
& text
,
654 const wxString
& help
,
657 : wxMenuItemBase(parentMenu
, id
, text
, help
,
658 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
663 void wxMenuItem::Init(const wxString
& text
)
665 m_labelWidget
= (GtkWidget
*) NULL
;
666 m_menuItem
= (GtkWidget
*) NULL
;
671 wxMenuItem::~wxMenuItem()
673 // don't delete menu items, the menus take care of that
676 // return the menu item text without any menu accels
679 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
681 // The argument to this function will now always be in wxWidgets standard label
682 // format, not GTK+ format, so we do what the other ports do.
684 return wxStripMenuCodes(text
);
689 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
691 if ( *pc
== wxT('\t'))
694 if ( *pc
== wxT('_') )
696 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
702 if ( *pc
== wxT('\\') )
704 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
710 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
713 // "&" is doubled to indicate "&" instead of accelerator
720 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
726 wxString
wxMenuItem::GetItemLabel() const
728 wxString label
= wxConvertMnemonicsFromGTK(m_text
);
729 if (!m_hotKey
.IsEmpty())
730 label
<< "\t" << m_hotKey
;
734 void wxMenuItem::SetItemLabel( const wxString
& str
)
736 // cache some data which must be used later
737 bool isstock
= wxIsStockID(GetId());
738 const char *stockid
= NULL
;
740 stockid
= wxGetStockGtkID(GetId());
742 // Some optimization to avoid flicker
743 wxString oldLabel
= m_text
;
744 oldLabel
= wxStripMenuCodes(oldLabel
);
745 oldLabel
.Replace(wxT("_"), wxT(""));
746 wxString label1
= wxStripMenuCodes(str
);
748 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
749 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
750 #endif // wxUSE_ACCEL
755 if (oldLabel
== label1
&&
756 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
763 label
= (GtkLabel
*) m_labelWidget
;
765 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
767 // stock menu items can have empty labels:
768 wxString text
= m_text
;
769 if (text
.IsEmpty() && !IsSeparator())
771 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
772 text
= wxGetStockLabel(GetId());
774 // need & => _ conversion
775 text
= GTKProcessMenuItemLabel(text
, NULL
);
778 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
781 // remove old accelerator from our parent's accelerator group, if present
783 GdkModifierType accel_mods
;
784 if (oldbuf
[(size_t)0] != '\0')
786 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
789 gtk_widget_remove_accelerator(m_menuItem
,
790 m_parentMenu
->m_accel
,
797 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
798 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
799 gtk_widget_remove_accelerator( m_menuItem
,
800 m_parentMenu
->m_accel
,
805 // add new accelerator to our parent's accelerator group
806 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
807 if (buf
[(size_t)0] != '\0')
809 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
812 gtk_widget_add_accelerator( m_menuItem
,
814 m_parentMenu
->m_accel
,
822 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
823 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
824 gtk_widget_remove_accelerator( m_menuItem
,
825 m_parentMenu
->m_accel
,
829 #endif // wxUSE_ACCEL
832 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
833 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
834 // so there's no real code duplication
835 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
839 // '\t' is the deliminator indicating a hot key
840 wxString::const_iterator pc
= str
.begin();
841 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
845 wxString::const_iterator next
= pc
+ 1;
846 if (next
!= str
.end() && *next
== wxT('&'))
848 // "&" is doubled to indicate "&" instead of accelerator
857 else if ( *pc
== wxT('_') ) // escape underscores
874 hotKey
->assign(pc
, str
.end());
881 // it's valid for this function to be called even if m_menuItem == NULL
882 void wxMenuItem::DoSetText( const wxString
& str
)
885 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
890 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
898 // accelerator parsing code looks for them after a TAB, so insert a dummy
901 label
<< wxT('\t') << GetHotKey();
903 return wxAcceleratorEntry::Create(label
);
906 #endif // wxUSE_ACCEL
908 void wxMenuItem::Check( bool check
)
910 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
912 if (check
== m_isChecked
)
915 wxMenuItemBase::Check( check
);
921 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
925 wxFAIL_MSG( _T("can't check this item") );
929 void wxMenuItem::Enable( bool enable
)
931 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
933 gtk_widget_set_sensitive( m_menuItem
, enable
);
934 wxMenuItemBase::Enable( enable
);
937 bool wxMenuItem::IsChecked() const
939 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
941 wxCHECK_MSG( IsCheckable(), false,
942 wxT("can't get state of uncheckable item!") );
944 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
947 //-----------------------------------------------------------------------------
949 //-----------------------------------------------------------------------------
951 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
955 m_accel
= gtk_accel_group_new();
956 m_menu
= gtk_menu_new();
957 // NB: keep reference to the menu so that it is not destroyed behind
958 // our back by GTK+ e.g. when it is removed from menubar:
959 g_object_ref(m_menu
);
960 gtk_object_sink(GTK_OBJECT(m_menu
));
962 m_owner
= (GtkWidget
*) NULL
;
964 // Tearoffs are entries, just like separators. So if we want this
965 // menu to be a tear-off one, we just append a tearoff entry
967 if ( m_style
& wxMENU_TEAROFF
)
969 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
971 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
976 // append the title as the very first entry if we have it
977 if ( !m_title
.empty() )
979 Append(wxGTK_TITLE_ID
, m_title
);
986 if ( GTK_IS_WIDGET( m_menu
))
989 g_object_unref(m_menu
);
991 // if the menu is inserted in another menu at this time, there was
992 // one more reference to it:
994 gtk_widget_destroy( m_menu
);
996 g_object_unref(m_accel
);
1000 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1003 wxWindow::GTKSetLayout(m_owner
, dir
);
1004 //else: will be called later by wxMenuBar again
1007 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1009 return wxWindow::GTKGetLayout(m_owner
);
1012 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1014 GtkWidget
*menuItem
;
1016 // cache some data used later
1017 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1018 int id
= mitem
->GetId();
1019 bool isstock
= wxIsStockID(id
);
1020 const char *stockid
= NULL
;
1022 stockid
= wxGetStockGtkID(mitem
->GetId());
1024 // stock menu items can have an empty label
1025 if (text
.IsEmpty() && !mitem
->IsSeparator())
1027 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1028 text
= wxGetStockLabel(id
);
1030 // need & => _ conversion
1031 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1034 if ( mitem
->IsSeparator() )
1036 menuItem
= gtk_separator_menu_item_new();
1039 else if ( mitem
->GetBitmap().Ok() ||
1040 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1042 wxBitmap
bitmap(mitem
->GetBitmap());
1044 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1049 // use stock bitmap for this item if available on the assumption
1050 // that it never hurts to follow GTK+ conventions more closely
1051 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1054 else // we have a custom bitmap
1056 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1057 _T("only normal menu items can have bitmaps") );
1059 if ( bitmap
.HasPixbuf() )
1061 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1065 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1066 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1067 bitmap
.GetMask()->GetBitmap() :
1069 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1075 gtk_widget_show(image
);
1077 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1082 else // a normal item
1084 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1087 switch ( mitem
->GetKind() )
1091 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1098 GSList
*group
= NULL
;
1099 if ( m_prevRadio
== NULL
)
1101 // start of a new radio group
1102 m_prevRadio
= menuItem
=
1103 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1105 else // continue the radio group
1107 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1108 m_prevRadio
= menuItem
=
1109 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1115 wxFAIL_MSG( _T("unexpected menu item kind") );
1120 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1130 GdkModifierType accel_mods
;
1131 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1133 if (buf
[(size_t)0] != '\0')
1135 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1138 gtk_widget_add_accelerator (menuItem
,
1148 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1149 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1150 gtk_widget_add_accelerator( menuItem
,
1157 #endif // wxUSE_ACCEL
1160 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1162 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1164 gtk_widget_show( menuItem
);
1166 if ( !mitem
->IsSeparator() )
1168 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1170 g_signal_connect (menuItem
, "select",
1171 G_CALLBACK (gtk_menu_hilight_callback
), this);
1172 g_signal_connect (menuItem
, "deselect",
1173 G_CALLBACK (gtk_menu_nolight_callback
), this);
1175 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1177 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1179 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1181 // if adding a submenu to a menu already existing in the menu bar, we
1182 // must set invoking window to allow processing events from this
1184 if ( m_invokingWindow
)
1185 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1189 g_signal_connect (menuItem
, "activate",
1190 G_CALLBACK (gtk_menu_clicked_callback
),
1195 mitem
->SetMenuItem(menuItem
);
1199 // This doesn't even exist!
1200 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1206 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1208 if (!GtkAppend(mitem
))
1211 return wxMenuBase::DoAppend(mitem
);
1214 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1216 if ( !wxMenuBase::DoInsert(pos
, item
) )
1220 if ( !GtkAppend(item
, (int)pos
) )
1226 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1228 if ( !wxMenuBase::DoRemove(item
) )
1231 GtkWidget
* const mitem
= item
->GetMenuItem();
1232 if ( m_prevRadio
== mitem
)
1234 // deleting an item starts a new radio group (has to as we shouldn't
1235 // keep a deleted pointer anyhow)
1239 // TODO: this code doesn't delete the item factory item and this seems
1240 // impossible as of GTK 1.2.6.
1241 gtk_widget_destroy( mitem
);
1246 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1248 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1251 wxMenuItem
*item
= node
->GetData();
1252 if (item
->GetMenuItem() == menuItem
)
1253 return item
->GetId();
1254 node
= node
->GetNext();
1260 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1262 wxMenuBase::Attach(menubar
);
1264 // inherit layout direction from menubar.
1265 SetLayoutDirection(menubar
->GetLayoutDirection());
1268 // ----------------------------------------------------------------------------
1270 // ----------------------------------------------------------------------------
1274 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1278 wxAcceleratorEntry
*accel
= item
.GetAccel();
1281 int flags
= accel
->GetFlags();
1282 if ( flags
& wxACCEL_ALT
)
1283 hotkey
+= wxT("<alt>");
1284 if ( flags
& wxACCEL_CTRL
)
1285 hotkey
+= wxT("<control>");
1286 if ( flags
& wxACCEL_SHIFT
)
1287 hotkey
+= wxT("<shift>");
1289 int code
= accel
->GetKeyCode();
1316 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1319 // TODO: we should use gdk_keyval_name() (a.k.a.
1320 // XKeysymToString) here as well as hardcoding the keysym
1321 // names this might be not portable
1323 hotkey
<< wxT("Insert" );
1326 hotkey
<< wxT("Delete" );
1329 hotkey
<< wxT("Up" );
1332 hotkey
<< wxT("Down" );
1335 hotkey
<< wxT("Page_Up" );
1338 hotkey
<< wxT("Page_Down" );
1341 hotkey
<< wxT("Left" );
1344 hotkey
<< wxT("Right" );
1347 hotkey
<< wxT("Home" );
1350 hotkey
<< wxT("End" );
1353 hotkey
<< wxT("Return" );
1356 hotkey
<< wxT("BackSpace" );
1359 hotkey
<< wxT("Tab" );
1362 hotkey
<< wxT("Esc" );
1365 hotkey
<< wxT("space" );
1368 hotkey
<< wxT("Multiply" );
1371 hotkey
<< wxT("Add" );
1374 hotkey
<< wxT("Separator" );
1377 hotkey
<< wxT("Subtract" );
1380 hotkey
<< wxT("Decimal" );
1383 hotkey
<< wxT("Divide" );
1386 hotkey
<< wxT("Cancel" );
1389 hotkey
<< wxT("Clear" );
1392 hotkey
<< wxT("Menu" );
1395 hotkey
<< wxT("Pause" );
1398 hotkey
<< wxT("Capital" );
1401 hotkey
<< wxT("Select" );
1404 hotkey
<< wxT("Print" );
1407 hotkey
<< wxT("Execute" );
1410 hotkey
<< wxT("Snapshot" );
1413 hotkey
<< wxT("Help" );
1416 hotkey
<< wxT("Num_Lock" );
1419 hotkey
<< wxT("Scroll_Lock" );
1421 case WXK_NUMPAD_INSERT
:
1422 hotkey
<< wxT("KP_Insert" );
1424 case WXK_NUMPAD_DELETE
:
1425 hotkey
<< wxT("KP_Delete" );
1427 case WXK_NUMPAD_SPACE
:
1428 hotkey
<< wxT("KP_Space" );
1430 case WXK_NUMPAD_TAB
:
1431 hotkey
<< wxT("KP_Tab" );
1433 case WXK_NUMPAD_ENTER
:
1434 hotkey
<< wxT("KP_Enter" );
1436 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1438 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1440 case WXK_NUMPAD_HOME
:
1441 hotkey
<< wxT("KP_Home" );
1443 case WXK_NUMPAD_LEFT
:
1444 hotkey
<< wxT("KP_Left" );
1447 hotkey
<< wxT("KP_Up" );
1449 case WXK_NUMPAD_RIGHT
:
1450 hotkey
<< wxT("KP_Right" );
1452 case WXK_NUMPAD_DOWN
:
1453 hotkey
<< wxT("KP_Down" );
1455 case WXK_NUMPAD_PAGEUP
:
1456 hotkey
<< wxT("KP_Page_Up" );
1458 case WXK_NUMPAD_PAGEDOWN
:
1459 hotkey
<< wxT("KP_Page_Down" );
1461 case WXK_NUMPAD_END
:
1462 hotkey
<< wxT("KP_End" );
1464 case WXK_NUMPAD_BEGIN
:
1465 hotkey
<< wxT("KP_Begin" );
1467 case WXK_NUMPAD_EQUAL
:
1468 hotkey
<< wxT("KP_Equal" );
1470 case WXK_NUMPAD_MULTIPLY
:
1471 hotkey
<< wxT("KP_Multiply" );
1473 case WXK_NUMPAD_ADD
:
1474 hotkey
<< wxT("KP_Add" );
1476 case WXK_NUMPAD_SEPARATOR
:
1477 hotkey
<< wxT("KP_Separator" );
1479 case WXK_NUMPAD_SUBTRACT
:
1480 hotkey
<< wxT("KP_Subtract" );
1482 case WXK_NUMPAD_DECIMAL
:
1483 hotkey
<< wxT("KP_Decimal" );
1485 case WXK_NUMPAD_DIVIDE
:
1486 hotkey
<< wxT("KP_Divide" );
1488 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1489 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1490 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1491 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1493 case WXK_WINDOWS_LEFT
:
1494 hotkey
<< wxT("Super_L" );
1496 case WXK_WINDOWS_RIGHT
:
1497 hotkey
<< wxT("Super_R" );
1499 case WXK_WINDOWS_MENU
:
1500 hotkey
<< wxT("Menu" );
1503 hotkey
<< wxT("Command" );
1505 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1506 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1507 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1508 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1509 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1510 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1511 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1514 // if there are any other keys wxAcceleratorEntry::Create() may
1515 // return, we should process them here
1521 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1522 if ( !name
.empty() )
1529 wxFAIL_MSG( wxT("unknown keyboard accel") );
1538 #endif // wxUSE_ACCEL
1540 // ----------------------------------------------------------------------------
1541 // Pop-up menu stuff
1542 // ----------------------------------------------------------------------------
1544 #if wxUSE_MENUS_NATIVE
1546 extern "C" WXDLLIMPEXP_CORE
1547 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1549 *is_waiting
= false;
1552 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1554 menu
->SetInvokingWindow( win
);
1556 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1559 wxMenuItem
*menuitem
= node
->GetData();
1560 if (menuitem
->IsSubMenu())
1562 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1565 node
= node
->GetNext();
1569 extern "C" WXDLLIMPEXP_CORE
1570 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1572 gboolean
* WXUNUSED(whatever
),
1573 gpointer user_data
)
1575 // ensure that the menu appears entirely on screen
1577 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1579 wxSize sizeScreen
= wxGetDisplaySize();
1580 wxPoint
*pos
= (wxPoint
*)user_data
;
1582 gint xmax
= sizeScreen
.x
- req
.width
,
1583 ymax
= sizeScreen
.y
- req
.height
;
1585 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1586 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1589 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1591 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1593 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1595 // NOTE: if you change this code, you need to update
1596 // the same code in taskbar.cpp as well. This
1597 // is ugly code duplication, I know.
1599 SetInvokingWindow( menu
, this );
1603 bool is_waiting
= true;
1605 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1606 G_CALLBACK (gtk_pop_hide_callback
),
1611 GtkMenuPositionFunc posfunc
;
1612 if ( x
== -1 && y
== -1 )
1614 // use GTK's default positioning algorithm
1620 pos
= ClientToScreen(wxPoint(x
, y
));
1622 posfunc
= wxPopupMenuPositionCallback
;
1625 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1626 DoCommonMenuCallbackCode(menu
, eventOpen
);
1629 GTK_MENU(menu
->m_menu
),
1630 (GtkWidget
*) NULL
, // parent menu shell
1631 (GtkWidget
*) NULL
, // parent menu item
1632 posfunc
, // function to position it
1633 userdata
, // client data
1634 0, // button used to activate it
1635 gtk_get_current_event_time()
1640 gtk_main_iteration();
1643 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1645 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1646 DoCommonMenuCallbackCode(menu
, eventClose
);
1651 #endif // wxUSE_MENUS_NATIVE
1653 #include <gtk/gtk.h>
1655 const char *wxGetStockGtkID(wxWindowID id
)
1657 #define STOCKITEM(wx,gtk) \
1661 #define STOCKITEM_MISSING(wx) \
1665 #if GTK_CHECK_VERSION(2,4,0)
1666 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1668 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1671 #if GTK_CHECK_VERSION(2,6,0)
1672 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1674 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1677 #if GTK_CHECK_VERSION(2,10,0)
1678 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1680 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1686 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1687 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1688 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1689 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1690 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1691 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1692 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1693 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1694 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1695 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1696 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1697 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1698 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1699 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1700 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1701 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1702 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1703 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1704 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1705 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1706 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1707 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1708 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1709 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1710 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1711 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1712 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1713 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1714 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1715 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1716 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1717 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1718 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1719 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1720 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1721 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1722 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1723 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1724 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1725 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1726 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1727 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1728 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1729 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1730 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1731 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1732 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1733 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1734 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1735 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1736 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1737 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1738 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1739 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1742 wxFAIL_MSG( _T("invalid stock item ID") );
1753 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1758 GtkStockItem stock_item
;
1759 if (gtk_stock_lookup (id
, &stock_item
))
1761 if (key
) *key
= stock_item
.keyval
;
1762 if (mod
) *mod
= stock_item
.modifier
;
1764 // some GTK stock items have zero values for the keyval;
1765 // it means that they do not have an accelerator...
1766 if (stock_item
.keyval
)
1772 #endif // wxUSE_ACCEL
1774 #endif // wxUSE_MENUS