Author: spitzak
Date: 2007-06-19 13:49:29 -0400 (Tue, 19 Jun 2007)
New Revision: 5915
Log:
Finally fixed ancient bug where calling Group::resize() before it is
first shown or layout() is called does not produce the same result as
afterwards. Removed older fix that went into an infinite recursion if
called from layout().


Modified:
   trunk/fltk/Group.h
   trunk/src/Group.cxx

Modified: trunk/fltk/Group.h
===================================================================
--- trunk/fltk/Group.h  2007-06-18 13:08:57 UTC (rev 5914)
+++ trunk/fltk/Group.h  2007-06-19 17:49:29 UTC (rev 5915)
@@ -71,8 +71,6 @@
   Widget* resizable() const {return resizable_;}
   void add_resizable(Widget& o) {resizable_ = &o; add(o);}
   void init_sizes();
-  bool resize(int,int,int,int) ;
-  bool resize(int w, int h) {return resize(x(),y(),w,h);}
 
   void focus_index(int v) {focus_index_ = v;}
   void set_focus(Widget* w) {focus_index_ = find(w);}
@@ -91,6 +89,7 @@
   void draw_child(Widget&) const;
   void update_child(Widget&) const;
   void draw_outside_label(Widget&) const ;
+  int initial_w, initial_h;
   int* sizes();
   void layout(const Rectangle&, int layout_damage);
 

Modified: trunk/src/Group.cxx
===================================================================
--- trunk/src/Group.cxx 2007-06-18 13:08:57 UTC (rev 5914)
+++ trunk/src/Group.cxx 2007-06-19 17:49:29 UTC (rev 5915)
@@ -94,6 +94,7 @@
   type(GROUP_TYPE);
   style(::group_style);
   align(ALIGN_TOP);
+  init_sizes();
   if (begin) this->begin();
 }
 
@@ -448,44 +449,21 @@
 
     The group remembers the initial size of itself and all it's children,
     so that the layout can be restored even if the group is resized so
-    that some children go to zero or negative sizes. Normally these
-    sizes are calculated the first time layout() is called, though you
-    can do so by calling sizes() directly.
+    that some children go to zero or negative sizes.
 
-    Though this makes sense it often results in unexpected behavior
-    when a program wants to rearrange the child widgets or change the
-    size of a group to surround a new arrangement of child widgets. The
-    widgets tend to snap back to a previous size.
+    This can produce unwanted behavior if you try to rearrange the
+    child widgets yourself, as the next resize will put them right back
+    where they were initially. Call this to make it forget all the
+    saved sizes and reinitialize them during the next layout().
 
-    Calling init_sizes() "resets" the sizes array to the current group
-    and children positions.  Actually it just deletes the sizes array,
-    and it is not recreated until the next time layout is called. Call
-    this if you manually adjust the sizes of the children, or attempt
-    to change the size of the group without wanting the children to scale.
-
     This is automatically done when any child is added or removed.  */
 void Group::init_sizes() {
+  initial_w = w();
+  initial_h = h();
   delete[] sizes_; sizes_ = 0;
-  relayout();
+  //relayout();
 }
 
-/** This non-virtual override is for programs that set up a group's
-    layout and then call resize() on it to set the correct size before
-    it is displayed. What it does is remember the current sizes (the
-    thing the init_sizes() method makes it forget) before calling the
-    normal widget resize().
-
-    This is a non-virtual override because in normal use fltk will call
-    layout() anyway before any use of the widget, and Group's layout()
-    initializes the sizes. This is only for programs that use resize()
-    directly.
-*/
-bool Group::resize(int x, int y, int w, int h) {
-  if (!sizes_ && resizable() && children_ && (w != this->w() || h != 
this->h()))
-    layout(); // this is needed to recursively get inner groups...
-  return Widget::resize(x,y,w,h);
-}
-
 /** Returns array of initial sizes of the widget and it's children.
 
     The sizes() array stores the initial positions of widgets as
@@ -504,9 +482,9 @@
     int* p = sizes_ = new int[4*(children_+2)];
     // first thing in sizes array is the group's size:
     p[0] = x();
-    p[1] = w();
+    p[1] = initial_w;
     p[2] = y();
-    p[3] = h();
+    p[3] = initial_h;
     // next is the resizable's size:
     p[4] = 0; // init to the group's size
     p[5] = p[1];
@@ -537,6 +515,10 @@
 
 void Group::layout() {
   int layout_damage = this->layout_damage();
+  if (!sizes_) {
+    if (!(layout_damage&LAYOUT_W)) initial_w = w();
+    if (!(layout_damage&LAYOUT_H)) initial_h = h();
+  }
   if (resizable() && layout_damage&(LAYOUT_WH|LAYOUT_DAMAGE))
     layout_damage |= LAYOUT_WH;
   else

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

Reply via email to