OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [java/] [awt/] [peer/] [x/] [KeyboardMapping.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* KeyboardMapping.java -- Maps X keysyms to Java keyCode and keyChar
2
   Copyright (C) 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package gnu.java.awt.peer.x;
39
 
40
import gnu.x11.Input;
41
import gnu.x11.keysym.Latin1;
42
import gnu.x11.keysym.Misc;
43
 
44
import java.awt.event.KeyEvent;
45
 
46
/**
47
 * Defines the keyboard mapping from X keysyms to Java
48
 * keycodes and keychars.
49
 *
50
 * @author Roman Kennke (kennke@aicas.com)
51
 */
52
final class KeyboardMapping
53
{
54
 
55
  /**
56
   * Maps X keycodes to AWT keycodes.
57
   *
58
   * @param xInput the X input event
59
   * @param xKeyCode the X keycode to map
60
   * @param xMods the X modifiers
61
   *
62
   * @return the AWT keycode and keychar
63
   */
64
  static int mapToKeyCode(gnu.x11.Input xInput, int xKeyCode, int xMods)
65
  {
66
    int mapped = KeyEvent.VK_UNDEFINED;
67
    int keysym = xInput.keycode_to_keysym(xKeyCode, xMods, true);
68
 
69
    // Special keys.
70
    if (keysym >= 255 << 8)
71
      {
72
        // FIXME: Add missing mappings.
73
        switch (keysym)
74
        {
75
          case Misc.BACKSPACE:
76
            mapped = KeyEvent.VK_BACK_SPACE;
77
            break;
78
          case Misc.TAB:
79
            mapped = KeyEvent.VK_TAB;
80
            break;
81
          case Misc.CLEAR:
82
            mapped = KeyEvent.VK_CLEAR;
83
            break;
84
          case Misc.RETURN:
85
            mapped = KeyEvent.VK_ENTER;
86
            break;
87
          case Misc.PAUSE:
88
            mapped = KeyEvent.VK_PAUSE;
89
            break;
90
          case Misc.SCROLL_LOCK:
91
            mapped = KeyEvent.VK_SCROLL_LOCK;
92
            break;
93
          case Misc.ESCAPE:
94
            mapped = KeyEvent.VK_ESCAPE;
95
            break;
96
          case Misc.HOME:
97
            mapped = KeyEvent.VK_HOME;
98
            break;
99
          case Misc.LEFT:
100
            mapped = KeyEvent.VK_LEFT;
101
            break;
102
          case Misc.UP:
103
            mapped = KeyEvent.VK_UP;
104
            break;
105
          case Misc.RIGHT:
106
            mapped = KeyEvent.VK_RIGHT;
107
            break;
108
          case Misc.DOWN:
109
            mapped = KeyEvent.VK_DOWN;
110
            break;
111
          case Misc.PAGE_UP:
112
            mapped = KeyEvent.VK_PAGE_UP;
113
            break;
114
          case Misc.PAGE_DOWN:
115
            mapped = KeyEvent.VK_PAGE_DOWN;
116
            break;
117
          case Misc.END:
118
            mapped = KeyEvent.VK_END;
119
            break;
120
          case Misc.BEGIN:
121
            mapped = KeyEvent.VK_BEGIN;
122
            break;
123
          case Misc.INSERT:
124
            mapped = KeyEvent.VK_INSERT;
125
            break;
126
          case Misc.UNDO:
127
            mapped = KeyEvent.VK_UNDO;
128
            break;
129
          case Misc.FIND:
130
            mapped = KeyEvent.VK_FIND;
131
            break;
132
          case Misc.CANCEL:
133
            mapped = KeyEvent.VK_CANCEL;
134
            break;
135
          case Misc.HELP:
136
            mapped = KeyEvent.VK_HELP;
137
            break;
138
          case Misc.MODE_SWITCH:
139
            mapped = KeyEvent.VK_MODECHANGE;
140
            break;
141
          case Misc.NUM_LOCK:
142
            mapped = KeyEvent.VK_NUM_LOCK;
143
            break;
144
          case Misc.KP_LEFT:
145
            mapped = KeyEvent.VK_KP_LEFT;
146
            break;
147
          case Misc.KP_UP:
148
            mapped = KeyEvent.VK_KP_UP;
149
            break;
150
          case Misc.KP_RIGHT:
151
            mapped = KeyEvent.VK_KP_RIGHT;
152
            break;
153
          case Misc.KP_DOWN:
154
            mapped = KeyEvent.VK_KP_DOWN;
155
            break;
156
          case Misc.F1:
157
            mapped = KeyEvent.VK_F1;
158
            break;
159
          case Misc.F2:
160
            mapped = KeyEvent.VK_F2;
161
            break;
162
          case Misc.F3:
163
            mapped = KeyEvent.VK_F3;
164
            break;
165
          case Misc.F4:
166
            mapped = KeyEvent.VK_F4;
167
            break;
168
          case Misc.F5:
169
            mapped = KeyEvent.VK_F5;
170
            break;
171
          case Misc.F6:
172
            mapped = KeyEvent.VK_F6;
173
            break;
174
          case Misc.F7:
175
            mapped = KeyEvent.VK_F7;
176
            break;
177
          case Misc.F8:
178
            mapped = KeyEvent.VK_F8;
179
            break;
180
          case Misc.F9:
181
            mapped = KeyEvent.VK_F9;
182
            break;
183
          case Misc.F10:
184
            mapped = KeyEvent.VK_F10;
185
            break;
186
          case Misc.F11:
187
            mapped = KeyEvent.VK_F11;
188
            break;
189
          case Misc.F12:
190
            mapped = KeyEvent.VK_F12;
191
            break;
192
          case Misc.F13:
193
            mapped = KeyEvent.VK_F13;
194
            break;
195
          case Misc.F14:
196
            mapped = KeyEvent.VK_F14;
197
            break;
198
          case Misc.F15:
199
            mapped = KeyEvent.VK_F15;
200
            break;
201
          case Misc.F16:
202
            mapped = KeyEvent.VK_F16;
203
            break;
204
          case Misc.F17:
205
            mapped = KeyEvent.VK_F17;
206
            break;
207
          case Misc.F18:
208
            mapped = KeyEvent.VK_F18;
209
            break;
210
          case Misc.F19:
211
            mapped = KeyEvent.VK_F19;
212
            break;
213
          case Misc.F20:
214
            mapped = KeyEvent.VK_F20;
215
            break;
216
          case Misc.F21:
217
            mapped = KeyEvent.VK_F21;
218
            break;
219
          case Misc.F22:
220
            mapped = KeyEvent.VK_F22;
221
            break;
222
          case Misc.F23:
223
            mapped = KeyEvent.VK_F23;
224
            break;
225
          case Misc.F24:
226
            mapped = KeyEvent.VK_F24;
227
            break;
228
          case Misc.SHIFT_L:
229
          case Misc.SHIFT_R:
230
            mapped = KeyEvent.VK_SHIFT;
231
            break;
232
          case Misc.CONTROL_L:
233
          case Misc.CONTROL_R:
234
            mapped = KeyEvent.VK_CONTROL;
235
            break;
236
          case Misc.CAPS_LOCK:
237
          case Misc.SHIFT_LOCK:
238
            mapped = KeyEvent.VK_CAPS_LOCK;
239
            break;
240
          case Misc.META_L:
241
          case Misc.META_R:
242
            mapped = KeyEvent.VK_META;
243
            break;
244
          case Misc.ALT_L:
245
          case Misc.ALT_R:
246
            mapped = KeyEvent.VK_ALT;
247
            break;
248
          case Misc.DELETE:
249
            mapped = KeyEvent.VK_DELETE;
250
            break;
251
          default:
252
            mapped = KeyEvent.VK_UNDEFINED;
253
        }
254
      }
255
    // Map Latin1 characters.
256
    else if (keysym < 256)
257
      {
258
        // TODO: Add missing mappings, if any.
259
        // Lowercase characters are mapped to
260
        // their corresponding upper case pendants.
261
        if (keysym >= Latin1.A_SMALL && keysym <= Latin1.Z_SMALL)
262
          mapped = keysym - 0x20;
263
        // Uppercase characters are mapped 1:1.
264
        else if (keysym >= Latin1.A && keysym <= Latin1.Z)
265
          mapped = keysym;
266
        // Digits are mapped 1:1.
267
        else if (keysym >= Latin1.NUM_0 && keysym <= Latin1.NUM_9)
268
          mapped = keysym;
269
        else
270
          {
271
            switch (keysym)
272
            {
273
              case Latin1.SPACE:
274
                mapped = KeyEvent.VK_SPACE;
275
                break;
276
              case Latin1.EXCLAM:
277
                mapped = KeyEvent.VK_EXCLAMATION_MARK;
278
                break;
279
              case Latin1.QUOTE_DBL:
280
                mapped = KeyEvent.VK_QUOTEDBL;
281
                break;
282
              case Latin1.NUMBER_SIGN:
283
                mapped = KeyEvent.VK_NUMBER_SIGN;
284
                break;
285
              case Latin1.DOLLAR:
286
                mapped = KeyEvent.VK_DOLLAR;
287
                break;
288
              case Latin1.AMPERSAND:
289
                mapped = KeyEvent.VK_AMPERSAND;
290
                break;
291
              case Latin1.APOSTROPHE:
292
                mapped = KeyEvent.VK_QUOTE;
293
                break;
294
              case Latin1.PAREN_LEFT:
295
                mapped = KeyEvent.VK_LEFT_PARENTHESIS;
296
                break;
297
              case Latin1.PAREN_RIGHT:
298
                mapped = KeyEvent.VK_RIGHT_PARENTHESIS;
299
                break;
300
              case Latin1.ASTERISK:
301
                mapped = KeyEvent.VK_ASTERISK;
302
                break;
303
              case Latin1.PLUS:
304
                mapped = KeyEvent.VK_PLUS;
305
                break;
306
              case Latin1.COMMA:
307
                mapped = KeyEvent.VK_COMMA;
308
                break;
309
              case Latin1.MINUS:
310
                mapped = KeyEvent.VK_MINUS;
311
                break;
312
              case Latin1.PERIOD:
313
                mapped = KeyEvent.VK_PERIOD;
314
                break;
315
              case Latin1.SLASH:
316
                mapped = KeyEvent.VK_SLASH;
317
                break;
318
              case Latin1.COLON:
319
                mapped = KeyEvent.VK_COLON;
320
                break;
321
              case Latin1.SEMICOLON:
322
                mapped = KeyEvent.VK_SEMICOLON;
323
                break;
324
              case Latin1.LESS:
325
                mapped = KeyEvent.VK_LESS;
326
                break;
327
              case Latin1.EQUAL:
328
                mapped = KeyEvent.VK_EQUALS;
329
                break;
330
              case Latin1.GREATER:
331
                mapped = KeyEvent.VK_GREATER;
332
                break;
333
              case Latin1.AT:
334
                mapped = KeyEvent.VK_AT;
335
                break;
336
              case Latin1.BRACKET_LEFT:
337
                mapped = KeyEvent.VK_OPEN_BRACKET;
338
                break;
339
              case Latin1.BACKSLASH:
340
                mapped = KeyEvent.VK_BACK_SLASH;
341
                break;
342
              case Latin1.BRACKET_RIGHT:
343
                mapped = KeyEvent.VK_CLOSE_BRACKET;
344
                break;
345
              case Latin1.ASCII_CIRCUM:
346
                mapped = KeyEvent.VK_CIRCUMFLEX;
347
                break;
348
              case Latin1.UNDERSCORE:
349
                mapped = KeyEvent.VK_UNDERSCORE;
350
                break;
351
              case Latin1.GRAVE:
352
                mapped = KeyEvent.VK_DEAD_GRAVE;
353
                break;
354
              case Latin1.BRACE_LEFT:
355
                mapped = KeyEvent.VK_BRACELEFT;
356
                break;
357
              case Latin1.BRACE_RIGHT:
358
                mapped = KeyEvent.VK_BRACERIGHT;
359
                break;
360
              case Latin1.ASCII_TILDE:
361
                mapped = KeyEvent.VK_DEAD_TILDE;
362
                break;
363
              case Latin1.EXCLAM_DOWN:
364
                mapped = KeyEvent.VK_INVERTED_EXCLAMATION_MARK;
365
                break;
366
              default:
367
                mapped = KeyEvent.VK_UNDEFINED;
368
            }
369
          }
370
      }
371
    return mapped;
372
  }
373
 
374
  /**
375
   * Maps X keycodes+modifiers to Java keychars.
376
   *
377
   * @param xInput The X Input to use for mapping
378
   * @param xKeyCode the X keycode
379
   * @param xMods the X key modifiers
380
   *
381
   * @return the Java keychar
382
   */
383
  static char mapToKeyChar(gnu.x11.Input xInput, int xKeyCode, int xMods)
384
  {
385
    char mapped = KeyEvent.CHAR_UNDEFINED;
386
    char keysym = (char) xInput.keycode_to_keysym(xKeyCode, xMods, false);
387
    // FIXME: Map other encodings properly.
388
    if (keysym < 256) // Latin1.
389
      {
390
        mapped = keysym;
391
      }
392
    return mapped;
393
  }
394
 
395
  /**
396
   * Maps X modifier masks to AWT modifier masks.
397
   *
398
   * @param xMods the X modifiers
399
   *
400
   * @return the AWT modifiers
401
   */
402
  static int mapModifiers(int xMods)
403
  {
404
    int mods = 0;
405
 
406
    if ((xMods & Input.SHIFT_MASK) != 0)
407
      mods |= KeyEvent.SHIFT_MASK | KeyEvent.SHIFT_DOWN_MASK;
408
    if ((xMods & Input.META_MASK) != 0)
409
      mods |= KeyEvent.META_MASK | KeyEvent.META_DOWN_MASK;
410
    if ((xMods & Input.ALT_MASK) != 0)
411
      mods |= KeyEvent.ALT_MASK | KeyEvent.ALT_DOWN_MASK;
412
    if ((xMods & Input.MOD5_MASK) != 0)
413
      mods |= KeyEvent.ALT_GRAPH_MASK | KeyEvent.ALT_GRAPH_DOWN_MASK;
414
    if ((xMods & Input.CONTROL_MASK) != 0)
415
      mods |= KeyEvent.CTRL_MASK | KeyEvent.CTRL_DOWN_MASK;
416
 
417
    return mods;
418
  }
419
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.