Commit | Line | Data |
---|---|---|
1a578e9b | 1 | /* Display module for Mac OS. |
e0f712ba | 2 | Copyright (C) 2000, 2001 Free Software Foundation, Inc. |
1a578e9b AC |
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 | ||
e0f712ba | 21 | /* Contributed by Andrew Choi (akochoi@mac.com). */ |
1a578e9b AC |
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 | ||
1a578e9b AC |
45 | /* Structure recording bitmaps and reference count. |
46 | If REFCOUNT is 0 then this record is free to be reused. */ | |
47 | ||
48 | struct mac_bitmap_record | |
49 | { | |
50 | char *bitmap_data; | |
51 | int refcount; | |
52 | int height, width; | |
53 | }; | |
54 | ||
55 | ||
56 | /* For each display (currently only one on mac), we have a structure that | |
57 | records information about it. */ | |
58 | ||
59 | struct mac_display_info | |
60 | { | |
61 | /* Chain of all mac_display_info structures. */ | |
62 | struct mac_display_info *next; | |
63 | ||
64 | /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). | |
65 | The same cons cell also appears in x_display_name_list. */ | |
66 | Lisp_Object name_list_element; | |
67 | ||
68 | /* Number of frames that are on this display. */ | |
69 | int reference_count; | |
70 | ||
71 | /* Dots per inch of the screen. */ | |
72 | double resx, resy; | |
73 | ||
74 | /* Number of planes on this screen. */ | |
75 | int n_planes; | |
76 | ||
77 | /* Number of bits per pixel on this screen. */ | |
78 | int n_cbits; | |
79 | ||
80 | /* Dimensions of this screen. */ | |
81 | int height, width; | |
82 | #if 0 | |
83 | int height_in,width_in; | |
84 | #endif | |
85 | ||
86 | /* Mask of things that cause the mouse to be grabbed. */ | |
87 | int grabbed; | |
88 | ||
89 | #if 0 | |
90 | /* Emacs bitmap-id of the default icon bitmap for this frame. | |
91 | Or -1 if none has been allocated yet. */ | |
92 | int icon_bitmap_id; | |
93 | ||
94 | #endif | |
95 | /* The root window of this screen. */ | |
96 | Window root_window; | |
97 | ||
98 | /* The cursor to use for vertical scroll bars. */ | |
e0f712ba | 99 | struct Cursor *vertical_scroll_bar_cursor; |
1a578e9b AC |
100 | |
101 | #if 0 | |
102 | /* color palette information. */ | |
103 | int has_palette; | |
104 | struct w32_palette_entry * color_list; | |
105 | unsigned num_colors; | |
106 | HPALETTE palette; | |
107 | ||
108 | /* deferred action flags checked when starting frame update. */ | |
109 | int regen_palette; | |
110 | ||
111 | /* Keystroke that has been faked by Emacs and will be ignored when | |
112 | received; value is reset after key is received. */ | |
113 | int faked_key; | |
114 | ||
115 | #endif | |
116 | ||
117 | /* A table of all the fonts we have already loaded. */ | |
118 | struct font_info *font_table; | |
119 | ||
120 | /* The current capacity of font_table. */ | |
121 | int font_table_size; | |
122 | ||
123 | /* The number of fonts actually stored in the font table. | |
124 | font_table[n] is used and valid iff 0 <= n < n_fonts. 0 <= | |
125 | n_fonts <= font_table_size. and font_table[i].name != 0. */ | |
126 | int n_fonts; | |
127 | ||
128 | /* Minimum width over all characters in all fonts in font_table. */ | |
129 | int smallest_char_width; | |
130 | ||
131 | /* Minimum font height over all fonts in font_table. */ | |
132 | int smallest_font_height; | |
133 | ||
134 | /* Reusable Graphics Context for drawing a cursor in a non-default face. */ | |
135 | XGCValues *scratch_cursor_gc; | |
136 | ||
137 | /* These variables describe the range of text currently shown in its | |
138 | mouse-face, together with the window they apply to. As long as | |
139 | the mouse stays within this range, we need not redraw anything on | |
140 | its account. Rows and columns are glyph matrix positions in | |
141 | MOUSE_FACE_WINDOW. */ | |
142 | int mouse_face_beg_row, mouse_face_beg_col; | |
143 | int mouse_face_beg_x, mouse_face_beg_y; | |
144 | int mouse_face_end_row, mouse_face_end_col; | |
145 | int mouse_face_end_x, mouse_face_end_y; | |
146 | int mouse_face_past_end; | |
1a578e9b | 147 | Lisp_Object mouse_face_window; |
1a578e9b | 148 | int mouse_face_face_id; |
e0f712ba | 149 | Lisp_Object mouse_face_overlay; |
1a578e9b AC |
150 | |
151 | /* 1 if a mouse motion event came and we didn't handle it right away because | |
152 | gc was in progress. */ | |
153 | int mouse_face_deferred_gc; | |
154 | ||
155 | /* FRAME and X, Y position of mouse when last checked for | |
156 | highlighting. X and Y can be negative or out of range for the frame. */ | |
157 | struct frame *mouse_face_mouse_frame; | |
158 | ||
159 | int mouse_face_mouse_x, mouse_face_mouse_y; | |
160 | ||
161 | /* Nonzero means defer mouse-motion highlighting. */ | |
162 | int mouse_face_defer; | |
163 | ||
e0f712ba AC |
164 | /* Nonzero means that the mouse highlight should not be shown. */ |
165 | int mouse_face_hidden; | |
166 | ||
1a578e9b AC |
167 | int mouse_face_image_state; |
168 | ||
169 | char *mac_id_name; | |
170 | ||
171 | /* Pointer to bitmap records. */ | |
172 | struct mac_bitmap_record *bitmaps; | |
173 | ||
174 | /* Allocated size of bitmaps field. */ | |
175 | int bitmaps_size; | |
176 | ||
177 | /* Last used bitmap index. */ | |
178 | int bitmaps_last; | |
179 | ||
180 | /* The frame (if any) which has the window that has keyboard focus. | |
181 | Zero if none. This is examined by Ffocus_frame in w32fns.c. Note | |
182 | that a mere EnterNotify event can set this; if you need to know the | |
183 | last frame specified in a FocusIn or FocusOut event, use | |
184 | w32_focus_event_frame. */ | |
185 | struct frame *x_focus_frame; | |
186 | ||
187 | /* The last frame mentioned in a FocusIn or FocusOut event. This is | |
188 | separate from w32_focus_frame, because whether or not LeaveNotify | |
189 | events cause us to lose focus depends on whether or not we have | |
190 | received a FocusIn event for it. */ | |
191 | struct frame *x_focus_event_frame; | |
192 | ||
193 | /* The frame which currently has the visual highlight, and should get | |
194 | keyboard input (other sorts of input have the frame encoded in the | |
195 | event). It points to the focus frame's selected window's | |
196 | frame. It differs from w32_focus_frame when we're using a global | |
197 | minibuffer. */ | |
198 | struct frame *x_highlight_frame; | |
199 | ||
200 | /* Cache of images. */ | |
201 | struct image_cache *image_cache; | |
202 | }; | |
203 | ||
204 | #define x_display_info mac_display_info | |
205 | ||
11c78113 AC |
206 | /* This is a chain of structures for all the X displays currently in use. */ |
207 | extern struct x_display_info *x_display_list; | |
208 | ||
e0f712ba AC |
209 | /* This is a chain of structures for all the displays currently in use. */ |
210 | extern struct mac_display_info one_mac_display_info; | |
211 | ||
1a578e9b | 212 | /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE), |
11c78113 | 213 | one for each element of x_display_list and in the same order. |
1a578e9b AC |
214 | NAME is the name of the frame. |
215 | FONT-LIST-CACHE records previous values returned by x-list-fonts. */ | |
216 | extern Lisp_Object x_display_name_list; | |
217 | ||
218 | /* A flag to control how to display unibyte 8-bit character. */ | |
219 | extern int unibyte_display_via_language_environment; | |
220 | ||
221 | extern struct x_display_info *x_display_info_for_display P_ ((Display *)); | |
222 | extern struct x_display_info *x_display_info_for_name P_ ((Lisp_Object)); | |
223 | ||
224 | extern struct mac_display_info *mac_term_init (); | |
225 | ||
e0f712ba AC |
226 | /* When Emacs uses a tty window, tty_display in frame.c points to an |
227 | x_output struct . */ | |
228 | struct x_output | |
229 | { | |
230 | unsigned long background_pixel; | |
231 | unsigned long foreground_pixel; | |
232 | }; | |
233 | ||
234 | /* The collection of data describing a window on the Mac. */ | |
1a578e9b | 235 | struct mac_output { |
e0f712ba AC |
236 | /* Placeholder for things accessed through output_data.x. Must |
237 | appear first. */ | |
238 | struct x_output x_compatible; | |
239 | ||
240 | /* Menubar "widget" handle. */ | |
241 | int menubar_widget; | |
242 | ||
243 | Window mWP; /* pointer to QuickDraw window */ | |
1a578e9b AC |
244 | FRAME_PTR mFP; /* points back to the frame struct */ |
245 | ||
246 | #if 0 | |
247 | int mNumCols; /* number of characters per column */ | |
248 | int mNumRows; /* number of characters per row */ | |
249 | int mLineHeight; /* height of one line of text in pixels */ | |
250 | int mCharWidth; /* width of one character in pixels */ | |
e0f712ba AC |
251 | int mHomeX; /* X pixel coordinate of lower left |
252 | corner of character at (0, 0) */ | |
253 | int mHomeY; /* Y pixel coordinate of lower left | |
254 | corner of character at (0, 0) */ | |
1a578e9b | 255 | int mHighlight; /* current highlight state (0 = off). */ |
e0f712ba AC |
256 | int mTermWinSize; /* num of lines from top of window |
257 | affected by ins_del_lines; set by | |
258 | set_terminal_window. */ | |
259 | #endif /* 0 */ | |
1a578e9b AC |
260 | |
261 | #if 0 | |
262 | /* stuffs used by xfaces.c */ | |
263 | struct face **param_faces; | |
264 | int n_param_faces; | |
265 | struct face **computed_faces; | |
266 | int n_computed_faces; | |
267 | int size_computed_faces; | |
268 | #endif | |
269 | ||
1a578e9b AC |
270 | /* Position of the Mac window (x and y offsets in global coordinates). */ |
271 | int left_pos; | |
272 | int top_pos; | |
273 | ||
274 | /* Border width of the W32 window as known by the window system. */ | |
275 | int border_width; | |
276 | ||
277 | /* Size of the W32 window in pixels. */ | |
278 | int pixel_height, pixel_width; | |
279 | ||
280 | /* Height of a line, in pixels. */ | |
281 | int line_height; | |
282 | ||
283 | /* Here are the Graphics Contexts for the default font. */ | |
284 | GC normal_gc; /* Normal video */ | |
285 | GC reverse_gc; /* Reverse video */ | |
286 | GC cursor_gc; /* cursor drawing */ | |
287 | ||
288 | /* Width of the internal border. This is a line of background color | |
289 | just inside the window's border. When the frame is selected, | |
290 | a highlighting is displayed inside the internal border. */ | |
291 | int internal_border_width; | |
292 | ||
293 | /* The window used for this frame. | |
294 | May be zero while the frame object is being created | |
295 | and the window has not yet been created. */ | |
296 | Window window_desc; | |
297 | ||
298 | /* The window that is the parent of this window. | |
299 | Usually this is a window that was made by the window manager, | |
300 | but it can be the root window, and it can be explicitly specified | |
301 | (see the explicit_parent field, below). */ | |
302 | Window parent_desc; | |
303 | ||
304 | /* Default ASCII font of this frame. */ | |
305 | XFontStruct *font; | |
306 | ||
307 | /* The baseline offset of the default ASCII font. */ | |
308 | int baseline_offset; | |
309 | ||
310 | /* If a fontset is specified for this frame instead of font, this | |
311 | value contains an ID of the fontset, else -1. */ | |
312 | int fontset; | |
313 | ||
314 | /* Pixel values used for various purposes. | |
315 | border_pixel may be -1 meaning use a gray tile. */ | |
316 | unsigned long cursor_pixel; | |
317 | unsigned long border_pixel; | |
318 | unsigned long mouse_pixel; | |
319 | unsigned long cursor_foreground_pixel; | |
320 | ||
321 | /* Foreground color for scroll bars. A value of -1 means use the | |
322 | default (black for non-toolkit scroll bars). */ | |
323 | unsigned long scroll_bar_foreground_pixel; | |
324 | ||
325 | /* Background color for scroll bars. A value of -1 means use the | |
326 | default (background color of the frame for non-toolkit scroll | |
327 | bars). */ | |
328 | unsigned long scroll_bar_background_pixel; | |
329 | ||
330 | /* Descriptor for the cursor in use for this window. */ | |
e0f712ba AC |
331 | struct Cursor *text_cursor; |
332 | struct Cursor *nontext_cursor; | |
333 | struct Cursor *modeline_cursor; | |
334 | struct Cursor *cross_cursor; | |
335 | struct Cursor *hourglass_cursor; | |
1a578e9b | 336 | #if 0 |
2e875e36 AC |
337 | /* Window whose cursor is hourglass_cursor. This window is temporarily |
338 | mapped to display a hourglass-cursor. */ | |
339 | Window hourglass_window; | |
1a578e9b | 340 | |
2e875e36 AC |
341 | /* Non-zero means hourglass cursor is currently displayed. */ |
342 | unsigned hourglass_p : 1; | |
1a578e9b AC |
343 | |
344 | /* Flag to set when the window needs to be completely repainted. */ | |
345 | int needs_exposure; | |
346 | ||
347 | #endif | |
348 | ||
1a578e9b AC |
349 | #if 0 |
350 | DWORD dwStyle; | |
351 | #endif | |
352 | ||
353 | /* The size of the extra width currently allotted for vertical | |
354 | scroll bars, in pixels. */ | |
355 | int vertical_scroll_bar_extra; | |
356 | ||
357 | /* The extra width currently allotted for the areas in which | |
358 | truncation marks, continuation marks, and overlay arrows are | |
359 | displayed. */ | |
099603ae KS |
360 | int left_fringe_width, right_fringe_width; |
361 | int fringe_cols, fringes_extra; | |
1a578e9b AC |
362 | |
363 | /* This is the gravity value for the specified window position. */ | |
364 | int win_gravity; | |
365 | ||
366 | /* The geometry flags for this window. */ | |
367 | int size_hint_flags; | |
368 | ||
369 | /* This is the Emacs structure for the display this frame is on. */ | |
370 | /* struct w32_display_info *display_info; */ | |
371 | ||
372 | /* Nonzero means our parent is another application's window | |
373 | and was explicitly specified. */ | |
374 | char explicit_parent; | |
375 | ||
376 | /* Nonzero means tried already to make this frame visible. */ | |
377 | char asked_for_visible; | |
378 | ||
379 | /* Nonzero means menubar is currently active. */ | |
380 | char menubar_active; | |
381 | ||
e0f712ba AC |
382 | /* Nonzero means a menu command is being processed. */ |
383 | char menu_command_in_progress; | |
384 | ||
1a578e9b AC |
385 | /* Nonzero means menubar is about to become active, but should be |
386 | brought up to date first. */ | |
387 | volatile char pending_menu_activation; | |
388 | ||
1a578e9b AC |
389 | /* Relief GCs, colors etc. */ |
390 | struct relief | |
391 | { | |
392 | XGCValues *gc; | |
393 | unsigned long pixel; | |
394 | int allocated_p; | |
395 | } | |
396 | black_relief, white_relief; | |
397 | ||
398 | /* The background for which the above relief GCs were set up. | |
399 | They are changed only when a different background is involved. */ | |
400 | unsigned long relief_background; | |
401 | }; | |
402 | ||
403 | typedef struct mac_output mac_output; | |
404 | ||
405 | /* Return the Mac window used for displaying data in frame F. */ | |
406 | #define FRAME_MAC_WINDOW(f) ((f)->output_data.mac->mWP) | |
407 | ||
e0f712ba AC |
408 | #define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel) |
409 | #define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel) | |
1a578e9b AC |
410 | |
411 | #define FRAME_FONT(f) ((f)->output_data.mac->font) | |
412 | #define FRAME_FONTSET(f) ((f)->output_data.mac->fontset) | |
413 | ||
e0f712ba AC |
414 | #undef FRAME_INTERNAL_BORDER_WIDTH |
415 | #define FRAME_INTERNAL_BORDER_WIDTH(f) \ | |
416 | ((f)->output_data.mac->internal_border_width) | |
1a578e9b AC |
417 | #define FRAME_LINE_HEIGHT(f) ((f)->output_data.mac->line_height) |
418 | /* Width of the default font of frame F. Must be defined by each | |
419 | terminal specific header. */ | |
420 | #define FRAME_DEFAULT_FONT_WIDTH(F) FONT_WIDTH (FRAME_FONT (F)) | |
421 | #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.mac->baseline_offset) | |
422 | ||
423 | /* This gives the w32_display_info structure for the display F is on. */ | |
424 | #define FRAME_MAC_DISPLAY_INFO(f) (&one_mac_display_info) | |
425 | #define FRAME_X_DISPLAY_INFO(f) (&one_mac_display_info) | |
426 | ||
427 | /* This is the `Display *' which frame F is on. */ | |
428 | #define FRAME_MAC_DISPLAY(f) (0) | |
429 | ||
430 | /* This is the 'font_info *' which frame F has. */ | |
431 | #define FRAME_MAC_FONT_TABLE(f) (FRAME_MAC_DISPLAY_INFO (f)->font_table) | |
432 | ||
433 | /* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */ | |
434 | #define PIXEL_WIDTH(f) ((f)->output_data.mac->pixel_width) | |
435 | #define PIXEL_HEIGHT(f) ((f)->output_data.mac->pixel_height) | |
436 | ||
1a578e9b AC |
437 | /* Value is the smallest width of any character in any font on frame F. */ |
438 | ||
439 | #define FRAME_SMALLEST_CHAR_WIDTH(F) \ | |
440 | FRAME_MAC_DISPLAY_INFO(F)->smallest_char_width | |
441 | ||
442 | /* Value is the smallest height of any font on frame F. */ | |
443 | ||
444 | #define FRAME_SMALLEST_FONT_HEIGHT(F) \ | |
445 | FRAME_MAC_DISPLAY_INFO(F)->smallest_font_height | |
446 | ||
447 | /* Return a pointer to the image cache of frame F. */ | |
448 | ||
449 | #define FRAME_X_IMAGE_CACHE(F) FRAME_MAC_DISPLAY_INFO ((F))->image_cache | |
450 | ||
451 | \f | |
f76e1b5f | 452 | /* Total width of fringes reserved for drawing truncation bitmaps, |
1a578e9b AC |
453 | continuation bitmaps and alike. The width is in canonical char |
454 | units of the frame. This must currently be the case because window | |
455 | sizes aren't pixel values. If it weren't the case, we wouldn't be | |
456 | able to split windows horizontally nicely. */ | |
457 | ||
099603ae | 458 | #define FRAME_X_FRINGE_COLS(F) ((F)->output_data.mac->fringe_cols) |
1a578e9b | 459 | |
f76e1b5f | 460 | /* Total width of fringes in pixels. */ |
1a578e9b | 461 | |
099603ae | 462 | #define FRAME_X_FRINGE_WIDTH(F) ((F)->output_data.mac->fringes_extra) |
1a578e9b | 463 | |
099603ae | 464 | /* Pixel-width of the left and right fringe. */ |
1a578e9b | 465 | |
099603ae KS |
466 | #define FRAME_X_LEFT_FRINGE_WIDTH(F) ((F)->output_data.mac->left_fringe_width) |
467 | #define FRAME_X_RIGHT_FRINGE_WIDTH(F) ((F)->output_data.mac->right_fringe_width) | |
1a578e9b | 468 | |
e0f712ba | 469 | |
1a578e9b AC |
470 | \f |
471 | /* Mac-specific scroll bar stuff. */ | |
472 | ||
473 | /* We represent scroll bars as lisp vectors. This allows us to place | |
474 | references to them in windows without worrying about whether we'll | |
475 | end up with windows referring to dead scroll bars; the garbage | |
476 | collector will free it when its time comes. | |
477 | ||
478 | We use struct scroll_bar as a template for accessing fields of the | |
479 | vector. */ | |
480 | ||
481 | struct scroll_bar { | |
482 | ||
483 | /* These fields are shared by all vectors. */ | |
484 | EMACS_INT size_from_Lisp_Vector_struct; | |
485 | struct Lisp_Vector *next_from_Lisp_Vector_struct; | |
486 | ||
487 | /* The window we're a scroll bar for. */ | |
488 | Lisp_Object window; | |
489 | ||
490 | /* The next and previous in the chain of scroll bars in this frame. */ | |
491 | Lisp_Object next, prev; | |
492 | ||
493 | /* The Mac control handle of this scroll bar. Since this is a full | |
494 | 32-bit quantity, we store it split into two 32-bit values. */ | |
495 | Lisp_Object control_handle_low, control_handle_high; | |
496 | ||
497 | /* The position and size of the scroll bar in pixels, relative to the | |
498 | frame. */ | |
499 | Lisp_Object top, left, width, height; | |
500 | ||
501 | /* The starting and ending positions of the handle, relative to the | |
502 | handle area (i.e. zero is the top position, not | |
503 | SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle | |
504 | hasn't been drawn yet. | |
505 | ||
506 | These are not actually the locations where the beginning and end | |
507 | are drawn; in order to keep handles from becoming invisible when | |
508 | editing large files, we establish a minimum height by always | |
509 | drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below | |
510 | where they would be normally; the bottom and top are in a | |
511 | different co-ordinate system. */ | |
512 | Lisp_Object start, end; | |
513 | ||
514 | /* If the scroll bar handle is currently being dragged by the user, | |
515 | this is the number of pixels from the top of the handle to the | |
516 | place where the user grabbed it. If the handle isn't currently | |
517 | being dragged, this is Qnil. */ | |
518 | Lisp_Object dragging; | |
519 | }; | |
520 | ||
521 | /* The number of elements a vector holding a struct scroll_bar needs. */ | |
522 | #define SCROLL_BAR_VEC_SIZE \ | |
523 | ((sizeof (struct scroll_bar) \ | |
524 | - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \ | |
525 | / sizeof (Lisp_Object)) | |
526 | ||
527 | /* Turning a lisp vector value into a pointer to a struct scroll_bar. */ | |
528 | #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec)) | |
529 | ||
530 | ||
531 | /* Building a 32-bit C integer from two 16-bit lisp integers. */ | |
532 | #define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low)) | |
533 | ||
534 | /* Setting two lisp integers to the low and high words of a 32-bit C int. */ | |
535 | #define SCROLL_BAR_UNPACK(low, high, int32) \ | |
536 | (XSETINT ((low), (int32) & 0xffff), \ | |
537 | XSETINT ((high), ((int32) >> 16) & 0xffff)) | |
538 | ||
539 | ||
e0f712ba AC |
540 | /* Extract the Mac control handle of the scroll bar from a struct |
541 | scroll_bar. */ | |
1a578e9b | 542 | #define SCROLL_BAR_CONTROL_HANDLE(ptr) \ |
e0f712ba AC |
543 | ((ControlHandle) SCROLL_BAR_PACK ((ptr)->control_handle_low, \ |
544 | (ptr)->control_handle_high)) | |
1a578e9b AC |
545 | |
546 | /* Store a Mac control handle in a struct scroll_bar. */ | |
547 | #define SET_SCROLL_BAR_CONTROL_HANDLE(ptr, id) \ | |
e0f712ba AC |
548 | (SCROLL_BAR_UNPACK ((ptr)->control_handle_low, \ |
549 | (ptr)->control_handle_high, (int) id)) | |
1a578e9b AC |
550 | |
551 | /* Return the inside width of a vertical scroll bar, given the outside | |
552 | width. */ | |
553 | #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f,width) \ | |
554 | ((width) \ | |
555 | - VERTICAL_SCROLL_BAR_LEFT_BORDER \ | |
556 | - VERTICAL_SCROLL_BAR_RIGHT_BORDER \ | |
557 | - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2) | |
558 | ||
559 | /* Return the length of the rectangle within which the top of the | |
560 | handle must stay. This isn't equivalent to the inside height, | |
561 | because the scroll bar handle has a minimum height. | |
562 | ||
563 | This is the real range of motion for the scroll bar, so when we're | |
564 | scaling buffer positions to scroll bar positions, we use this, not | |
565 | VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */ | |
566 | #define VERTICAL_SCROLL_BAR_TOP_RANGE(f,height) \ | |
e0f712ba AC |
567 | (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) \ |
568 | - VERTICAL_SCROLL_BAR_MIN_HANDLE - UP_AND_DOWN_ARROWS) | |
1a578e9b AC |
569 | |
570 | /* Return the inside height of vertical scroll bar, given the outside | |
571 | height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */ | |
572 | #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f,height) \ | |
e0f712ba AC |
573 | ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER \ |
574 | - VERTICAL_SCROLL_BAR_BOTTOM_BORDER) | |
1a578e9b AC |
575 | |
576 | ||
577 | /* Border widths for scroll bars. | |
578 | ||
579 | Scroll bar windows don't have any borders; their border width is | |
580 | set to zero, and we redraw borders ourselves. This makes the code | |
581 | a bit cleaner, since we don't have to convert between outside width | |
582 | (used when relating to the rest of the screen) and inside width | |
583 | (used when sizing and drawing the scroll bar window itself). | |
584 | ||
585 | The handle moves up and down/back and forth in a rectangle inset | |
586 | from the edges of the scroll bar. These are widths by which we | |
587 | inset the handle boundaries from the scroll bar edges. */ | |
588 | #define VERTICAL_SCROLL_BAR_LEFT_BORDER (0) | |
589 | #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (0) | |
590 | #define VERTICAL_SCROLL_BAR_TOP_BORDER (0) | |
591 | #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (0) | |
592 | ||
593 | /* Minimum lengths for scroll bar handles, in pixels. */ | |
594 | #define VERTICAL_SCROLL_BAR_MIN_HANDLE (16) | |
595 | ||
596 | /* Combined length of up and down arrow boxes in scroll bars, in pixels. */ | |
597 | #define UP_AND_DOWN_ARROWS (32) | |
598 | ||
599 | /* Trimming off a few pixels from each side prevents | |
600 | text from glomming up against the scroll bar */ | |
601 | #define VERTICAL_SCROLL_BAR_WIDTH_TRIM (0) | |
602 | ||
603 | \f | |
604 | /* Manipulating pixel sizes and character sizes. | |
605 | Knowledge of which factors affect the overall size of the window should | |
606 | be hidden in these macros, if that's possible. | |
607 | ||
608 | Return the upper/left pixel position of the character cell on frame F | |
609 | at ROW/COL. */ | |
610 | #define CHAR_TO_PIXEL_ROW(f, row) \ | |
611 | ((f)->output_data.mac->internal_border_width \ | |
612 | + (row) * (f)->output_data.mac->line_height) | |
613 | #define CHAR_TO_PIXEL_COL(f, col) \ | |
614 | ((f)->output_data.mac->internal_border_width \ | |
615 | + (col) * FONT_WIDTH ((f)->output_data.mac->font)) | |
616 | ||
617 | /* Return the pixel width/height of frame F if it has | |
618 | WIDTH columns/HEIGHT rows. */ | |
619 | #define CHAR_TO_PIXEL_WIDTH(f, width) \ | |
620 | (CHAR_TO_PIXEL_COL (f, width) \ | |
621 | + (f)->output_data.mac->vertical_scroll_bar_extra \ | |
f76e1b5f | 622 | + (f)->output_data.mac->fringes_extra \ |
1a578e9b AC |
623 | + (f)->output_data.mac->internal_border_width) |
624 | #define CHAR_TO_PIXEL_HEIGHT(f, height) \ | |
625 | (CHAR_TO_PIXEL_ROW (f, height) \ | |
626 | + (f)->output_data.mac->internal_border_width) | |
627 | ||
628 | ||
629 | /* Return the row/column (zero-based) of the character cell containing | |
630 | the pixel on FRAME at ROW/COL. */ | |
631 | #define PIXEL_TO_CHAR_ROW(f, row) \ | |
632 | (((row) - (f)->output_data.mac->internal_border_width) \ | |
633 | / (f)->output_data.mac->line_height) | |
634 | #define PIXEL_TO_CHAR_COL(f, col) \ | |
635 | (((col) - (f)->output_data.mac->internal_border_width) \ | |
636 | / FONT_WIDTH ((f)->output_data.mac->font)) | |
637 | ||
638 | /* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on | |
639 | frame F? */ | |
640 | #define PIXEL_TO_CHAR_WIDTH(f, width) \ | |
641 | (PIXEL_TO_CHAR_COL (f, ((width) \ | |
642 | - (f)->output_data.mac->internal_border_width \ | |
f76e1b5f | 643 | - (f)->output_data.mac->fringes_extra \ |
1a578e9b AC |
644 | - (f)->output_data.mac->vertical_scroll_bar_extra))) |
645 | #define PIXEL_TO_CHAR_HEIGHT(f, height) \ | |
646 | (PIXEL_TO_CHAR_ROW (f, ((height) \ | |
647 | - (f)->output_data.mac->internal_border_width))) | |
648 | ||
649 | struct frame * check_x_frame (Lisp_Object); | |
650 |