fcac228acce1fc3b205afd613940f37a440b0ddd
[xonotic/netradiant.git] / libs / gtkutil / accelerator.cpp
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #include "accelerator.h"
23
24 #include "debugging/debugging.h"
25
26 #include <map>
27 #include <set>
28 #include <gtk/gtk.h>
29
30 #include "generic/callback.h"
31 #include "generic/bitfield.h"
32 #include "string/string.h"
33
34 #include "pointer.h"
35 #include "closure.h"
36
37 #include <gdk/gdkkeysyms.h>
38
39
40
41 const char* global_keys_find( unsigned int key ){
42         const char *s;
43         if ( key == 0 ) {
44                 return "";
45         }
46         s = gdk_keyval_name( key );
47         if ( !s ) {
48                 return "";
49         }
50         return s;
51 }
52
53 unsigned int global_keys_find( const char* name ){
54         guint k;
55         if ( !name || !*name ) {
56                 return 0;
57         }
58         k = gdk_keyval_from_name( name );
59         if ( k == GDK_KEY_VoidSymbol ) {
60                 return 0;
61         }
62         return k;
63 }
64
65 void accelerator_write( const Accelerator& accelerator, TextOutputStream& ostream ){
66 #if 0
67         if ( accelerator.modifiers & GDK_SHIFT_MASK ) {
68                 ostream << "Shift + ";
69         }
70         if ( accelerator.modifiers & GDK_MOD1_MASK ) {
71                 ostream << "Alt + ";
72         }
73         if ( accelerator.modifiers & GDK_CONTROL_MASK ) {
74                 ostream << "Control + ";
75         }
76
77         const char* keyName = global_keys_find( accelerator.key );
78         if ( !string_empty( keyName ) ) {
79                 ostream << keyName;
80         }
81         else
82         {
83                 ostream << static_cast<char>( accelerator.key );
84         }
85 #endif
86         ostream << gtk_accelerator_get_label( accelerator.key, accelerator.modifiers );
87 }
88
89 typedef std::map<Accelerator, Callback> AcceleratorMap;
90 typedef std::set<Accelerator> AcceleratorSet;
91
92 bool accelerator_map_insert( AcceleratorMap& acceleratorMap, Accelerator accelerator, const Callback& callback ){
93         if ( accelerator.key != 0 ) {
94                 return acceleratorMap.insert( AcceleratorMap::value_type( accelerator, callback ) ).second;
95         }
96         return true;
97 }
98
99 bool accelerator_map_erase( AcceleratorMap& acceleratorMap, Accelerator accelerator ){
100         if ( accelerator.key != 0 ) {
101                 AcceleratorMap::iterator i = acceleratorMap.find( accelerator );
102                 if ( i == acceleratorMap.end() ) {
103                         return false;
104                 }
105                 acceleratorMap.erase( i );
106         }
107         return true;
108 }
109
110 Accelerator accelerator_for_event_key( guint keyval, guint state ){
111         keyval = gdk_keyval_to_upper( keyval );
112         if ( keyval == GDK_KEY_ISO_Left_Tab ) {
113                 keyval = GDK_KEY_Tab;
114         }
115         return Accelerator( keyval, (GdkModifierType)( state & gtk_accelerator_get_default_mod_mask() ) );
116 }
117
118 bool AcceleratorMap_activate( const AcceleratorMap& acceleratorMap, const Accelerator& accelerator ){
119         AcceleratorMap::const_iterator i = acceleratorMap.find( accelerator );
120         if ( i != acceleratorMap.end() ) {
121                 ( *i ).second();
122                 return true;
123         }
124
125         return false;
126 }
127
128 static gboolean accelerator_key_event( ui::Window window, GdkEventKey* event, AcceleratorMap* acceleratorMap ){
129         return AcceleratorMap_activate( *acceleratorMap, accelerator_for_event_key( event->keyval, event->state ) );
130 }
131
132
133 AcceleratorMap g_special_accelerators;
134
135
136 namespace MouseButton
137 {
138 enum
139 {
140         Left = 1 << 0,
141         Right = 1 << 1,
142         Middle = 1 << 2,
143 };
144 }
145
146 typedef unsigned int ButtonMask;
147
148 void print_buttons( ButtonMask mask ){
149         globalOutputStream() << "button state: ";
150         if ( ( mask & MouseButton::Left ) != 0 ) {
151                 globalOutputStream() << "Left ";
152         }
153         if ( ( mask & MouseButton::Right ) != 0 ) {
154                 globalOutputStream() << "Right ";
155         }
156         if ( ( mask & MouseButton::Middle ) != 0 ) {
157                 globalOutputStream() << "Middle ";
158         }
159         globalOutputStream() << "\n";
160 }
161
162 ButtonMask ButtonMask_for_event_button( guint button ){
163         switch ( button )
164         {
165         case 1:
166                 return MouseButton::Left;
167         case 2:
168                 return MouseButton::Middle;
169         case 3:
170                 return MouseButton::Right;
171         }
172         return 0;
173 }
174
175 bool window_has_accel( ui::Window toplevel ){
176         return g_slist_length( gtk_accel_groups_from_object( G_OBJECT( toplevel ) ) ) != 0;
177 }
178
179 namespace
180 {
181 bool g_accel_enabled = true;
182 }
183
184 bool global_accel_enabled(){
185         return g_accel_enabled;
186 }
187
188
189 GClosure* accel_group_add_accelerator( GtkAccelGroup* group, Accelerator accelerator, const Callback& callback );
190 void accel_group_remove_accelerator( GtkAccelGroup* group, Accelerator accelerator );
191
192 AcceleratorMap g_queuedAcceleratorsAdd;
193 AcceleratorSet g_queuedAcceleratorsRemove;
194
195 void globalQueuedAccelerators_add( Accelerator accelerator, const Callback& callback ){
196         if ( !g_queuedAcceleratorsAdd.insert( AcceleratorMap::value_type( accelerator, callback ) ).second ) {
197                 globalErrorStream() << "globalQueuedAccelerators_add: accelerator already queued: " << accelerator << "\n";
198         }
199 }
200
201 void globalQueuedAccelerators_remove( Accelerator accelerator ){
202         if ( g_queuedAcceleratorsAdd.erase( accelerator ) == 0 ) {
203                 if ( !g_queuedAcceleratorsRemove.insert( accelerator ).second ) {
204                         globalErrorStream() << "globalQueuedAccelerators_remove: accelerator already queued: " << accelerator << "\n";
205                 }
206         }
207 }
208
209 void globalQueuedAccelerators_commit(){
210         for ( AcceleratorSet::const_iterator i = g_queuedAcceleratorsRemove.begin(); i != g_queuedAcceleratorsRemove.end(); ++i )
211         {
212                 //globalOutputStream() << "removing: " << (*i).first << "\n";
213                 accel_group_remove_accelerator( global_accel, *i );
214         }
215         g_queuedAcceleratorsRemove.clear();
216         for ( AcceleratorMap::const_iterator i = g_queuedAcceleratorsAdd.begin(); i != g_queuedAcceleratorsAdd.end(); ++i )
217         {
218                 //globalOutputStream() << "adding: " << (*i).first << "\n";
219                 accel_group_add_accelerator( global_accel, ( *i ).first, ( *i ).second );
220         }
221         g_queuedAcceleratorsAdd.clear();
222 }
223
224 typedef std::set<ui::Window> WindowSet;
225 WindowSet g_accel_windows;
226
227 bool Buttons_press( ButtonMask& buttons, guint button, guint state ){
228         if ( buttons == 0 && bitfield_enable( buttons, ButtonMask_for_event_button( button ) ) != 0 ) {
229                 ASSERT_MESSAGE( g_accel_enabled, "Buttons_press: accelerators not enabled" );
230                 g_accel_enabled = false;
231                 for ( WindowSet::iterator i = g_accel_windows.begin(); i != g_accel_windows.end(); ++i )
232                 {
233                         ui::Window toplevel = *i;
234                         ASSERT_MESSAGE( window_has_accel( toplevel ), "ERROR" );
235                         ASSERT_MESSAGE( gtk_widget_is_toplevel( GTK_WIDGET(toplevel) ), "disabling accel for non-toplevel window" );
236                         gtk_window_remove_accel_group( toplevel,  global_accel );
237 #if 0
238                         globalOutputStream() << reinterpret_cast<unsigned int>( toplevel ) << ": disabled global accelerators\n";
239 #endif
240                 }
241         }
242         buttons = bitfield_enable( buttons, ButtonMask_for_event_button( button ) );
243 #if 0
244         globalOutputStream() << "Buttons_press: ";
245         print_buttons( buttons );
246 #endif
247         return false;
248 }
249
250 bool Buttons_release( ButtonMask& buttons, guint button, guint state ){
251         if ( buttons != 0 && bitfield_disable( buttons, ButtonMask_for_event_button( button ) ) == 0 ) {
252                 ASSERT_MESSAGE( !g_accel_enabled, "Buttons_release: accelerators are enabled" );
253                 g_accel_enabled = true;
254                 for ( WindowSet::iterator i = g_accel_windows.begin(); i != g_accel_windows.end(); ++i )
255                 {
256                         ui::Window toplevel = *i;
257                         ASSERT_MESSAGE( !window_has_accel( toplevel ), "ERROR" );
258                         ASSERT_MESSAGE( gtk_widget_is_toplevel( GTK_WIDGET(toplevel) ), "enabling accel for non-toplevel window" );
259                         toplevel.add_accel_group( global_accel );
260 #if 0
261                         globalOutputStream() << reinterpret_cast<unsigned int>( toplevel ) << ": enabled global accelerators\n";
262 #endif
263                 }
264                 globalQueuedAccelerators_commit();
265         }
266         buttons = bitfield_disable( buttons, ButtonMask_for_event_button( button ) );
267 #if 0
268         globalOutputStream() << "Buttons_release: ";
269         print_buttons( buttons );
270 #endif
271         return false;
272 }
273
274 bool Buttons_releaseAll( ButtonMask& buttons ){
275         Buttons_release( buttons, MouseButton::Left | MouseButton::Middle | MouseButton::Right, 0 );
276         return false;
277 }
278
279 struct PressedButtons
280 {
281         ButtonMask buttons;
282
283         PressedButtons() : buttons( 0 ){
284         }
285 };
286
287 gboolean PressedButtons_button_press( GtkWidget* widget, GdkEventButton* event, PressedButtons* pressed ){
288         if ( event->type == GDK_BUTTON_PRESS ) {
289                 return Buttons_press( pressed->buttons, event->button, event->state );
290         }
291         return FALSE;
292 }
293
294 gboolean PressedButtons_button_release( GtkWidget* widget, GdkEventButton* event, PressedButtons* pressed ){
295         if ( event->type == GDK_BUTTON_RELEASE ) {
296                 return Buttons_release( pressed->buttons, event->button, event->state );
297         }
298         return FALSE;
299 }
300
301 gboolean PressedButtons_focus_out( GtkWidget* widget, GdkEventFocus* event, PressedButtons* pressed ){
302         Buttons_releaseAll( pressed->buttons );
303         return FALSE;
304 }
305
306 void PressedButtons_connect( PressedButtons& pressedButtons, ui::Widget widget ){
307         widget.connect( "button_press_event", G_CALLBACK( PressedButtons_button_press ), &pressedButtons );
308         widget.connect( "button_release_event", G_CALLBACK( PressedButtons_button_release ), &pressedButtons );
309         widget.connect( "focus_out_event", G_CALLBACK( PressedButtons_focus_out ), &pressedButtons );
310 }
311
312 PressedButtons g_pressedButtons;
313
314
315 #include <set>
316 #include <uilib/uilib.h>
317
318 struct PressedKeys
319 {
320         typedef std::set<guint> Keys;
321         Keys keys;
322         std::size_t refcount;
323
324         PressedKeys() : refcount( 0 ){
325         }
326 };
327
328 AcceleratorMap g_keydown_accelerators;
329 AcceleratorMap g_keyup_accelerators;
330
331 bool Keys_press( PressedKeys::Keys& keys, guint keyval ){
332         if ( keys.insert( keyval ).second ) {
333                 return AcceleratorMap_activate( g_keydown_accelerators, accelerator_for_event_key( keyval, 0 ) );
334         }
335         return g_keydown_accelerators.find( accelerator_for_event_key( keyval, 0 ) ) != g_keydown_accelerators.end();
336 }
337
338 bool Keys_release( PressedKeys::Keys& keys, guint keyval ){
339         if ( keys.erase( keyval ) != 0 ) {
340                 return AcceleratorMap_activate( g_keyup_accelerators, accelerator_for_event_key( keyval, 0 ) );
341         }
342         return g_keyup_accelerators.find( accelerator_for_event_key( keyval, 0 ) ) != g_keyup_accelerators.end();
343 }
344
345 void Keys_releaseAll( PressedKeys::Keys& keys, guint state ){
346         for ( PressedKeys::Keys::iterator i = keys.begin(); i != keys.end(); ++i )
347         {
348                 AcceleratorMap_activate( g_keyup_accelerators, accelerator_for_event_key( *i, state ) );
349         }
350         keys.clear();
351 }
352
353 gboolean PressedKeys_key_press( GtkWidget* widget, GdkEventKey* event, PressedKeys* pressedKeys ){
354         //globalOutputStream() << "pressed: " << event->keyval << "\n";
355         return event->state == 0 && Keys_press( pressedKeys->keys, event->keyval );
356 }
357
358 gboolean PressedKeys_key_release( GtkWidget* widget, GdkEventKey* event, PressedKeys* pressedKeys ){
359         //globalOutputStream() << "released: " << event->keyval << "\n";
360         return Keys_release( pressedKeys->keys, event->keyval );
361 }
362
363 gboolean PressedKeys_focus_in( GtkWidget* widget, GdkEventFocus* event, PressedKeys* pressedKeys ){
364         ++pressedKeys->refcount;
365         return FALSE;
366 }
367
368 gboolean PressedKeys_focus_out( GtkWidget* widget, GdkEventFocus* event, PressedKeys* pressedKeys ){
369         if ( --pressedKeys->refcount == 0 ) {
370                 Keys_releaseAll( pressedKeys->keys, 0 );
371         }
372         return FALSE;
373 }
374
375 PressedKeys g_pressedKeys;
376
377 void GlobalPressedKeys_releaseAll(){
378         Keys_releaseAll( g_pressedKeys.keys, 0 );
379 }
380
381 void GlobalPressedKeys_connect( ui::Window window ){
382         unsigned int key_press_handler = window.connect( "key_press_event", G_CALLBACK( PressedKeys_key_press ), &g_pressedKeys );
383         unsigned int key_release_handler = window.connect( "key_release_event", G_CALLBACK( PressedKeys_key_release ), &g_pressedKeys );
384         g_object_set_data( G_OBJECT( window ), "key_press_handler", gint_to_pointer( key_press_handler ) );
385         g_object_set_data( G_OBJECT( window ), "key_release_handler", gint_to_pointer( key_release_handler ) );
386         unsigned int focus_in_handler = window.connect( "focus_in_event", G_CALLBACK( PressedKeys_focus_in ), &g_pressedKeys );
387         unsigned int focus_out_handler = window.connect( "focus_out_event", G_CALLBACK( PressedKeys_focus_out ), &g_pressedKeys );
388         g_object_set_data( G_OBJECT( window ), "focus_in_handler", gint_to_pointer( focus_in_handler ) );
389         g_object_set_data( G_OBJECT( window ), "focus_out_handler", gint_to_pointer( focus_out_handler ) );
390 }
391
392 void GlobalPressedKeys_disconnect( ui::Window window ){
393         g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "key_press_handler" ) ) );
394         g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "key_release_handler" ) ) );
395         g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "focus_in_handler" ) ) );
396         g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "focus_out_handler" ) ) );
397 }
398
399
400
401 void special_accelerators_add( Accelerator accelerator, const Callback& callback ){
402         //globalOutputStream() << "special_accelerators_add: " << makeQuoted(accelerator) << "\n";
403         if ( !accelerator_map_insert( g_special_accelerators, accelerator, callback ) ) {
404                 globalErrorStream() << "special_accelerators_add: already exists: " << makeQuoted( accelerator ) << "\n";
405         }
406 }
407 void special_accelerators_remove( Accelerator accelerator ){
408         //globalOutputStream() << "special_accelerators_remove: " << makeQuoted(accelerator) << "\n";
409         if ( !accelerator_map_erase( g_special_accelerators, accelerator ) ) {
410                 globalErrorStream() << "special_accelerators_remove: not found: " << makeQuoted( accelerator ) << "\n";
411         }
412 }
413
414 void keydown_accelerators_add( Accelerator accelerator, const Callback& callback ){
415         //globalOutputStream() << "keydown_accelerators_add: " << makeQuoted(accelerator) << "\n";
416         if ( !accelerator_map_insert( g_keydown_accelerators, accelerator, callback ) ) {
417                 globalErrorStream() << "keydown_accelerators_add: already exists: " << makeQuoted( accelerator ) << "\n";
418         }
419 }
420 void keydown_accelerators_remove( Accelerator accelerator ){
421         //globalOutputStream() << "keydown_accelerators_remove: " << makeQuoted(accelerator) << "\n";
422         if ( !accelerator_map_erase( g_keydown_accelerators, accelerator ) ) {
423                 globalErrorStream() << "keydown_accelerators_remove: not found: " << makeQuoted( accelerator ) << "\n";
424         }
425 }
426
427 void keyup_accelerators_add( Accelerator accelerator, const Callback& callback ){
428         //globalOutputStream() << "keyup_accelerators_add: " << makeQuoted(accelerator) << "\n";
429         if ( !accelerator_map_insert( g_keyup_accelerators, accelerator, callback ) ) {
430                 globalErrorStream() << "keyup_accelerators_add: already exists: " << makeQuoted( accelerator ) << "\n";
431         }
432 }
433 void keyup_accelerators_remove( Accelerator accelerator ){
434         //globalOutputStream() << "keyup_accelerators_remove: " << makeQuoted(accelerator) << "\n";
435         if ( !accelerator_map_erase( g_keyup_accelerators, accelerator ) ) {
436                 globalErrorStream() << "keyup_accelerators_remove: not found: " << makeQuoted( accelerator ) << "\n";
437         }
438 }
439
440
441 gboolean accel_closure_callback( GtkAccelGroup* group, GtkWidget* widget, guint key, GdkModifierType modifiers, gpointer data ){
442         ( *reinterpret_cast<Callback*>( data ) )( );
443         return TRUE;
444 }
445
446 GClosure* accel_group_add_accelerator( GtkAccelGroup* group, Accelerator accelerator, const Callback& callback ){
447         if ( accelerator.key != 0 && gtk_accelerator_valid( accelerator.key, accelerator.modifiers ) ) {
448                 //globalOutputStream() << "global_accel_connect: " << makeQuoted(accelerator) << "\n";
449                 GClosure* closure = create_cclosure( G_CALLBACK( accel_closure_callback ), callback );
450                 gtk_accel_group_connect( group, accelerator.key, accelerator.modifiers, GTK_ACCEL_VISIBLE, closure );
451                 return closure;
452         }
453         else
454         {
455                 special_accelerators_add( accelerator, callback );
456                 return 0;
457         }
458 }
459
460 void accel_group_remove_accelerator( GtkAccelGroup* group, Accelerator accelerator ){
461         if ( accelerator.key != 0 && gtk_accelerator_valid( accelerator.key, accelerator.modifiers ) ) {
462                 //globalOutputStream() << "global_accel_disconnect: " << makeQuoted(accelerator) << "\n";
463                 gtk_accel_group_disconnect_key( group, accelerator.key, accelerator.modifiers );
464         }
465         else
466         {
467                 special_accelerators_remove( accelerator );
468         }
469 }
470
471 ui::AccelGroup global_accel{ui::New};
472
473 GClosure* global_accel_group_add_accelerator( Accelerator accelerator, const Callback& callback ){
474         if ( !global_accel_enabled() ) {
475                 // workaround: cannot add to GtkAccelGroup while it is disabled
476                 //globalOutputStream() << "queued for add: " << accelerator << "\n";
477                 globalQueuedAccelerators_add( accelerator, callback );
478                 return 0;
479         }
480         return accel_group_add_accelerator( global_accel, accelerator, callback );
481 }
482 void global_accel_group_remove_accelerator( Accelerator accelerator ){
483         if ( !global_accel_enabled() ) {
484                 //globalOutputStream() << "queued for remove: " << accelerator << "\n";
485                 globalQueuedAccelerators_remove( accelerator );
486                 return;
487         }
488         accel_group_remove_accelerator( global_accel, accelerator );
489 }
490
491 /// \brief Propagates key events to the focus-widget, overriding global accelerators.
492 static gboolean override_global_accelerators( ui::Window window, GdkEventKey* event, gpointer data ){
493         gboolean b = gtk_window_propagate_key_event( window, event );
494         return b;
495 }
496
497 void global_accel_connect_window( ui::Window window ){
498 #if 1
499         unsigned int override_handler = window.connect( "key_press_event", G_CALLBACK( override_global_accelerators ), 0 );
500         g_object_set_data( G_OBJECT( window ), "override_handler", gint_to_pointer( override_handler ) );
501
502         unsigned int special_key_press_handler = window.connect( "key_press_event", G_CALLBACK( accelerator_key_event ), &g_special_accelerators );
503         g_object_set_data( G_OBJECT( window ), "special_key_press_handler", gint_to_pointer( special_key_press_handler ) );
504
505         GlobalPressedKeys_connect( window );
506 #else
507         unsigned int key_press_handler = window.connect( "key_press_event", G_CALLBACK( accelerator_key_event ), &g_keydown_accelerators );
508         unsigned int key_release_handler = window.connect( "key_release_event", G_CALLBACK( accelerator_key_event ), &g_keyup_accelerators );
509         g_object_set_data( G_OBJECT( window ), "key_press_handler", gint_to_pointer( key_press_handler ) );
510         g_object_set_data( G_OBJECT( window ), "key_release_handler", gint_to_pointer( key_release_handler ) );
511 #endif
512         g_accel_windows.insert( window );
513         window.add_accel_group( global_accel );
514 }
515 void global_accel_disconnect_window( ui::Window window ){
516 #if 1
517         GlobalPressedKeys_disconnect( window );
518
519         g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "override_handler" ) ) );
520         g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "special_key_press_handler" ) ) );
521 #else
522         g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "key_press_handler" ) ) );
523         g_signal_handler_disconnect( G_OBJECT( window ), gpointer_to_int( g_object_get_data( G_OBJECT( window ), "key_release_handler" ) ) );
524 #endif
525         gtk_window_remove_accel_group( window, global_accel );
526         std::size_t count = g_accel_windows.erase( window );
527         ASSERT_MESSAGE( count == 1, "failed to remove accel group\n" );
528 }
529
530
531 GClosure* global_accel_group_find( Accelerator accelerator ){
532         guint numEntries = 0;
533         GtkAccelGroupEntry* entry = gtk_accel_group_query( global_accel, accelerator.key, accelerator.modifiers, &numEntries );
534         if ( numEntries != 0 ) {
535                 if ( numEntries != 1 ) {
536                         char* name = gtk_accelerator_name( accelerator.key, accelerator.modifiers );
537                         globalErrorStream() << "accelerator already in-use: " << name << "\n";
538                         g_free( name );
539                 }
540                 return entry->closure;
541         }
542         return 0;
543 }
544
545 void global_accel_group_connect( const Accelerator& accelerator, const Callback& callback ){
546         if ( accelerator.key != 0 ) {
547                 global_accel_group_add_accelerator( accelerator, callback );
548         }
549 }
550
551 void global_accel_group_disconnect( const Accelerator& accelerator, const Callback& callback ){
552         if ( accelerator.key != 0 ) {
553                 global_accel_group_remove_accelerator( accelerator );
554         }
555 }