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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tkWinPointer.c --
3
 *
4
 *      Windows specific mouse tracking code.
5
 *
6
 * Copyright (c) 1995-1997 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: tkWinPointer.c,v 1.1.1.1 2002-01-16 10:26:03 markom Exp $
12
 */
13
 
14
#include "tkWinInt.h"
15
 
16
/*
17
 * Check for enter/leave events every MOUSE_TIMER_INTERVAL milliseconds.
18
 */
19
 
20
#define MOUSE_TIMER_INTERVAL 250
21
 
22
/*
23
 * Declarations of static variables used in this file.
24
 */
25
 
26
static int captured = 0;         /* 1 if mouse is currently captured. */
27
static TkWindow *keyboardWinPtr = NULL; /* Current keyboard grab window. */
28
static Tcl_TimerToken mouseTimer;       /* Handle to the latest mouse timer. */
29
static int mouseTimerSet = 0;            /* 1 if the mouse timer is active. */
30
 
31
/*
32
 * Forward declarations of procedures used in this file.
33
 */
34
 
35
static void             MouseTimerProc _ANSI_ARGS_((ClientData clientData));
36
 
37
/*
38
 *----------------------------------------------------------------------
39
 *
40
 * TkWinGetModifierState --
41
 *
42
 *      Return the modifier state as of the last message.
43
 *
44
 * Results:
45
 *      Returns the X modifier mask.
46
 *
47
 * Side effects:
48
 *      None.
49
 *
50
 *----------------------------------------------------------------------
51
 */
52
 
53
int
54
TkWinGetModifierState()
55
{
56
    int state = 0;
57
 
58
    if (GetKeyState(VK_SHIFT) & 0x8000) {
59
        state |= ShiftMask;
60
    }
61
    if (GetKeyState(VK_CONTROL) & 0x8000) {
62
        state |= ControlMask;
63
    }
64
    if (GetKeyState(VK_MENU) & 0x8000) {
65
        state |= Mod2Mask;
66
    }
67
    if (GetKeyState(VK_CAPITAL) & 0x0001) {
68
        state |= LockMask;
69
    }
70
    if (GetKeyState(VK_NUMLOCK) & 0x0001) {
71
        state |= Mod1Mask;
72
    }
73
    if (GetKeyState(VK_SCROLL) & 0x0001) {
74
        state |= Mod3Mask;
75
    }
76
    if (GetKeyState(VK_LBUTTON) & 0x8000) {
77
        state |= Button1Mask;
78
    }
79
    if (GetKeyState(VK_MBUTTON) & 0x8000) {
80
        state |= Button2Mask;
81
    }
82
    if (GetKeyState(VK_RBUTTON) & 0x8000) {
83
        state |= Button3Mask;
84
    }
85
    return state;
86
}
87
 
88
/*
89
 *----------------------------------------------------------------------
90
 *
91
 * Tk_PointerEvent --
92
 *
93
 *      This procedure is called for each pointer-related event.
94
 *      It converts the position to root coords and updates the
95
 *      global pointer state machine.  It also ensures that the
96
 *      mouse timer is scheduled.
97
 *
98
 * Results:
99
 *      None.
100
 *
101
 * Side effects:
102
 *      May queue events and change the grab state.
103
 *
104
 *----------------------------------------------------------------------
105
 */
106
 
107
void
108
Tk_PointerEvent(hwnd, x, y)
109
    HWND hwnd;                          /* Window for coords, or NULL for
110
                                         * the root window. */
111
    int x, y;                           /* Coords relative to hwnd, or screen
112
                                         * if hwnd is NULL. */
113
{
114
    POINT pos;
115
    int state;
116
    Tk_Window tkwin;
117
 
118
    pos.x = x;
119
    pos.y = y;
120
 
121
    /*
122
     * Convert client coords to root coords if we were given a window.
123
     */
124
 
125
    if (hwnd) {
126
        ClientToScreen(hwnd, &pos);
127
    }
128
 
129
    /*
130
     * If the mouse is captured, Windows will report all pointer
131
     * events to the capture window.  So, we need to determine which
132
     * window the mouse is really over and change the event.  Note
133
     * that the computed hwnd may point to a window not owned by Tk,
134
     * or a toplevel decorative frame, so tkwin can be NULL.
135
     */
136
 
137
    if (captured || hwnd == NULL) {
138
        hwnd = WindowFromPoint(pos);
139
    }
140
    tkwin = Tk_HWNDToWindow(hwnd);
141
 
142
    state = TkWinGetModifierState();
143
 
144
    Tk_UpdatePointer(tkwin, pos.x, pos.y, state);
145
 
146
    if ((captured || tkwin) && !mouseTimerSet) {
147
        mouseTimerSet = 1;
148
        mouseTimer = Tcl_CreateTimerHandler(MOUSE_TIMER_INTERVAL,
149
                MouseTimerProc, NULL);
150
    }
151
}
152
 
153
/*
154
 *----------------------------------------------------------------------
155
 *
156
 * XGrabKeyboard --
157
 *
158
 *      Simulates a keyboard grab by setting the focus.
159
 *
160
 * Results:
161
 *      Always returns GrabSuccess.
162
 *
163
 * Side effects:
164
 *      Sets the keyboard focus to the specified window.
165
 *
166
 *----------------------------------------------------------------------
167
 */
168
 
169
int
170
XGrabKeyboard(display, grab_window, owner_events, pointer_mode,
171
        keyboard_mode, time)
172
    Display* display;
173
    Window grab_window;
174
    Bool owner_events;
175
    int pointer_mode;
176
    int keyboard_mode;
177
    Time time;
178
{
179
    keyboardWinPtr = TkWinGetWinPtr(grab_window);
180
    return GrabSuccess;
181
}
182
 
183
/*
184
 *----------------------------------------------------------------------
185
 *
186
 * XUngrabKeyboard --
187
 *
188
 *      Releases the simulated keyboard grab.
189
 *
190
 * Results:
191
 *      None.
192
 *
193
 * Side effects:
194
 *      Sets the keyboard focus back to the value before the grab.
195
 *
196
 *----------------------------------------------------------------------
197
 */
198
 
199
void
200
XUngrabKeyboard(display, time)
201
    Display* display;
202
    Time time;
203
{
204
    keyboardWinPtr = NULL;
205
}
206
 
207
/*
208
 *----------------------------------------------------------------------
209
 *
210
 * MouseTimerProc --
211
 *
212
 *      Check the current mouse position and look for enter/leave
213
 *      events.
214
 *
215
 * Results:
216
 *      None.
217
 *
218
 * Side effects:
219
 *      May schedule a new timer and/or generate enter/leave events.
220
 *
221
 *----------------------------------------------------------------------
222
 */
223
 
224
void
225
MouseTimerProc(clientData)
226
    ClientData clientData;
227
{
228
    POINT pos;
229
 
230
    mouseTimerSet = 0;
231
 
232
    /*
233
     * Get the current mouse position and window.  Don't do anything
234
     * if the mouse hasn't moved since the last time we looked.
235
     */
236
 
237
    GetCursorPos(&pos);
238
    Tk_PointerEvent(NULL, pos.x, pos.y);
239
}
240
 
241
/* CYGNUS LOCAL: Cancel any current mouse timer.  */
242
 
243
void
244
TkWinCancelMouseTimer()
245
{
246
    if (mouseTimerSet) {
247
        Tcl_DeleteTimerHandler(mouseTimer);
248
        mouseTimerSet = 0;
249
    }
250
}
251
 
252
/*
253
 *----------------------------------------------------------------------
254
 *
255
 * TkGetPointerCoords --
256
 *
257
 *      Fetch the position of the mouse pointer.
258
 *
259
 * Results:
260
 *      *xPtr and *yPtr are filled in with the root coordinates
261
 *      of the mouse pointer for the display.
262
 *
263
 * Side effects:
264
 *      None.
265
 *
266
 *----------------------------------------------------------------------
267
 */
268
 
269
void
270
TkGetPointerCoords(tkwin, xPtr, yPtr)
271
    Tk_Window tkwin;            /* Window that identifies screen on which
272
                                 * lookup is to be done. */
273
    int *xPtr, *yPtr;           /* Store pointer coordinates here. */
274
{
275
    POINT point;
276
 
277
    GetCursorPos(&point);
278
    *xPtr = point.x;
279
    *yPtr = point.y;
280
}
281
 
282
/*
283
 *----------------------------------------------------------------------
284
 *
285
 * XQueryPointer --
286
 *
287
 *      Check the current state of the mouse.  This is not a complete
288
 *      implementation of this function.  It only computes the root
289
 *      coordinates and the current mask.
290
 *
291
 * Results:
292
 *      Sets root_x_return, root_y_return, and mask_return.  Returns
293
 *      true on success.
294
 *
295
 * Side effects:
296
 *      None.
297
 *
298
 *----------------------------------------------------------------------
299
 */
300
 
301
Bool
302
XQueryPointer(display, w, root_return, child_return, root_x_return,
303
        root_y_return, win_x_return, win_y_return, mask_return)
304
    Display* display;
305
    Window w;
306
    Window* root_return;
307
    Window* child_return;
308
    int* root_x_return;
309
    int* root_y_return;
310
    int* win_x_return;
311
    int* win_y_return;
312
    unsigned int* mask_return;
313
{
314
    display->request++;
315
    TkGetPointerCoords(NULL, root_x_return, root_y_return);
316
    *mask_return = TkWinGetModifierState();
317
    return True;
318
}
319
 
320
/*
321
 *----------------------------------------------------------------------
322
 *
323
 * XGetInputFocus --
324
 *
325
 *      Retrieves the current keyboard focus window.
326
 *
327
 * Results:
328
 *      Returns the current focus window.
329
 *
330
 * Side effects:
331
 *      None.
332
 *
333
 *----------------------------------------------------------------------
334
 */
335
 
336
void
337
XGetInputFocus(display, focus_return, revert_to_return)
338
    Display *display;
339
    Window *focus_return;
340
    int *revert_to_return;
341
{
342
    Tk_Window tkwin = Tk_HWNDToWindow(GetFocus());
343
    *focus_return = tkwin ? Tk_WindowId(tkwin) : None;
344
    *revert_to_return = RevertToParent;
345
    display->request++;
346
}
347
 
348
/*
349
 *----------------------------------------------------------------------
350
 *
351
 * XSetInputFocus --
352
 *
353
 *      Set the current focus window.
354
 *
355
 * Results:
356
 *      None.
357
 *
358
 * Side effects:
359
 *      Changes the keyboard focus and causes the selected window to
360
 *      be activated.
361
 *
362
 *----------------------------------------------------------------------
363
 */
364
 
365
void
366
XSetInputFocus(display, focus, revert_to, time)
367
    Display* display;
368
    Window focus;
369
    int revert_to;
370
    Time time;
371
{
372
    display->request++;
373
    if (focus != None) {
374
        SetFocus(Tk_GetHWND(focus));
375
    }
376
}
377
 
378
/*
379
 *----------------------------------------------------------------------
380
 *
381
 * TkpChangeFocus --
382
 *
383
 *      This procedure is invoked to move the system focus from
384
 *      one window to another.
385
 *
386
 * Results:
387
 *      The return value is the serial number of the command that
388
 *      changed the focus.  It may be needed by the caller to filter
389
 *      out focus change events that were queued before the command.
390
 *      If the procedure doesn't actually change the focus then
391
 *      it returns 0.
392
 *
393
 * Side effects:
394
 *      The official Windows focus window changes;  the application's focus
395
 *      window isn't changed by this procedure.
396
 *
397
 *----------------------------------------------------------------------
398
 */
399
 
400
int
401
TkpChangeFocus(winPtr, force)
402
    TkWindow *winPtr;           /* Window that is to receive the X focus. */
403
    int force;                  /* Non-zero means claim the focus even
404
                                 * if it didn't originally belong to
405
                                 * topLevelPtr's application. */
406
{
407
    TkDisplay *dispPtr = winPtr->dispPtr;
408
    Window focusWindow;
409
    int dummy, serial;
410
    TkWindow *winPtr2;
411
 
412
    if (!force) {
413
        XGetInputFocus(dispPtr->display, &focusWindow, &dummy);
414
        winPtr2 = (TkWindow *) Tk_IdToWindow(dispPtr->display, focusWindow);
415
        if ((winPtr2 == NULL) || (winPtr2->mainPtr != winPtr->mainPtr)) {
416
            return 0;
417
        }
418
    }
419
 
420
    if (winPtr->window == None) {
421
        panic("ChangeXFocus got null X window");
422
    }
423
 
424
    /*
425
     * Change the foreground window so the focus window is raised to the top of
426
     * the system stacking order and gets the keyboard focus.
427
     */
428
 
429
    if (force) {
430
        SetForegroundWindow(Tk_GetHWND(winPtr->window));
431
    }
432
    XSetInputFocus(dispPtr->display, winPtr->window, RevertToParent,
433
            CurrentTime);
434
 
435
    /*
436
     * Remember the current serial number for the X server and issue
437
     * a dummy server request.  This marks the position at which we
438
     * changed the focus, so we can distinguish FocusIn and FocusOut
439
     * events on either side of the mark.
440
     */
441
 
442
    serial = NextRequest(winPtr->display);
443
    XNoOp(winPtr->display);
444
    return serial;
445
}
446
 
447
/*
448
 *----------------------------------------------------------------------
449
 *
450
 * TkpSetCapture --
451
 *
452
 *      This function captures the mouse so that all future events
453
 *      will be reported to this window, even if the mouse is outside
454
 *      the window.  If the specified window is NULL, then the mouse
455
 *      is released.
456
 *
457
 * Results:
458
 *      None.
459
 *
460
 * Side effects:
461
 *      Sets the capture flag and captures the mouse.
462
 *
463
 *----------------------------------------------------------------------
464
 */
465
 
466
void
467
TkpSetCapture(winPtr)
468
    TkWindow *winPtr;                   /* Capture window, or NULL. */
469
{
470
    if (winPtr) {
471
        SetCapture(Tk_GetHWND(Tk_WindowId(winPtr)));
472
        captured = 1;
473
    } else {
474
        captured = 0;
475
        ReleaseCapture();
476
    }
477
}

powered by: WebSVN 2.1.0

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