1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/menu.cpp
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"
19 #include "wx/bitmap.h"
24 #include "wx/stockitem.h"
25 #include "wx/gtk/private.h"
28 #include <gdk/gdktypes.h>
31 // FIXME: is this right? somehow I don't think so (VZ)
33 #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
34 //#define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
35 //#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
37 #define ACCEL_OBJECT GtkWindow
38 #define ACCEL_OBJECTS(a) (a)->acceleratables
39 #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
41 // we use normal item but with a special id for the menu title
42 static const int wxGTK_TITLE_ID
= -3;
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
49 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
52 //-----------------------------------------------------------------------------
54 //-----------------------------------------------------------------------------
56 static wxString
wxReplaceUnderscore( const wxString
& title
)
58 // GTK 1.2 wants to have "_" instead of "&" for accelerators
61 for ( wxString::const_iterator pc
= title
.begin(); pc
!= title
.end(); ++pc
)
63 if ((*pc
== wxT('&')) && (pc
+1 != title
.end()) && (*(pc
+1) == wxT('&')))
65 // "&" is doubled to indicate "&" instead of accelerator
69 else if (*pc
== wxT('&'))
75 if ( *pc
== wxT('_') )
77 // underscores must be doubled to prevent them from being
78 // interpreted as accelerator character prefix by GTK
86 // wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() );
91 //-----------------------------------------------------------------------------
92 // activate message from GTK
93 //-----------------------------------------------------------------------------
95 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
97 event
.SetEventObject( menu
);
99 wxEvtHandler
* handler
= menu
->GetEventHandler();
100 if (handler
&& handler
->ProcessEvent(event
))
103 wxWindow
*win
= menu
->GetInvokingWindow();
105 win
->GetEventHandler()->ProcessEvent( event
);
110 static void gtk_menu_open_callback( GtkWidget
*widget
, wxMenu
*menu
)
112 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
114 DoCommonMenuCallbackCode(menu
, event
);
117 static void gtk_menu_close_callback( GtkWidget
*widget
, wxMenuBar
*menubar
)
119 if ( !menubar
->GetMenuCount() )
121 // if menubar is empty we can't call GetMenu(0) below
125 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
127 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
132 //-----------------------------------------------------------------------------
134 //-----------------------------------------------------------------------------
136 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
138 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
141 m_invokingWindow
= NULL
;
143 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
144 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
146 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
150 m_menubar
= gtk_menu_bar_new();
152 if (style
& wxMB_DOCKABLE
)
154 m_widget
= gtk_handle_box_new();
155 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
156 gtk_widget_show(m_menubar
);
160 m_widget
= m_menubar
;
167 for (size_t i
= 0; i
< n
; ++i
)
168 Append(menus
[i
], titles
[i
]);
170 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
171 // don't get it when the menu is dismissed by clicking outside the
172 // toolbar) so we connect to the global one, even if it means that we
173 // can't pass the menu which was closed in wxMenuEvent object
174 g_signal_connect (m_menubar
, "deactivate",
175 G_CALLBACK (gtk_menu_close_callback
), this);
179 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
181 Init(n
, menus
, titles
, style
);
184 wxMenuBar::wxMenuBar(long style
)
186 Init(0, NULL
, NULL
, style
);
189 wxMenuBar::wxMenuBar()
191 Init(0, NULL
, NULL
, 0);
194 wxMenuBar::~wxMenuBar()
198 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
200 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
202 wxWindow
*top_frame
= win
;
203 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
204 top_frame
= top_frame
->GetParent();
206 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
209 wxMenuItem
*menuitem
= node
->GetData();
210 if (menuitem
->IsSubMenu())
211 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
212 node
= node
->GetNext();
216 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
218 menu
->SetInvokingWindow( win
);
220 wxWindow
*top_frame
= win
;
221 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
222 top_frame
= top_frame
->GetParent();
224 // support for native hot keys
225 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
226 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
227 gtk_accel_group_attach( menu
->m_accel
, obj
);
229 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
232 wxMenuItem
*menuitem
= node
->GetData();
233 if (menuitem
->IsSubMenu())
234 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
235 node
= node
->GetNext();
239 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
241 m_invokingWindow
= win
;
242 wxWindow
*top_frame
= win
;
243 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
244 top_frame
= top_frame
->GetParent();
246 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
249 wxMenu
*menu
= node
->GetData();
250 wxMenubarSetInvokingWindow( menu
, win
);
251 node
= node
->GetNext();
255 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
257 if ( dir
== wxLayout_Default
)
259 const wxWindow
*const frame
= GetFrame();
262 // inherit layout from frame.
263 dir
= frame
->GetLayoutDirection();
265 else // use global layout
267 dir
= wxTheApp
->GetLayoutDirection();
271 if ( dir
== wxLayout_Default
)
274 GTKSetLayout(m_menubar
, dir
);
276 // also set the layout of all menus we already have (new ones will inherit
277 // the current layout)
278 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
280 node
= node
->GetNext() )
282 wxMenu
*const menu
= node
->GetData();
283 menu
->SetLayoutDirection(dir
);
287 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
289 return GTKGetLayout(m_menubar
);
292 void wxMenuBar::Attach(wxFrame
*frame
)
294 wxMenuBarBase::Attach(frame
);
296 SetLayoutDirection(wxLayout_Default
);
299 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
301 m_invokingWindow
= (wxWindow
*) NULL
;
302 wxWindow
*top_frame
= win
;
303 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
304 top_frame
= top_frame
->GetParent();
306 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
309 wxMenu
*menu
= node
->GetData();
310 wxMenubarUnsetInvokingWindow( menu
, win
);
311 node
= node
->GetNext();
315 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
317 if ( !wxMenuBarBase::Append( menu
, title
) )
320 return GtkAppend(menu
, title
);
323 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
325 wxString
str( wxReplaceUnderscore( title
) );
327 // This doesn't have much effect right now.
328 menu
->SetTitle( str
);
330 // The "m_owner" is the "menu item"
331 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
332 menu
->SetLayoutDirection(GetLayoutDirection());
334 gtk_widget_show( menu
->m_owner
);
336 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
339 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
341 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
343 g_signal_connect (menu
->m_owner
, "activate",
344 G_CALLBACK (gtk_menu_open_callback
),
347 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
348 // addings menu later on.
349 if (m_invokingWindow
)
351 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
353 // OPTIMISE ME: we should probably cache this, or pass it
354 // directly, but for now this is a minimal
355 // change to validate the new dynamic sizing.
356 // see (and refactor :) similar code in Remove
359 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
362 frame
->UpdateMenuBarSize();
368 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
370 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
375 if ( !GtkAppend(menu
, title
, (int)pos
) )
381 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
383 // remove the old item and insert a new one
384 wxMenu
*menuOld
= Remove(pos
);
385 if ( menuOld
&& !Insert(pos
, menu
, title
) )
387 return (wxMenu
*) NULL
;
390 // either Insert() succeeded or Remove() failed and menuOld is NULL
394 wxMenu
*wxMenuBar::Remove(size_t pos
)
396 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
398 return (wxMenu
*) NULL
;
400 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
401 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
403 gtk_widget_destroy( menu
->m_owner
);
404 menu
->m_owner
= NULL
;
406 if (m_invokingWindow
)
408 // OPTIMISE ME: see comment in GtkAppend
409 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
412 frame
->UpdateMenuBarSize();
418 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
420 if (wxMenuItem::GetLabelFromText(menu
->GetTitle()) == wxMenuItem::GetLabelFromText(menuString
))
422 int res
= menu
->FindItem( itemString
);
423 if (res
!= wxNOT_FOUND
)
427 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
430 wxMenuItem
*item
= node
->GetData();
431 if (item
->IsSubMenu())
432 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
434 node
= node
->GetNext();
440 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
442 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
445 wxMenu
*menu
= node
->GetData();
446 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
449 node
= node
->GetNext();
455 // Find a wxMenuItem using its id. Recurses down into sub-menus
456 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
458 wxMenuItem
* result
= menu
->FindChildItem(id
);
460 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
461 while ( node
&& result
== NULL
)
463 wxMenuItem
*item
= node
->GetData();
464 if (item
->IsSubMenu())
466 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
468 node
= node
->GetNext();
474 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
476 wxMenuItem
* result
= 0;
477 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
478 while (node
&& result
== 0)
480 wxMenu
*menu
= node
->GetData();
481 result
= FindMenuItemByIdRecursive( menu
, id
);
482 node
= node
->GetNext();
487 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
493 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
495 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
497 wxCHECK_RET( node
, wxT("menu not found") );
499 wxMenu
* menu
= node
->GetData();
502 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
505 wxString
wxMenuBar::GetLabelTop( size_t pos
) const
507 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
509 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
511 wxMenu
* menu
= node
->GetData();
514 wxString
text( menu
->GetTitle() );
515 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
517 if ( *pc
== wxT('_') )
519 // '_' is the escape character for GTK+
523 // don't remove ampersands '&' since if we have them in the menu title
524 // it means that they were doubled to indicate "&" instead of accelerator
532 void wxMenuBar::SetLabelTop( size_t pos
, const wxString
& label
)
534 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
536 wxCHECK_RET( node
, wxT("menu not found") );
538 wxMenu
* menu
= node
->GetData();
540 const wxString
str( wxReplaceUnderscore( label
) );
542 menu
->SetTitle( str
);
545 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
548 //-----------------------------------------------------------------------------
550 //-----------------------------------------------------------------------------
553 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
555 int id
= menu
->FindMenuIdByMenuItem(widget
);
557 /* should find it for normal (not popup) menu */
558 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
559 _T("menu item not found in gtk_menu_clicked_callback") );
561 if (!menu
->IsEnabled(id
))
564 wxMenuItem
* item
= menu
->FindChildItem( id
);
565 wxCHECK_RET( item
, wxT("error in menu item callback") );
567 if ( item
->GetId() == wxGTK_TITLE_ID
)
569 // ignore events from the menu title
573 if (item
->IsCheckable())
575 bool isReallyChecked
= item
->IsChecked(),
576 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
578 // ensure that the internal state is always consistent with what is
579 // shown on the screen
580 item
->wxMenuItemBase::Check(isReallyChecked
);
582 // we must not report the events for the radio button going up nor the
583 // events resulting from the calls to wxMenuItem::Check()
584 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
585 (isInternallyChecked
== isReallyChecked
) )
592 // Is this menu on a menubar? (possibly nested)
593 wxFrame
* frame
= NULL
;
594 if(menu
->IsAttached())
595 frame
= menu
->GetMenuBar()->GetFrame();
597 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
598 // normally wxMenu::SendEvent() should be enough, if it doesn't work
599 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
600 // should be fixed instead of working around it here...
603 // If it is attached then let the frame send the event.
604 // Don't call frame->ProcessCommand(id) because it toggles
605 // checkable items and we've already done that above.
606 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
607 commandEvent
.SetEventObject(frame
);
608 if (item
->IsCheckable())
609 commandEvent
.SetInt(item
->IsChecked());
610 commandEvent
.SetEventObject(menu
);
612 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
616 // otherwise let the menu have it
617 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
622 //-----------------------------------------------------------------------------
624 //-----------------------------------------------------------------------------
627 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
629 int id
= menu
->FindMenuIdByMenuItem(widget
);
631 wxASSERT( id
!= -1 ); // should find it!
633 if (!menu
->IsEnabled(id
))
636 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
637 event
.SetEventObject( menu
);
639 wxEvtHandler
* handler
= menu
->GetEventHandler();
640 if (handler
&& handler
->ProcessEvent(event
))
643 wxWindow
*win
= menu
->GetInvokingWindow();
644 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
648 //-----------------------------------------------------------------------------
650 //-----------------------------------------------------------------------------
653 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
655 int id
= menu
->FindMenuIdByMenuItem(widget
);
657 wxASSERT( id
!= -1 ); // should find it!
659 if (!menu
->IsEnabled(id
))
662 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
663 event
.SetEventObject( menu
);
665 wxEvtHandler
* handler
= menu
->GetEventHandler();
666 if (handler
&& handler
->ProcessEvent(event
))
669 wxWindow
*win
= menu
->GetInvokingWindow();
671 win
->GetEventHandler()->ProcessEvent( event
);
675 //-----------------------------------------------------------------------------
677 //-----------------------------------------------------------------------------
679 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
681 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
683 const wxString
& name
,
684 const wxString
& help
,
688 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
691 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
693 const wxString
& text
,
694 const wxString
& help
,
697 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
702 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
704 const wxString
& text
,
705 const wxString
& help
,
708 : wxMenuItemBase(parentMenu
, id
, text
, help
,
709 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
714 void wxMenuItem::Init(const wxString
& text
)
716 m_labelWidget
= (GtkWidget
*) NULL
;
717 m_menuItem
= (GtkWidget
*) NULL
;
722 wxMenuItem::~wxMenuItem()
724 // don't delete menu items, the menus take care of that
727 // return the menu item text without any menu accels
729 wxString
wxMenuItemBase::GetLabelFromText(const wxString
& text
)
733 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
735 if ( *pc
== wxT('\t'))
738 if ( *pc
== wxT('_') )
740 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
746 if ( *pc
== wxT('\\') )
748 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
754 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
757 // "&" is doubled to indicate "&" instead of accelerator
764 // wxPrintf( wxT("GetLabelFromText(): text %s label %s\n"), text.c_str(), label.c_str() );
769 void wxMenuItem::SetText( const wxString
& str
)
771 // cache some data which must be used later
772 bool isstock
= wxIsStockID(GetId());
773 const char *stockid
= NULL
;
775 stockid
= wxGetStockGtkID(GetId());
777 // Some optimization to avoid flicker
778 wxString oldLabel
= m_text
;
779 oldLabel
= wxStripMenuCodes(oldLabel
);
780 oldLabel
.Replace(wxT("_"), wxT(""));
781 wxString label1
= wxStripMenuCodes(str
);
782 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
783 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
787 if (oldLabel
== label1
&&
788 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
795 label
= (GtkLabel
*) m_labelWidget
;
797 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
799 // stock menu items can have empty labels:
800 wxString text
= m_text
;
801 if (text
.IsEmpty() && !IsSeparator())
803 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
804 text
= wxGetStockLabel(GetId());
806 // need & => _ conversion
807 text
= GTKProcessMenuItemLabel(text
, NULL
);
810 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
813 // remove old accelerator from our parent's accelerator group, if present
815 GdkModifierType accel_mods
;
816 if (oldbuf
[(size_t)0] != '\0')
818 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
821 gtk_widget_remove_accelerator(m_menuItem
,
822 m_parentMenu
->m_accel
,
829 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
830 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
831 gtk_widget_remove_accelerator( m_menuItem
,
832 m_parentMenu
->m_accel
,
837 // add new accelerator to our parent's accelerator group
838 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
839 if (buf
[(size_t)0] != '\0')
841 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
844 gtk_widget_add_accelerator( m_menuItem
,
846 m_parentMenu
->m_accel
,
854 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
855 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
856 gtk_widget_remove_accelerator( m_menuItem
,
857 m_parentMenu
->m_accel
,
863 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
864 // implemented in control.cpp and from wxMenuItemBase::GetLabelFromText...
865 // so there's no real code duplication
866 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
870 // '\t' is the deliminator indicating a hot key
871 wxString::const_iterator pc
= str
.begin();
872 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
876 wxString::const_iterator next
= pc
+ 1;
877 if (next
!= str
.end() && *next
== wxT('&'))
879 // "&" is doubled to indicate "&" instead of accelerator
888 else if ( *pc
== wxT('_') ) // escape underscores
905 hotKey
->assign(pc
, str
.end());
912 // it's valid for this function to be called even if m_menuItem == NULL
913 void wxMenuItem::DoSetText( const wxString
& str
)
916 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
921 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
929 // accelerator parsing code looks for them after a TAB, so insert a dummy
932 label
<< wxT('\t') << GetHotKey();
934 return wxAcceleratorEntry::Create(label
);
937 #endif // wxUSE_ACCEL
939 void wxMenuItem::Check( bool check
)
941 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
943 if (check
== m_isChecked
)
946 wxMenuItemBase::Check( check
);
952 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
956 wxFAIL_MSG( _T("can't check this item") );
960 void wxMenuItem::Enable( bool enable
)
962 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
964 gtk_widget_set_sensitive( m_menuItem
, enable
);
965 wxMenuItemBase::Enable( enable
);
968 bool wxMenuItem::IsChecked() const
970 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
972 wxCHECK_MSG( IsCheckable(), false,
973 wxT("can't get state of uncheckable item!") );
975 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
978 //-----------------------------------------------------------------------------
980 //-----------------------------------------------------------------------------
982 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
986 m_accel
= gtk_accel_group_new();
987 m_menu
= gtk_menu_new();
988 // NB: keep reference to the menu so that it is not destroyed behind
989 // our back by GTK+ e.g. when it is removed from menubar:
990 gtk_widget_ref(m_menu
);
992 m_owner
= (GtkWidget
*) NULL
;
994 // Tearoffs are entries, just like separators. So if we want this
995 // menu to be a tear-off one, we just append a tearoff entry
997 if ( m_style
& wxMENU_TEAROFF
)
999 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
1001 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
1006 // append the title as the very first entry if we have it
1007 if ( !m_title
.empty() )
1009 Append(wxGTK_TITLE_ID
, m_title
);
1016 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1018 if ( GTK_IS_WIDGET( m_menu
))
1021 gtk_widget_unref( m_menu
);
1022 g_object_unref( m_accel
);
1024 // if the menu is inserted in another menu at this time, there was
1025 // one more reference to it:
1027 gtk_widget_destroy( m_menu
);
1031 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1034 wxWindow::GTKSetLayout(m_owner
, dir
);
1035 //else: will be called later by wxMenuBar again
1038 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1040 return wxWindow::GTKGetLayout(m_owner
);
1043 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1045 GtkWidget
*menuItem
;
1047 // cache some data used later
1048 wxString text
= mitem
->GetText();
1049 int id
= mitem
->GetId();
1050 bool isstock
= wxIsStockID(id
);
1051 const char *stockid
= NULL
;
1053 stockid
= wxGetStockGtkID(mitem
->GetId());
1055 // stock menu items can have an empty label
1056 if (text
.IsEmpty() && !mitem
->IsSeparator())
1058 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1059 text
= wxGetStockLabel(id
);
1061 // need & => _ conversion
1062 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1065 if ( mitem
->IsSeparator() )
1067 menuItem
= gtk_separator_menu_item_new();
1069 else if ( mitem
->GetBitmap().Ok() ||
1070 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1072 wxBitmap
bitmap(mitem
->GetBitmap());
1074 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1079 // use stock bitmap for this item if available on the assumption
1080 // that it never hurts to follow GTK+ conventions more closely
1081 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1084 else // we have a custom bitmap
1086 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1087 _T("only normal menu items can have bitmaps") );
1089 if ( bitmap
.HasPixbuf() )
1091 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1095 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1096 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1097 bitmap
.GetMask()->GetBitmap() :
1099 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1105 gtk_widget_show(image
);
1107 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1112 else // a normal item
1114 // NB: 'text' variable has "_" instead of "&" after mitem->SetText()
1117 switch ( mitem
->GetKind() )
1121 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1128 GSList
*group
= NULL
;
1129 if ( m_prevRadio
== NULL
)
1131 // start of a new radio group
1132 m_prevRadio
= menuItem
=
1133 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1135 else // continue the radio group
1137 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1138 m_prevRadio
= menuItem
=
1139 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1145 wxFAIL_MSG( _T("unexpected menu item kind") );
1150 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1159 GdkModifierType accel_mods
;
1160 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1162 // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() );
1163 if (buf
[(size_t)0] != '\0')
1165 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1168 gtk_widget_add_accelerator (menuItem
,
1178 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1179 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1180 gtk_widget_add_accelerator( menuItem
,
1189 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1191 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1193 gtk_widget_show( menuItem
);
1195 if ( !mitem
->IsSeparator() )
1197 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1199 g_signal_connect (menuItem
, "select",
1200 G_CALLBACK (gtk_menu_hilight_callback
), this);
1201 g_signal_connect (menuItem
, "deselect",
1202 G_CALLBACK (gtk_menu_nolight_callback
), this);
1204 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1206 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1208 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1210 // if adding a submenu to a menu already existing in the menu bar, we
1211 // must set invoking window to allow processing events from this
1213 if ( m_invokingWindow
)
1214 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1218 g_signal_connect (menuItem
, "activate",
1219 G_CALLBACK (gtk_menu_clicked_callback
),
1224 mitem
->SetMenuItem(menuItem
);
1228 // This doesn't even exist!
1229 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1235 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1237 if (!GtkAppend(mitem
))
1240 return wxMenuBase::DoAppend(mitem
);
1243 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1245 if ( !wxMenuBase::DoInsert(pos
, item
) )
1249 if ( !GtkAppend(item
, (int)pos
) )
1255 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1257 if ( !wxMenuBase::DoRemove(item
) )
1258 return (wxMenuItem
*)NULL
;
1260 // TODO: this code doesn't delete the item factory item and this seems
1261 // impossible as of GTK 1.2.6.
1262 gtk_widget_destroy( item
->GetMenuItem() );
1267 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1269 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1272 wxMenuItem
*item
= node
->GetData();
1273 if (item
->GetMenuItem() == menuItem
)
1274 return item
->GetId();
1275 node
= node
->GetNext();
1281 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1283 wxMenuBase::Attach(menubar
);
1285 // inherit layout direction from menubar.
1286 SetLayoutDirection(menubar
->GetLayoutDirection());
1289 // ----------------------------------------------------------------------------
1291 // ----------------------------------------------------------------------------
1295 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1299 wxAcceleratorEntry
*accel
= item
.GetAccel();
1302 int flags
= accel
->GetFlags();
1303 if ( flags
& wxACCEL_ALT
)
1304 hotkey
+= wxT("<alt>");
1305 if ( flags
& wxACCEL_CTRL
)
1306 hotkey
+= wxT("<control>");
1307 if ( flags
& wxACCEL_SHIFT
)
1308 hotkey
+= wxT("<shift>");
1310 int code
= accel
->GetKeyCode();
1337 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1340 // TODO: we should use gdk_keyval_name() (a.k.a.
1341 // XKeysymToString) here as well as hardcoding the keysym
1342 // names this might be not portable
1344 hotkey
<< wxT("Insert" );
1347 hotkey
<< wxT("Delete" );
1350 hotkey
<< wxT("Up" );
1353 hotkey
<< wxT("Down" );
1356 hotkey
<< wxT("Page_Up" );
1359 hotkey
<< wxT("Page_Down" );
1362 hotkey
<< wxT("Left" );
1365 hotkey
<< wxT("Right" );
1368 hotkey
<< wxT("Home" );
1371 hotkey
<< wxT("End" );
1374 hotkey
<< wxT("Return" );
1377 hotkey
<< wxT("BackSpace" );
1380 hotkey
<< wxT("Tab" );
1383 hotkey
<< wxT("Esc" );
1386 hotkey
<< wxT("space" );
1389 hotkey
<< wxT("Multiply" );
1392 hotkey
<< wxT("Add" );
1395 hotkey
<< wxT("Separator" );
1398 hotkey
<< wxT("Subtract" );
1401 hotkey
<< wxT("Decimal" );
1404 hotkey
<< wxT("Divide" );
1407 hotkey
<< wxT("Cancel" );
1410 hotkey
<< wxT("Clear" );
1413 hotkey
<< wxT("Menu" );
1416 hotkey
<< wxT("Pause" );
1419 hotkey
<< wxT("Capital" );
1422 hotkey
<< wxT("Select" );
1425 hotkey
<< wxT("Print" );
1428 hotkey
<< wxT("Execute" );
1431 hotkey
<< wxT("Snapshot" );
1434 hotkey
<< wxT("Help" );
1437 hotkey
<< wxT("Num_Lock" );
1440 hotkey
<< wxT("Scroll_Lock" );
1442 case WXK_NUMPAD_INSERT
:
1443 hotkey
<< wxT("KP_Insert" );
1445 case WXK_NUMPAD_DELETE
:
1446 hotkey
<< wxT("KP_Delete" );
1448 case WXK_NUMPAD_SPACE
:
1449 hotkey
<< wxT("KP_Space" );
1451 case WXK_NUMPAD_TAB
:
1452 hotkey
<< wxT("KP_Tab" );
1454 case WXK_NUMPAD_ENTER
:
1455 hotkey
<< wxT("KP_Enter" );
1457 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1459 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1461 case WXK_NUMPAD_HOME
:
1462 hotkey
<< wxT("KP_Home" );
1464 case WXK_NUMPAD_LEFT
:
1465 hotkey
<< wxT("KP_Left" );
1468 hotkey
<< wxT("KP_Up" );
1470 case WXK_NUMPAD_RIGHT
:
1471 hotkey
<< wxT("KP_Right" );
1473 case WXK_NUMPAD_DOWN
:
1474 hotkey
<< wxT("KP_Down" );
1476 case WXK_NUMPAD_PAGEUP
:
1477 hotkey
<< wxT("KP_Page_Up" );
1479 case WXK_NUMPAD_PAGEDOWN
:
1480 hotkey
<< wxT("KP_Page_Down" );
1482 case WXK_NUMPAD_END
:
1483 hotkey
<< wxT("KP_End" );
1485 case WXK_NUMPAD_BEGIN
:
1486 hotkey
<< wxT("KP_Begin" );
1488 case WXK_NUMPAD_EQUAL
:
1489 hotkey
<< wxT("KP_Equal" );
1491 case WXK_NUMPAD_MULTIPLY
:
1492 hotkey
<< wxT("KP_Multiply" );
1494 case WXK_NUMPAD_ADD
:
1495 hotkey
<< wxT("KP_Add" );
1497 case WXK_NUMPAD_SEPARATOR
:
1498 hotkey
<< wxT("KP_Separator" );
1500 case WXK_NUMPAD_SUBTRACT
:
1501 hotkey
<< wxT("KP_Subtract" );
1503 case WXK_NUMPAD_DECIMAL
:
1504 hotkey
<< wxT("KP_Decimal" );
1506 case WXK_NUMPAD_DIVIDE
:
1507 hotkey
<< wxT("KP_Divide" );
1509 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1510 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1511 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1512 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1514 case WXK_WINDOWS_LEFT
:
1515 hotkey
<< wxT("Super_L" );
1517 case WXK_WINDOWS_RIGHT
:
1518 hotkey
<< wxT("Super_R" );
1520 case WXK_WINDOWS_MENU
:
1521 hotkey
<< wxT("Menu" );
1524 hotkey
<< wxT("Command" );
1526 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1527 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1528 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1529 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1530 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1531 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1532 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1535 // if there are any other keys wxAcceleratorEntry::Create() may
1536 // return, we should process them here
1542 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1543 if ( !name
.empty() )
1550 wxFAIL_MSG( wxT("unknown keyboard accel") );
1559 #endif // wxUSE_ACCEL
1561 // ----------------------------------------------------------------------------
1562 // Pop-up menu stuff
1563 // ----------------------------------------------------------------------------
1565 #if wxUSE_MENUS_NATIVE
1567 extern "C" WXDLLIMPEXP_CORE
1568 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1570 *is_waiting
= false;
1573 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1575 menu
->SetInvokingWindow( win
);
1577 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1580 wxMenuItem
*menuitem
= node
->GetData();
1581 if (menuitem
->IsSubMenu())
1583 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1586 node
= node
->GetNext();
1590 extern "C" WXDLLIMPEXP_CORE
1591 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1593 gboolean
* WXUNUSED(whatever
),
1594 gpointer user_data
)
1596 // ensure that the menu appears entirely on screen
1598 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1600 wxSize sizeScreen
= wxGetDisplaySize();
1601 wxPoint
*pos
= (wxPoint
*)user_data
;
1603 gint xmax
= sizeScreen
.x
- req
.width
,
1604 ymax
= sizeScreen
.y
- req
.height
;
1606 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1607 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1610 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1612 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1614 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1616 // NOTE: if you change this code, you need to update
1617 // the same code in taskbar.cpp as well. This
1618 // is ugly code duplication, I know.
1620 SetInvokingWindow( menu
, this );
1624 bool is_waiting
= true;
1626 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1627 G_CALLBACK (gtk_pop_hide_callback
),
1632 GtkMenuPositionFunc posfunc
;
1633 if ( x
== -1 && y
== -1 )
1635 // use GTK's default positioning algorithm
1641 pos
= ClientToScreen(wxPoint(x
, y
));
1643 posfunc
= wxPopupMenuPositionCallback
;
1646 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1647 DoCommonMenuCallbackCode(menu
, eventOpen
);
1650 GTK_MENU(menu
->m_menu
),
1651 (GtkWidget
*) NULL
, // parent menu shell
1652 (GtkWidget
*) NULL
, // parent menu item
1653 posfunc
, // function to position it
1654 userdata
, // client data
1655 0, // button used to activate it
1656 gtk_get_current_event_time()
1661 gtk_main_iteration();
1664 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1666 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1667 DoCommonMenuCallbackCode(menu
, eventClose
);
1672 #endif // wxUSE_MENUS_NATIVE
1676 #include <gtk/gtk.h>
1678 const char *wxGetStockGtkID(wxWindowID id
)
1680 #define STOCKITEM(wx,gtk) \
1684 #define STOCKITEM_MISSING(wx) \
1688 #if GTK_CHECK_VERSION(2,4,0)
1689 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1691 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1694 #if GTK_CHECK_VERSION(2,6,0)
1695 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1697 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1700 #if GTK_CHECK_VERSION(2,10,0)
1701 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1703 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1709 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1710 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1711 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1712 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1713 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1714 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1715 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1716 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1717 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1718 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1719 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1720 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1721 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1722 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1723 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1724 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1725 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1726 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1727 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1728 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1729 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1730 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1731 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1732 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1733 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1734 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1735 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1736 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1737 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1738 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1739 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1740 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1741 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1742 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1743 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1744 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1745 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1746 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1747 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1748 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1749 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1750 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1751 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1752 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1753 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1754 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1755 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1756 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1757 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1758 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1759 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1760 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1761 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1762 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1765 wxFAIL_MSG( _T("invalid stock item ID") );
1774 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1779 GtkStockItem stock_item
;
1780 if (gtk_stock_lookup (id
, &stock_item
))
1782 if (key
) *key
= stock_item
.keyval
;
1783 if (mod
) *mod
= stock_item
.modifier
;
1785 // some GTK stock items have zero values for the keyval;
1786 // it means that they do not have an accelerator...
1787 if (stock_item
.keyval
)
1794 #endif // __WXGTK20__