winemac: Implement MOUSE_SCROLL events.
[wine.git] / dlls / winemac.drv / mouse.c
blobd251808cfce7c8930d6876452e5fd821d4bd427d
1 /*
2 * MACDRV mouse driver
4 * Copyright 1998 Ulrich Weigand
5 * Copyright 2007 Henri Verbeet
6 * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
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.
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.
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
23 #include "config.h"
25 #include "macdrv.h"
26 #include "winuser.h"
27 #include "wine/server.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(cursor);
32 /***********************************************************************
33 * send_mouse_input
35 * Update the various window states on a mouse event.
37 static void send_mouse_input(HWND hwnd, UINT flags, int x, int y,
38 DWORD mouse_data, unsigned long time)
40 INPUT input;
41 HWND top_level_hwnd;
43 top_level_hwnd = GetAncestor(hwnd, GA_ROOT);
45 if ((flags & MOUSEEVENTF_MOVE) && (flags & MOUSEEVENTF_ABSOLUTE))
47 RECT rect;
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);
53 SERVER_START_REQ(update_window_zorder)
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);
62 SERVER_END_REQ;
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;
73 __wine_send_input(top_level_hwnd, &input);
77 /***********************************************************************
78 * macdrv_mouse_button
80 * Handler for MOUSE_BUTTON events.
82 void macdrv_mouse_button(HWND hwnd, const macdrv_event *event)
84 UINT flags = 0;
85 WORD data = 0;
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));
92 if (event->mouse_button.pressed)
94 switch (event->mouse_button.button)
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;
105 else
107 switch (event->mouse_button.button)
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;
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);
125 /***********************************************************************
126 * macdrv_mouse_moved
128 * Handler for MOUSE_MOVED and MOUSE_MOVED_ABSOLUTE events.
130 void macdrv_mouse_moved(HWND hwnd, const macdrv_event *event)
132 UINT flags = MOUSEEVENTF_MOVE;
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));
139 if (event->type == MOUSE_MOVED_ABSOLUTE)
140 flags |= MOUSEEVENTF_ABSOLUTE;
142 send_mouse_input(hwnd, flags, event->mouse_moved.x, event->mouse_moved.y,
143 0, event->mouse_moved.time_ms);
147 /***********************************************************************
148 * macdrv_mouse_scroll
150 * Handler for MOUSE_SCROLL events.
152 void macdrv_mouse_scroll(HWND hwnd, const macdrv_event *event)
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));
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);