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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tk/] [mac/] [tkMacKeyboard.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tkMacKeyboard.c --
3
 *
4
 *      Routines to support keyboard events on the Macintosh.
5
 *
6
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
7
 *
8
 * See the file "license.terms" for information on usage and redistribution
9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10
 *
11
 * RCS: @(#) $Id: tkMacKeyboard.c,v 1.1.1.1 2002-01-16 10:25:55 markom Exp $
12
 */
13
 
14
#include "tkInt.h"
15
#include "Xlib.h"
16
#include "keysym.h"
17
 
18
#include <Events.h>
19
#include <Script.h>
20
 
21
typedef struct {
22
    short keycode;              /* Macintosh keycode */
23
    KeySym keysym;              /* X windows Keysym */
24
} KeyInfo;
25
 
26
static KeyInfo keyArray[] = {
27
    {0x4C,      XK_Return},
28
    {0x24,      XK_Return},
29
    {0x33,      XK_BackSpace},
30
    {0x75,      XK_Delete},
31
    {0x30,      XK_Tab},
32
    {0x74,      XK_Page_Up},
33
    {0x79,      XK_Page_Down},
34
    {0x73,      XK_Home},
35
    {0x77,      XK_End},
36
    {0x7B,      XK_Left},
37
    {0x7C,      XK_Right},
38
    {0x7E,      XK_Up},
39
    {0x7D,      XK_Down},
40
    {0x72,      XK_Help},
41
    {0x35,      XK_Escape},
42
    {0x47,      XK_Clear},
43
    {0,          0}
44
};
45
 
46
static KeyInfo vituralkeyArray[] = {
47
    {122,       XK_F1},
48
    {120,       XK_F2},
49
    {99,        XK_F3},
50
    {118,       XK_F4},
51
    {96,        XK_F5},
52
    {97,        XK_F6},
53
    {98,        XK_F7},
54
    {100,       XK_F8},
55
    {101,       XK_F9},
56
    {109,       XK_F10},
57
    {103,       XK_F11},
58
    {111,       XK_F12},
59
    {105,       XK_F13},
60
    {107,       XK_F14},
61
    {113,       XK_F15},
62
    {0,          0}
63
};
64
 
65
static int initialized = 0;
66
static Tcl_HashTable keycodeTable;      /* keyArray hashed by keycode value. */
67
static Tcl_HashTable vkeyTable;         /* vituralkeyArray hashed by virtual
68
                                           keycode value. */
69
static Ptr KCHRPtr;                     /* Pointer to 'KCHR' resource. */
70
 
71
/*
72
 * Prototypes for static functions used in this file.
73
 */
74
static void     InitKeyMaps _ANSI_ARGS_((void));
75
 
76
 
77
/*
78
 *----------------------------------------------------------------------
79
 *
80
 * InitKeyMaps --
81
 *
82
 *      Creates hash tables used by some of the functions in this file.
83
 *
84
 * Results:
85
 *      None.
86
 *
87
 * Side effects:
88
 *      Allocates memory & creates some hash tables.
89
 *
90
 *----------------------------------------------------------------------
91
 */
92
 
93
static void
94
InitKeyMaps()
95
{
96
    register Tcl_HashEntry *hPtr;
97
    register KeyInfo *kPtr;
98
    int dummy;
99
 
100
    Tcl_InitHashTable(&keycodeTable, TCL_ONE_WORD_KEYS);
101
    for (kPtr = keyArray; kPtr->keycode != 0; kPtr++) {
102
        hPtr = Tcl_CreateHashEntry(&keycodeTable, (char *) kPtr->keycode,
103
                &dummy);
104
        Tcl_SetHashValue(hPtr, kPtr->keysym);
105
    }
106
    Tcl_InitHashTable(&vkeyTable, TCL_ONE_WORD_KEYS);
107
    for (kPtr = vituralkeyArray; kPtr->keycode != 0; kPtr++) {
108
        hPtr = Tcl_CreateHashEntry(&vkeyTable, (char *) kPtr->keycode,
109
                &dummy);
110
        Tcl_SetHashValue(hPtr, kPtr->keysym);
111
    }
112
    KCHRPtr = (Ptr) GetScriptManagerVariable(smKCHRCache);
113
    initialized = 1;
114
}
115
 
116
/*
117
 *----------------------------------------------------------------------
118
 *
119
 * XKeycodeToKeysym --
120
 *
121
 *      Translate from a system-dependent keycode to a
122
 *      system-independent keysym.
123
 *
124
 * Results:
125
 *      Returns the translated keysym, or NoSymbol on failure.
126
 *
127
 * Side effects:
128
 *      None.
129
 *
130
 *----------------------------------------------------------------------
131
 */
132
 
133
KeySym
134
XKeycodeToKeysym(
135
    Display* display,
136
    KeyCode keycode,
137
    int index)
138
{
139
    register Tcl_HashEntry *hPtr;
140
    register char c;
141
    char virtualKey;
142
    int newKeycode;
143
    unsigned long dummy, newChar;
144
 
145
    if (!initialized) {
146
        InitKeyMaps();
147
    }
148
 
149
    c = keycode & charCodeMask;
150
    virtualKey = (keycode & keyCodeMask) >> 8;
151
 
152
    /*
153
     * When determining what keysym to produce we firt check to see if
154
     * the key is a function key.  We then check to see if the character
155
     * is another non-printing key.  Finally, we return the key syms
156
     * for all ASCI chars.
157
     */
158
    if (c == 0x10) {
159
        hPtr = Tcl_FindHashEntry(&vkeyTable, (char *) virtualKey);
160
        if (hPtr != NULL) {
161
            return (KeySym) Tcl_GetHashValue(hPtr);
162
        }
163
    }
164
 
165
 
166
    hPtr = Tcl_FindHashEntry(&keycodeTable, (char *) virtualKey);
167
    if (hPtr != NULL) {
168
        return (KeySym) Tcl_GetHashValue(hPtr);
169
    }
170
 
171
    /*
172
     * Recompute the character based on the Shift key only.
173
     * TODO: The index may also specify the NUM_LOCK.
174
     */
175
    newKeycode = virtualKey;
176
    if (index & 0x01) {
177
        newKeycode += 0x0200;
178
    }
179
    dummy = 0;
180
    newChar = KeyTranslate(KCHRPtr, (short) newKeycode, &dummy);
181
    c = newChar & charCodeMask;
182
 
183
    if (c >= XK_space && c < XK_asciitilde) {
184
        return c;
185
    }
186
 
187
    return NoSymbol;
188
}
189
 
190
/*
191
 *----------------------------------------------------------------------
192
 *
193
 * XLookupString --
194
 *
195
 *      Retrieve the string equivalent for the given keyboard event.
196
 *
197
 * Results:
198
 *      Returns the number of characters stored in buffer_return.
199
 *
200
 * Side effects:
201
 *      Retrieves the characters stored in the event and inserts them
202
 *      into buffer_return.
203
 *
204
 *----------------------------------------------------------------------
205
 */
206
 
207
int
208
XLookupString(
209
    XKeyEvent* event_struct,
210
    char* buffer_return,
211
    int bytes_buffer,
212
    KeySym* keysym_return,
213
    XComposeStatus* status_in_out)
214
{
215
    register Tcl_HashEntry *hPtr;
216
    char string[3];
217
    char virtualKey;
218
    char c;
219
 
220
    if (!initialized) {
221
        InitKeyMaps();
222
    }
223
 
224
    c = event_struct->keycode & charCodeMask;
225
    string[0] = c;
226
    string[1] = '\0';
227
 
228
    /*
229
     * Just return NULL if the character is a function key or another
230
     * non-printing key.
231
     */
232
    if (c == 0x10) {
233
        string[0] = '\0';
234
    } else {
235
        virtualKey = (event_struct->keycode & keyCodeMask) >> 8;
236
        hPtr = Tcl_FindHashEntry(&keycodeTable, (char *) virtualKey);
237
        if (hPtr != NULL) {
238
            string[0] = '\0';
239
        }
240
    }
241
 
242
    if (buffer_return != NULL) {
243
        strncpy(buffer_return, string, bytes_buffer);
244
    }
245
 
246
    return strlen(string);
247
}
248
 
249
/*
250
 *----------------------------------------------------------------------
251
 *
252
 * XGetModifierMapping --
253
 *
254
 *      Fetch the current keycodes used as modifiers.
255
 *
256
 * Results:
257
 *      Returns a new modifier map.
258
 *
259
 * Side effects:
260
 *      Allocates a new modifier map data structure.
261
 *
262
 *----------------------------------------------------------------------
263
 */
264
 
265
XModifierKeymap *
266
XGetModifierMapping(
267
    Display* display)
268
{
269
    XModifierKeymap * modmap;
270
 
271
    modmap = (XModifierKeymap *) ckalloc(sizeof(XModifierKeymap));
272
    modmap->max_keypermod = 0;
273
    modmap->modifiermap = NULL;
274
    return modmap;
275
}
276
 
277
/*
278
 *----------------------------------------------------------------------
279
 *
280
 * XFreeModifiermap --
281
 *
282
 *      Deallocate a modifier map that was created by
283
 *      XGetModifierMapping.
284
 *
285
 * Results:
286
 *      None.
287
 *
288
 * Side effects:
289
 *      Frees the datastructure referenced by modmap.
290
 *
291
 *----------------------------------------------------------------------
292
 */
293
 
294
void
295
XFreeModifiermap(
296
    XModifierKeymap *modmap)
297
{
298
    if (modmap->modifiermap != NULL) {
299
        ckfree((char *) modmap->modifiermap);
300
    }
301
    ckfree((char *) modmap);
302
}
303
 
304
/*
305
 *----------------------------------------------------------------------
306
 *
307
 * XKeysymToString, XStringToKeysym --
308
 *
309
 *      These X window functions map Keysyms to strings & strings to
310
 *      keysyms.  However, Tk already does this for the most common keysyms.
311
 *      Therefor, these functions only need to support keysyms that will be
312
 *      specific to the Macintosh.  Currently, there are none.
313
 *
314
 * Results:
315
 *      None.
316
 *
317
 * Side effects:
318
 *      None.
319
 *
320
 *----------------------------------------------------------------------
321
 */
322
 
323
char *
324
XKeysymToString(
325
    KeySym keysym)
326
{
327
    return NULL;
328
}
329
 
330
KeySym
331
XStringToKeysym(
332
    const char* string)
333
{
334
    return NoSymbol;
335
}
336
 
337
/*
338
 *----------------------------------------------------------------------
339
 *
340
 * XKeysymToKeycode --
341
 *
342
 *      The function XKeysymToKeycode is only used by tkTest.c and
343
 *      currently only implementes the support for keys used in the
344
 *      Tk test suite.
345
 *
346
 * Results:
347
 *      None.
348
 *
349
 * Side effects:
350
 *      None.
351
 *
352
 *----------------------------------------------------------------------
353
 */
354
 
355
KeyCode
356
XKeysymToKeycode(
357
    Display* display,
358
    KeySym keysym)
359
{
360
    KeyCode keycode = 0;
361
    char virtualKeyCode = 0;
362
 
363
    if ((keysym >= XK_space) && (XK_asciitilde)) {
364
        if (keysym == 'a') {
365
            virtualKeyCode = 0x00;
366
        } else if (keysym == 'b' || keysym == 'B') {
367
            virtualKeyCode = 0x0B;
368
        } else if (keysym == 'c') {
369
            virtualKeyCode = 0x08;
370
        } else if (keysym == 'x' || keysym == 'X') {
371
            virtualKeyCode = 0x07;
372
        } else if (keysym == 'z') {
373
            virtualKeyCode = 0x06;
374
        } else if (keysym == ' ') {
375
            virtualKeyCode = 0x31;
376
        } else if (keysym == XK_Return) {
377
            virtualKeyCode = 0x24;
378
            keysym = '\r';
379
        }
380
        keycode = keysym + ((virtualKeyCode << 8) & keyCodeMask);
381
    }
382
 
383
    return keycode;
384
}

powered by: WebSVN 2.1.0

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