aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Blandy1993-01-14 15:34:59 +0000
committerJim Blandy1993-01-14 15:34:59 +0000
commit4e0277936aa6c6f966f635250b8a57b5a48c67fd (patch)
treecf5adf2c0b561e7af26dfe0add02546862c14f6a /src
parent12ba150f2f80f87cf02a6f1ac21bd51a4abf3c8d (diff)
downloademacs-4e0277936aa6c6f966f635250b8a57b5a48c67fd.tar.gz
emacs-4e0277936aa6c6f966f635250b8a57b5a48c67fd.zip
Make scrollbar structures into lisp objects, so that they can be
GC'd; this allows windows and scrollbars can refer to each other without worrying about dangling pointers. * xterm.h (struct x_display): vertical_scrollbars and judge_timestamp members deleted. (struct scrollbar): Redesigned to be a template for a Lisp_Vector. (SCROLLBAR_VEC_SIZE, XSCROLLBAR, SCROLLBAR_PACK, SCROLLBAR_UNPACK, SCROLLBAR_X_WINDOW, SET_SCROLLBAR_X_WINDOW, VERTICAL_SCROLLBAR_INSIDE_WIDTH, VERTICAL_SCROLLBAR_TOP_RANGE, VERTICAL_SCROLLBAR_INSIDE_HEIGHT, VERTICAL_SCROLLBAR_MIN_HANDLE): New macros, to help deal with the lispy structures, and deal with the graphics. * frame.h (WINDOW_VERTICAL_SCROLLBAR): Macro deleted. (struct frame): New fields `scrollbars' and `condemned_scrollbars', for use by the scrollbar implementation. [MULTI_FRAME and not MULTI_FRAME] (FRAME_SCROLLBARS, FRAME_CONDEMNED_SCROLLBARS): Accessors for the new field. * window.h (struct window): Doc fix for vertical_scrollbar field. * frame.c (make_frame): Initialize the `scrollbars' and `condemned_scrollbars' fields of the new frame. * alloc.c (mark_object): Mark the `scrollbars' and `condemned_scrollbars' slots of frames. * xterm.c (x_window_to_scrollbar): Scrollbars are chained on frames' scrollbar field, not their x.display->vertical_scrollbars field. (x_scrollbar_create, x_scrollbar_set_handle, x_scrollbar_move, x_scrollbar_remove, XTset_vertical_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar, XTjudge_scrollbars, x_scrollbar_expose, x_scrollbar_handle_click, x_scrollbar_handle_motion): Substantially rewritten to correct typos and brainos, and to accomodate the lispy structures. * xterm.h (CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH, PIXEL_TO_CHAR_HEIGHT): Rewritten, using: (CHAR_TO_PIXEL_ROW, CHAR_TO_PIXEL_COL, PIXEL_TO_CHAR_ROW, PIXEL_TO_CHAR_COL): New macros. * xfns.c [not HAVE_X11] (Fx_create_frame): Use the PIXEL_TO_CHAR_{HEIGHT,WIDTH} macros to figure the frame's character size, and the CHAR_TO_PIXEL* macros for vice versa. * xterm.c (XTwrite_glyphs, XTclear_end_of_line, stufflines, scraplines, dumprectangle, pixel_to_glyph_coords, x_draw_box, clear_cursor, x_display_bar_cursor, x_draw_single_glyph, x_set_mouse_position): Use the CHAR_TO_PIXEL_* macros.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.h182
1 files changed, 132 insertions, 50 deletions
diff --git a/src/xterm.h b/src/xterm.h
index a129e177c86..9bf083fa788 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -1,11 +1,11 @@
1/* Definitions and headers for communication with X protocol. 1/* Definitions and headers for communication with X protocol.
2 Copyright (C) 1989 Free Software Foundation, Inc. 2 Copyright (C) 1989, 1993 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
6GNU Emacs is free software; you can redistribute it and/or modify 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 7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option) 8the Free Software Foundation; either version 2, or (at your option)
9any later version. 9any later version.
10 10
11GNU Emacs is distributed in the hope that it will be useful, 11GNU Emacs is distributed in the hope that it will be useful,
@@ -333,13 +333,6 @@ struct x_display
333 to the mask as we go. */ 333 to the mask as we go. */
334 XWMHints wm_hints; 334 XWMHints wm_hints;
335 335
336 /* The list of vertical scrollbars currently being displayed in this
337 frame. */
338 struct scrollbar *vertical_scrollbars;
339
340 /* The timestamp used to implement the condemn/redeem/judge functions. */
341 int judge_timestamp;
342
343 /* The size of the extra width currently allotted for vertical 336 /* The size of the extra width currently allotted for vertical
344 scrollbars, in pixels. */ 337 scrollbars, in pixels. */
345 int vertical_scrollbar_extra; 338 int vertical_scrollbar_extra;
@@ -379,39 +372,81 @@ extern struct face *x_face_table[];
379 372
380/* X-specific scrollbar stuff. */ 373/* X-specific scrollbar stuff. */
381 374
375/* We represent scrollbars as lisp vectors. This allows us to place
376 references to them in windows without worrying about whether we'll
377 end up with windows referring to dead scrollbars; the garbage
378 collector will free it when its time comes.
379
380 We use struct scrollbar as a template for accessing fields of the
381 vector. */
382
382struct scrollbar { 383struct scrollbar {
383 384
384 /* The frame we're displayed on. */ 385 /* These fields are shared by all vectors. */
385 struct frame *frame; 386 int size_from_Lisp_Vector_struct;
387 struct Lisp_Vector *next_from_Lisp_Vector_struct;
388
389 /* The window we're a scrollbar for. */
390 Lisp_Object window;
386 391
387 /* The next in the chain of scrollbars in this frame. */ 392 /* The next and previous in the chain of scrollbars in this frame. */
388 struct scrollbar *next; 393 Lisp_Object next, prev;
389 394
390 /* The window representing this scrollbar. */ 395 /* The X window representing this scrollbar. Since this is a full
391 Window window; 396 32-bit quantity, we store it split into two 32-bit values. */
397 Lisp_Object x_window_low, x_window_high;
392 398
393 /* The position and size of the scrollbar in pixels, relative to the 399 /* The position and size of the scrollbar in pixels, relative to the
394 frame. */ 400 frame. */
395 int top, left; 401 Lisp_Object top, left, width, height;
396 int width, height;
397 402
398 /* The starting and ending positions of the handle, relative to 403 /* The starting and ending positions of the handle, relative to the
399 the handle area. If they're equal, that means the handle 404 handle area (i.e. zero is the top position, not
400 hasn't been drawn yet. */ 405 SCROLLBAR_TOP_BORDER). If they're equal, that means the handle
401 int start, end; 406 hasn't been drawn yet.
402 407
403 /* The timestamp for judgement. If this is less than 408 These are not actually the locations where the beginning and end
404 judge_timestamp in the x_display structure, this scrollbar is 409 are drawn; in order to keep handles from becoming invisible when
405 damned. */ 410 editing large files, we establish a minimum height by always
406 int judge_timestamp; 411 drawing handle bottoms VERTICAL_SCROLLBAR_MIN_HANDLE pixels below
412 where they would be normally; the bottom and top are in a
413 different co-ordinate system. */
414 Lisp_Object start, end;
407 415
408 /* If the scrollbar handle is currently being dragged by the user, 416 /* If the scrollbar handle is currently being dragged by the user,
409 this is the number of pixels from the top of the handle to the 417 this is the number of pixels from the top of the handle to the
410 place where the user grabbed it. If the handle isn't currently 418 place where the user grabbed it. If the handle isn't currently
411 being dragged, this is -1. */ 419 being dragged, this is Qnil. */
412 int dragging; 420 Lisp_Object dragging;
413}; 421};
414 422
423/* The number of elements a vector holding a struct scrollbar needs. */
424#define SCROLLBAR_VEC_SIZE \
425 ((sizeof (struct scrollbar) - sizeof (int) - sizeof (struct Lisp_Vector *)) \
426 / sizeof (Lisp_Object))
427
428/* Turning a lisp vector value into a pointer to a struct scrollbar. */
429#define XSCROLLBAR(vec) ((struct scrollbar *) XPNTR (vec))
430
431
432/* Building a 32-bit C integer from two 16-bit lisp integers. */
433#define SCROLLBAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
434
435/* Setting two lisp integers to the low and high words of a 32-bit C int. */
436#define SCROLLBAR_UNPACK(low, high, int32) \
437 (XSET ((low), Lisp_Int, (int32) & 0xffff), \
438 XSET ((high), Lisp_Int, ((int32) >> 16) & 0xffff))
439
440
441/* Extract the X window id of the scrollbar from a struct scrollbar. */
442#define SCROLLBAR_X_WINDOW(ptr) \
443 ((Window) SCROLLBAR_PACK ((ptr)->x_window_low, (ptr)->x_window_high))
444
445/* Store a window id in a struct scrollbar. */
446#define SET_SCROLLBAR_X_WINDOW(ptr, id) \
447 (SCROLLBAR_UNPACK ((ptr)->x_window_low, (ptr)->x_window_high, (int) id))
448
449
415/* Return the outside pixel width for a vertical scrollbar on frame F. */ 450/* Return the outside pixel width for a vertical scrollbar on frame F. */
416#define VERTICAL_SCROLLBAR_PIXEL_WIDTH(f) (2*FONT_WIDTH ((f)->display.x->font)) 451#define VERTICAL_SCROLLBAR_PIXEL_WIDTH(f) (2*FONT_WIDTH ((f)->display.x->font))
417 452
@@ -420,39 +455,86 @@ struct scrollbar {
420#define VERTICAL_SCROLLBAR_PIXEL_HEIGHT(f, height) \ 455#define VERTICAL_SCROLLBAR_PIXEL_HEIGHT(f, height) \
421 ((height) * FONT_HEIGHT ((f)->display.x->font)) 456 ((height) * FONT_HEIGHT ((f)->display.x->font))
422 457
458/* Return the inside width of a vertical scrollbar, given the outside
459 width. */
460#define VERTICAL_SCROLLBAR_INSIDE_WIDTH(width) \
461 ((width) - VERTICAL_SCROLLBAR_LEFT_BORDER - VERTICAL_SCROLLBAR_RIGHT_BORDER)
423 462
424/* Border widths for scrollbars. */ 463/* Return the length of the rectangle within which the top of the
425#define VERTICAL_SCROLLBAR_LEFT_BORDER (1) 464 handle must stay. This isn't equivalent to the inside height,
426#define VERTICAL_SCROLLBAR_RIGHT_BORDER (2) 465 because the scrollbar handle has a minimum height.
427#define VERTICAL_SCROLLBAR_TOP_BORDER (1) 466
428#define VERTICAL_SCROLLBAR_BOTTOM_BORDER (1) 467 This is the real range of motion for the scrollbar, so when we're
468 scaling buffer positions to scrollbar positions, we use this, not
469 VERTICAL_SCROLLBAR_INSIDE_HEIGHT. */
470#define VERTICAL_SCROLLBAR_TOP_RANGE(height) \
471 (VERTICAL_SCROLLBAR_INSIDE_HEIGHT (height) - VERTICAL_SCROLLBAR_MIN_HANDLE)
472
473/* Return the inside height of vertical scrollbar, given the outside
474 height. See VERTICAL_SCROLLBAR_TOP_RANGE too. */
475#define VERTICAL_SCROLLBAR_INSIDE_HEIGHT(height) \
476 ((height) - VERTICAL_SCROLLBAR_TOP_BORDER - VERTICAL_SCROLLBAR_BOTTOM_BORDER)
477
478
479/* Border widths for scrollbars.
480
481 Scrollbar windows don't have any X borders; their border width is
482 set to zero, and we redraw borders ourselves. This makes the code
483 a bit cleaner, since we don't have to convert between outside width
484 (used when relating to the rest of the screen) and inside width
485 (used when sizing and drawing the scrollbar window itself).
486
487 The handle moves up and down/back and forth in a rectange inset
488 from the edges of the scrollbar. These are widths by which we
489 inset the handle boundaries from the scrollbar edges. */
490#define VERTICAL_SCROLLBAR_LEFT_BORDER (2)
491#define VERTICAL_SCROLLBAR_RIGHT_BORDER (3)
492#define VERTICAL_SCROLLBAR_TOP_BORDER (2)
493#define VERTICAL_SCROLLBAR_BOTTOM_BORDER (2)
494
495/* Minimum lengths for scrollbar handles, in pixels. */
496#define VERTICAL_SCROLLBAR_MIN_HANDLE (5)
429 497
430 498
431/* Manipulating pixel sizes and character sizes. 499/* Manipulating pixel sizes and character sizes.
432 Knowledge of which factors affect the overall size of the window should 500 Knowledge of which factors affect the overall size of the window should
433 be hidden in these macros, if that's possible. 501 be hidden in these macros, if that's possible.
434 502
435/* Return the pixel width of frame F if it has WIDTH columns. */ 503/* Return the upper/left pixel position of the character cell on frame F
504 at ROW/COL. */
505#define CHAR_TO_PIXEL_ROW(f, row) \
506 ((f)->display.x->internal_border_width \
507 + (row) * FONT_HEIGHT ((f)->display.x->font))
508#define CHAR_TO_PIXEL_COL(f, col) \
509 ((f)->display.x->internal_border_width \
510 + (col) * FONT_WIDTH ((f)->display.x->font))
511
512/* Return the pixel width/height of frame F if it has
513 WIDTH columns/HEIGHT rows. */
436#define CHAR_TO_PIXEL_WIDTH(f, width) \ 514#define CHAR_TO_PIXEL_WIDTH(f, width) \
437 ((width) * FONT_WIDTH ((f)->display.x->font) \ 515 (CHAR_TO_PIXEL_COL (f, width) \
438 + 2 * (f)->display.x->internal_border_width \ 516 + (f)->display.x->vertical_scrollbar_extra \
439 + (f)->display.x->vertical_scrollbar_extra) 517 + (f)->display.x->internal_border_width)
440
441/* Return the pixel height of frame F if it has HEIGHT rows. */
442#define CHAR_TO_PIXEL_HEIGHT(f, height) \ 518#define CHAR_TO_PIXEL_HEIGHT(f, height) \
443 ((height) * FONT_HEIGHT ((f)->display.x->font) \ 519 (CHAR_TO_PIXEL_ROW (f, height) \
444 + 2 * (f)->display.x->internal_border_width) 520 + (f)->display.x->internal_border_width)
445 521
446/* How many columns of text can we fit in WIDTH pixels on frame F? */
447#define PIXEL_TO_CHAR_WIDTH(f, width) \
448 (((width) \
449 - (f)->display.x->vertical_scrollbar_extra \
450 - 2 * (f)->display.x->internal_border_width) \
451 / FONT_WIDTH ((f)->display.x->font))
452 522
453/* How many rows of text can we fit in HEIGHT pixels on frame F? */ 523/* Return the row/column (zero-based) of the character cell containing
454#define PIXEL_TO_CHAR_HEIGHT(f, height) \ 524 the pixel on FRAME at ROW/COL. */
455 (((height) \ 525#define PIXEL_TO_CHAR_ROW(frame, row) \
456 - 2 * (f)->display.x->internal_border_width) \ 526 (((row) - (f)->display.x->internal_border_width) \
457 / FONT_HEIGHT ((f)->display.x->font)) 527 / FONT_HEIGHT ((f)->display.x->font))
528#define PIXEL_TO_CHAR_COL(frame, col) \
529 (((col) - (f)->display.x->internal_border_width) \
530 / FONT_WIDTH ((f)->display.x->font))
458 531
532/* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on
533 frame F? */
534#define PIXEL_TO_CHAR_WIDTH(f, width) \
535 (PIXEL_TO_CHAR_COL (f, ((width) \
536 - (f)->display.x->internal_border_width \
537 - (f)->display.x->vertical_scrollbar_extra)))
538#define PIXEL_TO_CHAR_HEIGHT(f, height) \
539 (PIXEL_TO_CHAR_ROW (f, ((height) \
540 - (f)->display.x->internal_border_width)))