* fileio.c (Fmake_symbolic_link): Surround code by #ifdef S_IFLNK
[bpt/emacs.git] / src / macgui.h
1 /* Definitions and headers for communication on the Mac OS.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 /* Contributed by Andrew Choi (akochoi@mac.com). */
23
24 #ifndef EMACS_MACGUI_H
25 #define EMACS_MACGUI_H
26
27 typedef struct _XDisplay Display; /* opaque */
28
29 typedef Lisp_Object XrmDatabase;
30
31 typedef unsigned long Time;
32
33 #ifdef HAVE_CARBON
34 #undef Z
35 #ifdef MAC_OSX
36 #if ! HAVE_MKTIME || BROKEN_MKTIME
37 #undef mktime
38 #endif
39 #undef DEBUG
40 #undef free
41 #undef malloc
42 #undef realloc
43 /* Macros max and min defined in lisp.h conflict with those in
44 precompiled header Carbon.h. */
45 #undef max
46 #undef min
47 #undef init_process
48 #include <Carbon/Carbon.h>
49 #if ! HAVE_MKTIME || BROKEN_MKTIME
50 #undef mktime
51 #define mktime emacs_mktime
52 #endif
53 #undef free
54 #define free unexec_free
55 #undef malloc
56 #define malloc unexec_malloc
57 #undef realloc
58 #define realloc unexec_realloc
59 #undef min
60 #define min(a, b) ((a) < (b) ? (a) : (b))
61 #undef max
62 #define max(a, b) ((a) > (b) ? (a) : (b))
63 #undef init_process
64 #define init_process emacs_init_process
65 #undef INFINITY
66 #else /* not MAC_OSX */
67 #undef SIGHUP
68 #define OLDP2C 1
69 #include <Carbon.h>
70 #endif /* not MAC_OSX */
71 #undef Z
72 #define Z (current_buffer->text->z)
73 #else /* not HAVE_CARBON */
74 #include <Quickdraw.h> /* for WindowRef */
75 #include <QDOffscreen.h> /* for GWorldPtr */
76 #include <Appearance.h> /* for ThemeCursor */
77 #include <Windows.h>
78 #include <Controls.h>
79 #include <Gestalt.h>
80 #endif /* not HAVE_CARBON */
81
82 /* Whether to use ATSUI (Apple Type Services for Unicode Imaging) for
83 text drawing. */
84 #ifndef USE_ATSUI
85 #ifdef MAC_OSX
86 #define USE_ATSUI 1
87 #endif
88 #endif
89
90 /* Whether to use low-level Quartz 2D (aka Core Graphics) text drawing
91 in preference to ATSUI for ASCII and Latin-1 characters. */
92 #ifndef USE_CG_TEXT_DRAWING
93 #if USE_ATSUI && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
94 #define USE_CG_TEXT_DRAWING 1
95 #endif
96 #endif
97
98 /* Whether to use Quartz 2D routines for drawing operations other than
99 texts. */
100 #ifndef USE_CG_DRAWING
101 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
102 #define USE_CG_DRAWING 1
103 #endif
104 #endif
105
106 /* Whether to use the standard Font Panel floating dialog. */
107 #ifndef USE_MAC_FONT_PANEL
108 #if USE_ATSUI && MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
109 #define USE_MAC_FONT_PANEL 1
110 #endif
111 #endif
112
113 /* Whether to use Text Services Manager. */
114 #ifndef USE_MAC_TSM
115 #if TARGET_API_MAC_CARBON
116 #define USE_MAC_TSM 1
117 #endif
118 #endif
119
120 /* Whether to use HIToolbar. */
121 #ifndef USE_MAC_TOOLBAR
122 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 && MAC_OS_X_VERSION_MIN_REQUIRED != 1020
123 #define USE_MAC_TOOLBAR 1
124 #endif
125 #endif
126
127 typedef WindowRef Window;
128 #if TARGET_API_MAC_CARBON
129 typedef ScrapRef Selection;
130 #else
131 typedef int Selection;
132 #endif
133 #define mac_set_window_title SetWindowTitleWithCFString
134 #define mac_set_window_modified SetWindowModified
135 #define mac_is_window_visible IsWindowVisible
136 #define mac_is_window_collapsed IsWindowCollapsed
137 #define mac_bring_window_to_front BringToFront
138 #define mac_send_window_behind SendBehind
139 #define mac_hide_window HideWindow
140 #define mac_show_window ShowWindow
141 #define mac_collapse_window CollapseWindow
142 #define mac_front_non_floating_window FrontNonFloatingWindow
143 #define mac_active_non_floating_window ActiveNonFloatingWindow
144 #define mac_activate_window ActivateWindow
145 #define mac_move_window_structure MoveWindowStructure
146 #define mac_move_window MoveWindow
147 #define mac_size_window SizeWindow
148 #define mac_get_global_mouse GetGlobalMouse
149 #define mac_is_window_toolbar_visible IsWindowToolbarVisible
150 typedef GWorldPtr Pixmap;
151
152 #define Cursor ThemeCursor
153 #define No_Cursor (-1)
154
155 #define FACE_DEFAULT (~0)
156
157 #if !TARGET_API_MAC_CARBON
158 #define GetPixDepth(pmh) ((*(pmh))->pixelSize)
159 #endif
160
161
162 /* Emulate XCharStruct. */
163 /* If the sum of ascent and descent is negative, that means some
164 special status specified by enum pcm_status. */
165 typedef struct _XCharStruct
166 {
167 short lbearing; /* origin to left edge of raster */
168 short rbearing; /* origin to right edge of raster */
169 short width; /* advance to next char's origin */
170 short ascent; /* baseline to top edge of raster */
171 short descent; /* baseline to bottom edge of raster */
172 #if 0
173 unsigned short attributes; /* per char flags (not predefined) */
174 #endif
175 } XCharStruct;
176
177 enum pcm_status
178 {
179 PCM_VALID = 0, /* pcm data is valid */
180 PCM_INVALID = -1, /* pcm data is invalid */
181 };
182
183 #define STORE_XCHARSTRUCT(xcs, w, bds) \
184 ((xcs).width = (w), \
185 (xcs).lbearing = (bds).left, \
186 (xcs).rbearing = (bds).right, \
187 (xcs).ascent = -(bds).top, \
188 (xcs).descent = (bds).bottom)
189
190 struct MacFontStruct {
191 char *full_name;
192
193 short mac_fontnum; /* font number of font used in this window */
194 int mac_fontsize; /* size of font */
195 short mac_fontface; /* plain, bold, italics, etc. */
196 #if TARGET_API_MAC_CARBON
197 int mac_scriptcode; /* Mac OS script code for font used */
198 #else
199 short mac_scriptcode; /* Mac OS script code for font used */
200 #endif
201 #if USE_ATSUI
202 ATSUStyle mac_style; /* NULL if QuickDraw Text is used */
203 #if USE_CG_TEXT_DRAWING
204 CGFontRef cg_font; /* NULL if ATSUI text drawing is used */
205 CGGlyph *cg_glyphs; /* Likewise */
206 #endif
207 #endif
208
209 /* from Xlib.h */
210 #if 0
211 XExtData *ext_data; /* hook for extension to hang data */
212 Font fid; /* Font id for this font */
213 unsigned direction; /* hint about the direction font is painted */
214 #endif /* 0 */
215 unsigned min_char_or_byte2;/* first character */
216 unsigned max_char_or_byte2;/* last character */
217 unsigned min_byte1; /* first row that exists */
218 unsigned max_byte1; /* last row that exists */
219 #if 0
220 Bool all_chars_exist; /* flag if all characters have nonzero size */
221 unsigned default_char; /* char to print for undefined character */
222 int n_properties; /* how many properties there are */
223 XFontProp *properties; /* pointer to array of additional properties */
224 #endif /* 0 */
225 XCharStruct min_bounds; /* minimum bounds over all existing char */
226 XCharStruct max_bounds; /* maximum bounds over all existing char */
227 union {
228 XCharStruct *per_char; /* first_char to last_char information */
229 XCharStruct **rows; /* first row to last row information */
230 } bounds;
231 int ascent; /* logical extent above baseline for spacing */
232 int descent; /* logical decent below baseline for spacing */
233 };
234
235 typedef struct MacFontStruct MacFontStruct;
236 typedef struct MacFontStruct XFontStruct;
237
238 /* Structure borrowed from Xlib.h to represent two-byte characters. */
239
240 typedef struct {
241 unsigned char byte1;
242 unsigned char byte2;
243 } XChar2b;
244
245 #define STORE_XCHAR2B(chp, b1, b2) \
246 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
247
248 #define XCHAR2B_BYTE1(chp) \
249 ((chp)->byte1)
250
251 #define XCHAR2B_BYTE2(chp) \
252 ((chp)->byte2)
253
254
255 /* Emulate X GC's by keeping color and font info in a structure. */
256 typedef struct _XGCValues
257 {
258 unsigned long foreground;
259 unsigned long background;
260 XFontStruct *font;
261 } XGCValues;
262
263 typedef struct _XGC
264 {
265 /* Original value. */
266 XGCValues xgcv;
267
268 /* Cached data members follow. */
269
270 /* QuickDraw foreground color. */
271 RGBColor fore_color;
272
273 /* QuickDraw background color. */
274 RGBColor back_color;
275
276 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
277 /* Quartz 2D foreground color. */
278 CGColorRef cg_fore_color;
279
280 /* Quartz 2D background color. */
281 CGColorRef cg_back_color;
282 #endif
283
284 #define MAX_CLIP_RECTS 2
285 /* Number of clipping rectangles. */
286 int n_clip_rects;
287
288 /* QuickDraw clipping region. Ignored if n_clip_rects == 0. */
289 RgnHandle clip_region;
290
291 #if defined (MAC_OSX) && (USE_ATSUI || USE_CG_DRAWING)
292 /* Clipping rectangles used in Quartz 2D drawing. The y-coordinate
293 is in QuickDraw's. */
294 CGRect clip_rects[MAX_CLIP_RECTS];
295 #endif
296 } *GC;
297
298 #define GCForeground (1L<<2)
299 #define GCBackground (1L<<3)
300 #define GCFont (1L<<14)
301 #define GCGraphicsExposures 0
302
303 /* Bit Gravity */
304
305 #define ForgetGravity 0
306 #define NorthWestGravity 1
307 #define NorthGravity 2
308 #define NorthEastGravity 3
309 #define WestGravity 4
310 #define CenterGravity 5
311 #define EastGravity 6
312 #define SouthWestGravity 7
313 #define SouthGravity 8
314 #define SouthEastGravity 9
315 #define StaticGravity 10
316
317 #define NoValue 0x0000
318 #define XValue 0x0001
319 #define YValue 0x0002
320 #define WidthValue 0x0004
321 #define HeightValue 0x0008
322 #define AllValues 0x000F
323 #define XNegative 0x0010
324 #define YNegative 0x0020
325
326 typedef struct {
327 long flags; /* marks which fields in this structure are defined */
328 #if 0
329 int x, y; /* obsolete for new window mgrs, but clients */
330 int width, height; /* should set so old wm's don't mess up */
331 #endif
332 int min_width, min_height;
333 #if 0
334 int max_width, max_height;
335 #endif
336 int width_inc, height_inc;
337 #if 0
338 struct {
339 int x; /* numerator */
340 int y; /* denominator */
341 } min_aspect, max_aspect;
342 #endif
343 int base_width, base_height; /* added by ICCCM version 1 */
344 #if 0
345 int win_gravity; /* added by ICCCM version 1 */
346 #endif
347 } XSizeHints;
348
349 #define USPosition (1L << 0) /* user specified x, y */
350 #define USSize (1L << 1) /* user specified width, height */
351
352 #define PPosition (1L << 2) /* program specified position */
353 #define PSize (1L << 3) /* program specified size */
354 #define PMinSize (1L << 4) /* program specified minimum size */
355 #define PMaxSize (1L << 5) /* program specified maximum size */
356 #define PResizeInc (1L << 6) /* program specified resize increments */
357 #define PAspect (1L << 7) /* program specified min and max aspect ratios */
358 #define PBaseSize (1L << 8) /* program specified base for incrementing */
359 #define PWinGravity (1L << 9) /* program specified window gravity */
360
361 typedef struct {
362 int x, y;
363 unsigned width, height;
364 } XRectangle;
365
366 #define NativeRectangle Rect
367
368 #define CONVERT_TO_XRECT(xr,nr) \
369 ((xr).x = (nr).left, \
370 (xr).y = (nr).top, \
371 (xr).width = ((nr).right - (nr).left), \
372 (xr).height = ((nr).bottom - (nr).top))
373
374 #define CONVERT_FROM_XRECT(xr,nr) \
375 ((nr).left = (xr).x, \
376 (nr).top = (xr).y, \
377 (nr).right = ((xr).x + (xr).width), \
378 (nr).bottom = ((xr).y + (xr).height))
379
380 #define STORE_NATIVE_RECT(nr,x,y,width,height) \
381 ((nr).left = (x), \
382 (nr).top = (y), \
383 (nr).right = ((nr).left + (width)), \
384 (nr).bottom = ((nr).top + (height)))
385
386 /* Definitions copied from lwlib.h */
387
388 typedef void * XtPointer;
389
390 enum button_type
391 {
392 BUTTON_TYPE_NONE,
393 BUTTON_TYPE_TOGGLE,
394 BUTTON_TYPE_RADIO
395 };
396
397 /* This structure is based on the one in ../lwlib/lwlib.h, modified
398 for Mac OS. */
399 typedef struct _widget_value
400 {
401 /* name of widget */
402 Lisp_Object lname;
403 char* name;
404 /* value (meaning depend on widget type) */
405 char* value;
406 /* keyboard equivalent. no implications for XtTranslations */
407 Lisp_Object lkey;
408 char* key;
409 /* Help string or nil if none.
410 GC finds this string through the frame's menu_bar_vector
411 or through menu_items. */
412 Lisp_Object help;
413 /* true if enabled */
414 Boolean enabled;
415 /* true if selected */
416 Boolean selected;
417 /* The type of a button. */
418 enum button_type button_type;
419 /* true if menu title */
420 Boolean title;
421 #if 0
422 /* true if was edited (maintained by get_value) */
423 Boolean edited;
424 /* true if has changed (maintained by lw library) */
425 change_type change;
426 /* true if this widget itself has changed,
427 but not counting the other widgets found in the `next' field. */
428 change_type this_one_change;
429 #endif
430 /* Contents of the sub-widgets, also selected slot for checkbox */
431 struct _widget_value* contents;
432 /* data passed to callback */
433 XtPointer call_data;
434 /* next one in the list */
435 struct _widget_value* next;
436 #if 0
437 /* slot for the toolkit dependent part. Always initialize to NULL. */
438 void* toolkit_data;
439 /* tell us if we should free the toolkit data slot when freeing the
440 widget_value itself. */
441 Boolean free_toolkit_data;
442
443 /* we resource the widget_value structures; this points to the next
444 one on the free list if this one has been deallocated.
445 */
446 struct _widget_value *free_list;
447 #endif
448 } widget_value;
449
450 #if MAC_OS8
451 #define M_APPLE 234
452 #define I_ABOUT 1
453
454 #define EXTRA_STACK_ALLOC (256 * 1024)
455
456 #define ARGV_STRING_LIST_ID 129
457 #define RAM_TOO_LARGE_ALERT_ID 129
458 #define ABOUT_ALERT_ID 128
459 #endif
460
461 #define DIALOG_LEFT_MARGIN (112)
462 #define DIALOG_TOP_MARGIN (24)
463 #define DIALOG_RIGHT_MARGIN (24)
464 #define DIALOG_BOTTOM_MARGIN (20)
465 #define DIALOG_MIN_INNER_WIDTH (338)
466 #define DIALOG_MAX_INNER_WIDTH (564)
467 #define DIALOG_BUTTON_BUTTON_HORIZONTAL_SPACE (12)
468 #define DIALOG_BUTTON_BUTTON_VERTICAL_SPACE (12)
469 #define DIALOG_BUTTON_MIN_WIDTH (68)
470 #define DIALOG_TEXT_MIN_HEIGHT (50)
471 #define DIALOG_TEXT_BUTTONS_VERTICAL_SPACE (10)
472 #define DIALOG_ICON_WIDTH (64)
473 #define DIALOG_ICON_HEIGHT (64)
474 #define DIALOG_ICON_LEFT_MARGIN (24)
475 #define DIALOG_ICON_TOP_MARGIN (15)
476
477 #endif /* EMACS_MACGUI_H */
478
479 /* arch-tag: 5a0da49a-35e2-418b-a58c-8a55778ae849
480 (do not change this comment) */