(diff-auto-refine-mode): Remove lighter, since it's
[emacs.git] / src / macgui.h
blob6b8e560cac2319001d37503cfbcf3e8ded1581ce
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 of the License, or
10 (at your option) 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. If not, see <http://www.gnu.org/licenses/>. */
20 /* Contributed by Andrew Choi (akochoi@mac.com). */
22 #ifndef EMACS_MACGUI_H
23 #define EMACS_MACGUI_H
25 typedef struct _XDisplay Display; /* opaque */
27 typedef Lisp_Object XrmDatabase;
29 typedef unsigned long Time;
31 #ifdef HAVE_CARBON
32 #undef Z
33 #ifdef MAC_OSX
34 #if ! HAVE_MKTIME || BROKEN_MKTIME
35 #undef mktime
36 #endif
37 #undef DEBUG
38 #undef free
39 #undef malloc
40 #undef realloc
41 /* Macros max and min defined in lisp.h conflict with those in
42 precompiled header Carbon.h. */
43 #undef max
44 #undef min
45 #undef init_process
46 #include <Carbon/Carbon.h>
47 #if ! HAVE_MKTIME || BROKEN_MKTIME
48 #undef mktime
49 #define mktime emacs_mktime
50 #endif
51 #undef free
52 #define free unexec_free
53 #undef malloc
54 #define malloc unexec_malloc
55 #undef realloc
56 #define realloc unexec_realloc
57 #undef min
58 #define min(a, b) ((a) < (b) ? (a) : (b))
59 #undef max
60 #define max(a, b) ((a) > (b) ? (a) : (b))
61 #undef init_process
62 #define init_process emacs_init_process
63 #undef INFINITY
64 #else /* not MAC_OSX */
65 #undef SIGHUP
66 #define OLDP2C 1
67 #include <Carbon.h>
68 #endif /* not MAC_OSX */
69 #undef Z
70 #define Z (current_buffer->text->z)
71 #else /* not HAVE_CARBON */
72 #include <Quickdraw.h> /* for WindowRef */
73 #include <QDOffscreen.h> /* for GWorldPtr */
74 #include <Appearance.h> /* for ThemeCursor */
75 #include <Windows.h>
76 #include <Controls.h>
77 #include <Gestalt.h>
78 #endif /* not HAVE_CARBON */
80 /* Whether to use ATSUI (Apple Type Services for Unicode Imaging) for
81 text drawing. */
82 #if 0 /* Don't enable by default on the emacs-unicode-2 branch. */
83 #ifndef USE_ATSUI
84 #ifdef MAC_OSX
85 #define USE_ATSUI 1
86 #endif
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)
156 #if USE_MAC_IMAGE_IO
157 typedef struct _XImage
159 int width, height; /* size of image */
160 char *data; /* pointer to image data */
161 int bytes_per_line; /* accelarator to next line */
162 int bits_per_pixel; /* bits per pixel (ZPixmap) */
163 } *Pixmap;
164 #else
165 typedef GWorldPtr Pixmap;
166 #endif
168 #define Cursor ThemeCursor
169 #define No_Cursor (-1)
171 #define FACE_DEFAULT (~0)
173 #if !TARGET_API_MAC_CARBON
174 #define GetPixDepth(pmh) ((*(pmh))->pixelSize)
175 #endif
178 /* Emulate XCharStruct. */
179 /* If the sum of ascent and descent is negative, that means some
180 special status specified by enum pcm_status. */
181 typedef struct _XCharStruct
183 short lbearing; /* origin to left edge of raster */
184 short rbearing; /* origin to right edge of raster */
185 short width; /* advance to next char's origin */
186 short ascent; /* baseline to top edge of raster */
187 short descent; /* baseline to bottom edge of raster */
188 #if 0
189 unsigned short attributes; /* per char flags (not predefined) */
190 #endif
191 } XCharStruct;
193 enum pcm_status
195 PCM_VALID = 0, /* pcm data is valid */
196 PCM_INVALID = -1, /* pcm data is invalid */
199 #define STORE_XCHARSTRUCT(xcs, w, bds) \
200 ((xcs).width = (w), \
201 (xcs).lbearing = (bds).left, \
202 (xcs).rbearing = (bds).right, \
203 (xcs).ascent = -(bds).top, \
204 (xcs).descent = (bds).bottom)
206 struct MacFontStruct {
207 char *full_name;
209 short mac_fontnum; /* font number of font used in this window */
210 int mac_fontsize; /* size of font */
211 short mac_fontface; /* plain, bold, italics, etc. */
212 #if TARGET_API_MAC_CARBON
213 int mac_scriptcode; /* Mac OS script code for font used */
214 #else
215 short mac_scriptcode; /* Mac OS script code for font used */
216 #endif
217 #if USE_ATSUI
218 ATSUStyle mac_style; /* NULL if QuickDraw Text is used */
219 #if USE_CG_TEXT_DRAWING
220 CGFontRef cg_font; /* NULL if ATSUI text drawing is used */
221 CGGlyph *cg_glyphs; /* Likewise */
222 #endif
223 #endif
225 /* from Xlib.h */
226 #if 0
227 XExtData *ext_data; /* hook for extension to hang data */
228 Font fid; /* Font id for this font */
229 unsigned direction; /* hint about the direction font is painted */
230 #endif /* 0 */
231 unsigned min_char_or_byte2;/* first character */
232 unsigned max_char_or_byte2;/* last character */
233 unsigned min_byte1; /* first row that exists */
234 unsigned max_byte1; /* last row that exists */
235 #if 0
236 Bool all_chars_exist; /* flag if all characters have nonzero size */
237 unsigned default_char; /* char to print for undefined character */
238 int n_properties; /* how many properties there are */
239 XFontProp *properties; /* pointer to array of additional properties */
240 #endif /* 0 */
241 XCharStruct min_bounds; /* minimum bounds over all existing char */
242 XCharStruct max_bounds; /* maximum bounds over all existing char */
243 union {
244 XCharStruct *per_char; /* first_char to last_char information */
245 XCharStruct **rows; /* first row to last row information */
246 } bounds;
247 int ascent; /* logical extent above baseline for spacing */
248 int descent; /* logical decent below baseline for spacing */
251 typedef struct MacFontStruct MacFontStruct;
252 typedef struct MacFontStruct XFontStruct;
254 /* Structure borrowed from Xlib.h to represent two-byte characters. */
256 typedef struct {
257 unsigned char byte1;
258 unsigned char byte2;
259 } XChar2b;
261 #define STORE_XCHAR2B(chp, b1, b2) \
262 ((chp)->byte1 = (b1), (chp)->byte2 = (b2))
264 #define XCHAR2B_BYTE1(chp) \
265 ((chp)->byte1)
267 #define XCHAR2B_BYTE2(chp) \
268 ((chp)->byte2)
271 /* Emulate X GC's by keeping color and font info in a structure. */
272 typedef struct _XGCValues
274 unsigned long foreground;
275 unsigned long background;
276 XFontStruct *font;
277 } XGCValues;
279 typedef struct _XGC
281 /* Original value. */
282 XGCValues xgcv;
284 /* Cached data members follow. */
286 /* QuickDraw foreground color. */
287 RGBColor fore_color;
289 /* QuickDraw background color. */
290 RGBColor back_color;
292 #if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
293 /* Quartz 2D foreground color. */
294 CGColorRef cg_fore_color;
296 /* Quartz 2D background color. */
297 CGColorRef cg_back_color;
298 #endif
300 #define MAX_CLIP_RECTS 2
301 /* Number of clipping rectangles. */
302 int n_clip_rects;
304 /* QuickDraw clipping region. Ignored if n_clip_rects == 0. */
305 RgnHandle clip_region;
307 #if defined (MAC_OSX) && (USE_ATSUI || USE_CG_DRAWING)
308 /* Clipping rectangles used in Quartz 2D drawing. The y-coordinate
309 is in QuickDraw's. */
310 CGRect clip_rects[MAX_CLIP_RECTS];
311 #endif
312 } *GC;
314 #define GCForeground (1L<<2)
315 #define GCBackground (1L<<3)
316 #define GCFont (1L<<14)
317 #define GCGraphicsExposures 0
319 /* Bit Gravity */
321 #define ForgetGravity 0
322 #define NorthWestGravity 1
323 #define NorthGravity 2
324 #define NorthEastGravity 3
325 #define WestGravity 4
326 #define CenterGravity 5
327 #define EastGravity 6
328 #define SouthWestGravity 7
329 #define SouthGravity 8
330 #define SouthEastGravity 9
331 #define StaticGravity 10
333 #define NoValue 0x0000
334 #define XValue 0x0001
335 #define YValue 0x0002
336 #define WidthValue 0x0004
337 #define HeightValue 0x0008
338 #define AllValues 0x000F
339 #define XNegative 0x0010
340 #define YNegative 0x0020
342 typedef struct {
343 long flags; /* marks which fields in this structure are defined */
344 #if 0
345 int x, y; /* obsolete for new window mgrs, but clients */
346 int width, height; /* should set so old wm's don't mess up */
347 #endif
348 int min_width, min_height;
349 #if 0
350 int max_width, max_height;
351 #endif
352 int width_inc, height_inc;
353 #if 0
354 struct {
355 int x; /* numerator */
356 int y; /* denominator */
357 } min_aspect, max_aspect;
358 #endif
359 int base_width, base_height; /* added by ICCCM version 1 */
360 #if 0
361 int win_gravity; /* added by ICCCM version 1 */
362 #endif
363 } XSizeHints;
365 #define USPosition (1L << 0) /* user specified x, y */
366 #define USSize (1L << 1) /* user specified width, height */
368 #define PPosition (1L << 2) /* program specified position */
369 #define PSize (1L << 3) /* program specified size */
370 #define PMinSize (1L << 4) /* program specified minimum size */
371 #define PMaxSize (1L << 5) /* program specified maximum size */
372 #define PResizeInc (1L << 6) /* program specified resize increments */
373 #define PAspect (1L << 7) /* program specified min and max aspect ratios */
374 #define PBaseSize (1L << 8) /* program specified base for incrementing */
375 #define PWinGravity (1L << 9) /* program specified window gravity */
377 typedef struct {
378 int x, y;
379 unsigned width, height;
380 } XRectangle;
382 #define NativeRectangle Rect
384 #define CONVERT_TO_XRECT(xr,nr) \
385 ((xr).x = (nr).left, \
386 (xr).y = (nr).top, \
387 (xr).width = ((nr).right - (nr).left), \
388 (xr).height = ((nr).bottom - (nr).top))
390 #define CONVERT_FROM_XRECT(xr,nr) \
391 ((nr).left = (xr).x, \
392 (nr).top = (xr).y, \
393 (nr).right = ((xr).x + (xr).width), \
394 (nr).bottom = ((xr).y + (xr).height))
396 #define STORE_NATIVE_RECT(nr,x,y,width,height) \
397 ((nr).left = (x), \
398 (nr).top = (y), \
399 (nr).right = ((nr).left + (width)), \
400 (nr).bottom = ((nr).top + (height)))
402 /* Definitions copied from lwlib.h */
404 typedef void * XtPointer;
406 enum button_type
408 BUTTON_TYPE_NONE,
409 BUTTON_TYPE_TOGGLE,
410 BUTTON_TYPE_RADIO
413 /* This structure is based on the one in ../lwlib/lwlib.h, modified
414 for Mac OS. */
415 typedef struct _widget_value
417 /* name of widget */
418 Lisp_Object lname;
419 char* name;
420 /* value (meaning depend on widget type) */
421 char* value;
422 /* keyboard equivalent. no implications for XtTranslations */
423 Lisp_Object lkey;
424 char* key;
425 /* Help string or nil if none.
426 GC finds this string through the frame's menu_bar_vector
427 or through menu_items. */
428 Lisp_Object help;
429 /* true if enabled */
430 Boolean enabled;
431 /* true if selected */
432 Boolean selected;
433 /* The type of a button. */
434 enum button_type button_type;
435 /* true if menu title */
436 Boolean title;
437 #if 0
438 /* true if was edited (maintained by get_value) */
439 Boolean edited;
440 /* true if has changed (maintained by lw library) */
441 change_type change;
442 /* true if this widget itself has changed,
443 but not counting the other widgets found in the `next' field. */
444 change_type this_one_change;
445 #endif
446 /* Contents of the sub-widgets, also selected slot for checkbox */
447 struct _widget_value* contents;
448 /* data passed to callback */
449 XtPointer call_data;
450 /* next one in the list */
451 struct _widget_value* next;
452 #if 0
453 /* slot for the toolkit dependent part. Always initialize to NULL. */
454 void* toolkit_data;
455 /* tell us if we should free the toolkit data slot when freeing the
456 widget_value itself. */
457 Boolean free_toolkit_data;
459 /* we resource the widget_value structures; this points to the next
460 one on the free list if this one has been deallocated.
462 struct _widget_value *free_list;
463 #endif
464 } widget_value;
466 #if MAC_OS8
467 #define M_APPLE 234
468 #define I_ABOUT 1
470 #define EXTRA_STACK_ALLOC (256 * 1024)
472 #define ARGV_STRING_LIST_ID 129
473 #define RAM_TOO_LARGE_ALERT_ID 129
474 #define ABOUT_ALERT_ID 128
475 #endif
477 #define DIALOG_LEFT_MARGIN (112)
478 #define DIALOG_TOP_MARGIN (24)
479 #define DIALOG_RIGHT_MARGIN (24)
480 #define DIALOG_BOTTOM_MARGIN (20)
481 #define DIALOG_MIN_INNER_WIDTH (338)
482 #define DIALOG_MAX_INNER_WIDTH (564)
483 #define DIALOG_BUTTON_BUTTON_HORIZONTAL_SPACE (12)
484 #define DIALOG_BUTTON_BUTTON_VERTICAL_SPACE (12)
485 #define DIALOG_BUTTON_MIN_WIDTH (68)
486 #define DIALOG_TEXT_MIN_HEIGHT (50)
487 #define DIALOG_TEXT_BUTTONS_VERTICAL_SPACE (10)
488 #define DIALOG_ICON_WIDTH (64)
489 #define DIALOG_ICON_HEIGHT (64)
490 #define DIALOG_ICON_LEFT_MARGIN (24)
491 #define DIALOG_ICON_TOP_MARGIN (15)
493 #endif /* EMACS_MACGUI_H */
495 /* arch-tag: 5a0da49a-35e2-418b-a58c-8a55778ae849
496 (do not change this comment) */