Reorder conditions that are written backwards
[bpt/emacs.git] / src / xdisp.c
index 3838d23..d42e53f 100644 (file)
@@ -979,7 +979,7 @@ window_text_bottom_y (struct window *w)
 int
 window_box_width (struct window *w, int area)
 {
-  int cols = XFASTINT (w->total_cols);
+  int cols = w->total_cols;
   int pixels = 0;
 
   if (!w->pseudo_window_p)
@@ -2550,7 +2550,7 @@ markpos_of_region (void)
    at character position CHARPOS.  CHARPOS < 0 means that no buffer
    position is specified which is useful when the iterator is assigned
    a position later.  BYTEPOS is the byte position corresponding to
-   CHARPOS.  BYTEPOS < 0 means compute it from CHARPOS.
+   CHARPOS.
 
    If ROW is not null, calls to produce_glyphs with IT as parameter
    will produce glyphs in that row.
@@ -2677,7 +2677,7 @@ init_iterator (struct it *it, struct window *w,
      and IT->region_end_charpos to the start and end of a visible region
      in window IT->w.  Set both to -1 to indicate no region.  */
   markpos = markpos_of_region ();
-  if (0 <= markpos
+  if (markpos >= 0
       /* Maybe highlight only in selected window.  */
       && (/* Either show region everywhere.  */
          highlight_nonselected_windows
@@ -2828,18 +2828,14 @@ init_iterator (struct it *it, struct window *w,
   if (charpos >= BUF_BEG (current_buffer))
     {
       it->end_charpos = ZV;
+      eassert (charpos == BYTE_TO_CHAR (bytepos));
       IT_CHARPOS (*it) = charpos;
+      IT_BYTEPOS (*it) = bytepos;
 
       /* We will rely on `reseat' to set this up properly, via
         handle_face_prop.  */
       it->face_id = it->base_face_id;
 
-      /* Compute byte position if not specified.  */
-      if (bytepos < charpos)
-       IT_BYTEPOS (*it) = CHAR_TO_BYTE (charpos);
-      else
-       IT_BYTEPOS (*it) = bytepos;
-
       it->start = it->current;
       /* Do we need to reorder bidirectional text?  Not if this is a
         unibyte buffer: by definition, none of the single-byte
@@ -5905,8 +5901,10 @@ pop_it (struct it *it)
 static void
 back_to_previous_line_start (struct it *it)
 {
-  IT_CHARPOS (*it) = find_newline_no_quit (IT_CHARPOS (*it) - 1, -1,
-                                          &IT_BYTEPOS (*it));
+  ptrdiff_t cp = IT_CHARPOS (*it), bp = IT_BYTEPOS (*it);
+
+  DEC_BOTH (cp, bp);
+  IT_CHARPOS (*it) = find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it));
 }
 
 
@@ -5978,7 +5976,8 @@ forward_to_next_line_start (struct it *it, int *skipped_p,
   if (!newline_found_p)
     {
       ptrdiff_t bytepos, start = IT_CHARPOS (*it);
-      ptrdiff_t limit = find_newline_no_quit (start, 1, &bytepos);
+      ptrdiff_t limit = find_newline_no_quit (start, IT_BYTEPOS (*it),
+                                             1, &bytepos);
       Lisp_Object pos;
 
       eassert (!STRINGP (it->string));
@@ -7432,7 +7431,8 @@ get_visually_first_element (struct it *it)
       if (string_p)
        it->bidi_it.charpos = it->bidi_it.bytepos = 0;
       else
-       it->bidi_it.charpos = find_newline_no_quit (IT_CHARPOS (*it), -1,
+       it->bidi_it.charpos = find_newline_no_quit (IT_CHARPOS (*it),
+                                                   IT_BYTEPOS (*it), -1,
                                                    &it->bidi_it.bytepos);
       bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, 1);
       do
@@ -9067,10 +9067,11 @@ move_it_vertically_backward (struct it *it, int dy)
          && IT_CHARPOS (*it) > BEGV
          && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n')
        {
-         ptrdiff_t nl_pos = find_newline_no_quit (IT_CHARPOS (*it) - 1, -1,
-                                                  NULL);
+         ptrdiff_t cp = IT_CHARPOS (*it), bp = IT_BYTEPOS (*it);
 
-         move_it_to (it, nl_pos, -1, -1, -1, MOVE_TO_POS);
+         DEC_BOTH (cp, bp);
+         cp = find_newline_no_quit (cp, bp, -1, NULL);
+         move_it_to (it, cp, -1, -1, -1, MOVE_TO_POS);
        }
       bidi_unshelve_cache (it3data, 1);
     }
@@ -11706,7 +11707,8 @@ display_tool_bar_line (struct it *it, int height)
      no additional border below the possibly empty tool-bar lines.
      So to make the extra empty lines look "normal", we have to
      use the tool-bar face for the border too.  */
-  if (!row->displays_text_p && !EQ (Vauto_resize_tool_bars, Qgrow_only))
+  if (!MATRIX_ROW_DISPLAYS_TEXT_P (row)
+      && !EQ (Vauto_resize_tool_bars, Qgrow_only))
     it->face_id = DEFAULT_FACE_ID;
 
   extend_face_to_end_of_line (it);
@@ -11727,7 +11729,7 @@ display_tool_bar_line (struct it *it, int height)
   compute_line_metrics (it);
 
   /* If line is empty, make it occupy the rest of the tool-bar.  */
-  if (!row->displays_text_p)
+  if (!MATRIX_ROW_DISPLAYS_TEXT_P (row))
     {
       row->height = row->phys_height = it->last_visible_y - row->y;
       row->visible_height = row->height;
@@ -11942,13 +11944,13 @@ redisplay_tool_bar (struct frame *f)
       /* If there are blank lines at the end, except for a partially
         visible blank line at the end that is smaller than
         FRAME_LINE_HEIGHT, change the tool-bar's height.  */
-      if (!row->displays_text_p
+      if (!MATRIX_ROW_DISPLAYS_TEXT_P (row)
          && row->height >= FRAME_LINE_HEIGHT (f))
        change_height_p = 1;
 
       /* If row displays tool-bar items, but is partially visible,
         change the tool-bar's height.  */
-      if (row->displays_text_p
+      if (MATRIX_ROW_DISPLAYS_TEXT_P (row)
          && MATRIX_ROW_BOTTOM_Y (row) > it.last_visible_y
          && MATRIX_ROW_BOTTOM_Y (row) < max_tool_bar_height)
        change_height_p = 1;
@@ -13139,7 +13141,7 @@ redisplay_internal (void)
              /* If this row displays text now but previously didn't,
                 or vice versa, w->window_end_vpos may have to be
                 adjusted.  */
-             if ((it.glyph_row - 1)->displays_text_p)
+             if (MATRIX_ROW_DISPLAYS_TEXT_P (it.glyph_row - 1))
                {
                  if (XFASTINT (w->window_end_vpos) < this_line_vpos)
                    wset_window_end_vpos (w, make_number (this_line_vpos));
@@ -13168,8 +13170,8 @@ redisplay_internal (void)
               PT == w->last_point
               /* Make sure the cursor was last displayed
                  in this window.  Otherwise we have to reposition it.  */
-              && 0 <= w->cursor.vpos
-              && WINDOW_TOTAL_LINES (w) > w->cursor.vpos)
+              && w->cursor.vpos >= 0
+              && w->cursor.vpos < WINDOW_TOTAL_LINES (w))
        {
          if (!must_finish)
            {
@@ -13749,7 +13751,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
   /* Skip over glyphs not having an object at the start and the end of
      the row.  These are special glyphs like truncation marks on
      terminal frames.  */
-  if (row->displays_text_p)
+  if (MATRIX_ROW_DISPLAYS_TEXT_P (row))
     {
       if (!row->reversed_p)
        {
@@ -14926,8 +14928,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
                 we would rather display cursor in the next line.  */
              while (MATRIX_ROW_BOTTOM_Y (row) < last_y
                     && MATRIX_ROW_END_CHARPOS (row) == PT
-                    && row < w->current_matrix->rows
-                               + w->current_matrix->nrows - 1
+                    && row < MATRIX_MODE_LINE_ROW (w->current_matrix)
                     && MATRIX_ROW_START_CHARPOS (row+1) == PT
                     && !cursor_row_p (row))
                ++row;
@@ -15519,7 +15520,7 @@ redisplay_window (Lisp_Object window, int just_this_one_p)
 
          /* If we are highlighting the region, then we just changed
             the region, so redisplay to show it.  */
-         if (0 <= markpos_of_region ())
+         if (markpos_of_region () >= 0)
            {
              clear_glyph_matrix (w->desired_matrix);
              if (!try_window (window, startp, 0))
@@ -16166,8 +16167,8 @@ try_window (Lisp_Object window, struct text_pos pos, int flags)
       wset_window_end_vpos
        (w, make_number (MATRIX_ROW_VPOS (last_text_row, w->desired_matrix)));
       eassert
-       (MATRIX_ROW (w->desired_matrix,
-                    XFASTINT (w->window_end_vpos))->displays_text_p);
+       (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w->desired_matrix,
+                                                XFASTINT (w->window_end_vpos))));
     }
   else
     {
@@ -16220,7 +16221,7 @@ try_window_reusing_current_matrix (struct window *w)
     return 0;
 
   /* Can't do this if region may have changed.  */
-  if (0 <= markpos_of_region ()
+  if (markpos_of_region () >= 0
       || w->region_showing
       || !NILP (Vshow_trailing_whitespace))
     return 0;
@@ -17052,7 +17053,7 @@ try_window_id (struct window *w)
 
   /* Can't use this if highlighting a region because a cursor movement
      will do more than just set the cursor.  */
-  if (0 <= markpos_of_region ())
+  if (markpos_of_region () >= 0)
     GIVE_UP (9);
 
   /* Likewise if highlighting trailing whitespace.  */
@@ -17576,7 +17577,7 @@ try_window_id (struct window *w)
       struct glyph_row *last_row = MATRIX_ROW (current_matrix, last_vpos);
 
       /* If last_row is the window end line, it should display text.  */
-      eassert (last_row->displays_text_p);
+      eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row));
 
       /* If window end line was partially visible before, begin
         displaying at that line.  Otherwise begin displaying with the
@@ -17623,7 +17624,7 @@ try_window_id (struct window *w)
         matrix.  Set row to the last row displaying text in current
         matrix starting at first_unchanged_at_end_row, after
         scrolling.  */
-      eassert (first_unchanged_at_end_row->displays_text_p);
+      eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row));
       row = find_last_row_displaying_text (w->current_matrix, &it,
                                           first_unchanged_at_end_row);
       eassert (row && MATRIX_ROW_DISPLAYS_TEXT_P (row));
@@ -17677,10 +17678,10 @@ try_window_id (struct window *w)
        {
          if (desired_row->enabled_p)
            {
-             if (desired_row->displays_text_p)
+             if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row))
                row = desired_row;
            }
-         else if (current_row->displays_text_p)
+         else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row))
            row  = current_row;
        }
 
@@ -17860,7 +17861,7 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs)
               row->truncated_on_right_p,
               row->continued_p,
               MATRIX_ROW_CONTINUATION_LINE_P (row),
-              row->displays_text_p,
+              MATRIX_ROW_DISPLAYS_TEXT_P (row),
               row->ends_at_zv_p,
               row->fill_line_p,
               row->ends_in_middle_of_char_p,
@@ -18496,7 +18497,7 @@ extend_face_to_end_of_line (struct it *it)
     face = FACE_FROM_ID (f, it->face_id);
 
   if (FRAME_WINDOW_P (f)
-      && it->glyph_row->displays_text_p
+      && MATRIX_ROW_DISPLAYS_TEXT_P (it->glyph_row)
       && face->box == FACE_NO_BOX
       && face->background == FRAME_BACKGROUND_PIXEL (f)
       && !face->stipple
@@ -19756,7 +19757,7 @@ display_line (struct it *it)
      mark this glyph row as the one containing the overlay arrow.
      This is clearly a mess with variable size fonts.  It would be
      better to let it be displayed like cursors under X.  */
-  if ((row->displays_text_p || !overlay_arrow_seen)
+  if ((MATRIX_ROW_DISPLAYS_TEXT_P (row) || !overlay_arrow_seen)
       && (overlay_arrow_string = overlay_arrow_at_row (it, row),
          !NILP (overlay_arrow_string)))
     {
@@ -19856,7 +19857,7 @@ display_line (struct it *it)
   if (it->glyph_row < MATRIX_BOTTOM_TEXT_ROW (it->w->desired_matrix, it->w))
     it->glyph_row->reversed_p = row->reversed_p;
   it->start = row->end;
-  return row->displays_text_p;
+  return MATRIX_ROW_DISPLAYS_TEXT_P (row);
 
 #undef RECORD_MAX_MIN_POS
 }
@@ -19987,18 +19988,17 @@ display_menu_bar (struct window *w)
     return;
 #endif /* HAVE_NS */
 
-#ifdef USE_X_TOOLKIT
+#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
   eassert (!FRAME_WINDOW_P (f));
   init_iterator (&it, w, -1, -1, f->desired_matrix->rows, MENU_FACE_ID);
   it.first_visible_x = 0;
   it.last_visible_x = FRAME_TOTAL_COLS (f) * FRAME_COLUMN_WIDTH (f);
-#else /* not USE_X_TOOLKIT */
+#elif defined (HAVE_X_WINDOWS) /* X without toolkit.  */
   if (FRAME_WINDOW_P (f))
     {
       /* Menu bar lines are displayed in the desired matrix of the
         dummy window menu_bar_window.  */
       struct window *menu_w;
-      eassert (WINDOWP (f->menu_bar_window));
       menu_w = XWINDOW (f->menu_bar_window);
       init_iterator (&it, menu_w, -1, -1, menu_w->desired_matrix->rows,
                     MENU_FACE_ID);
@@ -20006,6 +20006,7 @@ display_menu_bar (struct window *w)
       it.last_visible_x = FRAME_TOTAL_COLS (f) * FRAME_COLUMN_WIDTH (f);
     }
   else
+#endif /* not USE_X_TOOLKIT and not USE_GTK */
     {
       /* This is a TTY frame, i.e. character hpos/vpos are used as
         pixel x/y.  */
@@ -20014,7 +20015,6 @@ display_menu_bar (struct window *w)
       it.first_visible_x = 0;
       it.last_visible_x = FRAME_COLS (f);
     }
-#endif /* not USE_X_TOOLKIT */
 
   /* FIXME: This should be controlled by a user option.  See the
      comments in redisplay_tool_bar and display_mode_line about
@@ -21008,7 +21008,7 @@ pint2hrstr (char *buf, int width, ptrdiff_t d)
   char * psuffix;
   char * p;
 
-  if (1000 <= quotient)
+  if (quotient >= 1000)
     {
       /* Scale to the appropriate EXPONENT. */
       do
@@ -21017,13 +21017,13 @@ pint2hrstr (char *buf, int width, ptrdiff_t d)
          quotient /= 1000;
          exponent++;
        }
-      while (1000 <= quotient);
+      while (quotient >= 1000);
 
       /* Round to nearest and decide whether to use TENTHS or not. */
       if (quotient <= 9)
        {
          tenths = remainder / 100;
-         if (50 <= remainder % 100)
+         if (remainder % 100 >= 50)
            {
              if (tenths < 9)
                tenths++;
@@ -21038,7 +21038,7 @@ pint2hrstr (char *buf, int width, ptrdiff_t d)
            }
        }
       else
-       if (500 <= remainder)
+       if (remainder >= 500)
          {
            if (quotient < 999)
              quotient++;
@@ -22081,11 +22081,6 @@ else if the text is replaced by an ellipsis.  */)
 
 */
 
-#define NUMVAL(X)                              \
-     ((INTEGERP (X) || FLOATP (X))             \
-      ? XFLOATINT (X)                          \
-      : - 1)
-
 static int
 calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
                            struct font *font, int width_p, int *align_to)
@@ -22116,24 +22111,11 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
            pixels = 0;
          if (pixels > 0)
            {
-             double ppi;
-#ifdef HAVE_WINDOW_SYSTEM
-             if (FRAME_WINDOW_P (it->f)
-                 && (ppi = (width_p
-                            ? FRAME_X_DISPLAY_INFO (it->f)->resx
-                            : FRAME_X_DISPLAY_INFO (it->f)->resy),
-                     ppi > 0))
-               return OK_PIXELS (ppi / pixels);
-#endif
+             double ppi = (width_p ? FRAME_RES_X (it->f)
+                           : FRAME_RES_Y (it->f));
 
-             if ((ppi = NUMVAL (Vdisplay_pixels_per_inch), ppi > 0)
-                 || (CONSP (Vdisplay_pixels_per_inch)
-                     && (ppi = (width_p
-                                ? NUMVAL (XCAR (Vdisplay_pixels_per_inch))
-                                : NUMVAL (XCDR (Vdisplay_pixels_per_inch))),
-                         ppi > 0)))
+             if (ppi > 0)
                return OK_PIXELS (ppi / pixels);
-
              return 0;
            }
        }
@@ -22409,16 +22391,16 @@ get_char_face_and_encoding (struct frame *f, int c, int face_id,
                            XChar2b *char2b, int display_p)
 {
   struct face *face = FACE_FROM_ID (f, face_id);
+  unsigned code = 0;
 
   if (face->font)
     {
-      unsigned code = face->font->driver->encode_char (face->font, c);
+      code = face->font->driver->encode_char (face->font, c);
 
-      if (code != FONT_INVALID_CODE)
-       STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
-      else
-       STORE_XCHAR2B (char2b, 0, 0);
+      if (code == FONT_INVALID_CODE)
+       code = 0;
     }
+  STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
 
   /* Make sure X resources of the face are allocated.  */
 #ifdef HAVE_X_WINDOWS
@@ -22442,31 +22424,30 @@ get_glyph_face_and_encoding (struct frame *f, struct glyph *glyph,
                             XChar2b *char2b, int *two_byte_p)
 {
   struct face *face;
+  unsigned code = 0;
 
   eassert (glyph->type == CHAR_GLYPH);
   face = FACE_FROM_ID (f, glyph->face_id);
 
+  /* Make sure X resources of the face are allocated.  */
+  eassert (face != NULL);
+  PREPARE_FACE_FOR_DISPLAY (f, face);
+
   if (two_byte_p)
     *two_byte_p = 0;
 
   if (face->font)
     {
-      unsigned code;
-
       if (CHAR_BYTE8_P (glyph->u.ch))
        code = CHAR_TO_BYTE8 (glyph->u.ch);
       else
        code = face->font->driver->encode_char (face->font, glyph->u.ch);
 
-      if (code != FONT_INVALID_CODE)
-       STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
-      else
-       STORE_XCHAR2B (char2b, 0, 0);
+      if (code == FONT_INVALID_CODE)
+       code = 0;
     }
 
-  /* Make sure X resources of the face are allocated.  */
-  eassert (face != NULL);
-  PREPARE_FACE_FOR_DISPLAY (f, face);
+  STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
   return face;
 }
 
@@ -22776,9 +22757,12 @@ static struct font_metrics *
 get_per_char_metric (struct font *font, XChar2b *char2b)
 {
   static struct font_metrics metrics;
-  unsigned code = (XCHAR2B_BYTE1 (char2b) << 8) | XCHAR2B_BYTE2 (char2b);
+  unsigned code;
 
-  if (! font || code == FONT_INVALID_CODE)
+  if (! font)
+    return NULL;
+  code = (XCHAR2B_BYTE1 (char2b) << 8) | XCHAR2B_BYTE2 (char2b);
+  if (code == FONT_INVALID_CODE)
     return NULL;
   font->driver->text_extents (font, &code, 1, &metrics);
   return &metrics;
@@ -25655,7 +25639,7 @@ notice_overwritten_cursor (struct window *w, enum glyph_row_area area,
   if (w->phys_cursor.vpos < 0
       || w->phys_cursor.vpos >= w->current_matrix->nrows
       || (row = w->current_matrix->rows + w->phys_cursor.vpos,
-         !(row->enabled_p && row->displays_text_p)))
+         !(row->enabled_p && MATRIX_ROW_DISPLAYS_TEXT_P (row))))
     return;
 
   if (row->cursor_in_fringe_p)
@@ -26590,7 +26574,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
       x = r1->x;
 
       /* Skip truncation glyphs at the start of the glyph row.  */
-      if (r1->displays_text_p)
+      if (MATRIX_ROW_DISPLAYS_TEXT_P (r1))
        for (; glyph < end
               && INTEGERP (glyph->object)
               && glyph->charpos < 0;
@@ -26641,7 +26625,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
       glyph = end + r1->used[TEXT_AREA];
 
       /* Skip truncation glyphs at the start of the glyph row.  */
-      if (r1->displays_text_p)
+      if (MATRIX_ROW_DISPLAYS_TEXT_P (r1))
        for (; glyph > end
               && INTEGERP (glyph->object)
               && glyph->charpos < 0;
@@ -26892,7 +26876,7 @@ fast_find_string_pos (struct window *w, ptrdiff_t pos, Lisp_Object object,
        }
 
       *y = best_row->y;
-      *vpos = best_row - w->current_matrix->rows;
+      *vpos = MATRIX_ROW_VPOS (best_row, w->current_matrix);
     }
 
   return best_glyph != NULL;
@@ -26930,7 +26914,8 @@ mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo,
            if (EQ (g->object, object)
                && startpos <= g->charpos && g->charpos <= endpos)
              {
-               hlinfo->mouse_face_beg_row = r - w->current_matrix->rows;
+               hlinfo->mouse_face_beg_row
+                 = MATRIX_ROW_VPOS (r, w->current_matrix);
                hlinfo->mouse_face_beg_y = r->y;
                hlinfo->mouse_face_beg_col = g - r->glyphs[TEXT_AREA];
                hlinfo->mouse_face_beg_x = gx;
@@ -26948,7 +26933,8 @@ mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo,
            if (EQ ((g-1)->object, object)
                && startpos <= (g-1)->charpos && (g-1)->charpos <= endpos)
              {
-               hlinfo->mouse_face_beg_row = r - w->current_matrix->rows;
+               hlinfo->mouse_face_beg_row
+                 = MATRIX_ROW_VPOS (r, w->current_matrix);
                hlinfo->mouse_face_beg_y = r->y;
                hlinfo->mouse_face_beg_col = g - r->glyphs[TEXT_AREA];
                for (gx = r->x, g1 = r->glyphs[TEXT_AREA]; g1 < g; ++g1)
@@ -26987,7 +26973,7 @@ mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo,
   r--;
 
   /* Set the end row and its vertical pixel coordinate.  */
-  hlinfo->mouse_face_end_row = r - w->current_matrix->rows;
+  hlinfo->mouse_face_end_row = MATRIX_ROW_VPOS (r, w->current_matrix);
   hlinfo->mouse_face_end_y = r->y;
 
   /* Compute and set the end column and the end column's horizontal
@@ -27671,7 +27657,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
       /* Clear mouse face if X/Y not over text.  */
       if (glyph == NULL
          || area != TEXT_AREA
-         || !MATRIX_ROW (w->current_matrix, vpos)->displays_text_p
+         || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w->current_matrix, vpos))
          /* Glyph's OBJECT is an integer for glyphs inserted by the
             display engine for its internal purposes, like truncation
             and continuation glyphs and blanks beyond the end of
@@ -27683,7 +27669,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
             all beyond the end of text.  Treat such stretch glyphs
             like we do with NULL glyphs in L2R rows.  */
          || (MATRIX_ROW (w->current_matrix, vpos)->reversed_p
-             && glyph == MATRIX_ROW (w->current_matrix, vpos)->glyphs[TEXT_AREA]
+             && glyph == MATRIX_ROW_GLYPH_START (w->current_matrix, vpos)
              && glyph->type == STRETCH_GLYPH
              && glyph->avoid_cursor_p))
        {
@@ -28495,11 +28481,11 @@ expose_frame (struct frame *f, int x, int y, int w, int h)
 
 #ifdef HAVE_X_WINDOWS
 #ifndef MSDOS
-#ifndef USE_X_TOOLKIT
+#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
   if (WINDOWP (f->menu_bar_window))
     mouse_face_overwritten_p
       |= expose_window (XWINDOW (f->menu_bar_window), &r);
-#endif /* not USE_X_TOOLKIT */
+#endif /* not USE_X_TOOLKIT and not USE_GTK */
 #endif
 #endif
 
@@ -29233,13 +29219,13 @@ init_xdisp (void)
 
       echo_area_window = minibuf_window;
 
-      wset_top_line (r, make_number (FRAME_TOP_MARGIN (f)));
-      wset_total_lines
-       (r, make_number (FRAME_LINES (f) - 1 - FRAME_TOP_MARGIN (f)));
-      wset_total_cols (r, make_number (FRAME_COLS (f)));
-      wset_top_line (m, make_number (FRAME_LINES (f) - 1));
-      wset_total_lines (m, make_number (1));
-      wset_total_cols (m, make_number (FRAME_COLS (f)));
+      r->top_line = FRAME_TOP_MARGIN (f);
+      r->total_lines = FRAME_LINES (f) - 1 - FRAME_TOP_MARGIN (f);
+      r->total_cols = FRAME_COLS (f);
+
+      m->top_line = FRAME_LINES (f) - 1;
+      m->total_lines = 1;
+      m->total_cols = FRAME_COLS (f);
 
       scratch_glyph_row.glyphs[TEXT_AREA] = scratch_glyphs;
       scratch_glyph_row.glyphs[TEXT_AREA + 1]