(line-number-display-limit): Doc fix.
[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 126
e964ed22
RS
127/* Structure recording X pixmap and reference count.
128 If REFCOUNT is 0 then this record is free to be reused. */
129
130struct x_bitmap_record
131{
132 Pixmap pixmap;
133 char *file;
134 int refcount;
135 /* Record some info about this pixmap. */
136 int height, width, depth;
137};
b242af88
RS
138\f
139/* For each X display, we have a structure that records
140 information about it. */
3f930d20 141
579dd4be 142struct x_display_info
b242af88 143{
e964ed22 144 /* Chain of all x_display_info structures. */
579dd4be
RS
145 struct x_display_info *next;
146 /* Connection number (normally a file descriptor number). */
147 int connection;
b242af88 148 /* This says how to access this display in Xlib. */
579dd4be 149 Display *display;
e964ed22
RS
150 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
151 The same cons cell also appears in x_display_name_list. */
152 Lisp_Object name_list_element;
b242af88
RS
153 /* Number of frames that are on this display. */
154 int reference_count;
579dd4be
RS
155 /* The Screen this connection is connected to. */
156 Screen *screen;
157 /* The Visual being used for this display. */
158 Visual *visual;
159 /* Number of panes on this screen. */
160 int n_planes;
161 /* Dimensions of this screen. */
162 int height, width;
163 /* Mask of things that cause the mouse to be grabbed. */
164 int grabbed;
165 /* Emacs bitmap-id of the default icon bitmap for this frame.
166 Or -1 if none has been allocated yet. */
167 int icon_bitmap_id;
168 /* The root window of this screen. */
169 Window root_window;
e964ed22
RS
170 /* The cursor to use for vertical scroll bars. */
171 Cursor vertical_scroll_bar_cursor;
579dd4be
RS
172 /* X Resource data base */
173 XrmDatabase xrdb;
174
e964ed22
RS
175 /* A table of all the fonts we have already loaded. */
176 struct font_info *font_table;
177
178 /* The current capacity of x_font_table. */
179 int font_table_size;
180
181 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
182 GC scratch_cursor_gc;
183
184 /* These variables describe the range of text currently shown
185 in its mouse-face, together with the window they apply to.
186 As long as the mouse stays within this range, we need not
187 redraw anything on its account. */
188 int mouse_face_beg_row, mouse_face_beg_col;
189 int mouse_face_end_row, mouse_face_end_col;
190 int mouse_face_past_end;
191 Lisp_Object mouse_face_window;
192 int mouse_face_face_id;
193
194 /* 1 if a mouse motion event came and we didn't handle it right away because
195 gc was in progress. */
196 int mouse_face_deferred_gc;
197
198 /* FRAME and X, Y position of mouse when last checked for
199 highlighting. X and Y can be negative or out of range for the frame. */
200 struct frame *mouse_face_mouse_frame;
201 int mouse_face_mouse_x, mouse_face_mouse_y;
202
203 /* Nonzero means defer mouse-motion highlighting. */
204 int mouse_face_defer;
205
206 char *x_id_name;
207
208 /* The number of fonts actually stored in x_font_table.
209 font_table[n] is used and valid iff 0 <= n < n_fonts.
210 0 <= n_fonts <= font_table_size. */
211 int n_fonts;
212
213 /* Pointer to bitmap records. */
214 struct x_bitmap_record *bitmaps;
215
216 /* Allocated size of bitmaps field. */
217 int bitmaps_size;
218
219 /* Last used bitmap index. */
220 int bitmaps_last;
221
579dd4be
RS
222 /* Which modifier keys are on which modifier bits?
223
224 With each keystroke, X returns eight bits indicating which modifier
225 keys were held down when the key was pressed. The interpretation
226 of the top five modifier bits depends on what keys are attached
227 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
228 is the meta bit.
229
230 meta_mod_mask is a mask containing the bits used for the meta key.
231 It may have more than one bit set, if more than one modifier bit
232 has meta keys on it. Basically, if EVENT is a KeyPress event,
233 the meta key is pressed if (EVENT.state & meta_mod_mask) != 0.
234
235 shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
236 lock modifier bit, or zero otherwise. Non-alphabetic keys should
237 only be affected by the lock modifier bit if XK_Shift_Lock is in
238 use; XK_Caps_Lock should only affect alphabetic keys. With this
239 arrangement, the lock modifier should shift the character if
240 (EVENT.state & shift_lock_mask) != 0. */
241 int meta_mod_mask, shift_lock_mask;
242
243 /* These are like meta_mod_mask, but for different modifiers. */
244 int alt_mod_mask, super_mod_mask, hyper_mod_mask;
245
246 /* Communication with window managers. */
247 Atom Xatom_wm_protocols;
248 /* Kinds of protocol things we may receive. */
249 Atom Xatom_wm_take_focus;
250 Atom Xatom_wm_save_yourself;
251 Atom Xatom_wm_delete_window;
252 /* Atom for indicating window state to the window manager. */
253 Atom Xatom_wm_change_state;
254 /* Other WM communication */
255 Atom Xatom_wm_configure_denied; /* When our config request is denied */
256 Atom Xatom_wm_window_moved; /* When the WM moves us. */
257 /* EditRes protocol */
258 Atom Xatom_editres;
259
260 /* More atoms, which are selection types. */
261 Atom Xatom_CLIPBOARD, Xatom_TIMESTAMP, Xatom_TEXT, Xatom_DELETE,
adb572fb 262 Xatom_COMPOUND_TEXT,
579dd4be
RS
263 Xatom_MULTIPLE, Xatom_INCR, Xatom_EMACS_TMP, Xatom_TARGETS, Xatom_NULL,
264 Xatom_ATOM_PAIR;
adb572fb 265
7b341ec2 266 /* More atoms for font properties. The last three are private
adb572fb
KH
267 properties, see the comments in src/fontset.h. */
268 Atom Xatom_PIXEL_SIZE,
7b341ec2
KH
269 Xatom_MULE_BASELINE_OFFSET, Xatom_MULE_RELATIVE_COMPOSE,
270 Xatom_MULE_DEFAULT_ASCENT;
adb572fb 271
6909e850 272#ifdef MULTI_KBOARD
e47a168b 273 struct kboard *kboard;
6909e850 274#endif
256d5bf6 275 int cut_buffers_initialized; /* Whether we're sure they all exist */
2820e308
KH
276
277 /* The frame (if any) which has the X window that has keyboard focus.
278 Zero if none. This is examined by Ffocus_frame in xfns.c. Note
279 that a mere EnterNotify event can set this; if you need to know the
280 last frame specified in a FocusIn or FocusOut event, use
281 x_focus_event_frame. */
282 struct frame *x_focus_frame;
283
284 /* The last frame mentioned in a FocusIn or FocusOut event. This is
285 separate from x_focus_frame, because whether or not LeaveNotify
286 events cause us to lose focus depends on whether or not we have
287 received a FocusIn event for it. */
288 struct frame *x_focus_event_frame;
289
290 /* The frame which currently has the visual highlight, and should get
291 keyboard input (other sorts of input have the frame encoded in the
292 event). It points to the X focus frame's selected window's
293 frame. It differs from x_focus_frame when we're using a global
294 minibuffer. */
295 struct frame *x_highlight_frame;
adb572fb
KH
296
297 /* The null pixel used for filling a character background with
298 background color of a gc. */
299 Pixmap null_pixel;
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
adb572fb
KH
311/* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
312extern Lisp_Object Vx_pixel_size_width_font_regexp;
313
ee8ddc1c 314/* A flag to control how to display unibyte 8-bit character. */
e3c55541 315extern int unibyte_display_via_language_environment;
ee8ddc1c 316
579dd4be
RS
317extern struct x_display_info *x_display_info_for_display ();
318extern struct x_display_info *x_display_info_for_name ();
319
320extern struct x_display_info *x_term_init ();
adb572fb
KH
321
322extern Lisp_Object x_list_fonts ();
323extern struct font_info *x_get_font_info(), *x_load_font (), *x_query_font ();
d7fcdd91 324extern void x_find_ccl_program();
b242af88 325\f
f39d1692
RS
326/* Each X frame object points to its own struct x_output object
327 in the output_data.x field. The x_output structure contains
3f930d20
JB
328 the information that is specific to X windows. */
329
f39d1692 330struct x_output
3f930d20
JB
331{
332 /* Position of the X window (x and y offsets in root window). */
333 int left_pos;
334 int top_pos;
335
336 /* Border width of the X window as known by the X window system. */
337 int border_width;
338
f3942238 339 /* Size of the X window in pixels. */
3f930d20
JB
340 int pixel_height, pixel_width;
341
ab6c5d93
KH
342 /* Height of menu bar widget, in pixels.
343 Zero if not using the X toolkit.
344 When using the toolkit, this value is not meaningful
345 if the menubar is turned off. */
346 int menubar_height;
347
2ba6876c
RS
348 /* Height of a line, in pixels. */
349 int line_height;
350
f3942238 351 /* The tiled border used when the mouse is out of the frame. */
3f930d20
JB
352 Pixmap border_tile;
353
f3942238 354 /* Here are the Graphics Contexts for the default font. */
3f930d20
JB
355 GC normal_gc; /* Normal video */
356 GC reverse_gc; /* Reverse video */
357 GC cursor_gc; /* cursor drawing */
3f930d20
JB
358
359 /* Width of the internal border. This is a line of background color
f676886a 360 just inside the window's border. When the frame is selected,
3f930d20
JB
361 a highlighting is displayed inside the internal border. */
362 int internal_border_width;
363
f676886a
JB
364 /* The X window used for this frame.
365 May be zero while the frame object is being created
3f930d20
JB
366 and the X window has not yet been created. */
367 Window window_desc;
368
369 /* The X window used for the bitmap icon;
370 or 0 if we don't have a bitmap icon. */
371 Window icon_desc;
372
373 /* The X window that is the parent of this X window.
dcc98b56
RS
374 Usually this is a window that was made by the window manager,
375 but it can be the root window, and it can be explicitly specified
376 (see the explicit_parent field, below). */
3f930d20
JB
377 Window parent_desc;
378
0be31d57
RS
379#ifdef USE_X_TOOLKIT
380 /* The widget of this screen. This is the window of a "shell" widget. */
381 Widget widget;
382 /* The XmPanedWindows... */
383 Widget column_widget;
384 /* The widget of the edit portion of this screen; the window in
385 "window_desc" is inside of this. */
386 Widget edit_widget;
387
388 Widget menubar_widget;
389#endif
390
78c3981d
RS
391 /* If >=0, a bitmap index. The indicated bitmap is used for the
392 icon. */
393 int icon_bitmap;
3f930d20 394
adb572fb 395 /* Default ASCII font of this frame. */
579dd4be 396 XFontStruct *font;
3f930d20 397
adb572fb
KH
398 /* The baseline position of the default ASCII font. */
399 int font_baseline;
400
401 /* If a fontset is specified for this frame instead of font, this
402 value contains an ID of the fontset, else -1. */
403 int fontset;
404
3f930d20
JB
405 /* Pixel values used for various purposes.
406 border_pixel may be -1 meaning use a gray tile. */
579dd4be
RS
407 unsigned long background_pixel;
408 unsigned long foreground_pixel;
409 unsigned long cursor_pixel;
410 unsigned long border_pixel;
411 unsigned long mouse_pixel;
412 unsigned long cursor_foreground_pixel;
3f930d20 413
3f930d20 414 /* Descriptor for the cursor in use for this window. */
3f930d20
JB
415 Cursor text_cursor;
416 Cursor nontext_cursor;
417 Cursor modeline_cursor;
6bfbdaeb 418 Cursor cross_cursor;
3f930d20 419
f3942238 420 /* Flag to set when the X window needs to be completely repainted. */
3f930d20
JB
421 int needs_exposure;
422
dbc4e1c1
JB
423 /* What kind of text cursor is drawn in this window right now?
424 (If there is no cursor (phys_cursor_x < 0), then this means nothing.) */
425 enum text_cursor_kinds current_cursor;
426
427 /* What kind of text cursor should we draw in the future?
428 This should always be filled_box_cursor or bar_cursor. */
429 enum text_cursor_kinds desired_cursor;
ef15f270 430
e36a2711
RS
431 /* Width of bar cursor (if we are using that). */
432 int cursor_width;
433
ef15f270
JB
434 /* These are the current window manager hints. It seems that
435 XSetWMHints, when presented with an unset bit in the `flags'
436 member of the hints structure, does not leave the corresponding
437 attribute unchanged; rather, it resets that attribute to its
438 default value. For example, unless you set the `icon_pixmap'
439 field and the `IconPixmapHint' bit, XSetWMHints will forget what
440 your icon pixmap was. This is rather troublesome, since some of
441 the members (for example, `input' and `icon_pixmap') want to stay
442 the same throughout the execution of Emacs. So, we keep this
443 structure around, just leaving values in it and adding new bits
444 to the mask as we go. */
445 XWMHints wm_hints;
c8e3cbe0 446
c8e3cbe0 447 /* The size of the extra width currently allotted for vertical
a3c87d4e
JB
448 scroll bars, in pixels. */
449 int vertical_scroll_bar_extra;
13bd51a5 450
28f72798
JB
451 /* Table of parameter faces for this frame. Any X resources (pixel
452 values, fonts) referred to here have been allocated explicitly
453 for this face, and should be freed if we change the face. */
454 struct face **param_faces;
455 int n_param_faces;
456
457 /* Table of computed faces for this frame. These are the faces
458 whose indexes go into the upper bits of a glyph, computed by
459 combining the parameter faces specified by overlays, text
460 properties, and what have you. The X resources mentioned here
461 are all shared with parameter faces. */
462 struct face **computed_faces;
463 int n_computed_faces; /* How many are valid */
464 int size_computed_faces; /* How many are allocated */
379564d6
RS
465
466 /* This is the gravity value for the specified window position. */
467 int win_gravity;
f3942238
RS
468
469 /* The geometry flags for this window. */
470 int size_hint_flags;
b242af88
RS
471
472 /* This is the Emacs structure for the X display this frame is on. */
579dd4be 473 struct x_display_info *display_info;
dcc98b56 474
51057b1f 475 /* This is a button event that wants to activate the menubar.
ff0113e7
KH
476 We save it here until the command loop gets to think about it. */
477 XEvent *saved_menu_event;
51057b1f
RS
478
479 /* This is the widget id used for this frame's menubar in lwlib. */
480#ifdef USE_X_TOOLKIT
481 int id;
482#endif
483
dcc98b56
RS
484 /* Nonzero means our parent is another application's window
485 and was explicitly specified. */
486 char explicit_parent;
cbef58c0
KH
487
488 /* Nonzero means tried already to make this frame visible. */
489 char asked_for_visible;
7b8d4a3f 490
4fe2b2b6
RS
491 /* Nonzero if this frame was ever previously visible. */
492 char has_been_visible;
493
7b8d4a3f 494#ifdef HAVE_X_I18N
f08fe433
RS
495 /* Input method. */
496 XIM xim;
7b8d4a3f
RS
497 /* Input context (currently, this means Compose key handler setup). */
498 XIC xic;
499#endif
3f930d20 500};
d2729198 501
28f72798 502/* Get at the computed faces of an X window frame. */
f39d1692
RS
503#define FRAME_PARAM_FACES(f) ((f)->output_data.x->param_faces)
504#define FRAME_N_PARAM_FACES(f) ((f)->output_data.x->n_param_faces)
28f72798
JB
505#define FRAME_DEFAULT_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[0])
506#define FRAME_MODE_LINE_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[1])
507
f39d1692
RS
508#define FRAME_COMPUTED_FACES(f) ((f)->output_data.x->computed_faces)
509#define FRAME_N_COMPUTED_FACES(f) ((f)->output_data.x->n_computed_faces)
510#define FRAME_SIZE_COMPUTED_FACES(f) ((f)->output_data.x->size_computed_faces)
511#define FRAME_DEFAULT_FACE(f) ((f)->output_data.x->computed_faces[0])
512#define FRAME_MODE_LINE_FACE(f) ((f)->output_data.x->computed_faces[1])
13bd51a5 513
dca3296e 514/* Return the X window used for displaying data in frame F. */
f39d1692 515#define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
d2729198 516
dca3296e
RS
517/* Return the outermost X window associated with the frame F. */
518#ifdef USE_X_TOOLKIT
519#define FRAME_OUTER_WINDOW(f) (XtWindow ((f)->output_data.x->widget))
520#else
521#define FRAME_OUTER_WINDOW(f) (FRAME_X_WINDOW (f))
522#endif
523
f39d1692
RS
524#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.x->foreground_pixel)
525#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.x->background_pixel)
526#define FRAME_FONT(f) ((f)->output_data.x->font)
adb572fb 527#define FRAME_FONTSET(f) ((f)->output_data.x->fontset)
5c9ee165
GV
528#define FRAME_INTERNAL_BORDER_WIDTH(f) ((f)->output_data.x->internal_border_width)
529#define FRAME_LINE_HEIGHT(f) ((f)->output_data.x->line_height)
8e533ff0 530
579dd4be 531/* This gives the x_display_info structure for the display F is on. */
f39d1692 532#define FRAME_X_DISPLAY_INFO(f) ((f)->output_data.x->display_info)
b242af88
RS
533
534/* This is the `Display *' which frame F is on. */
579dd4be
RS
535#define FRAME_X_DISPLAY(f) (FRAME_X_DISPLAY_INFO (f)->display)
536
537/* This is the `Screen *' which frame F is on. */
538#define FRAME_X_SCREEN(f) (FRAME_X_DISPLAY_INFO (f)->screen)
b242af88 539
adb572fb
KH
540/* This is the 'font_info *' which frame F has. */
541#define FRAME_X_FONT_TABLE(f) (FRAME_X_DISPLAY_INFO (f)->font_table)
542
dbc4e1c1 543/* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */
f39d1692
RS
544#define PIXEL_WIDTH(f) ((f)->output_data.x->pixel_width)
545#define PIXEL_HEIGHT(f) ((f)->output_data.x->pixel_height)
dbc4e1c1 546
f39d1692 547#define FRAME_DESIRED_CURSOR(f) ((f)->output_data.x->desired_cursor)
dbc4e1c1 548
f08fe433 549#define FRAME_XIM(f) ((f)->output_data.x->xim)
7afa6068 550#define FRAME_XIC(f) ((f)->output_data.x->xic)
3f930d20 551\f
a3c87d4e 552/* X-specific scroll bar stuff. */
c8e3cbe0 553
a3c87d4e 554/* We represent scroll bars as lisp vectors. This allows us to place
4e027793 555 references to them in windows without worrying about whether we'll
a3c87d4e 556 end up with windows referring to dead scroll bars; the garbage
4e027793
JB
557 collector will free it when its time comes.
558
a3c87d4e 559 We use struct scroll_bar as a template for accessing fields of the
4e027793
JB
560 vector. */
561
a3c87d4e 562struct scroll_bar {
c8e3cbe0 563
4e027793 564 /* These fields are shared by all vectors. */
820b2ca2 565 EMACS_INT size_from_Lisp_Vector_struct;
4e027793
JB
566 struct Lisp_Vector *next_from_Lisp_Vector_struct;
567
a3c87d4e 568 /* The window we're a scroll bar for. */
4e027793 569 Lisp_Object window;
c8e3cbe0 570
a3c87d4e 571 /* The next and previous in the chain of scroll bars in this frame. */
4e027793 572 Lisp_Object next, prev;
c8e3cbe0 573
a3c87d4e 574 /* The X window representing this scroll bar. Since this is a full
4e027793
JB
575 32-bit quantity, we store it split into two 32-bit values. */
576 Lisp_Object x_window_low, x_window_high;
c8e3cbe0 577
a3c87d4e 578 /* The position and size of the scroll bar in pixels, relative to the
c8e3cbe0 579 frame. */
4e027793 580 Lisp_Object top, left, width, height;
c8e3cbe0 581
4e027793
JB
582 /* The starting and ending positions of the handle, relative to the
583 handle area (i.e. zero is the top position, not
a3c87d4e 584 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
4e027793 585 hasn't been drawn yet.
c8e3cbe0 586
4e027793
JB
587 These are not actually the locations where the beginning and end
588 are drawn; in order to keep handles from becoming invisible when
589 editing large files, we establish a minimum height by always
a3c87d4e 590 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
4e027793
JB
591 where they would be normally; the bottom and top are in a
592 different co-ordinate system. */
593 Lisp_Object start, end;
c8e3cbe0 594
a3c87d4e 595 /* If the scroll bar handle is currently being dragged by the user,
c8e3cbe0
JB
596 this is the number of pixels from the top of the handle to the
597 place where the user grabbed it. If the handle isn't currently
4e027793
JB
598 being dragged, this is Qnil. */
599 Lisp_Object dragging;
c8e3cbe0
JB
600};
601
a3c87d4e 602/* The number of elements a vector holding a struct scroll_bar needs. */
35e5240a
KH
603#define SCROLL_BAR_VEC_SIZE \
604 ((sizeof (struct scroll_bar) \
605 - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
4e027793
JB
606 / sizeof (Lisp_Object))
607
a3c87d4e 608/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
35e5240a 609#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
4e027793
JB
610
611
612/* Building a 32-bit C integer from two 16-bit lisp integers. */
a3c87d4e 613#define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
4e027793
JB
614
615/* Setting two lisp integers to the low and high words of a 32-bit C int. */
a3c87d4e 616#define SCROLL_BAR_UNPACK(low, high, int32) \
df0f379b
KH
617 (XSETINT ((low), (int32) & 0xffff), \
618 XSETINT ((high), ((int32) >> 16) & 0xffff))
4e027793
JB
619
620
a3c87d4e
JB
621/* Extract the X window id of the scroll bar from a struct scroll_bar. */
622#define SCROLL_BAR_X_WINDOW(ptr) \
623 ((Window) SCROLL_BAR_PACK ((ptr)->x_window_low, (ptr)->x_window_high))
4e027793 624
a3c87d4e
JB
625/* Store a window id in a struct scroll_bar. */
626#define SET_SCROLL_BAR_X_WINDOW(ptr, id) \
627 (SCROLL_BAR_UNPACK ((ptr)->x_window_low, (ptr)->x_window_high, (int) id))
4e027793
JB
628
629
a3c87d4e 630/* Return the outside pixel height for a vertical scroll bar HEIGHT
c8e3cbe0 631 rows high on frame F. */
a3c87d4e 632#define VERTICAL_SCROLL_BAR_PIXEL_HEIGHT(f, height) \
f39d1692 633 ((height) * (f)->output_data.x->line_height)
c8e3cbe0 634
a3c87d4e 635/* Return the inside width of a vertical scroll bar, given the outside
4e027793 636 width. */
aa5abbc0
RS
637#define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f, width) \
638 ((width) \
639 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
640 - VERTICAL_SCROLL_BAR_RIGHT_BORDER \
36fe2f9a 641 - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2)
c8e3cbe0 642
4e027793
JB
643/* Return the length of the rectangle within which the top of the
644 handle must stay. This isn't equivalent to the inside height,
a3c87d4e 645 because the scroll bar handle has a minimum height.
4e027793 646
a3c87d4e
JB
647 This is the real range of motion for the scroll bar, so when we're
648 scaling buffer positions to scroll bar positions, we use this, not
649 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
aa5abbc0
RS
650#define VERTICAL_SCROLL_BAR_TOP_RANGE(f, height) \
651 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
4e027793 652
a3c87d4e
JB
653/* Return the inside height of vertical scroll bar, given the outside
654 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
aa5abbc0 655#define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f, height) \
a3c87d4e 656 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
4e027793
JB
657
658
a3c87d4e 659/* Border widths for scroll bars.
4e027793 660
a3c87d4e 661 Scroll bar windows don't have any X borders; their border width is
4e027793
JB
662 set to zero, and we redraw borders ourselves. This makes the code
663 a bit cleaner, since we don't have to convert between outside width
664 (used when relating to the rest of the screen) and inside width
a3c87d4e 665 (used when sizing and drawing the scroll bar window itself).
4e027793 666
eb8c3be9 667 The handle moves up and down/back and forth in a rectangle inset
a3c87d4e
JB
668 from the edges of the scroll bar. These are widths by which we
669 inset the handle boundaries from the scroll bar edges. */
670#define VERTICAL_SCROLL_BAR_LEFT_BORDER (2)
d68eb3a2 671#define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2)
a3c87d4e
JB
672#define VERTICAL_SCROLL_BAR_TOP_BORDER (2)
673#define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2)
4e027793 674
a3c87d4e
JB
675/* Minimum lengths for scroll bar handles, in pixels. */
676#define VERTICAL_SCROLL_BAR_MIN_HANDLE (5)
c8e3cbe0 677
36fe2f9a 678/* Trimming off a few pixels from each side prevents
aa5abbc0 679 text from glomming up against the scroll bar */
36fe2f9a 680#define VERTICAL_SCROLL_BAR_WIDTH_TRIM (2)
aa5abbc0 681
c8e3cbe0
JB
682\f
683/* Manipulating pixel sizes and character sizes.
684 Knowledge of which factors affect the overall size of the window should
685 be hidden in these macros, if that's possible.
686
0cabaf31 687 Return the upper/left pixel position of the character cell on frame F
4e027793
JB
688 at ROW/COL. */
689#define CHAR_TO_PIXEL_ROW(f, row) \
f39d1692
RS
690 ((f)->output_data.x->internal_border_width \
691 + (row) * (f)->output_data.x->line_height)
4e027793 692#define CHAR_TO_PIXEL_COL(f, col) \
f39d1692
RS
693 ((f)->output_data.x->internal_border_width \
694 + (col) * FONT_WIDTH ((f)->output_data.x->font))
4e027793
JB
695
696/* Return the pixel width/height of frame F if it has
697 WIDTH columns/HEIGHT rows. */
c8e3cbe0 698#define CHAR_TO_PIXEL_WIDTH(f, width) \
4e027793 699 (CHAR_TO_PIXEL_COL (f, width) \
f39d1692
RS
700 + (f)->output_data.x->vertical_scroll_bar_extra \
701 + (f)->output_data.x->internal_border_width)
c8e3cbe0 702#define CHAR_TO_PIXEL_HEIGHT(f, height) \
4e027793 703 (CHAR_TO_PIXEL_ROW (f, height) \
f39d1692 704 + (f)->output_data.x->internal_border_width)
c8e3cbe0 705
c8e3cbe0 706
4e027793
JB
707/* Return the row/column (zero-based) of the character cell containing
708 the pixel on FRAME at ROW/COL. */
cecfe612 709#define PIXEL_TO_CHAR_ROW(f, row) \
f39d1692
RS
710 (((row) - (f)->output_data.x->internal_border_width) \
711 / (f)->output_data.x->line_height)
cecfe612 712#define PIXEL_TO_CHAR_COL(f, col) \
f39d1692
RS
713 (((col) - (f)->output_data.x->internal_border_width) \
714 / FONT_WIDTH ((f)->output_data.x->font))
c8e3cbe0 715
4e027793
JB
716/* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on
717 frame F? */
718#define PIXEL_TO_CHAR_WIDTH(f, width) \
719 (PIXEL_TO_CHAR_COL (f, ((width) \
f39d1692
RS
720 - (f)->output_data.x->internal_border_width \
721 - (f)->output_data.x->vertical_scroll_bar_extra)))
4e027793
JB
722#define PIXEL_TO_CHAR_HEIGHT(f, height) \
723 (PIXEL_TO_CHAR_ROW (f, ((height) \
f39d1692 724 - (f)->output_data.x->internal_border_width)))
c352056c
RS
725\f
726/* If a struct input_event has a kind which is selection_request_event
727 or selection_clear_event, then its contents are really described
728 by this structure. */
729
730/* For an event of kind selection_request_event,
d601ce45
RS
731 this structure really describes the contents.
732 **Don't make this struct longer!**
733 If it overlaps the frame_or_window field of struct input_event,
734 that will cause GC to crash. */
c352056c
RS
735struct selection_input_event
736{
737 int kind;
738 Display *display;
beaff27b
RS
739 /* We spell it with an "o" here because X does. */
740 Window requestor;
c352056c
RS
741 Atom selection, target, property;
742 Time time;
743};
744
745#define SELECTION_EVENT_DISPLAY(eventp) \
746 (((struct selection_input_event *) (eventp))->display)
beaff27b
RS
747/* We spell it with an "o" here because X does. */
748#define SELECTION_EVENT_REQUESTOR(eventp) \
749 (((struct selection_input_event *) (eventp))->requestor)
c352056c
RS
750#define SELECTION_EVENT_SELECTION(eventp) \
751 (((struct selection_input_event *) (eventp))->selection)
752#define SELECTION_EVENT_TARGET(eventp) \
753 (((struct selection_input_event *) (eventp))->target)
754#define SELECTION_EVENT_PROPERTY(eventp) \
755 (((struct selection_input_event *) (eventp))->property)
756#define SELECTION_EVENT_TIME(eventp) \
757 (((struct selection_input_event *) (eventp))->time)
bf489d26
JB
758
759\f
760/* Interface to the face code functions. */
761
ec5d8db7
AS
762/* Forward declarations for prototypes. */
763struct frame;
764struct window;
765struct input_event;
766
28f72798
JB
767/* Create the first two computed faces for a frame -- the ones that
768 have GC's. */
ec5d8db7 769extern void init_frame_faces P_ ((struct frame *));
bf489d26
JB
770
771/* Free the resources for the faces associated with a frame. */
ec5d8db7 772extern void free_frame_faces P_ ((struct frame *));
bf489d26 773
28f72798 774/* Given a computed face, find or make an equivalent display face
bf489d26 775 in face_vector, and return a pointer to it. */
ec5d8db7 776extern struct face *intern_face P_ ((struct frame *, struct face *));
bf489d26
JB
777
778/* Given a frame and a face name, return the face's ID number, or
779 zero if it isn't a recognized face name. */
ec5d8db7 780extern int face_name_id_number P_ ((struct frame *, Lisp_Object));
bf489d26
JB
781
782/* Return non-zero if FONT1 and FONT2 have the same size bounding box.
783 We assume that they're both character-cell fonts. */
ec5d8db7 784extern int same_size_fonts P_ ((XFontStruct *, XFontStruct *));
bf489d26
JB
785
786/* Recompute the GC's for the default and modeline faces.
787 We call this after changing frame parameters on which those GC's
788 depend. */
ec5d8db7 789extern void recompute_basic_faces P_ ((struct frame *));
bf489d26 790
28f72798
JB
791/* Return the face ID associated with a buffer position POS. Store
792 into *ENDPTR the next position at which a different face is
793 needed. This does not take account of glyphs that specify their
794 own face codes. F is the frame in use for display, and W is a
795 window displaying the current buffer.
bf489d26
JB
796
797 REGION_BEG, REGION_END delimit the region, so it can be highlighted. */
ec5d8db7
AS
798extern int compute_char_face P_ ((struct frame *frame,
799 struct window *w,
800 int pos,
801 int region_beg, int region_end,
802 int *endptr,
803 int limit, int mouse));
bf489d26
JB
804/* Return the face ID to use to display a special glyph which selects
805 FACE_CODE as the face ID, assuming that ordinarily the face would
806 be BASIC_FACE. F is the frame. */
ec5d8db7
AS
807extern int compute_glyph_face P_ ((struct frame *, int, int));
808
809/* Given a pixel position (PIX_X, PIX_Y) on the frame F, return
810 glyph co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle
811 that the glyph at X, Y occupies, if BOUNDS != 0.
812 If NOCLIP is nonzero, do not force the value into range. */
813
814extern void pixel_to_glyph_coords P_ ((struct frame *f, int pix_x, int pix_y,
815 int *x, int *y, XRectangle *bounds,
816 int noclip));
817
818extern void glyph_to_pixel_coords P_ ((struct frame *f, int x, int y,
819 int *pix_x, int *pix_y));
820
821/* Defined in xterm.c */
822
823extern void cancel_mouse_face P_ ((struct frame *));
824extern void x_scroll_bar_clear P_ ((struct frame *));
825extern void x_start_queuing_selection_requests P_ ((Display *));
826extern void x_stop_queuing_selection_requests P_ ((Display *));
827extern void x_display_cursor P_ ((struct frame *, int, int, int));
828extern void x_update_cursor P_ ((struct frame *, int));
829extern int x_text_icon P_ ((struct frame *, char *));
830extern int x_bitmap_icon P_ ((struct frame *, Lisp_Object));
831extern int x_catch_errors P_ ((Display *));
832extern void x_check_errors P_ ((Display *, char *));
833extern int x_had_errors_p P_ ((Display *));
834extern void x_uncatch_errors P_ ((Display *, int));
835extern Lisp_Object x_new_font P_ ((struct frame *, char *));
836extern Lisp_Object x_new_fontset P_ ((struct frame *, char *));
837extern void x_set_offset P_ ((struct frame *, int, int, int));
838extern void x_set_window_size P_ ((struct frame *, int, int, int));
839extern void x_set_mouse_position P_ ((struct frame *, int, int));
840extern void x_set_mouse_pixel_position P_ ((struct frame *, int, int));
841extern void x_raise_frame P_ ((struct frame *));
842extern void x_lower_frame P_ ((struct frame *));
843extern void x_make_frame_visible P_ ((struct frame *));
844extern void x_make_frame_invisible P_ ((struct frame *));
845extern void x_iconify_frame P_ ((struct frame *));
846extern void x_destroy_window P_ ((struct frame *));
847extern void x_wm_set_size_hint P_ ((struct frame *, long, int));
848extern void x_wm_set_window_state P_ ((struct frame *, int));
849extern void x_wm_set_icon_pixmap P_ ((struct frame *, int));
850extern void x_wm_set_icon_position P_ ((struct frame *, int, int));
851extern void x_delete_display P_ ((struct x_display_info *));
852extern void x_initialize P_ ((void));
853
854/* Defined in xselect.c */
855
856extern void x_handle_property_notify P_ ((XPropertyEvent *));
857extern void x_handle_selection_notify P_ ((XSelectionEvent *));
858extern void x_handle_selection_request P_ ((struct input_event *));
859extern void x_handle_selection_clear P_ ((struct input_event *));
860extern void x_clear_frame_selections P_ ((struct frame *));
861
862/* Defined in xfns.c */
863
864extern int have_menus_p P_ ((void));
865extern int x_bitmap_height P_ ((struct frame *, int));
866extern int x_bitmap_width P_ ((struct frame *, int));
867extern int x_bitmap_pixmap P_ ((struct frame *, int));
868extern void x_reference_bitmap P_ ((struct frame *, int));
869extern int x_create_bitmap_from_data P_ ((struct frame *, char *,
870 unsigned int, unsigned int));
871extern int x_create_bitmap_from_file P_ ((struct frame *, Lisp_Object));
872extern void x_destroy_bitmap P_ ((struct frame *, int));
873extern void x_set_frame_parameters P_ ((struct frame *, Lisp_Object));
874extern void x_real_positions P_ ((struct frame *, int *, int *));
875extern void x_report_frame_params P_ ((struct frame *, Lisp_Object *));
876extern int defined_color P_ ((struct frame *, char *, XColor *, int));
877extern void x_set_border_pixel P_ ((struct frame *, int));
878extern void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
879extern void x_implicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
880extern int x_pixel_width P_ ((struct frame *));
881extern int x_pixel_height P_ ((struct frame *));
882extern int x_char_width P_ ((struct frame *));
883extern int x_char_height P_ ((struct frame *));
884extern int x_screen_planes P_ ((struct frame *));
885extern void x_sync P_ ((struct frame *));
886
887/* Defined in xfaces.c */
888extern int frame_update_line_height P_ ((struct frame *));
889extern void clear_face_cache P_ ((void));
890extern int compute_glyph_face P_ ((struct frame *, int, int));
891extern int compute_glyph_face_1 P_ ((struct frame *, Lisp_Object, int));
892
893/* Defined in xmenu.c */
894extern void x_activate_menubar P_ ((struct frame *));
895extern int popup_activated P_ ((void));
896extern void initialize_frame_menubar P_ ((struct frame *));
897
898/* Defined in widget.c */
09ba2aa0 899#ifdef USE_X_TOOLKIT
ec5d8db7 900extern void widget_store_internal_border P_ ((Widget));
09ba2aa0 901#endif