summaryrefslogtreecommitdiffstats
path: root/kdecore/kkeynative.h
blob: 47b4ad677e7362769748fa2d457a9a9c6bd2ed73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* This file is part of the KDE libraries
    Copyright (C) 2002 Ellis Whitehead <ellis@kde.org>

    Win32 port:
    Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef __KKEYNATIVE_H
#define __KKEYNATIVE_H

#include <kshortcut.h>

#ifdef Q_WS_X11
typedef union _XEvent XEvent;
#endif

class KKeyNativePrivate;
/**
 * Representation of a key in the format native of the windowing system (eg. X11).
 * @see KKey
 */
class KDECORE_EXPORT KKeyNative
{
 public:
	/**
	 * Creates a new null KKey.
	 * @see clear()
	 * @see isNull()
	 * @see null()
	 */
	KKeyNative();

#ifdef Q_WS_X11
	/**
	 * Extracts a new native key from the given xevent.
	 * @param xevent the XEvent that contains the key
	 */
	KKeyNative( const XEvent* xevent );
#endif

	/**
	 * Creates a new native key for the given KKey code.
	 * @param key the KKey that contains the generic key
	 */
	KKeyNative( const KKey& key );

	/**
	 * Copy constructor.
	 */
	KKeyNative( const KKeyNative& );

	/**
	 * @internal
	 */
	KKeyNative( uint code, uint mod, uint sym );
	~KKeyNative();

	/**
	 * Clears the key. The key is null after calling this function.
	 * @see isNull()
	 */
	void clear();

#ifdef Q_WS_X11
	/**
	 * Initializes the native key by extracting the information
	 * from the given xevent.
	 * @param xevent the XEvent that contains the key
	 * @return true if successful, false otherwise
	 */
	bool init( const XEvent* xevent );
#endif

	/**
	 * Creates a new native key for the given KKey code.
	 * @param key the KKey that contains the generic key
	 * @return true if successful, false otherwise
	 */
	bool init( const KKey& key );

	/**
	 * Copies the given key into this key.
	 * @param key the key to copy
	 * @return true if successful, false otherwise
	 */
	bool init( const KKeyNative& key );

	/**
	 * Copies the given key into this key.
	 * @param key the key to copy
	 * @return this key
	 */
	KKeyNative& operator =( const KKeyNative& key )
		{ init( key ); return *this; }

	/**
	 * Returns the qt key code.
	 * @return the qt key code or 0 if there is no key set.
	 * @see Qt::Key
	 */

	int keyCodeQt() const;

	/**
	 * Returns the KKey representation of this key.
	 * @return the KKey representation
	 */
	KKey key() const;

	/**
	 * Converts this key to its KKey representation.
	 * @return the KKey representation
	 * @see key()
	 */
	operator KKey() const     { return key(); }

	/**
	 * The native keycode of the key.
	 * @return the native keycode
	 */
	uint code() const;

	/**
	 * The native modifier flags of the key.
	 * @return the native modifier flags
	 */
	uint mod() const;

	/**
	 * The native symbol (KeySym) of the key.
	 * @return the native symbol (KeySym)
	 */
	uint sym() const;

	/**
	 * Returns true if the key is null (after clear() or empty
	 * constructor).
	 * @return true if the key is null
	 * @see clear()
	 * @see null()
	 */
	bool isNull() const;

	/**
	 * Compares this key with the given KKeyNative object. Returns a
	 * negative number if the given KKeyNative is larger, 0 if they
	 * are equal and a positive number this KKeyNative is larger. The
	 * returned value is the difference between the symbol, modifier
	 * or code, whatever is non-zero first.
	 *
	 * @param key the key to compare with this key
	 * @return a negative number if the given KKeyNative is larger, 0 if
	 * they are equal and a positive number this KKeyNative is larger
	 */
	int compare( const KKeyNative& key ) const;

	/**
	 * Compares the symbol, modifiers and code of both keys.
	 * @see compare()
	 */
	bool operator == ( const KKeyNative& key ) const
		{ return compare( key ) == 0; }

	/**
	 * Compares the symbol, modifiers and code of both keys.
	 * @see compare()
	 */
	bool operator != ( const KKeyNative& key ) const
		{ return compare( key ) != 0; }

	/**
	 * Compares the symbol, modifiers and code of both keys.
	 * @see compare()
	 */
	bool operator < ( const KKeyNative& key ) const
		{ return compare( key ) < 0; }

	/**
	 * Returns a null key.
	 * @return the null key
	 * @see isNull()
	 * @see clear()
	 */
	static KKeyNative& null();

	// General query functions. //
	/**
	 * Checks whether the keyboard has a Win key.
	 * @return true if the keyboard has a Win key
	 */
	static bool keyboardHasWinKey();

#ifdef Q_WS_X11
	/**
	 * Returns the equivalent X modifier mask of the given modifier flag.
	 * @param modFlag the mod flags to test
	 * @return the equivalent native flags of the window system
	 */
	static uint modX( KKey::ModFlag modFlag );

	/**
	 * Returns bitwise OR'ed mask containing Shift, Ctrl, Alt, and
	 * Win (if available).
	 * @return the mask of Shift, Ctrl, Alt and Win.
	 */
	static uint accelModMaskX();

	/**
	 * Returns the X11 NumLock modifier mask/flag.
	 * @return the X11 NumLock modifier mask/flag.
	 * @see accelModMaskX()
	 */
	static uint modXNumLock();

	/**
	 * Returns the X11 Lock modifier mask/flag.
	 * @return the X11 Lock modifier mask/flag.
	 * @see accelModMaskX()
	 */
	static uint modXLock();

	/**
	 * Returns the X11 ScrollLock modifier mask/flag.
	 * @return the X11 ScrollLock modifier mask/flag.
	 * @see accelModMaskX()
	 */
	static uint modXScrollLock();

	/** 
	 * Returns the X11 Mode_switch modifier mask/flag. 
	 * @return the X11 Mode_switch modifier mask/flag. 
	 * @see accelModMaskX() 
	 * @since 3.5
	 */ 
	static uint modXModeSwitch(); 
#endif

 private:
	uint m_code, m_mod, m_sym;
	KKeyNativePrivate* d;
};

#endif // !__KKEYNATIVE_H