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