[Aptitude-devel] r3093 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows@costa.debian.org
Tue, 26 Apr 2005 14:22:30 +0000


Author: dburrows
Date: Tue Apr 26 14:22:27 2005
New Revision: 3093

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
   branches/aptitude-0.3/aptitude/src/vscreen/fragment.h
   branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.cc
Log:
Fix the width calculation of fragments to adjust for indentation.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Tue Apr 26 14:22:27 2005
@@ -1,5 +1,10 @@
 2005-04-26  Daniel Burrows  <dburrows@debian.org>
 
+	* src/vscreen/fragment.cc, src/vscreen/fragment.h, src/vscreen/vs_text_layout.cc:
+
+	  Adjust the fragment width calculation to properly take
+	  indentation into account.
+
 	* src/solution_dialog.cc:
 
 	  Move the buttons into a separate "box" table, and add a

Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment.cc	Tue Apr 26 14:22:27 2005
@@ -36,14 +36,16 @@
     s.set_attr(attr);
   }
 
-  size_t max_width() const
+  size_t max_width(size_t first_indent,
+		   size_t rest_indent) const
   {
-    return s.size();
+    return first_indent+s.size();
   }
 
-  size_t trailing_width() const
+  size_t trailing_width(size_t first_indent,
+			size_t rest_indent) const
   {
-    return s.size();
+    return first_indent+s.size();
   }
 
   bool final_newline() const
@@ -78,14 +80,14 @@
   {
   }
 
-  size_t max_width() const
+  size_t max_width(size_t first_indent, size_t rest_indent) const
   {
-    return 0;
+    return first_indent;
   }
 
-  size_t trailing_width() const
+  size_t trailing_width(size_t first_indent, size_t rest_indent) const
   {
-    return 0;
+    return rest_indent;
   }
 
   bool final_newline() const
@@ -118,30 +120,35 @@
   }
 
   /** Actually calculate the maximum width. */
-  virtual size_t calc_max_width() const=0;
+  virtual size_t calc_max_width(size_t first_indent,
+				size_t rest_indent) const=0;
 
   /** Actually calculate the trailing width. */
-  virtual size_t calc_trailing_width() const=0;
+  virtual size_t calc_trailing_width(size_t first_indent,
+				     size_t rest_indent) const=0;
 
   /** Actually calculate the final-nl status. */
   virtual bool calc_final_newline() const=0;
 
-  size_t max_width() const
+  size_t max_width(size_t first_indent,
+		   size_t rest_indent) const
   {
     if(max_width_stale)
       {
-	max_width_cache=calc_max_width();
+	max_width_cache=calc_max_width(first_indent, rest_indent);
 	max_width_stale=false;
       }
 
     return max_width_cache;
   }
 
-  size_t trailing_width() const
+  size_t trailing_width(size_t first_indent,
+			size_t rest_indent) const
   {
     if(trailing_width_stale)
       {
-	trailing_width_cache=calc_trailing_width();
+	trailing_width_cache=calc_trailing_width(first_indent,
+						 rest_indent);
 	trailing_width_stale=false;
       }
 
@@ -226,16 +233,17 @@
       delete *i;
   }
 
-  size_t calc_max_width() const
+  size_t calc_max_width(size_t first_indent,
+			size_t rest_indent) const
   {
     size_t rval=0;
-    size_t partial=0;
+    size_t partial=first_indent;
     for(vector<fragment*>::const_iterator i=contents.begin();
 	i!=contents.end(); ++i)
       {
-	rval=max(rval, (*i)->max_width());
+	rval=max(rval, (*i)->max_width(partial, rest_indent));
 
-	partial+=(*i)->trailing_width();
+	partial=(*i)->trailing_width(partial, rest_indent);
 
 	if((*i)->final_newline())
 	  {
@@ -249,13 +257,14 @@
     return rval;
   }
 
-  size_t calc_trailing_width() const
+  size_t calc_trailing_width(size_t first_indent,
+			     size_t rest_indent) const
   {
-    size_t rval=0;
+    size_t rval=first_indent;
 
-    for(vector<fragment*>::const_reverse_iterator i=contents.rbegin();
-	i!=contents.rend() && !(*i)->final_newline(); ++i)
-      rval+=(*i)->trailing_width();
+    for(vector<fragment*>::const_iterator i=contents.begin();
+	i!=contents.end(); ++i)
+      rval=(*i)->trailing_width(rval, rest_indent);
 
     return rval;
   }
@@ -402,14 +411,16 @@
 
   void set_attr(int attr) { contents->set_attr(attr); }
 
-  size_t calc_max_width() const
+  size_t calc_max_width(size_t first_indent,
+			size_t rest_indent) const
   {
-    return contents->max_width();
+    return contents->max_width(first_indent, rest_indent);
   }
 
-  size_t calc_trailing_width() const
+  size_t calc_trailing_width(size_t first_indent,
+			     size_t rest_indent) const
   {
-    return 0;
+    return rest_indent;
   }
 
   bool calc_final_newline() const
@@ -548,14 +559,16 @@
 
   void set_attr(int attr) { contents->set_attr(attr); }
 
-  size_t calc_max_width() const
+  size_t calc_max_width(size_t first_indent,
+			size_t rest_indent) const
   {
-    return contents->max_width();
+    return contents->max_width(first_indent, rest_indent);
   }
 
-  size_t calc_trailing_width() const
+  size_t calc_trailing_width(size_t first_indent,
+			     size_t rest_indent) const
   {
-    return 0;
+    return rest_indent;
   }
 
   bool calc_final_newline() const
@@ -573,8 +586,6 @@
 
 class _hardwrapbox:public fragment_container
 {
-  fragment *contents;
-
 public:
   _hardwrapbox(fragment *_contents):contents(_contents) {}
 
@@ -615,20 +626,23 @@
 
   void set_attr(int attr) { contents->set_attr(attr); }
 
-  size_t calc_max_width() const
+  size_t calc_max_width(size_t first_indent, size_t rest_indent) const
   {
-    return contents->max_width();
+    return contents->max_width(first_indent, rest_indent);
   }
 
-  size_t calc_trailing_width() const
+  size_t calc_trailing_width(size_t first_indent, size_t rest_indent) const
   {
-    return 0;
+    return rest_indent;
   }
 
   bool calc_final_newline() const
   {
     return true;
   }
+
+private:
+  fragment * const contents;
 };
 
 fragment *hardwrapbox(fragment *contents)
@@ -661,14 +675,16 @@
 
   void set_attr(int attr) { contents->set_attr(attr); }
 
-  size_t calc_max_width() const
+  size_t calc_max_width(size_t first_indent,
+			size_t rest_indent) const
   {
-    return contents->max_width();
+    return contents->max_width(first_indent, rest_indent);
   }
 
-  size_t calc_trailing_width() const
+  size_t calc_trailing_width(size_t first_indent,
+			     size_t rest_indent) const
   {
-    return 0;
+    return rest_indent;
   }
 
   bool calc_final_newline() const
@@ -714,14 +730,17 @@
     return rval;
   }
 
-  size_t calc_max_width() const
+  size_t calc_max_width(size_t my_first_indent,
+			size_t my_rest_indent) const
   {
-    return contents->max_width();
+    return contents->max_width(my_first_indent+firstindent,
+			       my_rest_indent+restindent);
   }
 
-  size_t calc_trailing_width() const
+  size_t calc_trailing_width(size_t my_first_indent,
+			     size_t my_rest_indent) const
   {
-    return 0;
+    return my_rest_indent+restindent;
   }
 
   bool calc_final_newline() const

Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment.h	Tue Apr 26 14:22:27 2005
@@ -36,14 +36,27 @@
    */
   virtual void set_attr(int attr)=0;
 
-  /** \return the maximum length of any line in this fragment.  Any
+  /** \param first_indent the indentation of the first line, relative
+   *  to a baseline (which may be outside this fragment).
+   *
+   *  \param rest_indent the indentation of any other lines.
+   *
+   *  \return the maximum length of any line in this fragment.  Any
    *  call to layout() with a width greater than this maximum length
    *  will produce the same result.
    */
-  virtual size_t max_width() const=0;
+  virtual size_t max_width(size_t first_indent,
+			   size_t rest_indent) const=0;
 
-  /** \return the length of any "trailing" line in the fragment. */
-  virtual size_t trailing_width() const=0;
+  /** \param first_indent the indentation of the first line.
+   *
+   *  \param rest_indent the indentation of any other lines.
+   *
+   * \return the length of any "trailing" line in the fragment,
+   * including indentation.
+   */
+  virtual size_t trailing_width(size_t first_indent,
+				size_t rest_indent) const=0;
 
   /** \return \b true if this fragment ends in a newline. */
   virtual bool final_newline() const=0;

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.cc	Tue Apr 26 14:22:27 2005
@@ -56,7 +56,7 @@
 int vs_text_layout::width_request()
 {
   if(f!=NULL)
-    return f->max_width();
+    return f->max_width(0, 0);
   else
     return 0;
 }