Commit | Line | Data |
---|---|---|
1a578e9b AC |
1 | /* Display module for Mac OS. |
2 | Copyright (C) 2000 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GNU Emacs. | |
5 | ||
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) | |
9 | any later version. | |
10 | ||
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. | |
15 | ||
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. */ | |
20 | ||
21 | /* Contributed by Andrew Choi (akochoi@users.sourceforge.net). */ | |
22 | ||
23 | #include "macgui.h" | |
24 | #include "frame.h" | |
25 | ||
26 | /* The class of this X application. */ | |
27 | #define EMACS_CLASS "Emacs" | |
28 | ||
29 | #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b)) | |
30 | ||
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) | |
34 | ||
35 | #define BLACK_PIX_DEFAULT(f) RGB_TO_ULONG(0,0,0) | |
36 | #define WHITE_PIX_DEFAULT(f) RGB_TO_ULONG(255,255,255) | |
37 | ||
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) | |
42 | ||
43 | #define FONT_MAX_WIDTH(f) FONT_WIDTH(f) /* fix later */ | |
44 | ||
45 | enum text_cursor_kinds { | |
46 | NO_CURSOR = -1, | |
47 | FILLED_BOX_CURSOR, | |
48 | HOLLOW_BOX_CURSOR, | |
49 | BAR_CURSOR | |
50 | }; | |
51 | ||
52 | /* Structure recording bitmaps and reference count. | |
53 | If REFCOUNT is 0 then this record is free to be reused. */ | |
54 | ||
55 | struct mac_bitmap_record | |
56 | { | |
57 | char *bitmap_data; | |
58 | int refcount; | |
59 | int height, width; | |
60 | }; | |
61 | ||
62 | ||
63 | /* For each display (currently only one on mac), we have a structure that | |
64 | records information about it. */ | |
65 | ||
66 | struct mac_display_info | |
67 | { | |
68 | /* Chain of all mac_display_info structures. */ | |
69 | struct mac_display_info *next; | |
70 | ||
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; | |
74 | ||
75 | /* Number of frames that are on this display. */ | |
76 | int reference_count; | |
77 | ||
78 | /* Dots per inch of the screen. */ | |
79 | double resx, resy; | |
80 | ||
81 | /* Number of planes on this screen. */ | |
82 | int n_planes; | |
83 | ||
84 | /* Number of bits per pixel on this screen. */ | |
85 | int n_cbits; | |
86 | ||
87 | /* Dimensions of this screen. */ | |
88 | int height, width; | |
89 | #if 0 | |
90 | int height_in,width_in; | |
91 | #endif | |
92 | ||
93 | /* Mask of things that cause the mouse to be grabbed. */ | |
94 | int grabbed; | |
95 | ||
96 | #if 0 | |
97 | /* Emacs bitmap-id of the default icon bitmap for this frame. | |
98 | Or -1 if none has been allocated yet. */ | |
99 | int icon_bitmap_id; | |
100 | ||
101 | #endif | |
102 | /* The root window of this screen. */ | |
103 | Window root_window; | |
104 | ||
105 | /* The cursor to use for vertical scroll bars. */ | |
106 | Cursor vertical_scroll_bar_cursor; | |
107 | ||
108 | #if 0 | |
109 | /* color palette information. */ | |
110 | int has_palette; | |
111 | struct w32_palette_entry * color_list; | |
112 | unsigned num_colors; | |
113 | HPALETTE palette; | |
114 | ||
115 | /* deferred action flags checked when starting frame update. */ | |
116 | int regen_palette; | |
117 | ||
118 | /* Keystroke that has been faked by Emacs and will be ignored when | |
119 | received; value is reset after key is received. */ | |
120 | int faked_key; | |
121 | ||
122 | #endif | |
123 | ||
124 | /* A table of all the fonts we have already loaded. */ | |
125 | struct font_info *font_table; | |
126 | ||
127 | /* The current capacity of font_table. */ | |
128 | int font_table_size; | |
129 | ||
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. */ | |
133 | int n_fonts; | |
134 | ||
135 | /* Minimum width over all characters in all fonts in font_table. */ | |
136 | int smallest_char_width; | |
137 | ||
138 | /* Minimum font height over all fonts in font_table. */ | |
139 | int smallest_font_height; | |
140 | ||
141 | /* Reusable Graphics Context for drawing a cursor in a non-default face. */ | |
142 | XGCValues *scratch_cursor_gc; | |
143 | ||
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; | |
154 | ||
155 | Lisp_Object mouse_face_window; | |
156 | ||
157 | int mouse_face_face_id; | |
158 | ||
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; | |
162 | ||
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; | |
166 | ||
167 | int mouse_face_mouse_x, mouse_face_mouse_y; | |
168 | ||
169 | /* Nonzero means defer mouse-motion highlighting. */ | |
170 | int mouse_face_defer; | |
171 | ||
172 | int mouse_face_image_state; | |
173 | ||
174 | char *mac_id_name; | |
175 | ||
176 | /* Pointer to bitmap records. */ | |
177 | struct mac_bitmap_record *bitmaps; | |
178 | ||
179 | /* Allocated size of bitmaps field. */ | |
180 | int bitmaps_size; | |
181 | ||
182 | /* Last used bitmap index. */ | |
183 | int bitmaps_last; | |
184 | ||
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; | |
191 | ||
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; | |
197 | ||
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 | |
202 | minibuffer. */ | |
203 | struct frame *x_highlight_frame; | |
204 | ||
205 | /* Cache of images. */ | |
206 | struct image_cache *image_cache; | |
207 | }; | |
208 | ||
209 | #define x_display_info mac_display_info | |
210 | ||
211 | /* This is a chain of structures for all the displays currently in use. */ | |
212 | extern struct mac_display_info one_mac_display_info; | |
213 | ||
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; | |
219 | ||
220 | /* A flag to control how to display unibyte 8-bit character. */ | |
221 | extern int unibyte_display_via_language_environment; | |
222 | ||
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)); | |
225 | ||
226 | extern struct mac_display_info *mac_term_init (); | |
227 | ||
228 | /* The collection of data describing a window on the Mac. Functions | |
229 | defined in macterm.c */ | |
230 | struct mac_output { | |
231 | WindowPtr mWP; /* pointer to QuickDraw window */ | |
232 | FRAME_PTR mFP; /* points back to the frame struct */ | |
233 | ||
234 | #if 0 | |
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. */ | |
243 | #endif | |
244 | ||
245 | #if 0 | |
246 | /* stuffs used by xfaces.c */ | |
247 | struct face **param_faces; | |
248 | int n_param_faces; | |
249 | struct face **computed_faces; | |
250 | int n_computed_faces; | |
251 | int size_computed_faces; | |
252 | #endif | |
253 | ||
254 | unsigned long background_pixel; | |
255 | unsigned long foreground_pixel; | |
256 | ||
257 | /* Position of the Mac window (x and y offsets in global coordinates). */ | |
258 | int left_pos; | |
259 | int top_pos; | |
260 | ||
261 | /* Border width of the W32 window as known by the window system. */ | |
262 | int border_width; | |
263 | ||
264 | /* Size of the W32 window in pixels. */ | |
265 | int pixel_height, pixel_width; | |
266 | ||
267 | /* Height of a line, in pixels. */ | |
268 | int line_height; | |
269 | ||
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 */ | |
274 | ||
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; | |
279 | ||
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. */ | |
283 | Window window_desc; | |
284 | ||
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). */ | |
289 | Window parent_desc; | |
290 | ||
291 | /* Default ASCII font of this frame. */ | |
292 | XFontStruct *font; | |
293 | ||
294 | /* The baseline offset of the default ASCII font. */ | |
295 | int baseline_offset; | |
296 | ||
297 | /* If a fontset is specified for this frame instead of font, this | |
298 | value contains an ID of the fontset, else -1. */ | |
299 | int fontset; | |
300 | ||
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; | |
307 | ||
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; | |
311 | ||
312 | /* Background color for scroll bars. A value of -1 means use the | |
313 | default (background color of the frame for non-toolkit scroll | |
314 | bars). */ | |
315 | unsigned long scroll_bar_background_pixel; | |
316 | ||
317 | /* Descriptor for the cursor in use for this window. */ | |
318 | Cursor text_cursor; | |
319 | Cursor nontext_cursor; | |
320 | Cursor modeline_cursor; | |
321 | Cursor cross_cursor; | |
2e875e36 | 322 | Cursor hourglass_cursor; |
1a578e9b | 323 | #if 0 |
2e875e36 AC |
324 | /* Window whose cursor is hourglass_cursor. This window is temporarily |
325 | mapped to display a hourglass-cursor. */ | |
326 | Window hourglass_window; | |
1a578e9b | 327 | |
2e875e36 AC |
328 | /* Non-zero means hourglass cursor is currently displayed. */ |
329 | unsigned hourglass_p : 1; | |
1a578e9b AC |
330 | |
331 | /* Flag to set when the window needs to be completely repainted. */ | |
332 | int needs_exposure; | |
333 | ||
334 | #endif | |
335 | ||
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; | |
339 | ||
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; | |
343 | ||
344 | /* Width of bar cursor (if we are using that). */ | |
345 | int cursor_width; | |
346 | ||
347 | #if 0 | |
348 | DWORD dwStyle; | |
349 | #endif | |
350 | ||
351 | /* The size of the extra width currently allotted for vertical | |
352 | scroll bars, in pixels. */ | |
353 | int vertical_scroll_bar_extra; | |
354 | ||
355 | /* The extra width currently allotted for the areas in which | |
356 | truncation marks, continuation marks, and overlay arrows are | |
357 | displayed. */ | |
358 | int flags_areas_extra; | |
359 | ||
360 | /* This is the gravity value for the specified window position. */ | |
361 | int win_gravity; | |
362 | ||
363 | /* The geometry flags for this window. */ | |
364 | int size_hint_flags; | |
365 | ||
366 | /* This is the Emacs structure for the display this frame is on. */ | |
367 | /* struct w32_display_info *display_info; */ | |
368 | ||
369 | /* Nonzero means our parent is another application's window | |
370 | and was explicitly specified. */ | |
371 | char explicit_parent; | |
372 | ||
373 | /* Nonzero means tried already to make this frame visible. */ | |
374 | char asked_for_visible; | |
375 | ||
376 | /* Nonzero means menubar is currently active. */ | |
377 | char menubar_active; | |
378 | ||
379 | /* Always contains NULL on the Mac OS because the menu bar is shared. */ | |
380 | int menubar_widget; | |
381 | ||
382 | #if 0 | |
383 | /* Nonzero means menubar is about to become active, but should be | |
384 | brought up to date first. */ | |
385 | volatile char pending_menu_activation; | |
386 | ||
387 | #endif | |
388 | /* Relief GCs, colors etc. */ | |
389 | struct relief | |
390 | { | |
391 | XGCValues *gc; | |
392 | unsigned long pixel; | |
393 | int allocated_p; | |
394 | } | |
395 | black_relief, white_relief; | |
396 | ||
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; | |
400 | }; | |
401 | ||
402 | typedef struct mac_output mac_output; | |
403 | ||
404 | /* Return the Mac window used for displaying data in frame F. */ | |
405 | #define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->mWP) | |
406 | ||
407 | #define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.mac->foreground_pixel) | |
408 | #define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.mac->background_pixel) | |
409 | ||
410 | #define FRAME_FONT(f) ((f)->output_data.mac->font) | |
411 | #define FRAME_FONTSET(f) ((f)->output_data.mac->fontset) | |
412 | ||
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) | |
419 | ||
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) | |
423 | ||
424 | /* This is the `Display *' which frame F is on. */ | |
425 | #define FRAME_MAC_DISPLAY(f) (0) | |
426 | ||
427 | /* This is the 'font_info *' which frame F has. */ | |
428 | #define FRAME_MAC_FONT_TABLE(f) (FRAME_MAC_DISPLAY_INFO (f)->font_table) | |
429 | ||
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) | |
433 | ||
434 | #define FRAME_DESIRED_CURSOR(f) ((f)->output_data.mac->desired_cursor) | |
435 | ||
436 | /* Value is the smallest width of any character in any font on frame F. */ | |
437 | ||
438 | #define FRAME_SMALLEST_CHAR_WIDTH(F) \ | |
439 | FRAME_MAC_DISPLAY_INFO(F)->smallest_char_width | |
440 | ||
441 | /* Value is the smallest height of any font on frame F. */ | |
442 | ||
443 | #define FRAME_SMALLEST_FONT_HEIGHT(F) \ | |
444 | FRAME_MAC_DISPLAY_INFO(F)->smallest_font_height | |
445 | ||
446 | /* Return a pointer to the image cache of frame F. */ | |
447 | ||
448 | #define FRAME_X_IMAGE_CACHE(F) FRAME_MAC_DISPLAY_INFO ((F))->image_cache | |
449 | ||
450 | \f | |
451 | /* Pixel width of the bitmaps drawn to indicate truncation, | |
452 | continuation etc. */ | |
453 | ||
454 | #define FRAME_FLAGS_BITMAP_WIDTH(f) 8 | |
455 | #define FRAME_FLAGS_BITMAP_HEIGHT(f) 8 | |
456 | ||
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. */ | |
462 | ||
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))) | |
466 | ||
467 | /* Total width of flags areas in pixels. */ | |
468 | ||
469 | #define FRAME_X_FLAGS_AREA_WIDTH(F) \ | |
470 | (FRAME_X_FLAGS_AREA_COLS ((F)) * CANON_X_UNIT ((F))) | |
471 | ||
472 | /* Pixel-width of the left flags area. */ | |
473 | ||
474 | #define FRAME_X_LEFT_FLAGS_AREA_WIDTH(F) \ | |
475 | (FRAME_X_FLAGS_AREA_WIDTH (F) / 2) | |
476 | ||
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. */ | |
480 | ||
481 | #define FRAME_X_RIGHT_FLAGS_AREA_WIDTH(F) \ | |
482 | (FRAME_X_FLAGS_AREA_WIDTH (F) - FRAME_X_FLAGS_AREA_WIDTH (F) / 2) | |
483 | ||
484 | ||
485 | \f | |
486 | /* Mac-specific scroll bar stuff. */ | |
487 | ||
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. | |
492 | ||
493 | We use struct scroll_bar as a template for accessing fields of the | |
494 | vector. */ | |
495 | ||
496 | struct scroll_bar { | |
497 | ||
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; | |
501 | ||
502 | /* The window we're a scroll bar for. */ | |
503 | Lisp_Object window; | |
504 | ||
505 | /* The next and previous in the chain of scroll bars in this frame. */ | |
506 | Lisp_Object next, prev; | |
507 | ||
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; | |
511 | ||
512 | /* The position and size of the scroll bar in pixels, relative to the | |
513 | frame. */ | |
514 | Lisp_Object top, left, width, height; | |
515 | ||
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. | |
520 | ||
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; | |
528 | ||
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; | |
534 | }; | |
535 | ||
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)) | |
541 | ||
542 | /* Turning a lisp vector value into a pointer to a struct scroll_bar. */ | |
543 | #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec)) | |
544 | ||
545 | ||
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)) | |
548 | ||
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)) | |
553 | ||
554 | ||
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)) | |
558 | ||
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)) | |
562 | ||
563 | /* Return the inside width of a vertical scroll bar, given the outside | |
564 | width. */ | |
565 | #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f,width) \ | |
566 | ((width) \ | |
567 | - VERTICAL_SCROLL_BAR_LEFT_BORDER \ | |
568 | - VERTICAL_SCROLL_BAR_RIGHT_BORDER \ | |
569 | - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2) | |
570 | ||
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. | |
574 | ||
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) | |
580 | ||
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) | |
585 | ||
586 | ||
587 | /* Border widths for scroll bars. | |
588 | ||
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). | |
594 | ||
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) | |
602 | ||
603 | /* Minimum lengths for scroll bar handles, in pixels. */ | |
604 | #define VERTICAL_SCROLL_BAR_MIN_HANDLE (16) | |
605 | ||
606 | /* Combined length of up and down arrow boxes in scroll bars, in pixels. */ | |
607 | #define UP_AND_DOWN_ARROWS (32) | |
608 | ||
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) | |
612 | ||
613 | \f | |
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. | |
617 | ||
618 | Return the upper/left pixel position of the character cell on frame F | |
619 | at ROW/COL. */ | |
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)) | |
626 | ||
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) | |
637 | ||
638 | ||
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)) | |
647 | ||
648 | /* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on | |
649 | frame F? */ | |
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))) | |
658 | ||
659 | struct frame * check_x_frame (Lisp_Object); | |
660 | ||
661 | /* Dummy entry for defining tty_display in frame.c. */ | |
662 | struct x_output | |
663 | { | |
664 | char _dummy; | |
665 | }; |