Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <accelerators/keymapping.hxx>
30 : :
31 : : #include <macros/generic.hxx>
32 : :
33 : : #include <com/sun/star/awt/Key.hpp>
34 : :
35 : :
36 : : namespace framework
37 : : {
38 : :
39 : : //_______________________________________________
40 : : // helper
41 : :
42 : : KeyMapping::KeyIdentifierInfo KeyMapping::KeyIdentifierMap[] =
43 : : {
44 : : {css::awt::Key::NUM0 , "KEY_0" },
45 : : {css::awt::Key::NUM1 , "KEY_1" },
46 : : {css::awt::Key::NUM2 , "KEY_2" },
47 : : {css::awt::Key::NUM3 , "KEY_3" },
48 : : {css::awt::Key::NUM4 , "KEY_4" },
49 : : {css::awt::Key::NUM5 , "KEY_5" },
50 : : {css::awt::Key::NUM6 , "KEY_6" },
51 : : {css::awt::Key::NUM7 , "KEY_7" },
52 : : {css::awt::Key::NUM8 , "KEY_8" },
53 : : {css::awt::Key::NUM9 , "KEY_9" },
54 : : {css::awt::Key::A , "KEY_A" },
55 : : {css::awt::Key::B , "KEY_B" },
56 : : {css::awt::Key::C , "KEY_C" },
57 : : {css::awt::Key::D , "KEY_D" },
58 : : {css::awt::Key::E , "KEY_E" },
59 : : {css::awt::Key::F , "KEY_F" },
60 : : {css::awt::Key::G , "KEY_G" },
61 : : {css::awt::Key::H , "KEY_H" },
62 : : {css::awt::Key::I , "KEY_I" },
63 : : {css::awt::Key::J , "KEY_J" },
64 : : {css::awt::Key::K , "KEY_K" },
65 : : {css::awt::Key::L , "KEY_L" },
66 : : {css::awt::Key::M , "KEY_M" },
67 : : {css::awt::Key::N , "KEY_N" },
68 : : {css::awt::Key::O , "KEY_O" },
69 : : {css::awt::Key::P , "KEY_P" },
70 : : {css::awt::Key::Q , "KEY_Q" },
71 : : {css::awt::Key::R , "KEY_R" },
72 : : {css::awt::Key::S , "KEY_S" },
73 : : {css::awt::Key::T , "KEY_T" },
74 : : {css::awt::Key::U , "KEY_U" },
75 : : {css::awt::Key::V , "KEY_V" },
76 : : {css::awt::Key::W , "KEY_W" },
77 : : {css::awt::Key::X , "KEY_X" },
78 : : {css::awt::Key::Y , "KEY_Y" },
79 : : {css::awt::Key::Z , "KEY_Z" },
80 : : {css::awt::Key::F1 , "KEY_F1" },
81 : : {css::awt::Key::F2 , "KEY_F2" },
82 : : {css::awt::Key::F3 , "KEY_F3" },
83 : : {css::awt::Key::F4 , "KEY_F4" },
84 : : {css::awt::Key::F5 , "KEY_F5" },
85 : : {css::awt::Key::F6 , "KEY_F6" },
86 : : {css::awt::Key::F7 , "KEY_F7" },
87 : : {css::awt::Key::F8 , "KEY_F8" },
88 : : {css::awt::Key::F9 , "KEY_F9" },
89 : : {css::awt::Key::F10 , "KEY_F10" },
90 : : {css::awt::Key::F11 , "KEY_F11" },
91 : : {css::awt::Key::F12 , "KEY_F12" },
92 : : {css::awt::Key::F13 , "KEY_F13" },
93 : : {css::awt::Key::F14 , "KEY_F14" },
94 : : {css::awt::Key::F15 , "KEY_F15" },
95 : : {css::awt::Key::F16 , "KEY_F16" },
96 : : {css::awt::Key::F17 , "KEY_F17" },
97 : : {css::awt::Key::F18 , "KEY_F18" },
98 : : {css::awt::Key::F19 , "KEY_F19" },
99 : : {css::awt::Key::F20 , "KEY_F20" },
100 : : {css::awt::Key::F21 , "KEY_F21" },
101 : : {css::awt::Key::F22 , "KEY_F22" },
102 : : {css::awt::Key::F23 , "KEY_F23" },
103 : : {css::awt::Key::F24 , "KEY_F24" },
104 : : {css::awt::Key::F25 , "KEY_F25" },
105 : : {css::awt::Key::F26 , "KEY_F26" },
106 : : {css::awt::Key::DOWN , "KEY_DOWN" },
107 : : {css::awt::Key::UP , "KEY_UP" },
108 : : {css::awt::Key::LEFT , "KEY_LEFT" },
109 : : {css::awt::Key::RIGHT , "KEY_RIGHT" },
110 : : {css::awt::Key::HOME , "KEY_HOME" },
111 : : {css::awt::Key::END , "KEY_END" },
112 : : {css::awt::Key::PAGEUP , "KEY_PAGEUP" },
113 : : {css::awt::Key::PAGEDOWN , "KEY_PAGEDOWN" },
114 : : {css::awt::Key::RETURN , "KEY_RETURN" },
115 : : {css::awt::Key::ESCAPE , "KEY_ESCAPE" },
116 : : {css::awt::Key::TAB , "KEY_TAB" },
117 : : {css::awt::Key::BACKSPACE , "KEY_BACKSPACE" },
118 : : {css::awt::Key::SPACE , "KEY_SPACE" },
119 : : {css::awt::Key::INSERT , "KEY_INSERT" },
120 : : {css::awt::Key::DELETE , "KEY_DELETE" },
121 : : {css::awt::Key::ADD , "KEY_ADD" },
122 : : {css::awt::Key::SUBTRACT , "KEY_SUBTRACT" },
123 : : {css::awt::Key::MULTIPLY , "KEY_MULTIPLY" },
124 : : {css::awt::Key::DIVIDE , "KEY_DIVIDE" },
125 : : {css::awt::Key::POINT , "KEY_POINT" },
126 : : {css::awt::Key::COMMA , "KEY_COMMA" },
127 : : {css::awt::Key::LESS , "KEY_LESS" },
128 : : {css::awt::Key::GREATER , "KEY_GREATER" },
129 : : {css::awt::Key::EQUAL , "KEY_EQUAL" },
130 : : {css::awt::Key::OPEN , "KEY_OPEN" },
131 : : {css::awt::Key::CUT , "KEY_CUT" },
132 : : {css::awt::Key::COPY , "KEY_COPY" },
133 : : {css::awt::Key::PASTE , "KEY_PASTE" },
134 : : {css::awt::Key::UNDO , "KEY_UNDO" },
135 : : {css::awt::Key::REPEAT , "KEY_REPEAT" },
136 : : {css::awt::Key::FIND , "KEY_FIND" },
137 : : {css::awt::Key::PROPERTIES , "KEY_PROPERTIES" },
138 : : {css::awt::Key::FRONT , "KEY_FRONT" },
139 : : {css::awt::Key::CONTEXTMENU , "KEY_CONTEXTMENU"},
140 : : {css::awt::Key::HELP , "KEY_HELP" },
141 : : {css::awt::Key::MENU , "KEY_MENU" },
142 : : {css::awt::Key::HANGUL_HANJA , "KEY_HANGUL_HANJA"},
143 : : {css::awt::Key::DECIMAL , "KEY_DECIMAL" },
144 : : {css::awt::Key::TILDE , "KEY_TILDE" },
145 : : {css::awt::Key::QUOTELEFT , "KEY_QUOTELEFT" },
146 : : {css::awt::Key::BRACKETLEFT , "KEY_BRACKETLEFT" },
147 : : {css::awt::Key::BRACKETRIGHT , "KEY_BRACKETRIGHT" },
148 : : {css::awt::Key::SEMICOLON , "KEY_SEMICOLON" },
149 : : {0 , "" } // mark the end of this array!
150 : : };
151 : :
152 : : //-----------------------------------------------
153 [ + - ]: 118 : KeyMapping::KeyMapping()
154 : : {
155 : 118 : sal_Int32 i = 0;
156 [ + + ]: 12508 : while(KeyIdentifierMap[i].Code != 0)
157 : : {
158 : 12390 : ::rtl::OUString sIdentifier = ::rtl::OUString::createFromAscii(KeyIdentifierMap[i].Identifier);
159 : 12390 : sal_Int16 nCode = KeyIdentifierMap[i].Code;
160 : :
161 [ + - ]: 12390 : m_lIdentifierHash[sIdentifier] = nCode ;
162 [ + - ]: 12390 : m_lCodeHash [nCode] = sIdentifier;
163 : :
164 : 12390 : ++i;
165 : 12390 : }
166 : 118 : }
167 : :
168 : : //-----------------------------------------------
169 [ + - ]: 118 : KeyMapping::~KeyMapping()
170 : : {
171 [ - + ]: 236 : }
172 : :
173 : : //-----------------------------------------------
174 : 82656 : sal_uInt16 KeyMapping::mapIdentifierToCode(const ::rtl::OUString& sIdentifier)
175 : : throw(css::lang::IllegalArgumentException)
176 : : {
177 [ + - ]: 82656 : Identifier2CodeHash::const_iterator pIt = m_lIdentifierHash.find(sIdentifier);
178 [ + - ][ + - ]: 82656 : if (pIt != m_lIdentifierHash.end())
179 [ + - ]: 82656 : return pIt->second;
180 : :
181 : : // Its not well known identifier - but may be a pure key code formated as string ...
182 : : // Check and convert it!
183 : 0 : sal_uInt16 nCode = 0;
184 [ # # ][ # # ]: 0 : if (!KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(sIdentifier, nCode))
185 : : throw css::lang::IllegalArgumentException(
186 : : DECLARE_ASCII("Cant map given identifier to a valid key code value."),
187 : : css::uno::Reference< css::uno::XInterface >(),
188 [ # # ][ # # ]: 0 : 0);
189 : :
190 : 82656 : return (sal_uInt16)nCode;
191 : : }
192 : :
193 : : //-----------------------------------------------
194 : 0 : ::rtl::OUString KeyMapping::mapCodeToIdentifier(sal_uInt16 nCode)
195 : : {
196 [ # # ]: 0 : Code2IdentifierHash::const_iterator pIt = m_lCodeHash.find(nCode);
197 [ # # ][ # # ]: 0 : if (pIt != m_lCodeHash.end())
198 [ # # ]: 0 : return pIt->second;
199 : :
200 : : // If we have no well known identifier - use the pure code value!
201 : 0 : return ::rtl::OUString::valueOf((sal_Int32)nCode);
202 : : }
203 : :
204 : : //-----------------------------------------------
205 : 0 : sal_Bool KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(const ::rtl::OUString& sIdentifier,
206 : : sal_uInt16& rCode )
207 : : {
208 : 0 : sal_Int32 nCode = sIdentifier.toInt32();
209 [ # # ]: 0 : if (nCode > 0)
210 : : {
211 : 0 : rCode = (sal_uInt16)nCode;
212 : 0 : return sal_True;
213 : : }
214 : :
215 : : // 0 is normaly an error of the called method toInt32() ...
216 : : // But we must be aware, that the identifier is "0"!
217 : 0 : rCode = 0;
218 : 0 : return sIdentifier == "0";
219 : : }
220 : :
221 : : } // namespace framework
222 : :
223 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|