1 /* Display module for Mac OS.
2 Copyright (C) 2000 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Contributed by Andrew Choi (akochoi@users.sourceforge.net). */
26 /* The class of this X application. */
27 #define EMACS_CLASS "Emacs"
29 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
31 #define RED_FROM_ULONG(color) ((color) >> 16)
32 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
33 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
35 #define BLACK_PIX_DEFAULT(f) RGB_TO_ULONG(0,0,0)
36 #define WHITE_PIX_DEFAULT(f) RGB_TO_ULONG(255,255,255)
38 #define FONT_WIDTH(f) ((f)->max_bounds.width)
39 #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
40 #define FONT_BASE(f) ((f)->ascent)
41 #define FONT_DESCENT(f) ((f)->descent)
43 #define FONT_MAX_WIDTH(f) FONT_WIDTH(f) /* fix later */
45 enum text_cursor_kinds
{
52 /* Structure recording bitmaps and reference count.
53 If REFCOUNT is 0 then this record is free to be reused. */
55 struct mac_bitmap_record
63 /* For each display (currently only one on mac), we have a structure that
64 records information about it. */
66 struct mac_display_info
68 /* Chain of all mac_display_info structures. */
69 struct mac_display_info
*next
;
71 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
72 The same cons cell also appears in x_display_name_list. */
73 Lisp_Object name_list_element
;
75 /* Number of frames that are on this display. */
78 /* Dots per inch of the screen. */
81 /* Number of planes on this screen. */
84 /* Number of bits per pixel on this screen. */
87 /* Dimensions of this screen. */
90 int height_in
,width_in
;
93 /* Mask of things that cause the mouse to be grabbed. */
97 /* Emacs bitmap-id of the default icon bitmap for this frame.
98 Or -1 if none has been allocated yet. */
102 /* The root window of this screen. */
105 /* The cursor to use for vertical scroll bars. */
106 Cursor vertical_scroll_bar_cursor
;
109 /* color palette information. */
111 struct w32_palette_entry
* color_list
;
115 /* deferred action flags checked when starting frame update. */
118 /* Keystroke that has been faked by Emacs and will be ignored when
119 received; value is reset after key is received. */
124 /* A table of all the fonts we have already loaded. */
125 struct font_info
*font_table
;
127 /* The current capacity of font_table. */
130 /* The number of fonts actually stored in the font table.
131 font_table[n] is used and valid iff 0 <= n < n_fonts. 0 <=
132 n_fonts <= font_table_size. and font_table[i].name != 0. */
135 /* Minimum width over all characters in all fonts in font_table. */
136 int smallest_char_width
;
138 /* Minimum font height over all fonts in font_table. */
139 int smallest_font_height
;
141 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
142 XGCValues
*scratch_cursor_gc
;
144 /* These variables describe the range of text currently shown in its
145 mouse-face, together with the window they apply to. As long as
146 the mouse stays within this range, we need not redraw anything on
147 its account. Rows and columns are glyph matrix positions in
148 MOUSE_FACE_WINDOW. */
149 int mouse_face_beg_row
, mouse_face_beg_col
;
150 int mouse_face_beg_x
, mouse_face_beg_y
;
151 int mouse_face_end_row
, mouse_face_end_col
;
152 int mouse_face_end_x
, mouse_face_end_y
;
153 int mouse_face_past_end
;
155 Lisp_Object mouse_face_window
;
157 int mouse_face_face_id
;
159 /* 1 if a mouse motion event came and we didn't handle it right away because
160 gc was in progress. */
161 int mouse_face_deferred_gc
;
163 /* FRAME and X, Y position of mouse when last checked for
164 highlighting. X and Y can be negative or out of range for the frame. */
165 struct frame
*mouse_face_mouse_frame
;
167 int mouse_face_mouse_x
, mouse_face_mouse_y
;
169 /* Nonzero means defer mouse-motion highlighting. */
170 int mouse_face_defer
;
172 int mouse_face_image_state
;
176 /* Pointer to bitmap records. */
177 struct mac_bitmap_record
*bitmaps
;
179 /* Allocated size of bitmaps field. */
182 /* Last used bitmap index. */
185 /* The frame (if any) which has the window that has keyboard focus.
186 Zero if none. This is examined by Ffocus_frame in w32fns.c. Note
187 that a mere EnterNotify event can set this; if you need to know the
188 last frame specified in a FocusIn or FocusOut event, use
189 w32_focus_event_frame. */
190 struct frame
*x_focus_frame
;
192 /* The last frame mentioned in a FocusIn or FocusOut event. This is
193 separate from w32_focus_frame, because whether or not LeaveNotify
194 events cause us to lose focus depends on whether or not we have
195 received a FocusIn event for it. */
196 struct frame
*x_focus_event_frame
;
198 /* The frame which currently has the visual highlight, and should get
199 keyboard input (other sorts of input have the frame encoded in the
200 event). It points to the focus frame's selected window's
201 frame. It differs from w32_focus_frame when we're using a global
203 struct frame
*x_highlight_frame
;
205 /* Cache of images. */
206 struct image_cache
*image_cache
;
209 #define x_display_info mac_display_info
211 /* This is a chain of structures for all the displays currently in use. */
212 extern struct mac_display_info one_mac_display_info
;
214 /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
215 one for each element of w32_display_list and in the same order.
216 NAME is the name of the frame.
217 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
218 extern Lisp_Object x_display_name_list
;
220 /* A flag to control how to display unibyte 8-bit character. */
221 extern int unibyte_display_via_language_environment
;
223 extern struct x_display_info
*x_display_info_for_display
P_ ((Display
*));
224 extern struct x_display_info
*x_display_info_for_name
P_ ((Lisp_Object
));
226 extern struct mac_display_info
*mac_term_init ();
228 /* The collection of data describing a window on the Mac. Functions
229 defined in macterm.c */
231 WindowPtr mWP
; /* pointer to QuickDraw window */
232 FRAME_PTR mFP
; /* points back to the frame struct */
235 int mNumCols
; /* number of characters per column */
236 int mNumRows
; /* number of characters per row */
237 int mLineHeight
; /* height of one line of text in pixels */
238 int mCharWidth
; /* width of one character in pixels */
239 int mHomeX
; /* X pixel coordinate of lower left corner of character at (0, 0) */
240 int mHomeY
; /* Y pixel coordinate of lower left corner of character at (0, 0) */
241 int mHighlight
; /* current highlight state (0 = off). */
242 int mTermWinSize
; /* num of lines from top of window affected by ins_del_lines; set by set_terminal_window. */
246 /* stuffs used by xfaces.c */
247 struct face
**param_faces
;
249 struct face
**computed_faces
;
250 int n_computed_faces
;
251 int size_computed_faces
;
254 unsigned long background_pixel
;
255 unsigned long foreground_pixel
;
257 /* Position of the Mac window (x and y offsets in global coordinates). */
261 /* Border width of the W32 window as known by the window system. */
264 /* Size of the W32 window in pixels. */
265 int pixel_height
, pixel_width
;
267 /* Height of a line, in pixels. */
270 /* Here are the Graphics Contexts for the default font. */
271 GC normal_gc
; /* Normal video */
272 GC reverse_gc
; /* Reverse video */
273 GC cursor_gc
; /* cursor drawing */
275 /* Width of the internal border. This is a line of background color
276 just inside the window's border. When the frame is selected,
277 a highlighting is displayed inside the internal border. */
278 int internal_border_width
;
280 /* The window used for this frame.
281 May be zero while the frame object is being created
282 and the window has not yet been created. */
285 /* The window that is the parent of this window.
286 Usually this is a window that was made by the window manager,
287 but it can be the root window, and it can be explicitly specified
288 (see the explicit_parent field, below). */
291 /* Default ASCII font of this frame. */
294 /* The baseline offset of the default ASCII font. */
297 /* If a fontset is specified for this frame instead of font, this
298 value contains an ID of the fontset, else -1. */
301 /* Pixel values used for various purposes.
302 border_pixel may be -1 meaning use a gray tile. */
303 unsigned long cursor_pixel
;
304 unsigned long border_pixel
;
305 unsigned long mouse_pixel
;
306 unsigned long cursor_foreground_pixel
;
308 /* Foreground color for scroll bars. A value of -1 means use the
309 default (black for non-toolkit scroll bars). */
310 unsigned long scroll_bar_foreground_pixel
;
312 /* Background color for scroll bars. A value of -1 means use the
313 default (background color of the frame for non-toolkit scroll
315 unsigned long scroll_bar_background_pixel
;
317 /* Descriptor for the cursor in use for this window. */
319 Cursor nontext_cursor
;
320 Cursor modeline_cursor
;
324 /* Window whose cursor is busy_cursor. This window is temporarily
325 mapped to display a busy-cursor. */
328 /* Non-zero means busy cursor is currently displayed. */
331 /* Flag to set when the window needs to be completely repainted. */
336 /* What kind of text cursor is drawn in this window right now?
337 (If there is no cursor (phys_cursor_x < 0), then this means nothing.) */
338 enum text_cursor_kinds current_cursor
;
340 /* What kind of text cursor should we draw in the future?
341 This should always be filled_box_cursor or bar_cursor. */
342 enum text_cursor_kinds desired_cursor
;
344 /* Width of bar cursor (if we are using that). */
351 /* The size of the extra width currently allotted for vertical
352 scroll bars, in pixels. */
353 int vertical_scroll_bar_extra
;
355 /* The extra width currently allotted for the areas in which
356 truncation marks, continuation marks, and overlay arrows are
358 int flags_areas_extra
;
360 /* This is the gravity value for the specified window position. */
363 /* The geometry flags for this window. */
366 /* This is the Emacs structure for the display this frame is on. */
367 /* struct w32_display_info *display_info; */
369 /* Nonzero means our parent is another application's window
370 and was explicitly specified. */
371 char explicit_parent
;
373 /* Nonzero means tried already to make this frame visible. */
374 char asked_for_visible
;
376 /* Nonzero means menubar is currently active. */
379 /* Always contains NULL on the Mac OS because the menu bar is shared. */
383 /* Nonzero means menubar is about to become active, but should be
384 brought up to date first. */
385 volatile char pending_menu_activation
;
388 /* Relief GCs, colors etc. */
395 black_relief
, white_relief
;
397 /* The background for which the above relief GCs were set up.
398 They are changed only when a different background is involved. */
399 unsigned long relief_background
;
402 typedef struct mac_output mac_output
;
404 /* Return the Mac window used for displaying data in frame F. */
405 #define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->mWP)
407 #define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.mac->foreground_pixel)
408 #define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.mac->background_pixel)
410 #define FRAME_FONT(f) ((f)->output_data.mac->font)
411 #define FRAME_FONTSET(f) ((f)->output_data.mac->fontset)
413 #define FRAME_INTERNAL_BORDER_WIDTH(f) ((f)->output_data.mac->internal_border_width)
414 #define FRAME_LINE_HEIGHT(f) ((f)->output_data.mac->line_height)
415 /* Width of the default font of frame F. Must be defined by each
416 terminal specific header. */
417 #define FRAME_DEFAULT_FONT_WIDTH(F) FONT_WIDTH (FRAME_FONT (F))
418 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.mac->baseline_offset)
420 /* This gives the w32_display_info structure for the display F is on. */
421 #define FRAME_MAC_DISPLAY_INFO(f) (&one_mac_display_info)
422 #define FRAME_X_DISPLAY_INFO(f) (&one_mac_display_info)
424 /* This is the `Display *' which frame F is on. */
425 #define FRAME_MAC_DISPLAY(f) (0)
427 /* This is the 'font_info *' which frame F has. */
428 #define FRAME_MAC_FONT_TABLE(f) (FRAME_MAC_DISPLAY_INFO (f)->font_table)
430 /* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */
431 #define PIXEL_WIDTH(f) ((f)->output_data.mac->pixel_width)
432 #define PIXEL_HEIGHT(f) ((f)->output_data.mac->pixel_height)
434 #define FRAME_DESIRED_CURSOR(f) ((f)->output_data.mac->desired_cursor)
436 /* Value is the smallest width of any character in any font on frame F. */
438 #define FRAME_SMALLEST_CHAR_WIDTH(F) \
439 FRAME_MAC_DISPLAY_INFO(F)->smallest_char_width
441 /* Value is the smallest height of any font on frame F. */
443 #define FRAME_SMALLEST_FONT_HEIGHT(F) \
444 FRAME_MAC_DISPLAY_INFO(F)->smallest_font_height
446 /* Return a pointer to the image cache of frame F. */
448 #define FRAME_X_IMAGE_CACHE(F) FRAME_MAC_DISPLAY_INFO ((F))->image_cache
451 /* Pixel width of the bitmaps drawn to indicate truncation,
454 #define FRAME_FLAGS_BITMAP_WIDTH(f) 8
455 #define FRAME_FLAGS_BITMAP_HEIGHT(f) 8
457 /* Total width of areas reserved for drawing truncation bitmaps,
458 continuation bitmaps and alike. The width is in canonical char
459 units of the frame. This must currently be the case because window
460 sizes aren't pixel values. If it weren't the case, we wouldn't be
461 able to split windows horizontally nicely. */
463 #define FRAME_X_FLAGS_AREA_COLS(F) \
464 ((2 * FRAME_FLAGS_BITMAP_WIDTH ((F)) + CANON_X_UNIT ((F)) - 1) \
465 / CANON_X_UNIT ((F)))
467 /* Total width of flags areas in pixels. */
469 #define FRAME_X_FLAGS_AREA_WIDTH(F) \
470 (FRAME_X_FLAGS_AREA_COLS ((F)) * CANON_X_UNIT ((F)))
472 /* Pixel-width of the left flags area. */
474 #define FRAME_X_LEFT_FLAGS_AREA_WIDTH(F) \
475 (FRAME_X_FLAGS_AREA_WIDTH (F) / 2)
477 /* Pixel-width of the right flags area. Note that we are doing
478 integer arithmetic here, so don't loose a pixel if the total
479 width is an odd number. */
481 #define FRAME_X_RIGHT_FLAGS_AREA_WIDTH(F) \
482 (FRAME_X_FLAGS_AREA_WIDTH (F) - FRAME_X_FLAGS_AREA_WIDTH (F) / 2)
486 /* Mac-specific scroll bar stuff. */
488 /* We represent scroll bars as lisp vectors. This allows us to place
489 references to them in windows without worrying about whether we'll
490 end up with windows referring to dead scroll bars; the garbage
491 collector will free it when its time comes.
493 We use struct scroll_bar as a template for accessing fields of the
498 /* These fields are shared by all vectors. */
499 EMACS_INT size_from_Lisp_Vector_struct
;
500 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
502 /* The window we're a scroll bar for. */
505 /* The next and previous in the chain of scroll bars in this frame. */
506 Lisp_Object next
, prev
;
508 /* The Mac control handle of this scroll bar. Since this is a full
509 32-bit quantity, we store it split into two 32-bit values. */
510 Lisp_Object control_handle_low
, control_handle_high
;
512 /* The position and size of the scroll bar in pixels, relative to the
514 Lisp_Object top
, left
, width
, height
;
516 /* The starting and ending positions of the handle, relative to the
517 handle area (i.e. zero is the top position, not
518 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
519 hasn't been drawn yet.
521 These are not actually the locations where the beginning and end
522 are drawn; in order to keep handles from becoming invisible when
523 editing large files, we establish a minimum height by always
524 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
525 where they would be normally; the bottom and top are in a
526 different co-ordinate system. */
527 Lisp_Object start
, end
;
529 /* If the scroll bar handle is currently being dragged by the user,
530 this is the number of pixels from the top of the handle to the
531 place where the user grabbed it. If the handle isn't currently
532 being dragged, this is Qnil. */
533 Lisp_Object dragging
;
536 /* The number of elements a vector holding a struct scroll_bar needs. */
537 #define SCROLL_BAR_VEC_SIZE \
538 ((sizeof (struct scroll_bar) \
539 - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
540 / sizeof (Lisp_Object))
542 /* Turning a lisp vector value into a pointer to a struct scroll_bar. */
543 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
546 /* Building a 32-bit C integer from two 16-bit lisp integers. */
547 #define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
549 /* Setting two lisp integers to the low and high words of a 32-bit C int. */
550 #define SCROLL_BAR_UNPACK(low, high, int32) \
551 (XSETINT ((low), (int32) & 0xffff), \
552 XSETINT ((high), ((int32) >> 16) & 0xffff))
555 /* Extract the Mac control handle of the scroll bar from a struct scroll_bar. */
556 #define SCROLL_BAR_CONTROL_HANDLE(ptr) \
557 ((ControlHandle) SCROLL_BAR_PACK ((ptr)->control_handle_low, (ptr)->control_handle_high))
559 /* Store a Mac control handle in a struct scroll_bar. */
560 #define SET_SCROLL_BAR_CONTROL_HANDLE(ptr, id) \
561 (SCROLL_BAR_UNPACK ((ptr)->control_handle_low, (ptr)->control_handle_high, (int) id))
563 /* Return the inside width of a vertical scroll bar, given the outside
565 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f,width) \
567 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
568 - VERTICAL_SCROLL_BAR_RIGHT_BORDER \
569 - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2)
571 /* Return the length of the rectangle within which the top of the
572 handle must stay. This isn't equivalent to the inside height,
573 because the scroll bar handle has a minimum height.
575 This is the real range of motion for the scroll bar, so when we're
576 scaling buffer positions to scroll bar positions, we use this, not
577 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
578 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f,height) \
579 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE - UP_AND_DOWN_ARROWS)
581 /* Return the inside height of vertical scroll bar, given the outside
582 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
583 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f,height) \
584 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
587 /* Border widths for scroll bars.
589 Scroll bar windows don't have any borders; their border width is
590 set to zero, and we redraw borders ourselves. This makes the code
591 a bit cleaner, since we don't have to convert between outside width
592 (used when relating to the rest of the screen) and inside width
593 (used when sizing and drawing the scroll bar window itself).
595 The handle moves up and down/back and forth in a rectangle inset
596 from the edges of the scroll bar. These are widths by which we
597 inset the handle boundaries from the scroll bar edges. */
598 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (0)
599 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (0)
600 #define VERTICAL_SCROLL_BAR_TOP_BORDER (0)
601 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (0)
603 /* Minimum lengths for scroll bar handles, in pixels. */
604 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (16)
606 /* Combined length of up and down arrow boxes in scroll bars, in pixels. */
607 #define UP_AND_DOWN_ARROWS (32)
609 /* Trimming off a few pixels from each side prevents
610 text from glomming up against the scroll bar */
611 #define VERTICAL_SCROLL_BAR_WIDTH_TRIM (0)
614 /* Manipulating pixel sizes and character sizes.
615 Knowledge of which factors affect the overall size of the window should
616 be hidden in these macros, if that's possible.
618 Return the upper/left pixel position of the character cell on frame F
620 #define CHAR_TO_PIXEL_ROW(f, row) \
621 ((f)->output_data.mac->internal_border_width \
622 + (row) * (f)->output_data.mac->line_height)
623 #define CHAR_TO_PIXEL_COL(f, col) \
624 ((f)->output_data.mac->internal_border_width \
625 + (col) * FONT_WIDTH ((f)->output_data.mac->font))
627 /* Return the pixel width/height of frame F if it has
628 WIDTH columns/HEIGHT rows. */
629 #define CHAR_TO_PIXEL_WIDTH(f, width) \
630 (CHAR_TO_PIXEL_COL (f, width) \
631 + (f)->output_data.mac->vertical_scroll_bar_extra \
632 + (f)->output_data.mac->flags_areas_extra \
633 + (f)->output_data.mac->internal_border_width)
634 #define CHAR_TO_PIXEL_HEIGHT(f, height) \
635 (CHAR_TO_PIXEL_ROW (f, height) \
636 + (f)->output_data.mac->internal_border_width)
639 /* Return the row/column (zero-based) of the character cell containing
640 the pixel on FRAME at ROW/COL. */
641 #define PIXEL_TO_CHAR_ROW(f, row) \
642 (((row) - (f)->output_data.mac->internal_border_width) \
643 / (f)->output_data.mac->line_height)
644 #define PIXEL_TO_CHAR_COL(f, col) \
645 (((col) - (f)->output_data.mac->internal_border_width) \
646 / FONT_WIDTH ((f)->output_data.mac->font))
648 /* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on
650 #define PIXEL_TO_CHAR_WIDTH(f, width) \
651 (PIXEL_TO_CHAR_COL (f, ((width) \
652 - (f)->output_data.mac->internal_border_width \
653 - (f)->output_data.mac->flags_areas_extra \
654 - (f)->output_data.mac->vertical_scroll_bar_extra)))
655 #define PIXEL_TO_CHAR_HEIGHT(f, height) \
656 (PIXEL_TO_CHAR_ROW (f, ((height) \
657 - (f)->output_data.mac->internal_border_width)))
659 struct frame
* check_x_frame (Lisp_Object
);
661 /* Dummy entry for defining tty_display in frame.c. */