xref: /haiku/src/preferences/keymap/Keymap.h (revision 2222d0559df303a9846a2fad53741f8b20b14d7c)
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 <Entry.h>
15 #include <Messenger.h>
16 #include <String.h>
17 
18 
19 enum dead_key_index {
20 	kDeadKeyAcute = 1,
21 	kDeadKeyGrave,
22 	kDeadKeyCircumflex,
23 	kDeadKeyDiaeresis,
24 	kDeadKeyTilde
25 };
26 
27 
28 class Keymap {
29 public:
30 							Keymap();
31 							~Keymap();
32 
33 			void			SetTarget(BMessenger target,
34 								BMessage* modificationMessage);
35 
36 			status_t		Load(entry_ref& ref);
37 			status_t		Save(entry_ref& ref);
38 
39 			void			DumpKeymap();
40 
41 			bool			IsModifierKey(uint32 keyCode);
42 			uint32			Modifier(uint32 keyCode);
43 			uint32			KeyForModifier(uint32 modifier);
44 			status_t		SetModifier(uint32 keyCode, uint32 modifier);
45 
46 			uint8			IsDeadKey(uint32 keyCode, uint32 modifiers,
47 								bool* isEnabled = NULL);
48 			bool			IsDeadSecondKey(uint32 keyCode, uint32 modifiers,
49 								uint8 activeDeadKey);
50 			void			SetDeadKeyEnabled(uint32 keyCode, uint32 modifiers,
51 								bool enabled);
52 			void			GetDeadKeyTrigger(dead_key_index deadKeyIndex,
53 								BString& outTrigger);
54 			void			SetDeadKeyTrigger(dead_key_index deadKeyIndex,
55 								const BString& trigger);
56 
57 			void			GetChars(uint32 keyCode, uint32 modifiers,
58 								uint8 activeDeadKey, char** chars,
59 								int32* numBytes);
60 			status_t		Use();
61 			bool			Equals(const Keymap& map) const;
62 
63 			void			SetKey(uint32 keyCode, uint32 modifiers,
64 								int8 deadKey, const char* bytes,
65 								int32 numBytes = -1);
66 
67 			void			SetName(const char* name);
68 
69 			const key_map&	Map() const { return fKeys; }
70 			key_map&		Map() { return fKeys; }
71 
72 			Keymap&			operator=(const Keymap& other);
73 
74 private:
75 			int32			_Offset(uint32 keyCode, uint32 modifiers,
76 								uint32* _table = NULL);
77 			bool			_SetChars(int32 offset, const char* bytes,
78 								int32 numBytes);
79 			uint8			_GetDeadKeyIndex(int32 offset);
80 
81 			char*			fChars;
82 			key_map			fKeys;
83 			uint32			fCharsSize;
84 			char			fName[B_FILE_NAME_LENGTH];
85 
86 			BMessenger		fTarget;
87 			BMessage*		fModificationMessage;
88 };
89 
90 
91 #endif	// KEYMAP_H
92