]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/menu.cpp
Always invoke default action even if dclick is caught from wxListBox (as per wxMSW...
[wxWidgets.git] / src / gtk / menu.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/gtk/menu.cpp
28fcfbfe 3// Purpose: implementation of wxMenuBar and wxMenu classes for wxGTK
c801d85f 4// Author: Robert Roebling
96fd301f 5// Id: $Id$
a81258be 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
28fcfbfe
VZ
13#if wxUSE_MENUS
14
e1bf3ad3 15#include "wx/menu.h"
88a7a4e1
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/intl.h"
e4db172a 19 #include "wx/log.h"
d281df50 20 #include "wx/frame.h"
0bca0373 21 #include "wx/bitmap.h"
7d02e0d6 22 #include "wx/app.h"
88a7a4e1
WS
23#endif
24
d281df50 25#include "wx/accel.h"
ab73fe8d 26#include "wx/stockitem.h"
9e691f46 27#include "wx/gtk/private.h"
b1f17bf0 28#include "wx/gtk/private/mnemonics.h"
9e691f46 29
9e691f46 30// FIXME: is this right? somehow I don't think so (VZ)
0d2c4443
PC
31
32#define gtk_accel_group_attach(g, o) gtk_window_add_accel_group((o), (g))
05b743ba 33#define gtk_accel_group_detach(g, o) gtk_window_remove_accel_group((o), (g))
0d2c4443
PC
34//#define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m)
35
36#define ACCEL_OBJECT GtkWindow
37#define ACCEL_OBJECTS(a) (a)->acceleratables
38#define ACCEL_OBJ_CAST(obj) ((GtkWindow*) obj)
83624f79 39
9959e2b6
VZ
40// we use normal item but with a special id for the menu title
41static const int wxGTK_TITLE_ID = -3;
42
5e6f2fe9
VZ
43// forward declare it as it's used by wxMenuBar too when using Hildon
44extern "C"
45{
46 static void gtk_menu_clicked_callback(GtkWidget *widget, wxMenu *menu);
47}
6c76d1ce 48
6d971354 49#if wxUSE_ACCEL
19abd352 50static bool wxGetStockGtkAccelerator(const char *id, GdkModifierType *mod, guint *key);
98f29783 51static wxString GetGtkHotKey( const wxMenuItem& item );
717a57c2
VZ
52#endif
53
e6396ed4
JS
54//-----------------------------------------------------------------------------
55// activate message from GTK
56//-----------------------------------------------------------------------------
57
cdf003d4 58static void DoCommonMenuCallbackCode(wxMenu *menu, wxMenuEvent& event)
e6396ed4 59{
e6396ed4
JS
60 event.SetEventObject( menu );
61
a01fe3d6 62 wxEvtHandler* handler = menu->GetEventHandler();
937013e0 63 if (handler && handler->SafelyProcessEvent(event))
e6396ed4
JS
64 return;
65
66 wxWindow *win = menu->GetInvokingWindow();
cdf003d4 67 if (win)
937013e0 68 win->HandleWindowEvent( event );
cdf003d4
VZ
69}
70
71extern "C" {
72
e4161a2a
VZ
73static void
74gtk_menu_open_callback(GtkWidget * WXUNUSED(widget), wxMenu *menu)
cdf003d4
VZ
75{
76 wxMenuEvent event(wxEVT_MENU_OPEN, -1, menu);
77
78 DoCommonMenuCallbackCode(menu, event);
79}
80
e4161a2a
VZ
81static void
82gtk_menu_close_callback(GtkWidget * WXUNUSED(widget), wxMenuBar *menubar)
cdf003d4 83{
13d35112
VZ
84 if ( !menubar->GetMenuCount() )
85 {
86 // if menubar is empty we can't call GetMenu(0) below
87 return;
88 }
cdf003d4 89
13d35112
VZ
90 wxMenuEvent event( wxEVT_MENU_CLOSE, -1, NULL );
91
92 DoCommonMenuCallbackCode(menubar->GetMenu(0), event);
e6396ed4 93}
cdf003d4 94
865bb325 95}
e6396ed4 96
c801d85f
KB
97//-----------------------------------------------------------------------------
98// wxMenuBar
99//-----------------------------------------------------------------------------
100
101IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
102
294ea16d 103void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long style)
3502e687 104{
ae53c98c 105 m_style = style;
e8375af8 106 m_invokingWindow = NULL;
23280650 107
e2f3bc41
VZ
108#if wxUSE_LIBHILDON
109 // Hildon window uses a single menu instead of a menu bar, so wxMenuBar is
110 // the same as menu in this case
111 m_widget =
112 m_menubar = gtk_menu_new();
113#else // !wxUSE_LIBHILDON
e8375af8
VZ
114 if (!PreCreation( NULL, wxDefaultPosition, wxDefaultSize ) ||
115 !CreateBase( NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") ))
4dcaf11a 116 {
223d09f6 117 wxFAIL_MSG( wxT("wxMenuBar creation failed") );
455fadaa 118 return;
4dcaf11a 119 }
3502e687 120
3502e687
RR
121 m_menubar = gtk_menu_bar_new();
122
123 if (style & wxMB_DOCKABLE)
124 {
125 m_widget = gtk_handle_box_new();
10bd1f7d
PC
126 gtk_container_add(GTK_CONTAINER(m_widget), m_menubar);
127 gtk_widget_show(m_menubar);
3502e687
RR
128 }
129 else
130 {
10bd1f7d 131 m_widget = m_menubar;
3502e687
RR
132 }
133
134 PostCreation();
c4608a8a 135
db434467 136 ApplyWidgetStyle();
e2f3bc41 137#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
294ea16d
VZ
138
139 for (size_t i = 0; i < n; ++i )
140 Append(menus[i], titles[i]);
13d35112
VZ
141
142 // VZ: for some reason connecting to menus "deactivate" doesn't work (we
143 // don't get it when the menu is dismissed by clicking outside the
144 // toolbar) so we connect to the global one, even if it means that we
145 // can't pass the menu which was closed in wxMenuEvent object
9fa72bd2
MR
146 g_signal_connect (m_menubar, "deactivate",
147 G_CALLBACK (gtk_menu_close_callback), this);
3502e687
RR
148}
149
294ea16d 150wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style)
c801d85f 151{
294ea16d
VZ
152 Init(n, menus, titles, style);
153}
96fd301f 154
294ea16d
VZ
155wxMenuBar::wxMenuBar(long style)
156{
157 Init(0, NULL, NULL, style);
158}
c4608a8a 159
294ea16d
VZ
160wxMenuBar::wxMenuBar()
161{
162 Init(0, NULL, NULL, 0);
6de97a3b 163}
c801d85f 164
1e133b7d
RR
165wxMenuBar::~wxMenuBar()
166{
1e133b7d
RR
167}
168
5bd9e519
RR
169static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
170{
171 menu->SetInvokingWindow( (wxWindow*) NULL );
172
5bd9e519 173 wxWindow *top_frame = win;
8487f887 174 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
bd77da97 175 top_frame = top_frame->GetParent();
5bd9e519 176
05b743ba
RR
177 // support for native hot keys
178 ACCEL_OBJECT *obj = ACCEL_OBJ_CAST(top_frame->m_widget);
179 if ( menu->m_accel && g_slist_find( ACCEL_OBJECTS(menu->m_accel), obj ) )
180 gtk_accel_group_detach( menu->m_accel, obj );
181
222ed1d6 182 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
5bd9e519
RR
183 while (node)
184 {
1987af7e 185 wxMenuItem *menuitem = node->GetData();
5bd9e519
RR
186 if (menuitem->IsSubMenu())
187 wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win );
1987af7e 188 node = node->GetNext();
5bd9e519
RR
189 }
190}
191
192static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
193{
194 menu->SetInvokingWindow( win );
195
5bd9e519 196 wxWindow *top_frame = win;
8487f887 197 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
bd77da97 198 top_frame = top_frame->GetParent();
5bd9e519 199
6d971354 200 // support for native hot keys
9e691f46
VZ
201 ACCEL_OBJECT *obj = ACCEL_OBJ_CAST(top_frame->m_widget);
202 if ( !g_slist_find( ACCEL_OBJECTS(menu->m_accel), obj ) )
b4da05a6 203 gtk_accel_group_attach( menu->m_accel, obj );
5bd9e519 204
222ed1d6 205 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
5bd9e519
RR
206 while (node)
207 {
1987af7e 208 wxMenuItem *menuitem = node->GetData();
5bd9e519
RR
209 if (menuitem->IsSubMenu())
210 wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win );
1987af7e 211 node = node->GetNext();
5bd9e519
RR
212 }
213}
214
215void wxMenuBar::SetInvokingWindow( wxWindow *win )
216{
9c884972 217 m_invokingWindow = win;
5bd9e519 218 wxWindow *top_frame = win;
8487f887 219 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
bd77da97 220 top_frame = top_frame->GetParent();
5bd9e519 221
222ed1d6 222 wxMenuList::compatibility_iterator node = m_menus.GetFirst();
5bd9e519
RR
223 while (node)
224 {
1987af7e 225 wxMenu *menu = node->GetData();
5bd9e519 226 wxMenubarSetInvokingWindow( menu, win );
1987af7e 227 node = node->GetNext();
5bd9e519
RR
228 }
229}
230
978af864
VZ
231void wxMenuBar::SetLayoutDirection(wxLayoutDirection dir)
232{
233 if ( dir == wxLayout_Default )
234 {
235 const wxWindow *const frame = GetFrame();
236 if ( frame )
237 {
238 // inherit layout from frame.
239 dir = frame->GetLayoutDirection();
240 }
241 else // use global layout
242 {
243 dir = wxTheApp->GetLayoutDirection();
244 }
245 }
246
247 if ( dir == wxLayout_Default )
248 return;
249
250 GTKSetLayout(m_menubar, dir);
251
252 // also set the layout of all menus we already have (new ones will inherit
253 // the current layout)
254 for ( wxMenuList::compatibility_iterator node = m_menus.GetFirst();
255 node;
256 node = node->GetNext() )
257 {
258 wxMenu *const menu = node->GetData();
259 menu->SetLayoutDirection(dir);
260 }
261}
262
263wxLayoutDirection wxMenuBar::GetLayoutDirection() const
264{
265 return GTKGetLayout(m_menubar);
266}
267
268void wxMenuBar::Attach(wxFrame *frame)
269{
270 wxMenuBarBase::Attach(frame);
271
272 SetLayoutDirection(wxLayout_Default);
273}
274
5bd9e519
RR
275void wxMenuBar::UnsetInvokingWindow( wxWindow *win )
276{
9c884972 277 m_invokingWindow = (wxWindow*) NULL;
5bd9e519 278 wxWindow *top_frame = win;
8487f887 279 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
bd77da97 280 top_frame = top_frame->GetParent();
9959e2b6 281
222ed1d6 282 wxMenuList::compatibility_iterator node = m_menus.GetFirst();
5bd9e519
RR
283 while (node)
284 {
1987af7e 285 wxMenu *menu = node->GetData();
5bd9e519 286 wxMenubarUnsetInvokingWindow( menu, win );
1987af7e 287 node = node->GetNext();
5bd9e519
RR
288 }
289}
290
3dfac970 291bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
c801d85f 292{
f03ec224 293 if ( !wxMenuBarBase::Append( menu, title ) )
670f9935 294 return false;
f03ec224
VZ
295
296 return GtkAppend(menu, title);
297}
23280650 298
49826dab 299bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
f03ec224 300{
6c76d1ce 301 menu->SetLayoutDirection(GetLayoutDirection());
1e133b7d 302
6c76d1ce
VZ
303#if wxUSE_LIBHILDON
304 // if the menu has only one item, append it directly to the top level menu
305 // instead of inserting a useless submenu
306 if ( menu->GetMenuItemCount() == 1 )
307 {
308 wxMenuItem * const item = menu->FindItemByPosition(0);
23280650 309
6c76d1ce
VZ
310 // remove both mnemonics and accelerator: neither is useful under Maemo
311 const wxString str(wxStripMenuCodes(item->GetItemLabel()));
96fd301f 312
6c76d1ce
VZ
313 if ( item->IsSubMenu() )
314 return GtkAppend(item->GetSubMenu(), str, pos);
315
316 menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) );
9959e2b6 317
6c76d1ce
VZ
318 g_signal_connect(menu->m_owner, "activate",
319 G_CALLBACK(gtk_menu_clicked_callback), menu);
320 item->SetMenuItem(menu->m_owner);
321 }
322 else
323#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
324 {
325 const wxString str(wxConvertMnemonicsToGTK(title));
326
327 // This doesn't have much effect right now.
328 menu->SetTitle( str );
329
330 // The "m_owner" is the "menu item"
331 menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) );
332
333 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
334 }
335
336 gtk_widget_show( menu->m_owner );
9959e2b6 337
49826dab
RD
338 if (pos == -1)
339 gtk_menu_shell_append( GTK_MENU_SHELL(m_menubar), menu->m_owner );
340 else
341 gtk_menu_shell_insert( GTK_MENU_SHELL(m_menubar), menu->m_owner, pos );
9959e2b6 342
9fa72bd2
MR
343 g_signal_connect (menu->m_owner, "activate",
344 G_CALLBACK (gtk_menu_open_callback),
345 menu);
e6396ed4 346
9c884972 347 // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
2b5f62a0 348 // addings menu later on.
9c884972
RR
349 if (m_invokingWindow)
350 wxMenubarSetInvokingWindow( menu, m_invokingWindow );
3dfac970 351
670f9935 352 return true;
3dfac970
VZ
353}
354
355bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
356{
357 if ( !wxMenuBarBase::Insert(pos, menu, title) )
670f9935 358 return false;
3dfac970 359
6d971354 360 // TODO
9959e2b6 361
49826dab 362 if ( !GtkAppend(menu, title, (int)pos) )
670f9935 363 return false;
f03ec224 364
670f9935 365 return true;
3dfac970
VZ
366}
367
368wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
369{
f03ec224
VZ
370 // remove the old item and insert a new one
371 wxMenu *menuOld = Remove(pos);
372 if ( menuOld && !Insert(pos, menu, title) )
373 {
1d62a8b4 374 return (wxMenu*) NULL;
f03ec224 375 }
3dfac970 376
f03ec224
VZ
377 // either Insert() succeeded or Remove() failed and menuOld is NULL
378 return menuOld;
3dfac970
VZ
379}
380
381wxMenu *wxMenuBar::Remove(size_t pos)
382{
f03ec224
VZ
383 wxMenu *menu = wxMenuBarBase::Remove(pos);
384 if ( !menu )
1d62a8b4 385 return (wxMenu*) NULL;
f03ec224 386
defc0789
VS
387 gtk_menu_item_remove_submenu( GTK_MENU_ITEM(menu->m_owner) );
388 gtk_container_remove(GTK_CONTAINER(m_menubar), menu->m_owner);
c4608a8a 389
1d62a8b4 390 gtk_widget_destroy( menu->m_owner );
defc0789 391 menu->m_owner = NULL;
c4608a8a 392
2b5f62a0 393 if (m_invokingWindow)
05b743ba 394 wxMenubarUnsetInvokingWindow( menu, m_invokingWindow );
e4161a2a 395
1d62a8b4 396 return menu;
6de97a3b 397}
96fd301f 398
716b7364 399static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
c801d85f 400{
b1f17bf0 401 if (wxMenuItem::GetLabelText(wxConvertMnemonicsFromGTK(menu->GetTitle())) == wxMenuItem::GetLabelText(menuString))
83624f79
RR
402 {
403 int res = menu->FindItem( itemString );
c626a8b7
VZ
404 if (res != wxNOT_FOUND)
405 return res;
83624f79 406 }
c626a8b7 407
222ed1d6 408 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
83624f79
RR
409 while (node)
410 {
1987af7e 411 wxMenuItem *item = node->GetData();
83624f79
RR
412 if (item->IsSubMenu())
413 return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
2b1c162e 414
1987af7e 415 node = node->GetNext();
83624f79
RR
416 }
417
c626a8b7
VZ
418 return wxNOT_FOUND;
419}
420
c801d85f
KB
421int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
422{
222ed1d6 423 wxMenuList::compatibility_iterator node = m_menus.GetFirst();
83624f79
RR
424 while (node)
425 {
1987af7e 426 wxMenu *menu = node->GetData();
83624f79 427 int res = FindMenuItemRecursive( menu, menuString, itemString);
1987af7e
VZ
428 if (res != -1)
429 return res;
430 node = node->GetNext();
83624f79 431 }
1987af7e
VZ
432
433 return wxNOT_FOUND;
6de97a3b 434}
c801d85f 435
c626a8b7 436// Find a wxMenuItem using its id. Recurses down into sub-menus
96fd301f 437static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id)
716b7364 438{
717a57c2 439 wxMenuItem* result = menu->FindChildItem(id);
716b7364 440
222ed1d6 441 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
c626a8b7 442 while ( node && result == NULL )
83624f79 443 {
1987af7e 444 wxMenuItem *item = node->GetData();
83624f79 445 if (item->IsSubMenu())
c626a8b7 446 {
83624f79 447 result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
c626a8b7 448 }
1987af7e 449 node = node->GetNext();
83624f79 450 }
96fd301f 451
83624f79 452 return result;
6de97a3b 453}
716b7364 454
3dfac970 455wxMenuItem* wxMenuBar::FindItem( int id, wxMenu **menuForItem ) const
716b7364 456{
83624f79 457 wxMenuItem* result = 0;
222ed1d6 458 wxMenuList::compatibility_iterator node = m_menus.GetFirst();
83624f79
RR
459 while (node && result == 0)
460 {
1987af7e 461 wxMenu *menu = node->GetData();
83624f79 462 result = FindMenuItemByIdRecursive( menu, id );
1987af7e 463 node = node->GetNext();
83624f79 464 }
c626a8b7 465
3dfac970
VZ
466 if ( menuForItem )
467 {
468 *menuForItem = result ? result->GetMenu() : (wxMenu *)NULL;
469 }
c626a8b7 470
3dfac970 471 return result;
bbe0af5b
RR
472}
473
3dfac970 474void wxMenuBar::EnableTop( size_t pos, bool flag )
bbe0af5b 475{
222ed1d6 476 wxMenuList::compatibility_iterator node = m_menus.Item( pos );
c626a8b7 477
223d09f6 478 wxCHECK_RET( node, wxT("menu not found") );
c626a8b7 479
3dfac970 480 wxMenu* menu = node->GetData();
c626a8b7
VZ
481
482 if (menu->m_owner)
483 gtk_widget_set_sensitive( menu->m_owner, flag );
bbe0af5b
RR
484}
485
52af3158 486wxString wxMenuBar::GetMenuLabel( size_t pos ) const
bbe0af5b 487{
222ed1d6 488 wxMenuList::compatibility_iterator node = m_menus.Item( pos );
c626a8b7 489
223d09f6 490 wxCHECK_MSG( node, wxT("invalid"), wxT("menu not found") );
c626a8b7 491
3dfac970 492 wxMenu* menu = node->GetData();
c626a8b7 493
b1f17bf0 494 return wxConvertMnemonicsFromGTK(menu->GetTitle());
bbe0af5b
RR
495}
496
52af3158 497void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label )
bbe0af5b 498{
222ed1d6 499 wxMenuList::compatibility_iterator node = m_menus.Item( pos );
c626a8b7 500
223d09f6 501 wxCHECK_RET( node, wxT("menu not found") );
c626a8b7 502
3dfac970 503 wxMenu* menu = node->GetData();
c626a8b7 504
b1f17bf0 505 const wxString str(wxConvertMnemonicsToGTK(label));
f6bcfd97
BP
506
507 menu->SetTitle( str );
508
509 if (menu->m_owner)
8394218c 510 gtk_label_set_text_with_mnemonic( GTK_LABEL( GTK_BIN(menu->m_owner)->child), wxGTK_CONV(str) );
bbe0af5b
RR
511}
512
c801d85f 513//-----------------------------------------------------------------------------
cf7a7e13 514// "activate"
c801d85f
KB
515//-----------------------------------------------------------------------------
516
865bb325 517extern "C" {
6de97a3b 518static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu )
c801d85f 519{
83624f79 520 int id = menu->FindMenuIdByMenuItem(widget);
96fd301f 521
83624f79 522 /* should find it for normal (not popup) menu */
1e6feb95
VZ
523 wxASSERT_MSG( (id != -1) || (menu->GetInvokingWindow() != NULL),
524 _T("menu item not found in gtk_menu_clicked_callback") );
96fd301f 525
c626a8b7
VZ
526 if (!menu->IsEnabled(id))
527 return;
96fd301f 528
4e6beae5
RD
529 wxMenuItem* item = menu->FindChildItem( id );
530 wxCHECK_RET( item, wxT("error in menu item callback") );
531
9959e2b6
VZ
532 if ( item->GetId() == wxGTK_TITLE_ID )
533 {
534 // ignore events from the menu title
535 return;
536 }
537
4e6beae5
RD
538 if (item->IsCheckable())
539 {
540 bool isReallyChecked = item->IsChecked(),
541 isInternallyChecked = item->wxMenuItemBase::IsChecked();
542
543 // ensure that the internal state is always consistent with what is
544 // shown on the screen
545 item->wxMenuItemBase::Check(isReallyChecked);
546
547 // we must not report the events for the radio button going up nor the
548 // events resulting from the calls to wxMenuItem::Check()
549 if ( (item->GetKind() == wxITEM_RADIO && !isReallyChecked) ||
550 (isInternallyChecked == isReallyChecked) )
551 {
552 return;
553 }
554 }
555
556
02822c8c
RD
557 // Is this menu on a menubar? (possibly nested)
558 wxFrame* frame = NULL;
6edf1107
DE
559 if(menu->IsAttached())
560 frame = menu->GetMenuBar()->GetFrame();
02822c8c 561
da0b5338
VZ
562 // FIXME: why do we have to call wxFrame::GetEventHandler() directly here?
563 // normally wxMenu::SendEvent() should be enough, if it doesn't work
564 // in wxGTK then we have a bug in wxMenu::GetInvokingWindow() which
565 // should be fixed instead of working around it here...
02822c8c 566 if (frame)
2d17d68f 567 {
4e6beae5
RD
568 // If it is attached then let the frame send the event.
569 // Don't call frame->ProcessCommand(id) because it toggles
570 // checkable items and we've already done that above.
571 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
572 commandEvent.SetEventObject(frame);
573 if (item->IsCheckable())
574 commandEvent.SetInt(item->IsChecked());
575
937013e0 576 frame->HandleWindowEvent(commandEvent);
a01fe3d6
RD
577 }
578 else
579 {
4e6beae5 580 // otherwise let the menu have it
a01fe3d6 581 menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
2d17d68f 582 }
cf7a7e13 583}
865bb325 584}
cf7a7e13
RR
585
586//-----------------------------------------------------------------------------
587// "select"
588//-----------------------------------------------------------------------------
589
865bb325 590extern "C" {
cf7a7e13
RR
591static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
592{
83624f79
RR
593 int id = menu->FindMenuIdByMenuItem(widget);
594
595 wxASSERT( id != -1 ); // should find it!
cf7a7e13 596
c626a8b7
VZ
597 if (!menu->IsEnabled(id))
598 return;
cf7a7e13 599
342b6a2f 600 wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
83624f79 601 event.SetEventObject( menu );
cf7a7e13 602
a01fe3d6 603 wxEvtHandler* handler = menu->GetEventHandler();
937013e0 604 if (handler && handler->SafelyProcessEvent(event))
c626a8b7 605 return;
6de97a3b 606
83624f79 607 wxWindow *win = menu->GetInvokingWindow();
937013e0 608 if (win) win->HandleWindowEvent( event );
6de97a3b 609}
865bb325 610}
c801d85f 611
cd743a6f
RR
612//-----------------------------------------------------------------------------
613// "deselect"
614//-----------------------------------------------------------------------------
615
865bb325 616extern "C" {
cd743a6f
RR
617static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu )
618{
619 int id = menu->FindMenuIdByMenuItem(widget);
620
621 wxASSERT( id != -1 ); // should find it!
622
c626a8b7
VZ
623 if (!menu->IsEnabled(id))
624 return;
cd743a6f
RR
625
626 wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
627 event.SetEventObject( menu );
628
a01fe3d6 629 wxEvtHandler* handler = menu->GetEventHandler();
937013e0 630 if (handler && handler->SafelyProcessEvent(event))
c626a8b7 631 return;
cd743a6f
RR
632
633 wxWindow *win = menu->GetInvokingWindow();
c626a8b7 634 if (win)
937013e0 635 win->HandleWindowEvent( event );
cd743a6f 636}
865bb325 637}
cd743a6f 638
cf7a7e13 639//-----------------------------------------------------------------------------
db1b4961 640// wxMenuItem
cf7a7e13
RR
641//-----------------------------------------------------------------------------
642
7dbf5360 643IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
974e8d94
VZ
644
645wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
646 int id,
647 const wxString& name,
648 const wxString& help,
d65c269b 649 wxItemKind kind,
974e8d94
VZ
650 wxMenu *subMenu)
651{
d65c269b 652 return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
974e8d94 653}
96fd301f 654
974e8d94
VZ
655wxMenuItem::wxMenuItem(wxMenu *parentMenu,
656 int id,
657 const wxString& text,
658 const wxString& help,
d65c269b 659 wxItemKind kind,
974e8d94 660 wxMenu *subMenu)
d65c269b 661 : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
2368dcda 662{
092f7536 663 Init(text);
2368dcda
VZ
664}
665
666wxMenuItem::wxMenuItem(wxMenu *parentMenu,
667 int id,
668 const wxString& text,
669 const wxString& help,
670 bool isCheckable,
671 wxMenu *subMenu)
672 : wxMenuItemBase(parentMenu, id, text, help,
673 isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu)
674{
092f7536 675 Init(text);
2368dcda
VZ
676}
677
092f7536 678void wxMenuItem::Init(const wxString& text)
c801d85f 679{
37d403aa 680 m_labelWidget = (GtkWidget *) NULL;
83624f79 681 m_menuItem = (GtkWidget *) NULL;
974e8d94 682
092f7536 683 DoSetText(text);
6de97a3b 684}
c801d85f 685
d1b15f03
RR
686wxMenuItem::~wxMenuItem()
687{
688 // don't delete menu items, the menus take care of that
689}
690
717a57c2 691// return the menu item text without any menu accels
3b59cdbf 692/* static */
52af3158 693
52af3158 694wxString wxMenuItemBase::GetLabelText(const wxString& text)
717a57c2 695{
52af3158
JS
696 // The argument to this function will now always be in wxWidgets standard label
697 // format, not GTK+ format, so we do what the other ports do.
698
699 return wxStripMenuCodes(text);
700
701#if 0
717a57c2 702 wxString label;
2368dcda 703
3b59cdbf 704 for ( const wxChar *pc = text.c_str(); *pc; pc++ )
717a57c2 705 {
f0b72e0d
RR
706 if ( *pc == wxT('\t'))
707 break;
9959e2b6 708
7cf4f7e2 709 if ( *pc == wxT('_') )
717a57c2 710 {
2b5f62a0 711 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
d76419bd
RR
712 pc++;
713 label += *pc;
714 continue;
715 }
2368dcda 716
2b5f62a0 717 if ( *pc == wxT('\\') )
d76419bd 718 {
2b5f62a0
VZ
719 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
720 pc++;
721 label += *pc;
717a57c2
VZ
722 continue;
723 }
724
7cf4f7e2
GD
725 if ( (*pc == wxT('&')) && (*(pc+1) != wxT('&')) )
726 {
727 // wxMSW escapes "&"
728 // "&" is doubled to indicate "&" instead of accelerator
729 continue;
730 }
a01fe3d6 731
717a57c2
VZ
732 label += *pc;
733 }
a01fe3d6 734
52af3158 735 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
d9e403cc 736
717a57c2 737 return label;
52af3158 738#endif
717a57c2
VZ
739}
740
52af3158
JS
741wxString wxMenuItem::GetItemLabel() const
742{
b1f17bf0 743 wxString label = wxConvertMnemonicsFromGTK(m_text);
a738f87c 744 if (!m_hotKey.IsEmpty())
b1f17bf0 745 label << "\t" << m_hotKey;
a738f87c 746 return label;
52af3158
JS
747}
748
749void wxMenuItem::SetItemLabel( const wxString& str )
717a57c2 750{
ee0a94cf
RR
751 // cache some data which must be used later
752 bool isstock = wxIsStockID(GetId());
753 const char *stockid = NULL;
754 if (isstock)
755 stockid = wxGetStockGtkID(GetId());
756
5869f93f
JS
757 // Some optimization to avoid flicker
758 wxString oldLabel = m_text;
98f29783 759 oldLabel = wxStripMenuCodes(oldLabel);
5869f93f 760 oldLabel.Replace(wxT("_"), wxT(""));
98f29783 761 wxString label1 = wxStripMenuCodes(str);
6c309653 762#if wxUSE_ACCEL
a8e607d9 763 wxString oldhotkey = GetHotKey(); // Store the old hotkey in Ctrl-foo format
5f11fef5 764 wxCharBuffer oldbuf = wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
6c309653 765#endif // wxUSE_ACCEL
a01fe3d6 766
717a57c2 767 DoSetText(str);
354aa1e3 768
6c309653 769#if wxUSE_ACCEL
88d19775 770 if (oldLabel == label1 &&
ee0a94cf 771 oldhotkey == GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
98f29783
RR
772 return;
773
354aa1e3
RR
774 if (m_menuItem)
775 {
37d403aa
JS
776 GtkLabel *label;
777 if (m_labelWidget)
2b5f62a0 778 label = (GtkLabel*) m_labelWidget;
37d403aa 779 else
2b5f62a0 780 label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
717a57c2 781
ee0a94cf
RR
782 // stock menu items can have empty labels:
783 wxString text = m_text;
784 if (text.IsEmpty() && !IsSeparator())
785 {
786 wxASSERT_MSG(isstock, wxT("A non-stock menu item with an empty label?"));
787 text = wxGetStockLabel(GetId());
788
789 // need & => _ conversion
790 text = GTKProcessMenuItemLabel(text, NULL);
791 }
792
793 gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV_SYS(text) );
354aa1e3 794 }
98f29783 795
ee0a94cf 796 // remove old accelerator from our parent's accelerator group, if present
98f29783
RR
797 guint accel_key;
798 GdkModifierType accel_mods;
ee0a94cf 799 if (oldbuf[(size_t)0] != '\0')
98f29783 800 {
ee0a94cf
RR
801 gtk_accelerator_parse( (const char*) oldbuf, &accel_key, &accel_mods);
802 if (accel_key != 0)
803 {
10bd1f7d 804 gtk_widget_remove_accelerator(m_menuItem,
ee0a94cf
RR
805 m_parentMenu->m_accel,
806 accel_key,
807 accel_mods );
808 }
809 }
810 else if (isstock)
811 {
812 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
813 if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
10bd1f7d 814 gtk_widget_remove_accelerator( m_menuItem,
ee0a94cf
RR
815 m_parentMenu->m_accel,
816 accel_key,
817 accel_mods );
98f29783
RR
818 }
819
ee0a94cf 820 // add new accelerator to our parent's accelerator group
5f11fef5 821 wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*this) );
ee0a94cf 822 if (buf[(size_t)0] != '\0')
98f29783 823 {
ee0a94cf
RR
824 gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
825 if (accel_key != 0)
826 {
10bd1f7d 827 gtk_widget_add_accelerator( m_menuItem,
ee0a94cf
RR
828 "activate",
829 m_parentMenu->m_accel,
830 accel_key,
831 accel_mods,
832 GTK_ACCEL_VISIBLE);
833 }
834 }
835 else if (isstock)
836 {
837 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
838 if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
10bd1f7d 839 gtk_widget_remove_accelerator( m_menuItem,
ee0a94cf
RR
840 m_parentMenu->m_accel,
841 accel_key,
842 accel_mods );
98f29783 843 }
19abd352 844#endif // wxUSE_ACCEL
354aa1e3
RR
845}
846
ee0a94cf 847// NOTE: this function is different from the similar functions GTKProcessMnemonics()
52af3158 848// implemented in control.cpp and from wxMenuItemBase::GetLabelText...
ee0a94cf
RR
849// so there's no real code duplication
850wxString wxMenuItem::GTKProcessMenuItemLabel(const wxString& str, wxString *hotKey)
716b7364 851{
ee0a94cf
RR
852 wxString text;
853
2b5f62a0 854 // '\t' is the deliminator indicating a hot key
e0a050e3
VS
855 wxString::const_iterator pc = str.begin();
856 while ( pc != str.end() && *pc != wxT('\t') )
83624f79 857 {
e0a050e3 858 if (*pc == wxT('&'))
23280650 859 {
e0a050e3
VS
860 wxString::const_iterator next = pc + 1;
861 if (next != str.end() && *next == wxT('&'))
862 {
863 // "&" is doubled to indicate "&" instead of accelerator
864 ++pc;
865 text << wxT('&');
866 }
867 else
868 {
869 text << wxT('_');
870 }
572d7461 871 }
2b5f62a0
VZ
872 else if ( *pc == wxT('_') ) // escape underscores
873 {
ee0a94cf 874 text << wxT("__");
2b5f62a0 875 }
9959e2b6 876 else
23280650 877 {
ee0a94cf 878 text << *pc;
2b5f62a0
VZ
879 }
880 ++pc;
83624f79 881 }
a01fe3d6 882
ee0a94cf 883 if (hotKey)
d7dbc98a 884 {
ee0a94cf
RR
885 hotKey->Empty();
886 if(*pc == wxT('\t'))
887 {
888 pc++;
e0a050e3 889 hotKey->assign(pc, str.end());
ee0a94cf 890 }
d7dbc98a 891 }
88d19775 892
ee0a94cf
RR
893 return text;
894}
895
896// it's valid for this function to be called even if m_menuItem == NULL
897void wxMenuItem::DoSetText( const wxString& str )
898{
899 m_text.Empty();
900 m_text = GTKProcessMenuItemLabel(str, &m_hotKey);
716b7364
RR
901}
902
717a57c2
VZ
903#if wxUSE_ACCEL
904
905wxAcceleratorEntry *wxMenuItem::GetAccel() const
906{
1987af7e 907 if ( !GetHotKey() )
717a57c2
VZ
908 {
909 // nothing
90527a50 910 return NULL;
717a57c2
VZ
911 }
912
90527a50
VZ
913 // accelerator parsing code looks for them after a TAB, so insert a dummy
914 // one here
717a57c2 915 wxString label;
1987af7e 916 label << wxT('\t') << GetHotKey();
717a57c2 917
90527a50 918 return wxAcceleratorEntry::Create(label);
717a57c2
VZ
919}
920
921#endif // wxUSE_ACCEL
922
96fd301f 923void wxMenuItem::Check( bool check )
716b7364 924{
223d09f6 925 wxCHECK_RET( m_menuItem, wxT("invalid menu item") );
db1b4961 926
974e8d94
VZ
927 if (check == m_isChecked)
928 return;
2d17d68f 929
974e8d94 930 wxMenuItemBase::Check( check );
0472ece7 931
24bcaec3 932 switch ( GetKind() )
0472ece7 933 {
24bcaec3
VZ
934 case wxITEM_CHECK:
935 case wxITEM_RADIO:
8394218c 936 gtk_check_menu_item_set_active( (GtkCheckMenuItem*)m_menuItem, (gint)check );
24bcaec3
VZ
937 break;
938
939 default:
940 wxFAIL_MSG( _T("can't check this item") );
0472ece7 941 }
716b7364
RR
942}
943
8bbe427f
VZ
944void wxMenuItem::Enable( bool enable )
945{
223d09f6 946 wxCHECK_RET( m_menuItem, wxT("invalid menu item") );
db1b4961 947
83624f79 948 gtk_widget_set_sensitive( m_menuItem, enable );
974e8d94 949 wxMenuItemBase::Enable( enable );
a9c96bcc
RR
950}
951
96fd301f 952bool wxMenuItem::IsChecked() const
716b7364 953{
670f9935 954 wxCHECK_MSG( m_menuItem, false, wxT("invalid menu item") );
db1b4961 955
670f9935 956 wxCHECK_MSG( IsCheckable(), false,
974e8d94 957 wxT("can't get state of uncheckable item!") );
96fd301f 958
974e8d94 959 return ((GtkCheckMenuItem*)m_menuItem)->active != 0;
716b7364
RR
960}
961
db1b4961 962//-----------------------------------------------------------------------------
83624f79 963// wxMenu
db1b4961
RR
964//-----------------------------------------------------------------------------
965
c801d85f
KB
966IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
967
717a57c2 968void wxMenu::Init()
c801d85f 969{
034be888 970 m_accel = gtk_accel_group_new();
6d971354 971 m_menu = gtk_menu_new();
defc0789
VS
972 // NB: keep reference to the menu so that it is not destroyed behind
973 // our back by GTK+ e.g. when it is removed from menubar:
974 gtk_widget_ref(m_menu);
8bbe427f 975
2b1c162e 976 m_owner = (GtkWidget*) NULL;
2b2edbed 977
d9e403cc
RR
978 // Tearoffs are entries, just like separators. So if we want this
979 // menu to be a tear-off one, we just append a tearoff entry
980 // immediately.
9959e2b6 981 if ( m_style & wxMENU_TEAROFF )
2b2edbed 982 {
9959e2b6 983 GtkWidget *tearoff = gtk_tearoff_menu_item_new();
6d971354 984
1ab9e06d 985 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), tearoff);
9959e2b6 986 }
6d971354 987
9959e2b6 988 m_prevRadio = NULL;
c801d85f 989
717a57c2 990 // append the title as the very first entry if we have it
9959e2b6 991 if ( !m_title.empty() )
d1b15f03 992 {
9959e2b6 993 Append(wxGTK_TITLE_ID, m_title);
717a57c2 994 AppendSeparator();
d1b15f03 995 }
717a57c2 996}
15a2076a 997
717a57c2
VZ
998wxMenu::~wxMenu()
999{
368a4a47 1000 if ( GTK_IS_WIDGET( m_menu ))
defc0789 1001 {
a761df69 1002 // see wxMenu::Init
88d19775 1003 gtk_widget_unref( m_menu );
b8a922d0 1004 g_object_unref( m_accel );
52af3158 1005
a761df69
VS
1006 // if the menu is inserted in another menu at this time, there was
1007 // one more reference to it:
1008 if ( m_owner )
1009 gtk_widget_destroy( m_menu );
defc0789 1010 }
e4161a2a
VZ
1011
1012 // This must come after we release GTK resources above. Otherwise, GTK will
1013 // give warnings/errors when attempting to free accelerator resources from
1014 // child items that just were destroyed (the m_menu widget can contain
1015 // references to accelerators in child items. Problem detected when removing
1016 // a menu from a wxMenuBar, and the removed menu had submenus with accelerators.)
05b743ba 1017 WX_CLEAR_LIST(wxMenuItemList, m_items);
c2dd8380
GL
1018}
1019
978af864
VZ
1020void wxMenu::SetLayoutDirection(const wxLayoutDirection dir)
1021{
1022 if ( m_owner )
1023 wxWindow::GTKSetLayout(m_owner, dir);
1024 //else: will be called later by wxMenuBar again
1025}
1026
1027wxLayoutDirection wxMenu::GetLayoutDirection() const
1028{
1029 return wxWindow::GTKGetLayout(m_owner);
1030}
1031
49826dab 1032bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
c2dd8380 1033{
717a57c2 1034 GtkWidget *menuItem;
96fd301f 1035
ee0a94cf 1036 // cache some data used later
84c51319 1037 wxString text = mitem->wxMenuItemBase::GetItemLabel();
ee0a94cf
RR
1038 int id = mitem->GetId();
1039 bool isstock = wxIsStockID(id);
1040 const char *stockid = NULL;
1041 if (isstock)
1042 stockid = wxGetStockGtkID(mitem->GetId());
1043
1044 // stock menu items can have an empty label
1045 if (text.IsEmpty() && !mitem->IsSeparator())
1046 {
1047 wxASSERT_MSG(isstock, wxT("A non-stock menu item with an empty label?"));
1048 text = wxGetStockLabel(id);
1049
1050 // need & => _ conversion
1051 text = wxMenuItem::GTKProcessMenuItemLabel(text, NULL);
1052 }
e31126cb 1053
717a57c2
VZ
1054 if ( mitem->IsSeparator() )
1055 {
6d971354 1056 menuItem = gtk_separator_menu_item_new();
45813bad 1057 m_prevRadio = NULL;
837904f2 1058 }
ab73fe8d 1059 else if ( mitem->GetBitmap().Ok() ||
ee0a94cf 1060 (mitem->GetKind() == wxITEM_NORMAL && isstock) )
37d403aa 1061 {
ab73fe8d 1062 wxBitmap bitmap(mitem->GetBitmap());
9959e2b6 1063
5f11fef5 1064 menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
9959e2b6 1065
b1ad1424 1066 GtkWidget *image;
ab73fe8d 1067 if ( !bitmap.Ok() )
b1ad1424 1068 {
ab73fe8d
VZ
1069 // use stock bitmap for this item if available on the assumption
1070 // that it never hurts to follow GTK+ conventions more closely
ee0a94cf
RR
1071 image = stockid ? gtk_image_new_from_stock(stockid, GTK_ICON_SIZE_MENU)
1072 : NULL;
b1ad1424 1073 }
ab73fe8d 1074 else // we have a custom bitmap
b1ad1424 1075 {
ab73fe8d
VZ
1076 wxASSERT_MSG( mitem->GetKind() == wxITEM_NORMAL,
1077 _T("only normal menu items can have bitmaps") );
1078
1079 if ( bitmap.HasPixbuf() )
1080 {
1081 image = gtk_image_new_from_pixbuf(bitmap.GetPixbuf());
1082 }
1083 else
1084 {
1085 GdkPixmap *gdk_pixmap = bitmap.GetPixmap();
1086 GdkBitmap *gdk_bitmap = bitmap.GetMask() ?
1087 bitmap.GetMask()->GetBitmap() :
1088 (GdkBitmap*) NULL;
1089 image = gtk_image_new_from_pixmap( gdk_pixmap, gdk_bitmap );
1090 }
b1ad1424 1091 }
88d19775 1092
ab73fe8d
VZ
1093 if ( image )
1094 {
1095 gtk_widget_show(image);
9959e2b6 1096
ab73fe8d
VZ
1097 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem), image );
1098 }
9959e2b6 1099
6d971354
RR
1100 m_prevRadio = NULL;
1101 }
717a57c2
VZ
1102 else // a normal item
1103 {
52af3158 1104 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
ee0a94cf 1105 // so don't use it
717a57c2 1106
d65c269b
VZ
1107 switch ( mitem->GetKind() )
1108 {
546bfbea 1109 case wxITEM_CHECK:
6d971354 1110 {
5f11fef5 1111 menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
6d971354 1112 m_prevRadio = NULL;
d65c269b 1113 break;
6d971354 1114 }
d65c269b 1115
546bfbea 1116 case wxITEM_RADIO:
6d971354
RR
1117 {
1118 GSList *group = NULL;
1119 if ( m_prevRadio == NULL )
d65c269b
VZ
1120 {
1121 // start of a new radio group
5f11fef5
VZ
1122 m_prevRadio = menuItem =
1123 gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) );
d65c269b
VZ
1124 }
1125 else // continue the radio group
1126 {
6d971354 1127 group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio));
5f11fef5
VZ
1128 m_prevRadio = menuItem =
1129 gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) );
d65c269b 1130 }
c0d0a552 1131 break;
6d971354 1132 }
d65c269b
VZ
1133
1134 default:
1135 wxFAIL_MSG( _T("unexpected menu item kind") );
1136 // fall through
1137
546bfbea 1138 case wxITEM_NORMAL:
6d971354 1139 {
5f11fef5 1140 menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
6d971354 1141 m_prevRadio = NULL;
d65c269b 1142 break;
6d971354 1143 }
d65c269b
VZ
1144 }
1145
6d971354 1146 }
9959e2b6 1147
6c309653 1148#if wxUSE_ACCEL
6d971354
RR
1149 guint accel_key;
1150 GdkModifierType accel_mods;
5f11fef5 1151 wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*mitem) );
9959e2b6 1152
ee0a94cf
RR
1153 if (buf[(size_t)0] != '\0')
1154 {
1155 gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
1156 if (accel_key != 0)
1157 {
10bd1f7d 1158 gtk_widget_add_accelerator (menuItem,
ee0a94cf
RR
1159 "activate",
1160 m_accel,
1161 accel_key,
1162 accel_mods,
1163 GTK_ACCEL_VISIBLE);
1164 }
1165 }
1166 else if (isstock)
6d971354 1167 {
ee0a94cf
RR
1168 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1169 if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
10bd1f7d 1170 gtk_widget_add_accelerator( menuItem,
ee0a94cf
RR
1171 "activate",
1172 m_accel,
1173 accel_key,
1174 accel_mods,
1175 GTK_ACCEL_VISIBLE);
717a57c2 1176 }
19abd352 1177#endif // wxUSE_ACCEL
9959e2b6 1178
e31126cb
RR
1179 if (pos == -1)
1180 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem);
1181 else
1182 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos);
1183
6d971354 1184 gtk_widget_show( menuItem );
23280650 1185
717a57c2
VZ
1186 if ( !mitem->IsSeparator() )
1187 {
2b5f62a0 1188 wxASSERT_MSG( menuItem, wxT("invalid menuitem") );
a01fe3d6 1189
9fa72bd2
MR
1190 g_signal_connect (menuItem, "select",
1191 G_CALLBACK (gtk_menu_hilight_callback), this);
1192 g_signal_connect (menuItem, "deselect",
1193 G_CALLBACK (gtk_menu_nolight_callback), this);
e31126cb 1194
88d19775
MR
1195 if ( mitem->IsSubMenu() && mitem->GetKind() != wxITEM_RADIO && mitem->GetKind() != wxITEM_CHECK )
1196 {
e31126cb
RR
1197 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
1198
1199 gtk_widget_show( mitem->GetSubMenu()->m_menu );
1200
1201 // if adding a submenu to a menu already existing in the menu bar, we
1202 // must set invoking window to allow processing events from this
1203 // submenu
1204 if ( m_invokingWindow )
1205 wxMenubarSetInvokingWindow(mitem->GetSubMenu(), m_invokingWindow);
88d19775
MR
1206 }
1207 else
1208 {
9fa72bd2
MR
1209 g_signal_connect (menuItem, "activate",
1210 G_CALLBACK (gtk_menu_clicked_callback),
1211 this);
88d19775 1212 }
717a57c2 1213 }
23280650 1214
837904f2 1215 mitem->SetMenuItem(menuItem);
837904f2 1216
6d971354 1217 if (ms_locked)
d65c269b 1218 {
6d971354
RR
1219 // This doesn't even exist!
1220 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
d65c269b 1221 }
d65c269b 1222
670f9935 1223 return true;
6de97a3b 1224}
c801d85f 1225
9add9367 1226wxMenuItem* wxMenu::DoAppend(wxMenuItem *mitem)
828f655f 1227{
9add9367
RD
1228 if (!GtkAppend(mitem))
1229 return NULL;
9959e2b6 1230
9add9367 1231 return wxMenuBase::DoAppend(mitem);
c33c4050
RR
1232}
1233
9add9367 1234wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
c33c4050 1235{
717a57c2 1236 if ( !wxMenuBase::DoInsert(pos, item) )
9add9367 1237 return NULL;
c626a8b7 1238
6d971354 1239 // TODO
49826dab 1240 if ( !GtkAppend(item, (int)pos) )
9add9367 1241 return NULL;
32db328c 1242
9add9367 1243 return item;
c33c4050
RR
1244}
1245
717a57c2 1246wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
c33c4050 1247{
717a57c2 1248 if ( !wxMenuBase::DoRemove(item) )
8d749001
VZ
1249 return NULL;
1250
1251 GtkWidget * const mitem = item->GetMenuItem();
1252 if ( m_prevRadio == mitem )
1253 {
1254 // deleting an item starts a new radio group (has to as we shouldn't
1255 // keep a deleted pointer anyhow)
1256 m_prevRadio = NULL;
1257 }
c626a8b7 1258
717a57c2
VZ
1259 // TODO: this code doesn't delete the item factory item and this seems
1260 // impossible as of GTK 1.2.6.
8d749001 1261 gtk_widget_destroy( mitem );
c626a8b7 1262
717a57c2 1263 return item;
c33c4050
RR
1264}
1265
96fd301f
VZ
1266int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
1267{
222ed1d6 1268 wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
83624f79
RR
1269 while (node)
1270 {
b1d4dd7a 1271 wxMenuItem *item = node->GetData();
83624f79 1272 if (item->GetMenuItem() == menuItem)
88d19775 1273 return item->GetId();
b1d4dd7a 1274 node = node->GetNext();
83624f79 1275 }
96fd301f 1276
c626a8b7 1277 return wxNOT_FOUND;
6de97a3b 1278}
c801d85f 1279
978af864
VZ
1280void wxMenu::Attach(wxMenuBarBase *menubar)
1281{
1282 wxMenuBase::Attach(menubar);
1283
1284 // inherit layout direction from menubar.
1285 SetLayoutDirection(menubar->GetLayoutDirection());
1286}
1287
717a57c2
VZ
1288// ----------------------------------------------------------------------------
1289// helpers
1290// ----------------------------------------------------------------------------
1291
6d971354 1292#if wxUSE_ACCEL
a070d8ce 1293
98f29783 1294static wxString GetGtkHotKey( const wxMenuItem& item )
c801d85f 1295{
717a57c2
VZ
1296 wxString hotkey;
1297
1298 wxAcceleratorEntry *accel = item.GetAccel();
1299 if ( accel )
83624f79 1300 {
717a57c2
VZ
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>");
1308
1309 int code = accel->GetKeyCode();
1310 switch ( code )
c626a8b7 1311 {
717a57c2
VZ
1312 case WXK_F1:
1313 case WXK_F2:
1314 case WXK_F3:
1315 case WXK_F4:
1316 case WXK_F5:
1317 case WXK_F6:
1318 case WXK_F7:
1319 case WXK_F8:
1320 case WXK_F9:
1321 case WXK_F10:
1322 case WXK_F11:
1323 case WXK_F12:
bbcd4085
RR
1324 case WXK_F13:
1325 case WXK_F14:
1326 case WXK_F15:
1327 case WXK_F16:
1328 case WXK_F17:
1329 case WXK_F18:
1330 case WXK_F19:
1331 case WXK_F20:
1332 case WXK_F21:
1333 case WXK_F22:
1334 case WXK_F23:
1335 case WXK_F24:
04cc1e93 1336 hotkey += wxString::Format(wxT("F%d"), code - WXK_F1 + 1);
717a57c2 1337 break;
2368dcda 1338
a070d8ce
VZ
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
bbcd4085 1342 case WXK_INSERT:
3ca6a5f0
BP
1343 hotkey << wxT("Insert" );
1344 break;
1345 case WXK_DELETE:
1346 hotkey << wxT("Delete" );
1347 break;
2b5f62a0
VZ
1348 case WXK_UP:
1349 hotkey << wxT("Up" );
1350 break;
1351 case WXK_DOWN:
1352 hotkey << wxT("Down" );
1353 break;
1354 case WXK_PAGEUP:
f005ea42 1355 hotkey << wxT("Page_Up" );
2b5f62a0
VZ
1356 break;
1357 case WXK_PAGEDOWN:
f005ea42 1358 hotkey << wxT("Page_Down" );
2b5f62a0
VZ
1359 break;
1360 case WXK_LEFT:
1361 hotkey << wxT("Left" );
1362 break;
1363 case WXK_RIGHT:
1364 hotkey << wxT("Right" );
1365 break;
1366 case WXK_HOME:
1367 hotkey << wxT("Home" );
1368 break;
1369 case WXK_END:
1370 hotkey << wxT("End" );
1371 break;
1372 case WXK_RETURN:
1373 hotkey << wxT("Return" );
1374 break;
bbcd4085
RR
1375 case WXK_BACK:
1376 hotkey << wxT("BackSpace" );
1377 break;
1378 case WXK_TAB:
1379 hotkey << wxT("Tab" );
1380 break;
1381 case WXK_ESCAPE:
1382 hotkey << wxT("Esc" );
1383 break;
1384 case WXK_SPACE:
1385 hotkey << wxT("space" );
1386 break;
1387 case WXK_MULTIPLY:
1388 hotkey << wxT("Multiply" );
1389 break;
1390 case WXK_ADD:
1391 hotkey << wxT("Add" );
1392 break;
1393 case WXK_SEPARATOR:
1394 hotkey << wxT("Separator" );
1395 break;
1396 case WXK_SUBTRACT:
1397 hotkey << wxT("Subtract" );
1398 break;
1399 case WXK_DECIMAL:
1400 hotkey << wxT("Decimal" );
1401 break;
1402 case WXK_DIVIDE:
1403 hotkey << wxT("Divide" );
1404 break;
1405 case WXK_CANCEL:
1406 hotkey << wxT("Cancel" );
1407 break;
1408 case WXK_CLEAR:
1409 hotkey << wxT("Clear" );
1410 break;
1411 case WXK_MENU:
1412 hotkey << wxT("Menu" );
1413 break;
1414 case WXK_PAUSE:
1415 hotkey << wxT("Pause" );
1416 break;
1417 case WXK_CAPITAL:
1418 hotkey << wxT("Capital" );
1419 break;
1420 case WXK_SELECT:
1421 hotkey << wxT("Select" );
1422 break;
1423 case WXK_PRINT:
1424 hotkey << wxT("Print" );
1425 break;
1426 case WXK_EXECUTE:
1427 hotkey << wxT("Execute" );
1428 break;
1429 case WXK_SNAPSHOT:
1430 hotkey << wxT("Snapshot" );
1431 break;
1432 case WXK_HELP:
1433 hotkey << wxT("Help" );
1434 break;
1435 case WXK_NUMLOCK:
1436 hotkey << wxT("Num_Lock" );
1437 break;
1438 case WXK_SCROLL:
1439 hotkey << wxT("Scroll_Lock" );
1440 break;
1441 case WXK_NUMPAD_INSERT:
1442 hotkey << wxT("KP_Insert" );
1443 break;
1444 case WXK_NUMPAD_DELETE:
1445 hotkey << wxT("KP_Delete" );
1446 break;
1447 case WXK_NUMPAD_SPACE:
1448 hotkey << wxT("KP_Space" );
1449 break;
1450 case WXK_NUMPAD_TAB:
1451 hotkey << wxT("KP_Tab" );
1452 break;
1453 case WXK_NUMPAD_ENTER:
1454 hotkey << wxT("KP_Enter" );
1455 break;
1456 case WXK_NUMPAD_F1: case WXK_NUMPAD_F2: case WXK_NUMPAD_F3:
1457 case WXK_NUMPAD_F4:
1458 hotkey += wxString::Format(wxT("KP_F%d"), code - WXK_NUMPAD_F1 + 1);
1459 break;
1460 case WXK_NUMPAD_HOME:
1461 hotkey << wxT("KP_Home" );
1462 break;
1463 case WXK_NUMPAD_LEFT:
1464 hotkey << wxT("KP_Left" );
1465 break;
1466 case WXK_NUMPAD_UP:
1467 hotkey << wxT("KP_Up" );
1468 break;
1469 case WXK_NUMPAD_RIGHT:
1470 hotkey << wxT("KP_Right" );
1471 break;
1472 case WXK_NUMPAD_DOWN:
1473 hotkey << wxT("KP_Down" );
1474 break;
5bd24f72 1475 case WXK_NUMPAD_PAGEUP:
f005ea42 1476 hotkey << wxT("KP_Page_Up" );
bbcd4085 1477 break;
5bd24f72 1478 case WXK_NUMPAD_PAGEDOWN:
f005ea42 1479 hotkey << wxT("KP_Page_Down" );
bbcd4085
RR
1480 break;
1481 case WXK_NUMPAD_END:
1482 hotkey << wxT("KP_End" );
1483 break;
1484 case WXK_NUMPAD_BEGIN:
1485 hotkey << wxT("KP_Begin" );
1486 break;
1487 case WXK_NUMPAD_EQUAL:
1488 hotkey << wxT("KP_Equal" );
1489 break;
1490 case WXK_NUMPAD_MULTIPLY:
1491 hotkey << wxT("KP_Multiply" );
1492 break;
1493 case WXK_NUMPAD_ADD:
1494 hotkey << wxT("KP_Add" );
1495 break;
1496 case WXK_NUMPAD_SEPARATOR:
1497 hotkey << wxT("KP_Separator" );
1498 break;
1499 case WXK_NUMPAD_SUBTRACT:
1500 hotkey << wxT("KP_Subtract" );
1501 break;
1502 case WXK_NUMPAD_DECIMAL:
1503 hotkey << wxT("KP_Decimal" );
1504 break;
1505 case WXK_NUMPAD_DIVIDE:
1506 hotkey << wxT("KP_Divide" );
1507 break;
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);
1512 break;
1513 case WXK_WINDOWS_LEFT:
1514 hotkey << wxT("Super_L" );
1515 break;
1516 case WXK_WINDOWS_RIGHT:
1517 hotkey << wxT("Super_R" );
1518 break;
1519 case WXK_WINDOWS_MENU:
1520 hotkey << wxT("Menu" );
1521 break;
1522 case WXK_COMMAND:
1523 hotkey << wxT("Command" );
1524 break;
1525 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
88d19775
MR
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:
bbcd4085
RR
1530 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1531 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1532 break;
1533 */
90527a50 1534 // if there are any other keys wxAcceleratorEntry::Create() may
a070d8ce 1535 // return, we should process them here
8bbe427f 1536
717a57c2 1537 default:
a070d8ce 1538 if ( code < 127 )
717a57c2 1539 {
30083ad8
VZ
1540 const wxString
1541 name = wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint)code));
1542 if ( !name.empty() )
a070d8ce
VZ
1543 {
1544 hotkey << name;
1545 break;
1546 }
717a57c2 1547 }
c801d85f 1548
717a57c2
VZ
1549 wxFAIL_MSG( wxT("unknown keyboard accel") );
1550 }
c801d85f 1551
717a57c2 1552 delete accel;
631f1bfe 1553 }
717a57c2
VZ
1554
1555 return hotkey;
631f1bfe 1556}
a070d8ce 1557
717a57c2 1558#endif // wxUSE_ACCEL
43a11e2a
VZ
1559
1560// ----------------------------------------------------------------------------
1561// Pop-up menu stuff
1562// ----------------------------------------------------------------------------
1563
1564#if wxUSE_MENUS_NATIVE
1565
81939780 1566extern "C" WXDLLIMPEXP_CORE
43a11e2a
VZ
1567void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting )
1568{
670f9935 1569 *is_waiting = false;
43a11e2a
VZ
1570}
1571
81939780 1572WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win )
43a11e2a
VZ
1573{
1574 menu->SetInvokingWindow( win );
1575
1576 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
1577 while (node)
1578 {
1579 wxMenuItem *menuitem = node->GetData();
1580 if (menuitem->IsSubMenu())
1581 {
1582 SetInvokingWindow( menuitem->GetSubMenu(), win );
1583 }
1584
1585 node = node->GetNext();
1586 }
1587}
1588
81939780 1589extern "C" WXDLLIMPEXP_CORE
43a11e2a
VZ
1590void wxPopupMenuPositionCallback( GtkMenu *menu,
1591 gint *x, gint *y,
43a11e2a 1592 gboolean * WXUNUSED(whatever),
43a11e2a
VZ
1593 gpointer user_data )
1594{
1595 // ensure that the menu appears entirely on screen
1596 GtkRequisition req;
1597 gtk_widget_get_child_requisition(GTK_WIDGET(menu), &req);
1598
1599 wxSize sizeScreen = wxGetDisplaySize();
1600 wxPoint *pos = (wxPoint*)user_data;
1601
1602 gint xmax = sizeScreen.x - req.width,
1603 ymax = sizeScreen.y - req.height;
1604
1605 *x = pos->x < xmax ? pos->x : xmax;
1606 *y = pos->y < ymax ? pos->y : ymax;
1607}
1608
1609bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
1610{
1611 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
1612
1613 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
1614
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.
1618
1619 SetInvokingWindow( menu, this );
1620
1621 menu->UpdateUI();
1622
1623 bool is_waiting = true;
1624
9fa72bd2
MR
1625 gulong handler = g_signal_connect (menu->m_menu, "hide",
1626 G_CALLBACK (gtk_pop_hide_callback),
1627 &is_waiting);
43a11e2a
VZ
1628
1629 wxPoint pos;
1630 gpointer userdata;
1631 GtkMenuPositionFunc posfunc;
1632 if ( x == -1 && y == -1 )
1633 {
1634 // use GTK's default positioning algorithm
1635 userdata = NULL;
1636 posfunc = NULL;
1637 }
1638 else
1639 {
1640 pos = ClientToScreen(wxPoint(x, y));
1641 userdata = &pos;
1642 posfunc = wxPopupMenuPositionCallback;
1643 }
1644
1645 wxMenuEvent eventOpen(wxEVT_MENU_OPEN, -1, menu);
1646 DoCommonMenuCallbackCode(menu, eventOpen);
1647
1648 gtk_menu_popup(
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
43a11e2a 1655 gtk_get_current_event_time()
43a11e2a
VZ
1656 );
1657
1658 while (is_waiting)
1659 {
1660 gtk_main_iteration();
1661 }
1662
9fa72bd2 1663 g_signal_handler_disconnect (menu->m_menu, handler);
43a11e2a
VZ
1664
1665 wxMenuEvent eventClose(wxEVT_MENU_CLOSE, -1, menu);
1666 DoCommonMenuCallbackCode(menu, eventClose);
1667
1668 return true;
1669}
1670
1671#endif // wxUSE_MENUS_NATIVE
bcf881ef 1672
bcf881ef
JS
1673#include <gtk/gtk.h>
1674
1675const char *wxGetStockGtkID(wxWindowID id)
1676{
1677 #define STOCKITEM(wx,gtk) \
1678 case wx: \
1679 return gtk;
1680
1681 #define STOCKITEM_MISSING(wx) \
1682 case wx: \
1683 return NULL;
1684
1685 #if GTK_CHECK_VERSION(2,4,0)
1686 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1687 #else
1688 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1689 #endif
1690
1691 #if GTK_CHECK_VERSION(2,6,0)
1692 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1693 #else
1694 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1695 #endif
1696
1697 #if GTK_CHECK_VERSION(2,10,0)
1698 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1699 #else
1700 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1701 #endif
1702
1703
1704 switch (id)
1705 {
1706 STOCKITEM_26(wxID_ABOUT, GTK_STOCK_ABOUT)
1707 STOCKITEM(wxID_ADD, GTK_STOCK_ADD)
1708 STOCKITEM(wxID_APPLY, GTK_STOCK_APPLY)
1709 STOCKITEM(wxID_BOLD, GTK_STOCK_BOLD)
1710 STOCKITEM(wxID_CANCEL, GTK_STOCK_CANCEL)
1711 STOCKITEM(wxID_CLEAR, GTK_STOCK_CLEAR)
1712 STOCKITEM(wxID_CLOSE, GTK_STOCK_CLOSE)
1713 STOCKITEM(wxID_COPY, GTK_STOCK_COPY)
1714 STOCKITEM(wxID_CUT, GTK_STOCK_CUT)
1715 STOCKITEM(wxID_DELETE, GTK_STOCK_DELETE)
1716 STOCKITEM_26(wxID_EDIT, GTK_STOCK_EDIT)
1717 STOCKITEM(wxID_FIND, GTK_STOCK_FIND)
1718 STOCKITEM_26(wxID_FILE, GTK_STOCK_FILE)
1719 STOCKITEM(wxID_REPLACE, GTK_STOCK_FIND_AND_REPLACE)
1720 STOCKITEM(wxID_BACKWARD, GTK_STOCK_GO_BACK)
1721 STOCKITEM(wxID_DOWN, GTK_STOCK_GO_DOWN)
1722 STOCKITEM(wxID_FORWARD, GTK_STOCK_GO_FORWARD)
1723 STOCKITEM(wxID_UP, GTK_STOCK_GO_UP)
1724 STOCKITEM(wxID_HELP, GTK_STOCK_HELP)
1725 STOCKITEM(wxID_HOME, GTK_STOCK_HOME)
1726 STOCKITEM_24(wxID_INDENT, GTK_STOCK_INDENT)
1727 STOCKITEM(wxID_INDEX, GTK_STOCK_INDEX)
1728 STOCKITEM(wxID_ITALIC, GTK_STOCK_ITALIC)
1729 STOCKITEM(wxID_JUSTIFY_CENTER, GTK_STOCK_JUSTIFY_CENTER)
1730 STOCKITEM(wxID_JUSTIFY_FILL, GTK_STOCK_JUSTIFY_FILL)
1731 STOCKITEM(wxID_JUSTIFY_LEFT, GTK_STOCK_JUSTIFY_LEFT)
1732 STOCKITEM(wxID_JUSTIFY_RIGHT, GTK_STOCK_JUSTIFY_RIGHT)
1733 STOCKITEM(wxID_NEW, GTK_STOCK_NEW)
1734 STOCKITEM(wxID_NO, GTK_STOCK_NO)
1735 STOCKITEM(wxID_OK, GTK_STOCK_OK)
1736 STOCKITEM(wxID_OPEN, GTK_STOCK_OPEN)
1737 STOCKITEM(wxID_PASTE, GTK_STOCK_PASTE)
1738 STOCKITEM(wxID_PREFERENCES, GTK_STOCK_PREFERENCES)
1739 STOCKITEM(wxID_PRINT, GTK_STOCK_PRINT)
1740 STOCKITEM(wxID_PREVIEW, GTK_STOCK_PRINT_PREVIEW)
1741 STOCKITEM(wxID_PROPERTIES, GTK_STOCK_PROPERTIES)
1742 STOCKITEM(wxID_EXIT, GTK_STOCK_QUIT)
1743 STOCKITEM(wxID_REDO, GTK_STOCK_REDO)
1744 STOCKITEM(wxID_REFRESH, GTK_STOCK_REFRESH)
1745 STOCKITEM(wxID_REMOVE, GTK_STOCK_REMOVE)
1746 STOCKITEM(wxID_REVERT_TO_SAVED, GTK_STOCK_REVERT_TO_SAVED)
1747 STOCKITEM(wxID_SAVE, GTK_STOCK_SAVE)
1748 STOCKITEM(wxID_SAVEAS, GTK_STOCK_SAVE_AS)
1749 STOCKITEM_210(wxID_SELECTALL, GTK_STOCK_SELECT_ALL)
1750 STOCKITEM(wxID_STOP, GTK_STOCK_STOP)
1751 STOCKITEM(wxID_UNDELETE, GTK_STOCK_UNDELETE)
1752 STOCKITEM(wxID_UNDERLINE, GTK_STOCK_UNDERLINE)
1753 STOCKITEM(wxID_UNDO, GTK_STOCK_UNDO)
1754 STOCKITEM_24(wxID_UNINDENT, GTK_STOCK_UNINDENT)
1755 STOCKITEM(wxID_YES, GTK_STOCK_YES)
1756 STOCKITEM(wxID_ZOOM_100, GTK_STOCK_ZOOM_100)
1757 STOCKITEM(wxID_ZOOM_FIT, GTK_STOCK_ZOOM_FIT)
1758 STOCKITEM(wxID_ZOOM_IN, GTK_STOCK_ZOOM_IN)
1759 STOCKITEM(wxID_ZOOM_OUT, GTK_STOCK_ZOOM_OUT)
1760
1761 default:
1762 wxFAIL_MSG( _T("invalid stock item ID") );
1763 break;
1764 };
1765
1766 #undef STOCKITEM
1767
1768 return NULL;
1769}
1770
19abd352
PC
1771#if wxUSE_ACCEL
1772static
bcf881ef
JS
1773bool wxGetStockGtkAccelerator(const char *id, GdkModifierType *mod, guint *key)
1774{
1775 if (!id)
1776 return false;
1777
1778 GtkStockItem stock_item;
1779 if (gtk_stock_lookup (id, &stock_item))
1780 {
1781 if (key) *key = stock_item.keyval;
1782 if (mod) *mod = stock_item.modifier;
1783
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)
1787 return true;
1788 }
1789
1790 return false;
1791}
19abd352 1792#endif // wxUSE_ACCEL
bcf881ef 1793
28fcfbfe 1794#endif // wxUSE_MENUS