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