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