]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/gtkutil/accelerator.h
Propagate ui::Window
[xonotic/netradiant.git] / libs / gtkutil / accelerator.h
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 #if !defined( INCLUDED_GTKUTIL_ACCELERATOR_H )
23 #define INCLUDED_GTKUTIL_ACCELERATOR_H
24
25 #include <uilib/uilib.h>
26 #include <gdk/gdk.h>
27
28 #include "generic/callback.h"
29
30 // ignore numlock
31 #define ALLOWED_MODIFIERS ( ~( GDK_MOD2_MASK | GDK_LOCK_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK | GDK_MOD5_MASK ) )
32
33 struct Accelerator
34 {
35         Accelerator( guint _key )
36                 : key( gdk_keyval_to_upper( _key ) ), modifiers( ( GdkModifierType ) 0 ){
37         }
38         Accelerator( guint _key, GdkModifierType _modifiers )
39                 : key( gdk_keyval_to_upper( _key ) ), modifiers( ( GdkModifierType )( _modifiers & ALLOWED_MODIFIERS ) ){
40         }
41         Accelerator( const Accelerator &src )
42                 : key( gdk_keyval_to_upper( src.key ) ), modifiers( ( GdkModifierType )( src.modifiers & ALLOWED_MODIFIERS ) ){
43         }
44         bool operator<( const Accelerator& other ) const {
45                 guint k1 = key;
46                 guint k2 = other.key;
47                 int mod1 = modifiers & ALLOWED_MODIFIERS;
48                 int mod2 = other.modifiers & ALLOWED_MODIFIERS;
49                 return k1 < k2 || ( !( k2 < k1 ) && mod1 < mod2 );
50         }
51         bool operator==( const Accelerator& other ) const {
52                 guint k1 = key;
53                 guint k2 = other.key;
54                 int mod1 = modifiers & ALLOWED_MODIFIERS;
55                 int mod2 = other.modifiers & ALLOWED_MODIFIERS;
56                 return k1 == k2 && mod1 == mod2;
57         }
58         Accelerator &operator=( const Accelerator& other ){
59                 key = other.key;
60                 modifiers = (GdkModifierType) ( other.modifiers & ALLOWED_MODIFIERS );
61                 return *this;
62         }
63         guint key;
64         GdkModifierType modifiers;
65 };
66
67 inline Accelerator accelerator_null(){
68         return Accelerator( 0, (GdkModifierType)0 );
69 }
70
71 const char* global_keys_find( unsigned int key );
72 unsigned int global_keys_find( const char* name );
73
74 class TextOutputStream;
75 void accelerator_write( const Accelerator& accelerator, TextOutputStream& ostream );
76
77 template<typename TextOutputStreamType>
78 TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const Accelerator& accelerator ){
79         accelerator_write( accelerator, ostream );
80         return ostream;
81 }
82
83 void keydown_accelerators_add( Accelerator accelerator, const Callback& callback );
84 void keydown_accelerators_remove( Accelerator accelerator );
85 void keyup_accelerators_add( Accelerator accelerator, const Callback& callback );
86 void keyup_accelerators_remove( Accelerator accelerator );
87
88 typedef struct _GtkWidget GtkWidget;
89 void global_accel_connect_window( ui::Window window );
90 void global_accel_disconnect_window( ui::Window window );
91
92 void GlobalPressedKeys_releaseAll();
93
94 extern ui::AccelGroup global_accel;
95
96 GClosure* global_accel_group_find( Accelerator accelerator );
97
98 void global_accel_group_connect( const Accelerator& accelerator, const Callback& callback );
99 void global_accel_group_disconnect( const Accelerator& accelerator, const Callback& callback );
100
101
102 class Command
103 {
104 public:
105 Callback m_callback;
106 const Accelerator& m_accelerator;
107 Command( const Callback& callback, const Accelerator& accelerator ) : m_callback( callback ), m_accelerator( accelerator ){
108 }
109 };
110
111 class Toggle
112 {
113 public:
114 Command m_command;
115 BoolExportCallback m_exportCallback;
116 Toggle( const Callback& callback, const Accelerator& accelerator, const BoolExportCallback& exportCallback ) : m_command( callback, accelerator ), m_exportCallback( exportCallback ){
117 }
118 };
119
120 class KeyEvent
121 {
122 public:
123 const Accelerator& m_accelerator;
124 Callback m_keyDown;
125 Callback m_keyUp;
126 KeyEvent( const Accelerator& accelerator, const Callback& keyDown, const Callback& keyUp ) : m_accelerator( accelerator ), m_keyDown( keyDown ), m_keyUp( keyUp ){
127 }
128 };
129
130
131
132 struct PressedButtons;
133 typedef struct _GtkWidget GtkWidget;
134 void PressedButtons_connect( PressedButtons& pressedButtons, GtkWidget* widget );
135
136 extern PressedButtons g_pressedButtons;
137
138 #endif