Author: greg.ercolano
Date: 2009-04-01 23:44:34 -0700 (Wed, 01 Apr 2009)
New Revision: 6737
Log:

Fl_Browser mods for scrollbar sizing

        1) Moved Fl::scrollbar_size() implementation from Fl_Browser_ to Fl::

        2) Modified Fl_Browser as per fltk.dev discussions:

                * Deprecate Fl_Browser scrollbar_width() method
                * Introduce Fl_Browser scrollbar_size() method with global 
fallback behavior
                * Docs for above

Todo: Make similar changes to other scrollbar oriented widgets



Modified:
   branches/branch-1.3/FL/Fl.H
   branches/branch-1.3/FL/Fl_Browser_.H
   branches/branch-1.3/src/Fl.cxx
   branches/branch-1.3/src/Fl_Browser_.cxx

Modified: branches/branch-1.3/FL/Fl.H
===================================================================
--- branches/branch-1.3/FL/Fl.H 2009-04-02 01:19:25 UTC (rev 6736)
+++ branches/branch-1.3/FL/Fl.H 2009-04-02 06:44:34 UTC (rev 6737)
@@ -124,6 +124,7 @@
   static Fl_Image* scheme_bg_;
 
   static int e_original_keysym; // late addition
+  static int scrollbar_size_;
 #endif
 
 

Modified: branches/branch-1.3/FL/Fl_Browser_.H
===================================================================
--- branches/branch-1.3/FL/Fl_Browser_.H        2009-04-02 01:19:25 UTC (rev 
6736)
+++ branches/branch-1.3/FL/Fl_Browser_.H        2009-04-02 06:44:34 UTC (rev 
6737)
@@ -37,6 +37,7 @@
 #include "Fl_Group.H"
 #endif
 #include "Fl_Scrollbar.H"
+#include <FL/Fl.H>             // Fl::scrollbar_size()
 
 #define FL_NORMAL_BROWSER      0       /**< type() of Fl_Browser */
 #define FL_SELECT_BROWSER      1       /**< type() of FL_Select_Browser */
@@ -78,9 +79,8 @@
   void* selection_;    // which is selected (except for FL_MULTI_BROWSER)
   void *redraw1,*redraw2; // minimal update pointers
   void* max_width_item;        // which item has max_width_
+  int scrollbar_size_; // size of scrollbar trough
 
-  static int scrollbar_width_;
-
   void update_top();
 
 protected:
@@ -304,15 +304,61 @@
   void textcolor(unsigned col) { textcolor_ = col; }
 
   /**
-    Gets the current width of scrollbars in pixels.
+    Gets the current size of the scrollbars' troughs, in pixels.
+
+    If this value is zero (default), this widget will use the 
+    Fl::scrollbar_size() value as the scrollbar's width.
+  
+    \returns Scrollbar size in pixels, or 0 if the global Fl::scrollsize() is 
being used.
+    \see Fl::scrollbar_size(int)
   */
-  static int scrollbar_width() { return scrollbar_width_; }
+  int scrollbar_size() const {
+      return(scrollbar_size_);
+  }
   /**
-    Sets the width of scrollbars to pixel size \p width.
+    Sets the pixel size of the scrollbars' troughs to the \p size, in pixels.
+
+    Normally you should not need this method, and should use
+    Fl::scrollbar_size(int) instead to manage the size of ALL 
+    your widgets' scrollbars. This ensures your application 
+    has a consistent UI, is the default behavior, and is normally
+    what you want.
+
+    Only use THIS method if you really need to override the global
+    scrollbar size. The need for this should be rare.
+    
+    Setting \p size to the special value of 0 causes the widget to
+    track the global Fl::scrollbar_size(), which is the default.
+    
+    \param[in] size Sets the scrollbar size in pixels.\n
+                    If 0 (default), scrollbar size tracks the global 
Fl::scrollbar_size()
+    \see Fl::scrollbar_size()
   */
-  static void scrollbar_width(int width) { scrollbar_width_ = width; }
-
+  void scrollbar_size(int size) {
+      scrollbar_size_ = size;
+  }   
   /**
+    This method has been deprecated, existing for backwards compatibility only.
+    Use scrollbar_size() instead.
+    This method always returns the global value Fl::scrollbar_size().
+    \returns Always returns the global value Fl::scrollbar_size().
+    \todo This method should eventually be removed in 1.4+
+  */
+  int scrollbar_width() const {
+      return(Fl::scrollbar_size());
+  }
+  /**
+    This method has been deprecated, existing for backwards compatibility only.
+    Use scrollbar_size(int) instead.
+    This method sets the global Fl::scrollbar_size(), and forces this
+    instance of the widget to use it.
+    \todo This method should eventually be removed in 1.4+
+  */
+  void scrollbar_width(int width) {
+      Fl::scrollbar_size(width);
+      scrollbar_size_ = 0;
+  }
+  /**
     Moves the vertical scrollbar to the righthand side of the list.
     For back compatibility.
   */

Modified: branches/branch-1.3/src/Fl.cxx
===================================================================
--- branches/branch-1.3/src/Fl.cxx      2009-04-02 01:19:25 UTC (rev 6736)
+++ branches/branch-1.3/src/Fl.cxx      2009-04-02 06:44:34 UTC (rev 6737)
@@ -73,7 +73,9 @@
                Fl::e_clicks,
                Fl::e_is_click,
                Fl::e_keysym,
-                Fl::e_original_keysym;
+                Fl::e_original_keysym,
+               Fl::scrollbar_size_ = 16;
+
 char           *Fl::e_text = (char *)"";
 int            Fl::e_length;
 int            Fl::visible_focus_ = 1,
@@ -99,8 +101,32 @@
   return FL_VERSION;
 }
 
+/**
+  Gets the default scrollbar size used by 
+  Fl_Browser_,
+  Fl_Help_View,
+  Fl_Scroll, and
+  Fl_Text_Display widgets.
+  \returns The default size for widget scrollbars, in pixels.
+*/
+int Fl::scrollbar_size() {
+  return scrollbar_size_;
+}
 
 /**
+  Sets the default scrollbar size that is used by the
+  Fl_Browser_,
+  Fl_Help_View,
+  Fl_Scroll, and
+  Fl_Text_Display widgets.
+  \param[in] W The new default size for widget scrollbars, in pixels.
+*/
+void Fl::scrollbar_size(int W) {
+  scrollbar_size_ = W;
+}
+
+
+/**
     Returns whether or not the mouse event is inside the given rectangle.
     Returns non-zero if the current event_x and event_y
     put it inside the widget or inside an arbitrary bounding box.  You

Modified: branches/branch-1.3/src/Fl_Browser_.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Browser_.cxx     2009-04-02 01:19:25 UTC (rev 
6736)
+++ branches/branch-1.3/src/Fl_Browser_.cxx     2009-04-02 06:44:34 UTC (rev 
6737)
@@ -67,36 +67,6 @@
   ((Fl_Browser_*)(s->parent()))->hposition(int(((Fl_Scrollbar*)s)->value()));
 }
 
-// Scrollbar size should be part of the Fl class, but is left here for
-// binary compatibility in 1.1.x - M. Sweet
-int Fl_Browser_::scrollbar_width_ = 16;
-
-/**
-  Gets the default scrollbar size used by 
-  Fl_Browser_,
-  Fl_Help_View,
-  Fl_Scroll, and
-  Fl_Text_Display widgets.
-  \returns The default size for widget scrollbars, in pixels.
-  \todo The source code for this method needs to be moved from Fl_Browser_.cxx 
to Fl.cxx
-*/
-int Fl::scrollbar_size() {
-  return Fl_Browser_::scrollbar_width();
-}
-
-/**
-  Sets the default scrollbar size that is used by the
-  Fl_Browser_,
-  Fl_Help_View,
-  Fl_Scroll, and
-  Fl_Text_Display widgets.
-  \param[in] W The new default size for widget scrollbars, in pixels.
-  \todo The source code for this method needs to be moved from Fl_Browser_.cxx 
to Fl.cxx
-*/
-void Fl::scrollbar_size(int W) {
-  Fl_Browser_::scrollbar_width(W);
-}
-
 // return where to draw the actual box:
 /**
   Returns the bounding box for the interior of the list's display window, 
inside
@@ -105,19 +75,20 @@
                       (The original contents of these parameters are 
overwritten)
 */
 void Fl_Browser_::bbox(int& X, int& Y, int& W, int& H) const {
+  int scrollsize = scrollbar_size_ ? scrollbar_size_ : Fl::scrollbar_size();
   Fl_Boxtype b = box() ? box() : FL_DOWN_BOX;
   X = x()+Fl::box_dx(b);
   Y = y()+Fl::box_dy(b);
   W = w()-Fl::box_dw(b);
   H = h()-Fl::box_dh(b);
   if (scrollbar.visible()) {
-    W -= scrollbar_width_;
-    if (scrollbar.align() & FL_ALIGN_LEFT) X += scrollbar_width_;
+    W -= scrollsize;
+    if (scrollbar.align() & FL_ALIGN_LEFT) X += scrollsize;
   }
   if (W < 0) W = 0;
   if (hscrollbar.visible()) {
-    H -= scrollbar_width_;
-    if (scrollbar.align() & FL_ALIGN_TOP) Y += scrollbar_width_;
+    H -= scrollsize;
+    if (scrollbar.align() & FL_ALIGN_TOP) Y += scrollsize;
   }
   if (H < 0) H = 0;
 }
@@ -141,15 +112,16 @@
   \param[in] X,Y,W,H The new position and size for the browser, in pixels.
 */
 void Fl_Browser_::resize(int X, int Y, int W, int H) {
+  int scrollsize = scrollbar_size_ ? scrollbar_size_ : Fl::scrollbar_size();
   Fl_Widget::resize(X, Y, W, H);
   // move the scrollbars so they can respond to events:
   bbox(X,Y,W,H);
   scrollbar.resize(
-       scrollbar.align()&FL_ALIGN_LEFT ? X-scrollbar_width_ : X+W,
-       Y, scrollbar_width_, H);
+       scrollbar.align()&FL_ALIGN_LEFT ? X-scrollsize : X+W,
+       Y, scrollsize, H);
   hscrollbar.resize(
-       X, scrollbar.align()&FL_ALIGN_TOP ? Y-scrollbar_width_ : Y+H,
-       W, scrollbar_width_);
+       X, scrollbar.align()&FL_ALIGN_TOP ? Y-scrollsize : Y+H,
+       W, scrollsize);
 }
 
 // Cause minimal update to redraw the given item:
@@ -483,11 +455,12 @@
   }
 
   // update the scrollbars and redraw them:
+  int scrollsize = scrollbar_size_ ? scrollbar_size_ : Fl::scrollbar_size();
   int dy = top_ ? item_quick_height(top_) : 0; if (dy < 10) dy = 10;
   if (scrollbar.visible()) {
     scrollbar.damage_resize(
-       scrollbar.align()&FL_ALIGN_LEFT ? X-scrollbar_width_ : X+W,
-       Y, scrollbar_width_, H);
+       scrollbar.align()&FL_ALIGN_LEFT ? X-scrollsize : X+W,
+       Y, scrollsize, H);
     scrollbar.value(position_, H, 0, full_height_);
     scrollbar.linesize(dy);
     if (drawsquare) draw_child(scrollbar);
@@ -495,8 +468,8 @@
   }
   if (hscrollbar.visible()) {
     hscrollbar.damage_resize(
-       X, scrollbar.align()&FL_ALIGN_TOP ? Y-scrollbar_width_ : Y+H,
-       W, scrollbar_width_);
+       X, scrollbar.align()&FL_ALIGN_TOP ? Y-scrollsize : Y+H,
+       W, scrollsize);
     hscrollbar.value(hposition_, W, 0, full_width_);
     hscrollbar.linesize(dy);
     if (drawsquare) draw_child(hscrollbar);
@@ -506,7 +479,7 @@
   // draw that little square between the scrollbars:
   if (drawsquare && scrollbar.visible() && hscrollbar.visible()) {
     fl_color(parent()->color());
-    fl_rectf(scrollbar.x(), hscrollbar.y(), scrollbar_width_,scrollbar_width_);
+    fl_rectf(scrollbar.x(), hscrollbar.y(), scrollsize, scrollsize);
   }
 
   real_hposition_ = hposition_;
@@ -964,6 +937,7 @@
   has_scrollbar_ = BOTH;
   max_width = 0;
   max_width_item = 0;
+  scrollbar_size_ = 0;
   redraw1 = redraw2 = 0;
   end();
 }

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to