1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_ 29 #define __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_ 30 31 //__________________________________________ 32 // own includes 33 34 #include <general.h> 35 #include <stdtypes.h> 36 37 //__________________________________________ 38 // interface includes 39 #include <com/sun/star/lang/IllegalArgumentException.hpp> 40 41 //__________________________________________ 42 // other includes 43 44 //__________________________________________ 45 // definition 46 47 namespace framework 48 { 49 50 //__________________________________________ 51 /** 52 can be used to map key identifier to the 53 corresponding key codes ... 54 */ 55 class KeyMapping 56 { 57 //______________________________________ 58 // const, types 59 60 private: 61 62 //--------------------------------------- 63 /** @short is used to map a key code 64 to the right key identifier, which is 65 used to make the xml file "human readable" 66 */ 67 struct KeyIdentifierInfo 68 { 69 sal_Int16 Code ; 70 const char* Identifier; 71 }; 72 73 //--------------------------------------- 74 /** @short hash structure to map identifier to key codes. */ 75 typedef BaseHash< sal_Int16 > Identifier2CodeHash; 76 77 //--------------------------------------- 78 /** @short hash structure to map key codes to identifier. */ 79 typedef ::std::hash_map< sal_Int16 , 80 ::rtl::OUString , 81 ShortHashCode , 82 ::std::equal_to< sal_Int16 > > Code2IdentifierHash; 83 84 //______________________________________ 85 // member 86 87 private: 88 89 static KeyIdentifierInfo KeyIdentifierMap[]; 90 91 //--------------------------------------- 92 /** @short hash to map identifier to key codes. */ 93 Identifier2CodeHash m_lIdentifierHash; 94 95 //--------------------------------------- 96 /** @short hash to map key codes to identifier. */ 97 Code2IdentifierHash m_lCodeHash; 98 99 //______________________________________ 100 // interface 101 102 public: 103 104 KeyMapping(); 105 virtual ~KeyMapping(); 106 107 //---------------------------------- 108 /** @short return a suitable key code 109 for the specified key identifier. 110 111 @param sIdentifier 112 string value, which describe the key. 113 114 @return [css::awt::KeyEvent] 115 the corresponding key code as 116 short value. 117 118 @throw [css::lang::IllegalArgumentException] 119 if the given identifier does not describe 120 a well known key code. 121 */ 122 virtual sal_uInt16 mapIdentifierToCode(const ::rtl::OUString& sIdentifier) 123 throw(css::lang::IllegalArgumentException); 124 125 //---------------------------------- 126 /** @short return a suitable key identifier 127 for the specified key code. 128 129 @param nCode 130 short value, which describe the key. 131 132 @return The corresponding string identifier. 133 */ 134 virtual ::rtl::OUString mapCodeToIdentifier(sal_uInt16 nCode); 135 136 //______________________________________ 137 // helper 138 139 private: 140 141 //---------------------------------- 142 /** @short check if the given string describe a numeric 143 value ... and convert it. 144 145 @param sIdentifier 146 the string value, which should be converted. 147 148 149 @param rCode 150 contains the converted code, but is defined only 151 if this method returns sal_True! 152 153 @return [boolean] 154 sal_True if convertion was successfully. 155 */ 156 sal_Bool impl_st_interpretIdentifierAsPureKeyCode(const ::rtl::OUString& sIdentifier, 157 sal_uInt16& rCode ); 158 }; 159 160 } // namespace framework 161 162 #endif // __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_ 163