2 * MACDRV windowing driver
4 * Copyright 1996 Alexandre Julliard
5 * Copyright 1999 Patrik Stridvall
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 #ifndef __WINE_MACDRV_H
24 #define __WINE_MACDRV_H
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
30 #include "macdrv_cocoa.h"
34 #include "wine/debug.h"
35 #include "wine/gdi_driver.h"
39 extern BOOL skip_single_buffer_flushes DECLSPEC_HIDDEN
;
40 extern BOOL allow_vsync DECLSPEC_HIDDEN
;
41 extern BOOL allow_set_gamma DECLSPEC_HIDDEN
;
42 extern BOOL allow_software_rendering DECLSPEC_HIDDEN
;
43 extern BOOL disable_window_decorations DECLSPEC_HIDDEN
;
44 extern HMODULE macdrv_module DECLSPEC_HIDDEN
;
47 extern const char* debugstr_cf(CFTypeRef t
) DECLSPEC_HIDDEN
;
49 static inline CGRect
cgrect_from_rect(RECT rect
)
51 if (rect
.left
>= rect
.right
|| rect
.top
>= rect
.bottom
)
52 return CGRectMake(rect
.left
, rect
.top
, 0, 0);
53 return CGRectMake(rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
56 static inline RECT
rect_from_cgrect(CGRect cgrect
)
58 static const RECT empty
;
60 if (!CGRectIsNull(cgrect
))
62 RECT rect
= { CGRectGetMinX(cgrect
), CGRectGetMinY(cgrect
),
63 CGRectGetMaxX(cgrect
), CGRectGetMaxY(cgrect
) };
70 static inline const char *wine_dbgstr_cgrect(CGRect cgrect
)
72 return wine_dbg_sprintf("(%g,%g)-(%g,%g)", CGRectGetMinX(cgrect
), CGRectGetMinY(cgrect
),
73 CGRectGetMaxX(cgrect
), CGRectGetMaxY(cgrect
));
76 extern const char* debugstr_cf(CFTypeRef t
) DECLSPEC_HIDDEN
;
79 /**************************************************************************
83 extern CGRect
macdrv_get_desktop_rect(void) DECLSPEC_HIDDEN
;
84 extern void macdrv_reset_device_metrics(void) DECLSPEC_HIDDEN
;
85 extern BOOL CDECL
macdrv_GetDeviceGammaRamp(PHYSDEV dev
, LPVOID ramp
) DECLSPEC_HIDDEN
;
86 extern BOOL CDECL
macdrv_SetDeviceGammaRamp(PHYSDEV dev
, LPVOID ramp
) DECLSPEC_HIDDEN
;
89 /**************************************************************************
93 /* Mac driver private messages, must be in the range 0x80001000..0x80001fff */
94 enum macdrv_window_messages
96 WM_MACDRV_SET_WIN_REGION
= 0x80001000,
97 WM_MACDRV_UPDATE_DESKTOP_RECT
,
98 WM_MACDRV_RESET_DEVICE_METRICS
,
99 WM_MACDRV_DISPLAYCHANGE
,
100 WM_MACDRV_ACTIVATE_ON_FOLLOWING_FOCUS
,
103 struct macdrv_thread_data
105 macdrv_event_queue queue
;
106 const macdrv_event
*current_event
;
107 macdrv_window capture_window
;
108 CFDataRef keyboard_layout_uchr
;
109 CGEventSourceKeyboardType keyboard_type
;
111 CGEventFlags last_modifiers
;
112 UInt32 dead_key_state
;
113 HKL active_keyboard_layout
;
118 extern struct macdrv_thread_data
*macdrv_init_thread_data(void) DECLSPEC_HIDDEN
;
120 static inline struct macdrv_thread_data
*macdrv_thread_data(void)
122 return NtUserGetThreadInfo()->driver_data
;
126 extern BOOL
macdrv_ActivateKeyboardLayout(HKL hkl
, UINT flags
) DECLSPEC_HIDDEN
;
127 extern void macdrv_Beep(void) DECLSPEC_HIDDEN
;
128 extern LONG
macdrv_ChangeDisplaySettingsEx(LPCWSTR devname
, LPDEVMODEW devmode
,
129 HWND hwnd
, DWORD flags
, LPVOID lpvoid
) DECLSPEC_HIDDEN
;
130 extern BOOL
macdrv_EnumDisplaySettingsEx(LPCWSTR devname
, DWORD mode
,
131 LPDEVMODEW devmode
, DWORD flags
) DECLSPEC_HIDDEN
;
132 extern LRESULT
macdrv_ClipboardWindowProc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
) DECLSPEC_HIDDEN
;
133 extern void macdrv_UpdateDisplayDevices( const struct gdi_device_manager
*device_manager
,
134 BOOL force
, void *param
) DECLSPEC_HIDDEN
;
135 extern BOOL
macdrv_GetDeviceGammaRamp(PHYSDEV dev
, LPVOID ramp
) DECLSPEC_HIDDEN
;
136 extern BOOL
macdrv_SetDeviceGammaRamp(PHYSDEV dev
, LPVOID ramp
) DECLSPEC_HIDDEN
;
137 extern BOOL
macdrv_ClipCursor(LPCRECT clip
) DECLSPEC_HIDDEN
;
138 extern BOOL
macdrv_CreateDesktopWindow(HWND hwnd
) DECLSPEC_HIDDEN
;
139 extern LRESULT
macdrv_DesktopWindowProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
) DECLSPEC_HIDDEN
;
140 extern void macdrv_DestroyWindow(HWND hwnd
) DECLSPEC_HIDDEN
;
141 extern void macdrv_SetFocus(HWND hwnd
) DECLSPEC_HIDDEN
;
142 extern void macdrv_SetLayeredWindowAttributes(HWND hwnd
, COLORREF key
, BYTE alpha
,
143 DWORD flags
) DECLSPEC_HIDDEN
;
144 extern void macdrv_SetParent(HWND hwnd
, HWND parent
, HWND old_parent
) DECLSPEC_HIDDEN
;
145 extern void macdrv_SetWindowRgn(HWND hwnd
, HRGN hrgn
, BOOL redraw
) DECLSPEC_HIDDEN
;
146 extern void macdrv_SetWindowStyle(HWND hwnd
, INT offset
, STYLESTRUCT
*style
) DECLSPEC_HIDDEN
;
147 extern void macdrv_SetWindowText(HWND hwnd
, LPCWSTR text
) DECLSPEC_HIDDEN
;
148 extern UINT
macdrv_ShowWindow(HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
) DECLSPEC_HIDDEN
;
149 extern LRESULT
macdrv_SysCommand(HWND hwnd
, WPARAM wparam
, LPARAM lparam
) DECLSPEC_HIDDEN
;
150 extern BOOL
macdrv_UpdateLayeredWindow(HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
,
151 const RECT
*window_rect
) DECLSPEC_HIDDEN
;
152 extern LRESULT
macdrv_WindowMessage(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
) DECLSPEC_HIDDEN
;
153 extern BOOL
macdrv_WindowPosChanging(HWND hwnd
, HWND insert_after
, UINT swp_flags
,
154 const RECT
*window_rect
, const RECT
*client_rect
,
155 RECT
*visible_rect
, struct window_surface
**surface
) DECLSPEC_HIDDEN
;
156 extern void macdrv_WindowPosChanged(HWND hwnd
, HWND insert_after
, UINT swp_flags
,
157 const RECT
*window_rect
, const RECT
*client_rect
,
158 const RECT
*visible_rect
, const RECT
*valid_rects
,
159 struct window_surface
*surface
) DECLSPEC_HIDDEN
;
160 extern void macdrv_DestroyCursorIcon(HCURSOR cursor
) DECLSPEC_HIDDEN
;
161 extern BOOL
macdrv_ClipCursor(LPCRECT clip
) DECLSPEC_HIDDEN
;
162 extern BOOL
macdrv_GetCursorPos(LPPOINT pos
) DECLSPEC_HIDDEN
;
163 extern void macdrv_SetCapture(HWND hwnd
, UINT flags
) DECLSPEC_HIDDEN
;
164 extern void macdrv_SetCursor(HCURSOR cursor
) DECLSPEC_HIDDEN
;
165 extern BOOL
macdrv_SetCursorPos(INT x
, INT y
) DECLSPEC_HIDDEN
;
166 extern BOOL
macdrv_RegisterHotKey(HWND hwnd
, UINT mod_flags
, UINT vkey
) DECLSPEC_HIDDEN
;
167 extern void macdrv_UnregisterHotKey(HWND hwnd
, UINT modifiers
, UINT vkey
) DECLSPEC_HIDDEN
;
168 extern SHORT
macdrv_VkKeyScanEx(WCHAR wChar
, HKL hkl
) DECLSPEC_HIDDEN
;
169 extern UINT
macdrv_MapVirtualKeyEx(UINT wCode
, UINT wMapType
, HKL hkl
) DECLSPEC_HIDDEN
;
170 extern INT
macdrv_ToUnicodeEx(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
171 LPWSTR bufW
, int bufW_size
, UINT flags
, HKL hkl
) DECLSPEC_HIDDEN
;
172 extern UINT
macdrv_GetKeyboardLayoutList(INT size
, HKL
*list
) DECLSPEC_HIDDEN
;
173 extern INT
macdrv_GetKeyNameText(LONG lparam
, LPWSTR buffer
, INT size
) DECLSPEC_HIDDEN
;
174 extern BOOL
macdrv_SystemParametersInfo(UINT action
, UINT int_param
, void *ptr_param
,
175 UINT flags
) DECLSPEC_HIDDEN
;
176 extern NTSTATUS
macdrv_MsgWaitForMultipleObjectsEx(DWORD count
, const HANDLE
*handles
,
177 const LARGE_INTEGER
*timeout
, DWORD mask
,
178 DWORD flags
) DECLSPEC_HIDDEN
;
179 extern void macdrv_ThreadDetach(void) DECLSPEC_HIDDEN
;
182 /* macdrv private window data */
183 struct macdrv_win_data
185 HWND hwnd
; /* hwnd that this private data belongs to */
186 macdrv_window cocoa_window
;
187 macdrv_view cocoa_view
;
188 macdrv_view client_cocoa_view
;
189 RECT window_rect
; /* USER window rectangle relative to parent */
190 RECT whole_rect
; /* Mac window rectangle for the whole window relative to parent */
191 RECT client_rect
; /* client area relative to parent */
192 int pixel_format
; /* pixel format for GL */
193 COLORREF color_key
; /* color key for layered window; CLR_INVALID is not color keyed */
194 HANDLE drag_event
; /* event to signal that Cocoa-driven window dragging has ended */
195 unsigned int on_screen
: 1; /* is window ordered in? (minimized or not) */
196 unsigned int shaped
: 1; /* is window using a custom region shape? */
197 unsigned int layered
: 1; /* is window layered and with valid attributes? */
198 unsigned int ulw_layered
: 1; /* has UpdateLayeredWindow() been called for window? */
199 unsigned int per_pixel_alpha
: 1; /* is window using per-pixel alpha? */
200 unsigned int minimized
: 1; /* is window minimized? */
201 unsigned int swap_interval
: 1; /* GL swap interval for window */
202 struct window_surface
*surface
;
203 struct window_surface
*unminimized_surface
;
206 extern struct macdrv_win_data
*get_win_data(HWND hwnd
) DECLSPEC_HIDDEN
;
207 extern void release_win_data(struct macdrv_win_data
*data
) DECLSPEC_HIDDEN
;
208 extern void init_win_context(void) DECLSPEC_HIDDEN
;
209 extern macdrv_window
macdrv_get_cocoa_window(HWND hwnd
, BOOL require_on_screen
) DECLSPEC_HIDDEN
;
210 extern RGNDATA
*get_region_data(HRGN hrgn
, HDC hdc_lptodp
) DECLSPEC_HIDDEN
;
211 extern void activate_on_following_focus(void) DECLSPEC_HIDDEN
;
212 extern struct window_surface
*create_surface(macdrv_window window
, const RECT
*rect
,
213 struct window_surface
*old_surface
, BOOL use_alpha
) DECLSPEC_HIDDEN
;
214 extern void set_window_surface(macdrv_window window
, struct window_surface
*window_surface
) DECLSPEC_HIDDEN
;
215 extern void set_surface_use_alpha(struct window_surface
*window_surface
, BOOL use_alpha
) DECLSPEC_HIDDEN
;
216 extern void surface_clip_to_visible_rect(struct window_surface
*window_surface
, const RECT
*visible_rect
) DECLSPEC_HIDDEN
;
218 extern void macdrv_handle_event(const macdrv_event
*event
) DECLSPEC_HIDDEN
;
220 extern void macdrv_window_close_requested(HWND hwnd
) DECLSPEC_HIDDEN
;
221 extern void macdrv_window_frame_changed(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
222 extern void macdrv_window_got_focus(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
223 extern void macdrv_window_lost_focus(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
224 extern void macdrv_app_activated(void) DECLSPEC_HIDDEN
;
225 extern void macdrv_app_deactivated(void) DECLSPEC_HIDDEN
;
226 extern void macdrv_app_quit_requested(const macdrv_event
*event
) DECLSPEC_HIDDEN
;
227 extern void macdrv_window_maximize_requested(HWND hwnd
) DECLSPEC_HIDDEN
;
228 extern void macdrv_window_minimize_requested(HWND hwnd
) DECLSPEC_HIDDEN
;
229 extern void macdrv_window_did_minimize(HWND hwnd
) DECLSPEC_HIDDEN
;
230 extern void macdrv_window_did_unminimize(HWND hwnd
) DECLSPEC_HIDDEN
;
231 extern void macdrv_window_brought_forward(HWND hwnd
) DECLSPEC_HIDDEN
;
232 extern void macdrv_window_resize_ended(HWND hwnd
) DECLSPEC_HIDDEN
;
233 extern void macdrv_window_restore_requested(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
234 extern void macdrv_window_drag_begin(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
235 extern void macdrv_window_drag_end(HWND hwnd
) DECLSPEC_HIDDEN
;
236 extern void macdrv_reassert_window_position(HWND hwnd
) DECLSPEC_HIDDEN
;
237 extern BOOL
query_resize_size(HWND hwnd
, macdrv_query
*query
) DECLSPEC_HIDDEN
;
238 extern BOOL
query_resize_start(HWND hwnd
) DECLSPEC_HIDDEN
;
239 extern BOOL
query_min_max_info(HWND hwnd
) DECLSPEC_HIDDEN
;
241 extern void macdrv_mouse_button(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
242 extern void macdrv_mouse_moved(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
243 extern void macdrv_mouse_scroll(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
244 extern void macdrv_release_capture(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
245 extern void macdrv_SetCapture(HWND hwnd
, UINT flags
) DECLSPEC_HIDDEN
;
247 extern void macdrv_compute_keyboard_layout(struct macdrv_thread_data
*thread_data
) DECLSPEC_HIDDEN
;
248 extern void macdrv_keyboard_changed(const macdrv_event
*event
) DECLSPEC_HIDDEN
;
249 extern void macdrv_key_event(HWND hwnd
, const macdrv_event
*event
) DECLSPEC_HIDDEN
;
250 extern void macdrv_hotkey_press(const macdrv_event
*event
) DECLSPEC_HIDDEN
;
251 extern HKL
macdrv_get_hkl_from_source(TISInputSourceRef input_source
) DECLSPEC_HIDDEN
;
253 extern void macdrv_displays_changed(const macdrv_event
*event
) DECLSPEC_HIDDEN
;
255 extern void macdrv_UpdateClipboard(void) DECLSPEC_HIDDEN
;
256 extern BOOL
query_pasteboard_data(HWND hwnd
, CFStringRef type
) DECLSPEC_HIDDEN
;
257 extern void macdrv_lost_pasteboard_ownership(HWND hwnd
) DECLSPEC_HIDDEN
;
258 extern HANDLE
macdrv_get_pasteboard_data(CFTypeRef pasteboard
, UINT desired_format
) DECLSPEC_HIDDEN
;
260 extern struct opengl_funcs
*macdrv_wine_get_wgl_driver(UINT version
) DECLSPEC_HIDDEN
;
261 extern const struct vulkan_funcs
*macdrv_wine_get_vulkan_driver(UINT version
) DECLSPEC_HIDDEN
;
262 extern void sync_gl_view(struct macdrv_win_data
* data
, const RECT
* old_whole_rect
, const RECT
* old_client_rect
) DECLSPEC_HIDDEN
;
264 extern CGImageRef
create_cgimage_from_icon_bitmaps(HDC hdc
, HANDLE icon
, HBITMAP hbmColor
,
265 unsigned char *color_bits
, int color_size
, HBITMAP hbmMask
,
266 unsigned char *mask_bits
, int mask_size
, int width
,
267 int height
, int istep
) DECLSPEC_HIDDEN
;
268 extern CGImageRef
create_cgimage_from_icon(HANDLE icon
, int width
, int height
) DECLSPEC_HIDDEN
;
269 extern CFArrayRef
create_app_icon_images(void) DECLSPEC_HIDDEN
;
271 extern void macdrv_status_item_mouse_button(const macdrv_event
*event
) DECLSPEC_HIDDEN
;
272 extern void macdrv_status_item_mouse_move(const macdrv_event
*event
) DECLSPEC_HIDDEN
;
274 extern void check_retina_status(void) DECLSPEC_HIDDEN
;
275 extern void macdrv_init_display_devices(BOOL force
) DECLSPEC_HIDDEN
;
276 extern void init_user_driver(void) DECLSPEC_HIDDEN
;
277 extern NTSTATUS
macdrv_init(void *arg
) DECLSPEC_HIDDEN
;
279 /**************************************************************************
283 extern NTSTATUS WINAPI
macdrv_ime_set_text(void *params
, ULONG size
) DECLSPEC_HIDDEN
;
284 extern NTSTATUS WINAPI
macdrv_ime_query_char_rect(void *params
, ULONG size
) DECLSPEC_HIDDEN
;
286 /* unixlib interface */
288 extern NTSTATUS
macdrv_dnd_get_formats(void *arg
) DECLSPEC_HIDDEN
;
289 extern NTSTATUS
macdrv_dnd_have_format(void *arg
) DECLSPEC_HIDDEN
;
290 extern NTSTATUS
macdrv_dnd_release(void *arg
) DECLSPEC_HIDDEN
;
291 extern NTSTATUS
macdrv_dnd_retain(void *arg
) DECLSPEC_HIDDEN
;
292 extern NTSTATUS
macdrv_ime_process_text_input(void *arg
) DECLSPEC_HIDDEN
;
293 extern NTSTATUS
macdrv_notify_icon(void *arg
) DECLSPEC_HIDDEN
;
295 extern NTSTATUS
macdrv_client_func(enum macdrv_client_funcs func
, const void *params
,
296 ULONG size
) DECLSPEC_HIDDEN
;
298 extern NTSTATUS WINAPI
macdrv_dnd_query_drag(void *arg
, ULONG size
) DECLSPEC_HIDDEN
;
299 extern NTSTATUS WINAPI
macdrv_dnd_query_drop(void *arg
, ULONG size
) DECLSPEC_HIDDEN
;
300 extern NTSTATUS WINAPI
macdrv_dnd_query_exited(void *arg
, ULONG size
) DECLSPEC_HIDDEN
;
304 static inline LRESULT
send_message(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
306 return NtUserMessageCall(hwnd
, msg
, wparam
, lparam
, NULL
, NtUserSendMessage
, FALSE
);
309 static inline LRESULT
send_message_timeout(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
310 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
312 struct send_message_timeout_params params
= { .flags
= flags
, .timeout
= timeout
};
313 LRESULT res
= NtUserMessageCall(hwnd
, msg
, wparam
, lparam
, ¶ms
,
314 NtUserSendMessageTimeout
, FALSE
);
315 if (res_ptr
) *res_ptr
= params
.result
;
319 static inline HWND
get_active_window(void)
322 info
.cbSize
= sizeof(info
);
323 return NtUserGetGUIThreadInfo(GetCurrentThreadId(), &info
) ? info
.hwndActive
: 0;
326 static inline HWND
get_capture(void)
329 info
.cbSize
= sizeof(info
);
330 return NtUserGetGUIThreadInfo(GetCurrentThreadId(), &info
) ? info
.hwndCapture
: 0;
333 static inline HWND
get_focus(void)
336 info
.cbSize
= sizeof(info
);
337 return NtUserGetGUIThreadInfo(GetCurrentThreadId(), &info
) ? info
.hwndFocus
: 0;
340 static inline BOOL
intersect_rect( RECT
*dst
, const RECT
*src1
, const RECT
*src2
)
342 dst
->left
= max(src1
->left
, src2
->left
);
343 dst
->top
= max(src1
->top
, src2
->top
);
344 dst
->right
= min(src1
->right
, src2
->right
);
345 dst
->bottom
= min(src1
->bottom
, src2
->bottom
);
346 return !IsRectEmpty( dst
);
349 /* registry helpers */
351 extern HKEY
open_hkcu_key( const char *name
) DECLSPEC_HIDDEN
;
352 extern ULONG
query_reg_value(HKEY hkey
, const WCHAR
*name
, KEY_VALUE_PARTIAL_INFORMATION
*info
,
353 ULONG size
) DECLSPEC_HIDDEN
;
354 extern HKEY
reg_create_ascii_key(HKEY root
, const char *name
, DWORD options
,
355 DWORD
*disposition
) DECLSPEC_HIDDEN
;
356 extern HKEY
reg_create_key(HKEY root
, const WCHAR
*name
, ULONG name_len
,
357 DWORD options
, DWORD
*disposition
) DECLSPEC_HIDDEN
;
358 extern BOOL
reg_delete_tree(HKEY parent
, const WCHAR
*name
, ULONG name_len
) DECLSPEC_HIDDEN
;
359 extern HKEY
reg_open_key(HKEY root
, const WCHAR
*name
, ULONG name_len
) DECLSPEC_HIDDEN
;
363 static inline void ascii_to_unicode(WCHAR
*dst
, const char *src
, size_t len
)
365 while (len
--) *dst
++ = (unsigned char)*src
++;
368 static inline UINT
asciiz_to_unicode(WCHAR
*dst
, const char *src
)
371 while ((*p
++ = *src
++));
372 return (p
- dst
) * sizeof(WCHAR
);
375 /* FIXME: remove once we use unixlib */
376 #define wcsicmp strcmpiW
377 #define wcsnicmp strncmpiW
378 #define wcsrchr strrchrW
379 #define wcstol strtolW
381 #endif /* __WINE_MACDRV_H */