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