1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_
25 #define __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_
26 
27 //__________________________________________
28 // own includes
29 
30 #include <general.h>
31 #include <stdtypes.h>
32 
33 //__________________________________________
34 // interface includes
35 #include <com/sun/star/lang/IllegalArgumentException.hpp>
36 
37 //__________________________________________
38 // other includes
39 
40 //__________________________________________
41 // definition
42 
43 namespace framework
44 {
45 
46 //__________________________________________
47 /**
48     can be used to map key identifier to the
49     corresponding key codes ...
50  */
51 class KeyMapping
52 {
53     //______________________________________
54     // const, types
55 
56     private:
57 
58         //---------------------------------------
59         /** @short  is used to map a key code
60                     to the right key identifier, which is
61                     used to make the xml file "human readable"
62          */
63         struct KeyIdentifierInfo
64         {
65             sal_Int16       Code      ;
66             const char*     Identifier;
67         };
68 
69         //---------------------------------------
70         /** @short  hash structure to map identifier to key codes. */
71         typedef BaseHash< sal_Int16 > Identifier2CodeHash;
72 
73         //---------------------------------------
74         /** @short  hash structure to map key codes to identifier. */
75         typedef ::std::hash_map< sal_Int16                    ,
76                                  ::rtl::OUString              ,
77                                  ShortHashCode                ,
78                                  ::std::equal_to< sal_Int16 > > Code2IdentifierHash;
79 
80     //______________________________________
81     // member
82 
83     private:
84 
85         static KeyIdentifierInfo KeyIdentifierMap[];
86 
87         //---------------------------------------
88         /** @short  hash to map identifier to key codes. */
89         Identifier2CodeHash m_lIdentifierHash;
90 
91         //---------------------------------------
92         /** @short  hash to map key codes to identifier. */
93         Code2IdentifierHash m_lCodeHash;
94 
95     //______________________________________
96     // interface
97 
98     public:
99 
100                  KeyMapping();
101         virtual ~KeyMapping();
102 
103         //----------------------------------
104         /** @short  return a suitable key code
105                     for the specified key identifier.
106 
107             @param  sIdentifier
108                     string value, which describe the key.
109 
110             @return [css::awt::KeyEvent]
111                     the corresponding key code as
112                     short value.
113 
114             @throw  [css::lang::IllegalArgumentException]
115                     if the given identifier does not describe
116                     a well known key code.
117          */
118         virtual sal_uInt16 mapIdentifierToCode(const ::rtl::OUString& sIdentifier)
119             throw(css::lang::IllegalArgumentException);
120 
121         //----------------------------------
122         /** @short  return a suitable key identifier
123                     for the specified key code.
124 
125             @param  nCode
126                     short value, which describe the key.
127 
128             @return The corresponding string identifier.
129          */
130         virtual ::rtl::OUString mapCodeToIdentifier(sal_uInt16 nCode);
131 
132     //______________________________________
133     // helper
134 
135     private:
136 
137         //----------------------------------
138         /** @short  check if the given string describe a numeric
139                     value ... and convert it.
140 
141             @param  sIdentifier
142                     the string value, which should be converted.
143 
144 
145             @param  rCode
146                     contains the converted code, but is defined only
147                     if this method returns sal_True!
148 
149             @return [boolean]
150                     sal_True if convertion was successfully.
151           */
152         sal_Bool impl_st_interpretIdentifierAsPureKeyCode(const ::rtl::OUString& sIdentifier,
153                                                                 sal_uInt16&      rCode      );
154 };
155 
156 } // namespace framework
157 
158 #endif // __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_
159