jscript: Rename jsheap_t to heap_pool_t.
[wine] / dlls / winemac.drv / mouse.c
1 /*
2  * MACDRV mouse driver
3  *
4  * Copyright 1998 Ulrich Weigand
5  * Copyright 2007 Henri Verbeet
6  * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 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  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include "config.h"
24
25 #include "macdrv.h"
26 #include "winuser.h"
27 #include "wine/server.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(cursor);
30
31
32 /***********************************************************************
33  *              send_mouse_input
34  *
35  * Update the various window states on a mouse event.
36  */
37 static void send_mouse_input(HWND hwnd, UINT flags, int x, int y,
38                              DWORD mouse_data, unsigned long time)
39 {
40     INPUT input;
41     HWND top_level_hwnd;
42
43     top_level_hwnd = GetAncestor(hwnd, GA_ROOT);
44
45     if ((flags & MOUSEEVENTF_MOVE) && (flags & MOUSEEVENTF_ABSOLUTE))
46     {
47         RECT rect;
48
49         /* update the wine server Z-order */
50         SetRect(&rect, x, y, x + 1, y + 1);
51         MapWindowPoints(0, top_level_hwnd, (POINT *)&rect, 2);
52
53         SERVER_START_REQ(update_window_zorder)
54         {
55             req->window      = wine_server_user_handle(top_level_hwnd);
56             req->rect.left   = rect.left;
57             req->rect.top    = rect.top;
58             req->rect.right  = rect.right;
59             req->rect.bottom = rect.bottom;
60             wine_server_call(req);
61         }
62         SERVER_END_REQ;
63     }
64
65     input.type              = INPUT_MOUSE;
66     input.mi.dx             = x;
67     input.mi.dy             = y;
68     input.mi.mouseData      = mouse_data;
69     input.mi.dwFlags        = flags;
70     input.mi.time           = time;
71     input.mi.dwExtraInfo    = 0;
72
73     __wine_send_input(top_level_hwnd, &input);
74 }
75
76
77 /***********************************************************************
78  *              macdrv_mouse_button
79  *
80  * Handler for MOUSE_BUTTON events.
81  */
82 void macdrv_mouse_button(HWND hwnd, const macdrv_event *event)
83 {
84     UINT flags = 0;
85     WORD data = 0;
86
87     TRACE("win %p button %d %s at (%d,%d) time %lu (%lu ticks ago)\n", hwnd, event->mouse_button.button,
88           (event->mouse_button.pressed ? "pressed" : "released"),
89           event->mouse_button.x, event->mouse_button.y,
90           event->mouse_button.time_ms, (GetTickCount() - event->mouse_button.time_ms));
91
92     if (event->mouse_button.pressed)
93     {
94         switch (event->mouse_button.button)
95         {
96         case 0: flags |= MOUSEEVENTF_LEFTDOWN; break;
97         case 1: flags |= MOUSEEVENTF_RIGHTDOWN; break;
98         case 2: flags |= MOUSEEVENTF_MIDDLEDOWN; break;
99         default:
100             flags |= MOUSEEVENTF_XDOWN;
101             data = 1 << (event->mouse_button.button - 3);
102             break;
103         }
104     }
105     else
106     {
107         switch (event->mouse_button.button)
108         {
109         case 0: flags |= MOUSEEVENTF_LEFTUP; break;
110         case 1: flags |= MOUSEEVENTF_RIGHTUP; break;
111         case 2: flags |= MOUSEEVENTF_MIDDLEUP; break;
112         default:
113             flags |= MOUSEEVENTF_XUP;
114             data = 1 << (event->mouse_button.button - 3);
115             break;
116         }
117     }
118
119     send_mouse_input(hwnd, flags | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE,
120                      event->mouse_button.x, event->mouse_button.y,
121                      data, event->mouse_button.time_ms);
122 }
123
124
125 /***********************************************************************
126  *              macdrv_mouse_moved
127  *
128  * Handler for MOUSE_MOVED and MOUSE_MOVED_ABSOLUTE events.
129  */
130 void macdrv_mouse_moved(HWND hwnd, const macdrv_event *event)
131 {
132     UINT flags = MOUSEEVENTF_MOVE;
133
134     TRACE("win %p/%p %s (%d,%d) time %lu (%lu ticks ago)\n", hwnd, event->window,
135           (event->type == MOUSE_MOVED) ? "relative" : "absolute",
136           event->mouse_moved.x, event->mouse_moved.y,
137           event->mouse_moved.time_ms, (GetTickCount() - event->mouse_moved.time_ms));
138
139     if (event->type == MOUSE_MOVED_ABSOLUTE)
140         flags |= MOUSEEVENTF_ABSOLUTE;
141
142     send_mouse_input(hwnd, flags, event->mouse_moved.x, event->mouse_moved.y,
143                      0, event->mouse_moved.time_ms);
144 }
145
146
147 /***********************************************************************
148  *              macdrv_mouse_scroll
149  *
150  * Handler for MOUSE_SCROLL events.
151  */
152 void macdrv_mouse_scroll(HWND hwnd, const macdrv_event *event)
153 {
154     TRACE("win %p/%p scroll (%d,%d) at (%d,%d) time %lu (%lu ticks ago)\n", hwnd,
155           event->window, event->mouse_scroll.x_scroll, event->mouse_scroll.y_scroll,
156           event->mouse_scroll.x, event->mouse_scroll.y,
157           event->mouse_scroll.time_ms, (GetTickCount() - event->mouse_scroll.time_ms));
158
159     send_mouse_input(hwnd, MOUSEEVENTF_WHEEL | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE,
160                      event->mouse_scroll.x, event->mouse_scroll.y,
161                      event->mouse_scroll.y_scroll, event->mouse_scroll.time_ms);
162     send_mouse_input(hwnd, MOUSEEVENTF_HWHEEL | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE,
163                      event->mouse_scroll.x, event->mouse_scroll.y,
164                      event->mouse_scroll.x_scroll, event->mouse_scroll.time_ms);
165 }