changeset 71554:0b31608be4a1

(display_tool_bar_line): Skip glyphs which are too big to ever fit the tool-bar, (MAX_FRAME_TOOL_BAR_HEIGHT): New macro. (tool_bar_lines_needed): Use unused mode-line row as temp_row. (redisplay_tool_bar): Only clear desired matrix if we actually change the tool-bar window height. Only try to make the tool-bar window bigger if there is actually room for it.
author Kim F. Storm <storm@cua.dk>
date Sat, 01 Jul 2006 23:29:04 +0000
parents fab9a5c14338
children d9b9f70ec91a
files src/xdisp.c
diffstat 1 files changed, 31 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/xdisp.c	Sat Jul 01 23:28:38 2006 +0000
+++ b/src/xdisp.c	Sat Jul 01 23:29:04 2006 +0000
@@ -9608,6 +9608,12 @@
 	      /* Glyph doesn't fit on line.  Backtrack.  */
 	      row->used[TEXT_AREA] = n_glyphs_before;
 	      *it = it_before;
+	      /* If this is the only glyph on this line, it will never fit on the
+		 toolbar, so skip it.   But ensure there is at least one glyph,
+		 so we don't accidentally disable the tool-bar.  */
+	      if (n_glyphs_before == 0
+		  && (it->vpos > 0 || IT_STRING_CHARPOS (*it) < it->end_charpos-1))
+		break;
 	      goto out;
 	    }
 
@@ -9666,6 +9672,11 @@
 }
 
 
+/* Max tool-bar height.  */
+
+#define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
+  ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
+
 /* Value is the number of screen lines needed to make all tool-bar
    items of frame F visible.  The number of actual rows needed is
    returned in *N_ROWS if non-NULL.  */
@@ -9677,7 +9688,10 @@
 {
   struct window *w = XWINDOW (f->tool_bar_window);
   struct it it;
-  struct glyph_row *temp_row = w->desired_matrix->rows;
+  /* tool_bar_lines_needed is called from redisplay_tool_bar after building
+     the desired matrix, so use (unused) mode-line row as temporary row to
+     avoid destroying the first tool-bar row.  */
+  struct glyph_row *temp_row = MATRIX_MODE_LINE_ROW (w->desired_matrix);
 
   /* Initialize an iterator for iteration over
      F->desired_tool_bar_string in the tool-bar window of frame F.  */
@@ -9783,13 +9797,13 @@
 	  int old_height = WINDOW_TOTAL_LINES (w);
 
 	  XSETFRAME (frame, f);
-	  clear_glyph_matrix (w->desired_matrix);
 	  Fmodify_frame_parameters (frame,
 				    Fcons (Fcons (Qtool_bar_lines,
 						  make_number (nlines)),
 					   Qnil));
 	  if (WINDOW_TOTAL_LINES (w) != old_height)
 	    {
+	      clear_glyph_matrix (w->desired_matrix);
 	      fonts_changed_p = 1;
 	      return 1;
 	    }
@@ -9841,17 +9855,20 @@
 
   if (auto_resize_tool_bars_p)
     {
-      int nlines;
+      int nlines, nrows;
+      int max_tool_bar_height = MAX_FRAME_TOOL_BAR_HEIGHT (f);
 
       /* If we couldn't display everything, change the tool-bar's
-	 height.  */
-      if (IT_STRING_CHARPOS (it) < it.end_charpos)
+	 height if there is room for more.  */
+      if (IT_STRING_CHARPOS (it) < it.end_charpos
+	  && it.current_y < max_tool_bar_height)
 	change_height_p = 1;
 
+      row = it.glyph_row - 1;
+
       /* 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.  */
-      row = it.glyph_row - 1;
       if (!row->displays_text_p
 	  && row->height >= FRAME_LINE_HEIGHT (f))
 	change_height_p = 1;
@@ -9859,13 +9876,14 @@
       /* If row displays tool-bar items, but is partially visible,
 	 change the tool-bar's height.  */
       if (row->displays_text_p
-	  && MATRIX_ROW_BOTTOM_Y (row) > it.last_visible_y)
+	  && MATRIX_ROW_BOTTOM_Y (row) > it.last_visible_y
+	  && MATRIX_ROW_BOTTOM_Y (row) < max_tool_bar_height)
 	change_height_p = 1;
 
       /* Resize windows as needed by changing the `tool-bar-lines'
 	 frame parameter.  */
       if (change_height_p
-	  && (nlines = tool_bar_lines_needed (f, &f->n_tool_bar_rows),
+	  && (nlines = tool_bar_lines_needed (f, &nrows),
 	      nlines != WINDOW_TOTAL_LINES (w)))
 	{
 	  extern Lisp_Object Qtool_bar_lines;
@@ -9873,13 +9891,16 @@
 	  int old_height = WINDOW_TOTAL_LINES (w);
 
 	  XSETFRAME (frame, f);
-	  clear_glyph_matrix (w->desired_matrix);
 	  Fmodify_frame_parameters (frame,
 				    Fcons (Fcons (Qtool_bar_lines,
 						  make_number (nlines)),
 					   Qnil));
 	  if (WINDOW_TOTAL_LINES (w) != old_height)
-	    fonts_changed_p = 1;
+	    {
+	      clear_glyph_matrix (w->desired_matrix);
+	      f->n_tool_bar_rows = nrows;
+	      fonts_changed_p = 1;
+	    }
 	}
     }