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