xref: /haiku/src/bin/keymap/Keymap.h (revision e27f20198782c62e6cd78d41a3f35d708b343920)
1 /*
2  * Copyright 2004-2009, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Jérôme Duval
7  *		Axel Dörfler, axeld@pinc-software.de.
8  */
9 #ifndef KEYMAP_H
10 #define KEYMAP_H
11 
12 
13 #include <InterfaceDefs.h>
14 #include <TextView.h>
15 
16 #include <stdio.h>
17 #include <regex.h>
18 
19 
20 class Keymap {
21 public:
22 							Keymap();
23 							~Keymap();
24 
25 			status_t		LoadCurrent();
26 			status_t		Load(const char* name);
27 			status_t		Load(FILE* file);
28 			status_t		LoadSource(const char* name);
29 			status_t		LoadSource(FILE* file);
30 			status_t		SaveAsCurrent();
31 			status_t		Save(const char* name);
32 			status_t		SaveAsSource(const char* name);
33 			status_t		SaveAsSource(FILE* file);
34 			status_t		SaveAsCppHeader(const char* name,
35 								const char* mapName);
36 
37 			status_t		Use();
38 
39 			bool			IsModifierKey(uint32 keyCode);
40 			uint8			IsDeadKey(uint32 keyCode, uint32 modifiers);
41 			bool			IsDeadSecondKey(uint32 keyCode, uint32 modifiers,
42 								uint8 activeDeadKey);
43 			void			GetChars(uint32 keyCode, uint32 modifiers,
44 								uint8 activeDeadKey, char** chars,
45 								int32* numBytes);
46 			void			RestoreSystemDefault();
47 	static	void			GetKey(char* chars, int32 offset, char* string);
48 
49 private:
50 			void			_SaveSourceText(FILE* file,
51 								text_run_array** _textRuns);
52 			void			_ComputeChars(const char* buffer,
53 								struct re_registers& regs, int i, int& offset);
54 			void			_ComputeTables(const char* buffer,
55 								struct re_registers& regs, uint32& table);
56 
57 			char*			fChars;
58 			key_map			fKeys;
59 			uint32			fCharsSize;
60 };
61 
62 #define KEYMAP_ERROR_UNKNOWN_VERSION	(B_ERRORS_END + 1)
63 
64 #endif // KEYMAP_H
65