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