Git init
[framework/uifw/xorg/lib/libxt.git] / src / Pointer.c
1 /********************************************************
2
3 Copyright 1988 by Hewlett-Packard Company
4 Copyright 1987, 1988, 1989 by Digital Equipment Corporation, Maynard
5
6 Permission to use, copy, modify, and distribute this software
7 and its documentation for any purpose and without fee is hereby
8 granted, provided that the above copyright notice appear in all
9 copies and that both that copyright notice and this permission
10 notice appear in supporting documentation, and that the names of
11 Hewlett-Packard or Digital not be used in advertising or
12 publicity pertaining to distribution of the software without specific,
13 written prior permission.
14
15 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21 SOFTWARE.
22
23 ********************************************************/
24
25 /*
26
27 Copyright 1987, 1988, 1989, 1998  The Open Group
28
29 Permission to use, copy, modify, distribute, and sell this software and its
30 documentation for any purpose is hereby granted without fee, provided that
31 the above copyright notice appear in all copies and that both that
32 copyright notice and this permission notice appear in supporting
33 documentation.
34
35 The above copyright notice and this permission notice shall be included in
36 all copies or substantial portions of the Software.
37
38 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
41 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
42 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44
45 Except as contained in this notice, the name of The Open Group shall not be
46 used in advertising or otherwise to promote the sale, use or other dealings
47 in this Software without prior written authorization from The Open Group.
48
49 */
50
51 #ifdef HAVE_CONFIG_H
52 #include <config.h>
53 #endif
54 #include "IntrinsicI.h"
55 #include "PassivGraI.h"
56
57
58 #define AllButtonsMask (Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask)
59
60 Widget _XtProcessPointerEvent(
61     XButtonEvent        *event,
62     Widget              widget,
63     XtPerDisplayInput   pdi)
64 {
65     XtDevice            device = &pdi->pointer;
66     XtServerGrabPtr     newGrab = NULL, devGrab = &device->grab;
67     Widget              dspWidget = NULL;
68     Boolean             deactivateGrab = FALSE;
69
70     switch (event->type)
71       {
72         case ButtonPress:
73           {
74               if (!IsServerGrab(device->grabType))
75                 {
76                     Cardinal            i;
77
78                     for (i = pdi->traceDepth;
79                          i > 0 && !newGrab;
80                          i--)
81                       newGrab = _XtCheckServerGrabsOnWidget((XEvent*)event,
82                                                             pdi->trace[i-1],
83                                                             POINTER);
84                 }
85               if (newGrab)
86                 {
87                     /* Activate the grab */
88                     device->grab = *newGrab;
89                     device->grabType = XtPassiveServerGrab;
90                 }
91           }
92           break;
93
94         case ButtonRelease:
95           {
96               if ((device->grabType == XtPassiveServerGrab) &&
97                   !(event->state & ~(Button1Mask << (event->button - 1)) &
98                     AllButtonsMask))
99                 deactivateGrab = TRUE;
100           }
101           break;
102       }
103
104     if (IsServerGrab(device->grabType) && !(devGrab)->ownerEvents)
105       dspWidget = (devGrab)->widget;
106     else
107       dspWidget = widget;
108
109     if (deactivateGrab)
110       device->grabType = XtNoServerGrab;
111
112     return dspWidget;
113 }