1 /* Display module for Mac OS.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 2005, 2006 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 2, or (at your option)
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). */
27 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
29 #define RED_FROM_ULONG(color) ((color) >> 16)
30 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
31 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
33 /* Do not change `* 0x101' in the following lines to `<< 8'. If
34 changed, image masks in 1-bit depth will not work. */
35 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
36 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
37 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
39 #define BLACK_PIX_DEFAULT(f) RGB_TO_ULONG(0,0,0)
40 #define WHITE_PIX_DEFAULT(f) RGB_TO_ULONG(255,255,255)
42 #define FONT_WIDTH(f) ((f)->max_bounds.width)
43 #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
44 #define FONT_BASE(f) ((f)->ascent)
45 #define FONT_DESCENT(f) ((f)->descent)
47 #define FONT_MAX_WIDTH(f) FONT_WIDTH(f) /* fix later */
49 /* Structure recording bitmaps and reference count.
50 If REFCOUNT is 0 then this record is free to be reused. */
52 struct mac_bitmap_record
61 /* For each display (currently only one on mac), we have a structure that
62 records information about it. */
64 struct mac_display_info
66 /* Chain of all mac_display_info structures. */
67 struct mac_display_info
*next
;
69 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
70 The same cons cell also appears in x_display_name_list. */
71 Lisp_Object name_list_element
;
73 /* Number of frames that are on this display. */
76 /* Dots per inch of the screen. */
79 /* Number of planes on this screen. */
82 /* Whether the screen supports color */
85 /* Dimensions of this screen. */
88 /* Mask of things that cause the mouse to be grabbed. */
92 /* Emacs bitmap-id of the default icon bitmap for this frame.
93 Or -1 if none has been allocated yet. */
97 /* The root window of this screen. */
100 /* The cursor to use for vertical scroll bars. */
101 Cursor vertical_scroll_bar_cursor
;
103 /* Resource data base */
106 /* A table of all the fonts we have already loaded. */
107 struct font_info
*font_table
;
109 /* The current capacity of font_table. */
112 /* Minimum width over all characters in all fonts in font_table. */
113 int smallest_char_width
;
115 /* Minimum font height over all fonts in font_table. */
116 int smallest_font_height
;
118 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
119 GC scratch_cursor_gc
;
121 /* These variables describe the range of text currently shown in its
122 mouse-face, together with the window they apply to. As long as
123 the mouse stays within this range, we need not redraw anything on
124 its account. Rows and columns are glyph matrix positions in
125 MOUSE_FACE_WINDOW. */
126 int mouse_face_beg_row
, mouse_face_beg_col
;
127 int mouse_face_beg_x
, mouse_face_beg_y
;
128 int mouse_face_end_row
, mouse_face_end_col
;
129 int mouse_face_end_x
, mouse_face_end_y
;
130 int mouse_face_past_end
;
131 Lisp_Object mouse_face_window
;
132 int mouse_face_face_id
;
133 Lisp_Object mouse_face_overlay
;
135 /* 1 if a mouse motion event came and we didn't handle it right away because
136 gc was in progress. */
137 int mouse_face_deferred_gc
;
139 /* FRAME and X, Y position of mouse when last checked for
140 highlighting. X and Y can be negative or out of range for the frame. */
141 struct frame
*mouse_face_mouse_frame
;
142 int mouse_face_mouse_x
, mouse_face_mouse_y
;
144 /* Nonzero means defer mouse-motion highlighting. */
145 int mouse_face_defer
;
147 /* Nonzero means that the mouse highlight should not be shown. */
148 int mouse_face_hidden
;
150 int mouse_face_image_state
;
154 /* The number of fonts actually stored in the font table.
155 font_table[n] is used and valid iff 0 <= n < n_fonts. 0 <=
156 n_fonts <= font_table_size and font_table[i].name != 0. */
159 /* Pointer to bitmap records. */
160 struct mac_bitmap_record
*bitmaps
;
162 /* Allocated size of bitmaps field. */
165 /* Last used bitmap index. */
168 /* The frame (if any) which has the window that has keyboard focus.
169 Zero if none. This is examined by Ffocus_frame in macfns.c. Note
170 that a mere EnterNotify event can set this; if you need to know the
171 last frame specified in a FocusIn or FocusOut event, use
172 x_focus_event_frame. */
173 struct frame
*x_focus_frame
;
175 /* The last frame mentioned in a FocusIn or FocusOut event. This is
176 separate from x_focus_frame, because whether or not LeaveNotify
177 events cause us to lose focus depends on whether or not we have
178 received a FocusIn event for it. */
179 struct frame
*x_focus_event_frame
;
181 /* The frame which currently has the visual highlight, and should get
182 keyboard input (other sorts of input have the frame encoded in the
183 event). It points to the focus frame's selected window's
184 frame. It differs from x_focus_frame when we're using a global
186 struct frame
*x_highlight_frame
;
188 /* Cache of images. */
189 struct image_cache
*image_cache
;
192 /* This checks to make sure we have a display. */
193 extern void check_mac
P_ ((void));
195 #define x_display_info mac_display_info
197 /* This is a chain of structures for all the X displays currently in use. */
198 extern struct x_display_info
*x_display_list
;
200 /* This is a chain of structures for all the displays currently in use. */
201 extern struct mac_display_info one_mac_display_info
;
203 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
204 one for each element of x_display_list and in the same order.
205 NAME is the name of the frame.
206 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
207 extern Lisp_Object x_display_name_list
;
209 extern struct x_display_info
*x_display_info_for_display
P_ ((Display
*));
210 extern struct x_display_info
*x_display_info_for_name
P_ ((Lisp_Object
));
212 extern struct mac_display_info
*mac_term_init
P_ ((Lisp_Object
, char *, char *));
214 extern Lisp_Object x_list_fonts
P_ ((struct frame
*, Lisp_Object
, int, int));
215 extern struct font_info
*x_get_font_info
P_ ((struct frame
*f
, int));
216 extern struct font_info
*x_load_font
P_ ((struct frame
*, char *, int));
217 extern struct font_info
*x_query_font
P_ ((struct frame
*, char *));
218 extern void x_find_ccl_program
P_ ((struct font_info
*));
220 /* When Emacs uses a tty window, tty_display in frame.c points to an
224 unsigned long background_pixel
;
225 unsigned long foreground_pixel
;
228 /* The collection of data describing a window on the Mac. */
230 /* Placeholder for things accessed through output_data.x. Must
232 struct x_output x_compatible
;
234 /* Menubar "widget" handle. */
237 FRAME_PTR mFP
; /* points back to the frame struct */
239 /* Here are the Graphics Contexts for the default font. */
240 GC normal_gc
; /* Normal video */
241 GC reverse_gc
; /* Reverse video */
242 GC cursor_gc
; /* cursor drawing */
244 /* The window used for this frame.
245 May be zero while the frame object is being created
246 and the window has not yet been created. */
249 /* The window that is the parent of this window.
250 Usually this is a window that was made by the window manager,
251 but it can be the root window, and it can be explicitly specified
252 (see the explicit_parent field, below). */
255 /* Default ASCII font of this frame. */
258 /* The baseline offset of the default ASCII font. */
261 /* If a fontset is specified for this frame instead of font, this
262 value contains an ID of the fontset, else -1. */
265 /* Pixel values used for various purposes.
266 border_pixel may be -1 meaning use a gray tile. */
267 unsigned long cursor_pixel
;
268 unsigned long border_pixel
;
269 unsigned long mouse_pixel
;
270 unsigned long cursor_foreground_pixel
;
273 /* Foreground color for scroll bars. A value of -1 means use the
274 default (black for non-toolkit scroll bars). */
275 unsigned long scroll_bar_foreground_pixel
;
277 /* Background color for scroll bars. A value of -1 means use the
278 default (background color of the frame for non-toolkit scroll
280 unsigned long scroll_bar_background_pixel
;
283 /* Descriptor for the cursor in use for this window. */
285 Cursor nontext_cursor
;
286 Cursor modeline_cursor
;
288 Cursor hourglass_cursor
;
289 Cursor horizontal_drag_cursor
;
291 /* Window whose cursor is hourglass_cursor. This window is temporarily
292 mapped to display a hourglass-cursor. */
293 Window hourglass_window
;
295 /* Non-zero means hourglass cursor is currently displayed. */
296 unsigned hourglass_p
: 1;
298 /* Flag to set when the window needs to be completely repainted. */
303 #if TARGET_API_MAC_CARBON
304 /* The Mac control reference for the hourglass (progress indicator)
305 shown at the upper-right corner of the window. */
306 ControlRef hourglass_control
;
309 /* This is the Emacs structure for the display this frame is on. */
310 /* struct w32_display_info *display_info; */
312 /* Nonzero means our parent is another application's window
313 and was explicitly specified. */
314 char explicit_parent
;
316 /* Nonzero means tried already to make this frame visible. */
317 char asked_for_visible
;
319 /* Nonzero means menubar is currently active. */
322 /* Relief GCs, colors etc. */
329 black_relief
, white_relief
;
331 /* The background for which the above relief GCs were set up.
332 They are changed only when a different background is involved. */
333 unsigned long relief_background
;
335 /* Hints for the size and the position of a window. */
336 XSizeHints
*size_hints
;
339 typedef struct mac_output mac_output
;
341 /* Return the X output data for frame F. */
342 #define FRAME_X_OUTPUT(f) ((f)->output_data.mac)
344 /* Return the Mac window used for displaying data in frame F. */
345 #define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->window_desc)
346 #define FRAME_X_WINDOW(f) ((f)->output_data.mac->window_desc)
348 #define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel)
349 #define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
351 #define FRAME_FONT(f) ((f)->output_data.mac->font)
352 #define FRAME_FONTSET(f) ((f)->output_data.mac->fontset)
354 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.mac->baseline_offset)
356 #define FRAME_SIZE_HINTS(f) ((f)->output_data.mac->size_hints)
358 /* This gives the mac_display_info structure for the display F is on. */
359 #define FRAME_MAC_DISPLAY_INFO(f) (&one_mac_display_info)
360 #define FRAME_X_DISPLAY_INFO(f) (&one_mac_display_info)
362 /* This is the `Display *' which frame F is on. */
363 #define FRAME_MAC_DISPLAY(f) (0)
364 #define FRAME_X_DISPLAY(f) (0)
366 /* This is the 'font_info *' which frame F has. */
367 #define FRAME_MAC_FONT_TABLE(f) (FRAME_MAC_DISPLAY_INFO (f)->font_table)
369 /* Value is the smallest width of any character in any font on frame F. */
371 #define FRAME_SMALLEST_CHAR_WIDTH(F) \
372 FRAME_MAC_DISPLAY_INFO(F)->smallest_char_width
374 /* Value is the smallest height of any font on frame F. */
376 #define FRAME_SMALLEST_FONT_HEIGHT(F) \
377 FRAME_MAC_DISPLAY_INFO(F)->smallest_font_height
379 /* Return a pointer to the image cache of frame F. */
381 #define FRAME_X_IMAGE_CACHE(F) FRAME_MAC_DISPLAY_INFO ((F))->image_cache
384 /* Mac-specific scroll bar stuff. */
386 /* We represent scroll bars as lisp vectors. This allows us to place
387 references to them in windows without worrying about whether we'll
388 end up with windows referring to dead scroll bars; the garbage
389 collector will free it when its time comes.
391 We use struct scroll_bar as a template for accessing fields of the
396 /* These fields are shared by all vectors. */
397 EMACS_INT size_from_Lisp_Vector_struct
;
398 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
400 /* The window we're a scroll bar for. */
403 /* The next and previous in the chain of scroll bars in this frame. */
404 Lisp_Object next
, prev
;
406 /* The Mac control handle of this scroll bar. Since this is a full
407 32-bit quantity, we store it split into two 32-bit values. */
408 Lisp_Object control_handle_low
, control_handle_high
;
410 /* The position and size of the scroll bar in pixels, relative to the
412 Lisp_Object top
, left
, width
, height
;
414 /* The starting and ending positions of the handle, relative to the
415 handle area (i.e. zero is the top position, not
416 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
417 hasn't been drawn yet.
419 These are not actually the locations where the beginning and end
420 are drawn; in order to keep handles from becoming invisible when
421 editing large files, we establish a minimum height by always
422 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
423 where they would be normally; the bottom and top are in a
424 different co-ordinate system. */
425 Lisp_Object start
, end
;
427 /* If the scroll bar handle is currently being dragged by the user,
428 this is the number of pixels from the top of the handle to the
429 place where the user grabbed it. If the handle isn't currently
430 being dragged, this is Qnil. */
431 Lisp_Object dragging
;
433 #ifdef USE_TOOLKIT_SCROLL_BARS
434 /* The position and size of the scroll bar handle track area in
435 pixels, relative to the frame. */
436 Lisp_Object track_top
, track_height
;
440 /* The number of elements a vector holding a struct scroll_bar needs. */
441 #define SCROLL_BAR_VEC_SIZE \
442 ((sizeof (struct scroll_bar) \
443 - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
444 / sizeof (Lisp_Object))
446 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
447 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
450 /* Building a 32-bit C integer from two 16-bit lisp integers. */
451 #define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
453 /* Setting two lisp integers to the low and high words of a 32-bit C int. */
454 #define SCROLL_BAR_UNPACK(low, high, int32) \
455 (XSETINT ((low), (int32) & 0xffff), \
456 XSETINT ((high), ((int32) >> 16) & 0xffff))
459 /* Extract the Mac control handle of the scroll bar from a struct
461 #define SCROLL_BAR_CONTROL_HANDLE(ptr) \
462 ((ControlHandle) SCROLL_BAR_PACK ((ptr)->control_handle_low, \
463 (ptr)->control_handle_high))
465 /* Store a Mac control handle in a struct scroll_bar. */
466 #define SET_SCROLL_BAR_CONTROL_HANDLE(ptr, id) \
467 (SCROLL_BAR_UNPACK ((ptr)->control_handle_low, \
468 (ptr)->control_handle_high, (int) id))
470 /* Return the inside width of a vertical scroll bar, given the outside
472 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
474 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
475 - VERTICAL_SCROLL_BAR_RIGHT_BORDER \
476 - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2)
478 /* Return the length of the rectangle within which the top of the
479 handle must stay. This isn't equivalent to the inside height,
480 because the scroll bar handle has a minimum height.
482 This is the real range of motion for the scroll bar, so when we're
483 scaling buffer positions to scroll bar positions, we use this, not
484 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
485 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f,height) \
486 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) \
487 - VERTICAL_SCROLL_BAR_MIN_HANDLE - UP_AND_DOWN_ARROWS)
489 /* Return the inside height of vertical scroll bar, given the outside
490 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
491 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f,height) \
492 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER \
493 - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
496 /* Border widths for scroll bars.
498 Scroll bar windows don't have any borders; their border width is
499 set to zero, and we redraw borders ourselves. This makes the code
500 a bit cleaner, since we don't have to convert between outside width
501 (used when relating to the rest of the screen) and inside width
502 (used when sizing and drawing the scroll bar window itself).
504 The handle moves up and down/back and forth in a rectangle inset
505 from the edges of the scroll bar. These are widths by which we
506 inset the handle boundaries from the scroll bar edges. */
507 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (0)
508 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (0)
509 #define VERTICAL_SCROLL_BAR_TOP_BORDER (0)
510 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (0)
512 /* Minimum lengths for scroll bar handles, in pixels. */
513 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (16)
515 /* Combined length of up and down arrow boxes in scroll bars, in pixels. */
516 #define UP_AND_DOWN_ARROWS (32)
518 /* Trimming off a few pixels from each side prevents
519 text from glomming up against the scroll bar */
520 #define VERTICAL_SCROLL_BAR_WIDTH_TRIM (0)
522 /* Size of hourglass controls */
523 #define HOURGLASS_WIDTH 16
524 #define HOURGLASS_HEIGHT 16
530 Lisp_Object display_x_get_resource
P_ ((struct x_display_info
*,
531 Lisp_Object
, Lisp_Object
,
532 Lisp_Object
, Lisp_Object
));
533 struct frame
*check_x_frame
P_ ((Lisp_Object
));
534 EXFUN (Fx_display_color_p
, 1);
535 EXFUN (Fx_display_grayscale_p
, 1);
536 EXFUN (Fx_display_planes
, 1);
537 extern void x_free_gcs
P_ ((struct frame
*));
538 extern int XParseGeometry
P_ ((char *, int *, int *, unsigned int *,
541 /* Defined in macterm.c. */
543 extern void x_set_window_size
P_ ((struct frame
*, int, int, int));
544 extern void x_make_frame_visible
P_ ((struct frame
*));
545 extern void mac_initialize
P_ ((void));
546 extern Pixmap XCreatePixmap
P_ ((Display
*, WindowPtr
, unsigned int,
547 unsigned int, unsigned int));
548 extern Pixmap XCreatePixmapFromBitmapData
P_ ((Display
*, WindowPtr
, char *,
549 unsigned int, unsigned int,
550 unsigned long, unsigned long,
552 extern void XFreePixmap
P_ ((Display
*, Pixmap
));
553 extern GC XCreateGC
P_ ((Display
*, Window
, unsigned long, XGCValues
*));
554 extern void XSetForeground
P_ ((Display
*, GC
, unsigned long));
555 extern void XSetBackground
P_ ((Display
*, GC
, unsigned long));
556 extern void XSetWindowBackground
P_ ((Display
*, WindowPtr
, unsigned long));
557 extern void mac_draw_line_to_pixmap
P_ ((Display
*, Pixmap
, GC
, int, int,
559 extern void mac_clear_area
P_ ((struct frame
*, int, int,
560 unsigned int, unsigned int));
561 extern void mac_unload_font
P_ ((struct mac_display_info
*, XFontStruct
*));
562 extern OSErr install_window_handler
P_ ((WindowPtr
));
563 extern void remove_window_handler
P_ ((WindowPtr
));
564 extern Lisp_Object mac_make_lispy_event_code
P_ ((int));
566 #define FONT_TYPE_FOR_UNIBYTE(font, ch) 0
567 #define FONT_TYPE_FOR_MULTIBYTE(font, ch) 0
569 #define TYPE_FILE_NAME 'fNam'
571 /* Defined in macselect.c */
573 extern void x_clear_frame_selections
P_ ((struct frame
*));
575 /* Defined in mac.c. */
577 extern void mac_clear_font_name_table
P_ ((void));
578 extern Lisp_Object mac_aedesc_to_lisp
P_ ((AEDesc
*));
579 #if TARGET_API_MAC_CARBON
580 extern OSErr create_apple_event_from_event_ref
P_ ((EventRef
, UInt32
,
584 extern CFStringRef cfstring_create_with_utf8_cstring
P_ ((const char *));
585 extern CFStringRef cfstring_create_with_string
P_ ((Lisp_Object
));
586 extern Lisp_Object cfdata_to_lisp
P_ ((CFDataRef
));
587 extern Lisp_Object cfstring_to_lisp_nodecode
P_ ((CFStringRef
));
588 extern Lisp_Object cfstring_to_lisp
P_ ((CFStringRef
));
589 extern Lisp_Object cfnumber_to_lisp
P_ ((CFNumberRef
));
590 extern Lisp_Object cfdate_to_lisp
P_ ((CFDateRef
));
591 extern Lisp_Object cfboolean_to_lisp
P_ ((CFBooleanRef
));
592 extern Lisp_Object cfobject_desc_to_lisp
P_ ((CFTypeRef
));
593 extern Lisp_Object cfproperty_list_to_lisp
P_ ((CFPropertyListRef
, int, int));
595 extern void xrm_merge_string_database
P_ ((XrmDatabase
, char *));
596 extern Lisp_Object xrm_get_resource
P_ ((XrmDatabase
, char *, char *));
597 extern XrmDatabase xrm_get_preference_database
P_ ((char *));
598 EXFUN (Fmac_get_preference
, 4);
600 /* arch-tag: 6b4ca125-5bef-476d-8ee8-31ed808b7e79
601 (do not change this comment) */