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

Subversion Repositories or1k

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

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/*
/*
 * tkWinPointer.c --
 * tkWinPointer.c --
 *
 *
 *      Windows specific mouse tracking code.
 *      Windows specific mouse tracking code.
 *
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1995-1997 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: tkWinPointer.c,v 1.1.1.1 2002-01-16 10:26:03 markom Exp $
 * RCS: @(#) $Id: tkWinPointer.c,v 1.1.1.1 2002-01-16 10:26:03 markom Exp $
 */
 */
 
 
#include "tkWinInt.h"
#include "tkWinInt.h"
 
 
/*
/*
 * Check for enter/leave events every MOUSE_TIMER_INTERVAL milliseconds.
 * Check for enter/leave events every MOUSE_TIMER_INTERVAL milliseconds.
 */
 */
 
 
#define MOUSE_TIMER_INTERVAL 250
#define MOUSE_TIMER_INTERVAL 250
 
 
/*
/*
 * Declarations of static variables used in this file.
 * Declarations of static variables used in this file.
 */
 */
 
 
static int captured = 0;         /* 1 if mouse is currently captured. */
static int captured = 0;         /* 1 if mouse is currently captured. */
static TkWindow *keyboardWinPtr = NULL; /* Current keyboard grab window. */
static TkWindow *keyboardWinPtr = NULL; /* Current keyboard grab window. */
static Tcl_TimerToken mouseTimer;       /* Handle to the latest mouse timer. */
static Tcl_TimerToken mouseTimer;       /* Handle to the latest mouse timer. */
static int mouseTimerSet = 0;            /* 1 if the mouse timer is active. */
static int mouseTimerSet = 0;            /* 1 if the mouse timer is active. */
 
 
/*
/*
 * Forward declarations of procedures used in this file.
 * Forward declarations of procedures used in this file.
 */
 */
 
 
static void             MouseTimerProc _ANSI_ARGS_((ClientData clientData));
static void             MouseTimerProc _ANSI_ARGS_((ClientData clientData));


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkWinGetModifierState --
 * TkWinGetModifierState --
 *
 *
 *      Return the modifier state as of the last message.
 *      Return the modifier state as of the last message.
 *
 *
 * Results:
 * Results:
 *      Returns the X modifier mask.
 *      Returns the X modifier mask.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
TkWinGetModifierState()
TkWinGetModifierState()
{
{
    int state = 0;
    int state = 0;
 
 
    if (GetKeyState(VK_SHIFT) & 0x8000) {
    if (GetKeyState(VK_SHIFT) & 0x8000) {
        state |= ShiftMask;
        state |= ShiftMask;
    }
    }
    if (GetKeyState(VK_CONTROL) & 0x8000) {
    if (GetKeyState(VK_CONTROL) & 0x8000) {
        state |= ControlMask;
        state |= ControlMask;
    }
    }
    if (GetKeyState(VK_MENU) & 0x8000) {
    if (GetKeyState(VK_MENU) & 0x8000) {
        state |= Mod2Mask;
        state |= Mod2Mask;
    }
    }
    if (GetKeyState(VK_CAPITAL) & 0x0001) {
    if (GetKeyState(VK_CAPITAL) & 0x0001) {
        state |= LockMask;
        state |= LockMask;
    }
    }
    if (GetKeyState(VK_NUMLOCK) & 0x0001) {
    if (GetKeyState(VK_NUMLOCK) & 0x0001) {
        state |= Mod1Mask;
        state |= Mod1Mask;
    }
    }
    if (GetKeyState(VK_SCROLL) & 0x0001) {
    if (GetKeyState(VK_SCROLL) & 0x0001) {
        state |= Mod3Mask;
        state |= Mod3Mask;
    }
    }
    if (GetKeyState(VK_LBUTTON) & 0x8000) {
    if (GetKeyState(VK_LBUTTON) & 0x8000) {
        state |= Button1Mask;
        state |= Button1Mask;
    }
    }
    if (GetKeyState(VK_MBUTTON) & 0x8000) {
    if (GetKeyState(VK_MBUTTON) & 0x8000) {
        state |= Button2Mask;
        state |= Button2Mask;
    }
    }
    if (GetKeyState(VK_RBUTTON) & 0x8000) {
    if (GetKeyState(VK_RBUTTON) & 0x8000) {
        state |= Button3Mask;
        state |= Button3Mask;
    }
    }
    return state;
    return state;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * Tk_PointerEvent --
 * Tk_PointerEvent --
 *
 *
 *      This procedure is called for each pointer-related event.
 *      This procedure is called for each pointer-related event.
 *      It converts the position to root coords and updates the
 *      It converts the position to root coords and updates the
 *      global pointer state machine.  It also ensures that the
 *      global pointer state machine.  It also ensures that the
 *      mouse timer is scheduled.
 *      mouse timer is scheduled.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      May queue events and change the grab state.
 *      May queue events and change the grab state.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
Tk_PointerEvent(hwnd, x, y)
Tk_PointerEvent(hwnd, x, y)
    HWND hwnd;                          /* Window for coords, or NULL for
    HWND hwnd;                          /* Window for coords, or NULL for
                                         * the root window. */
                                         * the root window. */
    int x, y;                           /* Coords relative to hwnd, or screen
    int x, y;                           /* Coords relative to hwnd, or screen
                                         * if hwnd is NULL. */
                                         * if hwnd is NULL. */
{
{
    POINT pos;
    POINT pos;
    int state;
    int state;
    Tk_Window tkwin;
    Tk_Window tkwin;
 
 
    pos.x = x;
    pos.x = x;
    pos.y = y;
    pos.y = y;
 
 
    /*
    /*
     * Convert client coords to root coords if we were given a window.
     * Convert client coords to root coords if we were given a window.
     */
     */
 
 
    if (hwnd) {
    if (hwnd) {
        ClientToScreen(hwnd, &pos);
        ClientToScreen(hwnd, &pos);
    }
    }
 
 
    /*
    /*
     * If the mouse is captured, Windows will report all pointer
     * If the mouse is captured, Windows will report all pointer
     * events to the capture window.  So, we need to determine which
     * events to the capture window.  So, we need to determine which
     * window the mouse is really over and change the event.  Note
     * window the mouse is really over and change the event.  Note
     * that the computed hwnd may point to a window not owned by Tk,
     * that the computed hwnd may point to a window not owned by Tk,
     * or a toplevel decorative frame, so tkwin can be NULL.
     * or a toplevel decorative frame, so tkwin can be NULL.
     */
     */
 
 
    if (captured || hwnd == NULL) {
    if (captured || hwnd == NULL) {
        hwnd = WindowFromPoint(pos);
        hwnd = WindowFromPoint(pos);
    }
    }
    tkwin = Tk_HWNDToWindow(hwnd);
    tkwin = Tk_HWNDToWindow(hwnd);
 
 
    state = TkWinGetModifierState();
    state = TkWinGetModifierState();
 
 
    Tk_UpdatePointer(tkwin, pos.x, pos.y, state);
    Tk_UpdatePointer(tkwin, pos.x, pos.y, state);
 
 
    if ((captured || tkwin) && !mouseTimerSet) {
    if ((captured || tkwin) && !mouseTimerSet) {
        mouseTimerSet = 1;
        mouseTimerSet = 1;
        mouseTimer = Tcl_CreateTimerHandler(MOUSE_TIMER_INTERVAL,
        mouseTimer = Tcl_CreateTimerHandler(MOUSE_TIMER_INTERVAL,
                MouseTimerProc, NULL);
                MouseTimerProc, NULL);
    }
    }
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XGrabKeyboard --
 * XGrabKeyboard --
 *
 *
 *      Simulates a keyboard grab by setting the focus.
 *      Simulates a keyboard grab by setting the focus.
 *
 *
 * Results:
 * Results:
 *      Always returns GrabSuccess.
 *      Always returns GrabSuccess.
 *
 *
 * Side effects:
 * Side effects:
 *      Sets the keyboard focus to the specified window.
 *      Sets the keyboard focus to the specified window.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
XGrabKeyboard(display, grab_window, owner_events, pointer_mode,
XGrabKeyboard(display, grab_window, owner_events, pointer_mode,
        keyboard_mode, time)
        keyboard_mode, time)
    Display* display;
    Display* display;
    Window grab_window;
    Window grab_window;
    Bool owner_events;
    Bool owner_events;
    int pointer_mode;
    int pointer_mode;
    int keyboard_mode;
    int keyboard_mode;
    Time time;
    Time time;
{
{
    keyboardWinPtr = TkWinGetWinPtr(grab_window);
    keyboardWinPtr = TkWinGetWinPtr(grab_window);
    return GrabSuccess;
    return GrabSuccess;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XUngrabKeyboard --
 * XUngrabKeyboard --
 *
 *
 *      Releases the simulated keyboard grab.
 *      Releases the simulated keyboard grab.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Sets the keyboard focus back to the value before the grab.
 *      Sets the keyboard focus back to the value before the grab.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
XUngrabKeyboard(display, time)
XUngrabKeyboard(display, time)
    Display* display;
    Display* display;
    Time time;
    Time time;
{
{
    keyboardWinPtr = NULL;
    keyboardWinPtr = NULL;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * MouseTimerProc --
 * MouseTimerProc --
 *
 *
 *      Check the current mouse position and look for enter/leave
 *      Check the current mouse position and look for enter/leave
 *      events.
 *      events.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      May schedule a new timer and/or generate enter/leave events.
 *      May schedule a new timer and/or generate enter/leave events.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
MouseTimerProc(clientData)
MouseTimerProc(clientData)
    ClientData clientData;
    ClientData clientData;
{
{
    POINT pos;
    POINT pos;
 
 
    mouseTimerSet = 0;
    mouseTimerSet = 0;
 
 
    /*
    /*
     * Get the current mouse position and window.  Don't do anything
     * Get the current mouse position and window.  Don't do anything
     * if the mouse hasn't moved since the last time we looked.
     * if the mouse hasn't moved since the last time we looked.
     */
     */
 
 
    GetCursorPos(&pos);
    GetCursorPos(&pos);
    Tk_PointerEvent(NULL, pos.x, pos.y);
    Tk_PointerEvent(NULL, pos.x, pos.y);
}
}
 
 
/* CYGNUS LOCAL: Cancel any current mouse timer.  */
/* CYGNUS LOCAL: Cancel any current mouse timer.  */
 
 
void
void
TkWinCancelMouseTimer()
TkWinCancelMouseTimer()
{
{
    if (mouseTimerSet) {
    if (mouseTimerSet) {
        Tcl_DeleteTimerHandler(mouseTimer);
        Tcl_DeleteTimerHandler(mouseTimer);
        mouseTimerSet = 0;
        mouseTimerSet = 0;
    }
    }
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkGetPointerCoords --
 * TkGetPointerCoords --
 *
 *
 *      Fetch the position of the mouse pointer.
 *      Fetch the position of the mouse pointer.
 *
 *
 * Results:
 * Results:
 *      *xPtr and *yPtr are filled in with the root coordinates
 *      *xPtr and *yPtr are filled in with the root coordinates
 *      of the mouse pointer for the display.
 *      of the mouse pointer for the display.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
TkGetPointerCoords(tkwin, xPtr, yPtr)
TkGetPointerCoords(tkwin, xPtr, yPtr)
    Tk_Window tkwin;            /* Window that identifies screen on which
    Tk_Window tkwin;            /* Window that identifies screen on which
                                 * lookup is to be done. */
                                 * lookup is to be done. */
    int *xPtr, *yPtr;           /* Store pointer coordinates here. */
    int *xPtr, *yPtr;           /* Store pointer coordinates here. */
{
{
    POINT point;
    POINT point;
 
 
    GetCursorPos(&point);
    GetCursorPos(&point);
    *xPtr = point.x;
    *xPtr = point.x;
    *yPtr = point.y;
    *yPtr = point.y;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XQueryPointer --
 * XQueryPointer --
 *
 *
 *      Check the current state of the mouse.  This is not a complete
 *      Check the current state of the mouse.  This is not a complete
 *      implementation of this function.  It only computes the root
 *      implementation of this function.  It only computes the root
 *      coordinates and the current mask.
 *      coordinates and the current mask.
 *
 *
 * Results:
 * Results:
 *      Sets root_x_return, root_y_return, and mask_return.  Returns
 *      Sets root_x_return, root_y_return, and mask_return.  Returns
 *      true on success.
 *      true on success.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
Bool
Bool
XQueryPointer(display, w, root_return, child_return, root_x_return,
XQueryPointer(display, w, root_return, child_return, root_x_return,
        root_y_return, win_x_return, win_y_return, mask_return)
        root_y_return, win_x_return, win_y_return, mask_return)
    Display* display;
    Display* display;
    Window w;
    Window w;
    Window* root_return;
    Window* root_return;
    Window* child_return;
    Window* child_return;
    int* root_x_return;
    int* root_x_return;
    int* root_y_return;
    int* root_y_return;
    int* win_x_return;
    int* win_x_return;
    int* win_y_return;
    int* win_y_return;
    unsigned int* mask_return;
    unsigned int* mask_return;
{
{
    display->request++;
    display->request++;
    TkGetPointerCoords(NULL, root_x_return, root_y_return);
    TkGetPointerCoords(NULL, root_x_return, root_y_return);
    *mask_return = TkWinGetModifierState();
    *mask_return = TkWinGetModifierState();
    return True;
    return True;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XGetInputFocus --
 * XGetInputFocus --
 *
 *
 *      Retrieves the current keyboard focus window.
 *      Retrieves the current keyboard focus window.
 *
 *
 * Results:
 * Results:
 *      Returns the current focus window.
 *      Returns the current focus window.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
XGetInputFocus(display, focus_return, revert_to_return)
XGetInputFocus(display, focus_return, revert_to_return)
    Display *display;
    Display *display;
    Window *focus_return;
    Window *focus_return;
    int *revert_to_return;
    int *revert_to_return;
{
{
    Tk_Window tkwin = Tk_HWNDToWindow(GetFocus());
    Tk_Window tkwin = Tk_HWNDToWindow(GetFocus());
    *focus_return = tkwin ? Tk_WindowId(tkwin) : None;
    *focus_return = tkwin ? Tk_WindowId(tkwin) : None;
    *revert_to_return = RevertToParent;
    *revert_to_return = RevertToParent;
    display->request++;
    display->request++;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * XSetInputFocus --
 * XSetInputFocus --
 *
 *
 *      Set the current focus window.
 *      Set the current focus window.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Changes the keyboard focus and causes the selected window to
 *      Changes the keyboard focus and causes the selected window to
 *      be activated.
 *      be activated.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
XSetInputFocus(display, focus, revert_to, time)
XSetInputFocus(display, focus, revert_to, time)
    Display* display;
    Display* display;
    Window focus;
    Window focus;
    int revert_to;
    int revert_to;
    Time time;
    Time time;
{
{
    display->request++;
    display->request++;
    if (focus != None) {
    if (focus != None) {
        SetFocus(Tk_GetHWND(focus));
        SetFocus(Tk_GetHWND(focus));
    }
    }
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkpChangeFocus --
 * TkpChangeFocus --
 *
 *
 *      This procedure is invoked to move the system focus from
 *      This procedure is invoked to move the system focus from
 *      one window to another.
 *      one window to another.
 *
 *
 * Results:
 * Results:
 *      The return value is the serial number of the command that
 *      The return value is the serial number of the command that
 *      changed the focus.  It may be needed by the caller to filter
 *      changed the focus.  It may be needed by the caller to filter
 *      out focus change events that were queued before the command.
 *      out focus change events that were queued before the command.
 *      If the procedure doesn't actually change the focus then
 *      If the procedure doesn't actually change the focus then
 *      it returns 0.
 *      it returns 0.
 *
 *
 * Side effects:
 * Side effects:
 *      The official Windows focus window changes;  the application's focus
 *      The official Windows focus window changes;  the application's focus
 *      window isn't changed by this procedure.
 *      window isn't changed by this procedure.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
TkpChangeFocus(winPtr, force)
TkpChangeFocus(winPtr, force)
    TkWindow *winPtr;           /* Window that is to receive the X focus. */
    TkWindow *winPtr;           /* Window that is to receive the X focus. */
    int force;                  /* Non-zero means claim the focus even
    int force;                  /* Non-zero means claim the focus even
                                 * if it didn't originally belong to
                                 * if it didn't originally belong to
                                 * topLevelPtr's application. */
                                 * topLevelPtr's application. */
{
{
    TkDisplay *dispPtr = winPtr->dispPtr;
    TkDisplay *dispPtr = winPtr->dispPtr;
    Window focusWindow;
    Window focusWindow;
    int dummy, serial;
    int dummy, serial;
    TkWindow *winPtr2;
    TkWindow *winPtr2;
 
 
    if (!force) {
    if (!force) {
        XGetInputFocus(dispPtr->display, &focusWindow, &dummy);
        XGetInputFocus(dispPtr->display, &focusWindow, &dummy);
        winPtr2 = (TkWindow *) Tk_IdToWindow(dispPtr->display, focusWindow);
        winPtr2 = (TkWindow *) Tk_IdToWindow(dispPtr->display, focusWindow);
        if ((winPtr2 == NULL) || (winPtr2->mainPtr != winPtr->mainPtr)) {
        if ((winPtr2 == NULL) || (winPtr2->mainPtr != winPtr->mainPtr)) {
            return 0;
            return 0;
        }
        }
    }
    }
 
 
    if (winPtr->window == None) {
    if (winPtr->window == None) {
        panic("ChangeXFocus got null X window");
        panic("ChangeXFocus got null X window");
    }
    }
 
 
    /*
    /*
     * Change the foreground window so the focus window is raised to the top of
     * Change the foreground window so the focus window is raised to the top of
     * the system stacking order and gets the keyboard focus.
     * the system stacking order and gets the keyboard focus.
     */
     */
 
 
    if (force) {
    if (force) {
        SetForegroundWindow(Tk_GetHWND(winPtr->window));
        SetForegroundWindow(Tk_GetHWND(winPtr->window));
    }
    }
    XSetInputFocus(dispPtr->display, winPtr->window, RevertToParent,
    XSetInputFocus(dispPtr->display, winPtr->window, RevertToParent,
            CurrentTime);
            CurrentTime);
 
 
    /*
    /*
     * Remember the current serial number for the X server and issue
     * Remember the current serial number for the X server and issue
     * a dummy server request.  This marks the position at which we
     * a dummy server request.  This marks the position at which we
     * changed the focus, so we can distinguish FocusIn and FocusOut
     * changed the focus, so we can distinguish FocusIn and FocusOut
     * events on either side of the mark.
     * events on either side of the mark.
     */
     */
 
 
    serial = NextRequest(winPtr->display);
    serial = NextRequest(winPtr->display);
    XNoOp(winPtr->display);
    XNoOp(winPtr->display);
    return serial;
    return serial;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkpSetCapture --
 * TkpSetCapture --
 *
 *
 *      This function captures the mouse so that all future events
 *      This function captures the mouse so that all future events
 *      will be reported to this window, even if the mouse is outside
 *      will be reported to this window, even if the mouse is outside
 *      the window.  If the specified window is NULL, then the mouse
 *      the window.  If the specified window is NULL, then the mouse
 *      is released.
 *      is released.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Sets the capture flag and captures the mouse.
 *      Sets the capture flag and captures the mouse.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
TkpSetCapture(winPtr)
TkpSetCapture(winPtr)
    TkWindow *winPtr;                   /* Capture window, or NULL. */
    TkWindow *winPtr;                   /* Capture window, or NULL. */
{
{
    if (winPtr) {
    if (winPtr) {
        SetCapture(Tk_GetHWND(Tk_WindowId(winPtr)));
        SetCapture(Tk_GetHWND(Tk_WindowId(winPtr)));
        captured = 1;
        captured = 1;
    } else {
    } else {
        captured = 0;
        captured = 0;
        ReleaseCapture();
        ReleaseCapture();
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

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