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