(make_frame_glyphs, update_line, update_frame)
[bpt/emacs.git] / src / xterm.h
CommitLineData
3f930d20 1/* Definitions and headers for communication with X protocol.
3a22ee35 2 Copyright (C) 1989, 1993, 1994 Free Software Foundation, Inc.
3f930d20
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
4e027793 8the Free Software Foundation; either version 2, or (at your option)
3f930d20
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
3f930d20 20
3f930d20
JB
21#include <X11/Xlib.h>
22#include <X11/cursorfont.h>
23#include <X11/Xutil.h>
24#include <X11/keysym.h>
25#include <X11/Xatom.h>
26#include <X11/Xresource.h>
3f930d20 27
0be31d57
RS
28#ifdef USE_X_TOOLKIT
29#include <X11/StringDefs.h>
30#include <X11/IntrinsicP.h> /* CoreP.h needs this */
31#include <X11/CoreP.h> /* foul, but we need this to use our own
32 window inside a widget instead of one
33 that Xt creates... */
34#include <X11/StringDefs.h>
0be31d57
RS
35#endif
36
579dd4be
RS
37/* The class of this X application. */
38#define EMACS_CLASS "Emacs"
39\f
40/* Bookkeeping to distinguish X versions. */
ef15f270 41
d2729198
JB
42/* HAVE_X11R4 is defined if we have the features of X11R4. It should
43 be defined when we're using X11R5, since X11R5 has the features of
44 X11R4. If, in the future, we find we need more of these flags
45 (HAVE_X11R5, for example), code should always be written to test
46 the most recent flag first:
47
48 #ifdef HAVE_X11R5
49 ...
50 #elif HAVE_X11R4
51 ...
52 #elif HAVE_X11
53 ...
54 #endif
55
56 If you ever find yourself writing a "#ifdef HAVE_FOO" clause that
57 looks a lot like another one, consider moving the text into a macro
58 whose definition is configuration-dependent, but whose usage is
59 universal - like the stuff in systime.h.
60
61 It turns out that we can auto-detect whether we're being compiled
ef15f270
JB
62 with X11R3 or X11R4 by looking for the flag macros for R4 structure
63 members that R3 doesn't have. */
64#ifdef PBaseSize
3fe53836
RS
65/* AIX 3.1's X is somewhere between X11R3 and X11R4. It has
66 PBaseSize, but not XWithdrawWindow, XSetWMName, XSetWMNormalHints,
48508a3a
FP
67 XSetWMIconName.
68 AIX 3.2 is at least X11R4. */
69#if (!defined AIX) || (defined AIX3_2)
ef15f270
JB
70#define HAVE_X11R4
71#endif
3fe53836 72#endif
ef15f270 73
b1b57843 74#ifdef HAVE_X11R5
673fea7a
RS
75/* In case someone has X11R5 on AIX 3.1,
76 make sure HAVE_X11R4 is defined as well as HAVE_X11R5. */
77#define HAVE_X11R4
6bde6341 78#endif
cfc57cea
RS
79
80#ifdef HAVE_X11R5
81#define HAVE_X_I18N
82#include <X11/Xlocale.h>
83#endif
579dd4be
RS
84\f
85#define BLACK_PIX_DEFAULT(f) BlackPixel (FRAME_X_DISPLAY (f), \
86 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))
87#define WHITE_PIX_DEFAULT(f) WhitePixel (FRAME_X_DISPLAY (f), \
88 XScreenNumberOfScreen (FRAME_X_SCREEN (f)))
3f930d20
JB
89
90#define FONT_WIDTH(f) ((f)->max_bounds.width)
91#define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
92#define FONT_BASE(f) ((f)->ascent)
93
3f930d20 94/* The mask of events that text windows always want to receive. This
d2f764d0
RS
95 includes mouse movement events, since handling the mouse-font text property
96 means that we must track mouse motion all the time. */
3f930d20
JB
97
98#define STANDARD_EVENT_SET \
99 (KeyPressMask \
100 | ExposureMask \
101 | ButtonPressMask \
8828b393
JB
102 | ButtonReleaseMask \
103 | PointerMotionMask \
3f930d20
JB
104 | StructureNotifyMask \
105 | FocusChangeMask \
106 | LeaveWindowMask \
107 | EnterWindowMask \
108 | VisibilityChangeMask)
109
3868b9ec
KH
110/* This checks to make sure we have a display. */
111extern void check_x ();
112
f676886a 113extern struct frame *x_window_to_frame ();
3f930d20 114
0be31d57
RS
115#ifdef USE_X_TOOLKIT
116extern struct frame *x_any_window_to_frame ();
72de3c00 117extern struct frame *x_non_menubar_window_to_frame ();
090cebb5 118extern struct frame *x_top_window_to_frame ();
0be31d57
RS
119#endif
120
579dd4be 121extern Visual *select_visual ();
b242af88 122
3f930d20
JB
123enum text_cursor_kinds {
124 filled_box_cursor, hollow_box_cursor, bar_cursor
125};
e964ed22
RS
126
127/* This data type is used for the font_table field
128 of struct x_display_info. */
129
130struct font_info
131{
132 XFontStruct *font;
133 char *name;
134 char *full_name;
135};
136
137/* Structure recording X pixmap and reference count.
138 If REFCOUNT is 0 then this record is free to be reused. */
139
140struct x_bitmap_record
141{
142 Pixmap pixmap;
143 char *file;
144 int refcount;
145 /* Record some info about this pixmap. */
146 int height, width, depth;
147};
b242af88
RS
148\f
149/* For each X display, we have a structure that records
150 information about it. */
3f930d20 151
579dd4be 152struct x_display_info
b242af88 153{
e964ed22 154 /* Chain of all x_display_info structures. */
579dd4be
RS
155 struct x_display_info *next;
156 /* Connection number (normally a file descriptor number). */
157 int connection;
b242af88 158 /* This says how to access this display in Xlib. */
579dd4be 159 Display *display;
e964ed22
RS
160 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
161 The same cons cell also appears in x_display_name_list. */
162 Lisp_Object name_list_element;
b242af88
RS
163 /* Number of frames that are on this display. */
164 int reference_count;
579dd4be
RS
165 /* The Screen this connection is connected to. */
166 Screen *screen;
167 /* The Visual being used for this display. */
168 Visual *visual;
169 /* Number of panes on this screen. */
170 int n_planes;
171 /* Dimensions of this screen. */
172 int height, width;
173 /* Mask of things that cause the mouse to be grabbed. */
174 int grabbed;
175 /* Emacs bitmap-id of the default icon bitmap for this frame.
176 Or -1 if none has been allocated yet. */
177 int icon_bitmap_id;
178 /* The root window of this screen. */
179 Window root_window;
e964ed22
RS
180 /* The cursor to use for vertical scroll bars. */
181 Cursor vertical_scroll_bar_cursor;
579dd4be
RS
182 /* X Resource data base */
183 XrmDatabase xrdb;
184
e964ed22
RS
185 /* A table of all the fonts we have already loaded. */
186 struct font_info *font_table;
187
188 /* The current capacity of x_font_table. */
189 int font_table_size;
190
191 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
192 GC scratch_cursor_gc;
193
194 /* These variables describe the range of text currently shown
195 in its mouse-face, together with the window they apply to.
196 As long as the mouse stays within this range, we need not
197 redraw anything on its account. */
198 int mouse_face_beg_row, mouse_face_beg_col;
199 int mouse_face_end_row, mouse_face_end_col;
200 int mouse_face_past_end;
201 Lisp_Object mouse_face_window;
202 int mouse_face_face_id;
203
204 /* 1 if a mouse motion event came and we didn't handle it right away because
205 gc was in progress. */
206 int mouse_face_deferred_gc;
207
208 /* FRAME and X, Y position of mouse when last checked for
209 highlighting. X and Y can be negative or out of range for the frame. */
210 struct frame *mouse_face_mouse_frame;
211 int mouse_face_mouse_x, mouse_face_mouse_y;
212
213 /* Nonzero means defer mouse-motion highlighting. */
214 int mouse_face_defer;
215
216 char *x_id_name;
217
218 /* The number of fonts actually stored in x_font_table.
219 font_table[n] is used and valid iff 0 <= n < n_fonts.
220 0 <= n_fonts <= font_table_size. */
221 int n_fonts;
222
223 /* Pointer to bitmap records. */
224 struct x_bitmap_record *bitmaps;
225
226 /* Allocated size of bitmaps field. */
227 int bitmaps_size;
228
229 /* Last used bitmap index. */
230 int bitmaps_last;
231
579dd4be
RS
232 /* Which modifier keys are on which modifier bits?
233
234 With each keystroke, X returns eight bits indicating which modifier
235 keys were held down when the key was pressed. The interpretation
236 of the top five modifier bits depends on what keys are attached
237 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
238 is the meta bit.
239
240 meta_mod_mask is a mask containing the bits used for the meta key.
241 It may have more than one bit set, if more than one modifier bit
242 has meta keys on it. Basically, if EVENT is a KeyPress event,
243 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
244
245 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
246 lock modifier bit, or zero otherwise. Non-alphabetic keys should
247 only be affected by the lock modifier bit if XK_Shift_Lock is in
248 use; XK_Caps_Lock should only affect alphabetic keys. With this
249 arrangement, the lock modifier should shift the character if
250 (EVENT.state & shift_lock_mask) != 0. */
251 int meta_mod_mask, shift_lock_mask;
252
253 /* These are like meta_mod_mask, but for different modifiers. */
254 int alt_mod_mask, super_mod_mask, hyper_mod_mask;
255
256 /* Communication with window managers. */
257 Atom Xatom_wm_protocols;
258 /* Kinds of protocol things we may receive. */
259 Atom Xatom_wm_take_focus;
260 Atom Xatom_wm_save_yourself;
261 Atom Xatom_wm_delete_window;
262 /* Atom for indicating window state to the window manager. */
263 Atom Xatom_wm_change_state;
264 /* Other WM communication */
265 Atom Xatom_wm_configure_denied; /* When our config request is denied */
266 Atom Xatom_wm_window_moved; /* When the WM moves us. */
267 /* EditRes protocol */
268 Atom Xatom_editres;
c190bcd5
RS
269 /* Atom `FONT' */
270 Atom Xatom_FONT;
579dd4be
RS
271
272 /* More atoms, which are selection types. */
273 Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE,
274 Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL,
275 Xatom_ATOM_PAIR;
6909e850 276#ifdef MULTI_KBOARD
e47a168b 277 struct kboard *kboard;
6909e850 278#endif
256d5bf6 279 int cut_buffers_initialized; /* Whether we're sure they all exist */
2820e308
KH
280
281 /* The frame (if any) which has the X window that has keyboard focus.
282 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
283 that a mere EnterNotify event can set this; if you need to know the
284 last frame specified in a FocusIn or FocusOut event, use
285 x_focus_event_frame. */
286 struct frame *x_focus_frame;
287
288 /* The last frame mentioned in a FocusIn or FocusOut event. This is
289 separate from x_focus_frame, because whether or not LeaveNotify
290 events cause us to lose focus depends on whether or not we have
291 received a FocusIn event for it. */
292 struct frame *x_focus_event_frame;
293
294 /* The frame which currently has the visual highlight, and should get
295 keyboard input (other sorts of input have the frame encoded in the
296 event). It points to the X focus frame's selected window's
297 frame. It differs from x_focus_frame when we're using a global
298 minibuffer. */
299 struct frame *x_highlight_frame;
b242af88 300};
579dd4be
RS
301
302/* This is a chain of structures for all the X displays currently in use. */
303extern struct x_display_info *x_display_list;
304
e964ed22
RS
305/* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
306 one for each element of x_display_list and in the same order.
307 NAME is the name of the frame.
308 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
309extern Lisp_Object x_display_name_list;
310
579dd4be
RS
311extern struct x_display_info *x_display_info_for_display ();
312extern struct x_display_info *x_display_info_for_name ();
313
314extern struct x_display_info *x_term_init ();
b242af88 315\f
f39d1692
RS
316/* Each X frame object points to its own struct x_output object
317 in the output_data.x field. The x_output structure contains
3f930d20
JB
318 the information that is specific to X windows. */
319
f39d1692 320struct x_output
3f930d20
JB
321{
322 /* Position of the X window (x and y offsets in root window). */
323 int left_pos;
324 int top_pos;
325
326 /* Border width of the X window as known by the X window system. */
327 int border_width;
328
f3942238 329 /* Size of the X window in pixels. */
3f930d20
JB
330 int pixel_height, pixel_width;
331
ab6c5d93
KH
332 /* Height of menu bar widget, in pixels.
333 Zero if not using the X toolkit.
334 When using the toolkit, this value is not meaningful
335 if the menubar is turned off. */
336 int menubar_height;
337
2ba6876c
RS
338 /* Height of a line, in pixels. */
339 int line_height;
340
f3942238 341 /* The tiled border used when the mouse is out of the frame. */
3f930d20
JB
342 Pixmap border_tile;
343
f3942238 344 /* Here are the Graphics Contexts for the default font. */
3f930d20
JB
345 GC normal_gc; /* Normal video */
346 GC reverse_gc; /* Reverse video */
347 GC cursor_gc; /* cursor drawing */
3f930d20
JB
348
349 /* Width of the internal border. This is a line of background color
f676886a 350 just inside the window's border. When the frame is selected,
3f930d20
JB
351 a highlighting is displayed inside the internal border. */
352 int internal_border_width;
353
f676886a
JB
354 /* The X window used for this frame.
355 May be zero while the frame object is being created
3f930d20
JB
356 and the X window has not yet been created. */
357 Window window_desc;
358
359 /* The X window used for the bitmap icon;
360 or 0 if we don't have a bitmap icon. */
361 Window icon_desc;
362
363 /* The X window that is the parent of this X window.
dcc98b56
RS
364 Usually this is a window that was made by the window manager,
365 but it can be the root window, and it can be explicitly specified
366 (see the explicit_parent field, below). */
3f930d20
JB
367 Window parent_desc;
368
0be31d57
RS
369#ifdef USE_X_TOOLKIT
370 /* The widget of this screen. This is the window of a "shell" widget. */
371 Widget widget;
372 /* The XmPanedWindows... */
373 Widget column_widget;
374 /* The widget of the edit portion of this screen; the window in
375 "window_desc" is inside of this. */
376 Widget edit_widget;
377
378 Widget menubar_widget;
379#endif
380
78c3981d
RS
381 /* If >=0, a bitmap index. The indicated bitmap is used for the
382 icon. */
383 int icon_bitmap;
3f930d20 384
579dd4be 385 XFontStruct *font;
3f930d20
JB
386
387 /* Pixel values used for various purposes.
388 border_pixel may be -1 meaning use a gray tile. */
579dd4be
RS
389 unsigned long background_pixel;
390 unsigned long foreground_pixel;
391 unsigned long cursor_pixel;
392 unsigned long border_pixel;
393 unsigned long mouse_pixel;
394 unsigned long cursor_foreground_pixel;
3f930d20 395
3f930d20 396 /* Descriptor for the cursor in use for this window. */
3f930d20
JB
397 Cursor text_cursor;
398 Cursor nontext_cursor;
399 Cursor modeline_cursor;
6bfbdaeb 400 Cursor cross_cursor;
3f930d20 401
f3942238 402 /* Flag to set when the X window needs to be completely repainted. */
3f930d20
JB
403 int needs_exposure;
404
dbc4e1c1
JB
405 /* What kind of text cursor is drawn in this window right now?
406 (If there is no cursor (phys_cursor_x < 0), then this means nothing.) */
407 enum text_cursor_kinds current_cursor;
408
409 /* What kind of text cursor should we draw in the future?
410 This should always be filled_box_cursor or bar_cursor. */
411 enum text_cursor_kinds desired_cursor;
ef15f270 412
e36a2711
RS
413 /* Width of bar cursor (if we are using that). */
414 int cursor_width;
415
ef15f270
JB
416 /* These are the current window manager hints. It seems that
417 XSetWMHints, when presented with an unset bit in the `flags'
418 member of the hints structure, does not leave the corresponding
419 attribute unchanged; rather, it resets that attribute to its
420 default value. For example, unless you set the `icon_pixmap'
421 field and the `IconPixmapHint' bit, XSetWMHints will forget what
422 your icon pixmap was. This is rather troublesome, since some of
423 the members (for example, `input' and `icon_pixmap') want to stay
424 the same throughout the execution of Emacs. So, we keep this
425 structure around, just leaving values in it and adding new bits
426 to the mask as we go. */
427 XWMHints wm_hints;
c8e3cbe0 428
c8e3cbe0 429 /* The size of the extra width currently allotted for vertical
a3c87d4e
JB
430 scroll bars, in pixels. */
431 int vertical_scroll_bar_extra;
13bd51a5 432
28f72798
JB
433 /* Table of parameter faces for this frame. Any X resources (pixel
434 values, fonts) referred to here have been allocated explicitly
435 for this face, and should be freed if we change the face. */
436 struct face **param_faces;
437 int n_param_faces;
438
439 /* Table of computed faces for this frame. These are the faces
440 whose indexes go into the upper bits of a glyph, computed by
441 combining the parameter faces specified by overlays, text
442 properties, and what have you. The X resources mentioned here
443 are all shared with parameter faces. */
444 struct face **computed_faces;
445 int n_computed_faces; /* How many are valid */
446 int size_computed_faces; /* How many are allocated */
379564d6
RS
447
448 /* This is the gravity value for the specified window position. */
449 int win_gravity;
f3942238
RS
450
451 /* The geometry flags for this window. */
452 int size_hint_flags;
b242af88
RS
453
454 /* This is the Emacs structure for the X display this frame is on. */
579dd4be 455 struct x_display_info *display_info;
dcc98b56 456
51057b1f 457 /* This is a button event that wants to activate the menubar.
ff0113e7
KH
458 We save it here until the command loop gets to think about it. */
459 XEvent *saved_menu_event;
51057b1f
RS
460
461 /* This is the widget id used for this frame's menubar in lwlib. */
462#ifdef USE_X_TOOLKIT
463 int id;
464#endif
465
dcc98b56
RS
466 /* Nonzero means our parent is another application's window
467 and was explicitly specified. */
468 char explicit_parent;
cbef58c0
KH
469
470 /* Nonzero means tried already to make this frame visible. */
471 char asked_for_visible;
7b8d4a3f
RS
472
473#ifdef HAVE_X_I18N
f08fe433
RS
474 /* Input method. */
475 XIM xim;
7b8d4a3f
RS
476 /* Input context (currently, this means Compose key handler setup). */
477 XIC xic;
478#endif
3f930d20 479};
d2729198 480
28f72798 481/* Get at the computed faces of an X window frame. */
f39d1692
RS
482#define FRAME_PARAM_FACES(f) ((f)->output_data.x->param_faces)
483#define FRAME_N_PARAM_FACES(f) ((f)->output_data.x->n_param_faces)
28f72798
JB
484#define FRAME_DEFAULT_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[0])
485#define FRAME_MODE_LINE_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[1])
486
f39d1692
RS
487#define FRAME_COMPUTED_FACES(f) ((f)->output_data.x->computed_faces)
488#define FRAME_N_COMPUTED_FACES(f) ((f)->output_data.x->n_computed_faces)
489#define FRAME_SIZE_COMPUTED_FACES(f) ((f)->output_data.x->size_computed_faces)
490#define FRAME_DEFAULT_FACE(f) ((f)->output_data.x->computed_faces[0])
491#define FRAME_MODE_LINE_FACE(f) ((f)->output_data.x->computed_faces[1])
13bd51a5 492
d2729198 493/* Return the window associated with the frame F. */
f39d1692 494#define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
d2729198 495
f39d1692
RS
496#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel)
497#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
498#define FRAME_FONT(f) ((f)->output_data.x->font)
5c9ee165
GV
499#define FRAME_INTERNAL_BORDER_WIDTH(f) ((f)->output_data.x->internal_border_width)
500#define FRAME_LINE_HEIGHT(f) ((f)->output_data.x->line_height)
8e533ff0 501
579dd4be 502/* This gives the x_display_info structure for the display F is on. */
f39d1692 503#define FRAME_X_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
b242af88
RS
504
505/* This is the `Display *' which frame F is on. */
579dd4be
RS
506#define FRAME_X_DISPLAY(f) (FRAME_X_DISPLAY_INFO (f)->display)
507
508/* This is the `Screen *' which frame F is on. */
509#define FRAME_X_SCREEN(f) (FRAME_X_DISPLAY_INFO (f)->screen)
b242af88 510
dbc4e1c1 511/* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */
f39d1692
RS
512#define PIXEL_WIDTH(f) ((f)->output_data.x->pixel_width)
513#define PIXEL_HEIGHT(f) ((f)->output_data.x->pixel_height)
dbc4e1c1 514
f39d1692 515#define FRAME_DESIRED_CURSOR(f) ((f)->output_data.x->desired_cursor)
dbc4e1c1 516
f08fe433 517#define FRAME_XIM(f) ((f)->output_data.x->xim)
7afa6068 518#define FRAME_XIC(f) ((f)->output_data.x->xic)
3f930d20 519\f
a3c87d4e 520/* X-specific scroll bar stuff. */
c8e3cbe0 521
a3c87d4e 522/* We represent scroll bars as lisp vectors. This allows us to place
4e027793 523 references to them in windows without worrying about whether we'll
a3c87d4e 524 end up with windows referring to dead scroll bars; the garbage
4e027793
JB
525 collector will free it when its time comes.
526
a3c87d4e 527 We use struct scroll_bar as a template for accessing fields of the
4e027793
JB
528 vector. */
529
a3c87d4e 530struct scroll_bar {
c8e3cbe0 531
4e027793 532 /* These fields are shared by all vectors. */
820b2ca2 533 EMACS_INT size_from_Lisp_Vector_struct;
4e027793
JB
534 struct Lisp_Vector *next_from_Lisp_Vector_struct;
535
a3c87d4e 536 /* The window we're a scroll bar for. */
4e027793 537 Lisp_Object window;
c8e3cbe0 538
a3c87d4e 539 /* The next and previous in the chain of scroll bars in this frame. */
4e027793 540 Lisp_Object next, prev;
c8e3cbe0 541
a3c87d4e 542 /* The X window representing this scroll bar. Since this is a full
4e027793
JB
543 32-bit quantity, we store it split into two 32-bit values. */
544 Lisp_Object x_window_low, x_window_high;
c8e3cbe0 545
a3c87d4e 546 /* The position and size of the scroll bar in pixels, relative to the
c8e3cbe0 547 frame. */
4e027793 548 Lisp_Object top, left, width, height;
c8e3cbe0 549
4e027793
JB
550 /* The starting and ending positions of the handle, relative to the
551 handle area (i.e. zero is the top position, not
a3c87d4e 552 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
4e027793 553 hasn't been drawn yet.
c8e3cbe0 554
4e027793
JB
555 These are not actually the locations where the beginning and end
556 are drawn; in order to keep handles from becoming invisible when
557 editing large files, we establish a minimum height by always
a3c87d4e 558 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
4e027793
JB
559 where they would be normally; the bottom and top are in a
560 different co-ordinate system. */
561 Lisp_Object start, end;
c8e3cbe0 562
a3c87d4e 563 /* If the scroll bar handle is currently being dragged by the user,
c8e3cbe0
JB
564 this is the number of pixels from the top of the handle to the
565 place where the user grabbed it. If the handle isn't currently
4e027793
JB
566 being dragged, this is Qnil. */
567 Lisp_Object dragging;
c8e3cbe0
JB
568};
569
a3c87d4e 570/* The number of elements a vector holding a struct scroll_bar needs. */
35e5240a
KH
571#define SCROLL_BAR_VEC_SIZE \
572 ((sizeof (struct scroll_bar) \
573 - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
4e027793
JB
574 / sizeof (Lisp_Object))
575
a3c87d4e 576/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
35e5240a 577#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
4e027793
JB
578
579
580/* Building a 32-bit C integer from two 16-bit lisp integers. */
a3c87d4e 581#define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
4e027793
JB
582
583/* Setting two lisp integers to the low and high words of a 32-bit C int. */
a3c87d4e 584#define SCROLL_BAR_UNPACK(low, high, int32) \
df0f379b
KH
585 (XSETINT ((low), (int32) & 0xffff), \
586 XSETINT ((high), ((int32) >> 16) & 0xffff))
4e027793
JB
587
588
a3c87d4e
JB
589/* Extract the X window id of the scroll bar from a struct scroll_bar. */
590#define SCROLL_BAR_X_WINDOW(ptr) \
591 ((Window) SCROLL_BAR_PACK ((ptr)->x_window_low, (ptr)->x_window_high))
4e027793 592
a3c87d4e
JB
593/* Store a window id in a struct scroll_bar. */
594#define SET_SCROLL_BAR_X_WINDOW(ptr, id) \
595 (SCROLL_BAR_UNPACK ((ptr)->x_window_low, (ptr)->x_window_high, (int) id))
4e027793
JB
596
597
a3c87d4e 598/* Return the outside pixel height for a vertical scroll bar HEIGHT
c8e3cbe0 599 rows high on frame F. */
a3c87d4e 600#define VERTICAL_SCROLL_BAR_PIXEL_HEIGHT(f, height) \
f39d1692 601 ((height) * (f)->output_data.x->line_height)
c8e3cbe0 602
a3c87d4e 603/* Return the inside width of a vertical scroll bar, given the outside
4e027793 604 width. */
aa5abbc0
RS
605#define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
606 ((width) \
607 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
608 - VERTICAL_SCROLL_BAR_RIGHT_BORDER \
609 - (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f) \
610 ? LEFT_VERTICAL_SCROLL_BAR_WIDTH_TRIM \
611 : 0))
c8e3cbe0 612
4e027793
JB
613/* Return the length of the rectangle within which the top of the
614 handle must stay. This isn't equivalent to the inside height,
a3c87d4e 615 because the scroll bar handle has a minimum height.
4e027793 616
a3c87d4e
JB
617 This is the real range of motion for the scroll bar, so when we're
618 scaling buffer positions to scroll bar positions, we use this, not
619 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
aa5abbc0
RS
620#define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
621 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
4e027793 622
a3c87d4e
JB
623/* Return the inside height of vertical scroll bar, given the outside
624 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
aa5abbc0 625#define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
a3c87d4e 626 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
4e027793
JB
627
628
a3c87d4e 629/* Border widths for scroll bars.
4e027793 630
a3c87d4e 631 Scroll bar windows don't have any X borders; their border width is
4e027793
JB
632 set to zero, and we redraw borders ourselves. This makes the code
633 a bit cleaner, since we don't have to convert between outside width
634 (used when relating to the rest of the screen) and inside width
a3c87d4e 635 (used when sizing and drawing the scroll bar window itself).
4e027793 636
eb8c3be9 637 The handle moves up and down/back and forth in a rectangle inset
a3c87d4e
JB
638 from the edges of the scroll bar. These are widths by which we
639 inset the handle boundaries from the scroll bar edges. */
640#define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
d68eb3a2 641#define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
a3c87d4e
JB
642#define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
643#define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
4e027793 644
a3c87d4e
JB
645/* Minimum lengths for scroll bar handles, in pixels. */
646#define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
c8e3cbe0 647
aa5abbc0
RS
648/* For a left-side scroll bar, trimming off a few pixels prevents
649 text from glomming up against the scroll bar */
650#define LEFT_VERTICAL_SCROLL_BAR_WIDTH_TRIM (2)
651
c8e3cbe0
JB
652\f
653/* Manipulating pixel sizes and character sizes.
654 Knowledge of which factors affect the overall size of the window should
655 be hidden in these macros, if that's possible.
656
0cabaf31 657 Return the upper/left pixel position of the character cell on frame F
4e027793
JB
658 at ROW/COL. */
659#define CHAR_TO_PIXEL_ROW(f, row) \
f39d1692
RS
660 ((f)->output_data.x->internal_border_width \
661 + (row) * (f)->output_data.x->line_height)
4e027793 662#define CHAR_TO_PIXEL_COL(f, col) \
f39d1692
RS
663 ((f)->output_data.x->internal_border_width \
664 + (col) * FONT_WIDTH ((f)->output_data.x->font))
4e027793
JB
665
666/* Return the pixel width/height of frame F if it has
667 WIDTH columns/HEIGHT rows. */
c8e3cbe0 668#define CHAR_TO_PIXEL_WIDTH(f, width) \
4e027793 669 (CHAR_TO_PIXEL_COL (f, width) \
f39d1692
RS
670 + (f)->output_data.x->vertical_scroll_bar_extra \
671 + (f)->output_data.x->internal_border_width)
c8e3cbe0 672#define CHAR_TO_PIXEL_HEIGHT(f, height) \
4e027793 673 (CHAR_TO_PIXEL_ROW (f, height) \
f39d1692 674 + (f)->output_data.x->internal_border_width)
c8e3cbe0 675
c8e3cbe0 676
4e027793
JB
677/* Return the row/column (zero-based) of the character cell containing
678 the pixel on FRAME at ROW/COL. */
cecfe612 679#define PIXEL_TO_CHAR_ROW(f, row) \
f39d1692
RS
680 (((row) - (f)->output_data.x->internal_border_width) \
681 / (f)->output_data.x->line_height)
cecfe612 682#define PIXEL_TO_CHAR_COL(f, col) \
f39d1692
RS
683 (((col) - (f)->output_data.x->internal_border_width) \
684 / FONT_WIDTH ((f)->output_data.x->font))
c8e3cbe0 685
4e027793
JB
686/* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on
687 frame F? */
688#define PIXEL_TO_CHAR_WIDTH(f, width) \
689 (PIXEL_TO_CHAR_COL (f, ((width) \
f39d1692
RS
690 - (f)->output_data.x->internal_border_width \
691 - (f)->output_data.x->vertical_scroll_bar_extra)))
4e027793
JB
692#define PIXEL_TO_CHAR_HEIGHT(f, height) \
693 (PIXEL_TO_CHAR_ROW (f, ((height) \
f39d1692 694 - (f)->output_data.x->internal_border_width)))
c352056c
RS
695\f
696/* If a struct input_event has a kind which is selection_request_event
697 or selection_clear_event, then its contents are really described
698 by this structure. */
699
700/* For an event of kind selection_request_event,
d601ce45
RS
701 this structure really describes the contents.
702 **Don't make this struct longer!**
703 If it overlaps the frame_or_window field of struct input_event,
704 that will cause GC to crash. */
c352056c
RS
705struct selection_input_event
706{
707 int kind;
708 Display *display;
beaff27b
RS
709 /* We spell it with an "o" here because X does. */
710 Window requestor;
c352056c
RS
711 Atom selection, target, property;
712 Time time;
713};
714
715#define SELECTION_EVENT_DISPLAY(eventp) \
716 (((struct selection_input_event *) (eventp))->display)
beaff27b
RS
717/* We spell it with an "o" here because X does. */
718#define SELECTION_EVENT_REQUESTOR(eventp) \
719 (((struct selection_input_event *) (eventp))->requestor)
c352056c
RS
720#define SELECTION_EVENT_SELECTION(eventp) \
721 (((struct selection_input_event *) (eventp))->selection)
722#define SELECTION_EVENT_TARGET(eventp) \
723 (((struct selection_input_event *) (eventp))->target)
724#define SELECTION_EVENT_PROPERTY(eventp) \
725 (((struct selection_input_event *) (eventp))->property)
726#define SELECTION_EVENT_TIME(eventp) \
727 (((struct selection_input_event *) (eventp))->time)
bf489d26
JB
728
729\f
730/* Interface to the face code functions. */
731
28f72798
JB
732/* Create the first two computed faces for a frame -- the ones that
733 have GC's. */
bf489d26
JB
734extern void init_frame_faces (/* FRAME_PTR */);
735
736/* Free the resources for the faces associated with a frame. */
737extern void free_frame_faces (/* FRAME_PTR */);
738
28f72798 739/* Given a computed face, find or make an equivalent display face
bf489d26
JB
740 in face_vector, and return a pointer to it. */
741extern struct face *intern_face (/* FRAME_PTR, struct face * */);
742
743/* Given a frame and a face name, return the face's ID number, or
744 zero if it isn't a recognized face name. */
745extern int face_name_id_number (/* FRAME_PTR, Lisp_Object */);
746
747/* Return non-zero if FONT1 and FONT2 have the same size bounding box.
748 We assume that they're both character-cell fonts. */
749extern int same_size_fonts (/* XFontStruct *, XFontStruct * */);
750
751/* Recompute the GC's for the default and modeline faces.
752 We call this after changing frame parameters on which those GC's
753 depend. */
754extern void recompute_basic_faces (/* FRAME_PTR */);
755
28f72798
JB
756/* Return the face ID associated with a buffer position POS. Store
757 into *ENDPTR the next position at which a different face is
758 needed. This does not take account of glyphs that specify their
759 own face codes. F is the frame in use for display, and W is a
760 window displaying the current buffer.
bf489d26
JB
761
762 REGION_BEG, REGION_END delimit the region, so it can be highlighted. */
763extern int compute_char_face (/* FRAME_PTR frame,
764 struct window *w,
765 int pos,
766 int region_beg, int region_end,
767 int *endptr */);
768/* Return the face ID to use to display a special glyph which selects
769 FACE_CODE as the face ID, assuming that ordinarily the face would
770 be BASIC_FACE. F is the frame. */
771extern int compute_glyph_face (/* FRAME_PTR, int */);