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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [mac/] [tkMacKeyboard.c] - Diff between revs 579 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/*
/*
 * tkMacKeyboard.c --
 * tkMacKeyboard.c --
 *
 *
 *      Routines to support keyboard events on the Macintosh.
 *      Routines to support keyboard events on the Macintosh.
 *
 *
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 *
 *
 * See the file "license.terms" for information on usage and redistribution
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 *
 * RCS: @(#) $Id: tkMacKeyboard.c,v 1.1.1.1 2002-01-16 10:25:55 markom Exp $
 * RCS: @(#) $Id: tkMacKeyboard.c,v 1.1.1.1 2002-01-16 10:25:55 markom Exp $
 */
 */
 
 
#include "tkInt.h"
#include "tkInt.h"
#include "Xlib.h"
#include "Xlib.h"
#include "keysym.h"
#include "keysym.h"
 
 
#include <Events.h>
#include <Events.h>
#include <Script.h>
#include <Script.h>
 
 
typedef struct {
typedef struct {
    short keycode;              /* Macintosh keycode */
    short keycode;              /* Macintosh keycode */
    KeySym keysym;              /* X windows Keysym */
    KeySym keysym;              /* X windows Keysym */
} KeyInfo;
} KeyInfo;
 
 
static KeyInfo keyArray[] = {
static KeyInfo keyArray[] = {
    {0x4C,      XK_Return},
    {0x4C,      XK_Return},
    {0x24,      XK_Return},
    {0x24,      XK_Return},
    {0x33,      XK_BackSpace},
    {0x33,      XK_BackSpace},
    {0x75,      XK_Delete},
    {0x75,      XK_Delete},
    {0x30,      XK_Tab},
    {0x30,      XK_Tab},
    {0x74,      XK_Page_Up},
    {0x74,      XK_Page_Up},
    {0x79,      XK_Page_Down},
    {0x79,      XK_Page_Down},
    {0x73,      XK_Home},
    {0x73,      XK_Home},
    {0x77,      XK_End},
    {0x77,      XK_End},
    {0x7B,      XK_Left},
    {0x7B,      XK_Left},
    {0x7C,      XK_Right},
    {0x7C,      XK_Right},
    {0x7E,      XK_Up},
    {0x7E,      XK_Up},
    {0x7D,      XK_Down},
    {0x7D,      XK_Down},
    {0x72,      XK_Help},
    {0x72,      XK_Help},
    {0x35,      XK_Escape},
    {0x35,      XK_Escape},
    {0x47,      XK_Clear},
    {0x47,      XK_Clear},
    {0,          0}
    {0,          0}
};
};
 
 
static KeyInfo vituralkeyArray[] = {
static KeyInfo vituralkeyArray[] = {
    {122,       XK_F1},
    {122,       XK_F1},
    {120,       XK_F2},
    {120,       XK_F2},
    {99,        XK_F3},
    {99,        XK_F3},
    {118,       XK_F4},
    {118,       XK_F4},
    {96,        XK_F5},
    {96,        XK_F5},
    {97,        XK_F6},
    {97,        XK_F6},
    {98,        XK_F7},
    {98,        XK_F7},
    {100,       XK_F8},
    {100,       XK_F8},
    {101,       XK_F9},
    {101,       XK_F9},
    {109,       XK_F10},
    {109,       XK_F10},
    {103,       XK_F11},
    {103,       XK_F11},
    {111,       XK_F12},
    {111,       XK_F12},
    {105,       XK_F13},
    {105,       XK_F13},
    {107,       XK_F14},
    {107,       XK_F14},
    {113,       XK_F15},
    {113,       XK_F15},
    {0,          0}
    {0,          0}
};
};
 
 
static int initialized = 0;
static int initialized = 0;
static Tcl_HashTable keycodeTable;      /* keyArray hashed by keycode value. */
static Tcl_HashTable keycodeTable;      /* keyArray hashed by keycode value. */
static Tcl_HashTable vkeyTable;         /* vituralkeyArray hashed by virtual
static Tcl_HashTable vkeyTable;         /* vituralkeyArray hashed by virtual
                                           keycode value. */
                                           keycode value. */
static Ptr KCHRPtr;                     /* Pointer to 'KCHR' resource. */
static Ptr KCHRPtr;                     /* Pointer to 'KCHR' resource. */
 
 
/*
/*
 * Prototypes for static functions used in this file.
 * Prototypes for static functions used in this file.
 */
 */
static void     InitKeyMaps _ANSI_ARGS_((void));
static void     InitKeyMaps _ANSI_ARGS_((void));
 
 


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * InitKeyMaps --
 * InitKeyMaps --
 *
 *
 *      Creates hash tables used by some of the functions in this file.
 *      Creates hash tables used by some of the functions in this file.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Allocates memory & creates some hash tables.
 *      Allocates memory & creates some hash tables.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
static void
static void
InitKeyMaps()
InitKeyMaps()
{
{
    register Tcl_HashEntry *hPtr;
    register Tcl_HashEntry *hPtr;
    register KeyInfo *kPtr;
    register KeyInfo *kPtr;
    int dummy;
    int dummy;
 
 
    Tcl_InitHashTable(&keycodeTable, TCL_ONE_WORD_KEYS);
    Tcl_InitHashTable(&keycodeTable, TCL_ONE_WORD_KEYS);
    for (kPtr = keyArray; kPtr->keycode != 0; kPtr++) {
    for (kPtr = keyArray; kPtr->keycode != 0; kPtr++) {
        hPtr = Tcl_CreateHashEntry(&keycodeTable, (char *) kPtr->keycode,
        hPtr = Tcl_CreateHashEntry(&keycodeTable, (char *) kPtr->keycode,
                &dummy);
                &dummy);
        Tcl_SetHashValue(hPtr, kPtr->keysym);
        Tcl_SetHashValue(hPtr, kPtr->keysym);
    }
    }
    Tcl_InitHashTable(&vkeyTable, TCL_ONE_WORD_KEYS);
    Tcl_InitHashTable(&vkeyTable, TCL_ONE_WORD_KEYS);
    for (kPtr = vituralkeyArray; kPtr->keycode != 0; kPtr++) {
    for (kPtr = vituralkeyArray; kPtr->keycode != 0; kPtr++) {
        hPtr = Tcl_CreateHashEntry(&vkeyTable, (char *) kPtr->keycode,
        hPtr = Tcl_CreateHashEntry(&vkeyTable, (char *) kPtr->keycode,
                &dummy);
                &dummy);
        Tcl_SetHashValue(hPtr, kPtr->keysym);
        Tcl_SetHashValue(hPtr, kPtr->keysym);
    }
    }
    KCHRPtr = (Ptr) GetScriptManagerVariable(smKCHRCache);
    KCHRPtr = (Ptr) GetScriptManagerVariable(smKCHRCache);
    initialized = 1;
    initialized = 1;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XKeycodeToKeysym --
 * XKeycodeToKeysym --
 *
 *
 *      Translate from a system-dependent keycode to a
 *      Translate from a system-dependent keycode to a
 *      system-independent keysym.
 *      system-independent keysym.
 *
 *
 * Results:
 * Results:
 *      Returns the translated keysym, or NoSymbol on failure.
 *      Returns the translated keysym, or NoSymbol on failure.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
KeySym
KeySym
XKeycodeToKeysym(
XKeycodeToKeysym(
    Display* display,
    Display* display,
    KeyCode keycode,
    KeyCode keycode,
    int index)
    int index)
{
{
    register Tcl_HashEntry *hPtr;
    register Tcl_HashEntry *hPtr;
    register char c;
    register char c;
    char virtualKey;
    char virtualKey;
    int newKeycode;
    int newKeycode;
    unsigned long dummy, newChar;
    unsigned long dummy, newChar;
 
 
    if (!initialized) {
    if (!initialized) {
        InitKeyMaps();
        InitKeyMaps();
    }
    }
 
 
    c = keycode & charCodeMask;
    c = keycode & charCodeMask;
    virtualKey = (keycode & keyCodeMask) >> 8;
    virtualKey = (keycode & keyCodeMask) >> 8;
 
 
    /*
    /*
     * When determining what keysym to produce we firt check to see if
     * When determining what keysym to produce we firt check to see if
     * the key is a function key.  We then check to see if the character
     * the key is a function key.  We then check to see if the character
     * is another non-printing key.  Finally, we return the key syms
     * is another non-printing key.  Finally, we return the key syms
     * for all ASCI chars.
     * for all ASCI chars.
     */
     */
    if (c == 0x10) {
    if (c == 0x10) {
        hPtr = Tcl_FindHashEntry(&vkeyTable, (char *) virtualKey);
        hPtr = Tcl_FindHashEntry(&vkeyTable, (char *) virtualKey);
        if (hPtr != NULL) {
        if (hPtr != NULL) {
            return (KeySym) Tcl_GetHashValue(hPtr);
            return (KeySym) Tcl_GetHashValue(hPtr);
        }
        }
    }
    }
 
 
 
 
    hPtr = Tcl_FindHashEntry(&keycodeTable, (char *) virtualKey);
    hPtr = Tcl_FindHashEntry(&keycodeTable, (char *) virtualKey);
    if (hPtr != NULL) {
    if (hPtr != NULL) {
        return (KeySym) Tcl_GetHashValue(hPtr);
        return (KeySym) Tcl_GetHashValue(hPtr);
    }
    }
 
 
    /*
    /*
     * Recompute the character based on the Shift key only.
     * Recompute the character based on the Shift key only.
     * TODO: The index may also specify the NUM_LOCK.
     * TODO: The index may also specify the NUM_LOCK.
     */
     */
    newKeycode = virtualKey;
    newKeycode = virtualKey;
    if (index & 0x01) {
    if (index & 0x01) {
        newKeycode += 0x0200;
        newKeycode += 0x0200;
    }
    }
    dummy = 0;
    dummy = 0;
    newChar = KeyTranslate(KCHRPtr, (short) newKeycode, &dummy);
    newChar = KeyTranslate(KCHRPtr, (short) newKeycode, &dummy);
    c = newChar & charCodeMask;
    c = newChar & charCodeMask;
 
 
    if (c >= XK_space && c < XK_asciitilde) {
    if (c >= XK_space && c < XK_asciitilde) {
        return c;
        return c;
    }
    }
 
 
    return NoSymbol;
    return NoSymbol;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XLookupString --
 * XLookupString --
 *
 *
 *      Retrieve the string equivalent for the given keyboard event.
 *      Retrieve the string equivalent for the given keyboard event.
 *
 *
 * Results:
 * Results:
 *      Returns the number of characters stored in buffer_return.
 *      Returns the number of characters stored in buffer_return.
 *
 *
 * Side effects:
 * Side effects:
 *      Retrieves the characters stored in the event and inserts them
 *      Retrieves the characters stored in the event and inserts them
 *      into buffer_return.
 *      into buffer_return.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
XLookupString(
XLookupString(
    XKeyEvent* event_struct,
    XKeyEvent* event_struct,
    char* buffer_return,
    char* buffer_return,
    int bytes_buffer,
    int bytes_buffer,
    KeySym* keysym_return,
    KeySym* keysym_return,
    XComposeStatus* status_in_out)
    XComposeStatus* status_in_out)
{
{
    register Tcl_HashEntry *hPtr;
    register Tcl_HashEntry *hPtr;
    char string[3];
    char string[3];
    char virtualKey;
    char virtualKey;
    char c;
    char c;
 
 
    if (!initialized) {
    if (!initialized) {
        InitKeyMaps();
        InitKeyMaps();
    }
    }
 
 
    c = event_struct->keycode & charCodeMask;
    c = event_struct->keycode & charCodeMask;
    string[0] = c;
    string[0] = c;
    string[1] = '\0';
    string[1] = '\0';
 
 
    /*
    /*
     * Just return NULL if the character is a function key or another
     * Just return NULL if the character is a function key or another
     * non-printing key.
     * non-printing key.
     */
     */
    if (c == 0x10) {
    if (c == 0x10) {
        string[0] = '\0';
        string[0] = '\0';
    } else {
    } else {
        virtualKey = (event_struct->keycode & keyCodeMask) >> 8;
        virtualKey = (event_struct->keycode & keyCodeMask) >> 8;
        hPtr = Tcl_FindHashEntry(&keycodeTable, (char *) virtualKey);
        hPtr = Tcl_FindHashEntry(&keycodeTable, (char *) virtualKey);
        if (hPtr != NULL) {
        if (hPtr != NULL) {
            string[0] = '\0';
            string[0] = '\0';
        }
        }
    }
    }
 
 
    if (buffer_return != NULL) {
    if (buffer_return != NULL) {
        strncpy(buffer_return, string, bytes_buffer);
        strncpy(buffer_return, string, bytes_buffer);
    }
    }
 
 
    return strlen(string);
    return strlen(string);
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XGetModifierMapping --
 * XGetModifierMapping --
 *
 *
 *      Fetch the current keycodes used as modifiers.
 *      Fetch the current keycodes used as modifiers.
 *
 *
 * Results:
 * Results:
 *      Returns a new modifier map.
 *      Returns a new modifier map.
 *
 *
 * Side effects:
 * Side effects:
 *      Allocates a new modifier map data structure.
 *      Allocates a new modifier map data structure.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
XModifierKeymap *
XModifierKeymap *
XGetModifierMapping(
XGetModifierMapping(
    Display* display)
    Display* display)
{
{
    XModifierKeymap * modmap;
    XModifierKeymap * modmap;
 
 
    modmap = (XModifierKeymap *) ckalloc(sizeof(XModifierKeymap));
    modmap = (XModifierKeymap *) ckalloc(sizeof(XModifierKeymap));
    modmap->max_keypermod = 0;
    modmap->max_keypermod = 0;
    modmap->modifiermap = NULL;
    modmap->modifiermap = NULL;
    return modmap;
    return modmap;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XFreeModifiermap --
 * XFreeModifiermap --
 *
 *
 *      Deallocate a modifier map that was created by
 *      Deallocate a modifier map that was created by
 *      XGetModifierMapping.
 *      XGetModifierMapping.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Frees the datastructure referenced by modmap.
 *      Frees the datastructure referenced by modmap.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
XFreeModifiermap(
XFreeModifiermap(
    XModifierKeymap *modmap)
    XModifierKeymap *modmap)
{
{
    if (modmap->modifiermap != NULL) {
    if (modmap->modifiermap != NULL) {
        ckfree((char *) modmap->modifiermap);
        ckfree((char *) modmap->modifiermap);
    }
    }
    ckfree((char *) modmap);
    ckfree((char *) modmap);
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XKeysymToString, XStringToKeysym --
 * XKeysymToString, XStringToKeysym --
 *
 *
 *      These X window functions map Keysyms to strings & strings to
 *      These X window functions map Keysyms to strings & strings to
 *      keysyms.  However, Tk already does this for the most common keysyms.
 *      keysyms.  However, Tk already does this for the most common keysyms.
 *      Therefor, these functions only need to support keysyms that will be
 *      Therefor, these functions only need to support keysyms that will be
 *      specific to the Macintosh.  Currently, there are none.
 *      specific to the Macintosh.  Currently, there are none.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
char *
char *
XKeysymToString(
XKeysymToString(
    KeySym keysym)
    KeySym keysym)
{
{
    return NULL;
    return NULL;
}
}
 
 
KeySym
KeySym
XStringToKeysym(
XStringToKeysym(
    const char* string)
    const char* string)
{
{
    return NoSymbol;
    return NoSymbol;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XKeysymToKeycode --
 * XKeysymToKeycode --
 *
 *
 *      The function XKeysymToKeycode is only used by tkTest.c and
 *      The function XKeysymToKeycode is only used by tkTest.c and
 *      currently only implementes the support for keys used in the
 *      currently only implementes the support for keys used in the
 *      Tk test suite.
 *      Tk test suite.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
KeyCode
KeyCode
XKeysymToKeycode(
XKeysymToKeycode(
    Display* display,
    Display* display,
    KeySym keysym)
    KeySym keysym)
{
{
    KeyCode keycode = 0;
    KeyCode keycode = 0;
    char virtualKeyCode = 0;
    char virtualKeyCode = 0;
 
 
    if ((keysym >= XK_space) && (XK_asciitilde)) {
    if ((keysym >= XK_space) && (XK_asciitilde)) {
        if (keysym == 'a') {
        if (keysym == 'a') {
            virtualKeyCode = 0x00;
            virtualKeyCode = 0x00;
        } else if (keysym == 'b' || keysym == 'B') {
        } else if (keysym == 'b' || keysym == 'B') {
            virtualKeyCode = 0x0B;
            virtualKeyCode = 0x0B;
        } else if (keysym == 'c') {
        } else if (keysym == 'c') {
            virtualKeyCode = 0x08;
            virtualKeyCode = 0x08;
        } else if (keysym == 'x' || keysym == 'X') {
        } else if (keysym == 'x' || keysym == 'X') {
            virtualKeyCode = 0x07;
            virtualKeyCode = 0x07;
        } else if (keysym == 'z') {
        } else if (keysym == 'z') {
            virtualKeyCode = 0x06;
            virtualKeyCode = 0x06;
        } else if (keysym == ' ') {
        } else if (keysym == ' ') {
            virtualKeyCode = 0x31;
            virtualKeyCode = 0x31;
        } else if (keysym == XK_Return) {
        } else if (keysym == XK_Return) {
            virtualKeyCode = 0x24;
            virtualKeyCode = 0x24;
            keysym = '\r';
            keysym = '\r';
        }
        }
        keycode = keysym + ((virtualKeyCode << 8) & keyCodeMask);
        keycode = keysym + ((virtualKeyCode << 8) & keyCodeMask);
    }
    }
 
 
    return keycode;
    return keycode;
}
}
 
 

powered by: WebSVN 2.1.0

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