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"
33 #define WIN32_NO_STATUS
37 #include "wine/debug.h"
38 #include "wine/gdi_driver.h"
42 extern BOOL skip_single_buffer_flushes
;
43 extern BOOL allow_vsync
;
44 extern BOOL allow_set_gamma
;
45 extern BOOL allow_software_rendering
;
46 extern BOOL disable_window_decorations
;
48 extern const char* debugstr_cf(CFTypeRef t
);
50 static inline CGRect
cgrect_from_rect(RECT rect
)
52 if (rect
.left
>= rect
.right
|| rect
.top
>= rect
.bottom
)
53 return CGRectMake(rect
.left
, rect
.top
, 0, 0);
54 return CGRectMake(rect
.left
, rect
.top
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
57 static inline RECT
rect_from_cgrect(CGRect cgrect
)
59 static const RECT empty
;
61 if (!CGRectIsNull(cgrect
))
63 RECT rect
= { CGRectGetMinX(cgrect
), CGRectGetMinY(cgrect
),
64 CGRectGetMaxX(cgrect
), CGRectGetMaxY(cgrect
) };
71 static inline const char *wine_dbgstr_cgrect(CGRect cgrect
)
73 return wine_dbg_sprintf("(%g,%g)-(%g,%g)", CGRectGetMinX(cgrect
), CGRectGetMinY(cgrect
),
74 CGRectGetMaxX(cgrect
), CGRectGetMaxY(cgrect
));
77 extern const char* debugstr_cf(CFTypeRef t
);
80 /**************************************************************************
84 extern CGRect
macdrv_get_desktop_rect(void);
85 extern void macdrv_reset_device_metrics(void);
86 extern BOOL
macdrv_GetDeviceGammaRamp(PHYSDEV dev
, LPVOID ramp
);
87 extern BOOL
macdrv_SetDeviceGammaRamp(PHYSDEV dev
, LPVOID ramp
);
90 /**************************************************************************
94 /* Mac driver private messages */
95 enum macdrv_window_messages
97 WM_MACDRV_SET_WIN_REGION
= WM_WINE_FIRST_DRIVER_MSG
,
98 WM_MACDRV_ACTIVATE_ON_FOLLOWING_FOCUS
,
101 struct macdrv_thread_data
103 macdrv_event_queue queue
;
104 const macdrv_event
*current_event
;
105 macdrv_window capture_window
;
106 CFDataRef keyboard_layout_uchr
;
107 CGEventSourceKeyboardType keyboard_type
;
109 CGEventFlags last_modifiers
;
110 UInt32 dead_key_state
;
111 HKL active_keyboard_layout
;
116 extern struct macdrv_thread_data
*macdrv_init_thread_data(void);
118 static inline struct macdrv_thread_data
*macdrv_thread_data(void)
120 return (struct macdrv_thread_data
*)(UINT_PTR
)NtUserGetThreadInfo()->driver_data
;
124 extern BOOL
macdrv_ActivateKeyboardLayout(HKL hkl
, UINT flags
);
125 extern void macdrv_Beep(void);
126 extern LONG
macdrv_ChangeDisplaySettings(LPDEVMODEW displays
, LPCWSTR primary_name
, HWND hwnd
, DWORD flags
, LPVOID lpvoid
);
127 extern BOOL
macdrv_GetCurrentDisplaySettings(LPCWSTR name
, BOOL is_primary
, LPDEVMODEW devmode
);
128 extern INT
macdrv_GetDisplayDepth(LPCWSTR name
, BOOL is_primary
);
129 extern LRESULT
macdrv_ClipboardWindowProc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
);
130 extern UINT
macdrv_UpdateDisplayDevices(const struct gdi_device_manager
*device_manager
, void *param
);
131 extern BOOL
macdrv_GetDeviceGammaRamp(PHYSDEV dev
, LPVOID ramp
);
132 extern BOOL
macdrv_SetDeviceGammaRamp(PHYSDEV dev
, LPVOID ramp
);
133 extern BOOL
macdrv_ClipCursor(const RECT
*clip
, BOOL reset
);
134 extern LRESULT
macdrv_NotifyIcon(HWND hwnd
, UINT msg
, NOTIFYICONDATAW
*data
);
135 extern void macdrv_CleanupIcons(HWND hwnd
);
136 extern LRESULT
macdrv_DesktopWindowProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
);
137 extern void macdrv_DestroyWindow(HWND hwnd
);
138 extern void macdrv_SetDesktopWindow(HWND hwnd
);
139 extern void macdrv_SetFocus(HWND hwnd
);
140 extern void macdrv_SetLayeredWindowAttributes(HWND hwnd
, COLORREF key
, BYTE alpha
,
142 extern void macdrv_SetParent(HWND hwnd
, HWND parent
, HWND old_parent
);
143 extern void macdrv_SetWindowRgn(HWND hwnd
, HRGN hrgn
, BOOL redraw
);
144 extern void macdrv_SetWindowStyle(HWND hwnd
, INT offset
, STYLESTRUCT
*style
);
145 extern void macdrv_SetWindowText(HWND hwnd
, LPCWSTR text
);
146 extern UINT
macdrv_ShowWindow(HWND hwnd
, INT cmd
, RECT
*rect
, UINT swp
);
147 extern LRESULT
macdrv_SysCommand(HWND hwnd
, WPARAM wparam
, LPARAM lparam
);
148 extern BOOL
macdrv_CreateLayeredWindow(HWND hwnd
, const RECT
*window_rect
, COLORREF color_key
,
149 struct window_surface
**surface
);
150 extern void macdrv_UpdateLayeredWindow(HWND hwnd
, const RECT
*window_rect
, COLORREF color_key
,
151 BYTE alpha
, UINT flags
);
152 extern LRESULT
macdrv_WindowMessage(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
);
153 extern BOOL
macdrv_WindowPosChanging(HWND hwnd
, UINT swp_flags
, BOOL shaped
, const RECT
*window_rect
,
154 const RECT
*client_rect
, RECT
*visible_rect
);
155 extern BOOL
macdrv_CreateWindowSurface(HWND hwnd
, const RECT
*surface_rect
, struct window_surface
**surface
);
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
);
160 extern void macdrv_DestroyCursorIcon(HCURSOR cursor
);
161 extern BOOL
macdrv_GetCursorPos(LPPOINT pos
);
162 extern void macdrv_SetCapture(HWND hwnd
, UINT flags
);
163 extern void macdrv_SetCursor(HWND hwnd
, HCURSOR cursor
);
164 extern BOOL
macdrv_SetCursorPos(INT x
, INT y
);
165 extern BOOL
macdrv_RegisterHotKey(HWND hwnd
, UINT mod_flags
, UINT vkey
);
166 extern void macdrv_UnregisterHotKey(HWND hwnd
, UINT modifiers
, UINT vkey
);
167 extern SHORT
macdrv_VkKeyScanEx(WCHAR wChar
, HKL hkl
);
168 extern UINT
macdrv_ImeProcessKey(HIMC himc
, UINT wparam
, UINT lparam
, const BYTE
*state
);
169 extern UINT
macdrv_MapVirtualKeyEx(UINT wCode
, UINT wMapType
, HKL hkl
);
170 extern INT
macdrv_ToUnicodeEx(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
171 LPWSTR bufW
, int bufW_size
, UINT flags
, HKL hkl
);
172 extern UINT
macdrv_GetKeyboardLayoutList(INT size
, HKL
*list
);
173 extern INT
macdrv_GetKeyNameText(LONG lparam
, LPWSTR buffer
, INT size
);
174 extern void macdrv_NotifyIMEStatus( HWND hwnd
, UINT status
);
175 extern BOOL
macdrv_SystemParametersInfo(UINT action
, UINT int_param
, void *ptr_param
,
177 extern BOOL
macdrv_ProcessEvents(DWORD mask
);
178 extern void macdrv_ThreadDetach(void);
181 /* macdrv private window data */
182 struct macdrv_win_data
184 HWND hwnd
; /* hwnd that this private data belongs to */
185 macdrv_window cocoa_window
;
186 macdrv_view cocoa_view
;
187 macdrv_view client_cocoa_view
;
188 RECT window_rect
; /* USER window rectangle relative to parent */
189 RECT whole_rect
; /* Mac window rectangle for the whole window relative to parent */
190 RECT client_rect
; /* client area relative to parent */
191 int pixel_format
; /* pixel format for GL */
192 COLORREF color_key
; /* color key for layered window; CLR_INVALID is not color keyed */
193 HANDLE drag_event
; /* event to signal that Cocoa-driven window dragging has ended */
194 unsigned int on_screen
: 1; /* is window ordered in? (minimized or not) */
195 unsigned int shaped
: 1; /* is window using a custom region shape? */
196 unsigned int layered
: 1; /* is window layered and with valid attributes? */
197 unsigned int ulw_layered
: 1; /* has UpdateLayeredWindow() been called for window? */
198 unsigned int per_pixel_alpha
: 1; /* is window using per-pixel alpha? */
199 unsigned int minimized
: 1; /* is window minimized? */
200 unsigned int swap_interval
: 1; /* GL swap interval for window */
201 struct window_surface
*surface
;
202 struct window_surface
*unminimized_surface
;
205 extern struct macdrv_win_data
*get_win_data(HWND hwnd
);
206 extern void release_win_data(struct macdrv_win_data
*data
);
207 extern void init_win_context(void);
208 extern macdrv_window
macdrv_get_cocoa_window(HWND hwnd
, BOOL require_on_screen
);
209 extern RGNDATA
*get_region_data(HRGN hrgn
, HDC hdc_lptodp
);
210 extern void activate_on_following_focus(void);
212 extern void macdrv_handle_event(const macdrv_event
*event
);
214 extern void macdrv_window_close_requested(HWND hwnd
);
215 extern void macdrv_window_frame_changed(HWND hwnd
, const macdrv_event
*event
);
216 extern void macdrv_window_got_focus(HWND hwnd
, const macdrv_event
*event
);
217 extern void macdrv_window_lost_focus(HWND hwnd
, const macdrv_event
*event
);
218 extern void macdrv_app_activated(void);
219 extern void macdrv_app_deactivated(void);
220 extern void macdrv_app_quit_requested(const macdrv_event
*event
);
221 extern void macdrv_window_maximize_requested(HWND hwnd
);
222 extern void macdrv_window_minimize_requested(HWND hwnd
);
223 extern void macdrv_window_did_minimize(HWND hwnd
);
224 extern void macdrv_window_did_unminimize(HWND hwnd
);
225 extern void macdrv_window_brought_forward(HWND hwnd
);
226 extern void macdrv_window_resize_ended(HWND hwnd
);
227 extern void macdrv_window_restore_requested(HWND hwnd
, const macdrv_event
*event
);
228 extern void macdrv_window_drag_begin(HWND hwnd
, const macdrv_event
*event
);
229 extern void macdrv_window_drag_end(HWND hwnd
);
230 extern void macdrv_reassert_window_position(HWND hwnd
);
231 extern BOOL
query_resize_size(HWND hwnd
, macdrv_query
*query
);
232 extern BOOL
query_resize_start(HWND hwnd
);
233 extern BOOL
query_min_max_info(HWND hwnd
);
235 extern void macdrv_mouse_button(HWND hwnd
, const macdrv_event
*event
);
236 extern void macdrv_mouse_moved(HWND hwnd
, const macdrv_event
*event
);
237 extern void macdrv_mouse_scroll(HWND hwnd
, const macdrv_event
*event
);
238 extern void macdrv_release_capture(HWND hwnd
, const macdrv_event
*event
);
239 extern void macdrv_SetCapture(HWND hwnd
, UINT flags
);
241 extern void macdrv_compute_keyboard_layout(struct macdrv_thread_data
*thread_data
);
242 extern void macdrv_keyboard_changed(const macdrv_event
*event
);
243 extern void macdrv_key_event(HWND hwnd
, const macdrv_event
*event
);
244 extern void macdrv_hotkey_press(const macdrv_event
*event
);
245 extern HKL
macdrv_get_hkl_from_source(TISInputSourceRef input_source
);
247 extern void macdrv_displays_changed(const macdrv_event
*event
);
249 extern void macdrv_UpdateClipboard(void);
250 extern BOOL
query_pasteboard_data(HWND hwnd
, CFStringRef type
);
251 extern void macdrv_lost_pasteboard_ownership(HWND hwnd
);
253 extern struct opengl_funcs
*macdrv_wine_get_wgl_driver(UINT version
);
254 extern UINT
macdrv_VulkanInit(UINT version
, void *vulkan_handle
, const struct vulkan_driver_funcs
**driver_funcs
);
255 extern void sync_gl_view(struct macdrv_win_data
* data
, const RECT
* old_whole_rect
, const RECT
* old_client_rect
);
257 extern CGImageRef
create_cgimage_from_icon_bitmaps(HDC hdc
, HANDLE icon
, HBITMAP hbmColor
,
258 unsigned char *color_bits
, int color_size
, HBITMAP hbmMask
,
259 unsigned char *mask_bits
, int mask_size
, int width
,
260 int height
, int istep
);
261 extern CGImageRef
create_cgimage_from_icon(HANDLE icon
, int width
, int height
);
262 extern CFArrayRef
create_app_icon_images(void);
264 extern void macdrv_status_item_mouse_button(const macdrv_event
*event
);
265 extern void macdrv_status_item_mouse_move(const macdrv_event
*event
);
267 extern void check_retina_status(void);
268 extern void init_user_driver(void);
270 /* unixlib interface */
272 extern NTSTATUS
macdrv_dnd_get_data(void *arg
);
273 extern NTSTATUS
macdrv_dnd_get_formats(void *arg
);
274 extern NTSTATUS
macdrv_dnd_have_format(void *arg
);
275 extern NTSTATUS
macdrv_dnd_release(void *arg
);
276 extern NTSTATUS
macdrv_dnd_retain(void *arg
);
278 extern NTSTATUS
macdrv_client_func(enum macdrv_client_funcs func
, const void *params
,
283 static inline LRESULT
send_message(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
285 return NtUserMessageCall(hwnd
, msg
, wparam
, lparam
, NULL
, NtUserSendMessage
, FALSE
);
288 static inline LRESULT
send_message_timeout(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
289 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
291 struct send_message_timeout_params params
= { .flags
= flags
, .timeout
= timeout
};
292 LRESULT res
= NtUserMessageCall(hwnd
, msg
, wparam
, lparam
, ¶ms
,
293 NtUserSendMessageTimeout
, FALSE
);
294 if (res_ptr
) *res_ptr
= params
.result
;
298 static inline HWND
get_active_window(void)
301 info
.cbSize
= sizeof(info
);
302 return NtUserGetGUIThreadInfo(GetCurrentThreadId(), &info
) ? info
.hwndActive
: 0;
305 static inline HWND
get_capture(void)
308 info
.cbSize
= sizeof(info
);
309 return NtUserGetGUIThreadInfo(GetCurrentThreadId(), &info
) ? info
.hwndCapture
: 0;
312 static inline HWND
get_focus(void)
315 info
.cbSize
= sizeof(info
);
316 return NtUserGetGUIThreadInfo(GetCurrentThreadId(), &info
) ? info
.hwndFocus
: 0;
319 static inline BOOL
intersect_rect( RECT
*dst
, const RECT
*src1
, const RECT
*src2
)
321 dst
->left
= max(src1
->left
, src2
->left
);
322 dst
->top
= max(src1
->top
, src2
->top
);
323 dst
->right
= min(src1
->right
, src2
->right
);
324 dst
->bottom
= min(src1
->bottom
, src2
->bottom
);
325 return !IsRectEmpty( dst
);
328 /* registry helpers */
330 extern HKEY
open_hkcu_key( const char *name
);
331 extern ULONG
query_reg_value(HKEY hkey
, const WCHAR
*name
, KEY_VALUE_PARTIAL_INFORMATION
*info
,
333 extern HKEY
reg_create_ascii_key(HKEY root
, const char *name
, DWORD options
,
335 extern HKEY
reg_create_key(HKEY root
, const WCHAR
*name
, ULONG name_len
,
336 DWORD options
, DWORD
*disposition
);
337 extern BOOL
reg_delete_tree(HKEY parent
, const WCHAR
*name
, ULONG name_len
);
338 extern HKEY
reg_open_key(HKEY root
, const WCHAR
*name
, ULONG name_len
);
342 static inline void ascii_to_unicode(WCHAR
*dst
, const char *src
, size_t len
)
344 while (len
--) *dst
++ = (unsigned char)*src
++;
347 static inline UINT
asciiz_to_unicode(WCHAR
*dst
, const char *src
)
350 while ((*p
++ = *src
++));
351 return (p
- dst
) * sizeof(WCHAR
);
354 #endif /* __WINE_MACDRV_H */