Merge from gnus--rel--5.10
[emacs.git] / src / macgui.h
blobc1558e98bfe132deb501c16a269134e15605caff
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.
5 This file is part of GNU Emacs.
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.
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.
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. */
22 /* Contributed by Andrew Choi (akochoi@mac.com). */
24 #ifndef EMACS_MACGUI_H
25 #define EMACS_MACGUI_H
27 typedef struct _XDisplay Display; /* opaque */
29 typedef Lisp_Object XrmDatabase;
31 typedef unsigned long Time;
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 */
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
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
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
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
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
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
127 #ifndef CGFLOAT_DEFINED
128 typedef float CGFloat;
129 #endif
131 typedef WindowRef Window;
132 #if TARGET_API_MAC_CARBON
133 typedef ScrapRef Selection;
134 #else
135 typedef int Selection;
136 #endif
137 #define mac_set_window_title SetWindowTitleWithCFString
138 #define mac_set_window_modified SetWindowModified
139 #define mac_is_window_visible IsWindowVisible
140 #define mac_is_window_collapsed IsWindowCollapsed
141 #define mac_bring_window_to_front BringToFront
142 #define mac_send_window_behind SendBehind
143 #define mac_hide_window HideWindow
144 #define mac_show_window ShowWindow
145 #define mac_collapse_window CollapseWindow
146 #define mac_front_non_floating_window FrontNonFloatingWindow
147 #define mac_active_non_floating_window ActiveNonFloatingWindow
148 #define mac_activate_window ActivateWindow
149 #define mac_move_window_structure MoveWindowStructure
150 #define mac_move_window MoveWindow
151 #define mac_size_window SizeWindow
152 #define mac_get_global_mouse GetGlobalMouse
153 #define mac_is_window_toolbar_visible IsWindowToolbarVisible
154 #define mac_rect_make(f, x, y, w, h) CGRectMake (x, y, w, h)
155 typedef GWorldPtr Pixmap;
157 #define Cursor ThemeCursor
158 #define No_Cursor (-1)
160 #define FACE_DEFAULT (~0)
162 #if !TARGET_API_MAC_CARBON
163 #define GetPixDepth(pmh) ((*(pmh))->pixelSize)
164 #endif
167 /* Emulate XCharStruct. */
168 /* If the sum of ascent and descent is negative, that means some
169 special status specified by enum pcm_status. */
170 typedef struct _XCharStruct
172 short lbearing; /* origin to left edge of raster */
173 short rbearing; /* origin to right edge of raster */
174 short width; /* advance to next char's origin */
175 short ascent; /* baseline to top edge of raster */
176 short descent; /* baseline to bottom edge of raster */
177 #if 0
178 unsigned short attributes; /* per char flags (not predefined) */
179 #endif
180 } XCharStruct;
182 enum pcm_status
184 PCM_VALID = 0, /* pcm data is valid */
185 PCM_INVALID = -1, /* pcm data is invalid */
188 #define STORE_XCHARSTRUCT(xcs, w, bds) \
189 ((xcs).width = (w), \
190 (xcs).lbearing = (bds).left, \
191 (xcs).rbearing = (bds).right, \
192 (xcs).ascent = -(bds).top, \
193 (xcs).descent = (bds).bottom)
195 struct MacFontStruct {
196 char *full_name;
198 short mac_fontnum; /* font number of font used in this window */
199 int mac_fontsize; /* size of font */
200 short mac_fontface; /* plain, bold, italics, etc. */
201 #if TARGET_API_MAC_CARBON
202 int mac_scriptcode; /* Mac OS script code for font used */
203 #else
204 short mac_scriptcode; /* Mac OS script code for font used */
205 #endif
206 #if USE_ATSUI
207 ATSUStyle mac_style; /* NULL if QuickDraw Text is used */
208 #if USE_CG_TEXT_DRAWING
209 CGFontRef cg_font; /* NULL if ATSUI text drawing is used */
210 CGGlyph *cg_glyphs; /* Likewise */
211 #endif
212 #endif
214 /* from Xlib.h */
215 #if 0
216 XExtData *ext_data; /* hook for extension to hang data */
217 Font fid; /* Font id for this font */
218 unsigned direction; /* hint about the direction font is painted */
219 #endif /* 0 */
220 unsigned min_char_or_byte2;/* first character */
221 unsigned max_char_or_byte2;/* last character */
222 unsigned min_byte1; /* first row that exists */
223 unsigned max_byte1; /* last row that exists */
224 #if 0
225 Bool all_chars_exist; /* flag if all characters have nonzero size */
226 unsigned default_char; /* char to print for undefined character */
227 int n_properties; /* how many properties there are */
228 XFontProp *properties; /* pointer to array of additional properties */
229 #endif /* 0 */
230 XCharStruct min_bounds; /* minimum bounds over all existing char */
231 XCharStruct max_bounds; /* maximum bounds over all existing char */
232 union {
233 XCharStruct *per_char; /* first_char to last_char information */
234 XCharStruct **rows; /* first row to last row information */
235 } bounds;
236 int ascent; /* logical extent above baseline for spacing */
237 int descent; /* logical decent below baseline for spacing */
240 typedef struct MacFontStruct MacFontStruct;
241 typedef struct MacFontStruct XFontStruct;
243 /* Structure borrowed from Xlib.h to represent two-byte characters. */
245 typedef struct {
246 unsigned char byte1;
247 unsigned char byte2;
248 } XChar2b;
250 #define STORE_XCHAR2B(chp, b1, b2) \
251 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
253 #define XCHAR2B_BYTE1(chp) \
254 ((chp)->byte1)
256 #define XCHAR2B_BYTE2(chp) \
257 ((chp)->byte2)
260 /* Emulate X GC's by keeping color and font info in a structure. */
261 typedef struct _XGCValues
263 unsigned long foreground;
264 unsigned long background;
265 XFontStruct *font;
266 } XGCValues;
268 typedef struct _XGC
270 /* Original value. */
271 XGCValues xgcv;
273 /* Cached data members follow. */
275 /* QuickDraw foreground color. */
276 RGBColor fore_color;
278 /* QuickDraw background color. */
279 RGBColor back_color;
281 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
282 /* Quartz 2D foreground color. */
283 CGColorRef cg_fore_color;
285 /* Quartz 2D background color. */
286 CGColorRef cg_back_color;
287 #endif
289 #define MAX_CLIP_RECTS 2
290 /* Number of clipping rectangles. */
291 int n_clip_rects;
293 /* QuickDraw clipping region. Ignored if n_clip_rects == 0. */
294 RgnHandle clip_region;
296 #if defined (MAC_OSX) && (USE_ATSUI || USE_CG_DRAWING)
297 /* Clipping rectangles used in Quartz 2D drawing. The y-coordinate
298 is in QuickDraw's. */
299 CGRect clip_rects[MAX_CLIP_RECTS];
300 #endif
301 } *GC;
303 #define GCForeground (1L<<2)
304 #define GCBackground (1L<<3)
305 #define GCFont (1L<<14)
306 #define GCGraphicsExposures 0
308 /* Bit Gravity */
310 #define ForgetGravity 0
311 #define NorthWestGravity 1
312 #define NorthGravity 2
313 #define NorthEastGravity 3
314 #define WestGravity 4
315 #define CenterGravity 5
316 #define EastGravity 6
317 #define SouthWestGravity 7
318 #define SouthGravity 8
319 #define SouthEastGravity 9
320 #define StaticGravity 10
322 #define NoValue 0x0000
323 #define XValue 0x0001
324 #define YValue 0x0002
325 #define WidthValue 0x0004
326 #define HeightValue 0x0008
327 #define AllValues 0x000F
328 #define XNegative 0x0010
329 #define YNegative 0x0020
331 typedef struct {
332 long flags; /* marks which fields in this structure are defined */
333 #if 0
334 int x, y; /* obsolete for new window mgrs, but clients */
335 int width, height; /* should set so old wm's don't mess up */
336 #endif
337 int min_width, min_height;
338 #if 0
339 int max_width, max_height;
340 #endif
341 int width_inc, height_inc;
342 #if 0
343 struct {
344 int x; /* numerator */
345 int y; /* denominator */
346 } min_aspect, max_aspect;
347 #endif
348 int base_width, base_height; /* added by ICCCM version 1 */
349 #if 0
350 int win_gravity; /* added by ICCCM version 1 */
351 #endif
352 } XSizeHints;
354 #define USPosition (1L << 0) /* user specified x, y */
355 #define USSize (1L << 1) /* user specified width, height */
357 #define PPosition (1L << 2) /* program specified position */
358 #define PSize (1L << 3) /* program specified size */
359 #define PMinSize (1L << 4) /* program specified minimum size */
360 #define PMaxSize (1L << 5) /* program specified maximum size */
361 #define PResizeInc (1L << 6) /* program specified resize increments */
362 #define PAspect (1L << 7) /* program specified min and max aspect ratios */
363 #define PBaseSize (1L << 8) /* program specified base for incrementing */
364 #define PWinGravity (1L << 9) /* program specified window gravity */
366 typedef struct {
367 int x, y;
368 unsigned width, height;
369 } XRectangle;
371 #define NativeRectangle Rect
373 #define CONVERT_TO_XRECT(xr,nr) \
374 ((xr).x = (nr).left, \
375 (xr).y = (nr).top, \
376 (xr).width = ((nr).right - (nr).left), \
377 (xr).height = ((nr).bottom - (nr).top))
379 #define CONVERT_FROM_XRECT(xr,nr) \
380 ((nr).left = (xr).x, \
381 (nr).top = (xr).y, \
382 (nr).right = ((xr).x + (xr).width), \
383 (nr).bottom = ((xr).y + (xr).height))
385 #define STORE_NATIVE_RECT(nr,x,y,width,height) \
386 ((nr).left = (x), \
387 (nr).top = (y), \
388 (nr).right = ((nr).left + (width)), \
389 (nr).bottom = ((nr).top + (height)))
391 /* Definitions copied from lwlib.h */
393 typedef void * XtPointer;
395 enum button_type
397 BUTTON_TYPE_NONE,
398 BUTTON_TYPE_TOGGLE,
399 BUTTON_TYPE_RADIO
402 /* This structure is based on the one in ../lwlib/lwlib.h, modified
403 for Mac OS. */
404 typedef struct _widget_value
406 /* name of widget */
407 Lisp_Object lname;
408 char* name;
409 /* value (meaning depend on widget type) */
410 char* value;
411 /* keyboard equivalent. no implications for XtTranslations */
412 Lisp_Object lkey;
413 char* key;
414 /* Help string or nil if none.
415 GC finds this string through the frame's menu_bar_vector
416 or through menu_items. */
417 Lisp_Object help;
418 /* true if enabled */
419 Boolean enabled;
420 /* true if selected */
421 Boolean selected;
422 /* The type of a button. */
423 enum button_type button_type;
424 /* true if menu title */
425 Boolean title;
426 #if 0
427 /* true if was edited (maintained by get_value) */
428 Boolean edited;
429 /* true if has changed (maintained by lw library) */
430 change_type change;
431 /* true if this widget itself has changed,
432 but not counting the other widgets found in the `next' field. */
433 change_type this_one_change;
434 #endif
435 /* Contents of the sub-widgets, also selected slot for checkbox */
436 struct _widget_value* contents;
437 /* data passed to callback */
438 XtPointer call_data;
439 /* next one in the list */
440 struct _widget_value* next;
441 #if 0
442 /* slot for the toolkit dependent part. Always initialize to NULL. */
443 void* toolkit_data;
444 /* tell us if we should free the toolkit data slot when freeing the
445 widget_value itself. */
446 Boolean free_toolkit_data;
448 /* we resource the widget_value structures; this points to the next
449 one on the free list if this one has been deallocated.
451 struct _widget_value *free_list;
452 #endif
453 } widget_value;
455 #if MAC_OS8
456 #define M_APPLE 234
457 #define I_ABOUT 1
459 #define EXTRA_STACK_ALLOC (256 * 1024)
461 #define ARGV_STRING_LIST_ID 129
462 #define RAM_TOO_LARGE_ALERT_ID 129
463 #define ABOUT_ALERT_ID 128
464 #endif
466 #define DIALOG_LEFT_MARGIN (112)
467 #define DIALOG_TOP_MARGIN (24)
468 #define DIALOG_RIGHT_MARGIN (24)
469 #define DIALOG_BOTTOM_MARGIN (20)
470 #define DIALOG_MIN_INNER_WIDTH (338)
471 #define DIALOG_MAX_INNER_WIDTH (564)
472 #define DIALOG_BUTTON_BUTTON_HORIZONTAL_SPACE (12)
473 #define DIALOG_BUTTON_BUTTON_VERTICAL_SPACE (12)
474 #define DIALOG_BUTTON_MIN_WIDTH (68)
475 #define DIALOG_TEXT_MIN_HEIGHT (50)
476 #define DIALOG_TEXT_BUTTONS_VERTICAL_SPACE (10)
477 #define DIALOG_ICON_WIDTH (64)
478 #define DIALOG_ICON_HEIGHT (64)
479 #define DIALOG_ICON_LEFT_MARGIN (24)
480 #define DIALOG_ICON_TOP_MARGIN (15)
482 #endif /* EMACS_MACGUI_H */
484 /* arch-tag: 5a0da49a-35e2-418b-a58c-8a55778ae849
485 (do not change this comment) */