Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / src / ui / window.h
1 /* Window definitions for XEmacs.
2    Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995
3    Free Software Foundation, Inc.
4    Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
5    Copyright (C) 1995, 1996 Ben Wing.
6    Copyright (C) 1996 Chuck Thompson.
7
8 This file is part of SXEmacs
9
10 SXEmacs is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 SXEmacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
22
23
24 /* Synched up with: FSF 19.30. */
25
26 #ifndef INCLUDED_window_h_
27 #define INCLUDED_window_h_
28
29 #include "redisplay.h"
30 #ifdef HAVE_SCROLLBARS
31 #include "scrollbar.h"
32 #endif
33
34 /* All windows in use are arranged into a tree, with pointers up and down.
35
36 Windows that are leaves of the tree are actually displayed
37 and show the contents of buffers.  Windows that are not leaves
38 are used for representing the way groups of leaf windows are
39 arranged on the frame.  Leaf windows never become non-leaves.
40 They are deleted only by calling delete-window on them (but
41 this can be done implicitly).  Combination windows can be created
42 and deleted at any time.
43
44 A leaf window has a non-nil buffer field, and also
45  has markers in its start and pointm fields.  Non-leaf windows
46  have nil in these fields.
47
48 Non-leaf windows are either vertical or horizontal combinations.
49
50 A vertical combination window has children that are arranged on the frame
51 one above the next.  Its vchild field points to the uppermost child.
52 The parent field of each of the children points to the vertical
53 combination window.  The next field of each child points to the
54 child below it, or is nil for the lowest child.  The prev field
55 of each child points to the child above it, or is nil for the
56 highest child.
57
58 A horizontal combination window has children that are side by side.
59 Its hchild field points to the leftmost child.  In each child
60 the next field points to the child to the right and the prev field
61 points to the child to the left.
62
63 The children of a vertical combination window may be leaf windows
64 or horizontal combination windows.  The children of a horizontal
65 combination window may be leaf windows or vertical combination windows.
66
67 At the top of the tree are two windows which have nil as parent.
68 The second of these is minibuf_window.  The first one manages all
69 the frame area that is not minibuffer, and is called the root window.
70 Different windows can be the root at different times;
71 initially the root window is a leaf window, but if more windows
72 are created then that leaf window ceases to be root and a newly
73 made combination window becomes root instead.
74
75 In any case, on screens which have an ordinary window and a
76 minibuffer, prev of the minibuf window is the root window and next of
77 the root window is the minibuf window.  On minibufferless screens or
78 minibuffer-only screens, the root window and the minibuffer window are
79 one and the same, so its prev and next members are nil.
80
81 A dead window has the `dead' flag set on it.  Note that unlike other
82 dead objects, dead windows can be made live again through restoring a
83 window configuration.  This means that the values in a dead window
84 need to be preserved, except for those that are reconstructed by from
85 the window configuration. */
86
87 struct window {
88         struct lcrecord_header header;
89
90         /* The frame this window is on.  */
91         Lisp_Object frame;
92         /* t if this window is a minibuffer window.  */
93         Lisp_Object mini_p;
94         /* Following child (to right or down) at same level of tree */
95         Lisp_Object next;
96         /* Preceding child (to left or up) at same level of tree */
97         Lisp_Object prev;
98         /* First child of this window. */
99         /* vchild is used if this is a vertical combination,
100            hchild if this is a horizontal combination. */
101         Lisp_Object hchild, vchild;
102         /* The window this one is a child of. */
103         Lisp_Object parent;
104
105         /* The upper left corner coordinates of this window,
106            as integers (pixels) relative to upper left corner of frame = 0, 0 */
107         int pixel_left;
108         int pixel_top;
109         /* The size of the window (in pixels) */
110         int pixel_height;
111         int pixel_width;
112
113         /* The buffer displayed in this window */
114         /* Of the fields vchild, hchild and buffer, only one is non-nil.  */
115         Lisp_Object buffer;
116         /* A marker pointing to where in the text to start displaying */
117         /* need one for each set of display structures */
118         Lisp_Object start[3];
119         /* A marker pointing to where in the text point is in this window,
120            used only when the window is not selected.
121            This exists so that when multiple windows show one buffer
122            each one can have its own value of point.  */
123         /* need one for each set of display structures */
124         Lisp_Object pointm[3];
125         /* A marker pointing to where in the text the scrollbar is pointing */
126         Lisp_Object sb_point;
127         /* Number of columns display within the window is scrolled to the left. */
128         int hscroll;
129         /* Idem for the window's modeline */
130         Charcount modeline_hscroll;
131         /* Amount to clip off the top line for pixel-based scrolling. Point
132            will remain constant but this will be incremented to
133            incrementally shift lines up. */
134         int top_yoffset;
135         /* Amount to clip off the left of the lines for pixel-based
136            scrolling. Hscroll will remain constant but this will be
137            incremented to incrementally shift lines left. */
138         int left_xoffset;
139         /* Number saying how recently window was selected */
140         Lisp_Object use_time;
141         /* text.modified of displayed buffer as of last time display completed */
142         Lisp_Object last_modified[3];
143         /* Value of point at that time */
144         Lisp_Object last_point[3];
145         /* Value of start at that time */
146         Lisp_Object last_start[3];
147         /* buf.face_change as of last time display completed */
148         Lisp_Object last_facechange[3];
149
150         /* face cache elements correct for this window and its current buffer */
151         face_cachel_dynarr *face_cachels;
152         /* glyph cache elements correct for this window and its current buffer */
153         glyph_cachel_dynarr *glyph_cachels;
154         /* we cannot have a per-device cache of widgets / subwindows because
155            each visible instance needs to be a separate instance. The lowest
156            level of granularity we can get easily is the window that the
157            subwindow is in. This will fail if we attach the same subwindow
158            twice to a buffer. However, we are quite unlikely to do this,
159            especially with buttons which will need individual callbacks. The
160            proper solution is probably not worth the effort. */
161         Lisp_Object subwindow_instance_cache;
162         /* List of starting positions for display lines.  Only valid if
163            buffer has not changed. */
164         line_start_cache_dynarr *line_start_cache;
165         Lisp_Object line_cache_last_updated;
166         int line_cache_validation_override;
167
168         /* Length of longest line currently displayed.  Used to control the
169            width of the horizontal scrollbars. */
170         int max_line_len;
171
172         /* Frame coords of point at that time */
173         int last_point_x[3];
174         int last_point_y[3];
175
176         /* Number of characters in buffer past bottom of window,
177            as of last redisplay that finished. */
178         /* need one for each set of display structures */
179         int window_end_pos[3];
180
181         /* If redisplay in this window goes beyond this buffer position,
182            must run the redisplay-end-trigger-functions.  */
183         Lisp_Object redisplay_end_trigger;
184
185         /* Set by the extent code when extents in the gutter are changed. */
186         int gutter_extent_modiff[4];
187
188         /* Set by redisplay to the last position seen.  This is used
189            to implement the redisplay-end-trigger-functions. */
190         Bufpos last_redisplay_pos;
191
192 #define WINDOW_SLOT_DECLARATION
193 #define WINDOW_SLOT(slot, compare) Lisp_Object slot
194 #include "winslots.h"
195
196         /* one-bit flags: */
197
198         /* marker used when restoring a window configuration */
199         unsigned int config_mark:1;
200         /* Non-zero means window was dead. */
201         unsigned int dead:1;
202         /* Non-zero means next redisplay must use the value of start
203            set up for it in advance.  Set by scrolling commands.  */
204         unsigned int force_start:1;
205         /* Non-zero means must regenerate modeline of this window */
206         unsigned int redo_modeline:1;
207         /* Non-zero means current value of `start'
208            was the beginning of a line when it was chosen.  */
209         unsigned int start_at_line_beg:1;
210         /* new redisplay flag */
211         unsigned int windows_changed:1;
212         unsigned int shadow_thickness_changed:1;
213         /* Vertical divider flag and validity of it */
214         unsigned int need_vertical_divider_p:1;
215         unsigned int need_vertical_divider_valid_p:1;
216 };
217
218 #define CURRENT_DISP    0
219 #define DESIRED_DISP    1
220 #define CMOTION_DISP    2
221
222 struct window_mirror {
223         /* Frame this mirror is on. */
224         struct frame *frame;
225
226         /* Following child (to right or down) at same level of tree */
227         struct window_mirror *next;
228
229         /* There is no prev field because we never traverse this structure
230            backwards.  Same goes for the parent field. */
231
232         /* First child of this window. */
233         /* vchild is used if this is a vertical combination,
234            hchild if this is a horizontal combination. */
235         struct window_mirror *hchild, *vchild;
236
237         /* Dynamic array of display lines */
238         display_line_dynarr *current_display_lines;
239         display_line_dynarr *desired_display_lines;
240
241         /* Buffer current_display_lines represent. */
242         struct buffer *buffer;
243
244 #ifdef HAVE_SCROLLBARS
245         /* Scrollbars associated with window, if any. */
246         struct scrollbar_instance *scrollbar_vertical_instance;
247         struct scrollbar_instance *scrollbar_horizontal_instance;
248 #endif                          /* HAVE_SCROLLBARS */
249
250         /* Flag indicating whether a subwindow is currently being displayed. */
251         unsigned int subwindows_being_displayed:1;
252
253         /* Keep track of the truncation status in this window so we can
254            detect when it has changed.  #### Magic variables would be a huge
255            win here. */
256         unsigned int truncate_win:1;
257 };
258
259 #ifdef emacs                    /* some things other than emacs want the structs */
260
261 DECLARE_LRECORD(window, struct window);
262 #define XWINDOW(x) XRECORD (x, window, struct window)
263 #define XSETWINDOW(x, p) XSETRECORD (x, p, window)
264 #define WINDOWP(x) RECORDP (x, window)
265 #define CHECK_WINDOW(x) CHECK_RECORD (x, window)
266 #define CONCHECK_WINDOW(x) CONCHECK_RECORD (x, window)
267
268 #define WINDOW_LIVE_P(x) (!(x)->dead)
269 #define CHECK_LIVE_WINDOW(x) do {                       \
270   CHECK_WINDOW (x);                                     \
271   if (!WINDOW_LIVE_P (XWINDOW (x)))                     \
272     dead_wrong_type_argument (Qwindow_live_p, (x));     \
273 } while (0)
274 #define CONCHECK_LIVE_WINDOW(x) do {                    \
275   CONCHECK_WINDOW (x);                                  \
276   if (!WINDOW_LIVE_P (XWINDOW (x)))                     \
277     x = wrong_type_argument (Qwindow_live_p, (x));      \
278 } while (0)
279
280 /* 1 if W is a minibuffer window.  */
281 #define MINI_WINDOW_P(W)  (!NILP ((W)->mini_p))
282
283 /* 1 if we are dealing with a parentless window (this includes the
284    root window on a frame and the minibuffer window; both of these
285    are siblings). */
286 #define TOP_LEVEL_WINDOW_P(w) NILP ((w)->parent)
287
288 /* Set all redisplay flags indicating a window has changed */
289 #define MARK_WINDOWS_CHANGED(w) do {                    \
290   (w)->windows_changed = 1;                             \
291   if (!NILP (w->frame))                                 \
292     {                                                   \
293       struct frame *mwc_frame = XFRAME (w->frame);      \
294       MARK_FRAME_WINDOWS_CHANGED (mwc_frame);           \
295     }                                                   \
296   else                                                  \
297     windows_changed = 1;                                \
298 } while (0)
299
300 /* #### This should be fixed not to call MARK_FRAME_CHANGED because
301    faces are cached per window.  Also, other code which changes window's
302    face should use this macro.
303 */
304 #define MARK_WINDOW_FACES_CHANGED(w)    \
305   MARK_FRAME_FACES_CHANGED (XFRAME ((w)->frame))
306
307 #define WINDOW_TTY_P(w) FRAME_TTY_P (XFRAME ((w)->frame))
308 #define WINDOW_X_P(w)   FRAME_X_P   (XFRAME ((w)->frame))
309 #define WINDOW_NS_P(w)  FRAME_NS_P  (XFRAME ((w)->frame))
310 #define WINDOW_WIN_P(w) FRAME_WIN_P (XFRAME ((w)->frame))
311
312 DECLARE_LRECORD(window_configuration, struct window_config);
313
314 EXFUN(Fget_buffer_window, 3);
315 EXFUN(Fmove_to_window_line, 2);
316 EXFUN(Frecenter, 2);
317 EXFUN(Freplace_buffer_in_windows, 3);
318 EXFUN(Fselect_window, 2);
319 EXFUN(Fselected_window, 1);
320 EXFUN(Fset_window_buffer, 3);
321 EXFUN(Fset_window_hscroll, 2);
322 EXFUN(Fset_window_point, 2);
323 EXFUN(Fset_window_start, 3);
324 EXFUN(Fwindow_buffer, 1);
325 EXFUN(Fwindow_highest_p, 1);
326 EXFUN(Fwindow_point, 1);
327 EXFUN(Fwindow_start, 1);
328
329 /* The minibuffer window of the selected frame.
330    Note that you cannot test for minibufferness of an arbitrary window
331    by comparing against this; but you can test for minibufferness of
332    the selected window or of any window that is displayed.  */
333 extern Lisp_Object minibuf_window;
334
335 /* Prompt to display in front of the minibuffer contents, or nil */
336 extern Lisp_Object Vminibuf_prompt;
337 /* Prompt to display in front of the minibuffer prompt, or nil */
338 extern Lisp_Object Vminibuf_preprompt;
339
340 Lisp_Object allocate_window(void);
341 int window_char_width(struct window *, int include_margins_p);
342 int window_char_height(struct window *, int include_gutters_p);
343 int window_displayed_height(struct window *);
344 int window_is_leftmost(struct window *w);
345 int window_is_rightmost(struct window *w);
346 int window_is_lowest(struct window *w);
347 int window_is_highest(struct window *w);
348 int window_truncation_on(struct window *w);
349 int window_needs_vertical_divider(struct window *);
350 int window_scrollbar_width(struct window *w);
351 int window_scrollbar_height(struct window *w);
352 int window_modeline_height(struct window *w);
353 int window_left_margin_width(struct window *w);
354 int window_right_margin_width(struct window *w);
355 int window_top_gutter_height(struct window *w);
356 int window_bottom_gutter_height(struct window *w);
357 int window_left_gutter_width(struct window *w, int modeline);
358 int window_right_gutter_width(struct window *w, int modeline);
359
360 void delete_all_subwindows(struct window *w);
361 void undedicate_windows(Lisp_Object buffer, Lisp_Object frame);
362 void set_window_pixheight(Lisp_Object window, int pixheight, int nodelete);
363 void set_window_pixwidth(Lisp_Object window, int pixwidth, int nodelete);
364 void window_scroll(Lisp_Object window, Lisp_Object n, int direction,
365                    Error_behavior errb);
366 int buffer_window_count(struct buffer *b, struct frame *f);
367 int buffer_window_mru(struct window *w);
368 void check_frame_size(struct frame *frame, int *rows, int *cols);
369 int frame_pixsize_valid_p(struct frame *frame, int width, int height);
370 int frame_size_valid_p(struct frame *frame, int rows, int cols);
371 struct window *decode_window(Lisp_Object window);
372 struct window *find_window_by_pixel_pos(int pix_x, int pix_y, Lisp_Object win);
373
374 /* new functions to handle the window mirror */
375 void free_window_mirror(struct window_mirror *mir);
376 Lisp_Object real_window(struct window_mirror *mir, int no_abort);
377 struct window_mirror *find_window_mirror(struct window *w);
378 display_line_dynarr *window_display_lines(struct window *w, int);
379 struct buffer *window_display_buffer(struct window *w);
380 void set_window_display_buffer(struct window *w, struct buffer *b);
381 void update_frame_window_mirror(struct frame *f);
382
383 int map_windows(struct frame *f,
384                 int (*mapfun) (struct window * w, void *closure),
385                 void *closure);
386 void some_window_value_changed(Lisp_Object specifier, struct window *w,
387                                Lisp_Object oldval);
388 int invalidate_vertical_divider_cache_in_window(struct window *w,
389                                                 void *u_n_u_s_e_d);
390 int window_divider_width(struct window *w);
391
392 #define WINDOW_FRAME(w) ((w)->frame)
393 #define WINDOW_XFRAME(w) XFRAME (WINDOW_FRAME (w))
394 #define WINDOW_BUFFER(w) ((w)->buffer)
395 #define WINDOW_XBUFFER(w) XBUFFER (WINDOW_BUFFER (w))
396 #define WINDOW_DEVICE(w) FRAME_DEVICE (XFRAME (WINDOW_FRAME (w)))
397 #define WINDOW_XDEVICE(w) XDEVICE (WINDOW_DEVICE (w))
398 #define WINDOW_CONSOLE(w) DEVICE_CONSOLE (XDEVICE (WINDOW_DEVICE (w)))
399 #define WINDOW_XCONSOLE(w) XCONSOLE (WINDOW_CONSOLE (w))
400
401 /* XEmacs window size and positioning macros. */
402 #define WINDOW_TOP(w) ((w)->pixel_top)
403 #define WINDOW_TEXT_TOP(w) (WINDOW_TOP (w) + window_top_gutter_height (w))
404 #define WINDOW_TEXT_TOP_CLIP(w) ((w)->top_yoffset)
405 #define WINDOW_BOTTOM(w) ((w)->pixel_top + (w)->pixel_height)
406 #define WINDOW_TEXT_BOTTOM(w) (WINDOW_BOTTOM (w) - window_bottom_gutter_height (w))
407 #define WINDOW_LEFT(w) ((w)->pixel_left)
408 #define WINDOW_TEXT_LEFT(w) (WINDOW_LEFT (w) + window_left_gutter_width (w, 0))
409 #define WINDOW_MODELINE_LEFT(w) \
410   (WINDOW_LEFT (w) + window_left_gutter_width (w, 1))
411 #define WINDOW_RIGHT(w) ((w)->pixel_left + (w)->pixel_width)
412 #define WINDOW_TEXT_RIGHT(w)    \
413   (WINDOW_RIGHT (w) - window_right_gutter_width (w, 0))
414 #define WINDOW_MODELINE_RIGHT(w)        \
415   (WINDOW_RIGHT (w) - window_right_gutter_width (w, 1))
416
417 #define WINDOW_HEIGHT(w) ((w)->pixel_height)
418 #define WINDOW_TEXT_HEIGHT(w) (WINDOW_TEXT_BOTTOM (w) - WINDOW_TEXT_TOP (w))
419 #define WINDOW_WIDTH(w) ((w)->pixel_width)
420 #define WINDOW_TEXT_WIDTH(w) (WINDOW_TEXT_RIGHT (w) - WINDOW_TEXT_LEFT (w))
421
422 #define WINDOW_HAS_MODELINE_P(w) (!NILP (w->has_modeline_p))
423
424 #define MODELINE_OFF_SHADOW_THICKNESS_ADJUSTED(win)             \
425  abs ((!WINDOW_HAS_MODELINE_P (win)                             \
426        ? ((XINT (win->modeline_shadow_thickness) > 1)           \
427           ? XINT (win->modeline_shadow_thickness) - 1           \
428           : ((XINT (win->modeline_shadow_thickness) < -1)       \
429              ? XINT (win->modeline_shadow_thickness) + 1        \
430              : XINT (win->modeline_shadow_thickness)))          \
431        : XINT (win->modeline_shadow_thickness)))
432
433 #define MODELINE_SHADOW_THICKNESS(win)                          \
434  (MODELINE_OFF_SHADOW_THICKNESS_ADJUSTED (win) > 10             \
435   ? 10                                                          \
436   : MODELINE_OFF_SHADOW_THICKNESS_ADJUSTED (win))
437
438 #endif                          /* emacs */
439
440 #endif                          /* INCLUDED_window_h_ */