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