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