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

Daniel Burrows dburrows@costa.debian.org
Wed, 27 Apr 2005 02:10:25 +0000


Author: dburrows
Date: Wed Apr 27 02:10:22 2005
New Revision: 3118

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/fragment_cache.cc
   branches/aptitude-0.3/aptitude/src/vscreen/fragment_cache.h
   branches/aptitude-0.3/aptitude/src/vscreen/vs_button.cc
   branches/aptitude-0.3/aptitude/src/vscreen/vs_button.h
   branches/aptitude-0.3/aptitude/src/vscreen/vs_togglebutton.cc
Log:
Make the cache work, use it for buttons.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Apr 27 02:10:22 2005
@@ -1,5 +1,10 @@
 2005-04-26  Daniel Burrows  <dburrows@debian.org>
 
+	* src/vscreen/fragment_cache.cc, src/vscreen/fragment_cache.h, src/vscreen/vs_button.cc, src/vscreen/vs_button.h, src/vscreen/vs_togglebutton.cc:
+
+	  Get the cache working, and use it to hold the fragments of
+	  buttons.
+
 	* src/vscreen/fragment_cache.cc, src/vscreen/fragment_cache.h:
 
 	  Add a special intermediate fragment widget that caches the

Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment_cache.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment_cache.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment_cache.cc	Wed Apr 27 02:10:22 2005
@@ -59,7 +59,7 @@
   invalidate();
 }
 
-size_t fragment_cache::max_width(size_t first_indent, size_t rest_indent)
+size_t fragment_cache::max_width(size_t first_indent, size_t rest_indent) const
 {
   if(!cached_max_width_valid ||
      first_indent != cached_max_width_first_indent ||
@@ -74,7 +74,7 @@
   return cached_max_width;
 }
 
-size_t fragment_cache::trailing_width(size_t first_indent, size_t rest_indent)
+size_t fragment_cache::trailing_width(size_t first_indent, size_t rest_indent) const
 {
   if(!cached_trailing_width_valid ||
      first_indent != cached_trailing_width_first_indent ||
@@ -89,7 +89,7 @@
   return cached_trailing_width;
 }
 
-bool fragment_cache::final_newline()
+bool fragment_cache::final_newline() const
 {
   if(!cached_final_nl_valid)
     {

Modified: branches/aptitude-0.3/aptitude/src/vscreen/fragment_cache.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/fragment_cache.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/fragment_cache.h	Wed Apr 27 02:10:22 2005
@@ -34,32 +34,32 @@
   fragment *contents;
 
   /** The last cached result. */
-  fragment_contents cached_lines;
+  mutable fragment_contents cached_lines;
 
   /** If cached_lines is valid, cached_lines was formatted for these
    *  widths.
    */
-  size_t cached_lines_first_width, cached_lines_rest_width;
+  mutable size_t cached_lines_first_width, cached_lines_rest_width;
 
   /** The cached max_width value. */
-  size_t cached_max_width;
+  mutable size_t cached_max_width;
 
   /** For what indents is cached_max_width valid? */
-  size_t cached_max_width_first_indent, cached_max_width_rest_indent;
+  mutable size_t cached_max_width_first_indent, cached_max_width_rest_indent;
 
   /** The cached trailing_width value. */
-  size_t cached_trailing_width;
+  mutable size_t cached_trailing_width;
 
   /** For what indents is cached_trailing_width valid? */
-  size_t cached_trailing_width_first_indent, cached_trailing_width_rest_indent;
+  mutable size_t cached_trailing_width_first_indent, cached_trailing_width_rest_indent;
 
   /** The cached final_newline value. */
-  bool cached_final_nl:1;
+  mutable bool cached_final_nl:1;
 
   /** If \b true, the corresponding property is valid. */
-  bool cached_lines_valid:1, cached_max_width_valid:1;
+  mutable bool cached_lines_valid:1, cached_max_width_valid:1;
   /** If \b true, the corresponding property is valid. */
-  bool cached_trailing_width_valid:1, cached_final_nl_valid:1;
+  mutable bool cached_trailing_width_valid:1, cached_final_nl_valid:1;
 public:
   fragment_cache(fragment *_contents);
   ~fragment_cache();
@@ -70,10 +70,10 @@
 
   void set_attr(int attr);
 
-  size_t max_width(size_t first_indent, size_t rest_indent);
-  size_t trailing_width(size_t first_indent, size_t rest_indent);
+  size_t max_width(size_t first_indent, size_t rest_indent) const;
+  size_t trailing_width(size_t first_indent, size_t rest_indent) const;
 
-  bool final_newline();
+  bool final_newline() const;
 };
 
 

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_button.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_button.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_button.cc	Wed Apr 27 02:10:22 2005
@@ -3,6 +3,7 @@
 #include "vs_button.h"
 
 #include "fragment.h"
+#include "fragment_cache.h"
 #include "vscreen.h"
 
 #include "config/keybindings.h"
@@ -10,14 +11,14 @@
 #include <sigc++/functors/mem_fun.h>
 
 vs_button::vs_button(fragment *_label)
-  :label(_label)
+  :label(new fragment_cache(_label))
 {
   focussed.connect(sigc::mem_fun(*this, &vs_button::accept_focus));
   unfocussed.connect(sigc::mem_fun(*this, &vs_button::lose_focus));
 }
 
 vs_button::vs_button(const std::string &_label)
-  :label(text_fragment(_label))
+  :label(new fragment_cache(text_fragment(_label)))
 {
   focussed.connect(sigc::mem_fun(*this, &vs_button::accept_focus));
   unfocussed.connect(sigc::mem_fun(*this, &vs_button::lose_focus));

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_button.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_button.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_button.h	Wed Apr 27 02:10:22 2005
@@ -13,18 +13,19 @@
 #include <string>
 
 class fragment;
+class fragment_cache;
 
 /** This class represents a push-button. */
 class vs_button:public vscreen_widget
 {
-  fragment *label;
+  fragment_cache *label;
 
   void accept_focus();
   void lose_focus();
 
 protected:
   bool handle_char(chtype ch);
-  fragment *get_label() const {return label;}
+  fragment_cache *get_label() const {return label;}
 public:
   /** Instantiate a vs_button.
    *

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_togglebutton.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_togglebutton.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_togglebutton.cc	Wed Apr 27 02:10:22 2005
@@ -4,6 +4,7 @@
 #include "vs_togglebutton.h"
 
 #include "fragment.h"
+#include "fragment_cache.h"
 
 vs_togglebutton::vs_togglebutton(char _bracketl, char _mark, char _bracketr,
 				 fragment *_label, bool _checked)