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