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"
30 #include <gdk/gdktypes.h>
33 // FIXME: is this right? somehow I don't think so (VZ)
35 #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
36 //#define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
37 //#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
39 #define ACCEL_OBJECT GtkWindow
40 #define ACCEL_OBJECTS(a) (a)->acceleratables
41 #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
43 // we use normal item but with a special id for the menu title
44 static const int wxGTK_TITLE_ID
= -3;
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
51 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
54 //-----------------------------------------------------------------------------
56 //-----------------------------------------------------------------------------
58 static wxString
wxReplaceUnderscore( const wxString
& title
)
60 // GTK 1.2 wants to have "_" instead of "&" for accelerators
63 for ( wxString::const_iterator pc
= title
.begin(); pc
!= title
.end(); ++pc
)
65 if ((*pc
== wxT('&')) && (pc
+1 != title
.end()) && (*(pc
+1) == wxT('&')))
67 // "&" is doubled to indicate "&" instead of accelerator
71 else if (*pc
== wxT('&'))
77 if ( *pc
== wxT('_') )
79 // underscores must be doubled to prevent them from being
80 // interpreted as accelerator character prefix by GTK
88 // wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() );
93 //-----------------------------------------------------------------------------
94 // activate message from GTK
95 //-----------------------------------------------------------------------------
97 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
99 event
.SetEventObject( menu
);
101 wxEvtHandler
* handler
= menu
->GetEventHandler();
102 if (handler
&& handler
->ProcessEvent(event
))
105 wxWindow
*win
= menu
->GetInvokingWindow();
107 win
->GetEventHandler()->ProcessEvent( event
);
112 static void gtk_menu_open_callback( GtkWidget
*widget
, wxMenu
*menu
)
114 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
116 DoCommonMenuCallbackCode(menu
, event
);
119 static void gtk_menu_close_callback( GtkWidget
*widget
, wxMenuBar
*menubar
)
121 if ( !menubar
->GetMenuCount() )
123 // if menubar is empty we can't call GetMenu(0) below
127 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
129 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
134 //-----------------------------------------------------------------------------
136 //-----------------------------------------------------------------------------
138 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
140 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
143 m_invokingWindow
= NULL
;
145 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
146 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
148 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
152 m_menubar
= gtk_menu_bar_new();
154 if (style
& wxMB_DOCKABLE
)
156 m_widget
= gtk_handle_box_new();
157 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
158 gtk_widget_show(m_menubar
);
162 m_widget
= m_menubar
;
169 for (size_t i
= 0; i
< n
; ++i
)
170 Append(menus
[i
], titles
[i
]);
172 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
173 // don't get it when the menu is dismissed by clicking outside the
174 // toolbar) so we connect to the global one, even if it means that we
175 // can't pass the menu which was closed in wxMenuEvent object
176 g_signal_connect (m_menubar
, "deactivate",
177 G_CALLBACK (gtk_menu_close_callback
), this);
181 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
183 Init(n
, menus
, titles
, style
);
186 wxMenuBar::wxMenuBar(long style
)
188 Init(0, NULL
, NULL
, style
);
191 wxMenuBar::wxMenuBar()
193 Init(0, NULL
, NULL
, 0);
196 wxMenuBar::~wxMenuBar()
200 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
202 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
204 wxWindow
*top_frame
= win
;
205 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
206 top_frame
= top_frame
->GetParent();
208 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
211 wxMenuItem
*menuitem
= node
->GetData();
212 if (menuitem
->IsSubMenu())
213 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
214 node
= node
->GetNext();
218 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
220 menu
->SetInvokingWindow( win
);
222 wxWindow
*top_frame
= win
;
223 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
224 top_frame
= top_frame
->GetParent();
226 // support for native hot keys
227 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
228 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
229 gtk_accel_group_attach( menu
->m_accel
, obj
);
231 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
234 wxMenuItem
*menuitem
= node
->GetData();
235 if (menuitem
->IsSubMenu())
236 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
237 node
= node
->GetNext();
241 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
243 m_invokingWindow
= win
;
244 wxWindow
*top_frame
= win
;
245 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
246 top_frame
= top_frame
->GetParent();
248 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
251 wxMenu
*menu
= node
->GetData();
252 wxMenubarSetInvokingWindow( menu
, win
);
253 node
= node
->GetNext();
257 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
259 if ( dir
== wxLayout_Default
)
261 const wxWindow
*const frame
= GetFrame();
264 // inherit layout from frame.
265 dir
= frame
->GetLayoutDirection();
267 else // use global layout
269 dir
= wxTheApp
->GetLayoutDirection();
273 if ( dir
== wxLayout_Default
)
276 GTKSetLayout(m_menubar
, dir
);
278 // also set the layout of all menus we already have (new ones will inherit
279 // the current layout)
280 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
282 node
= node
->GetNext() )
284 wxMenu
*const menu
= node
->GetData();
285 menu
->SetLayoutDirection(dir
);
289 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
291 return GTKGetLayout(m_menubar
);
294 void wxMenuBar::Attach(wxFrame
*frame
)
296 wxMenuBarBase::Attach(frame
);
298 SetLayoutDirection(wxLayout_Default
);
301 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
303 m_invokingWindow
= (wxWindow
*) NULL
;
304 wxWindow
*top_frame
= win
;
305 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
306 top_frame
= top_frame
->GetParent();
308 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
311 wxMenu
*menu
= node
->GetData();
312 wxMenubarUnsetInvokingWindow( menu
, win
);
313 node
= node
->GetNext();
317 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
319 if ( !wxMenuBarBase::Append( menu
, title
) )
322 return GtkAppend(menu
, title
);
325 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
327 wxString
str( wxReplaceUnderscore( title
) );
329 // This doesn't have much effect right now.
330 menu
->SetTitle( str
);
332 // The "m_owner" is the "menu item"
333 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
334 menu
->SetLayoutDirection(GetLayoutDirection());
336 gtk_widget_show( menu
->m_owner
);
338 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
341 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
343 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
345 g_signal_connect (menu
->m_owner
, "activate",
346 G_CALLBACK (gtk_menu_open_callback
),
349 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
350 // addings menu later on.
351 if (m_invokingWindow
)
353 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
355 // OPTIMISE ME: we should probably cache this, or pass it
356 // directly, but for now this is a minimal
357 // change to validate the new dynamic sizing.
358 // see (and refactor :) similar code in Remove
361 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
364 frame
->UpdateMenuBarSize();
370 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
372 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
377 if ( !GtkAppend(menu
, title
, (int)pos
) )
383 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
385 // remove the old item and insert a new one
386 wxMenu
*menuOld
= Remove(pos
);
387 if ( menuOld
&& !Insert(pos
, menu
, title
) )
389 return (wxMenu
*) NULL
;
392 // either Insert() succeeded or Remove() failed and menuOld is NULL
396 wxMenu
*wxMenuBar::Remove(size_t pos
)
398 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
400 return (wxMenu
*) NULL
;
402 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
403 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
405 gtk_widget_destroy( menu
->m_owner
);
406 menu
->m_owner
= NULL
;
408 if (m_invokingWindow
)
410 // OPTIMISE ME: see comment in GtkAppend
411 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
414 frame
->UpdateMenuBarSize();
420 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
422 if (wxMenuItem::GetLabelFromText(menu
->GetTitle()) == wxMenuItem::GetLabelFromText(menuString
))
424 int res
= menu
->FindItem( itemString
);
425 if (res
!= wxNOT_FOUND
)
429 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
432 wxMenuItem
*item
= node
->GetData();
433 if (item
->IsSubMenu())
434 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
436 node
= node
->GetNext();
442 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
444 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
447 wxMenu
*menu
= node
->GetData();
448 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
451 node
= node
->GetNext();
457 // Find a wxMenuItem using its id. Recurses down into sub-menus
458 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
460 wxMenuItem
* result
= menu
->FindChildItem(id
);
462 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
463 while ( node
&& result
== NULL
)
465 wxMenuItem
*item
= node
->GetData();
466 if (item
->IsSubMenu())
468 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
470 node
= node
->GetNext();
476 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
478 wxMenuItem
* result
= 0;
479 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
480 while (node
&& result
== 0)
482 wxMenu
*menu
= node
->GetData();
483 result
= FindMenuItemByIdRecursive( menu
, id
);
484 node
= node
->GetNext();
489 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
495 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
497 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
499 wxCHECK_RET( node
, wxT("menu not found") );
501 wxMenu
* menu
= node
->GetData();
504 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
507 wxString
wxMenuBar::GetLabelTop( size_t pos
) const
509 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
511 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
513 wxMenu
* menu
= node
->GetData();
516 wxString
text( menu
->GetTitle() );
517 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
519 if ( *pc
== wxT('_') )
521 // '_' is the escape character for GTK+
525 // don't remove ampersands '&' since if we have them in the menu title
526 // it means that they were doubled to indicate "&" instead of accelerator
534 void wxMenuBar::SetLabelTop( size_t pos
, const wxString
& label
)
536 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
538 wxCHECK_RET( node
, wxT("menu not found") );
540 wxMenu
* menu
= node
->GetData();
542 const wxString
str( wxReplaceUnderscore( label
) );
544 menu
->SetTitle( str
);
547 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
550 //-----------------------------------------------------------------------------
552 //-----------------------------------------------------------------------------
555 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
557 int id
= menu
->FindMenuIdByMenuItem(widget
);
559 /* should find it for normal (not popup) menu */
560 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
561 _T("menu item not found in gtk_menu_clicked_callback") );
563 if (!menu
->IsEnabled(id
))
566 wxMenuItem
* item
= menu
->FindChildItem( id
);
567 wxCHECK_RET( item
, wxT("error in menu item callback") );
569 if ( item
->GetId() == wxGTK_TITLE_ID
)
571 // ignore events from the menu title
575 if (item
->IsCheckable())
577 bool isReallyChecked
= item
->IsChecked(),
578 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
580 // ensure that the internal state is always consistent with what is
581 // shown on the screen
582 item
->wxMenuItemBase::Check(isReallyChecked
);
584 // we must not report the events for the radio button going up nor the
585 // events resulting from the calls to wxMenuItem::Check()
586 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
587 (isInternallyChecked
== isReallyChecked
) )
594 // Is this menu on a menubar? (possibly nested)
595 wxFrame
* frame
= NULL
;
596 if(menu
->IsAttached())
597 frame
= menu
->GetMenuBar()->GetFrame();
599 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
600 // normally wxMenu::SendEvent() should be enough, if it doesn't work
601 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
602 // should be fixed instead of working around it here...
605 // If it is attached then let the frame send the event.
606 // Don't call frame->ProcessCommand(id) because it toggles
607 // checkable items and we've already done that above.
608 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
609 commandEvent
.SetEventObject(frame
);
610 if (item
->IsCheckable())
611 commandEvent
.SetInt(item
->IsChecked());
612 commandEvent
.SetEventObject(menu
);
614 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
618 // otherwise let the menu have it
619 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
624 //-----------------------------------------------------------------------------
626 //-----------------------------------------------------------------------------
629 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
631 int id
= menu
->FindMenuIdByMenuItem(widget
);
633 wxASSERT( id
!= -1 ); // should find it!
635 if (!menu
->IsEnabled(id
))
638 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
639 event
.SetEventObject( menu
);
641 wxEvtHandler
* handler
= menu
->GetEventHandler();
642 if (handler
&& handler
->ProcessEvent(event
))
645 wxWindow
*win
= menu
->GetInvokingWindow();
646 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
650 //-----------------------------------------------------------------------------
652 //-----------------------------------------------------------------------------
655 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
657 int id
= menu
->FindMenuIdByMenuItem(widget
);
659 wxASSERT( id
!= -1 ); // should find it!
661 if (!menu
->IsEnabled(id
))
664 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
665 event
.SetEventObject( menu
);
667 wxEvtHandler
* handler
= menu
->GetEventHandler();
668 if (handler
&& handler
->ProcessEvent(event
))
671 wxWindow
*win
= menu
->GetInvokingWindow();
673 win
->GetEventHandler()->ProcessEvent( event
);
677 //-----------------------------------------------------------------------------
679 //-----------------------------------------------------------------------------
681 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
683 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
685 const wxString
& name
,
686 const wxString
& help
,
690 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
693 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
695 const wxString
& text
,
696 const wxString
& help
,
699 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
704 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
706 const wxString
& text
,
707 const wxString
& help
,
710 : wxMenuItemBase(parentMenu
, id
, text
, help
,
711 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
716 void wxMenuItem::Init(const wxString
& text
)
718 m_labelWidget
= (GtkWidget
*) NULL
;
719 m_menuItem
= (GtkWidget
*) NULL
;
724 wxMenuItem::~wxMenuItem()
726 // don't delete menu items, the menus take care of that
729 // return the menu item text without any menu accels
731 wxString
wxMenuItemBase::GetLabelFromText(const wxString
& text
)
735 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
737 if ( *pc
== wxT('\t'))
740 if ( *pc
== wxT('_') )
742 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
748 if ( *pc
== wxT('\\') )
750 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
756 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
759 // "&" is doubled to indicate "&" instead of accelerator
766 // wxPrintf( wxT("GetLabelFromText(): text %s label %s\n"), text.c_str(), label.c_str() );
771 void wxMenuItem::SetText( const wxString
& str
)
773 // cache some data which must be used later
774 bool isstock
= wxIsStockID(GetId());
775 const char *stockid
= NULL
;
777 stockid
= wxGetStockGtkID(GetId());
779 // Some optimization to avoid flicker
780 wxString oldLabel
= m_text
;
781 oldLabel
= wxStripMenuCodes(oldLabel
);
782 oldLabel
.Replace(wxT("_"), wxT(""));
783 wxString label1
= wxStripMenuCodes(str
);
784 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
785 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
789 if (oldLabel
== label1
&&
790 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
797 label
= (GtkLabel
*) m_labelWidget
;
799 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
801 // stock menu items can have empty labels:
802 wxString text
= m_text
;
803 if (text
.IsEmpty() && !IsSeparator())
805 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
806 text
= wxGetStockLabel(GetId());
808 // need & => _ conversion
809 text
= GTKProcessMenuItemLabel(text
, NULL
);
812 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
815 // remove old accelerator from our parent's accelerator group, if present
817 GdkModifierType accel_mods
;
818 if (oldbuf
[(size_t)0] != '\0')
820 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
823 gtk_widget_remove_accelerator(m_menuItem
,
824 m_parentMenu
->m_accel
,
831 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
832 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
833 gtk_widget_remove_accelerator( m_menuItem
,
834 m_parentMenu
->m_accel
,
839 // add new accelerator to our parent's accelerator group
840 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
841 if (buf
[(size_t)0] != '\0')
843 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
846 gtk_widget_add_accelerator( m_menuItem
,
848 m_parentMenu
->m_accel
,
856 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
857 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
858 gtk_widget_remove_accelerator( m_menuItem
,
859 m_parentMenu
->m_accel
,
865 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
866 // implemented in control.cpp and from wxMenuItemBase::GetLabelFromText...
867 // so there's no real code duplication
868 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
872 // '\t' is the deliminator indicating a hot key
873 wxString::const_iterator pc
= str
.begin();
874 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
878 wxString::const_iterator next
= pc
+ 1;
879 if (next
!= str
.end() && *next
== wxT('&'))
881 // "&" is doubled to indicate "&" instead of accelerator
890 else if ( *pc
== wxT('_') ) // escape underscores
907 hotKey
->assign(pc
, str
.end());
914 // it's valid for this function to be called even if m_menuItem == NULL
915 void wxMenuItem::DoSetText( const wxString
& str
)
918 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
923 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
931 // accelerator parsing code looks for them after a TAB, so insert a dummy
934 label
<< wxT('\t') << GetHotKey();
936 return wxAcceleratorEntry::Create(label
);
939 #endif // wxUSE_ACCEL
941 void wxMenuItem::Check( bool check
)
943 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
945 if (check
== m_isChecked
)
948 wxMenuItemBase::Check( check
);
954 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
958 wxFAIL_MSG( _T("can't check this item") );
962 void wxMenuItem::Enable( bool enable
)
964 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
966 gtk_widget_set_sensitive( m_menuItem
, enable
);
967 wxMenuItemBase::Enable( enable
);
970 bool wxMenuItem::IsChecked() const
972 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
974 wxCHECK_MSG( IsCheckable(), false,
975 wxT("can't get state of uncheckable item!") );
977 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
980 //-----------------------------------------------------------------------------
982 //-----------------------------------------------------------------------------
984 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
988 m_accel
= gtk_accel_group_new();
989 m_menu
= gtk_menu_new();
990 // NB: keep reference to the menu so that it is not destroyed behind
991 // our back by GTK+ e.g. when it is removed from menubar:
992 gtk_widget_ref(m_menu
);
994 m_owner
= (GtkWidget
*) NULL
;
996 // Tearoffs are entries, just like separators. So if we want this
997 // menu to be a tear-off one, we just append a tearoff entry
999 if ( m_style
& wxMENU_TEAROFF
)
1001 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
1003 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
1008 // append the title as the very first entry if we have it
1009 if ( !m_title
.empty() )
1011 Append(wxGTK_TITLE_ID
, m_title
);
1018 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1020 if ( GTK_IS_WIDGET( m_menu
))
1023 gtk_widget_unref( m_menu
);
1024 g_object_unref( m_accel
);
1026 // if the menu is inserted in another menu at this time, there was
1027 // one more reference to it:
1029 gtk_widget_destroy( m_menu
);
1033 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1036 wxWindow::GTKSetLayout(m_owner
, dir
);
1037 //else: will be called later by wxMenuBar again
1040 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1042 return wxWindow::GTKGetLayout(m_owner
);
1045 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1047 GtkWidget
*menuItem
;
1049 // cache some data used later
1050 wxString text
= mitem
->GetText();
1051 int id
= mitem
->GetId();
1052 bool isstock
= wxIsStockID(id
);
1053 const char *stockid
= NULL
;
1055 stockid
= wxGetStockGtkID(mitem
->GetId());
1057 // stock menu items can have an empty label
1058 if (text
.IsEmpty() && !mitem
->IsSeparator())
1060 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1061 text
= wxGetStockLabel(id
);
1063 // need & => _ conversion
1064 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1067 if ( mitem
->IsSeparator() )
1069 menuItem
= gtk_separator_menu_item_new();
1071 else if ( mitem
->GetBitmap().Ok() ||
1072 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1074 wxBitmap
bitmap(mitem
->GetBitmap());
1076 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1081 // use stock bitmap for this item if available on the assumption
1082 // that it never hurts to follow GTK+ conventions more closely
1083 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1086 else // we have a custom bitmap
1088 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1089 _T("only normal menu items can have bitmaps") );
1091 if ( bitmap
.HasPixbuf() )
1093 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1097 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1098 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1099 bitmap
.GetMask()->GetBitmap() :
1101 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1107 gtk_widget_show(image
);
1109 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1114 else // a normal item
1116 // NB: 'text' variable has "_" instead of "&" after mitem->SetText()
1119 switch ( mitem
->GetKind() )
1123 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1130 GSList
*group
= NULL
;
1131 if ( m_prevRadio
== NULL
)
1133 // start of a new radio group
1134 m_prevRadio
= menuItem
=
1135 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1137 else // continue the radio group
1139 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1140 m_prevRadio
= menuItem
=
1141 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1147 wxFAIL_MSG( _T("unexpected menu item kind") );
1152 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1161 GdkModifierType accel_mods
;
1162 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1164 // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() );
1165 if (buf
[(size_t)0] != '\0')
1167 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1170 gtk_widget_add_accelerator (menuItem
,
1180 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1181 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1182 gtk_widget_add_accelerator( menuItem
,
1191 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1193 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1195 gtk_widget_show( menuItem
);
1197 if ( !mitem
->IsSeparator() )
1199 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1201 g_signal_connect (menuItem
, "select",
1202 G_CALLBACK (gtk_menu_hilight_callback
), this);
1203 g_signal_connect (menuItem
, "deselect",
1204 G_CALLBACK (gtk_menu_nolight_callback
), this);
1206 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1208 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1210 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1212 // if adding a submenu to a menu already existing in the menu bar, we
1213 // must set invoking window to allow processing events from this
1215 if ( m_invokingWindow
)
1216 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1220 g_signal_connect (menuItem
, "activate",
1221 G_CALLBACK (gtk_menu_clicked_callback
),
1226 mitem
->SetMenuItem(menuItem
);
1230 // This doesn't even exist!
1231 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1237 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1239 if (!GtkAppend(mitem
))
1242 return wxMenuBase::DoAppend(mitem
);
1245 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1247 if ( !wxMenuBase::DoInsert(pos
, item
) )
1251 if ( !GtkAppend(item
, (int)pos
) )
1257 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1259 if ( !wxMenuBase::DoRemove(item
) )
1260 return (wxMenuItem
*)NULL
;
1262 // TODO: this code doesn't delete the item factory item and this seems
1263 // impossible as of GTK 1.2.6.
1264 gtk_widget_destroy( item
->GetMenuItem() );
1269 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1271 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1274 wxMenuItem
*item
= node
->GetData();
1275 if (item
->GetMenuItem() == menuItem
)
1276 return item
->GetId();
1277 node
= node
->GetNext();
1283 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1285 wxMenuBase::Attach(menubar
);
1287 // inherit layout direction from menubar.
1288 SetLayoutDirection(menubar
->GetLayoutDirection());
1291 // ----------------------------------------------------------------------------
1293 // ----------------------------------------------------------------------------
1297 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1301 wxAcceleratorEntry
*accel
= item
.GetAccel();
1304 int flags
= accel
->GetFlags();
1305 if ( flags
& wxACCEL_ALT
)
1306 hotkey
+= wxT("<alt>");
1307 if ( flags
& wxACCEL_CTRL
)
1308 hotkey
+= wxT("<control>");
1309 if ( flags
& wxACCEL_SHIFT
)
1310 hotkey
+= wxT("<shift>");
1312 int code
= accel
->GetKeyCode();
1339 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1342 // TODO: we should use gdk_keyval_name() (a.k.a.
1343 // XKeysymToString) here as well as hardcoding the keysym
1344 // names this might be not portable
1346 hotkey
<< wxT("Insert" );
1349 hotkey
<< wxT("Delete" );
1352 hotkey
<< wxT("Up" );
1355 hotkey
<< wxT("Down" );
1358 hotkey
<< wxT("Page_Up" );
1361 hotkey
<< wxT("Page_Down" );
1364 hotkey
<< wxT("Left" );
1367 hotkey
<< wxT("Right" );
1370 hotkey
<< wxT("Home" );
1373 hotkey
<< wxT("End" );
1376 hotkey
<< wxT("Return" );
1379 hotkey
<< wxT("BackSpace" );
1382 hotkey
<< wxT("Tab" );
1385 hotkey
<< wxT("Esc" );
1388 hotkey
<< wxT("space" );
1391 hotkey
<< wxT("Multiply" );
1394 hotkey
<< wxT("Add" );
1397 hotkey
<< wxT("Separator" );
1400 hotkey
<< wxT("Subtract" );
1403 hotkey
<< wxT("Decimal" );
1406 hotkey
<< wxT("Divide" );
1409 hotkey
<< wxT("Cancel" );
1412 hotkey
<< wxT("Clear" );
1415 hotkey
<< wxT("Menu" );
1418 hotkey
<< wxT("Pause" );
1421 hotkey
<< wxT("Capital" );
1424 hotkey
<< wxT("Select" );
1427 hotkey
<< wxT("Print" );
1430 hotkey
<< wxT("Execute" );
1433 hotkey
<< wxT("Snapshot" );
1436 hotkey
<< wxT("Help" );
1439 hotkey
<< wxT("Num_Lock" );
1442 hotkey
<< wxT("Scroll_Lock" );
1444 case WXK_NUMPAD_INSERT
:
1445 hotkey
<< wxT("KP_Insert" );
1447 case WXK_NUMPAD_DELETE
:
1448 hotkey
<< wxT("KP_Delete" );
1450 case WXK_NUMPAD_SPACE
:
1451 hotkey
<< wxT("KP_Space" );
1453 case WXK_NUMPAD_TAB
:
1454 hotkey
<< wxT("KP_Tab" );
1456 case WXK_NUMPAD_ENTER
:
1457 hotkey
<< wxT("KP_Enter" );
1459 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1461 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1463 case WXK_NUMPAD_HOME
:
1464 hotkey
<< wxT("KP_Home" );
1466 case WXK_NUMPAD_LEFT
:
1467 hotkey
<< wxT("KP_Left" );
1470 hotkey
<< wxT("KP_Up" );
1472 case WXK_NUMPAD_RIGHT
:
1473 hotkey
<< wxT("KP_Right" );
1475 case WXK_NUMPAD_DOWN
:
1476 hotkey
<< wxT("KP_Down" );
1478 case WXK_NUMPAD_PAGEUP
:
1479 hotkey
<< wxT("KP_Page_Up" );
1481 case WXK_NUMPAD_PAGEDOWN
:
1482 hotkey
<< wxT("KP_Page_Down" );
1484 case WXK_NUMPAD_END
:
1485 hotkey
<< wxT("KP_End" );
1487 case WXK_NUMPAD_BEGIN
:
1488 hotkey
<< wxT("KP_Begin" );
1490 case WXK_NUMPAD_EQUAL
:
1491 hotkey
<< wxT("KP_Equal" );
1493 case WXK_NUMPAD_MULTIPLY
:
1494 hotkey
<< wxT("KP_Multiply" );
1496 case WXK_NUMPAD_ADD
:
1497 hotkey
<< wxT("KP_Add" );
1499 case WXK_NUMPAD_SEPARATOR
:
1500 hotkey
<< wxT("KP_Separator" );
1502 case WXK_NUMPAD_SUBTRACT
:
1503 hotkey
<< wxT("KP_Subtract" );
1505 case WXK_NUMPAD_DECIMAL
:
1506 hotkey
<< wxT("KP_Decimal" );
1508 case WXK_NUMPAD_DIVIDE
:
1509 hotkey
<< wxT("KP_Divide" );
1511 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1512 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1513 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1514 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1516 case WXK_WINDOWS_LEFT
:
1517 hotkey
<< wxT("Super_L" );
1519 case WXK_WINDOWS_RIGHT
:
1520 hotkey
<< wxT("Super_R" );
1522 case WXK_WINDOWS_MENU
:
1523 hotkey
<< wxT("Menu" );
1526 hotkey
<< wxT("Command" );
1528 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1529 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1530 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1531 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1532 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1533 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1534 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1537 // if there are any other keys wxAcceleratorEntry::Create() may
1538 // return, we should process them here
1544 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1545 if ( !name
.empty() )
1552 wxFAIL_MSG( wxT("unknown keyboard accel") );
1561 #endif // wxUSE_ACCEL
1563 // ----------------------------------------------------------------------------
1564 // Pop-up menu stuff
1565 // ----------------------------------------------------------------------------
1567 #if wxUSE_MENUS_NATIVE
1569 extern "C" WXDLLIMPEXP_CORE
1570 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1572 *is_waiting
= false;
1575 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1577 menu
->SetInvokingWindow( win
);
1579 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1582 wxMenuItem
*menuitem
= node
->GetData();
1583 if (menuitem
->IsSubMenu())
1585 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1588 node
= node
->GetNext();
1592 extern "C" WXDLLIMPEXP_CORE
1593 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1595 gboolean
* WXUNUSED(whatever
),
1596 gpointer user_data
)
1598 // ensure that the menu appears entirely on screen
1600 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1602 wxSize sizeScreen
= wxGetDisplaySize();
1603 wxPoint
*pos
= (wxPoint
*)user_data
;
1605 gint xmax
= sizeScreen
.x
- req
.width
,
1606 ymax
= sizeScreen
.y
- req
.height
;
1608 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1609 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1612 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1614 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1616 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1618 // NOTE: if you change this code, you need to update
1619 // the same code in taskbar.cpp as well. This
1620 // is ugly code duplication, I know.
1622 SetInvokingWindow( menu
, this );
1626 bool is_waiting
= true;
1628 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1629 G_CALLBACK (gtk_pop_hide_callback
),
1634 GtkMenuPositionFunc posfunc
;
1635 if ( x
== -1 && y
== -1 )
1637 // use GTK's default positioning algorithm
1643 pos
= ClientToScreen(wxPoint(x
, y
));
1645 posfunc
= wxPopupMenuPositionCallback
;
1648 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1649 DoCommonMenuCallbackCode(menu
, eventOpen
);
1652 GTK_MENU(menu
->m_menu
),
1653 (GtkWidget
*) NULL
, // parent menu shell
1654 (GtkWidget
*) NULL
, // parent menu item
1655 posfunc
, // function to position it
1656 userdata
, // client data
1657 0, // button used to activate it
1658 gtk_get_current_event_time()
1663 gtk_main_iteration();
1666 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1668 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1669 DoCommonMenuCallbackCode(menu
, eventClose
);
1674 #endif // wxUSE_MENUS_NATIVE
1678 #include <gtk/gtk.h>
1680 const char *wxGetStockGtkID(wxWindowID id
)
1682 #define STOCKITEM(wx,gtk) \
1686 #define STOCKITEM_MISSING(wx) \
1690 #if GTK_CHECK_VERSION(2,4,0)
1691 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1693 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1696 #if GTK_CHECK_VERSION(2,6,0)
1697 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1699 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1702 #if GTK_CHECK_VERSION(2,10,0)
1703 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1705 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1711 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1712 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1713 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1714 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1715 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1716 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1717 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1718 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1719 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1720 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1721 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1722 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1723 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1724 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1725 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1726 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1727 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1728 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1729 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1730 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1731 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1732 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1733 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1734 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1735 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1736 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1737 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1738 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1739 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1740 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1741 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1742 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1743 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1744 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1745 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1746 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1747 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1748 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1749 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1750 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1751 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1752 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1753 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1754 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1755 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1756 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1757 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1758 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1759 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1760 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1761 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1762 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1763 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1764 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1767 wxFAIL_MSG( _T("invalid stock item ID") );
1776 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1781 GtkStockItem stock_item
;
1782 if (gtk_stock_lookup (id
, &stock_item
))
1784 if (key
) *key
= stock_item
.keyval
;
1785 if (mod
) *mod
= stock_item
.modifier
;
1787 // some GTK stock items have zero values for the keyval;
1788 // it means that they do not have an accelerator...
1789 if (stock_item
.keyval
)
1796 #endif // __WXGTK20__
1798 #endif // wxUSE_MENUS