2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
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.
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.
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
22 #if !defined( INCLUDED_GTKUTIL_ACCELERATOR_H )
23 #define INCLUDED_GTKUTIL_ACCELERATOR_H
25 #include <uilib/uilib.h>
28 #include "generic/callback.h"
32 #define ALLOWED_MODIFIERS ( ~( GDK_MOD2_MASK | GDK_LOCK_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK ) )
36 Accelerator( guint _key )
37 : key( gdk_keyval_to_upper( _key ) ), modifiers( ( GdkModifierType ) 0 ){
39 Accelerator( guint _key, GdkModifierType _modifiers )
40 : key( gdk_keyval_to_upper( _key ) ), modifiers( ( GdkModifierType )( _modifiers & ALLOWED_MODIFIERS ) ){
42 Accelerator( const Accelerator &src )
43 : key( gdk_keyval_to_upper( src.key ) ), modifiers( ( GdkModifierType )( src.modifiers & ALLOWED_MODIFIERS ) ){
45 bool operator<( const Accelerator& other ) const {
48 int mod1 = modifiers & ALLOWED_MODIFIERS;
49 int mod2 = other.modifiers & ALLOWED_MODIFIERS;
50 return k1 < k2 || ( !( k2 < k1 ) && mod1 < mod2 );
52 bool operator==( const Accelerator& other ) const {
55 int mod1 = modifiers & ALLOWED_MODIFIERS;
56 int mod2 = other.modifiers & ALLOWED_MODIFIERS;
57 return k1 == k2 && mod1 == mod2;
59 Accelerator &operator=( const Accelerator& other ){
61 modifiers = (GdkModifierType) ( other.modifiers & ALLOWED_MODIFIERS );
65 GdkModifierType modifiers;
68 inline Accelerator accelerator_null(){
69 return Accelerator( 0, (GdkModifierType)0 );
72 const char* global_keys_find( unsigned int key );
73 unsigned int global_keys_find( const char* name );
75 class TextOutputStream;
76 void accelerator_write( const Accelerator& accelerator, TextOutputStream& ostream );
78 template<typename TextOutputStreamType>
79 TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const Accelerator& accelerator ){
80 accelerator_write( accelerator, ostream );
84 void keydown_accelerators_add( Accelerator accelerator, const Callback<void()>& callback );
85 void keydown_accelerators_remove( Accelerator accelerator );
86 void keyup_accelerators_add( Accelerator accelerator, const Callback<void()>& callback );
87 void keyup_accelerators_remove( Accelerator accelerator );
89 void global_accel_connect_window( ui::Window window );
90 void global_accel_disconnect_window( ui::Window window );
92 void GlobalPressedKeys_releaseAll();
94 extern ui::AccelGroup global_accel;
96 GClosure* global_accel_group_find( Accelerator accelerator );
98 void global_accel_group_connect( const Accelerator& accelerator, const Callback<void()>& callback );
99 void global_accel_group_disconnect( const Accelerator& accelerator, const Callback<void()>& callback );
105 Callback<void()> m_callback;
106 const Accelerator& m_accelerator;
107 Command( const Callback<void()>& callback, const Accelerator& accelerator ) : m_callback( callback ), m_accelerator( accelerator ){
115 Callback<void(const Callback<void(bool)> &)> m_exportCallback;
116 Toggle( const Callback<void()>& callback, const Accelerator& accelerator, const Callback<void(const Callback<void(bool)> &)>& exportCallback ) : m_command( callback, accelerator ), m_exportCallback( exportCallback ){
123 const Accelerator& m_accelerator;
124 Callback<void()> m_keyDown;
125 Callback<void()> m_keyUp;
126 KeyEvent( const Accelerator& accelerator, const Callback<void()>& keyDown, const Callback<void()>& keyUp ) : m_accelerator( accelerator ), m_keyDown( keyDown ), m_keyUp( keyUp ){
132 struct PressedButtons;
133 void PressedButtons_connect( PressedButtons& pressedButtons, ui::Widget widget );
135 extern PressedButtons g_pressedButtons;