+ (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)))
+
+/* Column-width of the left and right fringe. */
+
+#define WINDOW_LEFT_FRINGE_COLS(W) \
+ ((WINDOW_LEFT_FRINGE_WIDTH ((W)) \
+ + WINDOW_FRAME_COLUMN_WIDTH (W) - 1) \
+ / WINDOW_FRAME_COLUMN_WIDTH (W))
+
+#define WINDOW_RIGHT_FRINGE_COLS(W) \
+ ((WINDOW_RIGHT_FRINGE_WIDTH ((W)) \
+ + WINDOW_FRAME_COLUMN_WIDTH (W) - 1) \
+ / WINDOW_FRAME_COLUMN_WIDTH (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, and in lines, 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)
+
+#define WINDOW_MODE_LINE_LINES(W) \
+ (!! WINDOW_WANTS_MODELINE_P ((W)))
+
+/* Height in pixels, and in lines, 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)
+
+#define WINDOW_HEADER_LINE_LINES(W) \
+ (!! WINDOW_WANTS_HEADER_LINE_P ((W)))
+
+/* 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))