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