]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/menu.cpp
More attempts to better support theme borders
[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());
614
615 frame->GetEventHandler()->ProcessEvent(commandEvent);
a01fe3d6
RD
616 }
617 else
618 {
4e6beae5 619 // otherwise let the menu have it
a01fe3d6 620 menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1);
2d17d68f 621 }
cf7a7e13 622}
865bb325 623}
cf7a7e13
RR
624
625//-----------------------------------------------------------------------------
626// "select"
627//-----------------------------------------------------------------------------
628
865bb325 629extern "C" {
cf7a7e13
RR
630static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu )
631{
83624f79
RR
632 int id = menu->FindMenuIdByMenuItem(widget);
633
634 wxASSERT( id != -1 ); // should find it!
cf7a7e13 635
c626a8b7
VZ
636 if (!menu->IsEnabled(id))
637 return;
cf7a7e13 638
342b6a2f 639 wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id );
83624f79 640 event.SetEventObject( menu );
cf7a7e13 641
a01fe3d6
RD
642 wxEvtHandler* handler = menu->GetEventHandler();
643 if (handler && handler->ProcessEvent(event))
c626a8b7 644 return;
6de97a3b 645
83624f79
RR
646 wxWindow *win = menu->GetInvokingWindow();
647 if (win) win->GetEventHandler()->ProcessEvent( event );
6de97a3b 648}
865bb325 649}
c801d85f 650
cd743a6f
RR
651//-----------------------------------------------------------------------------
652// "deselect"
653//-----------------------------------------------------------------------------
654
865bb325 655extern "C" {
cd743a6f
RR
656static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu )
657{
658 int id = menu->FindMenuIdByMenuItem(widget);
659
660 wxASSERT( id != -1 ); // should find it!
661
c626a8b7
VZ
662 if (!menu->IsEnabled(id))
663 return;
cd743a6f
RR
664
665 wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 );
666 event.SetEventObject( menu );
667
a01fe3d6
RD
668 wxEvtHandler* handler = menu->GetEventHandler();
669 if (handler && handler->ProcessEvent(event))
c626a8b7 670 return;
cd743a6f
RR
671
672 wxWindow *win = menu->GetInvokingWindow();
c626a8b7
VZ
673 if (win)
674 win->GetEventHandler()->ProcessEvent( event );
cd743a6f 675}
865bb325 676}
cd743a6f 677
cf7a7e13 678//-----------------------------------------------------------------------------
db1b4961 679// wxMenuItem
cf7a7e13
RR
680//-----------------------------------------------------------------------------
681
7dbf5360 682IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
974e8d94
VZ
683
684wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
685 int id,
686 const wxString& name,
687 const wxString& help,
d65c269b 688 wxItemKind kind,
974e8d94
VZ
689 wxMenu *subMenu)
690{
d65c269b 691 return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
974e8d94 692}
96fd301f 693
974e8d94
VZ
694wxMenuItem::wxMenuItem(wxMenu *parentMenu,
695 int id,
696 const wxString& text,
697 const wxString& help,
d65c269b 698 wxItemKind kind,
974e8d94 699 wxMenu *subMenu)
d65c269b 700 : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu)
2368dcda 701{
092f7536 702 Init(text);
2368dcda
VZ
703}
704
705wxMenuItem::wxMenuItem(wxMenu *parentMenu,
706 int id,
707 const wxString& text,
708 const wxString& help,
709 bool isCheckable,
710 wxMenu *subMenu)
711 : wxMenuItemBase(parentMenu, id, text, help,
712 isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu)
713{
092f7536 714 Init(text);
2368dcda
VZ
715}
716
092f7536 717void wxMenuItem::Init(const wxString& text)
c801d85f 718{
37d403aa 719 m_labelWidget = (GtkWidget *) NULL;
83624f79 720 m_menuItem = (GtkWidget *) NULL;
974e8d94 721
092f7536 722 DoSetText(text);
6de97a3b 723}
c801d85f 724
d1b15f03
RR
725wxMenuItem::~wxMenuItem()
726{
727 // don't delete menu items, the menus take care of that
728}
729
717a57c2 730// return the menu item text without any menu accels
3b59cdbf 731/* static */
52af3158 732
52af3158 733wxString wxMenuItemBase::GetLabelText(const wxString& text)
717a57c2 734{
52af3158
JS
735 // The argument to this function will now always be in wxWidgets standard label
736 // format, not GTK+ format, so we do what the other ports do.
737
738 return wxStripMenuCodes(text);
739
740#if 0
717a57c2 741 wxString label;
2368dcda 742
3b59cdbf 743 for ( const wxChar *pc = text.c_str(); *pc; pc++ )
717a57c2 744 {
f0b72e0d
RR
745 if ( *pc == wxT('\t'))
746 break;
9959e2b6 747
7cf4f7e2 748 if ( *pc == wxT('_') )
717a57c2 749 {
2b5f62a0 750 // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx"
d76419bd
RR
751 pc++;
752 label += *pc;
753 continue;
754 }
2368dcda 755
2b5f62a0 756 if ( *pc == wxT('\\') )
d76419bd 757 {
2b5f62a0
VZ
758 // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx"
759 pc++;
760 label += *pc;
717a57c2
VZ
761 continue;
762 }
763
7cf4f7e2
GD
764 if ( (*pc == wxT('&')) && (*(pc+1) != wxT('&')) )
765 {
766 // wxMSW escapes "&"
767 // "&" is doubled to indicate "&" instead of accelerator
768 continue;
769 }
a01fe3d6 770
717a57c2
VZ
771 label += *pc;
772 }
a01fe3d6 773
52af3158 774 // wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
d9e403cc 775
717a57c2 776 return label;
52af3158 777#endif
717a57c2
VZ
778}
779
52af3158
JS
780wxString wxMenuItem::GetItemLabel() const
781{
a738f87c
JS
782 wxString label = wxConvertFromGTKToWXLabel(m_text);
783 if (!m_hotKey.IsEmpty())
784 label = label + wxT("\t") + m_hotKey;
785 return label;
52af3158
JS
786}
787
788void wxMenuItem::SetItemLabel( const wxString& str )
717a57c2 789{
ee0a94cf
RR
790 // cache some data which must be used later
791 bool isstock = wxIsStockID(GetId());
792 const char *stockid = NULL;
793 if (isstock)
794 stockid = wxGetStockGtkID(GetId());
795
5869f93f
JS
796 // Some optimization to avoid flicker
797 wxString oldLabel = m_text;
98f29783 798 oldLabel = wxStripMenuCodes(oldLabel);
5869f93f 799 oldLabel.Replace(wxT("_"), wxT(""));
98f29783 800 wxString label1 = wxStripMenuCodes(str);
a8e607d9 801 wxString oldhotkey = GetHotKey(); // Store the old hotkey in Ctrl-foo format
5f11fef5 802 wxCharBuffer oldbuf = wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
a01fe3d6 803
717a57c2 804 DoSetText(str);
354aa1e3 805
88d19775 806 if (oldLabel == label1 &&
ee0a94cf 807 oldhotkey == GetHotKey()) // Make sure we can change a hotkey even if the label is unaltered
98f29783
RR
808 return;
809
354aa1e3
RR
810 if (m_menuItem)
811 {
37d403aa
JS
812 GtkLabel *label;
813 if (m_labelWidget)
2b5f62a0 814 label = (GtkLabel*) m_labelWidget;
37d403aa 815 else
2b5f62a0 816 label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
717a57c2 817
ee0a94cf
RR
818 // stock menu items can have empty labels:
819 wxString text = m_text;
820 if (text.IsEmpty() && !IsSeparator())
821 {
822 wxASSERT_MSG(isstock, wxT("A non-stock menu item with an empty label?"));
823 text = wxGetStockLabel(GetId());
824
825 // need & => _ conversion
826 text = GTKProcessMenuItemLabel(text, NULL);
827 }
828
829 gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV_SYS(text) );
354aa1e3 830 }
98f29783 831
ee0a94cf 832 // remove old accelerator from our parent's accelerator group, if present
98f29783
RR
833 guint accel_key;
834 GdkModifierType accel_mods;
ee0a94cf 835 if (oldbuf[(size_t)0] != '\0')
98f29783 836 {
ee0a94cf
RR
837 gtk_accelerator_parse( (const char*) oldbuf, &accel_key, &accel_mods);
838 if (accel_key != 0)
839 {
10bd1f7d 840 gtk_widget_remove_accelerator(m_menuItem,
ee0a94cf
RR
841 m_parentMenu->m_accel,
842 accel_key,
843 accel_mods );
844 }
845 }
846 else if (isstock)
847 {
848 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
849 if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
10bd1f7d 850 gtk_widget_remove_accelerator( m_menuItem,
ee0a94cf
RR
851 m_parentMenu->m_accel,
852 accel_key,
853 accel_mods );
98f29783
RR
854 }
855
ee0a94cf 856 // add new accelerator to our parent's accelerator group
5f11fef5 857 wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*this) );
ee0a94cf 858 if (buf[(size_t)0] != '\0')
98f29783 859 {
ee0a94cf
RR
860 gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
861 if (accel_key != 0)
862 {
10bd1f7d 863 gtk_widget_add_accelerator( m_menuItem,
ee0a94cf
RR
864 "activate",
865 m_parentMenu->m_accel,
866 accel_key,
867 accel_mods,
868 GTK_ACCEL_VISIBLE);
869 }
870 }
871 else if (isstock)
872 {
873 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
874 if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
10bd1f7d 875 gtk_widget_remove_accelerator( m_menuItem,
ee0a94cf
RR
876 m_parentMenu->m_accel,
877 accel_key,
878 accel_mods );
98f29783 879 }
354aa1e3
RR
880}
881
ee0a94cf 882// NOTE: this function is different from the similar functions GTKProcessMnemonics()
52af3158 883// implemented in control.cpp and from wxMenuItemBase::GetLabelText...
ee0a94cf
RR
884// so there's no real code duplication
885wxString wxMenuItem::GTKProcessMenuItemLabel(const wxString& str, wxString *hotKey)
716b7364 886{
ee0a94cf
RR
887 wxString text;
888
2b5f62a0 889 // '\t' is the deliminator indicating a hot key
e0a050e3
VS
890 wxString::const_iterator pc = str.begin();
891 while ( pc != str.end() && *pc != wxT('\t') )
83624f79 892 {
e0a050e3 893 if (*pc == wxT('&'))
23280650 894 {
e0a050e3
VS
895 wxString::const_iterator next = pc + 1;
896 if (next != str.end() && *next == wxT('&'))
897 {
898 // "&" is doubled to indicate "&" instead of accelerator
899 ++pc;
900 text << wxT('&');
901 }
902 else
903 {
904 text << wxT('_');
905 }
572d7461 906 }
2b5f62a0
VZ
907 else if ( *pc == wxT('_') ) // escape underscores
908 {
ee0a94cf 909 text << wxT("__");
2b5f62a0 910 }
9959e2b6 911 else
23280650 912 {
ee0a94cf 913 text << *pc;
2b5f62a0
VZ
914 }
915 ++pc;
83624f79 916 }
a01fe3d6 917
ee0a94cf 918 if (hotKey)
d7dbc98a 919 {
ee0a94cf
RR
920 hotKey->Empty();
921 if(*pc == wxT('\t'))
922 {
923 pc++;
e0a050e3 924 hotKey->assign(pc, str.end());
ee0a94cf 925 }
d7dbc98a 926 }
88d19775 927
ee0a94cf
RR
928 return text;
929}
930
931// it's valid for this function to be called even if m_menuItem == NULL
932void wxMenuItem::DoSetText( const wxString& str )
933{
934 m_text.Empty();
935 m_text = GTKProcessMenuItemLabel(str, &m_hotKey);
716b7364
RR
936}
937
717a57c2
VZ
938#if wxUSE_ACCEL
939
940wxAcceleratorEntry *wxMenuItem::GetAccel() const
941{
1987af7e 942 if ( !GetHotKey() )
717a57c2
VZ
943 {
944 // nothing
90527a50 945 return NULL;
717a57c2
VZ
946 }
947
90527a50
VZ
948 // accelerator parsing code looks for them after a TAB, so insert a dummy
949 // one here
717a57c2 950 wxString label;
1987af7e 951 label << wxT('\t') << GetHotKey();
717a57c2 952
90527a50 953 return wxAcceleratorEntry::Create(label);
717a57c2
VZ
954}
955
956#endif // wxUSE_ACCEL
957
96fd301f 958void wxMenuItem::Check( bool check )
716b7364 959{
223d09f6 960 wxCHECK_RET( m_menuItem, wxT("invalid menu item") );
db1b4961 961
974e8d94
VZ
962 if (check == m_isChecked)
963 return;
2d17d68f 964
974e8d94 965 wxMenuItemBase::Check( check );
0472ece7 966
24bcaec3 967 switch ( GetKind() )
0472ece7 968 {
24bcaec3
VZ
969 case wxITEM_CHECK:
970 case wxITEM_RADIO:
8394218c 971 gtk_check_menu_item_set_active( (GtkCheckMenuItem*)m_menuItem, (gint)check );
24bcaec3
VZ
972 break;
973
974 default:
975 wxFAIL_MSG( _T("can't check this item") );
0472ece7 976 }
716b7364
RR
977}
978
8bbe427f
VZ
979void wxMenuItem::Enable( bool enable )
980{
223d09f6 981 wxCHECK_RET( m_menuItem, wxT("invalid menu item") );
db1b4961 982
83624f79 983 gtk_widget_set_sensitive( m_menuItem, enable );
974e8d94 984 wxMenuItemBase::Enable( enable );
a9c96bcc
RR
985}
986
96fd301f 987bool wxMenuItem::IsChecked() const
716b7364 988{
670f9935 989 wxCHECK_MSG( m_menuItem, false, wxT("invalid menu item") );
db1b4961 990
670f9935 991 wxCHECK_MSG( IsCheckable(), false,
974e8d94 992 wxT("can't get state of uncheckable item!") );
96fd301f 993
974e8d94 994 return ((GtkCheckMenuItem*)m_menuItem)->active != 0;
716b7364
RR
995}
996
db1b4961 997//-----------------------------------------------------------------------------
83624f79 998// wxMenu
db1b4961
RR
999//-----------------------------------------------------------------------------
1000
c801d85f
KB
1001IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
1002
717a57c2 1003void wxMenu::Init()
c801d85f 1004{
034be888 1005 m_accel = gtk_accel_group_new();
6d971354 1006 m_menu = gtk_menu_new();
defc0789
VS
1007 // NB: keep reference to the menu so that it is not destroyed behind
1008 // our back by GTK+ e.g. when it is removed from menubar:
1009 gtk_widget_ref(m_menu);
8bbe427f 1010
2b1c162e 1011 m_owner = (GtkWidget*) NULL;
2b2edbed 1012
d9e403cc
RR
1013 // Tearoffs are entries, just like separators. So if we want this
1014 // menu to be a tear-off one, we just append a tearoff entry
1015 // immediately.
9959e2b6 1016 if ( m_style & wxMENU_TEAROFF )
2b2edbed 1017 {
9959e2b6 1018 GtkWidget *tearoff = gtk_tearoff_menu_item_new();
6d971354 1019
1ab9e06d 1020 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), tearoff);
9959e2b6 1021 }
6d971354 1022
9959e2b6 1023 m_prevRadio = NULL;
c801d85f 1024
717a57c2 1025 // append the title as the very first entry if we have it
9959e2b6 1026 if ( !m_title.empty() )
d1b15f03 1027 {
9959e2b6 1028 Append(wxGTK_TITLE_ID, m_title);
717a57c2 1029 AppendSeparator();
d1b15f03 1030 }
717a57c2 1031}
15a2076a 1032
717a57c2
VZ
1033wxMenu::~wxMenu()
1034{
368a4a47 1035 if ( GTK_IS_WIDGET( m_menu ))
defc0789 1036 {
a761df69 1037 // see wxMenu::Init
88d19775 1038 gtk_widget_unref( m_menu );
b8a922d0 1039 g_object_unref( m_accel );
52af3158 1040
a761df69
VS
1041 // if the menu is inserted in another menu at this time, there was
1042 // one more reference to it:
1043 if ( m_owner )
1044 gtk_widget_destroy( m_menu );
defc0789 1045 }
e4161a2a
VZ
1046
1047 // This must come after we release GTK resources above. Otherwise, GTK will
1048 // give warnings/errors when attempting to free accelerator resources from
1049 // child items that just were destroyed (the m_menu widget can contain
1050 // references to accelerators in child items. Problem detected when removing
1051 // a menu from a wxMenuBar, and the removed menu had submenus with accelerators.)
05b743ba 1052 WX_CLEAR_LIST(wxMenuItemList, m_items);
c2dd8380
GL
1053}
1054
978af864
VZ
1055void wxMenu::SetLayoutDirection(const wxLayoutDirection dir)
1056{
1057 if ( m_owner )
1058 wxWindow::GTKSetLayout(m_owner, dir);
1059 //else: will be called later by wxMenuBar again
1060}
1061
1062wxLayoutDirection wxMenu::GetLayoutDirection() const
1063{
1064 return wxWindow::GTKGetLayout(m_owner);
1065}
1066
49826dab 1067bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
c2dd8380 1068{
717a57c2 1069 GtkWidget *menuItem;
96fd301f 1070
ee0a94cf 1071 // cache some data used later
84c51319 1072 wxString text = mitem->wxMenuItemBase::GetItemLabel();
ee0a94cf
RR
1073 int id = mitem->GetId();
1074 bool isstock = wxIsStockID(id);
1075 const char *stockid = NULL;
1076 if (isstock)
1077 stockid = wxGetStockGtkID(mitem->GetId());
1078
1079 // stock menu items can have an empty label
1080 if (text.IsEmpty() && !mitem->IsSeparator())
1081 {
1082 wxASSERT_MSG(isstock, wxT("A non-stock menu item with an empty label?"));
1083 text = wxGetStockLabel(id);
1084
1085 // need & => _ conversion
1086 text = wxMenuItem::GTKProcessMenuItemLabel(text, NULL);
1087 }
e31126cb 1088
717a57c2
VZ
1089 if ( mitem->IsSeparator() )
1090 {
6d971354 1091 menuItem = gtk_separator_menu_item_new();
837904f2 1092 }
ab73fe8d 1093 else if ( mitem->GetBitmap().Ok() ||
ee0a94cf 1094 (mitem->GetKind() == wxITEM_NORMAL && isstock) )
37d403aa 1095 {
ab73fe8d 1096 wxBitmap bitmap(mitem->GetBitmap());
9959e2b6 1097
5f11fef5 1098 menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
9959e2b6 1099
b1ad1424 1100 GtkWidget *image;
ab73fe8d 1101 if ( !bitmap.Ok() )
b1ad1424 1102 {
ab73fe8d
VZ
1103 // use stock bitmap for this item if available on the assumption
1104 // that it never hurts to follow GTK+ conventions more closely
ee0a94cf
RR
1105 image = stockid ? gtk_image_new_from_stock(stockid, GTK_ICON_SIZE_MENU)
1106 : NULL;
b1ad1424 1107 }
ab73fe8d 1108 else // we have a custom bitmap
b1ad1424 1109 {
ab73fe8d
VZ
1110 wxASSERT_MSG( mitem->GetKind() == wxITEM_NORMAL,
1111 _T("only normal menu items can have bitmaps") );
1112
1113 if ( bitmap.HasPixbuf() )
1114 {
1115 image = gtk_image_new_from_pixbuf(bitmap.GetPixbuf());
1116 }
1117 else
1118 {
1119 GdkPixmap *gdk_pixmap = bitmap.GetPixmap();
1120 GdkBitmap *gdk_bitmap = bitmap.GetMask() ?
1121 bitmap.GetMask()->GetBitmap() :
1122 (GdkBitmap*) NULL;
1123 image = gtk_image_new_from_pixmap( gdk_pixmap, gdk_bitmap );
1124 }
b1ad1424 1125 }
88d19775 1126
ab73fe8d
VZ
1127 if ( image )
1128 {
1129 gtk_widget_show(image);
9959e2b6 1130
ab73fe8d
VZ
1131 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(menuItem), image );
1132 }
9959e2b6 1133
6d971354
RR
1134 m_prevRadio = NULL;
1135 }
717a57c2
VZ
1136 else // a normal item
1137 {
52af3158 1138 // NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
ee0a94cf 1139 // so don't use it
717a57c2 1140
d65c269b
VZ
1141 switch ( mitem->GetKind() )
1142 {
546bfbea 1143 case wxITEM_CHECK:
6d971354 1144 {
5f11fef5 1145 menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
6d971354 1146 m_prevRadio = NULL;
d65c269b 1147 break;
6d971354 1148 }
d65c269b 1149
546bfbea 1150 case wxITEM_RADIO:
6d971354
RR
1151 {
1152 GSList *group = NULL;
1153 if ( m_prevRadio == NULL )
d65c269b
VZ
1154 {
1155 // start of a new radio group
5f11fef5
VZ
1156 m_prevRadio = menuItem =
1157 gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) );
d65c269b
VZ
1158 }
1159 else // continue the radio group
1160 {
6d971354 1161 group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio));
5f11fef5
VZ
1162 m_prevRadio = menuItem =
1163 gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) );
d65c269b 1164 }
c0d0a552 1165 break;
6d971354 1166 }
d65c269b
VZ
1167
1168 default:
1169 wxFAIL_MSG( _T("unexpected menu item kind") );
1170 // fall through
1171
546bfbea 1172 case wxITEM_NORMAL:
6d971354 1173 {
5f11fef5 1174 menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
6d971354 1175 m_prevRadio = NULL;
d65c269b 1176 break;
6d971354 1177 }
d65c269b
VZ
1178 }
1179
6d971354 1180 }
9959e2b6 1181
6d971354
RR
1182 guint accel_key;
1183 GdkModifierType accel_mods;
5f11fef5 1184 wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*mitem) );
9959e2b6 1185
52af3158 1186 // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetItemLabel().c_str(), GetGtkHotKey(*mitem).c_str() );
ee0a94cf
RR
1187 if (buf[(size_t)0] != '\0')
1188 {
1189 gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
1190 if (accel_key != 0)
1191 {
10bd1f7d 1192 gtk_widget_add_accelerator (menuItem,
ee0a94cf
RR
1193 "activate",
1194 m_accel,
1195 accel_key,
1196 accel_mods,
1197 GTK_ACCEL_VISIBLE);
1198 }
1199 }
1200 else if (isstock)
6d971354 1201 {
ee0a94cf
RR
1202 // if the accelerator was taken from a stock ID, just get it back from GTK+ stock
1203 if (wxGetStockGtkAccelerator(stockid, &accel_mods, &accel_key))
10bd1f7d 1204 gtk_widget_add_accelerator( menuItem,
ee0a94cf
RR
1205 "activate",
1206 m_accel,
1207 accel_key,
1208 accel_mods,
1209 GTK_ACCEL_VISIBLE);
717a57c2 1210 }
9959e2b6 1211
e31126cb
RR
1212 if (pos == -1)
1213 gtk_menu_shell_append(GTK_MENU_SHELL(m_menu), menuItem);
1214 else
1215 gtk_menu_shell_insert(GTK_MENU_SHELL(m_menu), menuItem, pos);
1216
6d971354 1217 gtk_widget_show( menuItem );
23280650 1218
717a57c2
VZ
1219 if ( !mitem->IsSeparator() )
1220 {
2b5f62a0 1221 wxASSERT_MSG( menuItem, wxT("invalid menuitem") );
a01fe3d6 1222
9fa72bd2
MR
1223 g_signal_connect (menuItem, "select",
1224 G_CALLBACK (gtk_menu_hilight_callback), this);
1225 g_signal_connect (menuItem, "deselect",
1226 G_CALLBACK (gtk_menu_nolight_callback), this);
e31126cb 1227
88d19775
MR
1228 if ( mitem->IsSubMenu() && mitem->GetKind() != wxITEM_RADIO && mitem->GetKind() != wxITEM_CHECK )
1229 {
e31126cb
RR
1230 gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
1231
1232 gtk_widget_show( mitem->GetSubMenu()->m_menu );
1233
1234 // if adding a submenu to a menu already existing in the menu bar, we
1235 // must set invoking window to allow processing events from this
1236 // submenu
1237 if ( m_invokingWindow )
1238 wxMenubarSetInvokingWindow(mitem->GetSubMenu(), m_invokingWindow);
88d19775
MR
1239 }
1240 else
1241 {
9fa72bd2
MR
1242 g_signal_connect (menuItem, "activate",
1243 G_CALLBACK (gtk_menu_clicked_callback),
1244 this);
88d19775 1245 }
717a57c2 1246 }
23280650 1247
837904f2 1248 mitem->SetMenuItem(menuItem);
837904f2 1249
6d971354 1250 if (ms_locked)
d65c269b 1251 {
6d971354
RR
1252 // This doesn't even exist!
1253 // gtk_widget_lock_accelerators(mitem->GetMenuItem());
d65c269b 1254 }
d65c269b 1255
670f9935 1256 return true;
6de97a3b 1257}
c801d85f 1258
9add9367 1259wxMenuItem* wxMenu::DoAppend(wxMenuItem *mitem)
828f655f 1260{
9add9367
RD
1261 if (!GtkAppend(mitem))
1262 return NULL;
9959e2b6 1263
9add9367 1264 return wxMenuBase::DoAppend(mitem);
c33c4050
RR
1265}
1266
9add9367 1267wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
c33c4050 1268{
717a57c2 1269 if ( !wxMenuBase::DoInsert(pos, item) )
9add9367 1270 return NULL;
c626a8b7 1271
6d971354 1272 // TODO
49826dab 1273 if ( !GtkAppend(item, (int)pos) )
9add9367 1274 return NULL;
32db328c 1275
9add9367 1276 return item;
c33c4050
RR
1277}
1278
717a57c2 1279wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
c33c4050 1280{
717a57c2
VZ
1281 if ( !wxMenuBase::DoRemove(item) )
1282 return (wxMenuItem *)NULL;
c626a8b7 1283
717a57c2
VZ
1284 // TODO: this code doesn't delete the item factory item and this seems
1285 // impossible as of GTK 1.2.6.
1286 gtk_widget_destroy( item->GetMenuItem() );
c626a8b7 1287
717a57c2 1288 return item;
c33c4050
RR
1289}
1290
96fd301f
VZ
1291int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
1292{
222ed1d6 1293 wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
83624f79
RR
1294 while (node)
1295 {
b1d4dd7a 1296 wxMenuItem *item = node->GetData();
83624f79 1297 if (item->GetMenuItem() == menuItem)
88d19775 1298 return item->GetId();
b1d4dd7a 1299 node = node->GetNext();
83624f79 1300 }
96fd301f 1301
c626a8b7 1302 return wxNOT_FOUND;
6de97a3b 1303}
c801d85f 1304
978af864
VZ
1305void wxMenu::Attach(wxMenuBarBase *menubar)
1306{
1307 wxMenuBase::Attach(menubar);
1308
1309 // inherit layout direction from menubar.
1310 SetLayoutDirection(menubar->GetLayoutDirection());
1311}
1312
717a57c2
VZ
1313// ----------------------------------------------------------------------------
1314// helpers
1315// ----------------------------------------------------------------------------
1316
6d971354 1317#if wxUSE_ACCEL
a070d8ce 1318
98f29783 1319static wxString GetGtkHotKey( const wxMenuItem& item )
c801d85f 1320{
717a57c2
VZ
1321 wxString hotkey;
1322
1323 wxAcceleratorEntry *accel = item.GetAccel();
1324 if ( accel )
83624f79 1325 {
717a57c2
VZ
1326 int flags = accel->GetFlags();
1327 if ( flags & wxACCEL_ALT )
1328 hotkey += wxT("<alt>");
1329 if ( flags & wxACCEL_CTRL )
1330 hotkey += wxT("<control>");
1331 if ( flags & wxACCEL_SHIFT )
1332 hotkey += wxT("<shift>");
1333
1334 int code = accel->GetKeyCode();
1335 switch ( code )
c626a8b7 1336 {
717a57c2
VZ
1337 case WXK_F1:
1338 case WXK_F2:
1339 case WXK_F3:
1340 case WXK_F4:
1341 case WXK_F5:
1342 case WXK_F6:
1343 case WXK_F7:
1344 case WXK_F8:
1345 case WXK_F9:
1346 case WXK_F10:
1347 case WXK_F11:
1348 case WXK_F12:
bbcd4085
RR
1349 case WXK_F13:
1350 case WXK_F14:
1351 case WXK_F15:
1352 case WXK_F16:
1353 case WXK_F17:
1354 case WXK_F18:
1355 case WXK_F19:
1356 case WXK_F20:
1357 case WXK_F21:
1358 case WXK_F22:
1359 case WXK_F23:
1360 case WXK_F24:
04cc1e93 1361 hotkey += wxString::Format(wxT("F%d"), code - WXK_F1 + 1);
717a57c2 1362 break;
2368dcda 1363
a070d8ce
VZ
1364 // TODO: we should use gdk_keyval_name() (a.k.a.
1365 // XKeysymToString) here as well as hardcoding the keysym
1366 // names this might be not portable
bbcd4085 1367 case WXK_INSERT:
3ca6a5f0
BP
1368 hotkey << wxT("Insert" );
1369 break;
1370 case WXK_DELETE:
1371 hotkey << wxT("Delete" );
1372 break;
2b5f62a0
VZ
1373 case WXK_UP:
1374 hotkey << wxT("Up" );
1375 break;
1376 case WXK_DOWN:
1377 hotkey << wxT("Down" );
1378 break;
1379 case WXK_PAGEUP:
f005ea42 1380 hotkey << wxT("Page_Up" );
2b5f62a0
VZ
1381 break;
1382 case WXK_PAGEDOWN:
f005ea42 1383 hotkey << wxT("Page_Down" );
2b5f62a0
VZ
1384 break;
1385 case WXK_LEFT:
1386 hotkey << wxT("Left" );
1387 break;
1388 case WXK_RIGHT:
1389 hotkey << wxT("Right" );
1390 break;
1391 case WXK_HOME:
1392 hotkey << wxT("Home" );
1393 break;
1394 case WXK_END:
1395 hotkey << wxT("End" );
1396 break;
1397 case WXK_RETURN:
1398 hotkey << wxT("Return" );
1399 break;
bbcd4085
RR
1400 case WXK_BACK:
1401 hotkey << wxT("BackSpace" );
1402 break;
1403 case WXK_TAB:
1404 hotkey << wxT("Tab" );
1405 break;
1406 case WXK_ESCAPE:
1407 hotkey << wxT("Esc" );
1408 break;
1409 case WXK_SPACE:
1410 hotkey << wxT("space" );
1411 break;
1412 case WXK_MULTIPLY:
1413 hotkey << wxT("Multiply" );
1414 break;
1415 case WXK_ADD:
1416 hotkey << wxT("Add" );
1417 break;
1418 case WXK_SEPARATOR:
1419 hotkey << wxT("Separator" );
1420 break;
1421 case WXK_SUBTRACT:
1422 hotkey << wxT("Subtract" );
1423 break;
1424 case WXK_DECIMAL:
1425 hotkey << wxT("Decimal" );
1426 break;
1427 case WXK_DIVIDE:
1428 hotkey << wxT("Divide" );
1429 break;
1430 case WXK_CANCEL:
1431 hotkey << wxT("Cancel" );
1432 break;
1433 case WXK_CLEAR:
1434 hotkey << wxT("Clear" );
1435 break;
1436 case WXK_MENU:
1437 hotkey << wxT("Menu" );
1438 break;
1439 case WXK_PAUSE:
1440 hotkey << wxT("Pause" );
1441 break;
1442 case WXK_CAPITAL:
1443 hotkey << wxT("Capital" );
1444 break;
1445 case WXK_SELECT:
1446 hotkey << wxT("Select" );
1447 break;
1448 case WXK_PRINT:
1449 hotkey << wxT("Print" );
1450 break;
1451 case WXK_EXECUTE:
1452 hotkey << wxT("Execute" );
1453 break;
1454 case WXK_SNAPSHOT:
1455 hotkey << wxT("Snapshot" );
1456 break;
1457 case WXK_HELP:
1458 hotkey << wxT("Help" );
1459 break;
1460 case WXK_NUMLOCK:
1461 hotkey << wxT("Num_Lock" );
1462 break;
1463 case WXK_SCROLL:
1464 hotkey << wxT("Scroll_Lock" );
1465 break;
1466 case WXK_NUMPAD_INSERT:
1467 hotkey << wxT("KP_Insert" );
1468 break;
1469 case WXK_NUMPAD_DELETE:
1470 hotkey << wxT("KP_Delete" );
1471 break;
1472 case WXK_NUMPAD_SPACE:
1473 hotkey << wxT("KP_Space" );
1474 break;
1475 case WXK_NUMPAD_TAB:
1476 hotkey << wxT("KP_Tab" );
1477 break;
1478 case WXK_NUMPAD_ENTER:
1479 hotkey << wxT("KP_Enter" );
1480 break;
1481 case WXK_NUMPAD_F1: case WXK_NUMPAD_F2: case WXK_NUMPAD_F3:
1482 case WXK_NUMPAD_F4:
1483 hotkey += wxString::Format(wxT("KP_F%d"), code - WXK_NUMPAD_F1 + 1);
1484 break;
1485 case WXK_NUMPAD_HOME:
1486 hotkey << wxT("KP_Home" );
1487 break;
1488 case WXK_NUMPAD_LEFT:
1489 hotkey << wxT("KP_Left" );
1490 break;
1491 case WXK_NUMPAD_UP:
1492 hotkey << wxT("KP_Up" );
1493 break;
1494 case WXK_NUMPAD_RIGHT:
1495 hotkey << wxT("KP_Right" );
1496 break;
1497 case WXK_NUMPAD_DOWN:
1498 hotkey << wxT("KP_Down" );
1499 break;
5bd24f72 1500 case WXK_NUMPAD_PAGEUP:
f005ea42 1501 hotkey << wxT("KP_Page_Up" );
bbcd4085 1502 break;
5bd24f72 1503 case WXK_NUMPAD_PAGEDOWN:
f005ea42 1504 hotkey << wxT("KP_Page_Down" );
bbcd4085
RR
1505 break;
1506 case WXK_NUMPAD_END:
1507 hotkey << wxT("KP_End" );
1508 break;
1509 case WXK_NUMPAD_BEGIN:
1510 hotkey << wxT("KP_Begin" );
1511 break;
1512 case WXK_NUMPAD_EQUAL:
1513 hotkey << wxT("KP_Equal" );
1514 break;
1515 case WXK_NUMPAD_MULTIPLY:
1516 hotkey << wxT("KP_Multiply" );
1517 break;
1518 case WXK_NUMPAD_ADD:
1519 hotkey << wxT("KP_Add" );
1520 break;
1521 case WXK_NUMPAD_SEPARATOR:
1522 hotkey << wxT("KP_Separator" );
1523 break;
1524 case WXK_NUMPAD_SUBTRACT:
1525 hotkey << wxT("KP_Subtract" );
1526 break;
1527 case WXK_NUMPAD_DECIMAL:
1528 hotkey << wxT("KP_Decimal" );
1529 break;
1530 case WXK_NUMPAD_DIVIDE:
1531 hotkey << wxT("KP_Divide" );
1532 break;
1533 case WXK_NUMPAD0: case WXK_NUMPAD1: case WXK_NUMPAD2:
1534 case WXK_NUMPAD3: case WXK_NUMPAD4: case WXK_NUMPAD5:
1535 case WXK_NUMPAD6: case WXK_NUMPAD7: case WXK_NUMPAD8: case WXK_NUMPAD9:
1536 hotkey += wxString::Format(wxT("KP_%d"), code - WXK_NUMPAD0);
1537 break;
1538 case WXK_WINDOWS_LEFT:
1539 hotkey << wxT("Super_L" );
1540 break;
1541 case WXK_WINDOWS_RIGHT:
1542 hotkey << wxT("Super_R" );
1543 break;
1544 case WXK_WINDOWS_MENU:
1545 hotkey << wxT("Menu" );
1546 break;
1547 case WXK_COMMAND:
1548 hotkey << wxT("Command" );
1549 break;
1550 /* These probably wouldn't work as there is no SpecialX in gdk/keynames.txt
88d19775
MR
1551 case WXK_SPECIAL1: case WXK_SPECIAL2: case WXK_SPECIAL3: case WXK_SPECIAL4:
1552 case WXK_SPECIAL5: case WXK_SPECIAL6: case WXK_SPECIAL7: case WXK_SPECIAL8:
1553 case WXK_SPECIAL9: case WXK_SPECIAL10: case WXK_SPECIAL11: case WXK_SPECIAL12:
1554 case WXK_SPECIAL13: case WXK_SPECIAL14: case WXK_SPECIAL15: case WXK_SPECIAL16:
bbcd4085
RR
1555 case WXK_SPECIAL17: case WXK_SPECIAL18: case WXK_SPECIAL19: case WXK_SPECIAL20:
1556 hotkey += wxString::Format(wxT("Special%d"), code - WXK_SPECIAL1 + 1);
1557 break;
1558 */
90527a50 1559 // if there are any other keys wxAcceleratorEntry::Create() may
a070d8ce 1560 // return, we should process them here
8bbe427f 1561
717a57c2 1562 default:
a070d8ce 1563 if ( code < 127 )
717a57c2 1564 {
30083ad8
VZ
1565 const wxString
1566 name = wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint)code));
1567 if ( !name.empty() )
a070d8ce
VZ
1568 {
1569 hotkey << name;
1570 break;
1571 }
717a57c2 1572 }
c801d85f 1573
717a57c2
VZ
1574 wxFAIL_MSG( wxT("unknown keyboard accel") );
1575 }
c801d85f 1576
717a57c2 1577 delete accel;
631f1bfe 1578 }
717a57c2
VZ
1579
1580 return hotkey;
631f1bfe 1581}
a070d8ce 1582
717a57c2 1583#endif // wxUSE_ACCEL
43a11e2a
VZ
1584
1585// ----------------------------------------------------------------------------
1586// Pop-up menu stuff
1587// ----------------------------------------------------------------------------
1588
1589#if wxUSE_MENUS_NATIVE
1590
81939780 1591extern "C" WXDLLIMPEXP_CORE
43a11e2a
VZ
1592void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting )
1593{
670f9935 1594 *is_waiting = false;
43a11e2a
VZ
1595}
1596
81939780 1597WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win )
43a11e2a
VZ
1598{
1599 menu->SetInvokingWindow( win );
1600
1601 wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
1602 while (node)
1603 {
1604 wxMenuItem *menuitem = node->GetData();
1605 if (menuitem->IsSubMenu())
1606 {
1607 SetInvokingWindow( menuitem->GetSubMenu(), win );
1608 }
1609
1610 node = node->GetNext();
1611 }
1612}
1613
81939780 1614extern "C" WXDLLIMPEXP_CORE
43a11e2a
VZ
1615void wxPopupMenuPositionCallback( GtkMenu *menu,
1616 gint *x, gint *y,
43a11e2a 1617 gboolean * WXUNUSED(whatever),
43a11e2a
VZ
1618 gpointer user_data )
1619{
1620 // ensure that the menu appears entirely on screen
1621 GtkRequisition req;
1622 gtk_widget_get_child_requisition(GTK_WIDGET(menu), &req);
1623
1624 wxSize sizeScreen = wxGetDisplaySize();
1625 wxPoint *pos = (wxPoint*)user_data;
1626
1627 gint xmax = sizeScreen.x - req.width,
1628 ymax = sizeScreen.y - req.height;
1629
1630 *x = pos->x < xmax ? pos->x : xmax;
1631 *y = pos->y < ymax ? pos->y : ymax;
1632}
1633
1634bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
1635{
1636 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
1637
1638 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
1639
1640 // NOTE: if you change this code, you need to update
1641 // the same code in taskbar.cpp as well. This
1642 // is ugly code duplication, I know.
1643
1644 SetInvokingWindow( menu, this );
1645
1646 menu->UpdateUI();
1647
1648 bool is_waiting = true;
1649
9fa72bd2
MR
1650 gulong handler = g_signal_connect (menu->m_menu, "hide",
1651 G_CALLBACK (gtk_pop_hide_callback),
1652 &is_waiting);
43a11e2a
VZ
1653
1654 wxPoint pos;
1655 gpointer userdata;
1656 GtkMenuPositionFunc posfunc;
1657 if ( x == -1 && y == -1 )
1658 {
1659 // use GTK's default positioning algorithm
1660 userdata = NULL;
1661 posfunc = NULL;
1662 }
1663 else
1664 {
1665 pos = ClientToScreen(wxPoint(x, y));
1666 userdata = &pos;
1667 posfunc = wxPopupMenuPositionCallback;
1668 }
1669
1670 wxMenuEvent eventOpen(wxEVT_MENU_OPEN, -1, menu);
1671 DoCommonMenuCallbackCode(menu, eventOpen);
1672
1673 gtk_menu_popup(
1674 GTK_MENU(menu->m_menu),
1675 (GtkWidget *) NULL, // parent menu shell
1676 (GtkWidget *) NULL, // parent menu item
1677 posfunc, // function to position it
1678 userdata, // client data
1679 0, // button used to activate it
43a11e2a 1680 gtk_get_current_event_time()
43a11e2a
VZ
1681 );
1682
1683 while (is_waiting)
1684 {
1685 gtk_main_iteration();
1686 }
1687
9fa72bd2 1688 g_signal_handler_disconnect (menu->m_menu, handler);
43a11e2a
VZ
1689
1690 wxMenuEvent eventClose(wxEVT_MENU_CLOSE, -1, menu);
1691 DoCommonMenuCallbackCode(menu, eventClose);
1692
1693 return true;
1694}
1695
1696#endif // wxUSE_MENUS_NATIVE
bcf881ef 1697
bcf881ef
JS
1698#include <gtk/gtk.h>
1699
1700const char *wxGetStockGtkID(wxWindowID id)
1701{
1702 #define STOCKITEM(wx,gtk) \
1703 case wx: \
1704 return gtk;
1705
1706 #define STOCKITEM_MISSING(wx) \
1707 case wx: \
1708 return NULL;
1709
1710 #if GTK_CHECK_VERSION(2,4,0)
1711 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
1712 #else
1713 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
1714 #endif
1715
1716 #if GTK_CHECK_VERSION(2,6,0)
1717 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
1718 #else
1719 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
1720 #endif
1721
1722 #if GTK_CHECK_VERSION(2,10,0)
1723 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
1724 #else
1725 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
1726 #endif
1727
1728
1729 switch (id)
1730 {
1731 STOCKITEM_26(wxID_ABOUT, GTK_STOCK_ABOUT)
1732 STOCKITEM(wxID_ADD, GTK_STOCK_ADD)
1733 STOCKITEM(wxID_APPLY, GTK_STOCK_APPLY)
1734 STOCKITEM(wxID_BOLD, GTK_STOCK_BOLD)
1735 STOCKITEM(wxID_CANCEL, GTK_STOCK_CANCEL)
1736 STOCKITEM(wxID_CLEAR, GTK_STOCK_CLEAR)
1737 STOCKITEM(wxID_CLOSE, GTK_STOCK_CLOSE)
1738 STOCKITEM(wxID_COPY, GTK_STOCK_COPY)
1739 STOCKITEM(wxID_CUT, GTK_STOCK_CUT)
1740 STOCKITEM(wxID_DELETE, GTK_STOCK_DELETE)
1741 STOCKITEM_26(wxID_EDIT, GTK_STOCK_EDIT)
1742 STOCKITEM(wxID_FIND, GTK_STOCK_FIND)
1743 STOCKITEM_26(wxID_FILE, GTK_STOCK_FILE)
1744 STOCKITEM(wxID_REPLACE, GTK_STOCK_FIND_AND_REPLACE)
1745 STOCKITEM(wxID_BACKWARD, GTK_STOCK_GO_BACK)
1746 STOCKITEM(wxID_DOWN, GTK_STOCK_GO_DOWN)
1747 STOCKITEM(wxID_FORWARD, GTK_STOCK_GO_FORWARD)
1748 STOCKITEM(wxID_UP, GTK_STOCK_GO_UP)
1749 STOCKITEM(wxID_HELP, GTK_STOCK_HELP)
1750 STOCKITEM(wxID_HOME, GTK_STOCK_HOME)
1751 STOCKITEM_24(wxID_INDENT, GTK_STOCK_INDENT)
1752 STOCKITEM(wxID_INDEX, GTK_STOCK_INDEX)
1753 STOCKITEM(wxID_ITALIC, GTK_STOCK_ITALIC)
1754 STOCKITEM(wxID_JUSTIFY_CENTER, GTK_STOCK_JUSTIFY_CENTER)
1755 STOCKITEM(wxID_JUSTIFY_FILL, GTK_STOCK_JUSTIFY_FILL)
1756 STOCKITEM(wxID_JUSTIFY_LEFT, GTK_STOCK_JUSTIFY_LEFT)
1757 STOCKITEM(wxID_JUSTIFY_RIGHT, GTK_STOCK_JUSTIFY_RIGHT)
1758 STOCKITEM(wxID_NEW, GTK_STOCK_NEW)
1759 STOCKITEM(wxID_NO, GTK_STOCK_NO)
1760 STOCKITEM(wxID_OK, GTK_STOCK_OK)
1761 STOCKITEM(wxID_OPEN, GTK_STOCK_OPEN)
1762 STOCKITEM(wxID_PASTE, GTK_STOCK_PASTE)
1763 STOCKITEM(wxID_PREFERENCES, GTK_STOCK_PREFERENCES)
1764 STOCKITEM(wxID_PRINT, GTK_STOCK_PRINT)
1765 STOCKITEM(wxID_PREVIEW, GTK_STOCK_PRINT_PREVIEW)
1766 STOCKITEM(wxID_PROPERTIES, GTK_STOCK_PROPERTIES)
1767 STOCKITEM(wxID_EXIT, GTK_STOCK_QUIT)
1768 STOCKITEM(wxID_REDO, GTK_STOCK_REDO)
1769 STOCKITEM(wxID_REFRESH, GTK_STOCK_REFRESH)
1770 STOCKITEM(wxID_REMOVE, GTK_STOCK_REMOVE)
1771 STOCKITEM(wxID_REVERT_TO_SAVED, GTK_STOCK_REVERT_TO_SAVED)
1772 STOCKITEM(wxID_SAVE, GTK_STOCK_SAVE)
1773 STOCKITEM(wxID_SAVEAS, GTK_STOCK_SAVE_AS)
1774 STOCKITEM_210(wxID_SELECTALL, GTK_STOCK_SELECT_ALL)
1775 STOCKITEM(wxID_STOP, GTK_STOCK_STOP)
1776 STOCKITEM(wxID_UNDELETE, GTK_STOCK_UNDELETE)
1777 STOCKITEM(wxID_UNDERLINE, GTK_STOCK_UNDERLINE)
1778 STOCKITEM(wxID_UNDO, GTK_STOCK_UNDO)
1779 STOCKITEM_24(wxID_UNINDENT, GTK_STOCK_UNINDENT)
1780 STOCKITEM(wxID_YES, GTK_STOCK_YES)
1781 STOCKITEM(wxID_ZOOM_100, GTK_STOCK_ZOOM_100)
1782 STOCKITEM(wxID_ZOOM_FIT, GTK_STOCK_ZOOM_FIT)
1783 STOCKITEM(wxID_ZOOM_IN, GTK_STOCK_ZOOM_IN)
1784 STOCKITEM(wxID_ZOOM_OUT, GTK_STOCK_ZOOM_OUT)
1785
1786 default:
1787 wxFAIL_MSG( _T("invalid stock item ID") );
1788 break;
1789 };
1790
1791 #undef STOCKITEM
1792
1793 return NULL;
1794}
1795
1796bool wxGetStockGtkAccelerator(const char *id, GdkModifierType *mod, guint *key)
1797{
1798 if (!id)
1799 return false;
1800
1801 GtkStockItem stock_item;
1802 if (gtk_stock_lookup (id, &stock_item))
1803 {
1804 if (key) *key = stock_item.keyval;
1805 if (mod) *mod = stock_item.modifier;
1806
1807 // some GTK stock items have zero values for the keyval;
1808 // it means that they do not have an accelerator...
1809 if (stock_item.keyval)
1810 return true;
1811 }
1812
1813 return false;
1814}
1815
28fcfbfe 1816#endif // wxUSE_MENUS