diff dw/fltkviewport.cc @ 2009:234097ef5e23

Bug fix: resize the viewport internally (when attached to a layout) * It also has a fix for scrollbars resize, and an optimization to avoid scrollbar adjustment overhead.
author Jorge Arellano Cid <jcid@dillo.org>
date Thu, 12 May 2011 07:56:37 -0400
parents e80effb57d8a
children f542084fa707
line wrap: on
line diff
--- a/dw/fltkviewport.cc	Wed May 11 15:41:15 2011 -0400
+++ b/dw/fltkviewport.cc	Thu May 12 07:56:37 2011 -0400
@@ -40,11 +40,13 @@
    hscrollbar = new Fl_Scrollbar (x (), y (), 1, 1);
    hscrollbar->type(FL_HORIZONTAL);
    hscrollbar->callback (hscrollbarCallback, this);
+   hscrollbar->hide();
    add (hscrollbar);
 
    vscrollbar = new Fl_Scrollbar (x (), y(), 1, 1);
    vscrollbar->type(FL_VERTICAL);
    vscrollbar->callback (vscrollbarCallback, this);
+   vscrollbar->hide();
    add (vscrollbar);
 
    scrollX = scrollY = scrollDX = scrollDY = 0;
@@ -70,6 +72,7 @@
    int hdiff = 0, vdiff = 0;
    int visibility = 0;
 
+   _MSG(" >>FltkViewport::adjustScrollbarsAndGadgetsAllocation\n");
    if (hscrollbar->visible ())
       visibility |= 1;
    if (vscrollbar->visible ())
@@ -384,18 +387,26 @@
                                     int hScrollbarThickness,
                                     int vScrollbarThickness)
 {
-   if (hScrollbarThickness > 0)
-      hscrollbar->show ();
-   else
-      hscrollbar->hide ();
-   if (vScrollbarThickness > 0)
-      vscrollbar->show ();
-   else
-      vscrollbar->hide ();
+   int adjustReq =
+      (hscrollbar->visible() ? !hScrollbarThickness : hScrollbarThickness) ||
+      (vscrollbar->visible() ? !vScrollbarThickness : vScrollbarThickness);
+
+   _MSG("FltkViewport::setViewportSize old_w,old_h=%dx%d -> w,h=%dx%d\n"
+       "\t hThick=%d hVis=%d, vThick=%d vVis=%d, adjustReq=%d\n",
+       w(),h(),width,height,
+       hScrollbarThickness,hscrollbar->visible(),
+       vScrollbarThickness,vscrollbar->visible(), adjustReq);
+
+   (hScrollbarThickness > 0) ? hscrollbar->show () : hscrollbar->hide ();
+   (vScrollbarThickness > 0) ? vscrollbar->show () : vscrollbar->hide ();
 
    /* If no scrollbar, go to the beginning */
    scroll(hScrollbarThickness ? 0 : -scrollX,
           vScrollbarThickness ? 0 : -scrollY);
+
+   /* Adjust when scrollbar visibility changes */
+   if (adjustReq)
+      adjustScrollbarsAndGadgetsAllocation ();
 }
 
 void FltkViewport::updateCanvasWidgets (int dx, int dy)