Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <unx/saldisp.hxx>
21 : #include <X11/keysym.h>
22 : #include <sal/macros.h>
23 :
24 : #if !defined (SunXK_Undo)
25 : #define SunXK_Undo 0x0000FF65 // XK_Undo
26 : #define SunXK_Again 0x0000FF66 // XK_Redo
27 : #define SunXK_Find 0x0000FF68 // XK_Find
28 : #define SunXK_Stop 0x0000FF69 // XK_Cancel
29 : #define SunXK_Props 0x1005FF70
30 : #define SunXK_Front 0x1005FF71
31 : #define SunXK_Copy 0x1005FF72
32 : #define SunXK_Open 0x1005FF73
33 : #define SunXK_Paste 0x1005FF74
34 : #define SunXK_Cut 0x1005FF75
35 : #endif
36 :
37 : #include <string.h>
38 : #include <rtl/ustring.hxx>
39 :
40 : namespace vcl_sal {
41 :
42 : struct KeysymNameReplacement
43 : {
44 : KeySym aSymbol;
45 : const char* pName;
46 : };
47 :
48 : struct KeyboardReplacements
49 : {
50 : const char* pLangName;
51 : const KeysymNameReplacement* pReplacements;
52 : int nReplacements;
53 : };
54 :
55 : // CAUTION CAUTION CAUTION
56 : // every string value in the replacements tables must be in UTF8
57 : // be careful with your editor !
58 :
59 : static const struct KeysymNameReplacement aImplReplacements_English[] =
60 : {
61 : { XK_Control_L, "Ctrl" },
62 : { XK_Control_R, "Ctrl" },
63 : { XK_Escape, "Esc" },
64 : { XK_space, "Space" },
65 : { XK_Page_Up, "PgUp"},
66 : { XK_Page_Down, "PgDn"}
67 : };
68 :
69 : static const struct KeysymNameReplacement aImplReplacements_Turkish[] =
70 : {
71 : { XK_Control_L, "Ctrl" },
72 : { XK_Control_R, "Ctrl" },
73 : { XK_Right, "Sa\304\237" },
74 : { XK_Left, "Sol" },
75 : { XK_Up, "Yukar\304\261" },
76 : { XK_Down, "A\305\237a\304\237\304\261" },
77 : { XK_space, "Bo\305\237luk" }
78 : };
79 :
80 : static const struct KeysymNameReplacement aImplReplacements_Russian[] =
81 : {
82 : { XK_Right, "\320\222\320\277\321\200\320\260\320\262\320\276" },
83 : { XK_Left, "\320\222\320\273\320\265\320\262\320\276" },
84 : { XK_Up, "\320\222\320\262\320\265\321\200\321\205" },
85 : { XK_Down, "\320\222\320\275\320\270\320\267" },
86 : { XK_space, "\320\237\321\200\320\276\320\261\320\265\320\273" }
87 : };
88 :
89 : static const struct KeysymNameReplacement aImplReplacements_German[] =
90 : {
91 : { XK_Control_L, "Strg" },
92 : { XK_Control_R, "Strg" },
93 : { XK_Shift_L, "Umschalt" },
94 : { XK_Shift_R, "Umschalt" },
95 : { XK_Alt_L, "Alt" },
96 : { XK_Alt_R, "Alt Gr" },
97 : { XK_Page_Up, "Bild auf" },
98 : { XK_Page_Down, "Bild ab" },
99 : { XK_End, "Ende" },
100 : { XK_Home, "Pos 1" },
101 : { XK_Insert, "Einfg" },
102 : { XK_Delete, "Entf" },
103 : { XK_Escape, "Esc" },
104 : { XK_Right, "Rechts" },
105 : { XK_Left, "Links" },
106 : { XK_Up, "Oben" },
107 : { XK_Down, "Unten" },
108 : { XK_BackSpace, "R\303\274ckschritt" },
109 : { XK_Return, "Eingabe" },
110 : { XK_slash, "Schr\303\244gstrich" },
111 : { XK_space, "Leertaste" },
112 : { SunXK_Stop, "Stop" },
113 : { SunXK_Again, "Wiederholen" },
114 : { SunXK_Props, "Eigenschaften" },
115 : { SunXK_Undo, "Zur\303\274cknehmen" },
116 : { SunXK_Front, "Vordergrund" },
117 : { SunXK_Copy, "Kopieren" },
118 : { SunXK_Open, "\303\226ffnen" },
119 : { SunXK_Paste, "Einsetzen" },
120 : { SunXK_Find, "Suchen" },
121 : { SunXK_Cut, "Ausschneiden" },
122 : };
123 :
124 : static const struct KeysymNameReplacement aImplReplacements_French[] =
125 : {
126 : { XK_Shift_L, "Maj" },
127 : { XK_Shift_R, "Maj" },
128 : { XK_Page_Up, "Pg. Pr\303\251c" },
129 : { XK_Page_Down, "Pg. Suiv" },
130 : { XK_End, "Fin" },
131 : { XK_Home, "Origine" },
132 : { XK_Insert, "Ins\303\251rer" },
133 : { XK_Delete, "Suppr" },
134 : { XK_Escape, "Esc" },
135 : { XK_Right, "Droite" },
136 : { XK_Left, "Gauche" },
137 : { XK_Up, "Haut" },
138 : { XK_Down, "Bas" },
139 : { XK_BackSpace, "Ret. Arr" },
140 : { XK_Return, "Retour" },
141 : { XK_space, "Espace" },
142 : { XK_KP_Enter, "Entr\303\251e" },
143 : { SunXK_Stop, "Stop" },
144 : { SunXK_Again, "Encore" },
145 : { SunXK_Props, "Props" },
146 : { SunXK_Undo, "Annuler" },
147 : { SunXK_Front, "Devant" },
148 : { SunXK_Copy, "Copy" },
149 : { SunXK_Open, "Ouvrir" },
150 : { SunXK_Paste, "Coller" },
151 : { SunXK_Find, "Cher." },
152 : { SunXK_Cut, "Couper" },
153 : };
154 :
155 : static const struct KeysymNameReplacement aImplReplacements_Italian[] =
156 : {
157 : { XK_Shift_L, "Maiusc" },
158 : { XK_Shift_R, "Maiusc" },
159 : { XK_Page_Up, "PgSu" },
160 : { XK_Page_Down, "PgGiu" },
161 : { XK_End, "Fine" },
162 : { XK_Insert, "Ins" },
163 : { XK_Delete, "Canc" },
164 : { XK_Escape, "Esc" },
165 : { XK_Right, "A destra" },
166 : { XK_Left, "A sinistra" },
167 : { XK_Up, "Sposta verso l'alto" },
168 : { XK_Down, "Sposta verso il basso" },
169 : { XK_BackSpace, "Backspace" },
170 : { XK_Return, "Invio" },
171 : { XK_space, "Spazio" },
172 : { SunXK_Stop, "Stop" },
173 : { SunXK_Again, "Ancora" },
174 : { SunXK_Props, "Propriet\303\240" },
175 : { SunXK_Undo, "Annulla" },
176 : { SunXK_Front, "Davanti" },
177 : { SunXK_Copy, "Copia" },
178 : { SunXK_Open, "Apri" },
179 : { SunXK_Paste, "Incolla" },
180 : { SunXK_Find, "Trova" },
181 : { SunXK_Cut, "Taglia" },
182 : };
183 :
184 : static const struct KeysymNameReplacement aImplReplacements_Dutch[] =
185 : {
186 : { XK_Page_Up, "PageUp" },
187 : { XK_Page_Down, "PageDown" },
188 : { XK_Escape, "Esc" },
189 : { XK_Right, "Rechts" },
190 : { XK_Left, "Links" },
191 : { XK_Up, "Boven" },
192 : { XK_Down, "Onder" },
193 : { XK_BackSpace, "Backspace" },
194 : { XK_Return, "Return" },
195 : { XK_space, "Spatiebalk" },
196 : { SunXK_Stop, "Stop" },
197 : { SunXK_Again, "Again" },
198 : { SunXK_Props, "Props" },
199 : { SunXK_Undo, "Undo" },
200 : { SunXK_Front, "Front" },
201 : { SunXK_Copy, "Copy" },
202 : { SunXK_Open, "Open" },
203 : { SunXK_Paste, "Paste" },
204 : { SunXK_Find, "Find" },
205 : { SunXK_Cut, "Cut" },
206 : };
207 :
208 : static const struct KeysymNameReplacement aImplReplacements_Norwegian[] =
209 : {
210 : { XK_Shift_L, "Skift" },
211 : { XK_Shift_R, "Skift" },
212 : { XK_Page_Up, "PageUp" },
213 : { XK_Page_Down, "PageDown" },
214 : { XK_Escape, "Esc" },
215 : { XK_Right, "H\303\270yre" },
216 : { XK_Left, "Venstre" },
217 : { XK_Up, "Opp" },
218 : { XK_Down, "Ned" },
219 : { XK_BackSpace, "Tilbake" },
220 : { XK_Return, "Enter" },
221 : { SunXK_Stop, "Avbryt" },
222 : { SunXK_Again, "Gjenta" },
223 : { SunXK_Props, "Egenskaper" },
224 : { SunXK_Undo, "Angre" },
225 : { SunXK_Front, "Front" },
226 : { SunXK_Copy, "Kopi" },
227 : { SunXK_Open, "\303\205pne" },
228 : { SunXK_Paste, "Lim" },
229 : { SunXK_Find, "S\303\270k" },
230 : { SunXK_Cut, "Klipp" },
231 : };
232 :
233 : static const struct KeysymNameReplacement aImplReplacements_Swedish[] =
234 : {
235 : { XK_Shift_L, "Skift" },
236 : { XK_Shift_R, "Skift" },
237 : { XK_Page_Up, "PageUp" },
238 : { XK_Page_Down, "PageDown" },
239 : { XK_Escape, "Esc" },
240 : { XK_Right, "H\303\266ger" },
241 : { XK_Left, "V\303\244nster" },
242 : { XK_Up, "Up" },
243 : { XK_Down, "Ned" },
244 : { XK_BackSpace, "Backsteg" },
245 : { XK_Return, "Retur" },
246 : { XK_space, "Blank" },
247 : { SunXK_Stop, "Avbryt" },
248 : { SunXK_Again, "Upprepa" },
249 : { SunXK_Props, "Egenskaper" },
250 : { SunXK_Undo, "\303\205ngra" },
251 : { SunXK_Front, "Fram" },
252 : { SunXK_Copy, "Kopiera" },
253 : { SunXK_Open, "\303\226ppna" },
254 : { SunXK_Paste, "Klistra in" },
255 : { SunXK_Find, "S\303\266k" },
256 : { SunXK_Cut, "Klipp ut" },
257 : };
258 :
259 : static const struct KeysymNameReplacement aImplReplacements_Portuguese[] =
260 : {
261 : { XK_Page_Up, "PageUp" },
262 : { XK_Page_Down, "PageDown" },
263 : { XK_Escape, "Esc" },
264 : { XK_Right, "Direita" },
265 : { XK_Left, "Esquerda" },
266 : { XK_Up, "Acima" },
267 : { XK_Down, "Abaixo" },
268 : { XK_BackSpace, "Backspace" },
269 : { XK_Return, "Enter" },
270 : { XK_slash, "Barra" },
271 : { SunXK_Stop, "Stop" },
272 : { SunXK_Again, "Again" },
273 : { SunXK_Props, "Props" },
274 : { SunXK_Undo, "Undo" },
275 : { SunXK_Front, "Front" },
276 : { SunXK_Copy, "Copy" },
277 : { SunXK_Open, "Open" },
278 : { SunXK_Paste, "Paste" },
279 : { SunXK_Find, "Find" },
280 : { SunXK_Cut, "Cut" },
281 : };
282 :
283 : static const struct KeysymNameReplacement aImplReplacements_Slovenian[] =
284 : {
285 : { XK_Control_L, "Krmilka" },
286 : { XK_Control_R, "Krmilka" },
287 : { XK_Shift_L, "Dvigalka" },
288 : { XK_Shift_R, "Dvigalka" },
289 : { XK_Alt_L, "Izmenjalka" },
290 : { XK_Alt_R, "Desna izmenjalka" },
291 : { XK_Page_Up, "Prej\305\241nja stranf" },
292 : { XK_Page_Down, "Naslednja stran" },
293 : { XK_End, "Konec" },
294 : { XK_Home, "Za\304\215etek" },
295 : { XK_Insert, "Vstavljalka" },
296 : { XK_Delete, "Brisalka" },
297 : { XK_Escape, "Ube\305\276nica" },
298 : { XK_Right, "Desno" },
299 : { XK_Left, "Levo" },
300 : { XK_Up, "Navzgor" },
301 : { XK_Down, "Navzdol" },
302 : { XK_BackSpace, "Vra\304\215alka" },
303 : { XK_Return, "Vna\305\241alka" },
304 : { XK_slash, "Po\305\241evnica" },
305 : { XK_space, "Preslednica" },
306 : { SunXK_Stop, "Ustavi" },
307 : { SunXK_Again, "Ponovi" },
308 : { SunXK_Props, "Lastnosti" },
309 : { SunXK_Undo, "Razveljavi" },
310 : { SunXK_Front, "Ospredje" },
311 : { SunXK_Copy, "Kopiraj" },
312 : { SunXK_Open, "Odpri" },
313 : { SunXK_Paste, "Prilepi" },
314 : { SunXK_Find, "Najdi" },
315 : { SunXK_Cut, "Izre\305\276i" },
316 : };
317 :
318 : static const struct KeysymNameReplacement aImplReplacements_Spanish[] =
319 : {
320 : { XK_Shift_L, "May\303\272s" },
321 : { XK_Shift_R, "May\303\272s" },
322 : { XK_Page_Up, "ReP\303\241g" },
323 : { XK_Page_Down, "AvP\303\241g" },
324 : { XK_End, "Fin" },
325 : { XK_Home, "Inicio" },
326 : { XK_Delete, "Supr" },
327 : { XK_Escape, "Esc" },
328 : { XK_Right, "Derecha" },
329 : { XK_Left, "Izquierda" },
330 : { XK_Up, "Arriba" },
331 : { XK_Down, "Abajo" },
332 : { XK_BackSpace, "Ret" },
333 : { XK_Return, "Entrada" },
334 : { XK_space, "Espacio" },
335 : { XK_KP_Enter, "Intro" },
336 : { SunXK_Stop, "Detener" },
337 : { SunXK_Again, "Repetir" },
338 : { SunXK_Props, "Props" },
339 : { SunXK_Undo, "Anular" },
340 : { SunXK_Front, "Delante" },
341 : { SunXK_Copy, "Copiar" },
342 : { SunXK_Open, "Abrir" },
343 : { SunXK_Paste, "Pegar" },
344 : { SunXK_Find, "Buscar" },
345 : { SunXK_Cut, "Cortar" },
346 : };
347 :
348 : static const struct KeysymNameReplacement aImplReplacements_Estonian[] =
349 : {
350 : { XK_Page_Up, "PgUp" },
351 : { XK_Page_Down, "PgDown" },
352 : { XK_End, "End" },
353 : { XK_Home, "Home" },
354 : { XK_Insert, "Ins" },
355 : { XK_Delete, "Del" },
356 : { XK_Escape, "Esc" },
357 : { XK_Right, "Nool paremale" },
358 : { XK_Left, "Nool vasakule" },
359 : { XK_Up, "Nool \303\274les" },
360 : { XK_Down, "Nool alla" },
361 : { XK_BackSpace, "Tagasil\303\274ke" },
362 : { XK_Return, "Enter" },
363 : { XK_slash, "Kaldkriips" },
364 : { XK_space, "T\303\274hik" },
365 : { XK_asterisk, "T\303\244rn" },
366 : { SunXK_Stop, "Peata" },
367 : { SunXK_Again, "Korda" },
368 : { SunXK_Props, "Omadused" },
369 : { SunXK_Undo, "V\303\265ta tagasi" },
370 : { SunXK_Front, "Esiplaanile" },
371 : { SunXK_Copy, "Kopeeri" },
372 : { SunXK_Open, "Ava" },
373 : { SunXK_Paste, "Aseta" },
374 : { SunXK_Find, "Otsi" },
375 : { SunXK_Cut, "L\303\265ika" },
376 : };
377 :
378 : static const struct KeysymNameReplacement aImplReplacements_Catalan[] =
379 : {
380 : { XK_Shift_L, "Maj" },
381 : { XK_Shift_R, "Maj" },
382 : { XK_Page_Up, "Re P\303\240g" },
383 : { XK_Page_Down, "Av P\303\240g" },
384 : { XK_End, "Fi" },
385 : { XK_Home, "Inici" },
386 : { XK_Delete, "Supr" },
387 : { XK_Escape, "Esc" },
388 : { XK_Right, "Dreta" },
389 : { XK_Left, "Esquerra" },
390 : { XK_Up, "Amunt" },
391 : { XK_Down, "Avall" },
392 : { XK_BackSpace, "Retroc\303\251s" },
393 : { XK_Return, "Retorn" },
394 : { XK_space, "Espai" },
395 : { XK_KP_Enter, "Retorn" },
396 : { SunXK_Stop, "Atura" },
397 : { SunXK_Again, "Repeteix" },
398 : { SunXK_Props, "Props" },
399 : { SunXK_Undo, "Desf\303\251s" },
400 : { SunXK_Front, "Davant" },
401 : { SunXK_Copy, "C\303\262pia" },
402 : { SunXK_Open, "Obre" },
403 : { SunXK_Paste, "Enganxa" },
404 : { SunXK_Find, "Cerca" },
405 : { SunXK_Cut, "Retalla" },
406 : };
407 :
408 : static const struct KeysymNameReplacement aImplReplacements_Lithuanian[] =
409 : {
410 : { XK_Control_L, "Vald" },
411 : { XK_Control_R, "Vald" },
412 : { XK_Shift_L, "Lyg2" },
413 : { XK_Shift_R, "Lyg2" },
414 : { XK_Alt_L, "Alt" },
415 : { XK_Alt_R, "Lyg3" },
416 : { XK_Page_Up, "Psl\342\206\221" },
417 : { XK_Page_Down, "Psl\342\206\223" },
418 : { XK_End, "Pab" },
419 : { XK_Home, "Prad" },
420 : { XK_Insert, "\304\256terpti" },
421 : { XK_Delete, "\305\240al" },
422 : { XK_Escape, "Gr" },
423 : { XK_Right, "De\305\241in\304\227n" },
424 : { XK_Left, "Kair\304\227n" },
425 : { XK_Up, "Auk\305\241tyn" },
426 : { XK_Down, "\305\275emyn" },
427 : { XK_BackSpace, "Naikinti" },
428 : { XK_Return, "\304\256vesti" },
429 : { XK_asterisk, "\305\275vaig\305\276dut\304\227" },
430 : { XK_slash, "De\305\241ininis br\305\253k\305\241nys" },
431 : { XK_space, "Tarpas" },
432 : { SunXK_Stop, "Stabdyti" },
433 : { SunXK_Again, "Kartoti" },
434 : { SunXK_Props, "Savyb\304\227s" },
435 : { SunXK_Undo, "At\305\241aukti" },
436 : { SunXK_Front, "Priekinis planas" },
437 : { SunXK_Copy, "Kopijuoti" },
438 : { SunXK_Open, "Atverti" },
439 : { SunXK_Paste, "\304\256d\304\227ti" },
440 : { SunXK_Find, "Ie\305\241koti" },
441 : { SunXK_Cut, "I\305\241kirpti" },
442 : };
443 :
444 : static const struct KeysymNameReplacement aImplReplacements_Hungarian[] =
445 : {
446 : { XK_Right, "Jobbra" },
447 : { XK_Left, "Balra" },
448 : { XK_Up, "Fel" },
449 : { XK_Down, "Le" },
450 : { XK_Return, "Enter" },
451 : { XK_space, "Sz\303\263k\303\266z" },
452 : { XK_asterisk, "Csillag" },
453 : { XK_slash, "Oszt\303\241sjel" },
454 : };
455 :
456 : static const struct KeyboardReplacements aKeyboards[] =
457 : {
458 : { "ca", aImplReplacements_Catalan, SAL_N_ELEMENTS(aImplReplacements_Catalan) },
459 : { "de", aImplReplacements_German, SAL_N_ELEMENTS(aImplReplacements_German) },
460 : { "sl", aImplReplacements_Slovenian, SAL_N_ELEMENTS(aImplReplacements_Slovenian) },
461 : { "es", aImplReplacements_Spanish, SAL_N_ELEMENTS(aImplReplacements_Spanish) },
462 : { "et", aImplReplacements_Estonian, SAL_N_ELEMENTS(aImplReplacements_Estonian) },
463 : { "fr", aImplReplacements_French, SAL_N_ELEMENTS(aImplReplacements_French) },
464 : { "hu", aImplReplacements_Hungarian, SAL_N_ELEMENTS(aImplReplacements_Hungarian) },
465 : { "it", aImplReplacements_Italian, SAL_N_ELEMENTS(aImplReplacements_Italian) },
466 : { "lt", aImplReplacements_Lithuanian, SAL_N_ELEMENTS(aImplReplacements_Lithuanian) },
467 : { "nl", aImplReplacements_Dutch, SAL_N_ELEMENTS(aImplReplacements_Dutch) },
468 : { "no", aImplReplacements_Norwegian, SAL_N_ELEMENTS(aImplReplacements_Norwegian) },
469 : { "pt", aImplReplacements_Portuguese, SAL_N_ELEMENTS(aImplReplacements_Portuguese) },
470 : { "ru", aImplReplacements_Russian, SAL_N_ELEMENTS(aImplReplacements_Russian) },
471 : { "sv", aImplReplacements_Swedish, SAL_N_ELEMENTS(aImplReplacements_Swedish) },
472 : { "tr", aImplReplacements_Turkish, SAL_N_ELEMENTS(aImplReplacements_Turkish) },
473 : };
474 :
475 : // translate keycodes, used within the displayed menu shortcuts
476 23 : OUString getKeysymReplacementName( const OUString& pLang, KeySym nSymbol )
477 : {
478 368 : for( unsigned int n = 0; n < SAL_N_ELEMENTS(aKeyboards); n++ )
479 : {
480 345 : if( pLang.equalsAscii( aKeyboards[n].pLangName ) )
481 : {
482 0 : const struct KeysymNameReplacement* pRepl = aKeyboards[n].pReplacements;
483 0 : for( int m = aKeyboards[n].nReplacements ; m ; )
484 : {
485 0 : if( nSymbol == pRepl[--m].aSymbol )
486 0 : return OUString( pRepl[m].pName, strlen(pRepl[m].pName), RTL_TEXTENCODING_UTF8 );
487 : }
488 : }
489 : }
490 :
491 : // try english fallbacks
492 23 : const struct KeysymNameReplacement* pRepl = aImplReplacements_English;
493 165 : for( int m = SAL_N_ELEMENTS(aImplReplacements_English); m ; )
494 : {
495 132 : if( nSymbol == pRepl[--m].aSymbol )
496 13 : return OUString( pRepl[m].pName, strlen(pRepl[m].pName), RTL_TEXTENCODING_UTF8 );
497 : }
498 :
499 10 : return OUString();
500 : }
501 : }
502 :
503 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|