]> icculus.org git repositories - divverent/netradiant.git/blob - libs/gtkutil/accelerator.h
initial
[divverent/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 <gdk/gdktypes.h>
26 #include <gdk/gdkkeysyms.h>
27
28 #include "generic/callback.h"
29
30 struct Accelerator
31 {
32   Accelerator(guint _key)
33     : key(_key), modifiers((GdkModifierType)0)
34   {
35   }
36   Accelerator(guint _key, GdkModifierType _modifiers)
37     : key(_key), modifiers(_modifiers)
38   {
39   }
40   bool operator<(const Accelerator& other) const
41   {
42     return key < other.key || (!(other.key < key) && modifiers < other.modifiers);
43   }
44   guint key;
45   GdkModifierType modifiers;
46 };
47
48 inline Accelerator accelerator_null()
49 {
50   return Accelerator(0, (GdkModifierType)0);
51 }
52
53 const char* global_keys_find(unsigned int key);
54 unsigned int global_keys_find(const char* name);
55
56 class TextOutputStream;
57 void accelerator_write(const Accelerator& accelerator, TextOutputStream& ostream);
58
59 template<typename TextOutputStreamType>
60 TextOutputStreamType& ostream_write(TextOutputStreamType& ostream, const Accelerator& accelerator)
61 {
62   accelerator_write(accelerator, ostream);
63   return ostream;
64 }
65
66 void keydown_accelerators_add(Accelerator accelerator, const Callback& callback);
67 void keydown_accelerators_remove(Accelerator accelerator);
68 void keyup_accelerators_add(Accelerator accelerator, const Callback& callback);
69 void keyup_accelerators_remove(Accelerator accelerator);
70
71 typedef struct _GtkWidget GtkWidget;
72 typedef struct _GtkWindow GtkWindow;
73 void global_accel_connect_window(GtkWindow* window);
74 void global_accel_disconnect_window(GtkWindow* window);
75
76 void GlobalPressedKeys_releaseAll();
77
78 typedef struct _GtkAccelGroup GtkAccelGroup;
79 extern GtkAccelGroup* global_accel;
80 void global_accel_init();
81 void global_accel_destroy();
82
83 GClosure* global_accel_group_find(Accelerator accelerator);
84
85 void global_accel_group_connect(const Accelerator& accelerator, const Callback& callback);
86 void global_accel_group_disconnect(const Accelerator& accelerator, const Callback& callback);
87
88
89 class Command
90 {
91 public:
92   Callback m_callback;
93   const Accelerator& m_accelerator;
94   Command(const Callback& callback, const Accelerator& accelerator) : m_callback(callback), m_accelerator(accelerator)
95   {
96   }
97 };
98
99 class Toggle
100 {
101 public:
102   Command m_command;
103   BoolExportCallback m_exportCallback;
104   Toggle(const Callback& callback, const Accelerator& accelerator, const BoolExportCallback& exportCallback) : m_command(callback, accelerator), m_exportCallback(exportCallback)
105   {
106   }
107 };
108
109 class KeyEvent
110 {
111 public:
112   const Accelerator& m_accelerator;
113   Callback m_keyDown;
114   Callback m_keyUp;
115   KeyEvent(const Accelerator& accelerator, const Callback& keyDown, const Callback& keyUp) : m_accelerator(accelerator), m_keyDown(keyDown), m_keyUp(keyUp)
116   {
117   }
118 };
119
120
121
122 struct PressedButtons;
123 typedef struct _GtkWidget GtkWidget;
124 void PressedButtons_connect(PressedButtons& pressedButtons, GtkWidget* widget);
125
126 extern PressedButtons g_pressedButtons;
127
128 #endif