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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [win/] [tkWinKey.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tkWinKey.c --
3
 *
4
 *      This file contains X emulation routines for keyboard related
5
 *      functions.
6
 *
7
 * Copyright (c) 1995 Sun Microsystems, Inc.
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 * RCS: @(#) $Id: tkWinKey.c,v 1.1.1.1 2002-01-16 10:26:02 markom Exp $
13
 */
14
 
15
#include "tkWinInt.h"
16
 
17
/*
18
 * FIXME - these are in i386-cygwin32/includes/Windows32/Defines.h
19
 * but not in the current Progressive release...
20
 */
21
 
22
#ifdef __CYGWIN32__
23
#define VK_LWIN (91)
24
#define VK_RWIN (92)
25
#define VK_APPS (93)
26
#endif
27
 
28
typedef struct {
29
    unsigned int keycode;
30
    KeySym keysym;
31
} Keys;
32
 
33
static Keys keymap[] = {
34
    VK_CANCEL, XK_Cancel,
35
    VK_BACK, XK_BackSpace,
36
    VK_TAB, XK_Tab,
37
    VK_CLEAR, XK_Clear,
38
    VK_RETURN, XK_Return,
39
    VK_SHIFT, XK_Shift_L,
40
    VK_CONTROL, XK_Control_L,
41
    VK_MENU, XK_Alt_L,
42
    VK_PAUSE, XK_Pause,
43
    VK_CAPITAL, XK_Caps_Lock,
44
    VK_ESCAPE, XK_Escape,
45
    VK_SPACE, XK_space,
46
    VK_PRIOR, XK_Prior,
47
    VK_NEXT, XK_Next,
48
    VK_END, XK_End,
49
    VK_HOME, XK_Home,
50
    VK_LEFT, XK_Left,
51
    VK_UP, XK_Up,
52
    VK_RIGHT, XK_Right,
53
    VK_DOWN, XK_Down,
54
    VK_SELECT, XK_Select,
55
    VK_PRINT, XK_Print,
56
    VK_EXECUTE, XK_Execute,
57
    VK_INSERT, XK_Insert,
58
    VK_DELETE, XK_Delete,
59
    VK_HELP, XK_Help,
60
    VK_F1, XK_F1,
61
    VK_F2, XK_F2,
62
    VK_F3, XK_F3,
63
    VK_F4, XK_F4,
64
    VK_F5, XK_F5,
65
    VK_F6, XK_F6,
66
    VK_F7, XK_F7,
67
    VK_F8, XK_F8,
68
    VK_F9, XK_F9,
69
    VK_F10, XK_F10,
70
    VK_F11, XK_F11,
71
    VK_F12, XK_F12,
72
    VK_F13, XK_F13,
73
    VK_F14, XK_F14,
74
    VK_F15, XK_F15,
75
    VK_F16, XK_F16,
76
    VK_F17, XK_F17,
77
    VK_F18, XK_F18,
78
    VK_F19, XK_F19,
79
    VK_F20, XK_F20,
80
    VK_F21, XK_F21,
81
    VK_F22, XK_F22,
82
    VK_F23, XK_F23,
83
    VK_F24, XK_F24,
84
    VK_NUMLOCK, XK_Num_Lock,
85
    VK_SCROLL, XK_Scroll_Lock,
86
 
87
    /*
88
     * The following support the new keys in the Microsoft keyboard.
89
     * Win_L and Win_R have the windows logo.  App has the menu.
90
     */
91
 
92
    VK_LWIN, XK_Win_L,
93
    VK_RWIN, XK_Win_R,
94
    VK_APPS, XK_App,
95
 
96
    0, NoSymbol
97
};
98
 
99
 
100
/*
101
 *----------------------------------------------------------------------
102
 *
103
 * XLookupString --
104
 *
105
 *      Retrieve the string equivalent for the given keyboard event.
106
 *
107
 * Results:
108
 *      Returns the number of characters stored in buffer_return.
109
 *
110
 * Side effects:
111
 *      Retrieves the characters stored in the event and inserts them
112
 *      into buffer_return.
113
 *
114
 *----------------------------------------------------------------------
115
 */
116
 
117
int
118
XLookupString(event_struct, buffer_return, bytes_buffer, keysym_return,
119
        status_in_out)
120
    XKeyEvent* event_struct;
121
    char* buffer_return;
122
    int bytes_buffer;
123
    KeySym* keysym_return;
124
    XComposeStatus* status_in_out;
125
{
126
    int i, limit;
127
 
128
    if (event_struct->send_event != -1) {
129
        /*
130
         * This is an event generated from generic code.  It has no
131
         * nchars or trans_chars members.
132
         */
133
 
134
        int index;
135
        KeySym keysym;
136
 
137
        index = 0;
138
        if (event_struct->state & ShiftMask) {
139
            index |= 1;
140
        }
141
        if (event_struct->state & Mod1Mask) {
142
            index |= 2;
143
        }
144
        keysym = XKeycodeToKeysym(event_struct->display,
145
                event_struct->keycode, index);
146
        if (((keysym != NoSymbol) && (keysym > 0) && (keysym < 256))
147
                || (keysym == XK_Return)
148
                || (keysym == XK_Tab)) {
149
            buffer_return[0] = (char) keysym;
150
            return 1;
151
        }
152
        return 0;
153
    }
154
    if ((event_struct->nchars <= 0) || (buffer_return == NULL)) {
155
        return 0;
156
    }
157
    limit = (event_struct->nchars < bytes_buffer) ? event_struct->nchars :
158
        bytes_buffer;
159
 
160
    for (i = 0; i < limit; i++) {
161
        buffer_return[i] = event_struct->trans_chars[i];
162
    }
163
 
164
    if (keysym_return != NULL) {
165
        *keysym_return = NoSymbol;
166
    }
167
    return i;
168
}
169
 
170
/*
171
 *----------------------------------------------------------------------
172
 *
173
 * XKeycodeToKeysym --
174
 *
175
 *      Translate from a system-dependent keycode to a
176
 *      system-independent keysym.
177
 *
178
 * Results:
179
 *      Returns the translated keysym, or NoSymbol on failure.
180
 *
181
 * Side effects:
182
 *      None.
183
 *
184
 *----------------------------------------------------------------------
185
 */
186
 
187
KeySym
188
XKeycodeToKeysym(display, keycode, index)
189
    Display* display;
190
    unsigned int keycode;
191
    int index;
192
{
193
    Keys* key;
194
    BYTE keys[256];
195
    int result;
196
    char buf[4];
197
    unsigned int scancode = MapVirtualKey(keycode, 0);
198
 
199
    memset(keys, 0, 256);
200
    if (index & 0x02) {
201
        keys[VK_NUMLOCK] = 1;
202
    }
203
    if (index & 0x01) {
204
        keys[VK_SHIFT] = 0x80;
205
    }
206
    result = ToAscii(keycode, scancode, keys, (LPWORD) buf, 0);
207
 
208
    /*
209
     * Keycode mapped to a valid Latin-1 character.  Since the keysyms
210
     * for alphanumeric characters map onto Latin-1, we just return it.
211
     */
212
 
213
    if (result == 1 && buf[0] >= 0x20) {
214
        return (KeySym) buf[0];
215
    }
216
 
217
    /*
218
     * Keycode is a non-alphanumeric key, so we have to do the lookup.
219
     */
220
 
221
    for (key = keymap; key->keycode != 0; key++) {
222
        if (key->keycode == keycode) {
223
            return key->keysym;
224
        }
225
    }
226
 
227
    return NoSymbol;
228
}
229
 
230
/*
231
 *----------------------------------------------------------------------
232
 *
233
 * XKeysymToKeycode --
234
 *
235
 *      Translate a keysym back into a keycode.
236
 *
237
 * Results:
238
 *      Returns the keycode that would generate the specified keysym.
239
 *
240
 * Side effects:
241
 *      None.
242
 *
243
 *----------------------------------------------------------------------
244
 */
245
 
246
KeyCode
247
XKeysymToKeycode(display, keysym)
248
    Display* display;
249
    KeySym keysym;
250
{
251
    Keys* key;
252
    SHORT result;
253
 
254
    if (keysym >= 0x20) {
255
        result = VkKeyScan((char) keysym);
256
        if (result != -1) {
257
            return (KeyCode) (result & 0xff);
258
        }
259
    }
260
 
261
    /*
262
     * Couldn't map the character to a virtual keycode, so do a
263
     * table lookup.
264
     */
265
 
266
    for (key = keymap; key->keycode != 0; key++) {
267
        if (key->keysym == keysym) {
268
            return key->keycode;
269
        }
270
    }
271
    return 0;
272
}
273
 
274
/*
275
 *----------------------------------------------------------------------
276
 *
277
 * XGetModifierMapping --
278
 *
279
 *      Fetch the current keycodes used as modifiers.
280
 *
281
 * Results:
282
 *      Returns a new modifier map.
283
 *
284
 * Side effects:
285
 *      Allocates a new modifier map data structure.
286
 *
287
 *----------------------------------------------------------------------
288
 */
289
 
290
XModifierKeymap *
291
XGetModifierMapping(display)
292
    Display* display;
293
{
294
    XModifierKeymap *map = (XModifierKeymap *)ckalloc(sizeof(XModifierKeymap));
295
 
296
    map->max_keypermod = 1;
297
    map->modifiermap = (KeyCode *) ckalloc(sizeof(KeyCode)*8);
298
    map->modifiermap[ShiftMapIndex] = VK_SHIFT;
299
    map->modifiermap[LockMapIndex] = VK_CAPITAL;
300
    map->modifiermap[ControlMapIndex] = VK_CONTROL;
301
    map->modifiermap[Mod1MapIndex] = VK_NUMLOCK;
302
    map->modifiermap[Mod2MapIndex] = VK_MENU;
303
    map->modifiermap[Mod3MapIndex] = VK_SCROLL;
304
    map->modifiermap[Mod4MapIndex] = 0;
305
    map->modifiermap[Mod5MapIndex] = 0;
306
    return map;
307
}
308
 
309
/*
310
 *----------------------------------------------------------------------
311
 *
312
 * XFreeModifiermap --
313
 *
314
 *      Deallocate a modifier map that was created by
315
 *      XGetModifierMapping.
316
 *
317
 * Results:
318
 *      None.
319
 *
320
 * Side effects:
321
 *      Frees the datastructure referenced by modmap.
322
 *
323
 *----------------------------------------------------------------------
324
 */
325
 
326
void
327
XFreeModifiermap(modmap)
328
    XModifierKeymap* modmap;
329
{
330
    ckfree((char *) modmap->modifiermap);
331
    ckfree((char *) modmap);
332
}
333
 
334
/*
335
 *----------------------------------------------------------------------
336
 *
337
 * XStringToKeysym --
338
 *
339
 *      Translate a keysym name to the matching keysym.
340
 *
341
 * Results:
342
 *      Returns the keysym.  Since this is already handled by
343
 *      Tk's StringToKeysym function, we just return NoSymbol.
344
 *
345
 * Side effects:
346
 *      None.
347
 *
348
 *----------------------------------------------------------------------
349
 */
350
 
351
KeySym
352
XStringToKeysym(string)
353
    _Xconst char *string;
354
{
355
    return NoSymbol;
356
}
357
 
358
/*
359
 *----------------------------------------------------------------------
360
 *
361
 * XKeysymToString --
362
 *
363
 *      Convert a keysym to character form.
364
 *
365
 * Results:
366
 *      Returns NULL, since Tk will have handled this already.
367
 *
368
 * Side effects:
369
 *      None.
370
 *
371
 *----------------------------------------------------------------------
372
 */
373
 
374
char *
375
XKeysymToString(keysym)
376
    KeySym keysym;
377
{
378
    return NULL;
379
}
380
 
381
 

powered by: WebSVN 2.1.0

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