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