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