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