blob: 76c9e9e15e1c224ea4356d2fc28615b028f55021 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_grab.cxx 8055 2010-12-18 22:31:01Z manolo $"
3//
4// Grab/release code for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28#include <config.h>
29#include <FL/Fl.H>
30#include <FL/x.H>
31
32////////////////////////////////////////////////////////////////
33// "Grab" is done while menu systems are up. This has several effects:
34// Events are all sent to the "grab window", which does not even
35// have to be displayed (and in the case of Fl_Menu.cxx it isn't).
36// The system is also told to "grab" events and send them to this app.
37// This also modifies how Fl_Window::show() works, on X it turns on
38// override_redirect, it does similar things on WIN32.
39
40extern void fl_fix_focus(); // in Fl.cxx
41
42#ifdef WIN32
43// We have to keep track of whether we have captured the mouse, since
44// MSWindows shows little respect for this... Grep for fl_capture to
45// see where and how this is used.
46extern HWND fl_capture;
47#endif
48
49#ifdef __APPLE__
50extern void *fl_capture;
51#endif
52
53void Fl::grab(Fl_Window* win) {
54 if (win) {
55 if (!grab_) {
56#ifdef WIN32
57 SetActiveWindow(fl_capture = fl_xid(first_window()));
58 SetCapture(fl_capture);
59#elif defined(__APPLE__)
60 fl_capture = Fl_X::i(first_window())->xid;
61 Fl_X::i(first_window())->set_key_window();
62#else
63 XGrabPointer(fl_display,
64 fl_xid(first_window()),
65 1,
66 ButtonPressMask|ButtonReleaseMask|
67 ButtonMotionMask|PointerMotionMask,
68 GrabModeAsync,
69 GrabModeAsync,
70 None,
71 0,
72 fl_event_time);
73 XGrabKeyboard(fl_display,
74 fl_xid(first_window()),
75 1,
76 GrabModeAsync,
77 GrabModeAsync,
78 fl_event_time);
79#endif
80 }
81 grab_ = win;
82 } else {
83 if (grab_) {
84#ifdef WIN32
85 fl_capture = 0;
86 ReleaseCapture();
87#elif defined(__APPLE__)
88 fl_capture = 0;
89#else
90 XUngrabKeyboard(fl_display, fl_event_time);
91 XUngrabPointer(fl_display, fl_event_time);
92 // this flush is done in case the picked menu item goes into
93 // an infinite loop, so we don't leave the X server locked up:
94 XFlush(fl_display);
95#endif
96 grab_ = 0;
97 fl_fix_focus();
98 }
99 }
100}
101
102//
103// End of "$Id: Fl_grab.cxx 8055 2010-12-18 22:31:01Z manolo $".
104//