]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: menu.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
96fd301f | 5 | // Id: $Id$ |
a81258be | 6 | // Copyright: (c) 1998 Robert Roebling |
96fd301f | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
c801d85f KB |
10 | #ifdef __GNUG__ |
11 | #pragma implementation "menu.h" | |
6ca41e57 | 12 | #pragma implementation "menuitem.h" |
c801d85f KB |
13 | #endif |
14 | ||
96fd301f | 15 | #include "wx/log.h" |
30dea054 | 16 | #include "wx/intl.h" |
06cfab17 | 17 | #include "wx/app.h" |
37d403aa | 18 | #include "wx/bitmap.h" |
3dfac970 | 19 | #include "wx/menu.h" |
c801d85f | 20 | |
974e8d94 VZ |
21 | #if wxUSE_ACCEL |
22 | #include "wx/accel.h" | |
23 | #endif // wxUSE_ACCEL | |
24 | ||
9e691f46 VZ |
25 | #include "wx/gtk/private.h" |
26 | ||
cc47eed9 | 27 | #include <gdk/gdkkeysyms.h> |
9e691f46 VZ |
28 | |
29 | // FIXME: is this right? somehow I don't think so (VZ) | |
30 | #ifdef __WXGTK20__ | |
31 | #include <glib-object.h> | |
32 | ||
33 | #define gtk_accel_group_attach(g, o) _gtk_accel_group_attach((g), (o)) | |
34 | #define gtk_accel_group_detach(g, o) _gtk_accel_group_detach((g), (o)) | |
35 | #define gtk_menu_ensure_uline_accel_group(m) gtk_menu_get_accel_group(m) | |
36 | ||
37 | #define ACCEL_OBJECT GObject | |
38 | #define ACCEL_OBJECTS(a) (a)->acceleratables | |
39 | #define ACCEL_OBJ_CAST(obj) G_OBJECT(obj) | |
40 | #else // GTK+ 1.x | |
41 | #define ACCEL_OBJECT GtkObject | |
42 | #define ACCEL_OBJECTS(a) (a)->attach_objects | |
43 | #define ACCEL_OBJ_CAST(obj) GTK_OBJECT(obj) | |
44 | #endif | |
83624f79 | 45 | |
acfd422a RR |
46 | //----------------------------------------------------------------------------- |
47 | // idle system | |
48 | //----------------------------------------------------------------------------- | |
49 | ||
50 | extern void wxapp_install_idle_handler(); | |
51 | extern bool g_isIdle; | |
52 | ||
9e691f46 VZ |
53 | #if GTK_CHECK_VERSION(1, 2, 0) && wxUSE_ACCEL |
54 | static wxString GetHotKey( const wxMenuItem& item ); | |
717a57c2 VZ |
55 | #endif |
56 | ||
cc47eed9 RR |
57 | //----------------------------------------------------------------------------- |
58 | // substitute for missing GtkPixmapMenuItem | |
59 | //----------------------------------------------------------------------------- | |
37d403aa | 60 | |
9e691f46 VZ |
61 | // FIXME: I can't make this compile with GTK+ 2.0, disabling for now (VZ) |
62 | #ifndef __WXGTK20__ | |
63 | #define USE_MENU_BITMAPS | |
64 | #endif | |
65 | ||
66 | #ifdef USE_MENU_BITMAPS | |
67 | ||
cc47eed9 RR |
68 | #define GTK_TYPE_PIXMAP_MENU_ITEM (gtk_pixmap_menu_item_get_type ()) |
69 | #define GTK_PIXMAP_MENU_ITEM(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_PIXMAP_MENU_ITEM, GtkPixmapMenuItem)) | |
37d403aa | 70 | #define GTK_PIXMAP_MENU_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_PIXMAP_MENU_ITEM, GtkPixmapMenuItemClass)) |
cc47eed9 | 71 | #define GTK_IS_PIXMAP_MENU_ITEM(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_PIXMAP_MENU_ITEM)) |
37d403aa JS |
72 | #define GTK_IS_PIXMAP_MENU_ITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PIXMAP_MENU_ITEM)) |
73 | //#define GTK_PIXMAP_MENU_ITEM_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), GTK_TYPE_PIXMAP_MENU_ITEM)) | |
cc47eed9 | 74 | #define GTK_PIXMAP_MENU_ITEM_GET_CLASS(obj) (GTK_PIXMAP_MENU_ITEM_CLASS( GTK_OBJECT_GET_CLASS(obj))) |
37d403aa JS |
75 | |
76 | #ifndef GTK_MENU_ITEM_GET_CLASS | |
77 | #define GTK_MENU_ITEM_GET_CLASS(obj) (GTK_MENU_ITEM_CLASS( GTK_OBJECT_GET_CLASS(obj))) | |
78 | #endif | |
79 | ||
80 | typedef struct _GtkPixmapMenuItem GtkPixmapMenuItem; | |
81 | typedef struct _GtkPixmapMenuItemClass GtkPixmapMenuItemClass; | |
82 | ||
83 | struct _GtkPixmapMenuItem | |
84 | { | |
cc47eed9 | 85 | GtkMenuItem menu_item; |
37d403aa | 86 | |
cc47eed9 | 87 | GtkWidget *pixmap; |
37d403aa JS |
88 | }; |
89 | ||
90 | struct _GtkPixmapMenuItemClass | |
91 | { | |
cc47eed9 | 92 | GtkMenuItemClass parent_class; |
37d403aa | 93 | |
cc47eed9 RR |
94 | guint orig_toggle_size; |
95 | guint have_pixmap_count; | |
37d403aa JS |
96 | }; |
97 | ||
98 | ||
8f262dc5 | 99 | GtkType gtk_pixmap_menu_item_get_type (void); |
cc47eed9 RR |
100 | GtkWidget* gtk_pixmap_menu_item_new (void); |
101 | void gtk_pixmap_menu_item_set_pixmap (GtkPixmapMenuItem *menu_item, | |
8f262dc5 | 102 | GtkWidget *pixmap); |
37d403aa | 103 | |
9e691f46 VZ |
104 | #endif // USE_MENU_BITMAPS |
105 | ||
f6bcfd97 BP |
106 | //----------------------------------------------------------------------------- |
107 | // idle system | |
108 | //----------------------------------------------------------------------------- | |
109 | ||
110 | static wxString wxReplaceUnderscore( const wxString& title ) | |
111 | { | |
112 | const wxChar *pc; | |
2368dcda | 113 | |
f6bcfd97 BP |
114 | /* GTK 1.2 wants to have "_" instead of "&" for accelerators */ |
115 | wxString str; | |
2b5f62a0 VZ |
116 | pc = title; |
117 | while (*pc != wxT('\0')) | |
f6bcfd97 | 118 | { |
2b5f62a0 VZ |
119 | if ((*pc == wxT('&')) && (*(pc+1) == wxT('&'))) |
120 | { | |
121 | // "&" is doubled to indicate "&" instead of accelerator | |
122 | ++pc; | |
123 | str << wxT('&'); | |
124 | } | |
125 | else if (*pc == wxT('&')) | |
f6bcfd97 | 126 | { |
4e9cbd33 | 127 | #if GTK_CHECK_VERSION(1, 2, 0) |
f6bcfd97 | 128 | str << wxT('_'); |
4e9cbd33 | 129 | #endif |
f6bcfd97 | 130 | } |
4e9cbd33 VS |
131 | #if GTK_CHECK_VERSION(2, 0, 0) |
132 | else if (*pc == wxT('/')) | |
133 | { | |
134 | str << wxT("\\/"); | |
135 | } | |
136 | else if (*pc == wxT('\\')) | |
137 | { | |
138 | str << wxT("\\\\"); | |
139 | } | |
140 | #elif GTK_CHECK_VERSION(1, 2, 0) | |
f6bcfd97 BP |
141 | else if (*pc == wxT('/')) |
142 | { | |
143 | str << wxT('\\'); | |
f6bcfd97 | 144 | } |
4e9cbd33 | 145 | #endif |
f6bcfd97 BP |
146 | else |
147 | { | |
d9e403cc | 148 | #ifdef __WXGTK12__ |
f6bcfd97 BP |
149 | if ( *pc == wxT('_') ) |
150 | { | |
151 | // underscores must be doubled to prevent them from being | |
152 | // interpreted as accelerator character prefix by GTK | |
153 | str << *pc; | |
154 | } | |
155 | #endif // GTK+ 1.2 | |
156 | ||
157 | str << *pc; | |
158 | } | |
2b5f62a0 | 159 | ++pc; |
f6bcfd97 BP |
160 | } |
161 | return str; | |
162 | } | |
163 | ||
e6396ed4 JS |
164 | //----------------------------------------------------------------------------- |
165 | // activate message from GTK | |
166 | //----------------------------------------------------------------------------- | |
167 | ||
168 | static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu ) | |
169 | { | |
170 | if (g_isIdle) wxapp_install_idle_handler(); | |
171 | ||
172 | wxMenuEvent event( wxEVT_MENU_OPEN, -1 ); | |
173 | event.SetEventObject( menu ); | |
174 | ||
a01fe3d6 RD |
175 | wxEvtHandler* handler = menu->GetEventHandler(); |
176 | if (handler && handler->ProcessEvent(event)) | |
e6396ed4 JS |
177 | return; |
178 | ||
179 | wxWindow *win = menu->GetInvokingWindow(); | |
180 | if (win) win->GetEventHandler()->ProcessEvent( event ); | |
181 | } | |
182 | ||
c801d85f KB |
183 | //----------------------------------------------------------------------------- |
184 | // wxMenuBar | |
185 | //----------------------------------------------------------------------------- | |
186 | ||
187 | IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) | |
188 | ||
3502e687 RR |
189 | wxMenuBar::wxMenuBar( long style ) |
190 | { | |
1e133b7d | 191 | /* the parent window is known after wxFrame::SetMenu() */ |
23280650 | 192 | m_needParent = FALSE; |
ae53c98c | 193 | m_style = style; |
9c884972 | 194 | m_invokingWindow = (wxWindow*) NULL; |
23280650 | 195 | |
4dcaf11a | 196 | if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) || |
223d09f6 | 197 | !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") )) |
4dcaf11a | 198 | { |
223d09f6 | 199 | wxFAIL_MSG( wxT("wxMenuBar creation failed") ); |
455fadaa | 200 | return; |
4dcaf11a | 201 | } |
3502e687 RR |
202 | |
203 | m_menus.DeleteContents( TRUE ); | |
204 | ||
1e133b7d | 205 | /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ |
9e691f46 | 206 | #if GTK_CHECK_VERSION(1, 2, 1) |
1e133b7d RR |
207 | m_accel = gtk_accel_group_new(); |
208 | m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "<main>", m_accel ); | |
209 | m_menubar = gtk_item_factory_get_widget( m_factory, "<main>" ); | |
23280650 | 210 | #else |
3502e687 | 211 | m_menubar = gtk_menu_bar_new(); |
1e133b7d | 212 | #endif |
3502e687 RR |
213 | |
214 | if (style & wxMB_DOCKABLE) | |
215 | { | |
216 | m_widget = gtk_handle_box_new(); | |
c626a8b7 VZ |
217 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_menubar) ); |
218 | gtk_widget_show( GTK_WIDGET(m_menubar) ); | |
3502e687 RR |
219 | } |
220 | else | |
221 | { | |
222 | m_widget = GTK_WIDGET(m_menubar); | |
223 | } | |
224 | ||
225 | PostCreation(); | |
c4608a8a | 226 | |
db434467 | 227 | ApplyWidgetStyle(); |
3502e687 RR |
228 | } |
229 | ||
96fd301f | 230 | wxMenuBar::wxMenuBar() |
c801d85f | 231 | { |
1e133b7d RR |
232 | /* the parent window is known after wxFrame::SetMenu() */ |
233 | m_needParent = FALSE; | |
ae53c98c | 234 | m_style = 0; |
9c884972 | 235 | m_invokingWindow = (wxWindow*) NULL; |
23280650 | 236 | |
4dcaf11a | 237 | if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) || |
223d09f6 | 238 | !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("menubar") )) |
4dcaf11a | 239 | { |
223d09f6 | 240 | wxFAIL_MSG( wxT("wxMenuBar creation failed") ); |
455fadaa | 241 | return; |
4dcaf11a | 242 | } |
974e8d94 | 243 | |
83624f79 | 244 | m_menus.DeleteContents( TRUE ); |
96fd301f | 245 | |
1e133b7d | 246 | /* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */ |
9e691f46 | 247 | #if GTK_CHECK_VERSION(1, 2, 1) |
1e133b7d RR |
248 | m_accel = gtk_accel_group_new(); |
249 | m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "<main>", m_accel ); | |
250 | m_menubar = gtk_item_factory_get_widget( m_factory, "<main>" ); | |
23280650 | 251 | #else |
83624f79 | 252 | m_menubar = gtk_menu_bar_new(); |
1e133b7d | 253 | #endif |
8bbe427f | 254 | |
828f655f | 255 | m_widget = GTK_WIDGET(m_menubar); |
96fd301f | 256 | |
83624f79 | 257 | PostCreation(); |
c4608a8a | 258 | |
db434467 | 259 | ApplyWidgetStyle(); |
6de97a3b | 260 | } |
c801d85f | 261 | |
1e133b7d RR |
262 | wxMenuBar::~wxMenuBar() |
263 | { | |
d1b15f03 | 264 | // gtk_object_unref( GTK_OBJECT(m_factory) ); why not ? |
1e133b7d RR |
265 | } |
266 | ||
5bd9e519 RR |
267 | static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win ) |
268 | { | |
269 | menu->SetInvokingWindow( (wxWindow*) NULL ); | |
270 | ||
5bd9e519 | 271 | wxWindow *top_frame = win; |
8487f887 | 272 | while (top_frame->GetParent() && !(top_frame->IsTopLevel())) |
bd77da97 | 273 | top_frame = top_frame->GetParent(); |
5bd9e519 | 274 | |
fab591c5 | 275 | /* support for native hot keys */ |
9e691f46 | 276 | gtk_accel_group_detach( menu->m_accel, ACCEL_OBJ_CAST(top_frame->m_widget) ); |
5bd9e519 | 277 | |
1987af7e | 278 | wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); |
5bd9e519 RR |
279 | while (node) |
280 | { | |
1987af7e | 281 | wxMenuItem *menuitem = node->GetData(); |
5bd9e519 RR |
282 | if (menuitem->IsSubMenu()) |
283 | wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win ); | |
1987af7e | 284 | node = node->GetNext(); |
5bd9e519 RR |
285 | } |
286 | } | |
287 | ||
288 | static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) | |
289 | { | |
290 | menu->SetInvokingWindow( win ); | |
291 | ||
9e691f46 | 292 | #if GTK_CHECK_VERSION(1, 2, 1) |
5bd9e519 | 293 | wxWindow *top_frame = win; |
8487f887 | 294 | while (top_frame->GetParent() && !(top_frame->IsTopLevel())) |
bd77da97 | 295 | top_frame = top_frame->GetParent(); |
5bd9e519 RR |
296 | |
297 | /* support for native hot keys */ | |
9e691f46 VZ |
298 | ACCEL_OBJECT *obj = ACCEL_OBJ_CAST(top_frame->m_widget); |
299 | if ( !g_slist_find( ACCEL_OBJECTS(menu->m_accel), obj ) ) | |
b4da05a6 | 300 | gtk_accel_group_attach( menu->m_accel, obj ); |
9e691f46 | 301 | #endif // GTK+ 1.2.1+ |
5bd9e519 | 302 | |
1987af7e | 303 | wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); |
5bd9e519 RR |
304 | while (node) |
305 | { | |
1987af7e | 306 | wxMenuItem *menuitem = node->GetData(); |
5bd9e519 RR |
307 | if (menuitem->IsSubMenu()) |
308 | wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win ); | |
1987af7e | 309 | node = node->GetNext(); |
5bd9e519 RR |
310 | } |
311 | } | |
312 | ||
313 | void wxMenuBar::SetInvokingWindow( wxWindow *win ) | |
314 | { | |
9c884972 | 315 | m_invokingWindow = win; |
9e691f46 | 316 | #if GTK_CHECK_VERSION(1, 2, 1) |
5bd9e519 | 317 | wxWindow *top_frame = win; |
8487f887 | 318 | while (top_frame->GetParent() && !(top_frame->IsTopLevel())) |
bd77da97 | 319 | top_frame = top_frame->GetParent(); |
5bd9e519 RR |
320 | |
321 | /* support for native key accelerators indicated by underscroes */ | |
9e691f46 VZ |
322 | ACCEL_OBJECT *obj = ACCEL_OBJ_CAST(top_frame->m_widget); |
323 | if ( !g_slist_find( ACCEL_OBJECTS(m_accel), obj ) ) | |
b4da05a6 | 324 | gtk_accel_group_attach( m_accel, obj ); |
9e691f46 | 325 | #endif // GTK+ 1.2.1+ |
5bd9e519 | 326 | |
1987af7e | 327 | wxMenuList::Node *node = m_menus.GetFirst(); |
5bd9e519 RR |
328 | while (node) |
329 | { | |
1987af7e | 330 | wxMenu *menu = node->GetData(); |
5bd9e519 | 331 | wxMenubarSetInvokingWindow( menu, win ); |
1987af7e | 332 | node = node->GetNext(); |
5bd9e519 RR |
333 | } |
334 | } | |
335 | ||
336 | void wxMenuBar::UnsetInvokingWindow( wxWindow *win ) | |
337 | { | |
9c884972 | 338 | m_invokingWindow = (wxWindow*) NULL; |
9e691f46 | 339 | #if GTK_CHECK_VERSION(1, 2, 1) |
5bd9e519 | 340 | wxWindow *top_frame = win; |
8487f887 | 341 | while (top_frame->GetParent() && !(top_frame->IsTopLevel())) |
bd77da97 | 342 | top_frame = top_frame->GetParent(); |
5bd9e519 | 343 | |
d9e403cc | 344 | // support for native key accelerators indicated by underscroes |
9e691f46 VZ |
345 | gtk_accel_group_detach( m_accel, ACCEL_OBJ_CAST(top_frame->m_widget) ); |
346 | #endif // GTK+ 1.2.1+ | |
5bd9e519 | 347 | |
1987af7e | 348 | wxMenuList::Node *node = m_menus.GetFirst(); |
5bd9e519 RR |
349 | while (node) |
350 | { | |
1987af7e | 351 | wxMenu *menu = node->GetData(); |
5bd9e519 | 352 | wxMenubarUnsetInvokingWindow( menu, win ); |
1987af7e | 353 | node = node->GetNext(); |
5bd9e519 RR |
354 | } |
355 | } | |
356 | ||
3dfac970 | 357 | bool wxMenuBar::Append( wxMenu *menu, const wxString &title ) |
c801d85f | 358 | { |
f03ec224 VZ |
359 | if ( !wxMenuBarBase::Append( menu, title ) ) |
360 | return FALSE; | |
361 | ||
362 | return GtkAppend(menu, title); | |
363 | } | |
23280650 | 364 | |
f03ec224 VZ |
365 | bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title) |
366 | { | |
f6bcfd97 | 367 | wxString str( wxReplaceUnderscore( title ) ); |
1e133b7d | 368 | |
d9e403cc | 369 | // This doesn't have much effect right now. |
1e133b7d | 370 | menu->SetTitle( str ); |
23280650 | 371 | |
d9e403cc | 372 | // GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. |
9e691f46 | 373 | #if GTK_CHECK_VERSION(1, 2, 1) |
1e133b7d | 374 | |
2b2edbed | 375 | wxString buf; |
223d09f6 | 376 | buf << wxT('/') << str.c_str(); |
c980c992 | 377 | |
d9e403cc | 378 | // local buffer in multibyte form |
a01fe3d6 | 379 | char cbuf[400]; |
fab591c5 | 380 | strcpy(cbuf, wxGTK_CONV(buf) ); |
c980c992 | 381 | |
1e133b7d | 382 | GtkItemFactoryEntry entry; |
c980c992 | 383 | entry.path = (gchar *)cbuf; // const_cast |
1e133b7d RR |
384 | entry.accelerator = (gchar*) NULL; |
385 | entry.callback = (GtkItemFactoryCallback) NULL; | |
386 | entry.callback_action = 0; | |
90350682 | 387 | entry.item_type = (char *)"<Branch>"; |
2b2edbed | 388 | |
d9e403cc | 389 | gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); // what is 2 ? |
a01fe3d6 | 390 | // in order to get the pointer to the item we need the item text _without_ underscores |
223d09f6 | 391 | wxString tmp = wxT("<main>/"); |
f6bcfd97 | 392 | const wxChar *pc; |
223d09f6 | 393 | for ( pc = str; *pc != wxT('\0'); pc++ ) |
1e133b7d | 394 | { |
455fadaa VZ |
395 | // contrary to the common sense, we must throw out _all_ underscores, |
396 | // (i.e. "Hello__World" => "HelloWorld" and not "Hello_World" as we | |
974e8d94 | 397 | // might naively think). IMHO it's a bug in GTK+ (VZ) |
223d09f6 | 398 | while (*pc == wxT('_')) |
455fadaa | 399 | pc++; |
2b2edbed | 400 | tmp << *pc; |
034be888 | 401 | } |
fab591c5 | 402 | menu->m_owner = gtk_item_factory_get_item( m_factory, wxGTK_CONV( tmp ) ); |
1e133b7d | 403 | gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); |
1e133b7d | 404 | #else |
96fd301f | 405 | |
fab591c5 | 406 | menu->m_owner = gtk_menu_item_new_with_label( wxGTK_CONV( str ) ); |
2b1c162e RR |
407 | gtk_widget_show( menu->m_owner ); |
408 | gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); | |
96fd301f | 409 | |
2b1c162e | 410 | gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner ); |
23280650 | 411 | |
1e133b7d | 412 | #endif |
9c884972 | 413 | |
e6396ed4 JS |
414 | gtk_signal_connect( GTK_OBJECT(menu->m_owner), "activate", |
415 | GTK_SIGNAL_FUNC(gtk_menu_open_callback), | |
416 | (gpointer)menu ); | |
417 | ||
9c884972 | 418 | // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables |
2b5f62a0 | 419 | // addings menu later on. |
9c884972 | 420 | if (m_invokingWindow) |
2b5f62a0 | 421 | { |
9c884972 | 422 | wxMenubarSetInvokingWindow( menu, m_invokingWindow ); |
3dfac970 | 423 | |
2b5f62a0 VZ |
424 | // OPTIMISE ME: we should probably cache this, or pass it |
425 | // directly, but for now this is a minimal | |
426 | // change to validate the new dynamic sizing. | |
427 | // see (and refactor :) similar code in Remove | |
428 | // below. | |
429 | ||
d9e403cc | 430 | wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame ); |
2b5f62a0 VZ |
431 | |
432 | if( frame ) | |
433 | frame->UpdateMenuBarSize(); | |
434 | } | |
435 | ||
3dfac970 VZ |
436 | return TRUE; |
437 | } | |
438 | ||
439 | bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) | |
440 | { | |
441 | if ( !wxMenuBarBase::Insert(pos, menu, title) ) | |
442 | return FALSE; | |
443 | ||
f03ec224 VZ |
444 | // GTK+ doesn't have a function to insert a menu using GtkItemFactory (as |
445 | // of version 1.2.6), so we first append the item and then change its | |
446 | // index | |
447 | if ( !GtkAppend(menu, title) ) | |
448 | return FALSE; | |
449 | ||
186baeb2 RR |
450 | if (pos+1 >= m_menus.GetCount()) |
451 | return TRUE; | |
452 | ||
f03ec224 VZ |
453 | GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget); |
454 | gpointer data = g_list_last(menu_shell->children)->data; | |
455 | menu_shell->children = g_list_remove(menu_shell->children, data); | |
456 | menu_shell->children = g_list_insert(menu_shell->children, data, pos); | |
457 | ||
458 | return TRUE; | |
3dfac970 VZ |
459 | } |
460 | ||
461 | wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) | |
462 | { | |
f03ec224 VZ |
463 | // remove the old item and insert a new one |
464 | wxMenu *menuOld = Remove(pos); | |
465 | if ( menuOld && !Insert(pos, menu, title) ) | |
466 | { | |
1d62a8b4 | 467 | return (wxMenu*) NULL; |
f03ec224 | 468 | } |
3dfac970 | 469 | |
f03ec224 VZ |
470 | // either Insert() succeeded or Remove() failed and menuOld is NULL |
471 | return menuOld; | |
3dfac970 VZ |
472 | } |
473 | ||
75c116ab JS |
474 | static wxMenu *CopyMenu (wxMenu *menu) |
475 | { | |
476 | wxMenu *menucopy = new wxMenu (); | |
477 | wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); | |
478 | while (node) | |
479 | { | |
480 | wxMenuItem *item = node->GetData(); | |
481 | int itemid = item->GetId(); | |
482 | wxString text = item->GetText(); | |
483 | text.Replace(wxT("_"), wxT("&")); | |
484 | wxMenu *submenu = item->GetSubMenu(); | |
485 | if (!submenu) | |
486 | { | |
487 | wxMenuItem* itemcopy = new wxMenuItem(menucopy, | |
488 | itemid, text, | |
489 | menu->GetHelpString(itemid)); | |
490 | itemcopy->SetBitmap(item->GetBitmap()); | |
491 | itemcopy->SetCheckable(item->IsCheckable()); | |
492 | menucopy->Append(itemcopy); | |
493 | } | |
494 | else | |
495 | menucopy->Append (itemid, text, CopyMenu(submenu), | |
496 | menu->GetHelpString(itemid)); | |
a01fe3d6 | 497 | |
75c116ab JS |
498 | node = node->GetNext(); |
499 | } | |
a01fe3d6 | 500 | |
75c116ab JS |
501 | return menucopy; |
502 | } | |
503 | ||
3dfac970 VZ |
504 | wxMenu *wxMenuBar::Remove(size_t pos) |
505 | { | |
f03ec224 VZ |
506 | wxMenu *menu = wxMenuBarBase::Remove(pos); |
507 | if ( !menu ) | |
1d62a8b4 | 508 | return (wxMenu*) NULL; |
f03ec224 | 509 | |
589c9fff | 510 | /* |
c4608a8a | 511 | GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget); |
589c9fff | 512 | |
1d62a8b4 RR |
513 | printf( "factory entries before %d\n", (int)g_slist_length(m_factory->items) ); |
514 | printf( "menu shell entries before %d\n", (int)g_list_length( menu_shell->children ) ); | |
589c9fff | 515 | */ |
c4608a8a | 516 | |
75c116ab JS |
517 | wxMenu *menucopy = CopyMenu( menu ); |
518 | ||
1d62a8b4 RR |
519 | // unparent calls unref() and that would delete the widget so we raise |
520 | // the ref count to 2 artificially before invoking unparent. | |
521 | gtk_widget_ref( menu->m_menu ); | |
522 | gtk_widget_unparent( menu->m_menu ); | |
c4608a8a | 523 | |
1d62a8b4 | 524 | gtk_widget_destroy( menu->m_owner ); |
75c116ab | 525 | delete menu; |
c4608a8a | 526 | |
75c116ab | 527 | menu = menucopy; |
589c9fff | 528 | /* |
1d62a8b4 RR |
529 | printf( "factory entries after %d\n", (int)g_slist_length(m_factory->items) ); |
530 | printf( "menu shell entries after %d\n", (int)g_list_length( menu_shell->children ) ); | |
589c9fff | 531 | */ |
c4608a8a | 532 | |
2b5f62a0 VZ |
533 | if (m_invokingWindow) |
534 | { | |
535 | // OPTIMISE ME: see comment in GtkAppend | |
536 | ||
d9e403cc | 537 | wxFrame *frame = wxDynamicCast( m_invokingWindow, wxFrame ); |
2b5f62a0 | 538 | |
d9e403cc | 539 | if( frame ) |
2b5f62a0 VZ |
540 | frame->UpdateMenuBarSize(); |
541 | } | |
542 | ||
1d62a8b4 | 543 | return menu; |
6de97a3b | 544 | } |
96fd301f | 545 | |
716b7364 | 546 | static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) |
c801d85f | 547 | { |
f6bcfd97 | 548 | if (wxMenuItem::GetLabelFromText(menu->GetTitle()) == wxMenuItem::GetLabelFromText(menuString)) |
83624f79 RR |
549 | { |
550 | int res = menu->FindItem( itemString ); | |
c626a8b7 VZ |
551 | if (res != wxNOT_FOUND) |
552 | return res; | |
83624f79 | 553 | } |
c626a8b7 | 554 | |
1987af7e | 555 | wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); |
83624f79 RR |
556 | while (node) |
557 | { | |
1987af7e | 558 | wxMenuItem *item = node->GetData(); |
83624f79 RR |
559 | if (item->IsSubMenu()) |
560 | return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString); | |
2b1c162e | 561 | |
1987af7e | 562 | node = node->GetNext(); |
83624f79 RR |
563 | } |
564 | ||
c626a8b7 VZ |
565 | return wxNOT_FOUND; |
566 | } | |
567 | ||
c801d85f KB |
568 | int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const |
569 | { | |
1987af7e | 570 | wxMenuList::Node *node = m_menus.GetFirst(); |
83624f79 RR |
571 | while (node) |
572 | { | |
1987af7e | 573 | wxMenu *menu = node->GetData(); |
83624f79 | 574 | int res = FindMenuItemRecursive( menu, menuString, itemString); |
1987af7e VZ |
575 | if (res != -1) |
576 | return res; | |
577 | node = node->GetNext(); | |
83624f79 | 578 | } |
1987af7e VZ |
579 | |
580 | return wxNOT_FOUND; | |
6de97a3b | 581 | } |
c801d85f | 582 | |
c626a8b7 | 583 | // Find a wxMenuItem using its id. Recurses down into sub-menus |
96fd301f | 584 | static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id) |
716b7364 | 585 | { |
717a57c2 | 586 | wxMenuItem* result = menu->FindChildItem(id); |
716b7364 | 587 | |
1987af7e | 588 | wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst(); |
c626a8b7 | 589 | while ( node && result == NULL ) |
83624f79 | 590 | { |
1987af7e | 591 | wxMenuItem *item = node->GetData(); |
83624f79 | 592 | if (item->IsSubMenu()) |
c626a8b7 | 593 | { |
83624f79 | 594 | result = FindMenuItemByIdRecursive( item->GetSubMenu(), id ); |
c626a8b7 | 595 | } |
1987af7e | 596 | node = node->GetNext(); |
83624f79 | 597 | } |
96fd301f | 598 | |
83624f79 | 599 | return result; |
6de97a3b | 600 | } |
716b7364 | 601 | |
3dfac970 | 602 | wxMenuItem* wxMenuBar::FindItem( int id, wxMenu **menuForItem ) const |
716b7364 | 603 | { |
83624f79 | 604 | wxMenuItem* result = 0; |
1987af7e | 605 | wxMenuList::Node *node = m_menus.GetFirst(); |
83624f79 RR |
606 | while (node && result == 0) |
607 | { | |
1987af7e | 608 | wxMenu *menu = node->GetData(); |
83624f79 | 609 | result = FindMenuItemByIdRecursive( menu, id ); |
1987af7e | 610 | node = node->GetNext(); |
83624f79 | 611 | } |
c626a8b7 | 612 | |
3dfac970 VZ |
613 | if ( menuForItem ) |
614 | { | |
615 | *menuForItem = result ? result->GetMenu() : (wxMenu *)NULL; | |
616 | } | |
c626a8b7 | 617 | |
3dfac970 | 618 | return result; |
bbe0af5b RR |
619 | } |
620 | ||
3dfac970 | 621 | void wxMenuBar::EnableTop( size_t pos, bool flag ) |
bbe0af5b | 622 | { |
3dfac970 | 623 | wxMenuList::Node *node = m_menus.Item( pos ); |
c626a8b7 | 624 | |
223d09f6 | 625 | wxCHECK_RET( node, wxT("menu not found") ); |
c626a8b7 | 626 | |
3dfac970 | 627 | wxMenu* menu = node->GetData(); |
c626a8b7 VZ |
628 | |
629 | if (menu->m_owner) | |
630 | gtk_widget_set_sensitive( menu->m_owner, flag ); | |
bbe0af5b RR |
631 | } |
632 | ||
3dfac970 | 633 | wxString wxMenuBar::GetLabelTop( size_t pos ) const |
bbe0af5b | 634 | { |
3dfac970 | 635 | wxMenuList::Node *node = m_menus.Item( pos ); |
c626a8b7 | 636 | |
223d09f6 | 637 | wxCHECK_MSG( node, wxT("invalid"), wxT("menu not found") ); |
c626a8b7 | 638 | |
3dfac970 | 639 | wxMenu* menu = node->GetData(); |
c626a8b7 | 640 | |
f6bcfd97 BP |
641 | wxString label; |
642 | wxString text( menu->GetTitle() ); | |
f6bcfd97 BP |
643 | for ( const wxChar *pc = text.c_str(); *pc; pc++ ) |
644 | { | |
2b5f62a0 | 645 | if ( *pc == wxT('_') ) |
f6bcfd97 | 646 | { |
2b5f62a0 | 647 | // '_' is the escape character for GTK+ |
f6bcfd97 BP |
648 | continue; |
649 | } | |
650 | ||
7cf4f7e2 GD |
651 | // don't remove ampersands '&' since if we have them in the menu title |
652 | // it means that they were doubled to indicate "&" instead of accelerator | |
653 | ||
f6bcfd97 BP |
654 | label += *pc; |
655 | } | |
f6bcfd97 BP |
656 | |
657 | return label; | |
bbe0af5b RR |
658 | } |
659 | ||
3dfac970 | 660 | void wxMenuBar::SetLabelTop( size_t pos, const wxString& label ) |
bbe0af5b | 661 | { |
3dfac970 | 662 | wxMenuList::Node *node = m_menus.Item( pos ); |
c626a8b7 | 663 | |
223d09f6 | 664 | wxCHECK_RET( node, wxT("menu not found") ); |
c626a8b7 | 665 | |
3dfac970 | 666 | wxMenu* menu = node->GetData(); |
c626a8b7 | 667 | |
f6bcfd97 BP |
668 | wxString str( wxReplaceUnderscore( label ) ); |
669 | ||
670 | menu->SetTitle( str ); | |
671 | ||
672 | if (menu->m_owner) | |
673 | { | |
674 | GtkLabel *label = GTK_LABEL( GTK_BIN(menu->m_owner)->child ); | |
675 | ||
676 | /* set new text */ | |
fab591c5 | 677 | gtk_label_set( label, wxGTK_CONV( str ) ); |
f6bcfd97 BP |
678 | |
679 | /* reparse key accel */ | |
fab591c5 | 680 | (void)gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( str ) ); |
f6bcfd97 BP |
681 | gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) ); |
682 | } | |
683 | ||
bbe0af5b RR |
684 | } |
685 | ||
c801d85f | 686 | //----------------------------------------------------------------------------- |
cf7a7e13 | 687 | // "activate" |
c801d85f KB |
688 | //----------------------------------------------------------------------------- |
689 | ||
6de97a3b | 690 | static void gtk_menu_clicked_callback( GtkWidget *widget, wxMenu *menu ) |
c801d85f | 691 | { |
1e6feb95 VZ |
692 | if (g_isIdle) |
693 | wxapp_install_idle_handler(); | |
c4608a8a | 694 | |
83624f79 | 695 | int id = menu->FindMenuIdByMenuItem(widget); |
96fd301f | 696 | |
83624f79 | 697 | /* should find it for normal (not popup) menu */ |
1e6feb95 VZ |
698 | wxASSERT_MSG( (id != -1) || (menu->GetInvokingWindow() != NULL), |
699 | _T("menu item not found in gtk_menu_clicked_callback") ); | |
96fd301f | 700 | |
c626a8b7 VZ |
701 | if (!menu->IsEnabled(id)) |
702 | return; | |
96fd301f | 703 | |
a01fe3d6 | 704 | if ( menu->IsAttached() ) // is this menu on a menubar? |
2d17d68f | 705 | { |
a01fe3d6 RD |
706 | wxFrame* frame = menu->GetMenuBar()->GetFrame(); |
707 | frame->ProcessCommand(id); | |
708 | } | |
709 | else | |
710 | { | |
711 | wxMenuItem* item = menu->FindChildItem( id ); | |
712 | wxCHECK_RET( item, wxT("error in menu item callback") ); | |
705dd80a | 713 | |
a01fe3d6 | 714 | if (item->IsCheckable()) |
2d17d68f | 715 | { |
a01fe3d6 RD |
716 | bool isReallyChecked = item->IsChecked(), |
717 | isInternallyChecked = item->wxMenuItemBase::IsChecked(); | |
718 | ||
719 | // ensure that the internal state is always consistent with what is | |
720 | // shown on the screen | |
721 | item->wxMenuItemBase::Check(isReallyChecked); | |
722 | ||
723 | // we must not report the events for the radio button going up nor the | |
724 | // events resulting from the calls to wxMenuItem::Check() | |
725 | if ( (item->GetKind() == wxITEM_RADIO && !isReallyChecked) || | |
726 | (isInternallyChecked == isReallyChecked) ) | |
727 | { | |
728 | return; | |
729 | } | |
730 | ||
731 | // the user pressed on the menu item: report the event below | |
c626a8b7 | 732 | } |
705dd80a | 733 | |
a01fe3d6 | 734 | menu->SendEvent(id, item->IsCheckable() ? item->IsChecked() : -1); |
2d17d68f | 735 | } |
cf7a7e13 RR |
736 | } |
737 | ||
738 | //----------------------------------------------------------------------------- | |
739 | // "select" | |
740 | //----------------------------------------------------------------------------- | |
741 | ||
742 | static void gtk_menu_hilight_callback( GtkWidget *widget, wxMenu *menu ) | |
743 | { | |
acfd422a RR |
744 | if (g_isIdle) wxapp_install_idle_handler(); |
745 | ||
83624f79 RR |
746 | int id = menu->FindMenuIdByMenuItem(widget); |
747 | ||
748 | wxASSERT( id != -1 ); // should find it! | |
cf7a7e13 | 749 | |
c626a8b7 VZ |
750 | if (!menu->IsEnabled(id)) |
751 | return; | |
cf7a7e13 | 752 | |
342b6a2f | 753 | wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, id ); |
83624f79 | 754 | event.SetEventObject( menu ); |
cf7a7e13 | 755 | |
a01fe3d6 RD |
756 | wxEvtHandler* handler = menu->GetEventHandler(); |
757 | if (handler && handler->ProcessEvent(event)) | |
c626a8b7 | 758 | return; |
6de97a3b | 759 | |
83624f79 RR |
760 | wxWindow *win = menu->GetInvokingWindow(); |
761 | if (win) win->GetEventHandler()->ProcessEvent( event ); | |
6de97a3b | 762 | } |
c801d85f | 763 | |
cd743a6f RR |
764 | //----------------------------------------------------------------------------- |
765 | // "deselect" | |
766 | //----------------------------------------------------------------------------- | |
767 | ||
768 | static void gtk_menu_nolight_callback( GtkWidget *widget, wxMenu *menu ) | |
769 | { | |
acfd422a RR |
770 | if (g_isIdle) wxapp_install_idle_handler(); |
771 | ||
cd743a6f RR |
772 | int id = menu->FindMenuIdByMenuItem(widget); |
773 | ||
774 | wxASSERT( id != -1 ); // should find it! | |
775 | ||
c626a8b7 VZ |
776 | if (!menu->IsEnabled(id)) |
777 | return; | |
cd743a6f RR |
778 | |
779 | wxMenuEvent event( wxEVT_MENU_HIGHLIGHT, -1 ); | |
780 | event.SetEventObject( menu ); | |
781 | ||
a01fe3d6 RD |
782 | wxEvtHandler* handler = menu->GetEventHandler(); |
783 | if (handler && handler->ProcessEvent(event)) | |
c626a8b7 | 784 | return; |
cd743a6f RR |
785 | |
786 | wxWindow *win = menu->GetInvokingWindow(); | |
c626a8b7 VZ |
787 | if (win) |
788 | win->GetEventHandler()->ProcessEvent( event ); | |
cd743a6f RR |
789 | } |
790 | ||
cf7a7e13 | 791 | //----------------------------------------------------------------------------- |
db1b4961 | 792 | // wxMenuItem |
cf7a7e13 RR |
793 | //----------------------------------------------------------------------------- |
794 | ||
7dbf5360 | 795 | IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) |
974e8d94 VZ |
796 | |
797 | wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, | |
798 | int id, | |
799 | const wxString& name, | |
800 | const wxString& help, | |
d65c269b | 801 | wxItemKind kind, |
974e8d94 VZ |
802 | wxMenu *subMenu) |
803 | { | |
d65c269b | 804 | return new wxMenuItem(parentMenu, id, name, help, kind, subMenu); |
974e8d94 | 805 | } |
96fd301f | 806 | |
974e8d94 VZ |
807 | wxMenuItem::wxMenuItem(wxMenu *parentMenu, |
808 | int id, | |
809 | const wxString& text, | |
810 | const wxString& help, | |
d65c269b | 811 | wxItemKind kind, |
974e8d94 | 812 | wxMenu *subMenu) |
d65c269b | 813 | : wxMenuItemBase(parentMenu, id, text, help, kind, subMenu) |
2368dcda | 814 | { |
092f7536 | 815 | Init(text); |
2368dcda VZ |
816 | } |
817 | ||
818 | wxMenuItem::wxMenuItem(wxMenu *parentMenu, | |
819 | int id, | |
820 | const wxString& text, | |
821 | const wxString& help, | |
822 | bool isCheckable, | |
823 | wxMenu *subMenu) | |
824 | : wxMenuItemBase(parentMenu, id, text, help, | |
825 | isCheckable ? wxITEM_CHECK : wxITEM_NORMAL, subMenu) | |
826 | { | |
092f7536 | 827 | Init(text); |
2368dcda VZ |
828 | } |
829 | ||
092f7536 | 830 | void wxMenuItem::Init(const wxString& text) |
c801d85f | 831 | { |
37d403aa | 832 | m_labelWidget = (GtkWidget *) NULL; |
83624f79 | 833 | m_menuItem = (GtkWidget *) NULL; |
974e8d94 | 834 | |
092f7536 | 835 | DoSetText(text); |
6de97a3b | 836 | } |
c801d85f | 837 | |
d1b15f03 RR |
838 | wxMenuItem::~wxMenuItem() |
839 | { | |
840 | // don't delete menu items, the menus take care of that | |
841 | } | |
842 | ||
717a57c2 | 843 | // return the menu item text without any menu accels |
3b59cdbf VZ |
844 | /* static */ |
845 | wxString wxMenuItemBase::GetLabelFromText(const wxString& text) | |
717a57c2 VZ |
846 | { |
847 | wxString label; | |
2368dcda | 848 | |
3b59cdbf | 849 | for ( const wxChar *pc = text.c_str(); *pc; pc++ ) |
717a57c2 | 850 | { |
7cf4f7e2 | 851 | if ( *pc == wxT('_') ) |
717a57c2 | 852 | { |
2b5f62a0 | 853 | // GTK 1.2 escapes "xxx_xxx" to "xxx__xxx" |
d76419bd RR |
854 | pc++; |
855 | label += *pc; | |
856 | continue; | |
857 | } | |
2368dcda | 858 | |
2b5f62a0 VZ |
859 | #if GTK_CHECK_VERSION(2, 0, 0) |
860 | if ( *pc == wxT('\\') ) | |
d76419bd | 861 | { |
2b5f62a0 VZ |
862 | // GTK 2.0 escapes "xxx/xxx" to "xxx\/xxx" |
863 | pc++; | |
864 | label += *pc; | |
717a57c2 VZ |
865 | continue; |
866 | } | |
2b5f62a0 | 867 | #endif |
717a57c2 | 868 | |
7cf4f7e2 GD |
869 | if ( (*pc == wxT('&')) && (*(pc+1) != wxT('&')) ) |
870 | { | |
871 | // wxMSW escapes "&" | |
872 | // "&" is doubled to indicate "&" instead of accelerator | |
873 | continue; | |
874 | } | |
a01fe3d6 | 875 | |
717a57c2 VZ |
876 | label += *pc; |
877 | } | |
a01fe3d6 | 878 | |
d9e403cc RR |
879 | // wxPrintf( L"text %s label %s\n", text.c_str(), label.c_str() ); |
880 | ||
717a57c2 VZ |
881 | return label; |
882 | } | |
883 | ||
884 | void wxMenuItem::SetText( const wxString& str ) | |
885 | { | |
5869f93f JS |
886 | // Some optimization to avoid flicker |
887 | wxString oldLabel = m_text; | |
888 | oldLabel = wxStripMenuCodes(oldLabel.BeforeFirst('\t')); | |
889 | oldLabel.Replace(wxT("_"), wxT("")); | |
890 | wxString label1 = wxStripMenuCodes(str.BeforeFirst('\t')); | |
891 | if (oldLabel == label1) | |
892 | return; | |
a01fe3d6 | 893 | |
717a57c2 | 894 | DoSetText(str); |
354aa1e3 RR |
895 | |
896 | if (m_menuItem) | |
897 | { | |
37d403aa JS |
898 | GtkLabel *label; |
899 | if (m_labelWidget) | |
2b5f62a0 | 900 | label = (GtkLabel*) m_labelWidget; |
37d403aa | 901 | else |
2b5f62a0 | 902 | label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); |
717a57c2 | 903 | |
2b5f62a0 VZ |
904 | #if GTK_CHECK_VERSION(2, 0, 0) |
905 | // We have to imitate item_factory_unescape_label here | |
906 | wxString tmp; | |
907 | for (size_t n = 0; n < m_text.Len(); n++) | |
908 | { | |
909 | if (m_text[n] != wxT('\\')) | |
910 | tmp += m_text[n]; | |
911 | } | |
a01fe3d6 | 912 | |
2b5f62a0 VZ |
913 | gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV(tmp) ); |
914 | #else | |
915 | // set new text | |
fab591c5 | 916 | gtk_label_set( label, wxGTK_CONV( m_text ) ); |
717a57c2 | 917 | |
2b5f62a0 VZ |
918 | // reparse key accel |
919 | (void)gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV(m_text) ); | |
354aa1e3 | 920 | gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) ); |
2b5f62a0 | 921 | #endif |
354aa1e3 RR |
922 | } |
923 | } | |
924 | ||
c626a8b7 | 925 | // it's valid for this function to be called even if m_menuItem == NULL |
974e8d94 | 926 | void wxMenuItem::DoSetText( const wxString& str ) |
716b7364 | 927 | { |
2b5f62a0 | 928 | // '\t' is the deliminator indicating a hot key |
974e8d94 | 929 | m_text.Empty(); |
ab46dc18 | 930 | const wxChar *pc = str; |
2b5f62a0 | 931 | while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) ) |
83624f79 | 932 | { |
2b5f62a0 | 933 | if ((*pc == wxT('&')) && (*(pc+1) == wxT('&'))) |
23280650 | 934 | { |
2b5f62a0 VZ |
935 | // "&" is doubled to indicate "&" instead of accelerator |
936 | ++pc; | |
937 | m_text << wxT('&'); | |
572d7461 | 938 | } |
2b5f62a0 | 939 | else if (*pc == wxT('&')) |
572d7461 | 940 | { |
2b5f62a0 | 941 | m_text << wxT('_'); |
572d7461 | 942 | } |
2b5f62a0 VZ |
943 | #if GTK_CHECK_VERSION(2, 0, 0) |
944 | else if ( *pc == wxT('_') ) // escape underscores | |
4e9cbd33 | 945 | { |
2b5f62a0 | 946 | // m_text << wxT("__"); doesn't work |
d9e403cc | 947 | m_text << wxT("__"); |
4e9cbd33 | 948 | } |
4e9cbd33 VS |
949 | else if (*pc == wxT('/')) // we have to escape slashes |
950 | { | |
951 | m_text << wxT("\\/"); | |
952 | } | |
953 | else if (*pc == wxT('\\')) // we have to double backslashes | |
954 | { | |
955 | m_text << wxT("\\\\"); | |
956 | } | |
2b5f62a0 VZ |
957 | #else |
958 | else if ( *pc == wxT('_') ) // escape underscores | |
959 | { | |
960 | m_text << wxT("__"); | |
961 | } | |
223d09f6 | 962 | else if (*pc == wxT('/')) /* we have to filter out slashes ... */ |
23280650 | 963 | { |
223d09f6 | 964 | m_text << wxT('\\'); /* ... and replace them with back slashes */ |
034be888 | 965 | } |
4e9cbd33 | 966 | #endif |
2b5f62a0 | 967 | else { |
354aa1e3 | 968 | m_text << *pc; |
2b5f62a0 VZ |
969 | } |
970 | ++pc; | |
83624f79 | 971 | } |
a01fe3d6 | 972 | |
d9e403cc | 973 | // wxPrintf( L"str %s m_text %s\n", str.c_str(), m_text.c_str() ); |
a01fe3d6 | 974 | |
223d09f6 | 975 | m_hotKey = wxT(""); |
9e691f46 | 976 | |
223d09f6 | 977 | if(*pc == wxT('\t')) |
d7dbc98a KB |
978 | { |
979 | pc++; | |
980 | m_hotKey = pc; | |
981 | } | |
716b7364 RR |
982 | } |
983 | ||
717a57c2 VZ |
984 | #if wxUSE_ACCEL |
985 | ||
986 | wxAcceleratorEntry *wxMenuItem::GetAccel() const | |
987 | { | |
1987af7e | 988 | if ( !GetHotKey() ) |
717a57c2 VZ |
989 | { |
990 | // nothing | |
991 | return (wxAcceleratorEntry *)NULL; | |
992 | } | |
993 | ||
994 | // as wxGetAccelFromString() looks for TAB, insert a dummy one here | |
995 | wxString label; | |
1987af7e | 996 | label << wxT('\t') << GetHotKey(); |
717a57c2 VZ |
997 | |
998 | return wxGetAccelFromString(label); | |
999 | } | |
1000 | ||
1001 | #endif // wxUSE_ACCEL | |
1002 | ||
96fd301f | 1003 | void wxMenuItem::Check( bool check ) |
716b7364 | 1004 | { |
223d09f6 | 1005 | wxCHECK_RET( m_menuItem, wxT("invalid menu item") ); |
db1b4961 | 1006 | |
974e8d94 VZ |
1007 | if (check == m_isChecked) |
1008 | return; | |
2d17d68f | 1009 | |
974e8d94 | 1010 | wxMenuItemBase::Check( check ); |
0472ece7 | 1011 | |
24bcaec3 | 1012 | switch ( GetKind() ) |
0472ece7 | 1013 | { |
24bcaec3 VZ |
1014 | case wxITEM_CHECK: |
1015 | case wxITEM_RADIO: | |
1016 | gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check ); | |
1017 | break; | |
1018 | ||
1019 | default: | |
1020 | wxFAIL_MSG( _T("can't check this item") ); | |
0472ece7 | 1021 | } |
716b7364 RR |
1022 | } |
1023 | ||
8bbe427f VZ |
1024 | void wxMenuItem::Enable( bool enable ) |
1025 | { | |
223d09f6 | 1026 | wxCHECK_RET( m_menuItem, wxT("invalid menu item") ); |
db1b4961 | 1027 | |
83624f79 | 1028 | gtk_widget_set_sensitive( m_menuItem, enable ); |
974e8d94 | 1029 | wxMenuItemBase::Enable( enable ); |
a9c96bcc RR |
1030 | } |
1031 | ||
96fd301f | 1032 | bool wxMenuItem::IsChecked() const |
716b7364 | 1033 | { |
223d09f6 | 1034 | wxCHECK_MSG( m_menuItem, FALSE, wxT("invalid menu item") ); |
db1b4961 | 1035 | |
974e8d94 VZ |
1036 | wxCHECK_MSG( IsCheckable(), FALSE, |
1037 | wxT("can't get state of uncheckable item!") ); | |
96fd301f | 1038 | |
974e8d94 | 1039 | return ((GtkCheckMenuItem*)m_menuItem)->active != 0; |
716b7364 RR |
1040 | } |
1041 | ||
354aa1e3 RR |
1042 | wxString wxMenuItem::GetFactoryPath() const |
1043 | { | |
d9e403cc RR |
1044 | // In order to get the pointer to the item we need the item |
1045 | // text _without_ underscores in GTK 1.2 | |
354aa1e3 | 1046 | wxString path( wxT("<main>/") ); |
717a57c2 | 1047 | |
d76419bd RR |
1048 | for ( const wxChar *pc = m_text.c_str(); *pc; pc++ ) |
1049 | { | |
2b5f62a0 | 1050 | if ( *pc == wxT('_') ) |
d76419bd | 1051 | { |
d9e403cc RR |
1052 | #ifdef __WXGTK20__ |
1053 | pc++; | |
1054 | #else | |
2b5f62a0 | 1055 | // remove '_' unconditionally |
d76419bd | 1056 | continue; |
d9e403cc | 1057 | #endif |
d76419bd | 1058 | } |
2368dcda | 1059 | |
7cf4f7e2 GD |
1060 | // don't remove ampersands '&' since if we have them in the menu item title |
1061 | // it means that they were doubled to indicate "&" instead of accelerator | |
1062 | ||
d76419bd RR |
1063 | path += *pc; |
1064 | } | |
2368dcda | 1065 | |
354aa1e3 RR |
1066 | return path; |
1067 | } | |
1068 | ||
db1b4961 | 1069 | //----------------------------------------------------------------------------- |
83624f79 | 1070 | // wxMenu |
db1b4961 RR |
1071 | //----------------------------------------------------------------------------- |
1072 | ||
c801d85f KB |
1073 | IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler) |
1074 | ||
717a57c2 | 1075 | void wxMenu::Init() |
c801d85f | 1076 | { |
034be888 RR |
1077 | m_accel = gtk_accel_group_new(); |
1078 | m_factory = gtk_item_factory_new( GTK_TYPE_MENU, "<main>", m_accel ); | |
1079 | m_menu = gtk_item_factory_get_widget( m_factory, "<main>" ); | |
8bbe427f | 1080 | |
2b1c162e | 1081 | m_owner = (GtkWidget*) NULL; |
2b2edbed | 1082 | |
d9e403cc RR |
1083 | // Tearoffs are entries, just like separators. So if we want this |
1084 | // menu to be a tear-off one, we just append a tearoff entry | |
1085 | // immediately. | |
2b2edbed KB |
1086 | if(m_style & wxMENU_TEAROFF) |
1087 | { | |
1088 | GtkItemFactoryEntry entry; | |
90350682 | 1089 | entry.path = (char *)"/tearoff"; |
2b2edbed KB |
1090 | entry.callback = (GtkItemFactoryCallback) NULL; |
1091 | entry.callback_action = 0; | |
90350682 | 1092 | entry.item_type = (char *)"<Tearoff>"; |
2b2edbed | 1093 | entry.accelerator = (gchar*) NULL; |
d9e403cc | 1094 | gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); // what is 2 ? |
23280650 | 1095 | //GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, "<main>/tearoff" ); |
2b2edbed | 1096 | } |
c801d85f | 1097 | |
717a57c2 VZ |
1098 | // append the title as the very first entry if we have it |
1099 | if ( !!m_title ) | |
d1b15f03 | 1100 | { |
717a57c2 VZ |
1101 | Append(-2, m_title); |
1102 | AppendSeparator(); | |
d1b15f03 | 1103 | } |
717a57c2 | 1104 | } |
15a2076a | 1105 | |
717a57c2 VZ |
1106 | wxMenu::~wxMenu() |
1107 | { | |
a583e623 | 1108 | m_items.Clear(); |
f03ec224 | 1109 | |
d1b15f03 | 1110 | gtk_widget_destroy( m_menu ); |
974e8d94 | 1111 | |
d1b15f03 | 1112 | gtk_object_unref( GTK_OBJECT(m_factory) ); |
c2dd8380 GL |
1113 | } |
1114 | ||
32db328c | 1115 | bool wxMenu::GtkAppend(wxMenuItem *mitem) |
c2dd8380 | 1116 | { |
717a57c2 | 1117 | GtkWidget *menuItem; |
96fd301f | 1118 | |
9e691f46 | 1119 | #if defined(USE_MENU_BITMAPS) || !GTK_CHECK_VERSION(1, 2, 0) |
37d403aa | 1120 | bool appended = FALSE; |
9e691f46 | 1121 | #endif |
37d403aa | 1122 | |
24bcaec3 VZ |
1123 | // does this item terminate the current radio group? |
1124 | bool endOfRadioGroup = TRUE; | |
d65c269b | 1125 | |
717a57c2 VZ |
1126 | if ( mitem->IsSeparator() ) |
1127 | { | |
717a57c2 | 1128 | GtkItemFactoryEntry entry; |
90350682 | 1129 | entry.path = (char *)"/sep"; |
717a57c2 VZ |
1130 | entry.callback = (GtkItemFactoryCallback) NULL; |
1131 | entry.callback_action = 0; | |
90350682 | 1132 | entry.item_type = (char *)"<Separator>"; |
717a57c2 VZ |
1133 | entry.accelerator = (gchar*) NULL; |
1134 | ||
d9e403cc | 1135 | gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); // what is 2 ? |
717a57c2 | 1136 | |
d9e403cc | 1137 | // this will be wrong for more than one separator. do we care? |
717a57c2 | 1138 | menuItem = gtk_item_factory_get_widget( m_factory, "<main>/sep" ); |
24bcaec3 VZ |
1139 | |
1140 | // we might have a separator inside a radio group | |
1141 | endOfRadioGroup = FALSE; | |
717a57c2 VZ |
1142 | } |
1143 | else if ( mitem->IsSubMenu() ) | |
837904f2 | 1144 | { |
d9e403cc | 1145 | // text has "_" instead of "&" after mitem->SetText() |
717a57c2 | 1146 | wxString text( mitem->GetText() ); |
974e8d94 | 1147 | |
d9e403cc | 1148 | // local buffer in multibyte form |
717a57c2 VZ |
1149 | char buf[200]; |
1150 | strcpy( buf, "/" ); | |
fab591c5 | 1151 | strcat( buf, wxGTK_CONV( text ) ); |
50592885 | 1152 | |
717a57c2 VZ |
1153 | GtkItemFactoryEntry entry; |
1154 | entry.path = buf; | |
1155 | entry.callback = (GtkItemFactoryCallback) 0; | |
1156 | entry.callback_action = 0; | |
90350682 | 1157 | entry.item_type = (char *)"<Branch>"; |
a583e623 | 1158 | entry.accelerator = (gchar*) NULL; |
50592885 | 1159 | |
d9e403cc | 1160 | gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); // what is 2 ? |
50592885 | 1161 | |
717a57c2 | 1162 | wxString path( mitem->GetFactoryPath() ); |
fab591c5 | 1163 | menuItem = gtk_item_factory_get_item( m_factory, wxGTK_CONV( path ) ); |
50592885 | 1164 | |
1987af7e | 1165 | gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu ); |
e7200790 VZ |
1166 | |
1167 | // if adding a submenu to a menu already existing in the menu bar, we | |
1168 | // must set invoking window to allow processing events from this | |
1169 | // submenu | |
1170 | if ( m_invokingWindow ) | |
1171 | wxMenubarSetInvokingWindow(mitem->GetSubMenu(), m_invokingWindow); | |
837904f2 | 1172 | } |
9e691f46 | 1173 | #ifdef USE_MENU_BITMAPS |
37d403aa JS |
1174 | else if (mitem->GetBitmap().Ok()) // An item with bitmap |
1175 | { | |
cc47eed9 RR |
1176 | wxString text( mitem->GetText() ); |
1177 | const wxBitmap *bitmap = &mitem->GetBitmap(); | |
2368dcda | 1178 | |
cc47eed9 | 1179 | menuItem = gtk_pixmap_menu_item_new (); |
fab591c5 | 1180 | GtkWidget *label = gtk_accel_label_new ( wxGTK_CONV( text ) ); |
cc47eed9 RR |
1181 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); |
1182 | gtk_container_add (GTK_CONTAINER (menuItem), label); | |
fab591c5 | 1183 | guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), wxGTK_CONV( text ) ); |
cc47eed9 RR |
1184 | gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), menuItem); |
1185 | if (accel_key != GDK_VoidSymbol) | |
2b5f62a0 | 1186 | { |
cc47eed9 | 1187 | gtk_widget_add_accelerator (menuItem, |
8f262dc5 VZ |
1188 | "activate_item", |
1189 | gtk_menu_ensure_uline_accel_group (GTK_MENU (m_menu)), | |
1190 | accel_key, 0, | |
1191 | GTK_ACCEL_LOCKED); | |
cc47eed9 RR |
1192 | } |
1193 | gtk_widget_show (label); | |
37d403aa | 1194 | |
cc47eed9 | 1195 | mitem->SetLabelWidget(label); |
37d403aa | 1196 | |
cc47eed9 RR |
1197 | GtkWidget* pixmap = gtk_pixmap_new( bitmap->GetPixmap(), bitmap->GetMask() ? bitmap->GetMask()->GetBitmap() : (GdkBitmap* )NULL); |
1198 | gtk_widget_show(pixmap); | |
1199 | gtk_pixmap_menu_item_set_pixmap(GTK_PIXMAP_MENU_ITEM( menuItem ), pixmap); | |
37d403aa JS |
1200 | |
1201 | gtk_signal_connect( GTK_OBJECT(menuItem), "activate", | |
1202 | GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), | |
1203 | (gpointer)this ); | |
a01fe3d6 | 1204 | |
37d403aa JS |
1205 | gtk_menu_append( GTK_MENU(m_menu), menuItem ); |
1206 | gtk_widget_show( menuItem ); | |
1207 | ||
37d403aa JS |
1208 | appended = TRUE; // We've done this, don't do it again |
1209 | } | |
9e691f46 | 1210 | #endif // USE_MENU_BITMAPS |
717a57c2 VZ |
1211 | else // a normal item |
1212 | { | |
982f23fd | 1213 | // text has "_" instead of "&" after mitem->SetText() so don't use it |
717a57c2 VZ |
1214 | wxString text( mitem->GetText() ); |
1215 | ||
8f262dc5 VZ |
1216 | // buffers containing the menu item path and type in multibyte form |
1217 | char bufPath[256], | |
1218 | bufType[256]; | |
1219 | ||
1220 | strcpy( bufPath, "/" ); | |
1221 | strncat( bufPath, wxGTK_CONV(text), WXSIZEOF(bufPath) - 2 ); | |
1222 | bufPath[WXSIZEOF(bufPath) - 1] = '\0'; | |
717a57c2 VZ |
1223 | |
1224 | GtkItemFactoryEntry entry; | |
8f262dc5 | 1225 | entry.path = bufPath; |
717a57c2 VZ |
1226 | entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback; |
1227 | entry.callback_action = 0; | |
d65c269b VZ |
1228 | |
1229 | wxString pathRadio; | |
1230 | const char *item_type; | |
1231 | switch ( mitem->GetKind() ) | |
1232 | { | |
546bfbea | 1233 | case wxITEM_CHECK: |
d65c269b VZ |
1234 | item_type = "<CheckItem>"; |
1235 | break; | |
1236 | ||
546bfbea | 1237 | case wxITEM_RADIO: |
d65c269b VZ |
1238 | if ( m_pathLastRadio.empty() ) |
1239 | { | |
1240 | // start of a new radio group | |
1241 | item_type = "<RadioItem>"; | |
2b5f62a0 VZ |
1242 | wxString tmp( wxGTK_CONV_BACK( bufPath ) ); |
1243 | tmp.Remove(0,1); | |
1244 | m_pathLastRadio = tmp; | |
d65c269b VZ |
1245 | } |
1246 | else // continue the radio group | |
1247 | { | |
1248 | pathRadio = m_pathLastRadio; | |
fab591c5 RR |
1249 | pathRadio.Replace(wxT("_"), wxT("")); |
1250 | pathRadio.Prepend(wxT("<main>/")); | |
982f23fd | 1251 | |
8f262dc5 VZ |
1252 | strncpy(bufType, wxGTK_CONV(pathRadio), WXSIZEOF(bufType)); |
1253 | bufType[WXSIZEOF(bufType) - 1] = '\0'; | |
1254 | item_type = bufType; | |
d65c269b VZ |
1255 | } |
1256 | ||
24bcaec3 VZ |
1257 | // continue the existing radio group, if any |
1258 | endOfRadioGroup = FALSE; | |
d65c269b VZ |
1259 | break; |
1260 | ||
1261 | default: | |
1262 | wxFAIL_MSG( _T("unexpected menu item kind") ); | |
1263 | // fall through | |
1264 | ||
546bfbea | 1265 | case wxITEM_NORMAL: |
d65c269b VZ |
1266 | item_type = "<Item>"; |
1267 | break; | |
1268 | } | |
1269 | ||
1270 | entry.item_type = (char *)item_type; // cast needed for GTK+ | |
a583e623 | 1271 | entry.accelerator = (gchar*) NULL; |
23280650 | 1272 | |
974e8d94 | 1273 | #if wxUSE_ACCEL |
717a57c2 VZ |
1274 | // due to an apparent bug in GTK+, we have to use a static buffer here - |
1275 | // otherwise GTK+ 1.2.2 manages to override the memory we pass to it | |
1276 | // somehow! (VZ) | |
982f23fd | 1277 | char s_accel[50]; // should be big enough, we check for overruns |
3ca6a5f0 | 1278 | wxString tmp( GetHotKey(*mitem) ); |
fab591c5 | 1279 | strncpy(s_accel, wxGTK_CONV( tmp ), WXSIZEOF(s_accel)); |
982f23fd | 1280 | s_accel[WXSIZEOF(s_accel) - 1] = '\0'; |
717a57c2 VZ |
1281 | entry.accelerator = s_accel; |
1282 | #else // !wxUSE_ACCEL | |
1283 | entry.accelerator = (char*) NULL; | |
1284 | #endif // wxUSE_ACCEL/!wxUSE_ACCEL | |
96fd301f | 1285 | |
717a57c2 | 1286 | gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ |
cf7a7e13 | 1287 | |
717a57c2 | 1288 | wxString path( mitem->GetFactoryPath() ); |
fab591c5 | 1289 | menuItem = gtk_item_factory_get_widget( m_factory, wxGTK_CONV( path ) ); |
a01fe3d6 | 1290 | |
2b5f62a0 VZ |
1291 | if (!menuItem) |
1292 | wxLogError( wxT("Wrong menu path: %s\n"), path.c_str() ); | |
717a57c2 | 1293 | } |
23280650 | 1294 | |
717a57c2 VZ |
1295 | if ( !mitem->IsSeparator() ) |
1296 | { | |
2b5f62a0 | 1297 | wxASSERT_MSG( menuItem, wxT("invalid menuitem") ); |
a01fe3d6 | 1298 | |
717a57c2 VZ |
1299 | gtk_signal_connect( GTK_OBJECT(menuItem), "select", |
1300 | GTK_SIGNAL_FUNC(gtk_menu_hilight_callback), | |
1301 | (gpointer)this ); | |
837904f2 | 1302 | |
717a57c2 VZ |
1303 | gtk_signal_connect( GTK_OBJECT(menuItem), "deselect", |
1304 | GTK_SIGNAL_FUNC(gtk_menu_nolight_callback), | |
1305 | (gpointer)this ); | |
1306 | } | |
23280650 | 1307 | |
837904f2 | 1308 | mitem->SetMenuItem(menuItem); |
837904f2 | 1309 | |
24bcaec3 | 1310 | if ( endOfRadioGroup ) |
d65c269b VZ |
1311 | { |
1312 | m_pathLastRadio.clear(); | |
1313 | } | |
d65c269b | 1314 | |
32db328c | 1315 | return TRUE; |
6de97a3b | 1316 | } |
c801d85f | 1317 | |
32db328c | 1318 | bool wxMenu::DoAppend(wxMenuItem *mitem) |
828f655f | 1319 | { |
32db328c | 1320 | return GtkAppend(mitem) && wxMenuBase::DoAppend(mitem); |
c33c4050 RR |
1321 | } |
1322 | ||
717a57c2 | 1323 | bool wxMenu::DoInsert(size_t pos, wxMenuItem *item) |
c33c4050 | 1324 | { |
717a57c2 VZ |
1325 | if ( !wxMenuBase::DoInsert(pos, item) ) |
1326 | return FALSE; | |
c626a8b7 | 1327 | |
32db328c VZ |
1328 | // GTK+ doesn't have a function to insert a menu using GtkItemFactory (as |
1329 | // of version 1.2.6), so we first append the item and then change its | |
1330 | // index | |
1331 | if ( !GtkAppend(item) ) | |
1332 | return FALSE; | |
1333 | ||
f6bcfd97 BP |
1334 | if ( m_style & wxMENU_TEAROFF ) |
1335 | { | |
1336 | // change the position as the first item is the tear-off marker | |
1337 | pos++; | |
1338 | } | |
1339 | ||
32db328c VZ |
1340 | GtkMenuShell *menu_shell = GTK_MENU_SHELL(m_factory->widget); |
1341 | gpointer data = g_list_last(menu_shell->children)->data; | |
1342 | menu_shell->children = g_list_remove(menu_shell->children, data); | |
1343 | menu_shell->children = g_list_insert(menu_shell->children, data, pos); | |
1344 | ||
1345 | return TRUE; | |
c33c4050 RR |
1346 | } |
1347 | ||
717a57c2 | 1348 | wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) |
c33c4050 | 1349 | { |
717a57c2 VZ |
1350 | if ( !wxMenuBase::DoRemove(item) ) |
1351 | return (wxMenuItem *)NULL; | |
c626a8b7 | 1352 | |
717a57c2 VZ |
1353 | // TODO: this code doesn't delete the item factory item and this seems |
1354 | // impossible as of GTK 1.2.6. | |
1355 | gtk_widget_destroy( item->GetMenuItem() ); | |
c626a8b7 | 1356 | |
717a57c2 | 1357 | return item; |
c33c4050 RR |
1358 | } |
1359 | ||
96fd301f VZ |
1360 | int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const |
1361 | { | |
b1d4dd7a | 1362 | wxMenuItemList::Node *node = m_items.GetFirst(); |
83624f79 RR |
1363 | while (node) |
1364 | { | |
b1d4dd7a | 1365 | wxMenuItem *item = node->GetData(); |
83624f79 RR |
1366 | if (item->GetMenuItem() == menuItem) |
1367 | return item->GetId(); | |
b1d4dd7a | 1368 | node = node->GetNext(); |
83624f79 | 1369 | } |
96fd301f | 1370 | |
c626a8b7 | 1371 | return wxNOT_FOUND; |
6de97a3b | 1372 | } |
c801d85f | 1373 | |
717a57c2 VZ |
1374 | // ---------------------------------------------------------------------------- |
1375 | // helpers | |
1376 | // ---------------------------------------------------------------------------- | |
1377 | ||
9e691f46 | 1378 | #if GTK_CHECK_VERSION(1, 2, 0) && wxUSE_ACCEL |
a070d8ce | 1379 | |
717a57c2 | 1380 | static wxString GetHotKey( const wxMenuItem& item ) |
c801d85f | 1381 | { |
717a57c2 VZ |
1382 | wxString hotkey; |
1383 | ||
1384 | wxAcceleratorEntry *accel = item.GetAccel(); | |
1385 | if ( accel ) | |
83624f79 | 1386 | { |
717a57c2 VZ |
1387 | int flags = accel->GetFlags(); |
1388 | if ( flags & wxACCEL_ALT ) | |
1389 | hotkey += wxT("<alt>"); | |
1390 | if ( flags & wxACCEL_CTRL ) | |
1391 | hotkey += wxT("<control>"); | |
1392 | if ( flags & wxACCEL_SHIFT ) | |
1393 | hotkey += wxT("<shift>"); | |
1394 | ||
1395 | int code = accel->GetKeyCode(); | |
1396 | switch ( code ) | |
c626a8b7 | 1397 | { |
717a57c2 VZ |
1398 | case WXK_F1: |
1399 | case WXK_F2: | |
1400 | case WXK_F3: | |
1401 | case WXK_F4: | |
1402 | case WXK_F5: | |
1403 | case WXK_F6: | |
1404 | case WXK_F7: | |
1405 | case WXK_F8: | |
1406 | case WXK_F9: | |
1407 | case WXK_F10: | |
1408 | case WXK_F11: | |
1409 | case WXK_F12: | |
1410 | hotkey << wxT('F') << code - WXK_F1 + 1; | |
1411 | break; | |
2368dcda | 1412 | |
a070d8ce VZ |
1413 | // TODO: we should use gdk_keyval_name() (a.k.a. |
1414 | // XKeysymToString) here as well as hardcoding the keysym | |
1415 | // names this might be not portable | |
3ca6a5f0 BP |
1416 | case WXK_NUMPAD_INSERT: |
1417 | hotkey << wxT("KP_Insert" ); | |
1418 | break; | |
1419 | case WXK_NUMPAD_DELETE: | |
1420 | hotkey << wxT("KP_Delete" ); | |
1421 | break; | |
1422 | case WXK_INSERT: | |
1423 | hotkey << wxT("Insert" ); | |
1424 | break; | |
1425 | case WXK_DELETE: | |
1426 | hotkey << wxT("Delete" ); | |
1427 | break; | |
2b5f62a0 VZ |
1428 | case WXK_UP: |
1429 | hotkey << wxT("Up" ); | |
1430 | break; | |
1431 | case WXK_DOWN: | |
1432 | hotkey << wxT("Down" ); | |
1433 | break; | |
1434 | case WXK_PAGEUP: | |
1435 | hotkey << wxT("Prior" ); | |
1436 | break; | |
1437 | case WXK_PAGEDOWN: | |
1438 | hotkey << wxT("Next" ); | |
1439 | break; | |
1440 | case WXK_LEFT: | |
1441 | hotkey << wxT("Left" ); | |
1442 | break; | |
1443 | case WXK_RIGHT: | |
1444 | hotkey << wxT("Right" ); | |
1445 | break; | |
1446 | case WXK_HOME: | |
1447 | hotkey << wxT("Home" ); | |
1448 | break; | |
1449 | case WXK_END: | |
1450 | hotkey << wxT("End" ); | |
1451 | break; | |
1452 | case WXK_RETURN: | |
1453 | hotkey << wxT("Return" ); | |
1454 | break; | |
96fd301f | 1455 | |
a070d8ce VZ |
1456 | // if there are any other keys wxGetAccelFromString() may |
1457 | // return, we should process them here | |
8bbe427f | 1458 | |
717a57c2 | 1459 | default: |
a070d8ce | 1460 | if ( code < 127 ) |
717a57c2 | 1461 | { |
2b5f62a0 | 1462 | wxString name = wxGTK_CONV_BACK( gdk_keyval_name((guint)code) ); |
a070d8ce VZ |
1463 | if ( name ) |
1464 | { | |
1465 | hotkey << name; | |
1466 | break; | |
1467 | } | |
717a57c2 | 1468 | } |
c801d85f | 1469 | |
717a57c2 VZ |
1470 | wxFAIL_MSG( wxT("unknown keyboard accel") ); |
1471 | } | |
c801d85f | 1472 | |
717a57c2 | 1473 | delete accel; |
631f1bfe | 1474 | } |
717a57c2 VZ |
1475 | |
1476 | return hotkey; | |
631f1bfe | 1477 | } |
a070d8ce | 1478 | |
717a57c2 | 1479 | #endif // wxUSE_ACCEL |
631f1bfe | 1480 | |
37d403aa | 1481 | |
cc47eed9 RR |
1482 | //----------------------------------------------------------------------------- |
1483 | // substitute for missing GtkPixmapMenuItem | |
1484 | //----------------------------------------------------------------------------- | |
37d403aa | 1485 | |
9e691f46 VZ |
1486 | #ifdef USE_MENU_BITMAPS |
1487 | ||
37d403aa JS |
1488 | /* |
1489 | * Copyright (C) 1998, 1999, 2000 Free Software Foundation | |
1490 | * All rights reserved. | |
1491 | * | |
1492 | * This file is part of the Gnome Library. | |
1493 | * | |
1494 | * The Gnome Library is free software; you can redistribute it and/or | |
1495 | * modify it under the terms of the GNU Library General Public License as | |
1496 | * published by the Free Software Foundation; either version 2 of the | |
1497 | * License, or (at your option) any later version. | |
1498 | * | |
1499 | * The Gnome Library is distributed in the hope that it will be useful, | |
1500 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1501 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1502 | * Library General Public License for more details. | |
1503 | * | |
1504 | * You should have received a copy of the GNU Library General Public | |
1505 | * License along with the Gnome Library; see the file COPYING.LIB. If not, | |
1506 | * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
1507 | * Boston, MA 02111-1307, USA. | |
1508 | */ | |
1509 | /* | |
1510 | @NOTATION@ | |
1511 | */ | |
1512 | ||
1513 | /* Author: Dietmar Maurer <dm@vlsivie.tuwien.ac.at> */ | |
1514 | ||
37d403aa JS |
1515 | #include <gtk/gtkaccellabel.h> |
1516 | #include <gtk/gtksignal.h> | |
1517 | #include <gtk/gtkmenuitem.h> | |
1518 | #include <gtk/gtkmenu.h> | |
1519 | #include <gtk/gtkcontainer.h> | |
1520 | ||
90350682 VZ |
1521 | extern "C" |
1522 | { | |
1523 | ||
37d403aa JS |
1524 | static void gtk_pixmap_menu_item_class_init (GtkPixmapMenuItemClass *klass); |
1525 | static void gtk_pixmap_menu_item_init (GtkPixmapMenuItem *menu_item); | |
1526 | static void gtk_pixmap_menu_item_draw (GtkWidget *widget, | |
8f262dc5 | 1527 | GdkRectangle *area); |
37d403aa | 1528 | static gint gtk_pixmap_menu_item_expose (GtkWidget *widget, |
8f262dc5 | 1529 | GdkEventExpose *event); |
37d403aa JS |
1530 | |
1531 | /* we must override the following functions */ | |
1532 | ||
1533 | static void gtk_pixmap_menu_item_map (GtkWidget *widget); | |
1534 | static void gtk_pixmap_menu_item_size_allocate (GtkWidget *widget, | |
8f262dc5 | 1535 | GtkAllocation *allocation); |
37d403aa | 1536 | static void gtk_pixmap_menu_item_forall (GtkContainer *container, |
8f262dc5 VZ |
1537 | gboolean include_internals, |
1538 | GtkCallback callback, | |
1539 | gpointer callback_data); | |
37d403aa | 1540 | static void gtk_pixmap_menu_item_size_request (GtkWidget *widget, |
8f262dc5 | 1541 | GtkRequisition *requisition); |
37d403aa | 1542 | static void gtk_pixmap_menu_item_remove (GtkContainer *container, |
8f262dc5 | 1543 | GtkWidget *child); |
37d403aa JS |
1544 | |
1545 | static void changed_have_pixmap_status (GtkPixmapMenuItem *menu_item); | |
1546 | ||
1547 | static GtkMenuItemClass *parent_class = NULL; | |
1548 | ||
90350682 VZ |
1549 | } |
1550 | ||
37d403aa JS |
1551 | #define BORDER_SPACING 3 |
1552 | #define PMAP_WIDTH 20 | |
1553 | ||
1554 | GtkType | |
1555 | gtk_pixmap_menu_item_get_type (void) | |
1556 | { | |
1557 | static GtkType pixmap_menu_item_type = 0; | |
1558 | ||
1559 | if (!pixmap_menu_item_type) | |
1560 | { | |
1561 | GtkTypeInfo pixmap_menu_item_info = | |
1562 | { | |
90350682 | 1563 | (char *)"GtkPixmapMenuItem", |
37d403aa JS |
1564 | sizeof (GtkPixmapMenuItem), |
1565 | sizeof (GtkPixmapMenuItemClass), | |
1566 | (GtkClassInitFunc) gtk_pixmap_menu_item_class_init, | |
1567 | (GtkObjectInitFunc) gtk_pixmap_menu_item_init, | |
1568 | /* reserved_1 */ NULL, | |
1569 | /* reserved_2 */ NULL, | |
1570 | (GtkClassInitFunc) NULL, | |
1571 | }; | |
1572 | ||
2368dcda | 1573 | pixmap_menu_item_type = gtk_type_unique (gtk_menu_item_get_type (), |
8f262dc5 | 1574 | &pixmap_menu_item_info); |
37d403aa JS |
1575 | } |
1576 | ||
1577 | return pixmap_menu_item_type; | |
1578 | } | |
1579 | ||
1580 | /** | |
1581 | * gtk_pixmap_menu_item_new | |
1582 | * | |
2368dcda | 1583 | * Creates a new pixmap menu item. Use gtk_pixmap_menu_item_set_pixmap() |
37d403aa JS |
1584 | * to set the pixmap wich is displayed at the left side. |
1585 | * | |
1586 | * Returns: | |
1587 | * &GtkWidget pointer to new menu item | |
1588 | **/ | |
1589 | ||
1590 | GtkWidget* | |
1591 | gtk_pixmap_menu_item_new (void) | |
1592 | { | |
1593 | return GTK_WIDGET (gtk_type_new (gtk_pixmap_menu_item_get_type ())); | |
1594 | } | |
1595 | ||
1596 | static void | |
1597 | gtk_pixmap_menu_item_class_init (GtkPixmapMenuItemClass *klass) | |
1598 | { | |
1599 | GtkObjectClass *object_class; | |
1600 | GtkWidgetClass *widget_class; | |
1601 | GtkMenuItemClass *menu_item_class; | |
1602 | GtkContainerClass *container_class; | |
1603 | ||
1604 | object_class = (GtkObjectClass*) klass; | |
1605 | widget_class = (GtkWidgetClass*) klass; | |
1606 | menu_item_class = (GtkMenuItemClass*) klass; | |
1607 | container_class = (GtkContainerClass*) klass; | |
1608 | ||
1609 | parent_class = (GtkMenuItemClass*) gtk_type_class (gtk_menu_item_get_type ()); | |
1610 | ||
1611 | widget_class->draw = gtk_pixmap_menu_item_draw; | |
1612 | widget_class->expose_event = gtk_pixmap_menu_item_expose; | |
1613 | widget_class->map = gtk_pixmap_menu_item_map; | |
1614 | widget_class->size_allocate = gtk_pixmap_menu_item_size_allocate; | |
1615 | widget_class->size_request = gtk_pixmap_menu_item_size_request; | |
1616 | ||
1617 | container_class->forall = gtk_pixmap_menu_item_forall; | |
1618 | container_class->remove = gtk_pixmap_menu_item_remove; | |
1619 | ||
1620 | klass->orig_toggle_size = menu_item_class->toggle_size; | |
1621 | klass->have_pixmap_count = 0; | |
1622 | } | |
1623 | ||
1624 | static void | |
1625 | gtk_pixmap_menu_item_init (GtkPixmapMenuItem *menu_item) | |
1626 | { | |
1627 | GtkMenuItem *mi; | |
1628 | ||
1629 | mi = GTK_MENU_ITEM (menu_item); | |
1630 | ||
1631 | menu_item->pixmap = NULL; | |
1632 | } | |
1633 | ||
1634 | static void | |
1635 | gtk_pixmap_menu_item_draw (GtkWidget *widget, | |
8f262dc5 | 1636 | GdkRectangle *area) |
37d403aa JS |
1637 | { |
1638 | g_return_if_fail (widget != NULL); | |
1639 | g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (widget)); | |
1640 | g_return_if_fail (area != NULL); | |
1641 | ||
1642 | if (GTK_WIDGET_CLASS (parent_class)->draw) | |
1643 | (* GTK_WIDGET_CLASS (parent_class)->draw) (widget, area); | |
1644 | ||
2368dcda | 1645 | if (GTK_WIDGET_DRAWABLE (widget) && |
37d403aa JS |
1646 | GTK_PIXMAP_MENU_ITEM(widget)->pixmap) { |
1647 | gtk_widget_draw(GTK_WIDGET(GTK_PIXMAP_MENU_ITEM(widget)->pixmap),NULL); | |
1648 | } | |
1649 | } | |
1650 | ||
1651 | static gint | |
1652 | gtk_pixmap_menu_item_expose (GtkWidget *widget, | |
8f262dc5 | 1653 | GdkEventExpose *event) |
37d403aa JS |
1654 | { |
1655 | g_return_val_if_fail (widget != NULL, FALSE); | |
1656 | g_return_val_if_fail (GTK_IS_PIXMAP_MENU_ITEM (widget), FALSE); | |
1657 | g_return_val_if_fail (event != NULL, FALSE); | |
1658 | ||
1659 | if (GTK_WIDGET_CLASS (parent_class)->expose_event) | |
1660 | (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); | |
1661 | ||
2368dcda | 1662 | if (GTK_WIDGET_DRAWABLE (widget) && |
37d403aa JS |
1663 | GTK_PIXMAP_MENU_ITEM(widget)->pixmap) { |
1664 | gtk_widget_draw(GTK_WIDGET(GTK_PIXMAP_MENU_ITEM(widget)->pixmap),NULL); | |
1665 | } | |
1666 | ||
1667 | return FALSE; | |
1668 | } | |
1669 | ||
1670 | /** | |
1671 | * gtk_pixmap_menu_item_set_pixmap | |
1672 | * @menu_item: Pointer to the pixmap menu item | |
1673 | * @pixmap: Pointer to a pixmap widget | |
1674 | * | |
1675 | * Set the pixmap of the menu item. | |
1676 | * | |
1677 | **/ | |
1678 | ||
1679 | void | |
1680 | gtk_pixmap_menu_item_set_pixmap (GtkPixmapMenuItem *menu_item, | |
8f262dc5 | 1681 | GtkWidget *pixmap) |
37d403aa JS |
1682 | { |
1683 | g_return_if_fail (menu_item != NULL); | |
1684 | g_return_if_fail (pixmap != NULL); | |
1685 | g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (menu_item)); | |
1686 | g_return_if_fail (GTK_IS_WIDGET (pixmap)); | |
1687 | g_return_if_fail (menu_item->pixmap == NULL); | |
1688 | ||
1689 | gtk_widget_set_parent (pixmap, GTK_WIDGET (menu_item)); | |
1690 | menu_item->pixmap = pixmap; | |
1691 | ||
1692 | if (GTK_WIDGET_REALIZED (pixmap->parent) && | |
1693 | !GTK_WIDGET_REALIZED (pixmap)) | |
1694 | gtk_widget_realize (pixmap); | |
2368dcda VZ |
1695 | |
1696 | if (GTK_WIDGET_VISIBLE (pixmap->parent)) { | |
37d403aa | 1697 | if (GTK_WIDGET_MAPPED (pixmap->parent) && |
8f262dc5 | 1698 | GTK_WIDGET_VISIBLE(pixmap) && |
37d403aa JS |
1699 | !GTK_WIDGET_MAPPED (pixmap)) |
1700 | gtk_widget_map (pixmap); | |
1701 | } | |
1702 | ||
1703 | changed_have_pixmap_status(menu_item); | |
2368dcda | 1704 | |
37d403aa JS |
1705 | if (GTK_WIDGET_VISIBLE (pixmap) && GTK_WIDGET_VISIBLE (menu_item)) |
1706 | gtk_widget_queue_resize (pixmap); | |
1707 | } | |
1708 | ||
1709 | static void | |
1710 | gtk_pixmap_menu_item_map (GtkWidget *widget) | |
1711 | { | |
1712 | GtkPixmapMenuItem *menu_item; | |
1713 | ||
1714 | g_return_if_fail (widget != NULL); | |
1715 | g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (widget)); | |
1716 | ||
1717 | menu_item = GTK_PIXMAP_MENU_ITEM(widget); | |
1718 | ||
1719 | GTK_WIDGET_CLASS(parent_class)->map(widget); | |
1720 | ||
1721 | if (menu_item->pixmap && | |
1722 | GTK_WIDGET_VISIBLE (menu_item->pixmap) && | |
1723 | !GTK_WIDGET_MAPPED (menu_item->pixmap)) | |
1724 | gtk_widget_map (menu_item->pixmap); | |
1725 | } | |
1726 | ||
1727 | static void | |
1728 | gtk_pixmap_menu_item_size_allocate (GtkWidget *widget, | |
8f262dc5 | 1729 | GtkAllocation *allocation) |
37d403aa JS |
1730 | { |
1731 | GtkPixmapMenuItem *pmenu_item; | |
1732 | ||
1733 | pmenu_item = GTK_PIXMAP_MENU_ITEM(widget); | |
1734 | ||
1735 | if (pmenu_item->pixmap && GTK_WIDGET_VISIBLE(pmenu_item)) | |
1736 | { | |
1737 | GtkAllocation child_allocation; | |
1738 | int border_width; | |
1739 | ||
1740 | border_width = GTK_CONTAINER (widget)->border_width; | |
1741 | ||
1742 | child_allocation.width = pmenu_item->pixmap->requisition.width; | |
1743 | child_allocation.height = pmenu_item->pixmap->requisition.height; | |
1744 | child_allocation.x = border_width + BORDER_SPACING; | |
1745 | child_allocation.y = (border_width + BORDER_SPACING | |
8f262dc5 VZ |
1746 | + (((allocation->height - child_allocation.height) - child_allocation.x) |
1747 | / 2)); /* center pixmaps vertically */ | |
37d403aa JS |
1748 | gtk_widget_size_allocate (pmenu_item->pixmap, &child_allocation); |
1749 | } | |
1750 | ||
1751 | if (GTK_WIDGET_CLASS (parent_class)->size_allocate) | |
1752 | GTK_WIDGET_CLASS(parent_class)->size_allocate (widget, allocation); | |
1753 | } | |
1754 | ||
1755 | static void | |
1756 | gtk_pixmap_menu_item_forall (GtkContainer *container, | |
8f262dc5 VZ |
1757 | gboolean include_internals, |
1758 | GtkCallback callback, | |
1759 | gpointer callback_data) | |
37d403aa JS |
1760 | { |
1761 | GtkPixmapMenuItem *menu_item; | |
1762 | ||
1763 | g_return_if_fail (container != NULL); | |
1764 | g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (container)); | |
1765 | g_return_if_fail (callback != NULL); | |
1766 | ||
1767 | menu_item = GTK_PIXMAP_MENU_ITEM (container); | |
1768 | ||
1769 | if (menu_item->pixmap) | |
1770 | (* callback) (menu_item->pixmap, callback_data); | |
1771 | ||
1772 | GTK_CONTAINER_CLASS(parent_class)->forall(container,include_internals, | |
8f262dc5 | 1773 | callback,callback_data); |
37d403aa JS |
1774 | } |
1775 | ||
1776 | static void | |
1777 | gtk_pixmap_menu_item_size_request (GtkWidget *widget, | |
8f262dc5 | 1778 | GtkRequisition *requisition) |
37d403aa JS |
1779 | { |
1780 | GtkPixmapMenuItem *menu_item; | |
1781 | GtkRequisition req = {0, 0}; | |
1782 | ||
1783 | g_return_if_fail (widget != NULL); | |
1784 | g_return_if_fail (GTK_IS_MENU_ITEM (widget)); | |
1785 | g_return_if_fail (requisition != NULL); | |
1786 | ||
1787 | GTK_WIDGET_CLASS(parent_class)->size_request(widget,requisition); | |
1788 | ||
1789 | menu_item = GTK_PIXMAP_MENU_ITEM (widget); | |
2368dcda | 1790 | |
37d403aa JS |
1791 | if (menu_item->pixmap) |
1792 | gtk_widget_size_request(menu_item->pixmap, &req); | |
1793 | ||
1794 | requisition->height = MAX(req.height + GTK_CONTAINER(widget)->border_width + BORDER_SPACING, (unsigned int) requisition->height); | |
1795 | requisition->width += (req.width + GTK_CONTAINER(widget)->border_width + BORDER_SPACING); | |
1796 | } | |
1797 | ||
1798 | static void | |
1799 | gtk_pixmap_menu_item_remove (GtkContainer *container, | |
8f262dc5 | 1800 | GtkWidget *child) |
37d403aa JS |
1801 | { |
1802 | GtkBin *bin; | |
1803 | gboolean widget_was_visible; | |
1804 | ||
1805 | g_return_if_fail (container != NULL); | |
1806 | g_return_if_fail (GTK_IS_PIXMAP_MENU_ITEM (container)); | |
1807 | g_return_if_fail (child != NULL); | |
1808 | g_return_if_fail (GTK_IS_WIDGET (child)); | |
1809 | ||
1810 | bin = GTK_BIN (container); | |
2368dcda | 1811 | g_return_if_fail ((bin->child == child || |
8f262dc5 | 1812 | (GTK_PIXMAP_MENU_ITEM(container)->pixmap == child))); |
37d403aa JS |
1813 | |
1814 | widget_was_visible = GTK_WIDGET_VISIBLE (child); | |
2368dcda | 1815 | |
37d403aa JS |
1816 | gtk_widget_unparent (child); |
1817 | if (bin->child == child) | |
2368dcda | 1818 | bin->child = NULL; |
37d403aa JS |
1819 | else { |
1820 | GTK_PIXMAP_MENU_ITEM(container)->pixmap = NULL; | |
1821 | changed_have_pixmap_status(GTK_PIXMAP_MENU_ITEM(container)); | |
1822 | } | |
2368dcda | 1823 | |
37d403aa JS |
1824 | if (widget_was_visible) |
1825 | gtk_widget_queue_resize (GTK_WIDGET (container)); | |
1826 | } | |
1827 | ||
1828 | ||
1829 | /* important to only call this if there was actually a _change_ in pixmap == NULL */ | |
1830 | static void | |
1831 | changed_have_pixmap_status (GtkPixmapMenuItem *menu_item) | |
1832 | { | |
1833 | if (menu_item->pixmap != NULL) { | |
1834 | GTK_PIXMAP_MENU_ITEM_GET_CLASS(menu_item)->have_pixmap_count += 1; | |
1835 | ||
1836 | if (GTK_PIXMAP_MENU_ITEM_GET_CLASS(menu_item)->have_pixmap_count == 1) { | |
1837 | /* Install pixmap toggle size */ | |
1838 | GTK_MENU_ITEM_GET_CLASS(menu_item)->toggle_size = MAX(GTK_PIXMAP_MENU_ITEM_GET_CLASS(menu_item)->orig_toggle_size, PMAP_WIDTH); | |
1839 | } | |
1840 | } else { | |
1841 | GTK_PIXMAP_MENU_ITEM_GET_CLASS(menu_item)->have_pixmap_count -= 1; | |
1842 | ||
1843 | if (GTK_PIXMAP_MENU_ITEM_GET_CLASS(menu_item)->have_pixmap_count == 0) { | |
1844 | /* Install normal toggle size */ | |
2368dcda | 1845 | GTK_MENU_ITEM_GET_CLASS(menu_item)->toggle_size = GTK_PIXMAP_MENU_ITEM_GET_CLASS(menu_item)->orig_toggle_size; |
37d403aa JS |
1846 | } |
1847 | } | |
1848 | ||
1849 | /* Note that we actually need to do this for _all_ GtkPixmapMenuItem | |
1850 | whenever the klass->toggle_size changes; but by doing it anytime | |
1851 | this function is called, we get the same effect, just because of | |
1852 | how the preferences option to show pixmaps works. Bogus, broken. | |
1853 | */ | |
2368dcda | 1854 | if (GTK_WIDGET_VISIBLE(GTK_WIDGET(menu_item))) |
37d403aa JS |
1855 | gtk_widget_queue_resize(GTK_WIDGET(menu_item)); |
1856 | } | |
1857 | ||
9e691f46 | 1858 | #endif // USE_MENU_BITMAPS |
37d403aa | 1859 |