window.h 40 KB
Newer Older
Jim Blandy's avatar
Jim Blandy committed
1
/* Window definitions for GNU Emacs.
Paul Eggert's avatar
Paul Eggert committed
2
   Copyright (C) 1985-1986, 1993, 1995, 1997-2016 Free Software
3
   Foundation, Inc.
Jim Blandy's avatar
Jim Blandy committed
4 5 6

This file is part of GNU Emacs.

7
GNU Emacs is free software: you can redistribute it and/or modify
Jim Blandy's avatar
Jim Blandy committed
8
it under the terms of the GNU General Public License as published by
9 10
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Jim Blandy's avatar
Jim Blandy committed
11 12 13 14 15 16 17

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
18
along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
Jim Blandy's avatar
Jim Blandy committed
19

Gerd Moellmann's avatar
Gerd Moellmann committed
20 21 22 23
#ifndef WINDOW_H_INCLUDED
#define WINDOW_H_INCLUDED

#include "dispextern.h"
Jim Blandy's avatar
Jim Blandy committed
24

Paul Eggert's avatar
Paul Eggert committed
25 26
INLINE_HEADER_BEGIN

Jim Blandy's avatar
Jim Blandy committed
27 28 29 30 31 32 33 34 35
/* Windows are allocated as if they were vectors, but then the
Lisp data type is changed to Lisp_Window.  They are garbage
collected along with the vectors.

All windows in use are arranged into a tree, with pointers up and down.

Windows that are leaves of the tree are actually displayed
and show the contents of buffers.  Windows that are not leaves
are used for representing the way groups of leaf windows are
Jim Blandy's avatar
Jim Blandy committed
36
arranged on the frame.  Leaf windows never become non-leaves.
Jim Blandy's avatar
Jim Blandy committed
37 38 39 40
They are deleted only by calling delete-window on them (but
this can be done implicitly).  Combination windows can be created
and deleted at any time.

41 42
A leaf window has a buffer stored in contents field and markers in its start
and pointm fields.  Non-leaf windows have nil in the latter two fields.
Jim Blandy's avatar
Jim Blandy committed
43 44 45

Non-leaf windows are either vertical or horizontal combinations.

Jim Blandy's avatar
Jim Blandy committed
46
A vertical combination window has children that are arranged on the frame
47
one above the next.  Its contents field points to the uppermost child.
Jim Blandy's avatar
Jim Blandy committed
48 49 50 51 52 53 54
The parent field of each of the children points to the vertical
combination window.  The next field of each child points to the
child below it, or is nil for the lowest child.  The prev field
of each child points to the child above it, or is nil for the
highest child.

A horizontal combination window has children that are side by side.
55
Its contents field points to the leftmost child.  In each child
Jim Blandy's avatar
Jim Blandy committed
56 57 58 59 60 61 62 63 64
the next field points to the child to the right and the prev field
points to the child to the left.

The children of a vertical combination window may be leaf windows
or horizontal combination windows.  The children of a horizontal
combination window may be leaf windows or vertical combination windows.

At the top of the tree are two windows which have nil as parent.
The second of these is minibuf_window.  The first one manages all
Jim Blandy's avatar
Jim Blandy committed
65
the frame area that is not minibuffer, and is called the root window.
Jim Blandy's avatar
Jim Blandy committed
66 67 68 69 70
Different windows can be the root at different times;
initially the root window is a leaf window, but if more windows
are created then that leaf window ceases to be root and a newly
made combination window becomes root instead.

Jim Blandy's avatar
Jim Blandy committed
71 72 73 74
In any case, on screens which have an ordinary window and a
minibuffer, prev of the minibuf window is the root window and next of
the root window is the minibuf window.  On minibufferless screens or
minibuffer-only screens, the root window and the minibuffer window are
75
one and the same, so its prev and next members are nil.
Jim Blandy's avatar
Jim Blandy committed
76

77
A dead window has its contents field set to nil.  */
Jim Blandy's avatar
Jim Blandy committed
78

Gerd Moellmann's avatar
Gerd Moellmann committed
79 80 81 82 83 84 85 86 87
struct cursor_pos
{
  /* Pixel position.  These are always window relative.  */
  int x, y;

  /* Glyph matrix position.  */
  int hpos, vpos;
};

Jim Blandy's avatar
Jim Blandy committed
88 89
struct window
  {
90
    /* This is for Lisp; the terminal code does not refer to it.  */
91
    struct vectorlike_header header;
92

Jim Blandy's avatar
Jim Blandy committed
93
    /* The frame this window is on.  */
94
    Lisp_Object frame;
95 96 97

    /* Following (to right or down) and preceding (to left or up) child
       at same level of tree.  */
98 99
    Lisp_Object next;
    Lisp_Object prev;
100 101

    /* The window this one is a child of.  */
102
    Lisp_Object parent;
103

104 105 106
    /* The normal size of the window.  These are fractions, but we do
       not use C doubles to avoid creating new Lisp_Float objects while
       interfacing Lisp in Fwindow_normal_size.  */
107 108
    Lisp_Object normal_lines;
    Lisp_Object normal_cols;
109

110 111
    /* New sizes of the window.  Note that Lisp code may set new_normal
       to something beyond an integer, so C int can't be used here.  */
112 113
    Lisp_Object new_total;
    Lisp_Object new_normal;
114
    Lisp_Object new_pixel;
115

116 117
    /* May be buffer, window, or nil.  */
    Lisp_Object contents;
118

119 120 121 122
    /* A marker pointing to where in the text to start displaying.
       BIDI Note: This is the _logical-order_ start, i.e. the smallest
       buffer position visible in the window, not necessarily the
       character displayed in the top left corner of the window.  */
123
    Lisp_Object start;
124

Jim Blandy's avatar
Jim Blandy committed
125 126 127 128
    /* A marker pointing to where in the text point is in this window,
       used only when the window is not selected.
       This exists so that when multiple windows show one buffer
       each one can have its own value of point.  */
129
    Lisp_Object pointm;
130

131 132 133 134 135
    /* A marker pointing to where in the text point was in this window
       at the time of last redisplay.  The value is saved for the
       selected window too.  */
    Lisp_Object old_pointm;

136 137
    /* No permanent meaning; used by save-window-excursion's
       bookkeeping.  */
138
    Lisp_Object temslot;
139

140 141 142 143 144
    /* This window's vertical scroll bar.  This field is only for use by
       the window-system-dependent code which implements the scroll
       bars; it can store anything it likes here.  If this window is
       newly created and we haven't displayed a scroll bar in it yet, or
       if the frame doesn't have any scroll bars, this is nil.  */
145
    Lisp_Object vertical_scroll_bar;
146

147 148
    /* Type of vertical scroll bar.  A value of nil means
       no scroll bar.  A value of t means use frame value.  */
149
    Lisp_Object vertical_scroll_bar_type;
Gerd Moellmann's avatar
Gerd Moellmann committed
150

151 152 153 154 155 156 157 158 159 160 161
    /* This window's horizontal scroll bar.  This field is only for use
       by the window-system-dependent code which implements the scroll
       bars; it can store anything it likes here.  If this window is
       newly created and we haven't displayed a scroll bar in it yet, or
       if the frame doesn't have any scroll bars, this is nil.  */
    Lisp_Object horizontal_scroll_bar;

    /* Type of horizontal scroll bar.  A value of nil means
       no scroll bar.  A value of t means use frame value.  */
    Lisp_Object horizontal_scroll_bar_type;

Jim Blandy's avatar
Jim Blandy committed
162 163
    /* Display-table to use for displaying chars in this window.
       Nil means use the buffer's own display-table.  */
164
    Lisp_Object display_table;
165

166 167 168
    /* Non-nil usually means window is marked as dedicated.
       Note Lisp code may set this to something beyond Qnil
       and Qt, so bitfield can't be used here.  */
169
    Lisp_Object dedicated;
170

171 172
    /* If redisplay in this window goes beyond this buffer position,
       must run the redisplay-end-trigger-hook.  */
173
    Lisp_Object redisplay_end_trigger;
174

175
    /* t means this window's child windows are not (re-)combined.  */
176
    Lisp_Object combination_limit;
177

Paul Eggert's avatar
Paul Eggert committed
178
    /* An alist with parameters.  */
179
    Lisp_Object window_parameters;
180

Gerd Moellmann's avatar
Gerd Moellmann committed
181 182 183 184 185 186 187 188
    /* No Lisp data may follow below this point without changing
       mark_object in alloc.c.  The member current_matrix must be the
       first non-Lisp member.  */

    /* Glyph matrices.  */
    struct glyph_matrix *current_matrix;
    struct glyph_matrix *desired_matrix;

189 190 191 192 193 194 195 196
    /* The two Lisp_Object fields below are marked in a special way,
       which is why they're placed after `current_matrix'.  */
    /* Alist of <buffer, window-start, window-point> triples listing
       buffers previously shown in this window.  */
    Lisp_Object prev_buffers;
    /* List of buffers re-shown in this window.  */
    Lisp_Object next_buffers;

197
    /* Number saying how recently window was selected.  */
198
    EMACS_INT use_time;
199

200
    /* Unique number of window assigned when it was created.  */
201
    EMACS_INT sequence_number;
202 203 204 205 206 207

    /* The upper left corner pixel coordinates of this window, as
       integers relative to upper left corner of frame = 0, 0.  */
    int pixel_left;
    int pixel_top;

208 209 210 211 212
    /* The upper left corner coordinates of this window,
       relative to upper left corner of frame = 0, 0.  */
    int left_col;
    int top_line;

213 214 215 216
    /* The pixel size of the window.  */
    int pixel_width;
    int pixel_height;

217 218 219 220 221
    /* The pixel sizes of the window at the last time
       `window-size-change-functions' was run.  */
    int pixel_width_before_size_change;
    int pixel_height_before_size_change;

222 223
    /* The size of the window.  */
    int total_cols;
224
    int total_lines;
225

226
    /* Number of columns display within the window is scrolled to the left.  */
227
    ptrdiff_t hscroll;
228 229 230

    /* Minimum hscroll for automatic hscrolling.  This is the value
       the user has set, by set-window-hscroll for example.  */
231
    ptrdiff_t min_hscroll;
232

233 234 235 236
    /* Maximum line length in pixels within window bound by size of
       window (set up by set_horizontal_scroll_bar).  */
    ptrdiff_t hscroll_whole;

237 238 239 240 241 242 243 244 245
    /* Displayed buffer's text modification events counter as of last time
       display completed.  */
    EMACS_INT last_modified;

    /* Displayed buffer's overlays modification events counter as of last
       complete update.  */
    EMACS_INT last_overlay_modified;

    /* Value of point at that time.  Since this is a position in a buffer,
246
       it should be positive.  */
247 248
    ptrdiff_t last_point;

249 250 251 252 253 254 255 256 257 258 259 260 261
    /* Line number and position of a line somewhere above the top of the
       screen.  If this field is zero, it means we don't have a base line.  */
    ptrdiff_t base_line_number;

    /* If this field is zero, it means we don't have a base line.
       If it is -1, it means don't display the line number as long
       as the window shows its buffer.  */
    ptrdiff_t base_line_pos;

    /* The column number currently displayed in this window's mode
       line, or -1 if column numbers are not being displayed.  */
    ptrdiff_t column_number_displayed;

262 263
    /* Scaling factor for the glyph_matrix size calculation in this window.
       Used if window contains many small images or uses proportional fonts,
Paul Eggert's avatar
Paul Eggert committed
264
       as the normal may yield a matrix which is too small.  */
265 266
    int nrows_scale_factor, ncols_scale_factor;

Gerd Moellmann's avatar
Gerd Moellmann committed
267 268 269
    /* Intended cursor position.   This is a position within the
       glyph matrix.  */
    struct cursor_pos cursor;
270

Gerd Moellmann's avatar
Gerd Moellmann committed
271 272
    /* Where the cursor actually is.  */
    struct cursor_pos phys_cursor;
273

274 275 276
    /* Internally used for redisplay purposes.  */
    struct cursor_pos output_cursor;

277 278 279 280
    /* Vertical cursor position as of last update that completed
       without pause.  This is the position of last_point.  */
    int last_cursor_vpos;

281 282 283 284 285 286 287
#ifdef HAVE_WINDOW_SYSTEM

    /* Cursor type of last cursor drawn on the window.  */
    enum text_cursor_kinds phys_cursor_type;

    /* Width of the cursor above.  */
    int phys_cursor_width;
Gerd Moellmann's avatar
Gerd Moellmann committed
288 289 290

    /* This is handy for undrawing the cursor.  */
    int phys_cursor_ascent, phys_cursor_height;
291

292 293
#endif /* HAVE_WINDOW_SYSTEM */

294 295 296 297 298
    /* Width of left and right fringes, in pixels.
       A value of -1 means use frame values.  */
    int left_fringe_width;
    int right_fringe_width;

299 300 301 302
    /* Requested width of left and right marginal areas in columns.  A
       value of 0 means no margin.  The actual values are recorded in
       the window's glyph matrix, in the left_margin_glyphs and
       right_margin_glyphs members.  */
303 304 305
    int left_margin_cols;
    int right_margin_cols;

306 307 308 309
    /* Pixel width of scroll bars.
       A value of -1 means use frame values.  */
    int scroll_bar_width;

310 311 312 313
    /* Pixel height of scroll bars.
       A value of -1 means use frame values.  */
    int scroll_bar_height;

314 315 316 317 318 319
    /* Effective height of the mode line, or -1 if not known.  */
    int mode_line_height;

    /* Effective height of the header line, or -1 if not known.  */
    int header_line_height;

320
    /* Z - the buffer position of the last glyph in the current
321
       matrix of W.  Only valid if window_end_valid is true.  */
322 323 324
    ptrdiff_t window_end_pos;

    /* Glyph matrix row of the last glyph in the current matrix
325
       of W.  Only valid if window_end_valid is true.  */
326 327
    int window_end_vpos;

328 329
    /* True if this window is a minibuffer window.  */
    bool_bf mini : 1;
330

Paul Eggert's avatar
Paul Eggert committed
331
    /* Meaningful only if contents is a window, true if this
332
       internal window is used in horizontal combination.  */
333
    bool_bf horizontal : 1;
334

335 336
    /* True means must regenerate mode line of this window.  */
    bool_bf update_mode_line : 1;
337

338
    /* True if the buffer was "modified" when the window
339
       was last updated.  */
340
    bool_bf last_had_star : 1;
341

342
    /* True means current value of `start'
343
       was the beginning of a line when it was chosen.  */
344
    bool_bf start_at_line_beg : 1;
345

346
    /* True means next redisplay must use the value of start
347
       set up for it in advance.  Set by scrolling commands.  */
348
    bool_bf force_start : 1;
349

350
    /* True means we have explicitly changed the value of start,
351 352 353
       but that the next redisplay is not obliged to use the new value.
       This is used in Fdelete_other_windows to force a call to
       Vwindow_scroll_functions; also by Frecenter with argument.  */
354
    bool_bf optional_new_start : 1;
355

356
    /* True means the cursor is currently displayed.  This can be
Gerd Moellmann's avatar
Gerd Moellmann committed
357
       set to zero by functions overpainting the cursor image.  */
358
    bool_bf phys_cursor_on_p : 1;
Gerd Moellmann's avatar
Gerd Moellmann committed
359

360
    /* False means cursor is logically on, true means it's off.  Used for
Gerd Moellmann's avatar
Gerd Moellmann committed
361
       blinking cursor.  */
362
    bool_bf cursor_off_p : 1;
Gerd Moellmann's avatar
Gerd Moellmann committed
363 364

    /* Value of cursor_off_p as of the last redisplay.  */
365
    bool_bf last_cursor_off_p : 1;
Gerd Moellmann's avatar
Gerd Moellmann committed
366

367
    /* True means desired matrix has been build and window must be
Gerd Moellmann's avatar
Gerd Moellmann committed
368
       updated in update_frame.  */
369
    bool_bf must_be_updated_p : 1;
Gerd Moellmann's avatar
Gerd Moellmann committed
370 371 372

    /* Flag indicating that this window is not a real one.
       Currently only used for menu bar windows of frames.  */
373
    bool_bf pseudo_window_p : 1;
Gerd Moellmann's avatar
Gerd Moellmann committed
374

375
    /* True means fringes are drawn outside display margins.
376
       Otherwise draw them between margin areas and text.  */
377
    bool_bf fringes_outside_margins : 1;
378

379 380
    /* True if window_end_pos and window_end_vpos are truly valid.
       This is false if nontrivial redisplay is preempted since in that case
381
       the frame image that window_end_pos did not get onto the frame.  */
382
    bool_bf window_end_valid : 1;
383 384

    /* True if it needs to be redisplayed.  */
385
    bool_bf redisplay : 1;
386

387 388 389 390
    /* True if auto hscrolling is currently suspended in this
       window.  */
    bool_bf suspend_auto_hscroll : 1;

Gerd Moellmann's avatar
Gerd Moellmann committed
391 392 393
    /* Amount by which lines of this window are scrolled in
       y-direction (smooth scrolling).  */
    int vscroll;
394

395
    /* Z_BYTE - buffer position of the last glyph in the current matrix of W.
396
       Should be nonnegative, and only valid if window_end_valid is true.  */
397
    ptrdiff_t window_end_bytepos;
398
  };
Jim Blandy's avatar
Jim Blandy committed
399

Paul Eggert's avatar
Paul Eggert committed
400 401
/* Most code should use these functions to set Lisp fields in struct
   window.  */
Paul Eggert's avatar
Paul Eggert committed
402
INLINE void
Paul Eggert's avatar
Paul Eggert committed
403 404 405 406
wset_frame (struct window *w, Lisp_Object val)
{
  w->frame = val;
}
407

Paul Eggert's avatar
Paul Eggert committed
408
INLINE void
Paul Eggert's avatar
Paul Eggert committed
409 410 411 412
wset_next (struct window *w, Lisp_Object val)
{
  w->next = val;
}
413

Paul Eggert's avatar
Paul Eggert committed
414
INLINE void
Paul Eggert's avatar
Paul Eggert committed
415 416 417 418
wset_prev (struct window *w, Lisp_Object val)
{
  w->prev = val;
}
419

Paul Eggert's avatar
Paul Eggert committed
420
INLINE void
Paul Eggert's avatar
Paul Eggert committed
421 422 423 424
wset_redisplay_end_trigger (struct window *w, Lisp_Object val)
{
  w->redisplay_end_trigger = val;
}
425 426 427 428 429 430 431

INLINE void
wset_new_pixel (struct window *w, Lisp_Object val)
{
  w->new_pixel = val;
}

Paul Eggert's avatar
Paul Eggert committed
432
INLINE void
Paul Eggert's avatar
Paul Eggert committed
433 434 435 436
wset_vertical_scroll_bar (struct window *w, Lisp_Object val)
{
  w->vertical_scroll_bar = val;
}
437

438 439 440 441 442 443 444 445 446 447 448 449
INLINE void
wset_horizontal_scroll_bar (struct window *w, Lisp_Object val)
{
  w->horizontal_scroll_bar = val;
}

INLINE void
wset_horizontal_scroll_bar_type (struct window *w, Lisp_Object val)
{
  w->horizontal_scroll_bar_type = val;
}

Paul Eggert's avatar
Paul Eggert committed
450
INLINE void
451 452 453 454
wset_prev_buffers (struct window *w, Lisp_Object val)
{
  w->prev_buffers = val;
}
455

Paul Eggert's avatar
Paul Eggert committed
456
INLINE void
457 458 459 460
wset_next_buffers (struct window *w, Lisp_Object val)
{
  w->next_buffers = val;
}
Paul Eggert's avatar
Paul Eggert committed
461

462
/* True if W is a minibuffer window.  */
463
#define MINI_WINDOW_P(W) ((W)->mini)
Jim Blandy's avatar
Jim Blandy committed
464

465 466 467 468 469 470 471 472 473
/* 1 if W is a non-only minibuffer window.  */
/* The first check is redundant and the second overly complicated. */
#define MINI_NON_ONLY_WINDOW_P(W)				\
  (MINI_WINDOW_P (W)						\
   && (EQ (W->prev, FRAME_ROOT_WINDOW (WINDOW_XFRAME (W)))))

/* 1 if W is a minibuffer-only window.  */
#define MINI_ONLY_WINDOW_P(W)			\
  (MINI_WINDOW_P (W) && NILP (W->prev))
Jim Blandy's avatar
Jim Blandy committed
474

475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
/* General window layout:

   LEFT_EDGE_COL         RIGHT_EDGE_COL
   |                                  |
   |                                  |
   |  BOX_LEFT_EDGE_COL               |
   |  |           BOX_RIGHT_EDGE_COL  |
   |  |                            |  |
   v  v                            v  v
   <-><-><---><-----------><---><-><->
    ^  ^   ^        ^        ^   ^  ^
    |  |   |        |        |   |  |
    |  |   |        |        |   |  +-- RIGHT_SCROLL_BAR_COLS
    |  |   |        |        |   +----- RIGHT_FRINGE_WIDTH
    |  |   |        |        +--------- RIGHT_MARGIN_COLS
    |  |   |        |
    |  |   |        +------------------ TEXT_AREA_COLS
    |  |   |
    |  |   +--------------------------- LEFT_MARGIN_COLS
    |  +------------------------------- LEFT_FRINGE_WIDTH
    +---------------------------------- LEFT_SCROLL_BAR_COLS
496

497 498 499 500 501
*/


/* A handy macro.  */

502
/* Non-nil if W is leaf (carry the buffer).  */
503 504 505 506

#define WINDOW_LEAF_P(W) \
  (BUFFERP ((W)->contents))

507 508 509
/* Non-nil if W is internal.  */
#define WINDOW_INTERNAL_P(W) \
  (WINDOWP ((W)->contents))
510

511
/* True if W is a member of horizontal combination.  */
512
#define WINDOW_HORIZONTAL_COMBINATION_P(W) \
513
  (WINDOW_INTERNAL_P (W) && (W)->horizontal)
514

515
/* True if W is a member of vertical combination.  */
516
#define WINDOW_VERTICAL_COMBINATION_P(W) \
517
  (WINDOW_INTERNAL_P (W) && !(W)->horizontal)
518

519 520
/* WINDOW's XFRAME.  */
#define WINDOW_XFRAME(W) (XFRAME (WINDOW_FRAME ((W))))
521

522 523
/* Whether WINDOW is a pseudo window.  */
#define WINDOW_PSEUDO_P(W) ((W)->pseudo_window_p)
524

525
/* Return the canonical column width of the frame of window W.  */
526 527 528
#define WINDOW_FRAME_COLUMN_WIDTH(W) \
  (FRAME_COLUMN_WIDTH (WINDOW_XFRAME ((W))))

529
/* Return the canonical line height of the frame of window W.  */
530 531 532
#define WINDOW_FRAME_LINE_HEIGHT(W) \
  (FRAME_LINE_HEIGHT (WINDOW_XFRAME ((W))))

533
/* Return the pixel width of window W.
534
   This includes scroll bars and fringes.  */
535
#define WINDOW_PIXEL_WIDTH(W) (W)->pixel_width
536

537 538 539 540 541 542 543 544
/* Return the pixel height of window W.
   This includes header and mode lines, if any.  */
#define WINDOW_PIXEL_HEIGHT(W) (W)->pixel_height

/* Return the width of window W in canonical column units.
   This includes scroll bars and fringes.
   This value is adjusted such that the sum of the widths of all child
   windows equals the width of their parent window.  */
545
#define WINDOW_TOTAL_COLS(W) (W)->total_cols
546

547
/* Return the height of window W in canonical line units.
548 549 550
   This includes header and mode lines, if any.
   This value is adjusted such that the sum of the heights of all child
   windows equals the height of their parent window.  */
551
#define WINDOW_TOTAL_LINES(W) (W)->total_lines
552

553 554
/* The smallest acceptable dimensions for a window.  Anything smaller
   might crash Emacs.  */
555 556 557 558
#define MIN_SAFE_WINDOW_WIDTH (2)

#define MIN_SAFE_WINDOW_PIXEL_WIDTH(W) \
  (2 * WINDOW_FRAME_COLUMN_WIDTH (W))
559 560

#define MIN_SAFE_WINDOW_HEIGHT (1)
561

562 563 564 565 566 567 568 569 570
#define MIN_SAFE_WINDOW_PIXEL_HEIGHT(W) \
  (WINDOW_FRAME_LINE_HEIGHT (W))

/* Width of right divider of window W.  */
#define WINDOW_RIGHT_DIVIDER_WIDTH(W)				\
  ((WINDOW_RIGHTMOST_P (W) || MINI_WINDOW_P (W))		\
   ? 0								\
   : FRAME_RIGHT_DIVIDER_WIDTH (WINDOW_XFRAME (W)))

571 572 573
/* Return the canonical frame column at which window W starts.
   This includes a left-hand scroll bar, if any.  */

574
#define WINDOW_LEFT_EDGE_COL(W) (W)->left_col
575 576

/* Return the canonical frame column before which window W ends.
577 578
   This includes a right-hand scroll bar, if any.  */

579 580
#define WINDOW_RIGHT_EDGE_COL(W) \
  (WINDOW_LEFT_EDGE_COL (W) + WINDOW_TOTAL_COLS (W))
581

582 583 584
/* Return the canonical frame line at which window W starts.
   This includes a header line, if any.  */

585
#define WINDOW_TOP_EDGE_LINE(W) (W)->top_line
586 587 588 589 590 591 592

/* Return the canonical frame line before which window W ends.
   This includes a mode line, if any.  */

#define WINDOW_BOTTOM_EDGE_LINE(W) \
  (WINDOW_TOP_EDGE_LINE (W) + WINDOW_TOTAL_LINES (W))

593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
/* Return the left pixel edge at which window W starts.
   This includes a left-hand scroll bar, if any.  */
#define WINDOW_LEFT_PIXEL_EDGE(W) (W)->pixel_left

/* Return the right pixel edge before which window W ends.
   This includes a right-hand scroll bar, if any.  */
#define WINDOW_RIGHT_PIXEL_EDGE(W) \
  (WINDOW_LEFT_PIXEL_EDGE (W) + WINDOW_PIXEL_WIDTH (W))

/* Return the top pixel edge at which window W starts.
   This includes a header line, if any.  */
#define WINDOW_TOP_PIXEL_EDGE(W) (W)->pixel_top

/* Return the bottom pixel edge before which window W ends.
   This includes a mode line, if any.  */
#define WINDOW_BOTTOM_PIXEL_EDGE(W) \
  (WINDOW_TOP_PIXEL_EDGE (W) + WINDOW_PIXEL_HEIGHT (W))
610 611 612 613 614 615

/* Return the frame x-position at which window W starts.
   This includes a left-hand scroll bar, if any.  */

#define WINDOW_LEFT_EDGE_X(W) \
  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
616
   + WINDOW_LEFT_PIXEL_EDGE (W))
617 618 619 620 621 622

/* Return the frame x- position before which window W ends.
   This includes a right-hand scroll bar, if any.  */

#define WINDOW_RIGHT_EDGE_X(W) \
  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
623
   + WINDOW_RIGHT_PIXEL_EDGE (W))
624

625
/* True if W is a menu bar window.  */
626

627
#if defined (HAVE_X_WINDOWS) && ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
628
#define WINDOW_MENU_BAR_P(W) \
629 630
  (WINDOWP (WINDOW_XFRAME (W)->menu_bar_window) \
   && (W) == XWINDOW (WINDOW_XFRAME (W)->menu_bar_window))
631 632
#else
/* No menu bar windows if X toolkit is in use.  */
633
#define WINDOW_MENU_BAR_P(W) false
634
#endif
635

636
/* True if W is a tool bar window.  */
637
#if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
638
#define WINDOW_TOOL_BAR_P(W) \
639 640
  (WINDOWP (WINDOW_XFRAME (W)->tool_bar_window) \
   && (W) == XWINDOW (WINDOW_XFRAME (W)->tool_bar_window))
641
#else
642
#define WINDOW_TOOL_BAR_P(W) false
643
#endif
644

645
/* Return the frame y-position at which window W starts.
646
   This includes a header line, if any.
647

648 649
   PXW: With a menu or tool bar this is not symmetric to the _X values
   since it _does_ include the internal border width.  */
650
#define WINDOW_TOP_EDGE_Y(W) \
651 652
  (((WINDOW_MENU_BAR_P (W) || WINDOW_TOOL_BAR_P (W)) \
    ? 0 : FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W))) \
653
   + WINDOW_TOP_PIXEL_EDGE (W))
654 655 656

/* Return the frame y-position before which window W ends.
   This includes a mode line, if any.  */
657 658
#define WINDOW_BOTTOM_EDGE_Y(W)				   \
  (((WINDOW_MENU_BAR_P (W) || WINDOW_TOOL_BAR_P (W))	   \
659
    ? 0 : FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W))) \
660
   + WINDOW_BOTTOM_PIXEL_EDGE (W))
661

662
/* True if window W takes up the full width of its frame.  */
663 664 665 666
#define WINDOW_FULL_WIDTH_P(W)					\
  (WINDOW_PIXEL_WIDTH (W)					\
   == (WINDOW_PIXEL_WIDTH					\
       (XWINDOW (FRAME_ROOT_WINDOW (WINDOW_XFRAME (W))))))	\
667

668
/* True if window W's has no other windows to its left in its frame.  */
669 670

#define WINDOW_LEFTMOST_P(W) \
671
  (WINDOW_LEFT_PIXEL_EDGE (W) == 0)
672

673 674 675 676
/* True if window W's has no other windows above in its frame.  */
#define WINDOW_TOPMOST_P(W) \
  (WINDOW_TOP_PIXEL_EDGE (W) == 0)

677
/* True if window W's has no other windows to its right in its frame.  */
678 679 680 681 682
#define WINDOW_RIGHTMOST_P(W)					\
  (WINDOW_RIGHT_PIXEL_EDGE (W)					\
   == (WINDOW_RIGHT_PIXEL_EDGE					\
       (XWINDOW (FRAME_ROOT_WINDOW (WINDOW_XFRAME (W))))))	\

683
/* True if window W's has no other windows below it in its frame
684 685 686 687 688
   (the minibuffer window is not counted in this respect).  */
#define WINDOW_BOTTOMMOST_P(W)					\
  (WINDOW_BOTTOM_PIXEL_EDGE (W)					\
   == (WINDOW_BOTTOM_PIXEL_EDGE					\
       (XWINDOW (FRAME_ROOT_WINDOW (WINDOW_XFRAME (W))))))	\
689 690 691 692 693 694 695 696

/* Return the frame column at which the text (or left fringe) in
   window W starts.  This is different from the `LEFT_EDGE' because it
   does not include a left-hand scroll bar if any.  */
#define WINDOW_BOX_LEFT_EDGE_COL(W) \
  (WINDOW_LEFT_EDGE_COL (W) \
   + WINDOW_LEFT_SCROLL_BAR_COLS (W))

697 698 699 700 701 702 703
/* Return the pixel value where the text (or left fringe) in
   window W starts.  This is different from the `LEFT_EDGE' because it
   does not include a left-hand scroll bar if any.  */
#define WINDOW_BOX_LEFT_PIXEL_EDGE(W)		\
  (WINDOW_LEFT_PIXEL_EDGE (W)			\
   + WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (W))

704 705 706 707 708 709 710
/* Return the window column before which the text in window W ends.
   This is different from WINDOW_RIGHT_EDGE_COL because it does not
   include a scroll bar or window-separating line on the right edge.  */
#define WINDOW_BOX_RIGHT_EDGE_COL(W) \
  (WINDOW_RIGHT_EDGE_COL (W) \
   - WINDOW_RIGHT_SCROLL_BAR_COLS (W))

711 712 713 714 715 716 717 718
/* Return the pixel value before which the text in window W ends.  This
   is different from the `RIGHT_EDGE' because it does not include a
   right-hand scroll bar or window-separating line on the right
   edge.  */
#define WINDOW_BOX_RIGHT_PIXEL_EDGE(W)		\
  (WINDOW_RIGHT_PIXEL_EDGE (W)			\
   - WINDOW_RIGHT_DIVIDER_WIDTH (W)		\
   - WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH (W))
719 720 721 722

/* Return the frame position at which the text (or left fringe) in
   window W starts.  This is different from the `LEFT_EDGE' because it
   does not include a left-hand scroll bar if any.  */
723
#define WINDOW_BOX_LEFT_EDGE_X(W)		   \
724
  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
725
   + WINDOW_BOX_LEFT_PIXEL_EDGE (W))
726 727 728 729

/* Return the window column before which the text in window W ends.
   This is different from WINDOW_RIGHT_EDGE_COL because it does not
   include a scroll bar or window-separating line on the right edge.  */
730
#define WINDOW_BOX_RIGHT_EDGE_X(W)		   \
731
  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
732
   + WINDOW_BOX_RIGHT_PIXEL_EDGE (W))
733

734
/* Widths of marginal areas in columns.  */
735
#define WINDOW_LEFT_MARGIN_COLS(W) (W->left_margin_cols)
736

737
#define WINDOW_RIGHT_MARGIN_COLS(W) (W->right_margin_cols)
738

739 740 741
#define WINDOW_MARGINS_COLS(W)			\
  (WINDOW_LEFT_MARGIN_COLS (W)			\
   + WINDOW_RIGHT_MARGIN_COLS (W))
742

743
/* Widths of marginal areas in pixels.  */
744 745
#define WINDOW_LEFT_MARGIN_WIDTH(W)			\
  (W->left_margin_cols * WINDOW_FRAME_COLUMN_WIDTH (W))
746

747
#define WINDOW_RIGHT_MARGIN_WIDTH(W)				\
748
  (W->right_margin_cols * WINDOW_FRAME_COLUMN_WIDTH (W))
749

750 751 752
#define WINDOW_MARGINS_WIDTH(W)			\
  (WINDOW_LEFT_MARGIN_WIDTH (W)			\
   + WINDOW_RIGHT_MARGIN_WIDTH (W))
753

754 755 756 757 758 759 760 761 762 763 764 765 766 767
/* Pixel-widths of fringes.  */
#define WINDOW_LEFT_FRINGE_WIDTH(W)			\
  (W->left_fringe_width >= 0				\
   ? W->left_fringe_width				\
   : FRAME_LEFT_FRINGE_WIDTH (WINDOW_XFRAME (W)))

#define WINDOW_RIGHT_FRINGE_WIDTH(W)			\
  (W->right_fringe_width >= 0				\
   ? W->right_fringe_width				\
   : FRAME_RIGHT_FRINGE_WIDTH (WINDOW_XFRAME (W)))

#define WINDOW_FRINGES_WIDTH(W)		\
  (WINDOW_LEFT_FRINGE_WIDTH (W) + WINDOW_RIGHT_FRINGE_WIDTH (W))

768 769
/* Are fringes outside display margins in window W.  */
#define WINDOW_HAS_FRINGES_OUTSIDE_MARGINS(W)	\
770
  ((W)->fringes_outside_margins)
771

772
/* Say whether vertical scroll bars are currently enabled for window W,
773
   and which side they are on.  */
774 775 776 777 778 779
#define WINDOW_VERTICAL_SCROLL_BAR_TYPE(W)		\
  (WINDOW_PSEUDO_P (W)					\
   ? vertical_scroll_bar_none				\
   : EQ (W->vertical_scroll_bar_type, Qt)		\
   ? FRAME_VERTICAL_SCROLL_BAR_TYPE (WINDOW_XFRAME (W))	\
   : EQ (W->vertical_scroll_bar_type, Qleft)		\
780
   ? vertical_scroll_bar_left				\
781
   : EQ (W->vertical_scroll_bar_type, Qright)		\
782
   ? vertical_scroll_bar_right				\
783 784 785 786 787 788 789 790 791 792 793 794
   : vertical_scroll_bar_none)

#define WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT(W)			\
  (WINDOW_VERTICAL_SCROLL_BAR_TYPE (W) == vertical_scroll_bar_left)

#define WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT(W)			\
  (WINDOW_VERTICAL_SCROLL_BAR_TYPE (W) == vertical_scroll_bar_right)

#define WINDOW_HAS_VERTICAL_SCROLL_BAR(W)		\
  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (W)		\
   || WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (W))

795
#if (defined (HAVE_WINDOW_SYSTEM)					\
796
     && ((defined (USE_TOOLKIT_SCROLL_BARS))	\
797
	 || defined (HAVE_NTGUI)))
798 799 800 801 802 803 804 805
# define USE_HORIZONTAL_SCROLL_BARS true
#else
# define USE_HORIZONTAL_SCROLL_BARS false
#endif

/* Say whether horizontal scroll bars are currently enabled for window
   W.  Horizontal scrollbars exist for toolkit versions only.  */
#if USE_HORIZONTAL_SCROLL_BARS
806 807 808 809 810 811 812 813 814 815 816
#define WINDOW_HAS_HORIZONTAL_SCROLL_BAR(W)			\
  ((WINDOW_PSEUDO_P (W) || MINI_NON_ONLY_WINDOW_P (W))		\
   ? false							\
   : EQ (W->horizontal_scroll_bar_type, Qt)			\
   ? FRAME_HAS_HORIZONTAL_SCROLL_BARS (WINDOW_XFRAME (W))	\
   : EQ (W->horizontal_scroll_bar_type, Qbottom)		\
   ? true							\
   : false)
#else
#define WINDOW_HAS_HORIZONTAL_SCROLL_BAR(W) false
#endif
817 818 819 820

/* Width that a scroll bar in window W should have, if there is one.
   Measured in pixels.  If scroll bars are turned off, this is still
   nonzero.  */
821 822 823 824
#define WINDOW_CONFIG_SCROLL_BAR_WIDTH(W)		\
  (W->scroll_bar_width >= 0				\
   ? W->scroll_bar_width				\
   : FRAME_CONFIG_SCROLL_BAR_WIDTH (WINDOW_XFRAME (W)))
825 826 827 828

/* Width that a scroll bar in window W should have, if there is one.
   Measured in columns (characters).  If scroll bars are turned off,
   this is still nonzero.  */
829 830 831 832 833 834
#define WINDOW_CONFIG_SCROLL_BAR_COLS(W)		\
  (W->scroll_bar_width >= 0				\
   ? ((W->scroll_bar_width				\
       + WINDOW_FRAME_COLUMN_WIDTH (W) - 1)		\
      / WINDOW_FRAME_COLUMN_WIDTH (W))			\
   : FRAME_CONFIG_SCROLL_BAR_COLS (WINDOW_XFRAME (W)))
835

836 837 838
/* Width of left scroll bar in window W, measured in columns
   (characters).  If scroll bars are on the right in this frame, or
   there are no scroll bars, value is 0.  */
839 840 841
#define WINDOW_LEFT_SCROLL_BAR_COLS(W)	       \
  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (W)  \
   ? (WINDOW_CONFIG_SCROLL_BAR_COLS (W))       \
842 843
   : 0)

844 845 846
/* Width of right scroll bar in window W, measured in columns
   (characters).  If scroll bars are on the left in this frame, or there
   are no scroll bars, value is 0.  */
847 848 849
#define WINDOW_RIGHT_SCROLL_BAR_COLS(W)		\
  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (W)	\
   ? WINDOW_CONFIG_SCROLL_BAR_COLS (W)		\
850 851
   : 0)

852
/* Width of a scroll bar in window W, measured in columns.  */
853 854 855
#define WINDOW_SCROLL_BAR_COLS(W)	       \
  (WINDOW_HAS_VERTICAL_SCROLL_BAR (W)	       \
   ? WINDOW_CONFIG_SCROLL_BAR_COLS (W)	       \
856 857
   : 0)

858
/* Width of a left scroll bar area in window W, measured in pixels.  */
859 860 861
#define WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH(W)				\
  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (W)				\
   ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (W)					\
862
   : 0)
863

864
/* Width of a right scroll bar area in window W, measured in pixels.  */
865 866 867
#define WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH(W)				\
  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (W)				\
   ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (W)					\
868 869
   : 0)

870
/* Width of scroll bar area in window W, measured in pixels.  */
871 872 873
#define WINDOW_SCROLL_BAR_AREA_WIDTH(W)					\
  (WINDOW_HAS_VERTICAL_SCROLL_BAR (W)					\
   ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (W)					\
874
   : 0)
875

876 877
/* Return the frame position where the vertical scroll bar of window W
   starts.  */
878 879 880 881 882
#define WINDOW_SCROLL_BAR_AREA_X(W)		\
  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (W)	\
   ? WINDOW_BOX_RIGHT_EDGE_X (W)		\
   : WINDOW_LEFT_EDGE_X (W))

883 884 885 886 887 888 889 890 891
/* Width of bottom divider of window W.  */
#define WINDOW_BOTTOM_DIVIDER_WIDTH(W)					\
  (((WINDOW_BOTTOMMOST_P (W)						\
     && NILP ((XWINDOW (FRAME_ROOT_WINDOW				\
			(WINDOW_XFRAME (W))))->next))			\
    || EQ ((W)->prev, FRAME_ROOT_WINDOW (WINDOW_XFRAME (W)))		\
    || (W)->pseudo_window_p)						\
   ? 0									\
   : FRAME_BOTTOM_DIVIDER_WIDTH (WINDOW_XFRAME (W)))
892

893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
/* Height that a scroll bar in window W should have, if there is one.
   Measured in pixels.  If scroll bars are turned off, this is still
   nonzero.  */
#define WINDOW_CONFIG_SCROLL_BAR_HEIGHT(W)			\
  (W->scroll_bar_height >= 0					\
   ? W->scroll_bar_height					\
   : FRAME_CONFIG_SCROLL_BAR_HEIGHT (WINDOW_XFRAME (W)))

/* Height that a scroll bar in window W should have, if there is one.
   Measured in lines (characters).  If scroll bars are turned off, this
   is still nonzero.  */
#define WINDOW_CONFIG_SCROLL_BAR_LINES(W)		\
  (W->scroll_bar_height >= 0				\
   ? ((W->scroll_bar_height				\
       + WINDOW_FRAME_LINE_HEIGHT (W) - 1)		\
      / WINDOW_FRAME_LINE_HEIGHT (W))			\
   : FRAME_CONFIG_SCROLL_BAR_LINES (WINDOW_XFRAME (W)))

/* Height of a scroll bar in window W, measured in columns.  */
#define WINDOW_SCROLL_BAR_LINES(W)	       \
  (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (W)	       \
   ? WINDOW_CONFIG_SCROLL_BAR_LINES (W)	       \
   : 0)

/* Height of scroll bar area in window W, measured in pixels.  */
#define WINDOW_SCROLL_BAR_AREA_HEIGHT(W)	\
  (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (W)		\
   ? WINDOW_CONFIG_SCROLL_BAR_HEIGHT (W)	\
   : 0)

923 924
/* Height in pixels, and in lines, of the mode line.
   May be zero if W doesn't have a mode line.  */
925 926 927 928 929
#define WINDOW_MODE_LINE_HEIGHT(W)	\
  (WINDOW_WANTS_MODELINE_P ((W))	\
   ? CURRENT_MODE_LINE_HEIGHT (W)	\
   : 0)

930
#define WINDOW_MODE_LINE_LINES(W)	\
Paul Eggert's avatar
Paul Eggert committed
931
  WINDOW_WANTS_MODELINE_P (W)
932 933 934

/* Height in pixels, and in lines, of the header line.
   Zero if W doesn't have a header line.  */
935
#define WINDOW_HEADER_LINE_HEIGHT(W)	\
936
  (WINDOW_WANTS_HEADER_LINE_P (W)	\
937 938 939
   ? CURRENT_HEADER_LINE_HEIGHT (W)	\
   : 0)

940
#define WINDOW_HEADER_LINE_LINES(W)	\
Paul Eggert's avatar
Paul Eggert committed
941
  WINDOW_WANTS_HEADER_LINE_P (W)
942

943 944
/* Pixel height of window W without mode line, bottom scroll bar and
   bottom divider.  */
945
#define WINDOW_BOX_HEIGHT_NO_MODE_LINE(W)	\
946
  (WINDOW_PIXEL_HEIGHT (W)			\
947
   - WINDOW_BOTTOM_DIVIDER_WIDTH (W)		\
948 949
   - WINDOW_SCROLL_BAR_AREA_HEIGHT (W)		\
   - WINDOW_MODE_LINE_HEIGHT (W))
950

951 952
/* Pixel height of window W without mode and header line and bottom
   divider.  */
953
#define WINDOW_BOX_TEXT_HEIGHT(W)	\
954 955
  (WINDOW_PIXEL_HEIGHT ((W))		\
   - WINDOW_BOTTOM_DIVIDER_WIDTH (W)	\
956