| 1 | /* Definitions and headers for communication with X protocol. |
| 2 | Copyright (C) 1989, 1993, 1994 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GNU Emacs. |
| 5 | |
| 6 | GNU Emacs is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2, or (at your option) |
| 9 | any later version. |
| 10 | |
| 11 | GNU Emacs is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Emacs; see the file COPYING. If not, write to |
| 18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 19 | |
| 20 | #ifdef HAVE_X11 |
| 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> |
| 27 | #else |
| 28 | #include <X/Xlib.h> |
| 29 | #endif /* HAVE_X11 */ |
| 30 | |
| 31 | #ifdef USE_X_TOOLKIT |
| 32 | #include <X11/StringDefs.h> |
| 33 | #include <X11/IntrinsicP.h> /* CoreP.h needs this */ |
| 34 | #include <X11/CoreP.h> /* foul, but we need this to use our own |
| 35 | window inside a widget instead of one |
| 36 | that Xt creates... */ |
| 37 | #include <X11/StringDefs.h> |
| 38 | #endif |
| 39 | |
| 40 | /* Define a queue for X-events. One such queue is used for mouse clicks. |
| 41 | Another is used for expose events. */ |
| 42 | |
| 43 | #define EVENT_BUFFER_SIZE 64 |
| 44 | |
| 45 | /* Max and Min sizes in character columns. */ |
| 46 | #define MINWIDTH 10 |
| 47 | #define MINHEIGHT 10 |
| 48 | #define MAXWIDTH 300 |
| 49 | #define MAXHEIGHT 80 |
| 50 | |
| 51 | #ifdef HAVE_X11 |
| 52 | |
| 53 | /* HAVE_X11R4 is defined if we have the features of X11R4. It should |
| 54 | be defined when we're using X11R5, since X11R5 has the features of |
| 55 | X11R4. If, in the future, we find we need more of these flags |
| 56 | (HAVE_X11R5, for example), code should always be written to test |
| 57 | the most recent flag first: |
| 58 | |
| 59 | #ifdef HAVE_X11R5 |
| 60 | ... |
| 61 | #elif HAVE_X11R4 |
| 62 | ... |
| 63 | #elif HAVE_X11 |
| 64 | ... |
| 65 | #endif |
| 66 | |
| 67 | If you ever find yourself writing a "#ifdef HAVE_FOO" clause that |
| 68 | looks a lot like another one, consider moving the text into a macro |
| 69 | whose definition is configuration-dependent, but whose usage is |
| 70 | universal - like the stuff in systime.h. |
| 71 | |
| 72 | It turns out that we can auto-detect whether we're being compiled |
| 73 | with X11R3 or X11R4 by looking for the flag macros for R4 structure |
| 74 | members that R3 doesn't have. */ |
| 75 | #ifdef PBaseSize |
| 76 | /* AIX 3.1's X is somewhere between X11R3 and X11R4. It has |
| 77 | PBaseSize, but not XWithdrawWindow, XSetWMName, XSetWMNormalHints, |
| 78 | XSetWMIconName. |
| 79 | AIX 3.2 is at least X11R4. */ |
| 80 | #if (!defined AIX) || (defined AIX3_2) |
| 81 | #define HAVE_X11R4 |
| 82 | #endif |
| 83 | #endif |
| 84 | |
| 85 | #ifdef XlibSpecificationRelease |
| 86 | #if XlibSpecificationRelease >= 5 |
| 87 | #define HAVE_X11R5 |
| 88 | /* In case someone has X11R5 on AIX 3.1, |
| 89 | make sure HAVE_X11R4 is defined as well as HAVE_X11R5. */ |
| 90 | #define HAVE_X11R4 |
| 91 | #endif |
| 92 | #endif |
| 93 | |
| 94 | #define PIX_TYPE unsigned long |
| 95 | #define XDISPLAY x_current_display, |
| 96 | #define XFlushQueue() XFlush(x_current_display) |
| 97 | #define BLACK_PIX_DEFAULT BlackPixel (x_current_display, \ |
| 98 | XDefaultScreen (x_current_display)) |
| 99 | #define WHITE_PIX_DEFAULT WhitePixel (x_current_display, \ |
| 100 | XDefaultScreen (x_current_display)) |
| 101 | #define DISPLAY_SCREEN_ARG x_current_display, \ |
| 102 | XDefaultScreen (x_current_display) |
| 103 | #define DISPLAY_CELLS DisplayCells (x_current_display, XDefaultScreen (x_current_display)) |
| 104 | #define ROOT_WINDOW RootWindow (x_current_display, DefaultScreen (x_current_display)) |
| 105 | #define FONT_TYPE XFontStruct |
| 106 | #define Color XColor |
| 107 | |
| 108 | #define XExposeRegionEvent XExposeEvent |
| 109 | #define Bitmap Pixmap /* In X11, Bitmaps are a kind of |
| 110 | Pixmap. */ |
| 111 | #define WINDOWINFO_TYPE XWindowAttributes |
| 112 | #define XGetWindowInfo(w, i) XGetWindowAttributes (x_current_display, \ |
| 113 | (w), (i)) |
| 114 | #define XGetFont(f) XLoadQueryFont (x_current_display, (f)) |
| 115 | #define XLoseFont(f) XFreeFont (x_current_display, (f)) |
| 116 | #define XStuffPending() XPending (x_current_display) |
| 117 | #define XClear(w) XClearWindow (x_current_display, (w)) |
| 118 | #define XWarpMousePointer(w,x,y) XWarpPointer (x_current_display, None, w, \ |
| 119 | 0,0,0,0, x, y) |
| 120 | #define XHandleError XSetErrorHandler |
| 121 | #define XHandleIOError XSetIOErrorHandler |
| 122 | |
| 123 | #define XChangeWindowSize(w,x,y) XResizeWindow(x_current_display,w,x,y) |
| 124 | |
| 125 | #define FONT_WIDTH(f) ((f)->max_bounds.width) |
| 126 | #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent) |
| 127 | #define FONT_BASE(f) ((f)->ascent) |
| 128 | |
| 129 | /* The mask of events that text windows always want to receive. This |
| 130 | does not include mouse movement events. It is used when the window |
| 131 | is created (in x_window) and when we ask/unask for mouse movement |
| 132 | events (in XTmouse_tracking_enable). |
| 133 | |
| 134 | We do include ButtonReleases in this set because elisp isn't always |
| 135 | fast enough to catch them when it wants them, and they're rare |
| 136 | enough that they don't use much processor time. */ |
| 137 | |
| 138 | #define STANDARD_EVENT_SET \ |
| 139 | (KeyPressMask \ |
| 140 | | ExposureMask \ |
| 141 | | ButtonPressMask \ |
| 142 | | ButtonReleaseMask \ |
| 143 | | PointerMotionMask \ |
| 144 | | PointerMotionHintMask \ |
| 145 | | StructureNotifyMask \ |
| 146 | | FocusChangeMask \ |
| 147 | | LeaveWindowMask \ |
| 148 | | EnterWindowMask \ |
| 149 | | VisibilityChangeMask) |
| 150 | |
| 151 | #else /* X10 */ |
| 152 | |
| 153 | #define ConnectionNumber(dpy) dpyno() |
| 154 | #define PIX_TYPE int |
| 155 | #define XDISPLAY |
| 156 | #define XFlushQueue() XFlush() |
| 157 | #define BLACK_PIX_DEFAULT BlackPixel |
| 158 | #define WHITE_PIX_DEFAULT WhitePixel |
| 159 | #define DISPLAY_SCREEN_ARG |
| 160 | #define DISPLAY_CELLS DisplayCells () |
| 161 | #define ROOT_WINDOW RootWindow |
| 162 | #define XFree free |
| 163 | #define FONT_TYPE FontInfo |
| 164 | |
| 165 | #define WINDOWINFO_TYPE WindowInfo |
| 166 | #define XGetWindowInfo(w, i) XQueryWindow ((w), (i)) |
| 167 | #define XGetFont(f) XOpenFont ((f)) |
| 168 | #define XLoseFont(f) XCloseFont ((f)) |
| 169 | #define XStuffPending() XPending () |
| 170 | #define XWarpMousePointer(w,x,y) XWarpMouse (w,x,y) |
| 171 | #define XHandleError XErrorHandler |
| 172 | #define XHandleIOError XIOErrorHandler |
| 173 | |
| 174 | #define FONT_WIDTH(f) ((f)->width) |
| 175 | #define FONT_HEIGHT(f) ((f)->height) |
| 176 | #define FONT_BASE(f) ((f)->base) |
| 177 | |
| 178 | #define XChangeWindowSize(w,x,y) XChangeWindow(w,x,y) |
| 179 | |
| 180 | #endif /* X10 */ |
| 181 | |
| 182 | struct event_queue |
| 183 | { |
| 184 | int rindex; /* Index at which to fetch next. */ |
| 185 | int windex; /* Index at which to store next. */ |
| 186 | XEvent xrep[EVENT_BUFFER_SIZE]; |
| 187 | }; |
| 188 | |
| 189 | /* Queue for mouse clicks. */ |
| 190 | extern struct event_queue x_mouse_queue; |
| 191 | |
| 192 | /* This is the X connection that we are using. */ |
| 193 | |
| 194 | extern Display *x_current_display; |
| 195 | |
| 196 | /* This checks to make sure we have a display. */ |
| 197 | extern void check_x (); |
| 198 | |
| 199 | extern struct frame *x_window_to_frame (); |
| 200 | |
| 201 | #ifdef USE_X_TOOLKIT |
| 202 | extern struct frame *x_any_window_to_frame (); |
| 203 | extern struct frame *x_top_window_to_frame (); |
| 204 | #endif |
| 205 | |
| 206 | /* The frame (if any) which has the X window that has keyboard focus. |
| 207 | Zero if none. This is examined by Ffocus_frame in xfns.c */ |
| 208 | |
| 209 | extern struct frame *x_focus_frame; |
| 210 | |
| 211 | #ifdef HAVE_X11 |
| 212 | /* Variables associated with the X display screen this emacs is using. */ |
| 213 | |
| 214 | /* How many screens this X display has. */ |
| 215 | extern int x_screen_count; |
| 216 | |
| 217 | /* The vendor supporting this X server. */ |
| 218 | extern Lisp_Object Vx_vendor; |
| 219 | |
| 220 | /* The vendor's release number for this X server. */ |
| 221 | extern int x_release; |
| 222 | |
| 223 | /* Height of this X screen in pixels. */ |
| 224 | extern int x_screen_height; |
| 225 | |
| 226 | /* Height of this X screen in millimeters. */ |
| 227 | extern int x_screen_height_mm; |
| 228 | |
| 229 | /* Width of this X screen in pixels. */ |
| 230 | extern int x_screen_width; |
| 231 | |
| 232 | /* Width of this X screen in millimeters. */ |
| 233 | extern int x_screen_width_mm; |
| 234 | |
| 235 | /* Does this X screen do backing store? */ |
| 236 | extern Lisp_Object Vx_backing_store; |
| 237 | |
| 238 | /* Does this X screen do save-unders? */ |
| 239 | extern int x_save_under; |
| 240 | |
| 241 | /* Number of planes for this screen. */ |
| 242 | extern int x_screen_planes; |
| 243 | |
| 244 | /* X Visual type of this screen. */ |
| 245 | extern Lisp_Object Vx_screen_visual; |
| 246 | |
| 247 | /* Mask of which mouse buttons are currently held down. */ |
| 248 | extern unsigned int x_mouse_grabbed; |
| 249 | |
| 250 | #endif /* HAVE_X11 */ |
| 251 | \f |
| 252 | enum text_cursor_kinds { |
| 253 | filled_box_cursor, hollow_box_cursor, bar_cursor |
| 254 | }; |
| 255 | |
| 256 | /* Each X frame object points to its own struct x_display object |
| 257 | in the display.x field. The x_display structure contains all |
| 258 | the information that is specific to X windows. */ |
| 259 | |
| 260 | struct x_display |
| 261 | { |
| 262 | /* Position of the X window (x and y offsets in root window). */ |
| 263 | int left_pos; |
| 264 | int top_pos; |
| 265 | |
| 266 | /* Border width of the X window as known by the X window system. */ |
| 267 | int border_width; |
| 268 | |
| 269 | /* Size of the X window in pixels. */ |
| 270 | int pixel_height, pixel_width; |
| 271 | |
| 272 | /* Height of a line, in pixels. */ |
| 273 | int line_height; |
| 274 | |
| 275 | #ifdef HAVE_X11 |
| 276 | /* The tiled border used when the mouse is out of the frame. */ |
| 277 | Pixmap border_tile; |
| 278 | |
| 279 | /* Here are the Graphics Contexts for the default font. */ |
| 280 | GC normal_gc; /* Normal video */ |
| 281 | GC reverse_gc; /* Reverse video */ |
| 282 | GC cursor_gc; /* cursor drawing */ |
| 283 | #endif /* HAVE_X11 */ |
| 284 | |
| 285 | /* Width of the internal border. This is a line of background color |
| 286 | just inside the window's border. When the frame is selected, |
| 287 | a highlighting is displayed inside the internal border. */ |
| 288 | int internal_border_width; |
| 289 | |
| 290 | /* The X window used for this frame. |
| 291 | May be zero while the frame object is being created |
| 292 | and the X window has not yet been created. */ |
| 293 | Window window_desc; |
| 294 | |
| 295 | /* The X window used for the bitmap icon; |
| 296 | or 0 if we don't have a bitmap icon. */ |
| 297 | Window icon_desc; |
| 298 | |
| 299 | /* The X window that is the parent of this X window. |
| 300 | Usually but not always RootWindow. */ |
| 301 | Window parent_desc; |
| 302 | |
| 303 | #ifdef USE_X_TOOLKIT |
| 304 | /* The widget of this screen. This is the window of a "shell" widget. */ |
| 305 | Widget widget; |
| 306 | /* The XmPanedWindows... */ |
| 307 | Widget column_widget; |
| 308 | /* The widget of the edit portion of this screen; the window in |
| 309 | "window_desc" is inside of this. */ |
| 310 | Widget edit_widget; |
| 311 | |
| 312 | Widget menubar_widget; |
| 313 | #endif |
| 314 | |
| 315 | /* 1 for bitmap icon, 0 for text icon. */ |
| 316 | int icon_bitmap_flag; |
| 317 | |
| 318 | FONT_TYPE *font; |
| 319 | |
| 320 | /* Pixel values used for various purposes. |
| 321 | border_pixel may be -1 meaning use a gray tile. */ |
| 322 | PIX_TYPE background_pixel; |
| 323 | PIX_TYPE foreground_pixel; |
| 324 | PIX_TYPE cursor_pixel; |
| 325 | PIX_TYPE border_pixel; |
| 326 | PIX_TYPE mouse_pixel; |
| 327 | PIX_TYPE cursor_foreground_pixel; |
| 328 | |
| 329 | /* Descriptor for the cursor in use for this window. */ |
| 330 | #ifdef HAVE_X11 |
| 331 | Cursor text_cursor; |
| 332 | Cursor nontext_cursor; |
| 333 | Cursor modeline_cursor; |
| 334 | Cursor cross_cursor; |
| 335 | #else |
| 336 | Cursor cursor; |
| 337 | #endif |
| 338 | |
| 339 | /* The name that was associated with the icon, the last time |
| 340 | it was refreshed. Usually the same as the name of the |
| 341 | buffer in the currently selected window in the frame */ |
| 342 | char *icon_label; |
| 343 | |
| 344 | /* Flag to set when the X window needs to be completely repainted. */ |
| 345 | int needs_exposure; |
| 346 | |
| 347 | /* What kind of text cursor is drawn in this window right now? |
| 348 | (If there is no cursor (phys_cursor_x < 0), then this means nothing.) */ |
| 349 | enum text_cursor_kinds current_cursor; |
| 350 | |
| 351 | /* What kind of text cursor should we draw in the future? |
| 352 | This should always be filled_box_cursor or bar_cursor. */ |
| 353 | enum text_cursor_kinds desired_cursor; |
| 354 | |
| 355 | /* These are the current window manager hints. It seems that |
| 356 | XSetWMHints, when presented with an unset bit in the `flags' |
| 357 | member of the hints structure, does not leave the corresponding |
| 358 | attribute unchanged; rather, it resets that attribute to its |
| 359 | default value. For example, unless you set the `icon_pixmap' |
| 360 | field and the `IconPixmapHint' bit, XSetWMHints will forget what |
| 361 | your icon pixmap was. This is rather troublesome, since some of |
| 362 | the members (for example, `input' and `icon_pixmap') want to stay |
| 363 | the same throughout the execution of Emacs. So, we keep this |
| 364 | structure around, just leaving values in it and adding new bits |
| 365 | to the mask as we go. */ |
| 366 | XWMHints wm_hints; |
| 367 | |
| 368 | /* The size of the extra width currently allotted for vertical |
| 369 | scroll bars, in pixels. */ |
| 370 | int vertical_scroll_bar_extra; |
| 371 | |
| 372 | /* Table of parameter faces for this frame. Any X resources (pixel |
| 373 | values, fonts) referred to here have been allocated explicitly |
| 374 | for this face, and should be freed if we change the face. */ |
| 375 | struct face **param_faces; |
| 376 | int n_param_faces; |
| 377 | |
| 378 | /* Table of computed faces for this frame. These are the faces |
| 379 | whose indexes go into the upper bits of a glyph, computed by |
| 380 | combining the parameter faces specified by overlays, text |
| 381 | properties, and what have you. The X resources mentioned here |
| 382 | are all shared with parameter faces. */ |
| 383 | struct face **computed_faces; |
| 384 | int n_computed_faces; /* How many are valid */ |
| 385 | int size_computed_faces; /* How many are allocated */ |
| 386 | |
| 387 | /* This is the gravity value for the specified window position. */ |
| 388 | int win_gravity; |
| 389 | |
| 390 | /* The geometry flags for this window. */ |
| 391 | int size_hint_flags; |
| 392 | }; |
| 393 | |
| 394 | /* Get at the computed faces of an X window frame. */ |
| 395 | #define FRAME_PARAM_FACES(f) ((f)->display.x->param_faces) |
| 396 | #define FRAME_N_PARAM_FACES(f) ((f)->display.x->n_param_faces) |
| 397 | #define FRAME_DEFAULT_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[0]) |
| 398 | #define FRAME_MODE_LINE_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[1]) |
| 399 | |
| 400 | #define FRAME_COMPUTED_FACES(f) ((f)->display.x->computed_faces) |
| 401 | #define FRAME_N_COMPUTED_FACES(f) ((f)->display.x->n_computed_faces) |
| 402 | #define FRAME_SIZE_COMPUTED_FACES(f) ((f)->display.x->size_computed_faces) |
| 403 | #define FRAME_DEFAULT_FACE(f) ((f)->display.x->computed_faces[0]) |
| 404 | #define FRAME_MODE_LINE_FACE(f) ((f)->display.x->computed_faces[1]) |
| 405 | |
| 406 | /* Return the window associated with the frame F. */ |
| 407 | #define FRAME_X_WINDOW(f) ((f)->display.x->window_desc) |
| 408 | |
| 409 | /* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */ |
| 410 | #define PIXEL_WIDTH(f) ((f)->display.x->pixel_width) |
| 411 | #define PIXEL_HEIGHT(f) ((f)->display.x->pixel_height) |
| 412 | |
| 413 | #define FRAME_DESIRED_CURSOR(f) ((f)->display.x->desired_cursor) |
| 414 | |
| 415 | \f |
| 416 | /* When X windows are used, a glyph may be a 16 bit unsigned datum. |
| 417 | The high order byte is the face number and is used as an index |
| 418 | in the face table. A face is a font plus: |
| 419 | 1) the unhighlighted foreground color, |
| 420 | 2) the unhighlighted background color. |
| 421 | For highlighting, the two colors are exchanged. |
| 422 | Face number 0 is unused. The low order byte of a glyph gives |
| 423 | the character within the font. All fonts are assumed to be |
| 424 | fixed width, and to have the same height and width. */ |
| 425 | |
| 426 | #ifdef HAVE_X11 |
| 427 | |
| 428 | /* Face declared in dispextern.h */ |
| 429 | |
| 430 | #else /* X10 */ |
| 431 | |
| 432 | struct face |
| 433 | { |
| 434 | FONT_TYPE *font; /* Font info for specified font. */ |
| 435 | int fg; /* Unhighlighted foreground. */ |
| 436 | int bg; /* Unhighlighted background. */ |
| 437 | }; |
| 438 | #endif /* X10 */ |
| 439 | |
| 440 | #define MAX_FACES_AND_GLYPHS 256 |
| 441 | extern struct face *x_face_table[]; |
| 442 | |
| 443 | \f |
| 444 | /* X-specific scroll bar stuff. */ |
| 445 | |
| 446 | /* We represent scroll bars as lisp vectors. This allows us to place |
| 447 | references to them in windows without worrying about whether we'll |
| 448 | end up with windows referring to dead scroll bars; the garbage |
| 449 | collector will free it when its time comes. |
| 450 | |
| 451 | We use struct scroll_bar as a template for accessing fields of the |
| 452 | vector. */ |
| 453 | |
| 454 | struct scroll_bar { |
| 455 | |
| 456 | /* These fields are shared by all vectors. */ |
| 457 | int size_from_Lisp_Vector_struct; |
| 458 | struct Lisp_Vector *next_from_Lisp_Vector_struct; |
| 459 | |
| 460 | /* The window we're a scroll bar for. */ |
| 461 | Lisp_Object window; |
| 462 | |
| 463 | /* The next and previous in the chain of scroll bars in this frame. */ |
| 464 | Lisp_Object next, prev; |
| 465 | |
| 466 | /* The X window representing this scroll bar. Since this is a full |
| 467 | 32-bit quantity, we store it split into two 32-bit values. */ |
| 468 | Lisp_Object x_window_low, x_window_high; |
| 469 | |
| 470 | /* The position and size of the scroll bar in pixels, relative to the |
| 471 | frame. */ |
| 472 | Lisp_Object top, left, width, height; |
| 473 | |
| 474 | /* The starting and ending positions of the handle, relative to the |
| 475 | handle area (i.e. zero is the top position, not |
| 476 | SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle |
| 477 | hasn't been drawn yet. |
| 478 | |
| 479 | These are not actually the locations where the beginning and end |
| 480 | are drawn; in order to keep handles from becoming invisible when |
| 481 | editing large files, we establish a minimum height by always |
| 482 | drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below |
| 483 | where they would be normally; the bottom and top are in a |
| 484 | different co-ordinate system. */ |
| 485 | Lisp_Object start, end; |
| 486 | |
| 487 | /* If the scroll bar handle is currently being dragged by the user, |
| 488 | this is the number of pixels from the top of the handle to the |
| 489 | place where the user grabbed it. If the handle isn't currently |
| 490 | being dragged, this is Qnil. */ |
| 491 | Lisp_Object dragging; |
| 492 | }; |
| 493 | |
| 494 | /* The number of elements a vector holding a struct scroll_bar needs. */ |
| 495 | #define SCROLL_BAR_VEC_SIZE \ |
| 496 | ((sizeof (struct scroll_bar) - sizeof (int) - sizeof (struct Lisp_Vector *)) \ |
| 497 | / sizeof (Lisp_Object)) |
| 498 | |
| 499 | /* Turning a lisp vector value into a pointer to a struct scroll_bar. */ |
| 500 | #define XSCROLL_BAR(vec) ((struct scroll_bar *) XPNTR (vec)) |
| 501 | |
| 502 | |
| 503 | /* Building a 32-bit C integer from two 16-bit lisp integers. */ |
| 504 | #define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low)) |
| 505 | |
| 506 | /* Setting two lisp integers to the low and high words of a 32-bit C int. */ |
| 507 | #define SCROLL_BAR_UNPACK(low, high, int32) \ |
| 508 | (XSET ((low), Lisp_Int, (int32) & 0xffff), \ |
| 509 | XSET ((high), Lisp_Int, ((int32) >> 16) & 0xffff)) |
| 510 | |
| 511 | |
| 512 | /* Extract the X window id of the scroll bar from a struct scroll_bar. */ |
| 513 | #define SCROLL_BAR_X_WINDOW(ptr) \ |
| 514 | ((Window) SCROLL_BAR_PACK ((ptr)->x_window_low, (ptr)->x_window_high)) |
| 515 | |
| 516 | /* Store a window id in a struct scroll_bar. */ |
| 517 | #define SET_SCROLL_BAR_X_WINDOW(ptr, id) \ |
| 518 | (SCROLL_BAR_UNPACK ((ptr)->x_window_low, (ptr)->x_window_high, (int) id)) |
| 519 | |
| 520 | |
| 521 | /* Return the outside pixel width for a vertical scroll bar on frame F. */ |
| 522 | #define VERTICAL_SCROLL_BAR_PIXEL_WIDTH(f) (2*FONT_WIDTH ((f)->display.x->font)) |
| 523 | |
| 524 | /* Return the outside pixel height for a vertical scroll bar HEIGHT |
| 525 | rows high on frame F. */ |
| 526 | #define VERTICAL_SCROLL_BAR_PIXEL_HEIGHT(f, height) \ |
| 527 | ((height) * (f)->display.x->line_height) |
| 528 | |
| 529 | /* Return the inside width of a vertical scroll bar, given the outside |
| 530 | width. */ |
| 531 | #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(width) \ |
| 532 | ((width) - VERTICAL_SCROLL_BAR_LEFT_BORDER - VERTICAL_SCROLL_BAR_RIGHT_BORDER) |
| 533 | |
| 534 | /* Return the length of the rectangle within which the top of the |
| 535 | handle must stay. This isn't equivalent to the inside height, |
| 536 | because the scroll bar handle has a minimum height. |
| 537 | |
| 538 | This is the real range of motion for the scroll bar, so when we're |
| 539 | scaling buffer positions to scroll bar positions, we use this, not |
| 540 | VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */ |
| 541 | #define VERTICAL_SCROLL_BAR_TOP_RANGE(height) \ |
| 542 | (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (height) - VERTICAL_SCROLL_BAR_MIN_HANDLE) |
| 543 | |
| 544 | /* Return the inside height of vertical scroll bar, given the outside |
| 545 | height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */ |
| 546 | #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(height) \ |
| 547 | ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER) |
| 548 | |
| 549 | |
| 550 | /* Border widths for scroll bars. |
| 551 | |
| 552 | Scroll bar windows don't have any X borders; their border width is |
| 553 | set to zero, and we redraw borders ourselves. This makes the code |
| 554 | a bit cleaner, since we don't have to convert between outside width |
| 555 | (used when relating to the rest of the screen) and inside width |
| 556 | (used when sizing and drawing the scroll bar window itself). |
| 557 | |
| 558 | The handle moves up and down/back and forth in a rectangle inset |
| 559 | from the edges of the scroll bar. These are widths by which we |
| 560 | inset the handle boundaries from the scroll bar edges. */ |
| 561 | #define VERTICAL_SCROLL_BAR_LEFT_BORDER (2) |
| 562 | #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (2) |
| 563 | #define VERTICAL_SCROLL_BAR_TOP_BORDER (2) |
| 564 | #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (2) |
| 565 | |
| 566 | /* Minimum lengths for scroll bar handles, in pixels. */ |
| 567 | #define VERTICAL_SCROLL_BAR_MIN_HANDLE (5) |
| 568 | |
| 569 | \f |
| 570 | /* Manipulating pixel sizes and character sizes. |
| 571 | Knowledge of which factors affect the overall size of the window should |
| 572 | be hidden in these macros, if that's possible. |
| 573 | |
| 574 | /* Return the upper/left pixel position of the character cell on frame F |
| 575 | at ROW/COL. */ |
| 576 | #define CHAR_TO_PIXEL_ROW(f, row) \ |
| 577 | ((f)->display.x->internal_border_width \ |
| 578 | + (row) * (f)->display.x->line_height) |
| 579 | #define CHAR_TO_PIXEL_COL(f, col) \ |
| 580 | ((f)->display.x->internal_border_width \ |
| 581 | + (col) * FONT_WIDTH ((f)->display.x->font)) |
| 582 | |
| 583 | /* Return the pixel width/height of frame F if it has |
| 584 | WIDTH columns/HEIGHT rows. */ |
| 585 | #define CHAR_TO_PIXEL_WIDTH(f, width) \ |
| 586 | (CHAR_TO_PIXEL_COL (f, width) \ |
| 587 | + (f)->display.x->vertical_scroll_bar_extra \ |
| 588 | + (f)->display.x->internal_border_width) |
| 589 | #define CHAR_TO_PIXEL_HEIGHT(f, height) \ |
| 590 | (CHAR_TO_PIXEL_ROW (f, height) \ |
| 591 | + (f)->display.x->internal_border_width) |
| 592 | |
| 593 | |
| 594 | /* Return the row/column (zero-based) of the character cell containing |
| 595 | the pixel on FRAME at ROW/COL. */ |
| 596 | #define PIXEL_TO_CHAR_ROW(f, row) \ |
| 597 | (((row) - (f)->display.x->internal_border_width) \ |
| 598 | / (f)->display.x->line_height) |
| 599 | #define PIXEL_TO_CHAR_COL(f, col) \ |
| 600 | (((col) - (f)->display.x->internal_border_width) \ |
| 601 | / FONT_WIDTH ((f)->display.x->font)) |
| 602 | |
| 603 | /* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on |
| 604 | frame F? */ |
| 605 | #define PIXEL_TO_CHAR_WIDTH(f, width) \ |
| 606 | (PIXEL_TO_CHAR_COL (f, ((width) \ |
| 607 | - (f)->display.x->internal_border_width \ |
| 608 | - (f)->display.x->vertical_scroll_bar_extra))) |
| 609 | #define PIXEL_TO_CHAR_HEIGHT(f, height) \ |
| 610 | (PIXEL_TO_CHAR_ROW (f, ((height) \ |
| 611 | - (f)->display.x->internal_border_width))) |
| 612 | \f |
| 613 | /* If a struct input_event has a kind which is selection_request_event |
| 614 | or selection_clear_event, then its contents are really described |
| 615 | by this structure. */ |
| 616 | |
| 617 | /* For an event of kind selection_request_event, |
| 618 | this structure really describes the contents. */ |
| 619 | struct selection_input_event |
| 620 | { |
| 621 | int kind; |
| 622 | Display *display; |
| 623 | Window requestor; |
| 624 | Atom selection, target, property; |
| 625 | Time time; |
| 626 | }; |
| 627 | |
| 628 | #define SELECTION_EVENT_DISPLAY(eventp) \ |
| 629 | (((struct selection_input_event *) (eventp))->display) |
| 630 | #define SELECTION_EVENT_REQUESTOR(eventp) \ |
| 631 | (((struct selection_input_event *) (eventp))->requestor) |
| 632 | #define SELECTION_EVENT_SELECTION(eventp) \ |
| 633 | (((struct selection_input_event *) (eventp))->selection) |
| 634 | #define SELECTION_EVENT_TARGET(eventp) \ |
| 635 | (((struct selection_input_event *) (eventp))->target) |
| 636 | #define SELECTION_EVENT_PROPERTY(eventp) \ |
| 637 | (((struct selection_input_event *) (eventp))->property) |
| 638 | #define SELECTION_EVENT_TIME(eventp) \ |
| 639 | (((struct selection_input_event *) (eventp))->time) |
| 640 | |
| 641 | \f |
| 642 | /* Interface to the face code functions. */ |
| 643 | |
| 644 | /* Create the first two computed faces for a frame -- the ones that |
| 645 | have GC's. */ |
| 646 | extern void init_frame_faces (/* FRAME_PTR */); |
| 647 | |
| 648 | /* Free the resources for the faces associated with a frame. */ |
| 649 | extern void free_frame_faces (/* FRAME_PTR */); |
| 650 | |
| 651 | /* Given a computed face, find or make an equivalent display face |
| 652 | in face_vector, and return a pointer to it. */ |
| 653 | extern struct face *intern_face (/* FRAME_PTR, struct face * */); |
| 654 | |
| 655 | /* Given a frame and a face name, return the face's ID number, or |
| 656 | zero if it isn't a recognized face name. */ |
| 657 | extern int face_name_id_number (/* FRAME_PTR, Lisp_Object */); |
| 658 | |
| 659 | /* Return non-zero if FONT1 and FONT2 have the same size bounding box. |
| 660 | We assume that they're both character-cell fonts. */ |
| 661 | extern int same_size_fonts (/* XFontStruct *, XFontStruct * */); |
| 662 | |
| 663 | /* Recompute the GC's for the default and modeline faces. |
| 664 | We call this after changing frame parameters on which those GC's |
| 665 | depend. */ |
| 666 | extern void recompute_basic_faces (/* FRAME_PTR */); |
| 667 | |
| 668 | /* Return the face ID associated with a buffer position POS. Store |
| 669 | into *ENDPTR the next position at which a different face is |
| 670 | needed. This does not take account of glyphs that specify their |
| 671 | own face codes. F is the frame in use for display, and W is a |
| 672 | window displaying the current buffer. |
| 673 | |
| 674 | REGION_BEG, REGION_END delimit the region, so it can be highlighted. */ |
| 675 | extern int compute_char_face (/* FRAME_PTR frame, |
| 676 | struct window *w, |
| 677 | int pos, |
| 678 | int region_beg, int region_end, |
| 679 | int *endptr */); |
| 680 | /* Return the face ID to use to display a special glyph which selects |
| 681 | FACE_CODE as the face ID, assuming that ordinarily the face would |
| 682 | be BASIC_FACE. F is the frame. */ |
| 683 | extern int compute_glyph_face (/* FRAME_PTR, int */); |