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
)
60 // GTK 1.2 wants to have "_" instead of "&" for accelerators
63 while (*pc
!= wxT('\0'))
65 if ((*pc
== wxT('&')) && (*(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
89 // wxPrintf( wxT("before %s after %s\n"), title.c_str(), str.c_str() );
94 //-----------------------------------------------------------------------------
95 // activate message from GTK
96 //-----------------------------------------------------------------------------
98 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
101 wxapp_install_idle_handler();
103 event
.SetEventObject( menu
);
105 wxEvtHandler
* handler
= menu
->GetEventHandler();
106 if (handler
&& handler
->ProcessEvent(event
))
109 wxWindow
*win
= menu
->GetInvokingWindow();
111 win
->GetEventHandler()->ProcessEvent( event
);
116 static void gtk_menu_open_callback( GtkWidget
*widget
, wxMenu
*menu
)
118 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
120 DoCommonMenuCallbackCode(menu
, event
);
123 static void gtk_menu_close_callback( GtkWidget
*widget
, wxMenuBar
*menubar
)
125 if ( !menubar
->GetMenuCount() )
127 // if menubar is empty we can't call GetMenu(0) below
131 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
133 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
138 //-----------------------------------------------------------------------------
140 //-----------------------------------------------------------------------------
142 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
144 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
146 // the parent window is known after wxFrame::SetMenu()
147 m_needParent
= false;
149 m_invokingWindow
= (wxWindow
*) NULL
;
151 if (!PreCreation( (wxWindow
*) NULL
, wxDefaultPosition
, wxDefaultSize
) ||
152 !CreateBase( (wxWindow
*) NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
154 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
158 m_menubar
= gtk_menu_bar_new();
160 if (style
& wxMB_DOCKABLE
)
162 m_widget
= gtk_handle_box_new();
163 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_menubar
) );
164 gtk_widget_show( GTK_WIDGET(m_menubar
) );
168 m_widget
= GTK_WIDGET(m_menubar
);
175 for (size_t i
= 0; i
< n
; ++i
)
176 Append(menus
[i
], titles
[i
]);
178 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
179 // don't get it when the menu is dismissed by clicking outside the
180 // toolbar) so we connect to the global one, even if it means that we
181 // can't pass the menu which was closed in wxMenuEvent object
182 g_signal_connect (m_menubar
, "deactivate",
183 G_CALLBACK (gtk_menu_close_callback
), this);
187 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
189 Init(n
, menus
, titles
, style
);
192 wxMenuBar::wxMenuBar(long style
)
194 Init(0, NULL
, NULL
, style
);
197 wxMenuBar::wxMenuBar()
199 Init(0, NULL
, NULL
, 0);
202 wxMenuBar::~wxMenuBar()
206 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
208 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
210 wxWindow
*top_frame
= win
;
211 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
212 top_frame
= top_frame
->GetParent();
214 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
217 wxMenuItem
*menuitem
= node
->GetData();
218 if (menuitem
->IsSubMenu())
219 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
220 node
= node
->GetNext();
224 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
226 menu
->SetInvokingWindow( win
);
228 wxWindow
*top_frame
= win
;
229 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
230 top_frame
= top_frame
->GetParent();
232 // support for native hot keys
233 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
234 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
235 gtk_accel_group_attach( menu
->m_accel
, obj
);
237 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
240 wxMenuItem
*menuitem
= node
->GetData();
241 if (menuitem
->IsSubMenu())
242 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
243 node
= node
->GetNext();
247 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
249 m_invokingWindow
= win
;
250 wxWindow
*top_frame
= win
;
251 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
252 top_frame
= top_frame
->GetParent();
254 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
257 wxMenu
*menu
= node
->GetData();
258 wxMenubarSetInvokingWindow( menu
, win
);
259 node
= node
->GetNext();
263 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
265 if ( dir
== wxLayout_Default
)
267 const wxWindow
*const frame
= GetFrame();
270 // inherit layout from frame.
271 dir
= frame
->GetLayoutDirection();
273 else // use global layout
275 dir
= wxTheApp
->GetLayoutDirection();
279 if ( dir
== wxLayout_Default
)
282 GTKSetLayout(m_menubar
, dir
);
284 // also set the layout of all menus we already have (new ones will inherit
285 // the current layout)
286 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
288 node
= node
->GetNext() )
290 wxMenu
*const menu
= node
->GetData();
291 menu
->SetLayoutDirection(dir
);
295 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
297 return GTKGetLayout(m_menubar
);
300 void wxMenuBar::Attach(wxFrame
*frame
)
302 wxMenuBarBase::Attach(frame
);
304 SetLayoutDirection(wxLayout_Default
);
307 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
309 m_invokingWindow
= (wxWindow
*) NULL
;
310 wxWindow
*top_frame
= win
;
311 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
312 top_frame
= top_frame
->GetParent();
314 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
317 wxMenu
*menu
= node
->GetData();
318 wxMenubarUnsetInvokingWindow( menu
, win
);
319 node
= node
->GetNext();
323 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
325 if ( !wxMenuBarBase::Append( menu
, title
) )
328 return GtkAppend(menu
, title
);
331 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
333 wxString
str( wxReplaceUnderscore( title
) );
335 // This doesn't have much effect right now.
336 menu
->SetTitle( str
);
338 // The "m_owner" is the "menu item"
339 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
340 menu
->SetLayoutDirection(GetLayoutDirection());
342 gtk_widget_show( menu
->m_owner
);
344 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
347 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
349 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
351 g_signal_connect (menu
->m_owner
, "activate",
352 G_CALLBACK (gtk_menu_open_callback
),
355 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
356 // addings menu later on.
357 if (m_invokingWindow
)
359 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
361 // OPTIMISE ME: we should probably cache this, or pass it
362 // directly, but for now this is a minimal
363 // change to validate the new dynamic sizing.
364 // see (and refactor :) similar code in Remove
367 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
370 frame
->UpdateMenuBarSize();
376 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
378 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
383 if ( !GtkAppend(menu
, title
, (int)pos
) )
389 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
391 // remove the old item and insert a new one
392 wxMenu
*menuOld
= Remove(pos
);
393 if ( menuOld
&& !Insert(pos
, menu
, title
) )
395 return (wxMenu
*) NULL
;
398 // either Insert() succeeded or Remove() failed and menuOld is NULL
402 wxMenu
*wxMenuBar::Remove(size_t pos
)
404 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
406 return (wxMenu
*) NULL
;
408 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
409 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
411 gtk_widget_destroy( menu
->m_owner
);
412 menu
->m_owner
= NULL
;
414 if (m_invokingWindow
)
416 // OPTIMISE ME: see comment in GtkAppend
417 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
420 frame
->UpdateMenuBarSize();
426 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
428 if (wxMenuItem::GetLabelFromText(menu
->GetTitle()) == wxMenuItem::GetLabelFromText(menuString
))
430 int res
= menu
->FindItem( itemString
);
431 if (res
!= wxNOT_FOUND
)
435 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
438 wxMenuItem
*item
= node
->GetData();
439 if (item
->IsSubMenu())
440 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
442 node
= node
->GetNext();
448 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
450 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
453 wxMenu
*menu
= node
->GetData();
454 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
457 node
= node
->GetNext();
463 // Find a wxMenuItem using its id. Recurses down into sub-menus
464 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
466 wxMenuItem
* result
= menu
->FindChildItem(id
);
468 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
469 while ( node
&& result
== NULL
)
471 wxMenuItem
*item
= node
->GetData();
472 if (item
->IsSubMenu())
474 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
476 node
= node
->GetNext();
482 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
484 wxMenuItem
* result
= 0;
485 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
486 while (node
&& result
== 0)
488 wxMenu
*menu
= node
->GetData();
489 result
= FindMenuItemByIdRecursive( menu
, id
);
490 node
= node
->GetNext();
495 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
501 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
503 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
505 wxCHECK_RET( node
, wxT("menu not found") );
507 wxMenu
* menu
= node
->GetData();
510 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
513 wxString
wxMenuBar::GetLabelTop( size_t pos
) const
515 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
517 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
519 wxMenu
* menu
= node
->GetData();
522 wxString
text( menu
->GetTitle() );
523 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
525 if ( *pc
== wxT('_') )
527 // '_' is the escape character for GTK+
531 // don't remove ampersands '&' since if we have them in the menu title
532 // it means that they were doubled to indicate "&" instead of accelerator
540 void wxMenuBar::SetLabelTop( size_t pos
, const wxString
& label
)
542 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
544 wxCHECK_RET( node
, wxT("menu not found") );
546 wxMenu
* menu
= node
->GetData();
548 const wxString
str( wxReplaceUnderscore( label
) );
550 menu
->SetTitle( str
);
553 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
556 //-----------------------------------------------------------------------------
558 //-----------------------------------------------------------------------------
561 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
564 wxapp_install_idle_handler();
566 int id
= menu
->FindMenuIdByMenuItem(widget
);
568 /* should find it for normal (not popup) menu */
569 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
570 _T("menu item not found in gtk_menu_clicked_callback") );
572 if (!menu
->IsEnabled(id
))
575 wxMenuItem
* item
= menu
->FindChildItem( id
);
576 wxCHECK_RET( item
, wxT("error in menu item callback") );
578 if ( item
->GetId() == wxGTK_TITLE_ID
)
580 // ignore events from the menu title
584 if (item
->IsCheckable())
586 bool isReallyChecked
= item
->IsChecked(),
587 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
589 // ensure that the internal state is always consistent with what is
590 // shown on the screen
591 item
->wxMenuItemBase::Check(isReallyChecked
);
593 // we must not report the events for the radio button going up nor the
594 // events resulting from the calls to wxMenuItem::Check()
595 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
596 (isInternallyChecked
== isReallyChecked
) )
603 // Is this menu on a menubar? (possibly nested)
604 wxFrame
* frame
= NULL
;
605 if(menu
->IsAttached())
606 frame
= menu
->GetMenuBar()->GetFrame();
608 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
609 // normally wxMenu::SendEvent() should be enough, if it doesn't work
610 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
611 // should be fixed instead of working around it here...
614 // If it is attached then let the frame send the event.
615 // Don't call frame->ProcessCommand(id) because it toggles
616 // checkable items and we've already done that above.
617 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
618 commandEvent
.SetEventObject(frame
);
619 if (item
->IsCheckable())
620 commandEvent
.SetInt(item
->IsChecked());
621 commandEvent
.SetEventObject(menu
);
623 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
627 // otherwise let the menu have it
628 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
633 //-----------------------------------------------------------------------------
635 //-----------------------------------------------------------------------------
638 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
640 if (g_isIdle
) wxapp_install_idle_handler();
642 int id
= menu
->FindMenuIdByMenuItem(widget
);
644 wxASSERT( id
!= -1 ); // should find it!
646 if (!menu
->IsEnabled(id
))
649 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
650 event
.SetEventObject( menu
);
652 wxEvtHandler
* handler
= menu
->GetEventHandler();
653 if (handler
&& handler
->ProcessEvent(event
))
656 wxWindow
*win
= menu
->GetInvokingWindow();
657 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
661 //-----------------------------------------------------------------------------
663 //-----------------------------------------------------------------------------
666 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
668 if (g_isIdle
) wxapp_install_idle_handler();
670 int id
= menu
->FindMenuIdByMenuItem(widget
);
672 wxASSERT( id
!= -1 ); // should find it!
674 if (!menu
->IsEnabled(id
))
677 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
678 event
.SetEventObject( menu
);
680 wxEvtHandler
* handler
= menu
->GetEventHandler();
681 if (handler
&& handler
->ProcessEvent(event
))
684 wxWindow
*win
= menu
->GetInvokingWindow();
686 win
->GetEventHandler()->ProcessEvent( event
);
690 //-----------------------------------------------------------------------------
692 //-----------------------------------------------------------------------------
694 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
696 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
698 const wxString
& name
,
699 const wxString
& help
,
703 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
706 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
708 const wxString
& text
,
709 const wxString
& help
,
712 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
717 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
719 const wxString
& text
,
720 const wxString
& help
,
723 : wxMenuItemBase(parentMenu
, id
, text
, help
,
724 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
729 void wxMenuItem::Init(const wxString
& text
)
731 m_labelWidget
= (GtkWidget
*) NULL
;
732 m_menuItem
= (GtkWidget
*) NULL
;
737 wxMenuItem::~wxMenuItem()
739 // don't delete menu items, the menus take care of that
742 // return the menu item text without any menu accels
744 wxString
wxMenuItemBase::GetLabelFromText(const wxString
& text
)
748 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
750 if ( *pc
== wxT('\t'))
753 if ( *pc
== wxT('_') )
755 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
761 if ( *pc
== wxT('\\') )
763 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
769 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
772 // "&" is doubled to indicate "&" instead of accelerator
779 // wxPrintf( wxT("GetLabelFromText(): text %s label %s\n"), text.c_str(), label.c_str() );
784 void wxMenuItem::SetText( const wxString
& str
)
786 // cache some data which must be used later
787 bool isstock
= wxIsStockID(GetId());
788 const char *stockid
= NULL
;
790 stockid
= wxGetStockGtkID(GetId());
792 // Some optimization to avoid flicker
793 wxString oldLabel
= m_text
;
794 oldLabel
= wxStripMenuCodes(oldLabel
);
795 oldLabel
.Replace(wxT("_"), wxT(""));
796 wxString label1
= wxStripMenuCodes(str
);
797 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
798 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
802 if (oldLabel
== label1
&&
803 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
810 label
= (GtkLabel
*) m_labelWidget
;
812 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
814 // stock menu items can have empty labels:
815 wxString text
= m_text
;
816 if (text
.IsEmpty() && !IsSeparator())
818 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
819 text
= wxGetStockLabel(GetId());
821 // need & => _ conversion
822 text
= GTKProcessMenuItemLabel(text
, NULL
);
825 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
828 // remove old accelerator from our parent's accelerator group, if present
830 GdkModifierType accel_mods
;
831 if (oldbuf
[(size_t)0] != '\0')
833 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
836 gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem
),
837 m_parentMenu
->m_accel
,
844 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
845 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
846 gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem
),
847 m_parentMenu
->m_accel
,
852 // add new accelerator to our parent's accelerator group
853 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
854 if (buf
[(size_t)0] != '\0')
856 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
859 gtk_widget_add_accelerator( GTK_WIDGET(m_menuItem
),
861 m_parentMenu
->m_accel
,
869 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
870 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
871 gtk_widget_remove_accelerator( GTK_WIDGET(m_menuItem
),
872 m_parentMenu
->m_accel
,
878 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
879 // implemented in control.cpp and from wxMenuItemBase::GetLabelFromText...
880 // so there's no real code duplication
881 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
885 // '\t' is the deliminator indicating a hot key
886 const wxChar
*pc
= str
;
887 while ( (*pc
!= wxT('\0')) && (*pc
!= wxT('\t')) )
889 if ((*pc
== wxT('&')) && (*(pc
+1) == wxT('&')))
891 // "&" is doubled to indicate "&" instead of accelerator
895 else if (*pc
== wxT('&'))
899 else if ( *pc
== wxT('_') ) // escape underscores
923 // it's valid for this function to be called even if m_menuItem == NULL
924 void wxMenuItem::DoSetText( const wxString
& str
)
927 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
932 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
940 // accelerator parsing code looks for them after a TAB, so insert a dummy
943 label
<< wxT('\t') << GetHotKey();
945 return wxAcceleratorEntry::Create(label
);
948 #endif // wxUSE_ACCEL
950 void wxMenuItem::Check( bool check
)
952 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
954 if (check
== m_isChecked
)
957 wxMenuItemBase::Check( check
);
963 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
967 wxFAIL_MSG( _T("can't check this item") );
971 void wxMenuItem::Enable( bool enable
)
973 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
975 gtk_widget_set_sensitive( m_menuItem
, enable
);
976 wxMenuItemBase::Enable( enable
);
979 bool wxMenuItem::IsChecked() const
981 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
983 wxCHECK_MSG( IsCheckable(), false,
984 wxT("can't get state of uncheckable item!") );
986 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
989 //-----------------------------------------------------------------------------
991 //-----------------------------------------------------------------------------
993 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
997 m_accel
= gtk_accel_group_new();
998 m_menu
= gtk_menu_new();
999 // NB: keep reference to the menu so that it is not destroyed behind
1000 // our back by GTK+ e.g. when it is removed from menubar:
1001 gtk_widget_ref(m_menu
);
1003 m_owner
= (GtkWidget
*) NULL
;
1005 // Tearoffs are entries, just like separators. So if we want this
1006 // menu to be a tear-off one, we just append a tearoff entry
1008 if ( m_style
& wxMENU_TEAROFF
)
1010 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
1012 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
1017 // append the title as the very first entry if we have it
1018 if ( !m_title
.empty() )
1020 Append(wxGTK_TITLE_ID
, m_title
);
1027 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1029 if ( GTK_IS_WIDGET( m_menu
))
1032 gtk_widget_unref( m_menu
);
1033 // if the menu is inserted in another menu at this time, there was
1034 // one more reference to it:
1036 gtk_widget_destroy( m_menu
);
1040 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1043 wxWindow::GTKSetLayout(m_owner
, dir
);
1044 //else: will be called later by wxMenuBar again
1047 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1049 return wxWindow::GTKGetLayout(m_owner
);
1052 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1054 GtkWidget
*menuItem
;
1056 // cache some data used later
1057 wxString text
= mitem
->GetText();
1058 int id
= mitem
->GetId();
1059 bool isstock
= wxIsStockID(id
);
1060 const char *stockid
= NULL
;
1062 stockid
= wxGetStockGtkID(mitem
->GetId());
1064 // stock menu items can have an empty label
1065 if (text
.IsEmpty() && !mitem
->IsSeparator())
1067 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1068 text
= wxGetStockLabel(id
);
1070 // need & => _ conversion
1071 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1074 if ( mitem
->IsSeparator() )
1076 menuItem
= gtk_separator_menu_item_new();
1078 else if ( mitem
->GetBitmap().Ok() ||
1079 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1081 wxBitmap
bitmap(mitem
->GetBitmap());
1083 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1088 // use stock bitmap for this item if available on the assumption
1089 // that it never hurts to follow GTK+ conventions more closely
1090 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1093 else // we have a custom bitmap
1095 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1096 _T("only normal menu items can have bitmaps") );
1098 if ( bitmap
.HasPixbuf() )
1100 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1104 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1105 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1106 bitmap
.GetMask()->GetBitmap() :
1108 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1114 gtk_widget_show(image
);
1116 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1121 else // a normal item
1123 // NB: 'text' variable has "_" instead of "&" after mitem->SetText()
1126 switch ( mitem
->GetKind() )
1130 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1137 GSList
*group
= NULL
;
1138 if ( m_prevRadio
== NULL
)
1140 // start of a new radio group
1141 m_prevRadio
= menuItem
=
1142 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1144 else // continue the radio group
1146 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1147 m_prevRadio
= menuItem
=
1148 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1154 wxFAIL_MSG( _T("unexpected menu item kind") );
1159 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1168 GdkModifierType accel_mods
;
1169 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1171 // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() );
1172 if (buf
[(size_t)0] != '\0')
1174 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1177 gtk_widget_add_accelerator (GTK_WIDGET(menuItem
),
1187 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1188 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1189 gtk_widget_add_accelerator( GTK_WIDGET(menuItem
),
1198 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1200 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1202 gtk_widget_show( menuItem
);
1204 if ( !mitem
->IsSeparator() )
1206 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1208 g_signal_connect (menuItem
, "select",
1209 G_CALLBACK (gtk_menu_hilight_callback
), this);
1210 g_signal_connect (menuItem
, "deselect",
1211 G_CALLBACK (gtk_menu_nolight_callback
), this);
1213 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1215 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1217 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1219 // if adding a submenu to a menu already existing in the menu bar, we
1220 // must set invoking window to allow processing events from this
1222 if ( m_invokingWindow
)
1223 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1227 g_signal_connect (menuItem
, "activate",
1228 G_CALLBACK (gtk_menu_clicked_callback
),
1233 mitem
->SetMenuItem(menuItem
);
1237 // This doesn't even exist!
1238 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1244 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1246 if (!GtkAppend(mitem
))
1249 return wxMenuBase::DoAppend(mitem
);
1252 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1254 if ( !wxMenuBase::DoInsert(pos
, item
) )
1258 if ( !GtkAppend(item
, (int)pos
) )
1264 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1266 if ( !wxMenuBase::DoRemove(item
) )
1267 return (wxMenuItem
*)NULL
;
1269 // TODO: this code doesn't delete the item factory item and this seems
1270 // impossible as of GTK 1.2.6.
1271 gtk_widget_destroy( item
->GetMenuItem() );
1276 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1278 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1281 wxMenuItem
*item
= node
->GetData();
1282 if (item
->GetMenuItem() == menuItem
)
1283 return item
->GetId();
1284 node
= node
->GetNext();
1290 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1292 wxMenuBase::Attach(menubar
);
1294 // inherit layout direction from menubar.
1295 SetLayoutDirection(menubar
->GetLayoutDirection());
1298 // ----------------------------------------------------------------------------
1300 // ----------------------------------------------------------------------------
1304 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1308 wxAcceleratorEntry
*accel
= item
.GetAccel();
1311 int flags
= accel
->GetFlags();
1312 if ( flags
& wxACCEL_ALT
)
1313 hotkey
+= wxT("<alt>");
1314 if ( flags
& wxACCEL_CTRL
)
1315 hotkey
+= wxT("<control>");
1316 if ( flags
& wxACCEL_SHIFT
)
1317 hotkey
+= wxT("<shift>");
1319 int code
= accel
->GetKeyCode();
1346 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1349 // TODO: we should use gdk_keyval_name() (a.k.a.
1350 // XKeysymToString) here as well as hardcoding the keysym
1351 // names this might be not portable
1353 hotkey
<< wxT("Insert" );
1356 hotkey
<< wxT("Delete" );
1359 hotkey
<< wxT("Up" );
1362 hotkey
<< wxT("Down" );
1365 hotkey
<< wxT("Page_Up" );
1368 hotkey
<< wxT("Page_Down" );
1371 hotkey
<< wxT("Left" );
1374 hotkey
<< wxT("Right" );
1377 hotkey
<< wxT("Home" );
1380 hotkey
<< wxT("End" );
1383 hotkey
<< wxT("Return" );
1386 hotkey
<< wxT("BackSpace" );
1389 hotkey
<< wxT("Tab" );
1392 hotkey
<< wxT("Esc" );
1395 hotkey
<< wxT("space" );
1398 hotkey
<< wxT("Multiply" );
1401 hotkey
<< wxT("Add" );
1404 hotkey
<< wxT("Separator" );
1407 hotkey
<< wxT("Subtract" );
1410 hotkey
<< wxT("Decimal" );
1413 hotkey
<< wxT("Divide" );
1416 hotkey
<< wxT("Cancel" );
1419 hotkey
<< wxT("Clear" );
1422 hotkey
<< wxT("Menu" );
1425 hotkey
<< wxT("Pause" );
1428 hotkey
<< wxT("Capital" );
1431 hotkey
<< wxT("Select" );
1434 hotkey
<< wxT("Print" );
1437 hotkey
<< wxT("Execute" );
1440 hotkey
<< wxT("Snapshot" );
1443 hotkey
<< wxT("Help" );
1446 hotkey
<< wxT("Num_Lock" );
1449 hotkey
<< wxT("Scroll_Lock" );
1451 case WXK_NUMPAD_INSERT
:
1452 hotkey
<< wxT("KP_Insert" );
1454 case WXK_NUMPAD_DELETE
:
1455 hotkey
<< wxT("KP_Delete" );
1457 case WXK_NUMPAD_SPACE
:
1458 hotkey
<< wxT("KP_Space" );
1460 case WXK_NUMPAD_TAB
:
1461 hotkey
<< wxT("KP_Tab" );
1463 case WXK_NUMPAD_ENTER
:
1464 hotkey
<< wxT("KP_Enter" );
1466 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1468 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1470 case WXK_NUMPAD_HOME
:
1471 hotkey
<< wxT("KP_Home" );
1473 case WXK_NUMPAD_LEFT
:
1474 hotkey
<< wxT("KP_Left" );
1477 hotkey
<< wxT("KP_Up" );
1479 case WXK_NUMPAD_RIGHT
:
1480 hotkey
<< wxT("KP_Right" );
1482 case WXK_NUMPAD_DOWN
:
1483 hotkey
<< wxT("KP_Down" );
1485 case WXK_NUMPAD_PAGEUP
:
1486 hotkey
<< wxT("KP_Page_Up" );
1488 case WXK_NUMPAD_PAGEDOWN
:
1489 hotkey
<< wxT("KP_Page_Down" );
1491 case WXK_NUMPAD_END
:
1492 hotkey
<< wxT("KP_End" );
1494 case WXK_NUMPAD_BEGIN
:
1495 hotkey
<< wxT("KP_Begin" );
1497 case WXK_NUMPAD_EQUAL
:
1498 hotkey
<< wxT("KP_Equal" );
1500 case WXK_NUMPAD_MULTIPLY
:
1501 hotkey
<< wxT("KP_Multiply" );
1503 case WXK_NUMPAD_ADD
:
1504 hotkey
<< wxT("KP_Add" );
1506 case WXK_NUMPAD_SEPARATOR
:
1507 hotkey
<< wxT("KP_Separator" );
1509 case WXK_NUMPAD_SUBTRACT
:
1510 hotkey
<< wxT("KP_Subtract" );
1512 case WXK_NUMPAD_DECIMAL
:
1513 hotkey
<< wxT("KP_Decimal" );
1515 case WXK_NUMPAD_DIVIDE
:
1516 hotkey
<< wxT("KP_Divide" );
1518 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1519 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1520 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1521 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1523 case WXK_WINDOWS_LEFT
:
1524 hotkey
<< wxT("Super_L" );
1526 case WXK_WINDOWS_RIGHT
:
1527 hotkey
<< wxT("Super_R" );
1529 case WXK_WINDOWS_MENU
:
1530 hotkey
<< wxT("Menu" );
1533 hotkey
<< wxT("Command" );
1535 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1536 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1537 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1538 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1539 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1540 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1541 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1544 // if there are any other keys wxAcceleratorEntry::Create() may
1545 // return, we should process them here
1551 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1552 if ( !name
.empty() )
1559 wxFAIL_MSG( wxT("unknown keyboard accel") );
1568 #endif // wxUSE_ACCEL
1570 // ----------------------------------------------------------------------------
1571 // Pop-up menu stuff
1572 // ----------------------------------------------------------------------------
1574 #if wxUSE_MENUS_NATIVE
1576 extern "C" WXDLLIMPEXP_CORE
1577 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1579 *is_waiting
= false;
1582 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1584 menu
->SetInvokingWindow( win
);
1586 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1589 wxMenuItem
*menuitem
= node
->GetData();
1590 if (menuitem
->IsSubMenu())
1592 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1595 node
= node
->GetNext();
1599 extern "C" WXDLLIMPEXP_CORE
1600 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1602 gboolean
* WXUNUSED(whatever
),
1603 gpointer user_data
)
1605 // ensure that the menu appears entirely on screen
1607 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1609 wxSize sizeScreen
= wxGetDisplaySize();
1610 wxPoint
*pos
= (wxPoint
*)user_data
;
1612 gint xmax
= sizeScreen
.x
- req
.width
,
1613 ymax
= sizeScreen
.y
- req
.height
;
1615 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1616 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1619 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1621 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1623 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1625 // NOTE: if you change this code, you need to update
1626 // the same code in taskbar.cpp as well. This
1627 // is ugly code duplication, I know.
1629 SetInvokingWindow( menu
, this );
1633 bool is_waiting
= true;
1635 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1636 G_CALLBACK (gtk_pop_hide_callback
),
1641 GtkMenuPositionFunc posfunc
;
1642 if ( x
== -1 && y
== -1 )
1644 // use GTK's default positioning algorithm
1650 pos
= ClientToScreen(wxPoint(x
, y
));
1652 posfunc
= wxPopupMenuPositionCallback
;
1655 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1656 DoCommonMenuCallbackCode(menu
, eventOpen
);
1659 GTK_MENU(menu
->m_menu
),
1660 (GtkWidget
*) NULL
, // parent menu shell
1661 (GtkWidget
*) NULL
, // parent menu item
1662 posfunc
, // function to position it
1663 userdata
, // client data
1664 0, // button used to activate it
1665 gtk_get_current_event_time()
1670 gtk_main_iteration();
1673 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1675 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1676 DoCommonMenuCallbackCode(menu
, eventClose
);
1681 #endif // wxUSE_MENUS_NATIVE
1685 #include <gtk/gtk.h>
1687 const char *wxGetStockGtkID(wxWindowID id
)
1689 #define STOCKITEM(wx,gtk) \
1693 #define STOCKITEM_MISSING(wx) \
1697 #if GTK_CHECK_VERSION(2,4,0)
1698 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1700 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1703 #if GTK_CHECK_VERSION(2,6,0)
1704 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1706 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1709 #if GTK_CHECK_VERSION(2,10,0)
1710 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1712 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1718 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1719 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1720 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1721 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1722 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1723 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1724 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1725 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1726 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1727 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1728 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1729 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1730 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1731 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1732 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1733 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1734 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1735 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1736 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1737 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1738 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1739 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1740 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1741 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1742 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1743 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1744 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1745 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1746 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1747 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1748 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1749 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1750 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1751 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1752 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1753 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1754 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1755 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1756 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1757 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1758 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1759 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1760 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1761 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1762 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1763 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1764 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1765 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1766 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1767 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1768 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1769 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1770 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1771 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1774 wxFAIL_MSG( _T("invalid stock item ID") );
1783 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1788 GtkStockItem stock_item
;
1789 if (gtk_stock_lookup (id
, &stock_item
))
1791 if (key
) *key
= stock_item
.keyval
;
1792 if (mod
) *mod
= stock_item
.modifier
;
1794 // some GTK stock items have zero values for the keyval;
1795 // it means that they do not have an accelerator...
1796 if (stock_item
.keyval
)
1803 #endif // __WXGTK20__