Release 1.5.29.
[wine] / dlls / winemac.drv / macdrv_cocoa.h
1 /*
2  * MACDRV Cocoa interface declarations
3  *
4  * Copyright 2011, 2012, 2013 Ken Thomases for CodeWeavers Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 /* This header serves as a C interface between the Wine parts of MACDRV
22  * and the Objective-C parts.  It should restrict itself to C and the C-based
23  * Mac APIs, avoiding both Wine and Objective-C/Cocoa features, so that it can
24  * be included by both sides without contaminating either.
25  */
26
27 #ifndef __WINE_MACDRV_COCOA_H
28 #define __WINE_MACDRV_COCOA_H
29
30
31 #define GetCurrentProcess MacGetCurrentProcess
32 #define GetCurrentThread MacGetCurrentThread
33 #define LoadResource MacLoadResource
34 #define AnimatePalette MacAnimatePalette
35 #define EqualRgn MacEqualRgn
36 #define FillRgn MacFillRgn
37 #define FrameRgn MacFrameRgn
38 #define GetPixel MacGetPixel
39 #define InvertRgn MacInvertRgn
40 #define LineTo MacLineTo
41 #define OffsetRgn MacOffsetRgn
42 #define PaintRgn MacPaintRgn
43 #define Polygon MacPolygon
44 #define ResizePalette MacResizePalette
45 #define SetRectRgn MacSetRectRgn
46 #define EqualRect MacEqualRect
47 #define FillRect MacFillRect
48 #define FrameRect MacFrameRect
49 #define GetCursor MacGetCursor
50 #define InvertRect MacInvertRect
51 #define OffsetRect MacOffsetRect
52 #define PtInRect MacPtInRect
53 #define SetCursor MacSetCursor
54 #define SetRect MacSetRect
55 #define ShowCursor MacShowCursor
56 #define UnionRect MacUnionRect
57
58 #include <ApplicationServices/ApplicationServices.h>
59
60 #undef GetCurrentProcess
61 #undef GetCurrentThread
62 #undef LoadResource
63 #undef AnimatePalette
64 #undef EqualRgn
65 #undef FillRgn
66 #undef FrameRgn
67 #undef GetPixel
68 #undef InvertRgn
69 #undef LineTo
70 #undef OffsetRgn
71 #undef PaintRgn
72 #undef Polygon
73 #undef ResizePalette
74 #undef SetRectRgn
75 #undef EqualRect
76 #undef FillRect
77 #undef FrameRect
78 #undef GetCursor
79 #undef InvertRect
80 #undef OffsetRect
81 #undef PtInRect
82 #undef SetCursor
83 #undef SetRect
84 #undef ShowCursor
85 #undef UnionRect
86 #undef DPRINTF
87
88 #include <pthread.h>
89
90
91 #ifndef DECLSPEC_HIDDEN
92 # if defined(__MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__)
93 #  define DECLSPEC_HIDDEN
94 # elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
95 #  define DECLSPEC_HIDDEN __attribute__((visibility ("hidden")))
96 # else
97 #  define DECLSPEC_HIDDEN
98 # endif
99 #endif
100
101
102 /* Must match the values of Cocoa's NSDragOperation enum. */
103 enum {
104     DRAG_OP_NONE    = 0,
105     DRAG_OP_COPY    = 1,
106     DRAG_OP_LINK    = 2,
107     DRAG_OP_GENERIC = 4,
108     DRAG_OP_PRIVATE = 8,
109     DRAG_OP_MOVE    = 16,
110     DRAG_OP_DELETE  = 32,
111     DRAG_OP_EVERY   = UINT32_MAX
112 };
113
114
115 typedef struct macdrv_opaque_window* macdrv_window;
116 typedef struct macdrv_opaque_event_queue* macdrv_event_queue;
117 typedef struct macdrv_opaque_view* macdrv_view;
118 typedef struct macdrv_opaque_opengl_context* macdrv_opengl_context;
119 typedef struct macdrv_opaque_status_item* macdrv_status_item;
120 struct macdrv_event;
121 struct macdrv_query;
122
123 struct macdrv_display {
124     CGDirectDisplayID displayID;
125     CGRect frame;
126     CGRect work_frame;
127 };
128
129
130 /* main */
131 extern int macdrv_err_on;
132
133 extern int macdrv_start_cocoa_app(unsigned long long tickcount) DECLSPEC_HIDDEN;
134 extern void macdrv_window_rejected_focus(const struct macdrv_event *event) DECLSPEC_HIDDEN;
135 extern void macdrv_beep(void) DECLSPEC_HIDDEN;
136 extern void macdrv_set_application_icon(CFArrayRef images) DECLSPEC_HIDDEN;
137 extern void macdrv_quit_reply(int reply) DECLSPEC_HIDDEN;
138 extern int macdrv_using_input_method(void) DECLSPEC_HIDDEN;
139
140
141 /* cursor */
142 extern void macdrv_set_cursor(CFStringRef name, CFArrayRef frames) DECLSPEC_HIDDEN;
143 extern int macdrv_get_cursor_position(CGPoint *pos) DECLSPEC_HIDDEN;
144 extern int macdrv_set_cursor_position(CGPoint pos) DECLSPEC_HIDDEN;
145 extern int macdrv_clip_cursor(CGRect rect) DECLSPEC_HIDDEN;
146
147
148 /* display */
149 extern int macdrv_get_displays(struct macdrv_display** displays, int* count) DECLSPEC_HIDDEN;
150 extern void macdrv_free_displays(struct macdrv_display* displays) DECLSPEC_HIDDEN;
151 extern int macdrv_set_display_mode(const struct macdrv_display* display,
152                                    CGDisplayModeRef display_mode) DECLSPEC_HIDDEN;
153
154
155 /* event */
156 enum {
157     APP_DEACTIVATED,
158     APP_QUIT_REQUESTED,
159     DISPLAYS_CHANGED,
160     IM_SET_CURSOR_POS,
161     IM_SET_TEXT,
162     KEY_PRESS,
163     KEY_RELEASE,
164     KEYBOARD_CHANGED,
165     MOUSE_BUTTON,
166     MOUSE_MOVED,
167     MOUSE_MOVED_ABSOLUTE,
168     MOUSE_SCROLL,
169     QUERY_EVENT,
170     STATUS_ITEM_CLICKED,
171     WINDOW_CLOSE_REQUESTED,
172     WINDOW_DID_MINIMIZE,
173     WINDOW_DID_UNMINIMIZE,
174     WINDOW_FRAME_CHANGED,
175     WINDOW_GOT_FOCUS,
176     WINDOW_LOST_FOCUS,
177     NUM_EVENT_TYPES
178 };
179
180 enum {
181     QUIT_REASON_NONE,
182     QUIT_REASON_LOGOUT,
183     QUIT_REASON_RESTART,
184     QUIT_REASON_SHUTDOWN,
185 };
186
187 typedef uint32_t macdrv_event_mask;
188
189 typedef struct macdrv_event {
190     int                 refs;
191     int                 deliver;
192     int                 type;
193     macdrv_window       window;
194     union {
195         struct {
196             int reason;
197         }                                           app_quit_requested;
198         struct {
199             int activating;
200         }                                           displays_changed;
201         struct {
202             void           *data;
203             unsigned int    pos;
204         }                                           im_set_cursor_pos;
205         struct {
206             void           *data;
207             CFStringRef     text;       /* new text or NULL if just completing existing text */
208             unsigned int    complete;   /* is completing text? */
209         }                                           im_set_text;
210         struct {
211             CGKeyCode                   keycode;
212             CGEventFlags                modifiers;
213             unsigned long               time_ms;
214         }                                           key;
215         struct {
216             CFDataRef                   uchr;
217             CGEventSourceKeyboardType   keyboard_type;
218             int                         iso_keyboard;
219         }                                           keyboard_changed;
220         struct {
221             int             button;
222             int             pressed;
223             int             x;
224             int             y;
225             unsigned long   time_ms;
226         }                                           mouse_button;
227         struct {
228             int             x;
229             int             y;
230             unsigned long   time_ms;
231         }                                           mouse_moved;
232         struct {
233             int             x_scroll;
234             int             y_scroll;
235             int             x;
236             int             y;
237             unsigned long   time_ms;
238         }                                           mouse_scroll;
239         struct {
240             struct macdrv_query *query;
241         }                                           query_event;
242         struct {
243             macdrv_status_item  item;
244             int                 count;
245         }                                           status_item_clicked;
246         struct {
247             CGRect frame;
248         }                                           window_frame_changed;
249         struct {
250             unsigned long   serial;
251             void           *tried_windows;
252         }                                           window_got_focus;
253     };
254 } macdrv_event;
255
256 enum {
257     QUERY_DRAG_DROP,
258     QUERY_DRAG_EXITED,
259     QUERY_DRAG_OPERATION,
260     QUERY_PASTEBOARD_DATA,
261     NUM_QUERY_TYPES
262 };
263
264 typedef struct macdrv_query {
265     int                 refs;
266     int                 type;
267     macdrv_window       window;
268     int                 status;
269     int                 done;
270     union {
271         struct {
272             int                 x;
273             int                 y;
274             uint32_t            op;
275             CFTypeRef           pasteboard;
276         }                                           drag_drop;
277         struct {
278             int                 x;
279             int                 y;
280             uint32_t            offered_ops;
281             uint32_t            accepted_op;
282             CFTypeRef           pasteboard;
283         }                                           drag_operation;
284         struct {
285             CFStringRef type;
286         }                                           pasteboard_data;
287     };
288 } macdrv_query;
289
290 static inline macdrv_event_mask event_mask_for_type(int type)
291 {
292     return ((macdrv_event_mask)1 << type);
293 }
294
295 typedef void (*macdrv_event_handler)(const macdrv_event *event);
296
297 extern macdrv_event_queue macdrv_create_event_queue(macdrv_event_handler handler) DECLSPEC_HIDDEN;
298 extern void macdrv_destroy_event_queue(macdrv_event_queue queue) DECLSPEC_HIDDEN;
299 extern int macdrv_get_event_queue_fd(macdrv_event_queue queue) DECLSPEC_HIDDEN;
300
301 extern int macdrv_copy_event_from_queue(macdrv_event_queue queue,
302         macdrv_event_mask mask, macdrv_event **event) DECLSPEC_HIDDEN;
303 extern void macdrv_release_event(macdrv_event *event) DECLSPEC_HIDDEN;
304
305 extern macdrv_query* macdrv_create_query(void) DECLSPEC_HIDDEN;
306 extern macdrv_query* macdrv_retain_query(macdrv_query *query) DECLSPEC_HIDDEN;
307 extern void macdrv_release_query(macdrv_query *query) DECLSPEC_HIDDEN;
308 extern void macdrv_set_query_done(macdrv_query *query) DECLSPEC_HIDDEN;
309
310
311 /* window */
312 struct macdrv_window_features {
313     unsigned int    title_bar:1;
314     unsigned int    close_button:1;
315     unsigned int    minimize_button:1;
316     unsigned int    resizable:1;
317     unsigned int    utility:1;
318     unsigned int    shadow:1;
319 };
320
321 struct macdrv_window_state {
322     unsigned int    disabled:1;
323     unsigned int    no_activate:1;
324     unsigned int    floating:1;
325     unsigned int    excluded_by_expose:1;
326     unsigned int    excluded_by_cycle:1;
327     unsigned int    minimized:1;
328 };
329
330 extern macdrv_window macdrv_create_cocoa_window(const struct macdrv_window_features* wf,
331         CGRect frame, void* hwnd, macdrv_event_queue queue) DECLSPEC_HIDDEN;
332 extern void macdrv_destroy_cocoa_window(macdrv_window w) DECLSPEC_HIDDEN;
333 extern void* macdrv_get_window_hwnd(macdrv_window w) DECLSPEC_HIDDEN;
334 extern void macdrv_set_cocoa_window_features(macdrv_window w,
335         const struct macdrv_window_features* wf) DECLSPEC_HIDDEN;
336 extern void macdrv_set_cocoa_window_state(macdrv_window w,
337         const struct macdrv_window_state* state) DECLSPEC_HIDDEN;
338 extern void macdrv_set_cocoa_window_title(macdrv_window w, const UniChar* title,
339         size_t length) DECLSPEC_HIDDEN;
340 extern int macdrv_order_cocoa_window(macdrv_window w, macdrv_window prev,
341         macdrv_window next) DECLSPEC_HIDDEN;
342 extern void macdrv_hide_cocoa_window(macdrv_window w) DECLSPEC_HIDDEN;
343 extern int macdrv_set_cocoa_window_frame(macdrv_window w, const CGRect* new_frame) DECLSPEC_HIDDEN;
344 extern void macdrv_get_cocoa_window_frame(macdrv_window w, CGRect* out_frame) DECLSPEC_HIDDEN;
345 extern void macdrv_set_cocoa_parent_window(macdrv_window w, macdrv_window parent) DECLSPEC_HIDDEN;
346 extern void macdrv_set_window_surface(macdrv_window w, void *surface, pthread_mutex_t *mutex) DECLSPEC_HIDDEN;
347 extern CGImageRef create_surface_image(void *window_surface, CGRect *rect, int copy_data) DECLSPEC_HIDDEN;
348 extern int get_surface_blit_rects(void *window_surface, const CGRect **rects, int *count) DECLSPEC_HIDDEN;
349 extern void macdrv_window_needs_display(macdrv_window w, CGRect rect) DECLSPEC_HIDDEN;
350 extern void macdrv_set_window_shape(macdrv_window w, const CGRect *rects, int count) DECLSPEC_HIDDEN;
351 extern void macdrv_set_window_alpha(macdrv_window w, CGFloat alpha) DECLSPEC_HIDDEN;
352 extern void macdrv_set_window_color_key(macdrv_window w, CGFloat keyRed, CGFloat keyGreen,
353                                         CGFloat keyBlue) DECLSPEC_HIDDEN;
354 extern void macdrv_clear_window_color_key(macdrv_window w) DECLSPEC_HIDDEN;
355 extern void macdrv_window_use_per_pixel_alpha(macdrv_window w, int use_per_pixel_alpha) DECLSPEC_HIDDEN;
356 extern void macdrv_give_cocoa_window_focus(macdrv_window w, int activate) DECLSPEC_HIDDEN;
357 extern macdrv_view macdrv_create_view(macdrv_window w, CGRect rect) DECLSPEC_HIDDEN;
358 extern void macdrv_dispose_view(macdrv_view v) DECLSPEC_HIDDEN;
359 extern void macdrv_set_view_window_and_frame(macdrv_view v, macdrv_window w, CGRect rect) DECLSPEC_HIDDEN;
360 extern void macdrv_add_view_opengl_context(macdrv_view v, macdrv_opengl_context c) DECLSPEC_HIDDEN;
361 extern void macdrv_remove_view_opengl_context(macdrv_view v, macdrv_opengl_context c) DECLSPEC_HIDDEN;
362 extern uint32_t macdrv_window_background_color(void) DECLSPEC_HIDDEN;
363 extern int macdrv_send_text_input_event(int pressed, unsigned int flags, int repeat, int keyc,
364                                         void* data) DECLSPEC_HIDDEN;
365
366
367 /* keyboard */
368 extern CFDataRef macdrv_copy_keyboard_layout(CGEventSourceKeyboardType* keyboard_type, int* is_iso) DECLSPEC_HIDDEN;
369
370
371 /* clipboard */
372 extern CFArrayRef macdrv_copy_pasteboard_types(CFTypeRef pasteboard) DECLSPEC_HIDDEN;
373 extern CFDataRef macdrv_copy_pasteboard_data(CFTypeRef pasteboard, CFStringRef type) DECLSPEC_HIDDEN;
374 extern int macdrv_is_pasteboard_owner(void) DECLSPEC_HIDDEN;
375 extern void macdrv_clear_pasteboard(void) DECLSPEC_HIDDEN;
376 extern int macdrv_set_pasteboard_data(CFStringRef type, CFDataRef data, macdrv_window w) DECLSPEC_HIDDEN;
377
378
379 /* opengl */
380 extern macdrv_opengl_context macdrv_create_opengl_context(void* cglctx) DECLSPEC_HIDDEN;
381 extern void macdrv_dispose_opengl_context(macdrv_opengl_context c) DECLSPEC_HIDDEN;
382 extern void macdrv_make_context_current(macdrv_opengl_context c, macdrv_view v) DECLSPEC_HIDDEN;
383 extern void macdrv_update_opengl_context(macdrv_opengl_context c) DECLSPEC_HIDDEN;
384 extern void macdrv_flush_opengl_context(macdrv_opengl_context c) DECLSPEC_HIDDEN;
385
386
387 /* systray / status item */
388 extern macdrv_status_item macdrv_create_status_item(macdrv_event_queue q) DECLSPEC_HIDDEN;
389 extern void macdrv_destroy_status_item(macdrv_status_item s) DECLSPEC_HIDDEN;
390 extern void macdrv_set_status_item_image(macdrv_status_item s, CGImageRef cgimage) DECLSPEC_HIDDEN;
391 extern void macdrv_set_status_item_tooltip(macdrv_status_item s, CFStringRef cftip) DECLSPEC_HIDDEN;
392
393 #endif  /* __WINE_MACDRV_COCOA_H */