[Aptitude-svn-commit] r3297 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows@costa.debian.org
Sat, 04 Jun 2005 17:13:27 +0000


Author: dburrows
Date: Sat Jun  4 17:13:24 2005
New Revision: 3297

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/vscreen.cc
   branches/aptitude-0.3/aptitude/src/vscreen/vscreen_widget.cc
   branches/aptitude-0.3/aptitude/src/vscreen/vscreen_widget.h
Log:
Remove the stack of styles and just use explicit setting of style
information instead.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sat Jun  4 17:13:24 2005
@@ -1,3 +1,12 @@
+2005-06-04  Daniel Burrows  <dburrows@debian.org>
+
+	* src/vscreen/vscreen_widget.cc, src/vscreen/vscreen_widget.h:
+
+	Remove the stack of styles, it's the Wrong Way to do things.  (if
+	this were Lisp, a with-style macro would be appropriate, but it's
+	not so it isn't) Instead, just let the user directly set the
+	current text attributes based on a full style.
+
 2005-06-02  Tetralet  <tetralet@pchome.com.tw>
 
 	* po/zh_TW.po: Updated from sarge branch. Closes: #311587

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vscreen.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vscreen.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vscreen.cc	Sat Jun  4 17:13:24 2005
@@ -447,7 +447,7 @@
 {
   if(toplevel)
     {
-      toplevel->display();
+      toplevel->display(get_style("Default"));
       toplevel->sync();
 
       vscreen_updatecursornow();
@@ -650,7 +650,7 @@
   if(toplevel)
     {
       toplevel->set_owner_window(rootwin, 0, 0, rootwin.getmaxx(), rootwin.getmaxy());
-      toplevel->display();
+      toplevel->display(get_style("Default"));
       toplevel->sync();
       doupdate();
     }
@@ -673,7 +673,7 @@
       toplevel->get_win().touch();
       toplevel->get_win().clearok(true);
       toplevel->do_layout();
-      toplevel->display();
+      toplevel->display(get_style("Default"));
       vscreen_updatecursornow();
       toplevel->sync();
       doupdate();

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vscreen_widget.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vscreen_widget.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vscreen_widget.cc	Sat Jun  4 17:13:24 2005
@@ -43,26 +43,14 @@
 
 void vscreen_widget::set_bg_style(const style &new_style)
 {
-  assert(style_stack.empty());
-
   bg_style=new_style;
-  if(win)
-    win.setattr(bg_style.get_attrs());
-}
-
-void vscreen_widget::push_style(const style &new_style)
-{
-  style_stack.push_back(get_current_style()+new_style);
-
-  win->setattr(style_stack.back().get_attrs());
 }
 
-void vscreen_widget::pop_style()
+void vscreen_widget::apply_style(const style &st)
 {
-  style_stack.pop_back();
+  attrset(st.get_attrs());
 }
 
-
 void vscreen_widget::set_isfocussed(bool _isfocussed)
 {
   isfocussed=_isfocussed;
@@ -181,9 +169,14 @@
   hidden_sig();
 }
 
-void vscreen_widget::display()
+void vscreen_widget::display(const style &st)
 {
-  if(bgattr!=-1)
+  // Erase our window, using the composition of the surrounding style
+  // and our background style.
+  style basic_st=st+bg_style;
+  int bgattr=basic_st.get_attrs();
+
+  if(pre_display_erase)
     {
       bkgd(bgattr);
       erase();

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vscreen_widget.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vscreen_widget.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vscreen_widget.h	Sat Jun  4 17:13:24 2005
@@ -93,20 +93,20 @@
   // This stores the CURRENT size of the widget.
   rect geom;
 
-  // Whether the widget is visible (distinct from whether it has a window;
-  // answers the question "should this widget have a window?")
-  bool visible;
-
   /** The basic style attached to this widget. */
   style bg_style;
 
-  /** A stack of additional styles that have been overlaid (if
-   *  empty, the current style is bg_style).
-   */
-  std::vector<style> style_stack;
+  // Whether the widget is visible (distinct from whether it has a window;
+  // answers the question "should this widget have a window?")
+  bool visible:1;
 
   // Tracks whether or not we have the focus.
-  bool isfocussed;
+  bool isfocussed:1;
+
+  /** If \b true (the default setting), clear this widget with the
+   *  background color before displaying it.
+   */
+  bool pre_display_erase:1;
 
   // Used to set the owner-window without setting the owner.  Used only
   // to handle the toplevel widget (which has a window but no owner)
@@ -118,7 +118,12 @@
 protected:
   cwindow get_win() {return win;}
 
-  virtual void paint()=0;
+  /** Display this widget.
+   *
+   *  \param st the style environment in which the widget is to be
+   *            displayed.
+   */
+  virtual void paint(const style &st)=0;
 
   // Returns true if it consumed the character (otherwise, it'll be processed
   // further)
@@ -216,7 +221,14 @@
   // Makes this widget a child of the given widget (incidentally will delete
   // any allocated size; setting the owner to NULL hides the widget for now)
 
-  void display();
+  /** Display this widget in the given style environment.  This is an
+   *  interface function only; subclasses should override paint() to
+   *  control behavior (but should call display() on subwidgets).
+   *
+   *  \param st the style environment in which this widget should be
+   *  displayed.
+   */
+  void display(const style &st);
 
   int timeout(int msecs);
 
@@ -313,33 +325,28 @@
       return false;
   }
 
-  /** Update this widget's basic style to the given value.  The style
-   *  stack must be empty.
-   */
-  void set_bg_style(const style &new_style);
-
-  /** \return a reference to this widget's current style, valid until
-   *  the widget is destroyed or a style is pushed/popped.
+  /** Enable or disable clearing the background before displaying the
+   *  widget.
+   *
+   *  \param opaque if \b true (the default setting), the widget's
+   *  entire area will be overwritten with its background style prior
+   *  to displaying it.
    */
-  const style &get_current_style() const
+  void set_opaque(bool opaque)
   {
-    if(style_stack.empty())
-      return bg_style;
-    else
-      return style_stack.back();
+    pre_display_erase=opaque;
   }
 
-  /** Apply the given style to the current style, pushing the result
-   *  onto the style stack.  This should only be called from drawing
-   *  routines; other routines should use set_bg_style to set the
-   *  basic style of this widget.
+  /** Update this widget's basic style to the given value.  The style
+   *  stack must be empty.
    */
-  void push_style(const style &new_style);
+  void set_bg_style(const style &new_style);
 
-  /** Pop the most recently pushed style from the style stack (the
-   *  stack must of course be nonempty).
+  /** Set the display attributes of our associated window directly
+   *  from the given style.  (it is expected that subclasses will use
+   *  this to control what is output to the window)
    */
-  void pop_style();
+  void apply_style(const style &st);
 
   typedef std::list<binding_connection>::iterator key_connection;
   // This can be used to connect to a pseudo-signal for keypresses.