changeset 51208:86d74f5ea803

(struct window): Rename members left to left_col, top to top_line, height to total_lines, width to total_cols, left_margin_width to left_margin_cols, right_margin_width to right_margin_cols, orig_height to orig_total_lines, orig_top to orig_top_line. All uses changed. (struct window): New members left_fringe_width, right_fringe_width, fringes_outside_margins, scroll_bar_width, vertical_scroll_bar_type. (WINDOW_XFRAME, WINDOW_FRAME_COLUMN_WIDTH, WINDOW_FRAME_LINE_HEIGHT): New macros primarily used to simplify other macros. (WINDOW_TOTAL_COLS): New macro. Change relevant code that referred to XINT (w->width). (WINDOW_TOTAL_LINES): New macro. Change relevant code that referred to XINT (w->height). (WINDOW_TOTAL_WIDTH): New macro. Change relevant code that referred to XINT (w->width) * canon_x_unit. (WINDOW_TOTAL_HEIGHT): New macro. Change relevant code that referred to XINT (w->height) * canon_y_unit. (WINDOW_LEFT_EDGE_COL): New macro. Change relevant code that referred to XINT (w->left). (WINDOW_RIGHT_EDGE_COL): Renamed from WINDOW_RIGHT_EDGE. Change all uses and code that referred to XINT (w->left) + XINT (w->width). (WINDOW_TOP_EDGE_LINE): New macro. Change relevant code that referred to XINT (w->top). (WINDOW_BOTTOM_EDGE_LINE): New macro. Change relevant code that referred to XINT (w->top) + XINT (w->height). (WINDOW_LEFT_EDGE_X): New macro. Change relevant code that referred to XINT (w->left) * canon_x_unit. (WINDOW_RIGHT_EDGE_X): New macro. Change relevant code that referred to (XINT (w->left) + XINT (w->width)) * canon_x_unit. (WINDOW_TOP_EDGE_Y): New macro. Change relevant code that referred to XINT (w->top) * canon_y_unit. (WINDOW_BOTTOM_EDGE_Y): New macro. Change relevant code that referred to (XINT (w->top) + XINT (w->height)) * canon_y_unit. (WINDOW_LEFTMOST_P): New macro. (WINDOW_BOX_LEFT_EDGE_COL): Renamed from WINDOW_LEFT_MARGIN. All uses changed. (WINDOW_BOX_RIGHT_EDGE_COL): Renamed from WINDOW_RIGHT_MARGIN. All uses changed. (WINDOW_BOX_LEFT_EDGE_X): Renamed from WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X, moved from dispextern.h. Do not exclude left fringe width. (WINDOW_BOX_RIGHT_EDGE_X): Renamed from WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X, moved from dispextern.h. Do not exclude fringe widths. (WINDOW_LEFT_FRINGE_WIDTH, WINDOW_RIGHT_FRINGE_WIDTH) (WINDOW_FRINGE_COLS, WINDOW_TOTAL_FRINGE_WIDTH): New macros. Change relevant code that referred to FRAME_LEFT_FRINGE_WIDTH, FRAME_RIGHT_FRINGE_WIDTH, FRAME_FRINGE_COLS, and FRAME_TOTAL_FRINGE_WIDTH to allow per-window fringe settings. (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS): New macro. (WINDOW_VERTICAL_SCROLL_BAR_TYPE, WINDOW_HAS_VERTICAL_SCROLL_BAR) (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT) (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT) (WINDOW_CONFIG_SCROLL_BAR_WIDTH, WINDOW_CONFIG_SCROLL_BAR_COLS): New macros. Change code which referenced corresponding FRAME_VERTICAL_SCROLL_BAR_TYPE, FRAME_HAS_VERTICAL_SCROLL_BARS, FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT, FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT, FRAME_SCROLL_BAR_PIXEL_WIDTH, and FRAME_SCROLL_BAR_COLS macros to allow per-window scroll-bar settings. (WINDOW_LEFT_SCROLL_BAR_COLS, WINDOW_RIGHT_SCROLL_BAR_COLS): New macros. (WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH): New macro. Change code that referred to FRAME_LEFT_SCROLL_BAR_WIDTH. (WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH): New macro. Change code that referred to FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT and FRAME_SCROLL_BAR_WIDTH. (WINDOW_SCROLL_BAR_COLS, WINDOW_SCROLL_BAR_AREA_WIDTH) (WINDOW_SCROLL_BAR_AREA_X): New macros. (WINDOW_HEADER_LINE_HEIGHT): Renamed from WINDOW_DISPLAY_HEADER_LINE_HEIGHT, moved from dispextern.h. (WINDOW_BOX_HEIGHT_NO_MODE_LINE): Renamed from WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE, moved from dispextern.h. (WINDOW_BOX_TEXT_HEIGHT): Renamed from WINDOW_DISPLAY_PIXEL_WIDTH, moved from dispextern.h. (WINDOW_TO_FRAME_PIXEL_X, WINDOW_TO_FRAME_PIXEL_Y) (FRAME_TO_WINDOW_PIXEL_X, FRAME_TO_WINDOW_PIXEL_Y) (WINDOW_TEXT_TO_FRAME_PIXEL_X): Moved here from dispextern.h. (WINDOW_LEFT_MARGIN_WIDTH): Renamed from WINDOW_DISPLAY_LEFT_AREA_PIXEL_WIDTH, moved from dispextern.h. (WINDOW_RIGHT_MARGIN_WIDTH): Renamed from WINDOW_DISPLAY_RIGHT_AREA_PIXEL_WIDTH, moved from dispextern.h. (window_from_coordinates): Update prototype. (Fset_window_buffer): Update EXFUN. (set_window_buffer): Update prototype.
author Kim F. Storm <storm@cua.dk>
date Sat, 24 May 2003 22:08:20 +0000
parents 7e176ef34c10
children 880539128b51
files src/window.h
diffstat 1 files changed, 406 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/window.h	Sat May 24 22:07:51 2003 +0000
+++ b/src/window.h	Sat May 24 22:08:20 2003 +0000
@@ -24,6 +24,8 @@
 
 #include "dispextern.h"
 
+extern Lisp_Object Qleft, Qright;
+
 /* 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.
@@ -108,11 +110,11 @@
     Lisp_Object parent;
     /* The upper left corner coordinates of this window,
        as integers relative to upper left corner of frame = 0, 0 */
-    Lisp_Object left;
-    Lisp_Object top;
+    Lisp_Object left_col;
+    Lisp_Object top_line;
     /* The size of the window */
-    Lisp_Object height;
-    Lisp_Object width;
+    Lisp_Object total_lines;
+    Lisp_Object total_cols;
     /* The buffer displayed in this window */
     /* Of the fields vchild, hchild and buffer, only one is non-nil.  */
     Lisp_Object buffer;
@@ -160,8 +162,22 @@
 
     /* Width of left and right marginal areas.  A value of nil means
        no margin.  */
-    Lisp_Object left_margin_width;
-    Lisp_Object right_margin_width;
+    Lisp_Object left_margin_cols, right_margin_cols;
+
+    /* Width of left and right fringes.
+       A value of nil or t means use frame values.  */
+    Lisp_Object left_fringe_width, right_fringe_width;
+
+  /* Non-nil means fringes are drawn outside display margins;
+     othersize draw them between margin areas and text.  */
+    Lisp_Object fringes_outside_margins;
+
+    /* Pixel width of scroll bars.
+       A value of nil or t means use frame values.  */
+    Lisp_Object scroll_bar_width;
+    /* Type of vertical scroll bar.  A value of nil means
+       no scroll bar.  A value of t means use frame value.  */
+    Lisp_Object vertical_scroll_bar_type;
 
 /* The rest are currently not used or only half used */
     /* Frame coords of mark as of last time display completed */
@@ -211,7 +227,7 @@
 
     /* Original window height and top before mini-window was
        enlarged. */
-    Lisp_Object orig_height, orig_top;
+    Lisp_Object orig_total_lines, orig_top_line;
 
     /* No Lisp data may follow below this point without changing
        mark_object in alloc.c.  The member current_matrix must be the
@@ -281,40 +297,400 @@
 
 #define MINI_WINDOW_P(W)	(!NILP ((W)->mini_p))
 
-/* Return the window column at which the text in window W starts.
-   This is different from the `left' field because it does not include
-   a left-hand scroll bar if any.  */
+/* 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
+    
+*/
+
+
+/* A handy macro.  */
+
+#define WINDOW_XFRAME(W) \
+  (XFRAME (WINDOW_FRAME ((W))))
+
+/* Return the canonical column width of the frame of window W.  */
+
+#define WINDOW_FRAME_COLUMN_WIDTH(W) \
+  (FRAME_COLUMN_WIDTH (WINDOW_XFRAME ((W))))
 
-#define WINDOW_LEFT_MARGIN(W) \
-     (XFASTINT ((W)->left) \
-      + FRAME_LEFT_SCROLL_BAR_WIDTH (XFRAME (WINDOW_FRAME (W))))
+/* Return the canonical column width of the frame of window W.  */
+
+#define WINDOW_FRAME_LINE_HEIGHT(W) \
+  (FRAME_LINE_HEIGHT (WINDOW_XFRAME ((W))))
+
+
+/* Return the frame width in canonical column units.
+   This includes scroll bars and fringes.  */
+
+#define WINDOW_TOTAL_COLS(W) \
+  (XFASTINT ((W)->total_cols))
+
+/* Return the frame height in canonical line units.
+   This includes header and mode lines, if any.  */
+
+#define WINDOW_TOTAL_LINES(W) \
+  (XFASTINT ((W)->total_lines))
+
 
-/* Return the window column before which window W ends.
+/* Return the total pixel width of window W.  */
+
+#define WINDOW_TOTAL_WIDTH(W) \
+  (WINDOW_TOTAL_COLS (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
+
+/* Return the total pixel height of window W.  */
+
+#define WINDOW_TOTAL_HEIGHT(W) \
+  (WINDOW_TOTAL_LINES (W) * WINDOW_FRAME_LINE_HEIGHT (W))
+
+
+/* Return the canonical frame column at which window W starts.
+   This includes a left-hand scroll bar, if any.  */
+
+#define WINDOW_LEFT_EDGE_COL(W) \
+  (XFASTINT ((W)->left_col))
+
+/* Return the canonical frame column before which window W ends.
    This includes a right-hand scroll bar, if any.  */
 
-#define WINDOW_RIGHT_EDGE(W) \
-     (XFASTINT ((W)->left) + XFASTINT ((W)->width))
+#define WINDOW_RIGHT_EDGE_COL(W) \
+  (WINDOW_LEFT_EDGE_COL (W) + WINDOW_TOTAL_COLS (W))
+
+/* Return the canonical frame line at which window W starts.
+   This includes a header line, if any.  */
+
+#define WINDOW_TOP_EDGE_LINE(W) \
+  (XFASTINT ((W)->top_line))
+
+/* 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))
+
+
+/* Return the frame x-position at which window W starts.
+   This includes a left-hand scroll bar, if any.  */
 
-/* Return the window column before which the text in window W ends.
-   This is different from WINDOW_RIGHT_EDGE because it does not include
-   a scroll bar or window-separating line on the right edge.  */
+#define WINDOW_LEFT_EDGE_X(W) \
+  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
+   + WINDOW_LEFT_EDGE_COL (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
+
+/* 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)) \
+   + WINDOW_RIGHT_EDGE_COL (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
 
-#define WINDOW_RIGHT_MARGIN(W) \
-     (WINDOW_RIGHT_EDGE (W) \
-      - (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (XFRAME (WINDOW_FRAME (W))) \
-         ? FRAME_SCROLL_BAR_COLS (XFRAME (WINDOW_FRAME (W))) \
-         : 0))
+/* Return the frame y-position at which window W starts.
+   This includes a header line, if any.  */
+
+#define WINDOW_TOP_EDGE_Y(W) \
+  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
+   + WINDOW_TOP_EDGE_LINE (W) * WINDOW_FRAME_LINE_HEIGHT (W))
+
+/* Return the frame y-position before which window W ends.
+   This includes a mode line, if any.  */
+
+#define WINDOW_BOTTOM_EDGE_Y(W) \
+  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
+   + WINDOW_BOTTOM_EDGE_LINE (W) * WINDOW_FRAME_LINE_HEIGHT (W))
+
 
 /* 1 if window W takes up the full width of its frame.  */
 
 #define WINDOW_FULL_WIDTH_P(W) \
-     (XFASTINT ((W)->width) == FRAME_WINDOW_WIDTH (XFRAME (WINDOW_FRAME (W))))
+  (WINDOW_TOTAL_COLS (W) == FRAME_TOTAL_COLS (WINDOW_XFRAME (W)))
+
+/* 1 if window W's has no other windows to its left in its frame.  */
+
+#define WINDOW_LEFTMOST_P(W) \
+  (WINDOW_LEFT_EDGE_COL (W) == 0)
 
 /* 1 if window W's has no other windows to its right in its frame.  */
 
 #define WINDOW_RIGHTMOST_P(W) \
-     (WINDOW_RIGHT_EDGE (W) == FRAME_WINDOW_WIDTH (XFRAME (WINDOW_FRAME (W))))
+  (WINDOW_RIGHT_EDGE_COL (W) == FRAME_TOTAL_COLS (WINDOW_XFRAME (W)))
+
+
+/* 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))
+
+/* 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))
+
+
+/* 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.  */
+
+#define WINDOW_BOX_LEFT_EDGE_X(W) \
+  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
+   + WINDOW_BOX_LEFT_EDGE_COL (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
+
+/* 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_X(W) \
+  (FRAME_INTERNAL_BORDER_WIDTH (WINDOW_XFRAME (W)) \
+   + WINDOW_BOX_RIGHT_EDGE_COL (W) * WINDOW_FRAME_COLUMN_WIDTH (W))
+
+
+/* Width of left margin area in columns.  */
+
+#define WINDOW_LEFT_MARGIN_COLS(W)			\
+  (NILP ((W)->left_margin_cols)				\
+   ? 0							\
+   : XINT ((W)->left_margin_cols))
+
+/* Width of right marginal area in columns.  */
+
+#define WINDOW_RIGHT_MARGIN_COLS(W)			\
+  (NILP ((W)->right_margin_cols)			\
+   ? 0							\
+   : XINT ((W)->right_margin_cols))
+
+/* Width of left margin area in pixels.  */
+
+#define WINDOW_LEFT_MARGIN_WIDTH(W)			\
+  (NILP ((W)->left_margin_cols)				\
+   ? 0							\
+   : (XINT ((W)->left_margin_cols)			\
+      * WINDOW_FRAME_COLUMN_WIDTH (W)))
+
+/* Width of right marginal area in pixels.  */
+
+#define WINDOW_RIGHT_MARGIN_WIDTH(W)			\
+  (NILP ((W)->right_margin_cols)			\
+   ? 0							\
+   : (XINT ((W)->right_margin_cols)			\
+      * WINDOW_FRAME_COLUMN_WIDTH (W)))
+
+/* Total width of fringes reserved for drawing truncation bitmaps,
+   continuation bitmaps and alike.  The width is in canonical char
+   units of the frame.  This must currently be the case because window
+   sizes aren't pixel values.  If it weren't the case, we wouldn't be
+   able to split windows horizontally nicely.  */
+
+#define WINDOW_FRINGE_COLS(W)				\
+  ((INTEGERP ((W)->left_fringe_width)			\
+    || INTEGERP ((W)->right_fringe_width))		\
+   ? ((WINDOW_LEFT_FRINGE_WIDTH (W)			\
+       + WINDOW_RIGHT_FRINGE_WIDTH (W)			\
+       + WINDOW_FRAME_COLUMN_WIDTH (W) - 1)		\
+      / WINDOW_FRAME_COLUMN_WIDTH (W))			\
+   : FRAME_FRINGE_COLS (WINDOW_XFRAME (W)))
+
+/* Pixel-width of the left and right fringe.  */
+
+#define WINDOW_LEFT_FRINGE_WIDTH(W)			\
+  (INTEGERP ((W)->left_fringe_width)			\
+   ? XFASTINT ((W)->left_fringe_width)			\
+   : FRAME_LEFT_FRINGE_WIDTH (WINDOW_XFRAME (W)))
+
+#define WINDOW_RIGHT_FRINGE_WIDTH(W)			\
+  (INTEGERP ((W)->right_fringe_width)			\
+   ? XFASTINT ((W)->right_fringe_width)			\
+   : FRAME_RIGHT_FRINGE_WIDTH (WINDOW_XFRAME (W)))
+
+/* Total width of fringes in pixels.  */
+
+#define WINDOW_TOTAL_FRINGE_WIDTH(W)		\
+  (WINDOW_LEFT_FRINGE_WIDTH (W) + WINDOW_RIGHT_FRINGE_WIDTH (W))
+
+/* Are fringes outside display margins in window W.  */
+
+#define WINDOW_HAS_FRINGES_OUTSIDE_MARGINS(W)	\
+  (!NILP ((W)->fringes_outside_margins))
+
+/* Say whether scroll bars are currently enabled for window W,
+   and which side they are on.  */
+
+#define WINDOW_VERTICAL_SCROLL_BAR_TYPE(w)		\
+  (EQ ((w)->vertical_scroll_bar_type, Qt)		\
+   ? FRAME_VERTICAL_SCROLL_BAR_TYPE (WINDOW_XFRAME (w))	\
+   : EQ ((w)->vertical_scroll_bar_type, Qleft)		\
+   ? vertical_scroll_bar_left				\
+   : EQ ((w)->vertical_scroll_bar_type, Qright)		\
+   ? vertical_scroll_bar_right				\
+   : vertical_scroll_bar_none)				\
+
+#define WINDOW_HAS_VERTICAL_SCROLL_BAR(w)		\
+  (EQ ((w)->vertical_scroll_bar_type, Qt)		\
+   ? FRAME_HAS_VERTICAL_SCROLL_BARS (WINDOW_XFRAME (w))	\
+   : !NILP ((w)->vertical_scroll_bar_type))
+
+#define WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT(w)		\
+  (EQ ((w)->vertical_scroll_bar_type, Qt)			\
+   ? FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (WINDOW_XFRAME (w))	\
+   : EQ ((w)->vertical_scroll_bar_type, Qleft))
+
+#define WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT(w)		\
+  (EQ ((w)->vertical_scroll_bar_type, Qt)			\
+   ? FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (WINDOW_XFRAME (w))\
+   : EQ ((w)->vertical_scroll_bar_type, Qright))
 
+/* 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.  */
+
+#define WINDOW_CONFIG_SCROLL_BAR_WIDTH(w)		\
+  (INTEGERP ((w)->scroll_bar_width)			\
+   ? XFASTINT ((w)->scroll_bar_width)			\
+   : FRAME_CONFIG_SCROLL_BAR_WIDTH (WINDOW_XFRAME (w)))
+
+/* 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.  */
+
+#define WINDOW_CONFIG_SCROLL_BAR_COLS(w)		\
+  (INTEGERP ((w)->scroll_bar_width)			\
+   ? ((XFASTINT ((w)->scroll_bar_width)			\
+       + WINDOW_FRAME_COLUMN_WIDTH (w) - 1)		\
+      / WINDOW_FRAME_COLUMN_WIDTH (w))			\
+   : FRAME_CONFIG_SCROLL_BAR_COLS (WINDOW_XFRAME (w)))
+
+/* Width of a scroll bar in window W, measured in columns (characters),
+   but only if scroll bars are on the left.  If scroll bars are on
+   the right in this frame, or there are no scroll bars, value is 0.  */
+
+#define WINDOW_LEFT_SCROLL_BAR_COLS(w)	       \
+  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) \
+   ? (WINDOW_CONFIG_SCROLL_BAR_COLS (w))       \
+   : 0)
+
+/* Width of a left scroll bar area in window W , measured in pixels.  */
+
+#define WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH(w) \
+  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) \
+   ? (WINDOW_CONFIG_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w)) \
+   : 0)
+
+/* Width of a scroll bar in window W, measured in columns (characters),
+   but only if scroll bars are on the right.  If scroll bars are on
+   the left in this frame, or there are no scroll bars, value is 0.  */
+
+#define WINDOW_RIGHT_SCROLL_BAR_COLS(w)		\
+  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w) \
+   ? WINDOW_CONFIG_SCROLL_BAR_COLS (w)		\
+   : 0)
+
+/* Width of a left scroll bar area in window W , measured in pixels.  */
+
+#define WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH(w)				 \
+  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w)				 \
+   ? (WINDOW_CONFIG_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w)) \
+   : 0)
+
+
+/* Actual width of a scroll bar in window W, measured in columns.  */
+
+#define WINDOW_SCROLL_BAR_COLS(w)	       \
+  (WINDOW_HAS_VERTICAL_SCROLL_BAR (w)	       \
+   ? WINDOW_CONFIG_SCROLL_BAR_COLS (w)	       \
+   : 0)
+
+/* Width of a left scroll bar area in window W , measured in pixels.  */
+
+#define WINDOW_SCROLL_BAR_AREA_WIDTH(w)					 \
+  (WINDOW_HAS_VERTICAL_SCROLL_BAR (w)					\
+   ? (WINDOW_CONFIG_SCROLL_BAR_COLS (w) * WINDOW_FRAME_COLUMN_WIDTH (w)) \
+   : 0)
+
+
+/* Return the frame position where the scroll bar of window W starts.  */
+
+#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))
+
+
+/* Height in pixels of the mode line.  May be zero if W doesn't have a
+   mode line.  */
+
+#define WINDOW_MODE_LINE_HEIGHT(W)	\
+  (WINDOW_WANTS_MODELINE_P ((W))	\
+   ? CURRENT_MODE_LINE_HEIGHT (W)	\
+   : 0)
+
+/* Height in pixels of the header line.  Zero if W doesn't have a header
+   line.  */
+
+#define WINDOW_HEADER_LINE_HEIGHT(W)	\
+  (WINDOW_WANTS_HEADER_LINE_P ((W))	\
+   ? CURRENT_HEADER_LINE_HEIGHT (W)	\
+   : 0)
+
+/* Pixel height of window W without mode line.  */
+
+#define WINDOW_BOX_HEIGHT_NO_MODE_LINE(W)	\
+  (WINDOW_TOTAL_HEIGHT ((W))			\
+   - WINDOW_MODE_LINE_HEIGHT ((W)))
+
+/* Pixel height of window W without mode and header line.  */
+
+#define WINDOW_BOX_TEXT_HEIGHT(W)		\
+  (WINDOW_TOTAL_HEIGHT ((W))			\
+   - WINDOW_MODE_LINE_HEIGHT ((W))		\
+   - WINDOW_HEADER_LINE_HEIGHT ((W)))
+
+
+/* Convert window W relative pixel X to frame pixel coordinates.  */
+
+#define WINDOW_TO_FRAME_PIXEL_X(W, X)		\
+  ((X) + WINDOW_BOX_LEFT_EDGE_X ((W)))
+
+/* Convert window W relative pixel Y to frame pixel coordinates.  */
+
+#define WINDOW_TO_FRAME_PIXEL_Y(W, Y)		\
+  ((Y) + WINDOW_TOP_EDGE_Y ((W)))
+
+/* Convert frame relative pixel X to window relative pixel X.  */
+
+#define FRAME_TO_WINDOW_PIXEL_X(W, X)		\
+  ((X) - WINDOW_BOX_LEFT_EDGE_X ((W)))
+
+/* Convert frame relative pixel Y to window relative pixel Y.  */
+
+#define FRAME_TO_WINDOW_PIXEL_Y(W, Y)		\
+  ((Y) - WINDOW_TOP_EDGE_Y ((W)))
+
+/* Convert a text area relative x-position in window W to frame X
+   pixel coordinates.  */
+
+#define WINDOW_TEXT_TO_FRAME_PIXEL_X(W, X)		\
+  (window_box_left ((W), TEXT_AREA) + (X))
 
 /* This is the window in which the terminal's cursor should
    be left when nothing is being done with it.  This must
@@ -368,7 +744,7 @@
 EXFUN (Fnext_window, 3);
 EXFUN (Fselect_window, 2);
 EXFUN (Fdisplay_buffer, 3);
-EXFUN (Fset_window_buffer, 2);
+EXFUN (Fset_window_buffer, 3);
 EXFUN (Fset_window_hscroll, 2);
 EXFUN (Fwindow_hscroll, 1);
 EXFUN (Fset_window_vscroll, 2);
@@ -379,7 +755,8 @@
 extern Lisp_Object make_window P_ ((void));
 extern void delete_window P_ ((Lisp_Object));
 extern Lisp_Object window_from_coordinates P_ ((struct frame *, int, int,
-						enum window_part *, int));
+						enum window_part *,
+						int *, int*, int));
 EXFUN (Fwindow_dedicated_p, 1);
 extern int window_height P_ ((Lisp_Object));
 extern int window_width P_ ((Lisp_Object));
@@ -400,7 +777,7 @@
    it's not allowed.  */
 
 void set_window_buffer P_ ((Lisp_Object window, Lisp_Object buffer,
-			    int run_hooks_p));
+			    int run_hooks_p, int keep_margins_p));
 
 /* Prompt to display in front of the minibuffer contents.  */