1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/menu.cpp
3 // Purpose: implementation of wxMenuBar and wxMenu classes for wxGTK
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
21 #include "wx/bitmap.h"
26 #include "wx/stockitem.h"
27 #include "wx/gtk/private.h"
28 #include "wx/gtk/private/mnemonics.h"
30 // FIXME: is this right? somehow I don't think so (VZ)
32 #define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
33 #define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
34 //#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
36 #define ACCEL_OBJECT GtkWindow
37 #define ACCEL_OBJECTS(a) (a)->acceleratables
38 #define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
40 // we use normal item but with a special id for the menu title
41 static const int wxGTK_TITLE_ID
= -3;
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
48 static wxString
GetGtkHotKey( const wxMenuItem
& item
);
51 //-----------------------------------------------------------------------------
52 // activate message from GTK
53 //-----------------------------------------------------------------------------
55 static void DoCommonMenuCallbackCode(wxMenu
*menu
, wxMenuEvent
& event
)
57 event
.SetEventObject( menu
);
59 wxEvtHandler
* handler
= menu
->GetEventHandler();
60 if (handler
&& handler
->ProcessEvent(event
))
63 wxWindow
*win
= menu
->GetInvokingWindow();
65 win
->GetEventHandler()->ProcessEvent( event
);
71 gtk_menu_open_callback(GtkWidget
* WXUNUSED(widget
), wxMenu
*menu
)
73 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
75 DoCommonMenuCallbackCode(menu
, event
);
79 gtk_menu_close_callback(GtkWidget
* WXUNUSED(widget
), wxMenuBar
*menubar
)
81 if ( !menubar
->GetMenuCount() )
83 // if menubar is empty we can't call GetMenu(0) below
87 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
89 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
94 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
98 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
100 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
103 m_invokingWindow
= NULL
;
106 // Hildon window uses a single menu instead of a menu bar, so wxMenuBar is
107 // the same as menu in this case
109 m_menubar
= gtk_menu_new();
110 #else // !wxUSE_LIBHILDON
111 if (!PreCreation( NULL
, wxDefaultPosition
, wxDefaultSize
) ||
112 !CreateBase( NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
114 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
118 m_menubar
= gtk_menu_bar_new();
120 if (style
& wxMB_DOCKABLE
)
122 m_widget
= gtk_handle_box_new();
123 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
124 gtk_widget_show(m_menubar
);
128 m_widget
= m_menubar
;
134 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
136 for (size_t i
= 0; i
< n
; ++i
)
137 Append(menus
[i
], titles
[i
]);
139 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
140 // don't get it when the menu is dismissed by clicking outside the
141 // toolbar) so we connect to the global one, even if it means that we
142 // can't pass the menu which was closed in wxMenuEvent object
143 g_signal_connect (m_menubar
, "deactivate",
144 G_CALLBACK (gtk_menu_close_callback
), this);
147 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
149 Init(n
, menus
, titles
, style
);
152 wxMenuBar::wxMenuBar(long style
)
154 Init(0, NULL
, NULL
, style
);
157 wxMenuBar::wxMenuBar()
159 Init(0, NULL
, NULL
, 0);
162 wxMenuBar::~wxMenuBar()
166 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
168 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
170 wxWindow
*top_frame
= win
;
171 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
172 top_frame
= top_frame
->GetParent();
174 // support for native hot keys
175 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
176 if ( menu
->m_accel
&& g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
177 gtk_accel_group_detach( menu
->m_accel
, obj
);
179 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
182 wxMenuItem
*menuitem
= node
->GetData();
183 if (menuitem
->IsSubMenu())
184 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
185 node
= node
->GetNext();
189 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
191 menu
->SetInvokingWindow( win
);
193 wxWindow
*top_frame
= win
;
194 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
195 top_frame
= top_frame
->GetParent();
197 // support for native hot keys
198 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
199 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
200 gtk_accel_group_attach( menu
->m_accel
, obj
);
202 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
205 wxMenuItem
*menuitem
= node
->GetData();
206 if (menuitem
->IsSubMenu())
207 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
208 node
= node
->GetNext();
212 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
214 m_invokingWindow
= win
;
215 wxWindow
*top_frame
= win
;
216 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
217 top_frame
= top_frame
->GetParent();
219 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
222 wxMenu
*menu
= node
->GetData();
223 wxMenubarSetInvokingWindow( menu
, win
);
224 node
= node
->GetNext();
228 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
230 if ( dir
== wxLayout_Default
)
232 const wxWindow
*const frame
= GetFrame();
235 // inherit layout from frame.
236 dir
= frame
->GetLayoutDirection();
238 else // use global layout
240 dir
= wxTheApp
->GetLayoutDirection();
244 if ( dir
== wxLayout_Default
)
247 GTKSetLayout(m_menubar
, dir
);
249 // also set the layout of all menus we already have (new ones will inherit
250 // the current layout)
251 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
253 node
= node
->GetNext() )
255 wxMenu
*const menu
= node
->GetData();
256 menu
->SetLayoutDirection(dir
);
260 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
262 return GTKGetLayout(m_menubar
);
265 void wxMenuBar::Attach(wxFrame
*frame
)
267 wxMenuBarBase::Attach(frame
);
269 SetLayoutDirection(wxLayout_Default
);
272 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
274 m_invokingWindow
= (wxWindow
*) NULL
;
275 wxWindow
*top_frame
= win
;
276 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
277 top_frame
= top_frame
->GetParent();
279 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
282 wxMenu
*menu
= node
->GetData();
283 wxMenubarUnsetInvokingWindow( menu
, win
);
284 node
= node
->GetNext();
288 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
290 if ( !wxMenuBarBase::Append( menu
, title
) )
293 return GtkAppend(menu
, title
);
296 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
298 const wxString
str(wxConvertMnemonicsToGTK(title
));
300 // This doesn't have much effect right now.
301 menu
->SetTitle( str
);
303 // The "m_owner" is the "menu item"
304 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
305 menu
->SetLayoutDirection(GetLayoutDirection());
307 gtk_widget_show( menu
->m_owner
);
309 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
312 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
314 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
316 g_signal_connect (menu
->m_owner
, "activate",
317 G_CALLBACK (gtk_menu_open_callback
),
320 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
321 // addings menu later on.
322 if (m_invokingWindow
)
323 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
328 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
330 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
335 if ( !GtkAppend(menu
, title
, (int)pos
) )
341 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
343 // remove the old item and insert a new one
344 wxMenu
*menuOld
= Remove(pos
);
345 if ( menuOld
&& !Insert(pos
, menu
, title
) )
347 return (wxMenu
*) NULL
;
350 // either Insert() succeeded or Remove() failed and menuOld is NULL
354 wxMenu
*wxMenuBar::Remove(size_t pos
)
356 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
358 return (wxMenu
*) NULL
;
360 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
361 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
363 gtk_widget_destroy( menu
->m_owner
);
364 menu
->m_owner
= NULL
;
366 if (m_invokingWindow
)
367 wxMenubarUnsetInvokingWindow( menu
, m_invokingWindow
);
372 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
374 if (wxMenuItem::GetLabelText(wxConvertMnemonicsFromGTK(menu
->GetTitle())) == wxMenuItem::GetLabelText(menuString
))
376 int res
= menu
->FindItem( itemString
);
377 if (res
!= wxNOT_FOUND
)
381 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
384 wxMenuItem
*item
= node
->GetData();
385 if (item
->IsSubMenu())
386 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
388 node
= node
->GetNext();
394 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
396 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
399 wxMenu
*menu
= node
->GetData();
400 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
403 node
= node
->GetNext();
409 // Find a wxMenuItem using its id. Recurses down into sub-menus
410 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
412 wxMenuItem
* result
= menu
->FindChildItem(id
);
414 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
415 while ( node
&& result
== NULL
)
417 wxMenuItem
*item
= node
->GetData();
418 if (item
->IsSubMenu())
420 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
422 node
= node
->GetNext();
428 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
430 wxMenuItem
* result
= 0;
431 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
432 while (node
&& result
== 0)
434 wxMenu
*menu
= node
->GetData();
435 result
= FindMenuItemByIdRecursive( menu
, id
);
436 node
= node
->GetNext();
441 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
447 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
449 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
451 wxCHECK_RET( node
, wxT("menu not found") );
453 wxMenu
* menu
= node
->GetData();
456 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
459 wxString
wxMenuBar::GetMenuLabel( size_t pos
) const
461 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
463 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
465 wxMenu
* menu
= node
->GetData();
467 return wxConvertMnemonicsFromGTK(menu
->GetTitle());
470 void wxMenuBar::SetMenuLabel( size_t pos
, const wxString
& label
)
472 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
474 wxCHECK_RET( node
, wxT("menu not found") );
476 wxMenu
* menu
= node
->GetData();
478 const wxString
str(wxConvertMnemonicsToGTK(label
));
480 menu
->SetTitle( str
);
483 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
486 //-----------------------------------------------------------------------------
488 //-----------------------------------------------------------------------------
491 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
493 int id
= menu
->FindMenuIdByMenuItem(widget
);
495 /* should find it for normal (not popup) menu */
496 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
497 _T("menu item not found in gtk_menu_clicked_callback") );
499 if (!menu
->IsEnabled(id
))
502 wxMenuItem
* item
= menu
->FindChildItem( id
);
503 wxCHECK_RET( item
, wxT("error in menu item callback") );
505 if ( item
->GetId() == wxGTK_TITLE_ID
)
507 // ignore events from the menu title
511 if (item
->IsCheckable())
513 bool isReallyChecked
= item
->IsChecked(),
514 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
516 // ensure that the internal state is always consistent with what is
517 // shown on the screen
518 item
->wxMenuItemBase::Check(isReallyChecked
);
520 // we must not report the events for the radio button going up nor the
521 // events resulting from the calls to wxMenuItem::Check()
522 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
523 (isInternallyChecked
== isReallyChecked
) )
530 // Is this menu on a menubar? (possibly nested)
531 wxFrame
* frame
= NULL
;
532 if(menu
->IsAttached())
533 frame
= menu
->GetMenuBar()->GetFrame();
535 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
536 // normally wxMenu::SendEvent() should be enough, if it doesn't work
537 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
538 // should be fixed instead of working around it here...
541 // If it is attached then let the frame send the event.
542 // Don't call frame->ProcessCommand(id) because it toggles
543 // checkable items and we've already done that above.
544 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
545 commandEvent
.SetEventObject(frame
);
546 if (item
->IsCheckable())
547 commandEvent
.SetInt(item
->IsChecked());
549 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
553 // otherwise let the menu have it
554 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
559 //-----------------------------------------------------------------------------
561 //-----------------------------------------------------------------------------
564 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
566 int id
= menu
->FindMenuIdByMenuItem(widget
);
568 wxASSERT( id
!= -1 ); // should find it!
570 if (!menu
->IsEnabled(id
))
573 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
574 event
.SetEventObject( menu
);
576 wxEvtHandler
* handler
= menu
->GetEventHandler();
577 if (handler
&& handler
->ProcessEvent(event
))
580 wxWindow
*win
= menu
->GetInvokingWindow();
581 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
585 //-----------------------------------------------------------------------------
587 //-----------------------------------------------------------------------------
590 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
592 int id
= menu
->FindMenuIdByMenuItem(widget
);
594 wxASSERT( id
!= -1 ); // should find it!
596 if (!menu
->IsEnabled(id
))
599 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
600 event
.SetEventObject( menu
);
602 wxEvtHandler
* handler
= menu
->GetEventHandler();
603 if (handler
&& handler
->ProcessEvent(event
))
606 wxWindow
*win
= menu
->GetInvokingWindow();
608 win
->GetEventHandler()->ProcessEvent( event
);
612 //-----------------------------------------------------------------------------
614 //-----------------------------------------------------------------------------
616 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
618 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
620 const wxString
& name
,
621 const wxString
& help
,
625 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
628 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
630 const wxString
& text
,
631 const wxString
& help
,
634 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
639 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
641 const wxString
& text
,
642 const wxString
& help
,
645 : wxMenuItemBase(parentMenu
, id
, text
, help
,
646 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
651 void wxMenuItem::Init(const wxString
& text
)
653 m_labelWidget
= (GtkWidget
*) NULL
;
654 m_menuItem
= (GtkWidget
*) NULL
;
659 wxMenuItem::~wxMenuItem()
661 // don't delete menu items, the menus take care of that
664 // return the menu item text without any menu accels
667 wxString
wxMenuItemBase::GetLabelText(const wxString
& text
)
669 // The argument to this function will now always be in wxWidgets standard label
670 // format, not GTK+ format, so we do what the other ports do.
672 return wxStripMenuCodes(text
);
677 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
679 if ( *pc
== wxT('\t'))
682 if ( *pc
== wxT('_') )
684 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
690 if ( *pc
== wxT('\\') )
692 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
698 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
701 // "&" is doubled to indicate "&" instead of accelerator
708 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
714 wxString
wxMenuItem::GetItemLabel() const
716 wxString label
= wxConvertMnemonicsFromGTK(m_text
);
717 if (!m_hotKey
.IsEmpty())
718 label
<< "\t" << m_hotKey
;
722 void wxMenuItem::SetItemLabel( const wxString
& str
)
724 // cache some data which must be used later
725 bool isstock
= wxIsStockID(GetId());
726 const char *stockid
= NULL
;
728 stockid
= wxGetStockGtkID(GetId());
730 // Some optimization to avoid flicker
731 wxString oldLabel
= m_text
;
732 oldLabel
= wxStripMenuCodes(oldLabel
);
733 oldLabel
.Replace(wxT("_"), wxT(""));
734 wxString label1
= wxStripMenuCodes(str
);
736 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
737 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
738 #endif // wxUSE_ACCEL
743 if (oldLabel
== label1
&&
744 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
751 label
= (GtkLabel
*) m_labelWidget
;
753 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
755 // stock menu items can have empty labels:
756 wxString text
= m_text
;
757 if (text
.IsEmpty() && !IsSeparator())
759 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
760 text
= wxGetStockLabel(GetId());
762 // need & => _ conversion
763 text
= GTKProcessMenuItemLabel(text
, NULL
);
766 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
769 // remove old accelerator from our parent's accelerator group, if present
771 GdkModifierType accel_mods
;
772 if (oldbuf
[(size_t)0] != '\0')
774 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
777 gtk_widget_remove_accelerator(m_menuItem
,
778 m_parentMenu
->m_accel
,
785 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
786 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
787 gtk_widget_remove_accelerator( m_menuItem
,
788 m_parentMenu
->m_accel
,
793 // add new accelerator to our parent's accelerator group
794 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
795 if (buf
[(size_t)0] != '\0')
797 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
800 gtk_widget_add_accelerator( m_menuItem
,
802 m_parentMenu
->m_accel
,
810 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
811 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
812 gtk_widget_remove_accelerator( m_menuItem
,
813 m_parentMenu
->m_accel
,
817 #endif // wxUSE_FILECTRL
820 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
821 // implemented in control.cpp and from wxMenuItemBase::GetLabelText...
822 // so there's no real code duplication
823 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
827 // '\t' is the deliminator indicating a hot key
828 wxString::const_iterator pc
= str
.begin();
829 while ( pc
!= str
.end() && *pc
!= wxT('\t') )
833 wxString::const_iterator next
= pc
+ 1;
834 if (next
!= str
.end() && *next
== wxT('&'))
836 // "&" is doubled to indicate "&" instead of accelerator
845 else if ( *pc
== wxT('_') ) // escape underscores
862 hotKey
->assign(pc
, str
.end());
869 // it's valid for this function to be called even if m_menuItem == NULL
870 void wxMenuItem::DoSetText( const wxString
& str
)
873 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
878 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
886 // accelerator parsing code looks for them after a TAB, so insert a dummy
889 label
<< wxT('\t') << GetHotKey();
891 return wxAcceleratorEntry::Create(label
);
894 #endif // wxUSE_ACCEL
896 void wxMenuItem::Check( bool check
)
898 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
900 if (check
== m_isChecked
)
903 wxMenuItemBase::Check( check
);
909 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
913 wxFAIL_MSG( _T("can't check this item") );
917 void wxMenuItem::Enable( bool enable
)
919 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
921 gtk_widget_set_sensitive( m_menuItem
, enable
);
922 wxMenuItemBase::Enable( enable
);
925 bool wxMenuItem::IsChecked() const
927 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
929 wxCHECK_MSG( IsCheckable(), false,
930 wxT("can't get state of uncheckable item!") );
932 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
935 //-----------------------------------------------------------------------------
937 //-----------------------------------------------------------------------------
939 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
943 m_accel
= gtk_accel_group_new();
944 m_menu
= gtk_menu_new();
945 // NB: keep reference to the menu so that it is not destroyed behind
946 // our back by GTK+ e.g. when it is removed from menubar:
947 gtk_widget_ref(m_menu
);
949 m_owner
= (GtkWidget
*) NULL
;
951 // Tearoffs are entries, just like separators. So if we want this
952 // menu to be a tear-off one, we just append a tearoff entry
954 if ( m_style
& wxMENU_TEAROFF
)
956 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
958 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
963 // append the title as the very first entry if we have it
964 if ( !m_title
.empty() )
966 Append(wxGTK_TITLE_ID
, m_title
);
973 if ( GTK_IS_WIDGET( m_menu
))
976 gtk_widget_unref( m_menu
);
977 g_object_unref( m_accel
);
979 // if the menu is inserted in another menu at this time, there was
980 // one more reference to it:
982 gtk_widget_destroy( m_menu
);
985 // This must come after we release GTK resources above. Otherwise, GTK will
986 // give warnings/errors when attempting to free accelerator resources from
987 // child items that just were destroyed (the m_menu widget can contain
988 // references to accelerators in child items. Problem detected when removing
989 // a menu from a wxMenuBar, and the removed menu had submenus with accelerators.)
990 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
993 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
996 wxWindow::GTKSetLayout(m_owner
, dir
);
997 //else: will be called later by wxMenuBar again
1000 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1002 return wxWindow::GTKGetLayout(m_owner
);
1005 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1007 GtkWidget
*menuItem
;
1009 // cache some data used later
1010 wxString text
= mitem
->wxMenuItemBase::GetItemLabel();
1011 int id
= mitem
->GetId();
1012 bool isstock
= wxIsStockID(id
);
1013 const char *stockid
= NULL
;
1015 stockid
= wxGetStockGtkID(mitem
->GetId());
1017 // stock menu items can have an empty label
1018 if (text
.IsEmpty() && !mitem
->IsSeparator())
1020 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1021 text
= wxGetStockLabel(id
);
1023 // need & => _ conversion
1024 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1027 if ( mitem
->IsSeparator() )
1029 menuItem
= gtk_separator_menu_item_new();
1031 else if ( mitem
->GetBitmap().Ok() ||
1032 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1034 wxBitmap
bitmap(mitem
->GetBitmap());
1036 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1041 // use stock bitmap for this item if available on the assumption
1042 // that it never hurts to follow GTK+ conventions more closely
1043 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1046 else // we have a custom bitmap
1048 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1049 _T("only normal menu items can have bitmaps") );
1051 if ( bitmap
.HasPixbuf() )
1053 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1057 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1058 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1059 bitmap
.GetMask()->GetBitmap() :
1061 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1067 gtk_widget_show(image
);
1069 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1074 else // a normal item
1076 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
1079 switch ( mitem
->GetKind() )
1083 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1090 GSList
*group
= NULL
;
1091 if ( m_prevRadio
== NULL
)
1093 // start of a new radio group
1094 m_prevRadio
= menuItem
=
1095 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1097 else // continue the radio group
1099 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1100 m_prevRadio
= menuItem
=
1101 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1107 wxFAIL_MSG( _T("unexpected menu item kind") );
1112 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1122 GdkModifierType accel_mods
;
1123 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1125 if (buf
[(size_t)0] != '\0')
1127 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1130 gtk_widget_add_accelerator (menuItem
,
1140 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1141 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1142 gtk_widget_add_accelerator( menuItem
,
1149 #endif // wxUSE_FILECTRL
1152 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1154 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1156 gtk_widget_show( menuItem
);
1158 if ( !mitem
->IsSeparator() )
1160 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1162 g_signal_connect (menuItem
, "select",
1163 G_CALLBACK (gtk_menu_hilight_callback
), this);
1164 g_signal_connect (menuItem
, "deselect",
1165 G_CALLBACK (gtk_menu_nolight_callback
), this);
1167 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1169 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1171 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1173 // if adding a submenu to a menu already existing in the menu bar, we
1174 // must set invoking window to allow processing events from this
1176 if ( m_invokingWindow
)
1177 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1181 g_signal_connect (menuItem
, "activate",
1182 G_CALLBACK (gtk_menu_clicked_callback
),
1187 mitem
->SetMenuItem(menuItem
);
1191 // This doesn't even exist!
1192 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1198 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1200 if (!GtkAppend(mitem
))
1203 return wxMenuBase::DoAppend(mitem
);
1206 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1208 if ( !wxMenuBase::DoInsert(pos
, item
) )
1212 if ( !GtkAppend(item
, (int)pos
) )
1218 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1220 if ( !wxMenuBase::DoRemove(item
) )
1221 return (wxMenuItem
*)NULL
;
1223 // TODO: this code doesn't delete the item factory item and this seems
1224 // impossible as of GTK 1.2.6.
1225 gtk_widget_destroy( item
->GetMenuItem() );
1230 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1232 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1235 wxMenuItem
*item
= node
->GetData();
1236 if (item
->GetMenuItem() == menuItem
)
1237 return item
->GetId();
1238 node
= node
->GetNext();
1244 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1246 wxMenuBase::Attach(menubar
);
1248 // inherit layout direction from menubar.
1249 SetLayoutDirection(menubar
->GetLayoutDirection());
1252 // ----------------------------------------------------------------------------
1254 // ----------------------------------------------------------------------------
1258 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1262 wxAcceleratorEntry
*accel
= item
.GetAccel();
1265 int flags
= accel
->GetFlags();
1266 if ( flags
& wxACCEL_ALT
)
1267 hotkey
+= wxT("<alt>");
1268 if ( flags
& wxACCEL_CTRL
)
1269 hotkey
+= wxT("<control>");
1270 if ( flags
& wxACCEL_SHIFT
)
1271 hotkey
+= wxT("<shift>");
1273 int code
= accel
->GetKeyCode();
1300 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1303 // TODO: we should use gdk_keyval_name() (a.k.a.
1304 // XKeysymToString) here as well as hardcoding the keysym
1305 // names this might be not portable
1307 hotkey
<< wxT("Insert" );
1310 hotkey
<< wxT("Delete" );
1313 hotkey
<< wxT("Up" );
1316 hotkey
<< wxT("Down" );
1319 hotkey
<< wxT("Page_Up" );
1322 hotkey
<< wxT("Page_Down" );
1325 hotkey
<< wxT("Left" );
1328 hotkey
<< wxT("Right" );
1331 hotkey
<< wxT("Home" );
1334 hotkey
<< wxT("End" );
1337 hotkey
<< wxT("Return" );
1340 hotkey
<< wxT("BackSpace" );
1343 hotkey
<< wxT("Tab" );
1346 hotkey
<< wxT("Esc" );
1349 hotkey
<< wxT("space" );
1352 hotkey
<< wxT("Multiply" );
1355 hotkey
<< wxT("Add" );
1358 hotkey
<< wxT("Separator" );
1361 hotkey
<< wxT("Subtract" );
1364 hotkey
<< wxT("Decimal" );
1367 hotkey
<< wxT("Divide" );
1370 hotkey
<< wxT("Cancel" );
1373 hotkey
<< wxT("Clear" );
1376 hotkey
<< wxT("Menu" );
1379 hotkey
<< wxT("Pause" );
1382 hotkey
<< wxT("Capital" );
1385 hotkey
<< wxT("Select" );
1388 hotkey
<< wxT("Print" );
1391 hotkey
<< wxT("Execute" );
1394 hotkey
<< wxT("Snapshot" );
1397 hotkey
<< wxT("Help" );
1400 hotkey
<< wxT("Num_Lock" );
1403 hotkey
<< wxT("Scroll_Lock" );
1405 case WXK_NUMPAD_INSERT
:
1406 hotkey
<< wxT("KP_Insert" );
1408 case WXK_NUMPAD_DELETE
:
1409 hotkey
<< wxT("KP_Delete" );
1411 case WXK_NUMPAD_SPACE
:
1412 hotkey
<< wxT("KP_Space" );
1414 case WXK_NUMPAD_TAB
:
1415 hotkey
<< wxT("KP_Tab" );
1417 case WXK_NUMPAD_ENTER
:
1418 hotkey
<< wxT("KP_Enter" );
1420 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1422 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1424 case WXK_NUMPAD_HOME
:
1425 hotkey
<< wxT("KP_Home" );
1427 case WXK_NUMPAD_LEFT
:
1428 hotkey
<< wxT("KP_Left" );
1431 hotkey
<< wxT("KP_Up" );
1433 case WXK_NUMPAD_RIGHT
:
1434 hotkey
<< wxT("KP_Right" );
1436 case WXK_NUMPAD_DOWN
:
1437 hotkey
<< wxT("KP_Down" );
1439 case WXK_NUMPAD_PAGEUP
:
1440 hotkey
<< wxT("KP_Page_Up" );
1442 case WXK_NUMPAD_PAGEDOWN
:
1443 hotkey
<< wxT("KP_Page_Down" );
1445 case WXK_NUMPAD_END
:
1446 hotkey
<< wxT("KP_End" );
1448 case WXK_NUMPAD_BEGIN
:
1449 hotkey
<< wxT("KP_Begin" );
1451 case WXK_NUMPAD_EQUAL
:
1452 hotkey
<< wxT("KP_Equal" );
1454 case WXK_NUMPAD_MULTIPLY
:
1455 hotkey
<< wxT("KP_Multiply" );
1457 case WXK_NUMPAD_ADD
:
1458 hotkey
<< wxT("KP_Add" );
1460 case WXK_NUMPAD_SEPARATOR
:
1461 hotkey
<< wxT("KP_Separator" );
1463 case WXK_NUMPAD_SUBTRACT
:
1464 hotkey
<< wxT("KP_Subtract" );
1466 case WXK_NUMPAD_DECIMAL
:
1467 hotkey
<< wxT("KP_Decimal" );
1469 case WXK_NUMPAD_DIVIDE
:
1470 hotkey
<< wxT("KP_Divide" );
1472 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1473 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1474 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1475 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1477 case WXK_WINDOWS_LEFT
:
1478 hotkey
<< wxT("Super_L" );
1480 case WXK_WINDOWS_RIGHT
:
1481 hotkey
<< wxT("Super_R" );
1483 case WXK_WINDOWS_MENU
:
1484 hotkey
<< wxT("Menu" );
1487 hotkey
<< wxT("Command" );
1489 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1490 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1491 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1492 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1493 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1494 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1495 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1498 // if there are any other keys wxAcceleratorEntry::Create() may
1499 // return, we should process them here
1505 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1506 if ( !name
.empty() )
1513 wxFAIL_MSG( wxT("unknown keyboard accel") );
1522 #endif // wxUSE_ACCEL
1524 // ----------------------------------------------------------------------------
1525 // Pop-up menu stuff
1526 // ----------------------------------------------------------------------------
1528 #if wxUSE_MENUS_NATIVE
1530 extern "C" WXDLLIMPEXP_CORE
1531 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1533 *is_waiting
= false;
1536 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1538 menu
->SetInvokingWindow( win
);
1540 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1543 wxMenuItem
*menuitem
= node
->GetData();
1544 if (menuitem
->IsSubMenu())
1546 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1549 node
= node
->GetNext();
1553 extern "C" WXDLLIMPEXP_CORE
1554 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1556 gboolean
* WXUNUSED(whatever
),
1557 gpointer user_data
)
1559 // ensure that the menu appears entirely on screen
1561 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1563 wxSize sizeScreen
= wxGetDisplaySize();
1564 wxPoint
*pos
= (wxPoint
*)user_data
;
1566 gint xmax
= sizeScreen
.x
- req
.width
,
1567 ymax
= sizeScreen
.y
- req
.height
;
1569 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1570 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1573 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1575 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1577 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1579 // NOTE: if you change this code, you need to update
1580 // the same code in taskbar.cpp as well. This
1581 // is ugly code duplication, I know.
1583 SetInvokingWindow( menu
, this );
1587 bool is_waiting
= true;
1589 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1590 G_CALLBACK (gtk_pop_hide_callback
),
1595 GtkMenuPositionFunc posfunc
;
1596 if ( x
== -1 && y
== -1 )
1598 // use GTK's default positioning algorithm
1604 pos
= ClientToScreen(wxPoint(x
, y
));
1606 posfunc
= wxPopupMenuPositionCallback
;
1609 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1610 DoCommonMenuCallbackCode(menu
, eventOpen
);
1613 GTK_MENU(menu
->m_menu
),
1614 (GtkWidget
*) NULL
, // parent menu shell
1615 (GtkWidget
*) NULL
, // parent menu item
1616 posfunc
, // function to position it
1617 userdata
, // client data
1618 0, // button used to activate it
1619 gtk_get_current_event_time()
1624 gtk_main_iteration();
1627 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1629 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1630 DoCommonMenuCallbackCode(menu
, eventClose
);
1635 #endif // wxUSE_MENUS_NATIVE
1637 #include <gtk/gtk.h>
1639 const char *wxGetStockGtkID(wxWindowID id
)
1641 #define STOCKITEM(wx,gtk) \
1645 #define STOCKITEM_MISSING(wx) \
1649 #if GTK_CHECK_VERSION(2,4,0)
1650 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1652 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1655 #if GTK_CHECK_VERSION(2,6,0)
1656 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1658 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1661 #if GTK_CHECK_VERSION(2,10,0)
1662 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1664 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1670 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1671 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1672 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1673 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1674 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1675 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1676 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1677 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1678 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1679 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1680 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1681 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1682 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1683 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1684 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1685 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1686 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1687 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1688 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1689 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1690 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1691 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1692 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1693 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1694 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1695 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1696 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1697 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1698 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1699 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1700 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1701 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1702 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1703 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1704 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1705 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1706 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1707 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1708 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1709 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1710 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1711 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1712 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1713 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1714 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1715 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1716 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1717 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1718 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1719 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1720 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1721 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1722 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1723 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1726 wxFAIL_MSG( _T("invalid stock item ID") );
1735 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1740 GtkStockItem stock_item
;
1741 if (gtk_stock_lookup (id
, &stock_item
))
1743 if (key
) *key
= stock_item
.keyval
;
1744 if (mod
) *mod
= stock_item
.modifier
;
1746 // some GTK stock items have zero values for the keyval;
1747 // it means that they do not have an accelerator...
1748 if (stock_item
.keyval
)
1755 #endif // wxUSE_MENUS