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
)
100 event
.SetEventObject( menu
);
102 wxEvtHandler
* handler
= menu
->GetEventHandler();
103 if (handler
&& handler
->ProcessEvent(event
))
106 wxWindow
*win
= menu
->GetInvokingWindow();
108 win
->GetEventHandler()->ProcessEvent( event
);
113 static void gtk_menu_open_callback( GtkWidget
*widget
, wxMenu
*menu
)
115 wxMenuEvent
event(wxEVT_MENU_OPEN
, -1, menu
);
117 DoCommonMenuCallbackCode(menu
, event
);
120 static void gtk_menu_close_callback( GtkWidget
*widget
, wxMenuBar
*menubar
)
122 if ( !menubar
->GetMenuCount() )
124 // if menubar is empty we can't call GetMenu(0) below
128 wxMenuEvent
event( wxEVT_MENU_CLOSE
, -1, NULL
);
130 DoCommonMenuCallbackCode(menubar
->GetMenu(0), event
);
135 //-----------------------------------------------------------------------------
137 //-----------------------------------------------------------------------------
139 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
,wxWindow
)
141 void wxMenuBar::Init(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
143 // the parent window is known after wxFrame::SetMenu()
144 m_needParent
= false;
146 m_invokingWindow
= (wxWindow
*) NULL
;
148 if (!PreCreation( (wxWindow
*) NULL
, wxDefaultPosition
, wxDefaultSize
) ||
149 !CreateBase( (wxWindow
*) NULL
, -1, wxDefaultPosition
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("menubar") ))
151 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
155 m_menubar
= gtk_menu_bar_new();
157 if (style
& wxMB_DOCKABLE
)
159 m_widget
= gtk_handle_box_new();
160 gtk_container_add(GTK_CONTAINER(m_widget
), m_menubar
);
161 gtk_widget_show(m_menubar
);
165 m_widget
= m_menubar
;
172 for (size_t i
= 0; i
< n
; ++i
)
173 Append(menus
[i
], titles
[i
]);
175 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
176 // don't get it when the menu is dismissed by clicking outside the
177 // toolbar) so we connect to the global one, even if it means that we
178 // can't pass the menu which was closed in wxMenuEvent object
179 g_signal_connect (m_menubar
, "deactivate",
180 G_CALLBACK (gtk_menu_close_callback
), this);
184 wxMenuBar::wxMenuBar(size_t n
, wxMenu
*menus
[], const wxString titles
[], long style
)
186 Init(n
, menus
, titles
, style
);
189 wxMenuBar::wxMenuBar(long style
)
191 Init(0, NULL
, NULL
, style
);
194 wxMenuBar::wxMenuBar()
196 Init(0, NULL
, NULL
, 0);
199 wxMenuBar::~wxMenuBar()
203 static void wxMenubarUnsetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
205 menu
->SetInvokingWindow( (wxWindow
*) NULL
);
207 wxWindow
*top_frame
= win
;
208 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
209 top_frame
= top_frame
->GetParent();
211 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
214 wxMenuItem
*menuitem
= node
->GetData();
215 if (menuitem
->IsSubMenu())
216 wxMenubarUnsetInvokingWindow( menuitem
->GetSubMenu(), win
);
217 node
= node
->GetNext();
221 static void wxMenubarSetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
223 menu
->SetInvokingWindow( win
);
225 wxWindow
*top_frame
= win
;
226 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
227 top_frame
= top_frame
->GetParent();
229 // support for native hot keys
230 ACCEL_OBJECT
*obj
= ACCEL_OBJ_CAST(top_frame
->m_widget
);
231 if ( !g_slist_find( ACCEL_OBJECTS(menu
->m_accel
), obj
) )
232 gtk_accel_group_attach( menu
->m_accel
, obj
);
234 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
237 wxMenuItem
*menuitem
= node
->GetData();
238 if (menuitem
->IsSubMenu())
239 wxMenubarSetInvokingWindow( menuitem
->GetSubMenu(), win
);
240 node
= node
->GetNext();
244 void wxMenuBar::SetInvokingWindow( wxWindow
*win
)
246 m_invokingWindow
= win
;
247 wxWindow
*top_frame
= win
;
248 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
249 top_frame
= top_frame
->GetParent();
251 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
254 wxMenu
*menu
= node
->GetData();
255 wxMenubarSetInvokingWindow( menu
, win
);
256 node
= node
->GetNext();
260 void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir
)
262 if ( dir
== wxLayout_Default
)
264 const wxWindow
*const frame
= GetFrame();
267 // inherit layout from frame.
268 dir
= frame
->GetLayoutDirection();
270 else // use global layout
272 dir
= wxTheApp
->GetLayoutDirection();
276 if ( dir
== wxLayout_Default
)
279 GTKSetLayout(m_menubar
, dir
);
281 // also set the layout of all menus we already have (new ones will inherit
282 // the current layout)
283 for ( wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
285 node
= node
->GetNext() )
287 wxMenu
*const menu
= node
->GetData();
288 menu
->SetLayoutDirection(dir
);
292 wxLayoutDirection
wxMenuBar::GetLayoutDirection() const
294 return GTKGetLayout(m_menubar
);
297 void wxMenuBar::Attach(wxFrame
*frame
)
299 wxMenuBarBase::Attach(frame
);
301 SetLayoutDirection(wxLayout_Default
);
304 void wxMenuBar::UnsetInvokingWindow( wxWindow
*win
)
306 m_invokingWindow
= (wxWindow
*) NULL
;
307 wxWindow
*top_frame
= win
;
308 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
309 top_frame
= top_frame
->GetParent();
311 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
314 wxMenu
*menu
= node
->GetData();
315 wxMenubarUnsetInvokingWindow( menu
, win
);
316 node
= node
->GetNext();
320 bool wxMenuBar::Append( wxMenu
*menu
, const wxString
&title
)
322 if ( !wxMenuBarBase::Append( menu
, title
) )
325 return GtkAppend(menu
, title
);
328 bool wxMenuBar::GtkAppend(wxMenu
*menu
, const wxString
& title
, int pos
)
330 wxString
str( wxReplaceUnderscore( title
) );
332 // This doesn't have much effect right now.
333 menu
->SetTitle( str
);
335 // The "m_owner" is the "menu item"
336 menu
->m_owner
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str
) );
337 menu
->SetLayoutDirection(GetLayoutDirection());
339 gtk_widget_show( menu
->m_owner
);
341 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu
->m_owner
), menu
->m_menu
);
344 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
);
346 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar
), menu
->m_owner
, pos
);
348 g_signal_connect (menu
->m_owner
, "activate",
349 G_CALLBACK (gtk_menu_open_callback
),
352 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
353 // addings menu later on.
354 if (m_invokingWindow
)
356 wxMenubarSetInvokingWindow( menu
, m_invokingWindow
);
358 // OPTIMISE ME: we should probably cache this, or pass it
359 // directly, but for now this is a minimal
360 // change to validate the new dynamic sizing.
361 // see (and refactor :) similar code in Remove
364 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
367 frame
->UpdateMenuBarSize();
373 bool wxMenuBar::Insert(size_t pos
, wxMenu
*menu
, const wxString
& title
)
375 if ( !wxMenuBarBase::Insert(pos
, menu
, title
) )
380 if ( !GtkAppend(menu
, title
, (int)pos
) )
386 wxMenu
*wxMenuBar::Replace(size_t pos
, wxMenu
*menu
, const wxString
& title
)
388 // remove the old item and insert a new one
389 wxMenu
*menuOld
= Remove(pos
);
390 if ( menuOld
&& !Insert(pos
, menu
, title
) )
392 return (wxMenu
*) NULL
;
395 // either Insert() succeeded or Remove() failed and menuOld is NULL
399 wxMenu
*wxMenuBar::Remove(size_t pos
)
401 wxMenu
*menu
= wxMenuBarBase::Remove(pos
);
403 return (wxMenu
*) NULL
;
405 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu
->m_owner
) );
406 gtk_container_remove(GTK_CONTAINER(m_menubar
), menu
->m_owner
);
408 gtk_widget_destroy( menu
->m_owner
);
409 menu
->m_owner
= NULL
;
411 if (m_invokingWindow
)
413 // OPTIMISE ME: see comment in GtkAppend
414 wxFrame
*frame
= wxDynamicCast( m_invokingWindow
, wxFrame
);
417 frame
->UpdateMenuBarSize();
423 static int FindMenuItemRecursive( const wxMenu
*menu
, const wxString
&menuString
, const wxString
&itemString
)
425 if (wxMenuItem::GetLabelFromText(menu
->GetTitle()) == wxMenuItem::GetLabelFromText(menuString
))
427 int res
= menu
->FindItem( itemString
);
428 if (res
!= wxNOT_FOUND
)
432 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
435 wxMenuItem
*item
= node
->GetData();
436 if (item
->IsSubMenu())
437 return FindMenuItemRecursive(item
->GetSubMenu(), menuString
, itemString
);
439 node
= node
->GetNext();
445 int wxMenuBar::FindMenuItem( const wxString
&menuString
, const wxString
&itemString
) const
447 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
450 wxMenu
*menu
= node
->GetData();
451 int res
= FindMenuItemRecursive( menu
, menuString
, itemString
);
454 node
= node
->GetNext();
460 // Find a wxMenuItem using its id. Recurses down into sub-menus
461 static wxMenuItem
* FindMenuItemByIdRecursive(const wxMenu
* menu
, int id
)
463 wxMenuItem
* result
= menu
->FindChildItem(id
);
465 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
466 while ( node
&& result
== NULL
)
468 wxMenuItem
*item
= node
->GetData();
469 if (item
->IsSubMenu())
471 result
= FindMenuItemByIdRecursive( item
->GetSubMenu(), id
);
473 node
= node
->GetNext();
479 wxMenuItem
* wxMenuBar::FindItem( int id
, wxMenu
**menuForItem
) const
481 wxMenuItem
* result
= 0;
482 wxMenuList::compatibility_iterator node
= m_menus
.GetFirst();
483 while (node
&& result
== 0)
485 wxMenu
*menu
= node
->GetData();
486 result
= FindMenuItemByIdRecursive( menu
, id
);
487 node
= node
->GetNext();
492 *menuForItem
= result
? result
->GetMenu() : (wxMenu
*)NULL
;
498 void wxMenuBar::EnableTop( size_t pos
, bool flag
)
500 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
502 wxCHECK_RET( node
, wxT("menu not found") );
504 wxMenu
* menu
= node
->GetData();
507 gtk_widget_set_sensitive( menu
->m_owner
, flag
);
510 wxString
wxMenuBar::GetLabelTop( size_t pos
) const
512 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
514 wxCHECK_MSG( node
, wxT("invalid"), wxT("menu not found") );
516 wxMenu
* menu
= node
->GetData();
519 wxString
text( menu
->GetTitle() );
520 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
522 if ( *pc
== wxT('_') )
524 // '_' is the escape character for GTK+
528 // don't remove ampersands '&' since if we have them in the menu title
529 // it means that they were doubled to indicate "&" instead of accelerator
537 void wxMenuBar::SetLabelTop( size_t pos
, const wxString
& label
)
539 wxMenuList::compatibility_iterator node
= m_menus
.Item( pos
);
541 wxCHECK_RET( node
, wxT("menu not found") );
543 wxMenu
* menu
= node
->GetData();
545 const wxString
str( wxReplaceUnderscore( label
) );
547 menu
->SetTitle( str
);
550 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu
->m_owner
)->child
), wxGTK_CONV(str
) );
553 //-----------------------------------------------------------------------------
555 //-----------------------------------------------------------------------------
558 static void gtk_menu_clicked_callback( GtkWidget
*widget
, wxMenu
*menu
)
560 int id
= menu
->FindMenuIdByMenuItem(widget
);
562 /* should find it for normal (not popup) menu */
563 wxASSERT_MSG( (id
!= -1) || (menu
->GetInvokingWindow() != NULL
),
564 _T("menu item not found in gtk_menu_clicked_callback") );
566 if (!menu
->IsEnabled(id
))
569 wxMenuItem
* item
= menu
->FindChildItem( id
);
570 wxCHECK_RET( item
, wxT("error in menu item callback") );
572 if ( item
->GetId() == wxGTK_TITLE_ID
)
574 // ignore events from the menu title
578 if (item
->IsCheckable())
580 bool isReallyChecked
= item
->IsChecked(),
581 isInternallyChecked
= item
->wxMenuItemBase::IsChecked();
583 // ensure that the internal state is always consistent with what is
584 // shown on the screen
585 item
->wxMenuItemBase::Check(isReallyChecked
);
587 // we must not report the events for the radio button going up nor the
588 // events resulting from the calls to wxMenuItem::Check()
589 if ( (item
->GetKind() == wxITEM_RADIO
&& !isReallyChecked
) ||
590 (isInternallyChecked
== isReallyChecked
) )
597 // Is this menu on a menubar? (possibly nested)
598 wxFrame
* frame
= NULL
;
599 if(menu
->IsAttached())
600 frame
= menu
->GetMenuBar()->GetFrame();
602 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
603 // normally wxMenu::SendEvent() should be enough, if it doesn't work
604 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
605 // should be fixed instead of working around it here...
608 // If it is attached then let the frame send the event.
609 // Don't call frame->ProcessCommand(id) because it toggles
610 // checkable items and we've already done that above.
611 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
612 commandEvent
.SetEventObject(frame
);
613 if (item
->IsCheckable())
614 commandEvent
.SetInt(item
->IsChecked());
615 commandEvent
.SetEventObject(menu
);
617 frame
->GetEventHandler()->ProcessEvent(commandEvent
);
621 // otherwise let the menu have it
622 menu
->SendEvent(id
, item
->IsCheckable() ? item
->IsChecked() : -1);
627 //-----------------------------------------------------------------------------
629 //-----------------------------------------------------------------------------
632 static void gtk_menu_hilight_callback( GtkWidget
*widget
, wxMenu
*menu
)
634 int id
= menu
->FindMenuIdByMenuItem(widget
);
636 wxASSERT( id
!= -1 ); // should find it!
638 if (!menu
->IsEnabled(id
))
641 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, id
);
642 event
.SetEventObject( menu
);
644 wxEvtHandler
* handler
= menu
->GetEventHandler();
645 if (handler
&& handler
->ProcessEvent(event
))
648 wxWindow
*win
= menu
->GetInvokingWindow();
649 if (win
) win
->GetEventHandler()->ProcessEvent( event
);
653 //-----------------------------------------------------------------------------
655 //-----------------------------------------------------------------------------
658 static void gtk_menu_nolight_callback( GtkWidget
*widget
, wxMenu
*menu
)
660 int id
= menu
->FindMenuIdByMenuItem(widget
);
662 wxASSERT( id
!= -1 ); // should find it!
664 if (!menu
->IsEnabled(id
))
667 wxMenuEvent
event( wxEVT_MENU_HIGHLIGHT
, -1 );
668 event
.SetEventObject( menu
);
670 wxEvtHandler
* handler
= menu
->GetEventHandler();
671 if (handler
&& handler
->ProcessEvent(event
))
674 wxWindow
*win
= menu
->GetInvokingWindow();
676 win
->GetEventHandler()->ProcessEvent( event
);
680 //-----------------------------------------------------------------------------
682 //-----------------------------------------------------------------------------
684 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
686 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
688 const wxString
& name
,
689 const wxString
& help
,
693 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);
696 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
698 const wxString
& text
,
699 const wxString
& help
,
702 : wxMenuItemBase(parentMenu
, id
, text
, help
, kind
, subMenu
)
707 wxMenuItem::wxMenuItem(wxMenu
*parentMenu
,
709 const wxString
& text
,
710 const wxString
& help
,
713 : wxMenuItemBase(parentMenu
, id
, text
, help
,
714 isCheckable
? wxITEM_CHECK
: wxITEM_NORMAL
, subMenu
)
719 void wxMenuItem::Init(const wxString
& text
)
721 m_labelWidget
= (GtkWidget
*) NULL
;
722 m_menuItem
= (GtkWidget
*) NULL
;
727 wxMenuItem::~wxMenuItem()
729 // don't delete menu items, the menus take care of that
732 // return the menu item text without any menu accels
734 wxString
wxMenuItemBase::GetLabelFromText(const wxString
& text
)
738 for ( const wxChar
*pc
= text
.c_str(); *pc
; pc
++ )
740 if ( *pc
== wxT('\t'))
743 if ( *pc
== wxT('_') )
745 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
751 if ( *pc
== wxT('\\') )
753 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
759 if ( (*pc
== wxT('&')) && (*(pc
+1) != wxT('&')) )
762 // "&" is doubled to indicate "&" instead of accelerator
769 // wxPrintf( wxT("GetLabelFromText(): text %s label %s\n"), text.c_str(), label.c_str() );
774 void wxMenuItem::SetText( const wxString
& str
)
776 // cache some data which must be used later
777 bool isstock
= wxIsStockID(GetId());
778 const char *stockid
= NULL
;
780 stockid
= wxGetStockGtkID(GetId());
782 // Some optimization to avoid flicker
783 wxString oldLabel
= m_text
;
784 oldLabel
= wxStripMenuCodes(oldLabel
);
785 oldLabel
.Replace(wxT("_"), wxT(""));
786 wxString label1
= wxStripMenuCodes(str
);
787 wxString oldhotkey
= GetHotKey(); // Store the old hotkey in Ctrl-foo format
788 wxCharBuffer oldbuf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
792 if (oldLabel
== label1
&&
793 oldhotkey
== GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
800 label
= (GtkLabel
*) m_labelWidget
;
802 label
= GTK_LABEL( GTK_BIN(m_menuItem
)->child
);
804 // stock menu items can have empty labels:
805 wxString text
= m_text
;
806 if (text
.IsEmpty() && !IsSeparator())
808 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
809 text
= wxGetStockLabel(GetId());
811 // need & => _ conversion
812 text
= GTKProcessMenuItemLabel(text
, NULL
);
815 gtk_label_set_text_with_mnemonic( GTK_LABEL(label
), wxGTK_CONV_SYS(text
) );
818 // remove old accelerator from our parent's accelerator group, if present
820 GdkModifierType accel_mods
;
821 if (oldbuf
[(size_t)0] != '\0')
823 gtk_accelerator_parse( (const char*) oldbuf
, &accel_key
, &accel_mods
);
826 gtk_widget_remove_accelerator(m_menuItem
,
827 m_parentMenu
->m_accel
,
834 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
835 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
836 gtk_widget_remove_accelerator( m_menuItem
,
837 m_parentMenu
->m_accel
,
842 // add new accelerator to our parent's accelerator group
843 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*this) );
844 if (buf
[(size_t)0] != '\0')
846 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
849 gtk_widget_add_accelerator( m_menuItem
,
851 m_parentMenu
->m_accel
,
859 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
860 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
861 gtk_widget_remove_accelerator( m_menuItem
,
862 m_parentMenu
->m_accel
,
868 // NOTE: this function is different from the similar functions GTKProcessMnemonics()
869 // implemented in control.cpp and from wxMenuItemBase::GetLabelFromText...
870 // so there's no real code duplication
871 wxString
wxMenuItem::GTKProcessMenuItemLabel(const wxString
& str
, wxString
*hotKey
)
875 // '\t' is the deliminator indicating a hot key
876 const wxChar
*pc
= str
;
877 while ( (*pc
!= wxT('\0')) && (*pc
!= wxT('\t')) )
879 if ((*pc
== wxT('&')) && (*(pc
+1) == wxT('&')))
881 // "&" is doubled to indicate "&" instead of accelerator
885 else if (*pc
== wxT('&'))
889 else if ( *pc
== wxT('_') ) // escape underscores
913 // it's valid for this function to be called even if m_menuItem == NULL
914 void wxMenuItem::DoSetText( const wxString
& str
)
917 m_text
= GTKProcessMenuItemLabel(str
, &m_hotKey
);
922 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
930 // accelerator parsing code looks for them after a TAB, so insert a dummy
933 label
<< wxT('\t') << GetHotKey();
935 return wxAcceleratorEntry::Create(label
);
938 #endif // wxUSE_ACCEL
940 void wxMenuItem::Check( bool check
)
942 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
944 if (check
== m_isChecked
)
947 wxMenuItemBase::Check( check
);
953 gtk_check_menu_item_set_active( (GtkCheckMenuItem
*)m_menuItem
, (gint
)check
);
957 wxFAIL_MSG( _T("can't check this item") );
961 void wxMenuItem::Enable( bool enable
)
963 wxCHECK_RET( m_menuItem
, wxT("invalid menu item") );
965 gtk_widget_set_sensitive( m_menuItem
, enable
);
966 wxMenuItemBase::Enable( enable
);
969 bool wxMenuItem::IsChecked() const
971 wxCHECK_MSG( m_menuItem
, false, wxT("invalid menu item") );
973 wxCHECK_MSG( IsCheckable(), false,
974 wxT("can't get state of uncheckable item!") );
976 return ((GtkCheckMenuItem
*)m_menuItem
)->active
!= 0;
979 //-----------------------------------------------------------------------------
981 //-----------------------------------------------------------------------------
983 IMPLEMENT_DYNAMIC_CLASS(wxMenu
,wxEvtHandler
)
987 m_accel
= gtk_accel_group_new();
988 m_menu
= gtk_menu_new();
989 // NB: keep reference to the menu so that it is not destroyed behind
990 // our back by GTK+ e.g. when it is removed from menubar:
991 gtk_widget_ref(m_menu
);
993 m_owner
= (GtkWidget
*) NULL
;
995 // Tearoffs are entries, just like separators. So if we want this
996 // menu to be a tear-off one, we just append a tearoff entry
998 if ( m_style
& wxMENU_TEAROFF
)
1000 GtkWidget
*tearoff
= gtk_tearoff_menu_item_new();
1002 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), tearoff
);
1007 // append the title as the very first entry if we have it
1008 if ( !m_title
.empty() )
1010 Append(wxGTK_TITLE_ID
, m_title
);
1017 WX_CLEAR_LIST(wxMenuItemList
, m_items
);
1019 if ( GTK_IS_WIDGET( m_menu
))
1022 gtk_widget_unref( m_menu
);
1023 // if the menu is inserted in another menu at this time, there was
1024 // one more reference to it:
1026 gtk_widget_destroy( m_menu
);
1030 void wxMenu::SetLayoutDirection(const wxLayoutDirection dir
)
1033 wxWindow::GTKSetLayout(m_owner
, dir
);
1034 //else: will be called later by wxMenuBar again
1037 wxLayoutDirection
wxMenu::GetLayoutDirection() const
1039 return wxWindow::GTKGetLayout(m_owner
);
1042 bool wxMenu::GtkAppend(wxMenuItem
*mitem
, int pos
)
1044 GtkWidget
*menuItem
;
1046 // cache some data used later
1047 wxString text
= mitem
->GetText();
1048 int id
= mitem
->GetId();
1049 bool isstock
= wxIsStockID(id
);
1050 const char *stockid
= NULL
;
1052 stockid
= wxGetStockGtkID(mitem
->GetId());
1054 // stock menu items can have an empty label
1055 if (text
.IsEmpty() && !mitem
->IsSeparator())
1057 wxASSERT_MSG(isstock
, wxT("A non-stock menu item with an empty label?"));
1058 text
= wxGetStockLabel(id
);
1060 // need & => _ conversion
1061 text
= wxMenuItem::GTKProcessMenuItemLabel(text
, NULL
);
1064 if ( mitem
->IsSeparator() )
1066 menuItem
= gtk_separator_menu_item_new();
1068 else if ( mitem
->GetBitmap().Ok() ||
1069 (mitem
->GetKind() == wxITEM_NORMAL
&& isstock
) )
1071 wxBitmap
bitmap(mitem
->GetBitmap());
1073 menuItem
= gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1078 // use stock bitmap for this item if available on the assumption
1079 // that it never hurts to follow GTK+ conventions more closely
1080 image
= stockid
? gtk_image_new_from_stock(stockid
, GTK_ICON_SIZE_MENU
)
1083 else // we have a custom bitmap
1085 wxASSERT_MSG( mitem
->GetKind() == wxITEM_NORMAL
,
1086 _T("only normal menu items can have bitmaps") );
1088 if ( bitmap
.HasPixbuf() )
1090 image
= gtk_image_new_from_pixbuf(bitmap
.GetPixbuf());
1094 GdkPixmap
*gdk_pixmap
= bitmap
.GetPixmap();
1095 GdkBitmap
*gdk_bitmap
= bitmap
.GetMask() ?
1096 bitmap
.GetMask()->GetBitmap() :
1098 image
= gtk_image_new_from_pixmap( gdk_pixmap
, gdk_bitmap
);
1104 gtk_widget_show(image
);
1106 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem
), image
);
1111 else // a normal item
1113 // NB: 'text' variable has "_" instead of "&" after mitem->SetText()
1116 switch ( mitem
->GetKind() )
1120 menuItem
= gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1127 GSList
*group
= NULL
;
1128 if ( m_prevRadio
== NULL
)
1130 // start of a new radio group
1131 m_prevRadio
= menuItem
=
1132 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1134 else // continue the radio group
1136 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio
));
1137 m_prevRadio
= menuItem
=
1138 gtk_radio_menu_item_new_with_mnemonic( group
, wxGTK_CONV_SYS( text
) );
1144 wxFAIL_MSG( _T("unexpected menu item kind") );
1149 menuItem
= gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text
) );
1158 GdkModifierType accel_mods
;
1159 wxCharBuffer buf
= wxGTK_CONV_SYS( GetGtkHotKey(*mitem
) );
1161 // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() );
1162 if (buf
[(size_t)0] != '\0')
1164 gtk_accelerator_parse( (const char*) buf
, &accel_key
, &accel_mods
);
1167 gtk_widget_add_accelerator (menuItem
,
1177 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1178 if (wxGetStockGtkAccelerator(stockid
, &accel_mods
, &accel_key
))
1179 gtk_widget_add_accelerator( menuItem
,
1188 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu
), menuItem
);
1190 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu
), menuItem
, pos
);
1192 gtk_widget_show( menuItem
);
1194 if ( !mitem
->IsSeparator() )
1196 wxASSERT_MSG( menuItem
, wxT("invalid menuitem") );
1198 g_signal_connect (menuItem
, "select",
1199 G_CALLBACK (gtk_menu_hilight_callback
), this);
1200 g_signal_connect (menuItem
, "deselect",
1201 G_CALLBACK (gtk_menu_nolight_callback
), this);
1203 if ( mitem
->IsSubMenu() && mitem
->GetKind() != wxITEM_RADIO
&& mitem
->GetKind() != wxITEM_CHECK
)
1205 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem
), mitem
->GetSubMenu()->m_menu
);
1207 gtk_widget_show( mitem
->GetSubMenu()->m_menu
);
1209 // if adding a submenu to a menu already existing in the menu bar, we
1210 // must set invoking window to allow processing events from this
1212 if ( m_invokingWindow
)
1213 wxMenubarSetInvokingWindow(mitem
->GetSubMenu(), m_invokingWindow
);
1217 g_signal_connect (menuItem
, "activate",
1218 G_CALLBACK (gtk_menu_clicked_callback
),
1223 mitem
->SetMenuItem(menuItem
);
1227 // This doesn't even exist!
1228 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
1234 wxMenuItem
* wxMenu::DoAppend(wxMenuItem
*mitem
)
1236 if (!GtkAppend(mitem
))
1239 return wxMenuBase::DoAppend(mitem
);
1242 wxMenuItem
* wxMenu::DoInsert(size_t pos
, wxMenuItem
*item
)
1244 if ( !wxMenuBase::DoInsert(pos
, item
) )
1248 if ( !GtkAppend(item
, (int)pos
) )
1254 wxMenuItem
*wxMenu::DoRemove(wxMenuItem
*item
)
1256 if ( !wxMenuBase::DoRemove(item
) )
1257 return (wxMenuItem
*)NULL
;
1259 // TODO: this code doesn't delete the item factory item and this seems
1260 // impossible as of GTK 1.2.6.
1261 gtk_widget_destroy( item
->GetMenuItem() );
1266 int wxMenu::FindMenuIdByMenuItem( GtkWidget
*menuItem
) const
1268 wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
1271 wxMenuItem
*item
= node
->GetData();
1272 if (item
->GetMenuItem() == menuItem
)
1273 return item
->GetId();
1274 node
= node
->GetNext();
1280 void wxMenu::Attach(wxMenuBarBase
*menubar
)
1282 wxMenuBase::Attach(menubar
);
1284 // inherit layout direction from menubar.
1285 SetLayoutDirection(menubar
->GetLayoutDirection());
1288 // ----------------------------------------------------------------------------
1290 // ----------------------------------------------------------------------------
1294 static wxString
GetGtkHotKey( const wxMenuItem
& item
)
1298 wxAcceleratorEntry
*accel
= item
.GetAccel();
1301 int flags
= accel
->GetFlags();
1302 if ( flags
& wxACCEL_ALT
)
1303 hotkey
+= wxT("<alt>");
1304 if ( flags
& wxACCEL_CTRL
)
1305 hotkey
+= wxT("<control>");
1306 if ( flags
& wxACCEL_SHIFT
)
1307 hotkey
+= wxT("<shift>");
1309 int code
= accel
->GetKeyCode();
1336 hotkey
+= wxString::Format(wxT("F%d"), code
- WXK_F1
+ 1);
1339 // TODO: we should use gdk_keyval_name() (a.k.a.
1340 // XKeysymToString) here as well as hardcoding the keysym
1341 // names this might be not portable
1343 hotkey
<< wxT("Insert" );
1346 hotkey
<< wxT("Delete" );
1349 hotkey
<< wxT("Up" );
1352 hotkey
<< wxT("Down" );
1355 hotkey
<< wxT("Page_Up" );
1358 hotkey
<< wxT("Page_Down" );
1361 hotkey
<< wxT("Left" );
1364 hotkey
<< wxT("Right" );
1367 hotkey
<< wxT("Home" );
1370 hotkey
<< wxT("End" );
1373 hotkey
<< wxT("Return" );
1376 hotkey
<< wxT("BackSpace" );
1379 hotkey
<< wxT("Tab" );
1382 hotkey
<< wxT("Esc" );
1385 hotkey
<< wxT("space" );
1388 hotkey
<< wxT("Multiply" );
1391 hotkey
<< wxT("Add" );
1394 hotkey
<< wxT("Separator" );
1397 hotkey
<< wxT("Subtract" );
1400 hotkey
<< wxT("Decimal" );
1403 hotkey
<< wxT("Divide" );
1406 hotkey
<< wxT("Cancel" );
1409 hotkey
<< wxT("Clear" );
1412 hotkey
<< wxT("Menu" );
1415 hotkey
<< wxT("Pause" );
1418 hotkey
<< wxT("Capital" );
1421 hotkey
<< wxT("Select" );
1424 hotkey
<< wxT("Print" );
1427 hotkey
<< wxT("Execute" );
1430 hotkey
<< wxT("Snapshot" );
1433 hotkey
<< wxT("Help" );
1436 hotkey
<< wxT("Num_Lock" );
1439 hotkey
<< wxT("Scroll_Lock" );
1441 case WXK_NUMPAD_INSERT
:
1442 hotkey
<< wxT("KP_Insert" );
1444 case WXK_NUMPAD_DELETE
:
1445 hotkey
<< wxT("KP_Delete" );
1447 case WXK_NUMPAD_SPACE
:
1448 hotkey
<< wxT("KP_Space" );
1450 case WXK_NUMPAD_TAB
:
1451 hotkey
<< wxT("KP_Tab" );
1453 case WXK_NUMPAD_ENTER
:
1454 hotkey
<< wxT("KP_Enter" );
1456 case WXK_NUMPAD_F1
: case WXK_NUMPAD_F2
: case WXK_NUMPAD_F3
:
1458 hotkey
+= wxString::Format(wxT("KP_F%d"), code
- WXK_NUMPAD_F1
+ 1);
1460 case WXK_NUMPAD_HOME
:
1461 hotkey
<< wxT("KP_Home" );
1463 case WXK_NUMPAD_LEFT
:
1464 hotkey
<< wxT("KP_Left" );
1467 hotkey
<< wxT("KP_Up" );
1469 case WXK_NUMPAD_RIGHT
:
1470 hotkey
<< wxT("KP_Right" );
1472 case WXK_NUMPAD_DOWN
:
1473 hotkey
<< wxT("KP_Down" );
1475 case WXK_NUMPAD_PAGEUP
:
1476 hotkey
<< wxT("KP_Page_Up" );
1478 case WXK_NUMPAD_PAGEDOWN
:
1479 hotkey
<< wxT("KP_Page_Down" );
1481 case WXK_NUMPAD_END
:
1482 hotkey
<< wxT("KP_End" );
1484 case WXK_NUMPAD_BEGIN
:
1485 hotkey
<< wxT("KP_Begin" );
1487 case WXK_NUMPAD_EQUAL
:
1488 hotkey
<< wxT("KP_Equal" );
1490 case WXK_NUMPAD_MULTIPLY
:
1491 hotkey
<< wxT("KP_Multiply" );
1493 case WXK_NUMPAD_ADD
:
1494 hotkey
<< wxT("KP_Add" );
1496 case WXK_NUMPAD_SEPARATOR
:
1497 hotkey
<< wxT("KP_Separator" );
1499 case WXK_NUMPAD_SUBTRACT
:
1500 hotkey
<< wxT("KP_Subtract" );
1502 case WXK_NUMPAD_DECIMAL
:
1503 hotkey
<< wxT("KP_Decimal" );
1505 case WXK_NUMPAD_DIVIDE
:
1506 hotkey
<< wxT("KP_Divide" );
1508 case WXK_NUMPAD0
: case WXK_NUMPAD1
: case WXK_NUMPAD2
:
1509 case WXK_NUMPAD3
: case WXK_NUMPAD4
: case WXK_NUMPAD5
:
1510 case WXK_NUMPAD6
: case WXK_NUMPAD7
: case WXK_NUMPAD8
: case WXK_NUMPAD9
:
1511 hotkey
+= wxString::Format(wxT("KP_%d"), code
- WXK_NUMPAD0
);
1513 case WXK_WINDOWS_LEFT
:
1514 hotkey
<< wxT("Super_L" );
1516 case WXK_WINDOWS_RIGHT
:
1517 hotkey
<< wxT("Super_R" );
1519 case WXK_WINDOWS_MENU
:
1520 hotkey
<< wxT("Menu" );
1523 hotkey
<< wxT("Command" );
1525 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
1526 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1527 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1528 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1529 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
1530 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1531 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1534 // if there are any other keys wxAcceleratorEntry::Create() may
1535 // return, we should process them here
1541 name
= wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint
)code
));
1542 if ( !name
.empty() )
1549 wxFAIL_MSG( wxT("unknown keyboard accel") );
1558 #endif // wxUSE_ACCEL
1560 // ----------------------------------------------------------------------------
1561 // Pop-up menu stuff
1562 // ----------------------------------------------------------------------------
1564 #if wxUSE_MENUS_NATIVE
1566 extern "C" WXDLLIMPEXP_CORE
1567 void gtk_pop_hide_callback( GtkWidget
*WXUNUSED(widget
), bool* is_waiting
)
1569 *is_waiting
= false;
1572 WXDLLIMPEXP_CORE
void SetInvokingWindow( wxMenu
*menu
, wxWindow
* win
)
1574 menu
->SetInvokingWindow( win
);
1576 wxMenuItemList::compatibility_iterator node
= menu
->GetMenuItems().GetFirst();
1579 wxMenuItem
*menuitem
= node
->GetData();
1580 if (menuitem
->IsSubMenu())
1582 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
1585 node
= node
->GetNext();
1589 extern "C" WXDLLIMPEXP_CORE
1590 void wxPopupMenuPositionCallback( GtkMenu
*menu
,
1592 gboolean
* WXUNUSED(whatever
),
1593 gpointer user_data
)
1595 // ensure that the menu appears entirely on screen
1597 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &req
);
1599 wxSize sizeScreen
= wxGetDisplaySize();
1600 wxPoint
*pos
= (wxPoint
*)user_data
;
1602 gint xmax
= sizeScreen
.x
- req
.width
,
1603 ymax
= sizeScreen
.y
- req
.height
;
1605 *x
= pos
->x
< xmax
? pos
->x
: xmax
;
1606 *y
= pos
->y
< ymax
? pos
->y
: ymax
;
1609 bool wxWindowGTK::DoPopupMenu( wxMenu
*menu
, int x
, int y
)
1611 wxCHECK_MSG( m_widget
!= NULL
, false, wxT("invalid window") );
1613 wxCHECK_MSG( menu
!= NULL
, false, wxT("invalid popup-menu") );
1615 // NOTE: if you change this code, you need to update
1616 // the same code in taskbar.cpp as well. This
1617 // is ugly code duplication, I know.
1619 SetInvokingWindow( menu
, this );
1623 bool is_waiting
= true;
1625 gulong handler
= g_signal_connect (menu
->m_menu
, "hide",
1626 G_CALLBACK (gtk_pop_hide_callback
),
1631 GtkMenuPositionFunc posfunc
;
1632 if ( x
== -1 && y
== -1 )
1634 // use GTK's default positioning algorithm
1640 pos
= ClientToScreen(wxPoint(x
, y
));
1642 posfunc
= wxPopupMenuPositionCallback
;
1645 wxMenuEvent
eventOpen(wxEVT_MENU_OPEN
, -1, menu
);
1646 DoCommonMenuCallbackCode(menu
, eventOpen
);
1649 GTK_MENU(menu
->m_menu
),
1650 (GtkWidget
*) NULL
, // parent menu shell
1651 (GtkWidget
*) NULL
, // parent menu item
1652 posfunc
, // function to position it
1653 userdata
, // client data
1654 0, // button used to activate it
1655 gtk_get_current_event_time()
1660 gtk_main_iteration();
1663 g_signal_handler_disconnect (menu
->m_menu
, handler
);
1665 wxMenuEvent
eventClose(wxEVT_MENU_CLOSE
, -1, menu
);
1666 DoCommonMenuCallbackCode(menu
, eventClose
);
1671 #endif // wxUSE_MENUS_NATIVE
1675 #include <gtk/gtk.h>
1677 const char *wxGetStockGtkID(wxWindowID id
)
1679 #define STOCKITEM(wx,gtk) \
1683 #define STOCKITEM_MISSING(wx) \
1687 #if GTK_CHECK_VERSION(2,4,0)
1688 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1690 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1693 #if GTK_CHECK_VERSION(2,6,0)
1694 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1696 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1699 #if GTK_CHECK_VERSION(2,10,0)
1700 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1702 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1708 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
1709 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
1710 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
1711 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
1712 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
1713 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
1714 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
1715 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
1716 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
1717 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
1718 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
1719 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
1720 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
1721 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
1722 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
1723 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
1724 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
1725 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
1726 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
1727 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
1728 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
1729 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
1730 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
1731 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
1732 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
1733 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
1734 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
1735 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
1736 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
1737 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
1738 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
1739 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
1740 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
1741 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
1742 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
1743 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
1744 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
1745 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
1746 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
1747 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
1748 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
1749 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
1750 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
1751 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
1752 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
1753 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
1754 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
1755 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
1756 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
1757 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
1758 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
1759 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
1760 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
1761 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
1764 wxFAIL_MSG( _T("invalid stock item ID") );
1773 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
1778 GtkStockItem stock_item
;
1779 if (gtk_stock_lookup (id
, &stock_item
))
1781 if (key
) *key
= stock_item
.keyval
;
1782 if (mod
) *mod
= stock_item
.modifier
;
1784 // some GTK stock items have zero values for the keyval;
1785 // it means that they do not have an accelerator...
1786 if (stock_item
.keyval
)
1793 #endif // __WXGTK20__