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 15 #if (defined(__BEOS__) || defined(__HAIKU__)) 16 # include <TextView.h> 17 #endif 18 19 #include <stdio.h> 20 #include <regex.h> 21 22 23 class Keymap { 24 public: 25 Keymap(); 26 ~Keymap(); 27 28 status_t LoadCurrent(); 29 status_t Load(const char* name); 30 status_t Load(FILE* file); 31 status_t LoadSource(const char* name); 32 status_t LoadSource(FILE* file); 33 status_t SaveAsCurrent(); 34 status_t Save(const char* name); 35 status_t SaveAsSource(const char* name); 36 status_t SaveAsSource(FILE* file); 37 status_t SaveAsCppHeader(const char* name, 38 const char* mapName); 39 40 status_t Use(); 41 42 bool IsModifierKey(uint32 keyCode); 43 uint8 IsDeadKey(uint32 keyCode, uint32 modifiers); 44 bool IsDeadSecondKey(uint32 keyCode, uint32 modifiers, 45 uint8 activeDeadKey); 46 void GetChars(uint32 keyCode, uint32 modifiers, 47 uint8 activeDeadKey, char** chars, 48 int32* numBytes); 49 void RestoreSystemDefault(); 50 static bool GetKey(const char* chars, int32 offset, 51 char* buffer, size_t bufferSize); 52 53 private: 54 #if (defined(__BEOS__) || defined(__HAIKU__)) 55 void _SaveSourceText(FILE* file, 56 text_run_array** _textRuns = NULL); 57 #else 58 void _SaveSourceText(FILE* file); 59 #endif 60 void _ComputeChars(const char* buffer, 61 struct re_registers& regs, int i, int& offset); 62 void _ComputeTables(const char* buffer, 63 struct re_registers& regs, uint32& table); 64 65 char* fChars; 66 key_map fKeys; 67 uint32 fCharsSize; 68 }; 69 70 #define KEYMAP_ERROR_UNKNOWN_VERSION (B_ERRORS_END + 1) 71 72 #endif // KEYMAP_H 73