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"
29 // FIXME: is this right? somehow I don't think so (VZ)
31 #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
32 #define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
33 //#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
35 #define ACCEL_OBJECT GtkWindow
36 #define ACCEL_OBJECTS(a) (a)->acceleratables
37 #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
39 // we use normal item but with a special id for the menu title
40 static const int wxGTK_TITLE_ID
= -3;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
47 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 static wxString
wxReplaceUnderscore( const wxString
& title
)
56 // GTK 1.2 wants to have "_" instead of "&" for accelerators
59 for ( wxString::const_iterator pc
= title
.begin(); pc
!= title
.end(); ++pc
)
61 if ((*pc
== wxT('&')) && (pc
+1 != title
.end()) && (*(pc
+1) == wxT('&')))
63 // "&" is doubled to indicate "&" instead of accelerator
67 else if (*pc
== wxT('&'))
73 if ( *pc
== wxT('_') )
75 // underscores must be doubled to prevent them from being
76 // interpreted as accelerator character prefix by GTK
84 // wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() );
89 static wxString
wxConvertFromGTKToWXLabel(const wxString
& gtkLabel
)
92 for ( const wxChar
*pc
= gtkLabel
.c_str(); *pc
; pc
++ )
94 // '_' is the escape character for GTK+.
96 if ( *pc
== wxT('_') && *(pc
+1) == wxT('_'))
98 // An underscore was escaped.
102 else if ( *pc
== wxT('_') )
104 // Convert GTK+ hotkey symbol to wxWidgets/Windows standard
107 else if ( *pc
== wxT('&') )
109 // Double the ampersand to escape it as far as wxWidgets is concerned
114 // don't remove ampersands '&' since if we have them in the menu title
115 // it means that they were doubled to indicate "&" instead of accelerator
123 //-----------------------------------------------------------------------------
124 // activate message from GTK
125 //-----------------------------------------------------------------------------
127 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
129 event
.SetEventObject( menu
);
131 wxEvtHandler
* handler
= menu
->GetEventHandler();
132 if (handler
&& handler
->ProcessEvent(event
))
135 wxWindow
*win
= menu
->GetInvokingWindow();
137 win
->GetEventHandler()->ProcessEvent( event
);
143 gtk_menu_open_callback(GtkWidget
* WXUNUSED(widget
), wxMenu
*menu
)
145 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
147 DoCommonMenuCallbackCode(menu
, event
);
151 gtk_menu_close_callback(GtkWidget
* WXUNUSED(widget
), wxMenuBar
*menubar
)
153 if ( !menubar
->GetMenuCount() )
155 // if menubar is empty we can't call GetMenu(0) below
159 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
161 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
166 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
170 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
172 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
175 m_invokingWindow
= NULL
;
177 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
178 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
180 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
184 m_menubar
= gtk_menu_bar_new();
186 if (style
& wxMB_DOCKABLE
)
188 m_widget
= gtk_handle_box_new();
189 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
190 gtk_widget_show(m_menubar
);
194 m_widget
= m_menubar
;
201 for (size_t i
= 0; i
< n
; ++i
)
202 Append(menus
[i
], titles
[i
]);
204 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
205 // don't get it when the menu is dismissed by clicking outside the
206 // toolbar) so we connect to the global one, even if it means that we
207 // can't pass the menu which was closed in wxMenuEvent object
208 g_signal_connect (m_menubar
, "deactivate",
209 G_CALLBACK (gtk_menu_close_callback
), this);
213 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
215 Init(n
, menus
, titles
, style
);
218 wxMenuBar::wxMenuBar(long style
)
220 Init(0, NULL
, NULL
, style
);
223 wxMenuBar::wxMenuBar()
225 Init(0, NULL
, NULL
, 0);
228 wxMenuBar::~wxMenuBar()
232 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
234 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
236 wxWindow
*top_frame
= win
;
237 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
238 top_frame
= top_frame
->GetParent();
240 // support for native hot keys
241 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
242 if ( menu
->m_accel
&& g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
243 gtk_accel_group_detach( menu
->m_accel
, obj
);
245 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
248 wxMenuItem
*menuitem
= node
->GetData();
249 if (menuitem
->IsSubMenu())
250 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
251 node
= node
->GetNext();
255 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
257 menu
->SetInvokingWindow( win
);
259 wxWindow
*top_frame
= win
;
260 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
261 top_frame
= top_frame
->GetParent();
263 // support for native hot keys
264 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
265 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
266 gtk_accel_group_attach( menu
->m_accel
, obj
);
268 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
271 wxMenuItem
*menuitem
= node
->GetData();
272 if (menuitem
->IsSubMenu())
273 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
274 node
= node
->GetNext();
278 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
280 m_invokingWindow
= win
;
281 wxWindow
*top_frame
= win
;
282 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
283 top_frame
= top_frame
->GetParent();
285 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
288 wxMenu
*menu
= node
->GetData();
289 wxMenubarSetInvokingWindow( menu
, win
);
290 node
= node
->GetNext();
294 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
296 if ( dir
== wxLayout_Default
)
298 const wxWindow
*const frame
= GetFrame();
301 // inherit layout from frame.
302 dir
= frame
->GetLayoutDirection();
304 else // use global layout
306 dir
= wxTheApp
->GetLayoutDirection();
310 if ( dir
== wxLayout_Default
)
313 GTKSetLayout(m_menubar
, dir
);
315 // also set the layout of all menus we already have (new ones will inherit
316 // the current layout)
317 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
319 node
= node
->GetNext() )
321 wxMenu
*const menu
= node
->GetData();
322 menu
->SetLayoutDirection(dir
);
326 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
328 return GTKGetLayout(m_menubar
);
331 void wxMenuBar::Attach(wxFrame
*frame
)
333 wxMenuBarBase::Attach(frame
);
335 SetLayoutDirection(wxLayout_Default
);
338 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
340 m_invokingWindow
= (wxWindow
*) NULL
;
341 wxWindow
*top_frame
= win
;
342 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
343 top_frame
= top_frame
->GetParent();
345 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
348 wxMenu
*menu
= node
->GetData();
349 wxMenubarUnsetInvokingWindow( menu
, win
);
350 node
= node
->GetNext();
354 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
356 if ( !wxMenuBarBase::Append( menu
, title
) )
359 return GtkAppend(menu
, title
);
362 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
364 wxString
str( wxReplaceUnderscore( title
) );
366 // This doesn't have much effect right now.
367 menu
->SetTitle( str
);
369 // The "m_owner" is the "menu item"
370 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
371 menu
->SetLayoutDirection(GetLayoutDirection());
373 gtk_widget_show( menu
->m_owner
);
375 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
378 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
380 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
382 g_signal_connect (menu
->m_owner
, "activate",
383 G_CALLBACK (gtk_menu_open_callback
),
386 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
387 // addings menu later on.
388 if (m_invokingWindow
)
389 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
394 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
396 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
401 if ( !GtkAppend(menu
, title
, (int)pos
) )
407 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
409 // remove the old item and insert a new one
410 wxMenu
*menuOld
= Remove(pos
);
411 if ( menuOld
&& !Insert(pos
, menu
, title
) )
413 return (wxMenu
*) NULL
;
416 // either Insert() succeeded or Remove() failed and menuOld is NULL
420 wxMenu
*wxMenuBar::Remove(size_t pos
)
422 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
424 return (wxMenu
*) NULL
;
426 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
427 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
429 gtk_widget_destroy( menu
->m_owner
);
430 menu
->m_owner
= NULL
;
432 if (m_invokingWindow
)
433 wxMenubarUnsetInvokingWindow( menu
, m_invokingWindow
);
438 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
440 if (wxMenuItem::GetLabelText(wxConvertFromGTKToWXLabel(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
442 int res
= menu
->FindItem( itemString
);
443 if (res
!= wxNOT_FOUND
)
447 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
450 wxMenuItem
*item
= node
->GetData();
451 if (item
->IsSubMenu())
452 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
454 node
= node
->GetNext();
460 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
462 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
465 wxMenu
*menu
= node
->GetData();
466 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
469 node
= node
->GetNext();
475 // Find a wxMenuItem using its id. Recurses down into sub-menus
476 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
478 wxMenuItem
* result
= menu
->FindChildItem(id
);
480 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
481 while ( node
&& result
== NULL
)
483 wxMenuItem
*item
= node
->GetData();
484 if (item
->IsSubMenu())
486 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
488 node
= node
->GetNext();
494 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
496 wxMenuItem
* result
= 0;
497 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
498 while (node
&& result
== 0)
500 wxMenu
*menu
= node
->GetData();
501 result
= FindMenuItemByIdRecursive( menu
, id
);
502 node
= node
->GetNext();
507 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
513 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
515 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
517 wxCHECK_RET( node
, wxT("menu not found") );
519 wxMenu
* menu
= node
->GetData();
522 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
525 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
527 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
529 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
531 wxMenu
* menu
= node
->GetData();
533 return wxConvertFromGTKToWXLabel(menu
->GetTitle());
536 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
538 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
540 wxCHECK_RET( node
, wxT("menu not found") );
542 wxMenu
* menu
= node
->GetData();
544 const wxString
str( wxReplaceUnderscore( label
) );
546 menu
->SetTitle( str
);
549 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
552 //-----------------------------------------------------------------------------
554 //-----------------------------------------------------------------------------
557 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
559 int id
= menu
->FindMenuIdByMenuItem(widget
);
561 /* should find it for normal (not popup) menu */
562 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
563 _T("menu item not found in gtk_menu_clicked_callback") );
565 if (!menu
->IsEnabled(id
))
568 wxMenuItem
* item
= menu
->FindChildItem( id
);
569 wxCHECK_RET( item
, wxT("error in menu item callback") );
571 if ( item
->GetId() == wxGTK_TITLE_ID
)
573 // ignore events from the menu title
577 if (item
->IsCheckable())
579 bool isReallyChecked
= item
->IsChecked(),
580 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
582 // ensure that the internal state is always consistent with what is
583 // shown on the screen
584 item
->wxMenuItemBase::Check(isReallyChecked
);
586 // we must not report the events for the radio button going up nor the
587 // events resulting from the calls to wxMenuItem::Check()
588 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
589 (isInternallyChecked
== isReallyChecked
) )
596 // Is this menu on a menubar? (possibly nested)
597 wxFrame
* frame
= NULL
;
598 if(menu
->IsAttached())
599 frame
= menu
->GetMenuBar()->GetFrame();
601 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
602 // normally wxMenu::SendEvent() should be enough, if it doesn't work
603 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
604 // should be fixed instead of working around it here...
607 // If it is attached then let the frame send the event.
608 // Don't call frame->ProcessCommand(id) because it toggles
609 // checkable items and we've already done that above.
610 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
611 commandEvent
.SetEventObject(frame
);
612 if (item
->IsCheckable())
613 commandEvent
.SetInt(item
->IsChecked());
615 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
619 // otherwise let the menu have it
620 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
625 //-----------------------------------------------------------------------------
627 //-----------------------------------------------------------------------------
630 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
632 int id
= menu
->FindMenuIdByMenuItem(widget
);
634 wxASSERT( id
!= -1 ); // should find it!
636 if (!menu
->IsEnabled(id
))
639 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
640 event
.SetEventObject( menu
);
642 wxEvtHandler
* handler
= menu
->GetEventHandler();
643 if (handler
&& handler
->ProcessEvent(event
))
646 wxWindow
*win
= menu
->GetInvokingWindow();
647 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
651 //-----------------------------------------------------------------------------
653 //-----------------------------------------------------------------------------
656 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
658 int id
= menu
->FindMenuIdByMenuItem(widget
);
660 wxASSERT( id
!= -1 ); // should find it!
662 if (!menu
->IsEnabled(id
))
665 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
666 event
.SetEventObject( menu
);
668 wxEvtHandler
* handler
= menu
->GetEventHandler();
669 if (handler
&& handler
->ProcessEvent(event
))
672 wxWindow
*win
= menu
->GetInvokingWindow();
674 win
->GetEventHandler()->ProcessEvent( event
);
678 //-----------------------------------------------------------------------------
680 //-----------------------------------------------------------------------------
682 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
684 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
686 const wxString
& name
,
687 const wxString
& help
,
691 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
694 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
696 const wxString
& text
,
697 const wxString
& help
,
700 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
705 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
707 const wxString
& text
,
708 const wxString
& help
,
711 : wxMenuItemBase(parentMenu
, id
, text
, help
,
712 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
717 void wxMenuItem::Init(const wxString
& text
)
719 m_labelWidget
= (GtkWidget
*) NULL
;
720 m_menuItem
= (GtkWidget
*) NULL
;
725 wxMenuItem::~wxMenuItem()
727 // don't delete menu items, the menus take care of that
730 // return the menu item text without any menu accels
733 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
735 // The argument to this function will now always be in wxWidgets standard label
736 // format, not GTK+ format, so we do what the other ports do.
738 return wxStripMenuCodes(text
);
743 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
745 if ( *pc
== wxT('\t'))
748 if ( *pc
== wxT('_') )
750 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
756 if ( *pc
== wxT('\\') )
758 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
764 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
767 // "&" is doubled to indicate "&" instead of accelerator
774 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
780 wxString
wxMenuItem::GetItemLabel() const
782 wxString label
= wxConvertFromGTKToWXLabel(m_text
);
783 if (!m_hotKey
.IsEmpty())
784 label
= label
+ wxT("\t") + m_hotKey
;
788 void wxMenuItem::SetItemLabel( const wxString
& str
)
790 // cache some data which must be used later
791 bool isstock
= wxIsStockID(GetId());
792 const char *stockid
= NULL
;
794 stockid
= wxGetStockGtkID(GetId());
796 // Some optimization to avoid flicker
797 wxString oldLabel
= m_text
;
798 oldLabel
= wxStripMenuCodes(oldLabel
);
799 oldLabel
.Replace(wxT("_"), wxT(""));
800 wxString label1
= wxStripMenuCodes(str
);
801 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
802 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
806 if (oldLabel
== label1
&&
807 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
814 label
= (GtkLabel
*) m_labelWidget
;
816 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
818 // stock menu items can have empty labels:
819 wxString text
= m_text
;
820 if (text
.IsEmpty() && !IsSeparator())
822 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
823 text
= wxGetStockLabel(GetId());
825 // need & => _ conversion
826 text
= GTKProcessMenuItemLabel(text
, NULL
);
829 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
832 // remove old accelerator from our parent's accelerator group, if present
834 GdkModifierType accel_mods
;
835 if (oldbuf
[(size_t)0] != '\0')
837 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
840 gtk_widget_remove_accelerator(m_menuItem
,
841 m_parentMenu
->m_accel
,
848 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
849 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
850 gtk_widget_remove_accelerator( m_menuItem
,
851 m_parentMenu
->m_accel
,
856 // add new accelerator to our parent's accelerator group
857 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
858 if (buf
[(size_t)0] != '\0')
860 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
863 gtk_widget_add_accelerator( m_menuItem
,
865 m_parentMenu
->m_accel
,
873 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
874 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
875 gtk_widget_remove_accelerator( m_menuItem
,
876 m_parentMenu
->m_accel
,
882 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
883 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
884 // so there's no real code duplication
885 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
889 // '\t' is the deliminator indicating a hot key
890 wxString::const_iterator pc
= str
.begin();
891 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
895 wxString::const_iterator next
= pc
+ 1;
896 if (next
!= str
.end() && *next
== wxT('&'))
898 // "&" is doubled to indicate "&" instead of accelerator
907 else if ( *pc
== wxT('_') ) // escape underscores
924 hotKey
->assign(pc
, str
.end());
931 // it's valid for this function to be called even if m_menuItem == NULL
932 void wxMenuItem::DoSetText( const wxString
& str
)
935 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
940 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
948 // accelerator parsing code looks for them after a TAB, so insert a dummy
951 label
<< wxT('\t') << GetHotKey();
953 return wxAcceleratorEntry::Create(label
);
956 #endif // wxUSE_ACCEL
958 void wxMenuItem::Check( bool check
)
960 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
962 if (check
== m_isChecked
)
965 wxMenuItemBase::Check( check
);
971 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
975 wxFAIL_MSG( _T("can't check this item") );
979 void wxMenuItem::Enable( bool enable
)
981 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
983 gtk_widget_set_sensitive( m_menuItem
, enable
);
984 wxMenuItemBase::Enable( enable
);
987 bool wxMenuItem::IsChecked() const
989 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
991 wxCHECK_MSG( IsCheckable(), false,
992 wxT("can't get state of uncheckable item!") );
994 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
997 //-----------------------------------------------------------------------------
999 //-----------------------------------------------------------------------------
1001 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
1005 m_accel
= gtk_accel_group_new();
1006 m_menu
= gtk_menu_new();
1007 // NB: keep reference to the menu so that it is not destroyed behind
1008 // our back by GTK+ e.g. when it is removed from menubar:
1009 gtk_widget_ref(m_menu
);
1011 m_owner
= (GtkWidget
*) NULL
;
1013 // Tearoffs are entries, just like separators. So if we want this
1014 // menu to be a tear-off one, we just append a tearoff entry
1016 if ( m_style
& wxMENU_TEAROFF
)
1018 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
1020 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
1025 // append the title as the very first entry if we have it
1026 if ( !m_title
.empty() )
1028 Append(wxGTK_TITLE_ID
, m_title
);
1035 if ( GTK_IS_WIDGET( m_menu
))
1038 gtk_widget_unref( m_menu
);
1039 g_object_unref( m_accel
);
1041 // if the menu is inserted in another menu at this time, there was
1042 // one more reference to it:
1044 gtk_widget_destroy( m_menu
);
1047 // This must come after we release GTK resources above. Otherwise, GTK will
1048 // give warnings/errors when attempting to free accelerator resources from
1049 // child items that just were destroyed (the m_menu widget can contain
1050 // references to accelerators in child items. Problem detected when removing
1051 // a menu from a wxMenuBar, and the removed menu had submenus with accelerators.)
1052 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1055 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1058 wxWindow::GTKSetLayout(m_owner
, dir
);
1059 //else: will be called later by wxMenuBar again
1062 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1064 return wxWindow::GTKGetLayout(m_owner
);
1067 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1069 GtkWidget
*menuItem
;
1071 // cache some data used later
1072 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1073 int id
= mitem
->GetId();
1074 bool isstock
= wxIsStockID(id
);
1075 const char *stockid
= NULL
;
1077 stockid
= wxGetStockGtkID(mitem
->GetId());
1079 // stock menu items can have an empty label
1080 if (text
.IsEmpty() && !mitem
->IsSeparator())
1082 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1083 text
= wxGetStockLabel(id
);
1085 // need & => _ conversion
1086 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1089 if ( mitem
->IsSeparator() )
1091 menuItem
= gtk_separator_menu_item_new();
1093 else if ( mitem
->GetBitmap().Ok() ||
1094 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1096 wxBitmap
bitmap(mitem
->GetBitmap());
1098 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1103 // use stock bitmap for this item if available on the assumption
1104 // that it never hurts to follow GTK+ conventions more closely
1105 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1108 else // we have a custom bitmap
1110 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1111 _T("only normal menu items can have bitmaps") );
1113 if ( bitmap
.HasPixbuf() )
1115 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1119 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1120 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1121 bitmap
.GetMask()->GetBitmap() :
1123 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1129 gtk_widget_show(image
);
1131 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1136 else // a normal item
1138 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1141 switch ( mitem
->GetKind() )
1145 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1152 GSList
*group
= NULL
;
1153 if ( m_prevRadio
== NULL
)
1155 // start of a new radio group
1156 m_prevRadio
= menuItem
=
1157 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1159 else // continue the radio group
1161 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1162 m_prevRadio
= menuItem
=
1163 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1169 wxFAIL_MSG( _T("unexpected menu item kind") );
1174 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1183 GdkModifierType accel_mods
;
1184 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1186 // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetItemLabel().c_str(), GetGtkHotKey(*mitem).c_str() );
1187 if (buf
[(size_t)0] != '\0')
1189 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1192 gtk_widget_add_accelerator (menuItem
,
1202 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1203 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1204 gtk_widget_add_accelerator( menuItem
,
1213 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1215 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1217 gtk_widget_show( menuItem
);
1219 if ( !mitem
->IsSeparator() )
1221 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1223 g_signal_connect (menuItem
, "select",
1224 G_CALLBACK (gtk_menu_hilight_callback
), this);
1225 g_signal_connect (menuItem
, "deselect",
1226 G_CALLBACK (gtk_menu_nolight_callback
), this);
1228 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1230 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1232 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1234 // if adding a submenu to a menu already existing in the menu bar, we
1235 // must set invoking window to allow processing events from this
1237 if ( m_invokingWindow
)
1238 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1242 g_signal_connect (menuItem
, "activate",
1243 G_CALLBACK (gtk_menu_clicked_callback
),
1248 mitem
->SetMenuItem(menuItem
);
1252 // This doesn't even exist!
1253 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1259 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1261 if (!GtkAppend(mitem
))
1264 return wxMenuBase::DoAppend(mitem
);
1267 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1269 if ( !wxMenuBase::DoInsert(pos
, item
) )
1273 if ( !GtkAppend(item
, (int)pos
) )
1279 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1281 if ( !wxMenuBase::DoRemove(item
) )
1282 return (wxMenuItem
*)NULL
;
1284 // TODO: this code doesn't delete the item factory item and this seems
1285 // impossible as of GTK 1.2.6.
1286 gtk_widget_destroy( item
->GetMenuItem() );
1291 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1293 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1296 wxMenuItem
*item
= node
->GetData();
1297 if (item
->GetMenuItem() == menuItem
)
1298 return item
->GetId();
1299 node
= node
->GetNext();
1305 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1307 wxMenuBase::Attach(menubar
);
1309 // inherit layout direction from menubar.
1310 SetLayoutDirection(menubar
->GetLayoutDirection());
1313 // ----------------------------------------------------------------------------
1315 // ----------------------------------------------------------------------------
1319 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1323 wxAcceleratorEntry
*accel
= item
.GetAccel();
1326 int flags
= accel
->GetFlags();
1327 if ( flags
& wxACCEL_ALT
)
1328 hotkey
+= wxT("<alt>");
1329 if ( flags
& wxACCEL_CTRL
)
1330 hotkey
+= wxT("<control>");
1331 if ( flags
& wxACCEL_SHIFT
)
1332 hotkey
+= wxT("<shift>");
1334 int code
= accel
->GetKeyCode();
1361 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1364 // TODO: we should use gdk_keyval_name() (a.k.a.
1365 // XKeysymToString) here as well as hardcoding the keysym
1366 // names this might be not portable
1368 hotkey
<< wxT("Insert" );
1371 hotkey
<< wxT("Delete" );
1374 hotkey
<< wxT("Up" );
1377 hotkey
<< wxT("Down" );
1380 hotkey
<< wxT("Page_Up" );
1383 hotkey
<< wxT("Page_Down" );
1386 hotkey
<< wxT("Left" );
1389 hotkey
<< wxT("Right" );
1392 hotkey
<< wxT("Home" );
1395 hotkey
<< wxT("End" );
1398 hotkey
<< wxT("Return" );
1401 hotkey
<< wxT("BackSpace" );
1404 hotkey
<< wxT("Tab" );
1407 hotkey
<< wxT("Esc" );
1410 hotkey
<< wxT("space" );
1413 hotkey
<< wxT("Multiply" );
1416 hotkey
<< wxT("Add" );
1419 hotkey
<< wxT("Separator" );
1422 hotkey
<< wxT("Subtract" );
1425 hotkey
<< wxT("Decimal" );
1428 hotkey
<< wxT("Divide" );
1431 hotkey
<< wxT("Cancel" );
1434 hotkey
<< wxT("Clear" );
1437 hotkey
<< wxT("Menu" );
1440 hotkey
<< wxT("Pause" );
1443 hotkey
<< wxT("Capital" );
1446 hotkey
<< wxT("Select" );
1449 hotkey
<< wxT("Print" );
1452 hotkey
<< wxT("Execute" );
1455 hotkey
<< wxT("Snapshot" );
1458 hotkey
<< wxT("Help" );
1461 hotkey
<< wxT("Num_Lock" );
1464 hotkey
<< wxT("Scroll_Lock" );
1466 case WXK_NUMPAD_INSERT
:
1467 hotkey
<< wxT("KP_Insert" );
1469 case WXK_NUMPAD_DELETE
:
1470 hotkey
<< wxT("KP_Delete" );
1472 case WXK_NUMPAD_SPACE
:
1473 hotkey
<< wxT("KP_Space" );
1475 case WXK_NUMPAD_TAB
:
1476 hotkey
<< wxT("KP_Tab" );
1478 case WXK_NUMPAD_ENTER
:
1479 hotkey
<< wxT("KP_Enter" );
1481 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1483 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1485 case WXK_NUMPAD_HOME
:
1486 hotkey
<< wxT("KP_Home" );
1488 case WXK_NUMPAD_LEFT
:
1489 hotkey
<< wxT("KP_Left" );
1492 hotkey
<< wxT("KP_Up" );
1494 case WXK_NUMPAD_RIGHT
:
1495 hotkey
<< wxT("KP_Right" );
1497 case WXK_NUMPAD_DOWN
:
1498 hotkey
<< wxT("KP_Down" );
1500 case WXK_NUMPAD_PAGEUP
:
1501 hotkey
<< wxT("KP_Page_Up" );
1503 case WXK_NUMPAD_PAGEDOWN
:
1504 hotkey
<< wxT("KP_Page_Down" );
1506 case WXK_NUMPAD_END
:
1507 hotkey
<< wxT("KP_End" );
1509 case WXK_NUMPAD_BEGIN
:
1510 hotkey
<< wxT("KP_Begin" );
1512 case WXK_NUMPAD_EQUAL
:
1513 hotkey
<< wxT("KP_Equal" );
1515 case WXK_NUMPAD_MULTIPLY
:
1516 hotkey
<< wxT("KP_Multiply" );
1518 case WXK_NUMPAD_ADD
:
1519 hotkey
<< wxT("KP_Add" );
1521 case WXK_NUMPAD_SEPARATOR
:
1522 hotkey
<< wxT("KP_Separator" );
1524 case WXK_NUMPAD_SUBTRACT
:
1525 hotkey
<< wxT("KP_Subtract" );
1527 case WXK_NUMPAD_DECIMAL
:
1528 hotkey
<< wxT("KP_Decimal" );
1530 case WXK_NUMPAD_DIVIDE
:
1531 hotkey
<< wxT("KP_Divide" );
1533 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1534 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1535 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1536 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1538 case WXK_WINDOWS_LEFT
:
1539 hotkey
<< wxT("Super_L" );
1541 case WXK_WINDOWS_RIGHT
:
1542 hotkey
<< wxT("Super_R" );
1544 case WXK_WINDOWS_MENU
:
1545 hotkey
<< wxT("Menu" );
1548 hotkey
<< wxT("Command" );
1550 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1551 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1552 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1553 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1554 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1555 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1556 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1559 // if there are any other keys wxAcceleratorEntry::Create() may
1560 // return, we should process them here
1566 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1567 if ( !name
.empty() )
1574 wxFAIL_MSG( wxT("unknown keyboard accel") );
1583 #endif // wxUSE_ACCEL
1585 // ----------------------------------------------------------------------------
1586 // Pop-up menu stuff
1587 // ----------------------------------------------------------------------------
1589 #if wxUSE_MENUS_NATIVE
1591 extern "C" WXDLLIMPEXP_CORE
1592 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1594 *is_waiting
= false;
1597 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1599 menu
->SetInvokingWindow( win
);
1601 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1604 wxMenuItem
*menuitem
= node
->GetData();
1605 if (menuitem
->IsSubMenu())
1607 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1610 node
= node
->GetNext();
1614 extern "C" WXDLLIMPEXP_CORE
1615 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1617 gboolean
* WXUNUSED(whatever
),
1618 gpointer user_data
)
1620 // ensure that the menu appears entirely on screen
1622 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1624 wxSize sizeScreen
= wxGetDisplaySize();
1625 wxPoint
*pos
= (wxPoint
*)user_data
;
1627 gint xmax
= sizeScreen
.x
- req
.width
,
1628 ymax
= sizeScreen
.y
- req
.height
;
1630 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1631 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1634 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1636 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1638 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1640 // NOTE: if you change this code, you need to update
1641 // the same code in taskbar.cpp as well. This
1642 // is ugly code duplication, I know.
1644 SetInvokingWindow( menu
, this );
1648 bool is_waiting
= true;
1650 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1651 G_CALLBACK (gtk_pop_hide_callback
),
1656 GtkMenuPositionFunc posfunc
;
1657 if ( x
== -1 && y
== -1 )
1659 // use GTK's default positioning algorithm
1665 pos
= ClientToScreen(wxPoint(x
, y
));
1667 posfunc
= wxPopupMenuPositionCallback
;
1670 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1671 DoCommonMenuCallbackCode(menu
, eventOpen
);
1674 GTK_MENU(menu
->m_menu
),
1675 (GtkWidget
*) NULL
, // parent menu shell
1676 (GtkWidget
*) NULL
, // parent menu item
1677 posfunc
, // function to position it
1678 userdata
, // client data
1679 0, // button used to activate it
1680 gtk_get_current_event_time()
1685 gtk_main_iteration();
1688 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1690 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1691 DoCommonMenuCallbackCode(menu
, eventClose
);
1696 #endif // wxUSE_MENUS_NATIVE
1700 #include <gtk/gtk.h>
1702 const char *wxGetStockGtkID(wxWindowID id
)
1704 #define STOCKITEM(wx,gtk) \
1708 #define STOCKITEM_MISSING(wx) \
1712 #if GTK_CHECK_VERSION(2,4,0)
1713 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1715 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1718 #if GTK_CHECK_VERSION(2,6,0)
1719 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1721 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1724 #if GTK_CHECK_VERSION(2,10,0)
1725 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1727 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1733 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1734 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1735 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1736 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1737 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1738 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1739 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1740 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1741 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1742 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1743 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1744 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1745 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1746 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1747 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1748 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1749 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1750 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1751 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1752 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1753 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1754 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1755 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1756 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1757 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1758 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1759 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1760 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1761 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1762 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1763 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1764 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1765 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1766 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1767 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1768 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1769 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1770 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1771 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1772 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1773 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1774 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1775 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1776 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1777 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1778 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1779 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1780 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1781 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1782 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1783 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1784 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1785 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1786 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1789 wxFAIL_MSG( _T("invalid stock item ID") );
1798 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1803 GtkStockItem stock_item
;
1804 if (gtk_stock_lookup (id
, &stock_item
))
1806 if (key
) *key
= stock_item
.keyval
;
1807 if (mod
) *mod
= stock_item
.modifier
;
1809 // some GTK stock items have zero values for the keyval;
1810 // it means that they do not have an accelerator...
1811 if (stock_item
.keyval
)
1818 #endif // __WXGTK20__
1820 #endif // wxUSE_MENUS