comparison 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
comparison
equal deleted inserted replaced
2008:0da9d72218ee 2009:234097ef5e23
38 FltkWidgetView (X, Y, W, H, label) 38 FltkWidgetView (X, Y, W, H, label)
39 { 39 {
40 hscrollbar = new Fl_Scrollbar (x (), y (), 1, 1); 40 hscrollbar = new Fl_Scrollbar (x (), y (), 1, 1);
41 hscrollbar->type(FL_HORIZONTAL); 41 hscrollbar->type(FL_HORIZONTAL);
42 hscrollbar->callback (hscrollbarCallback, this); 42 hscrollbar->callback (hscrollbarCallback, this);
43 hscrollbar->hide();
43 add (hscrollbar); 44 add (hscrollbar);
44 45
45 vscrollbar = new Fl_Scrollbar (x (), y(), 1, 1); 46 vscrollbar = new Fl_Scrollbar (x (), y(), 1, 1);
46 vscrollbar->type(FL_VERTICAL); 47 vscrollbar->type(FL_VERTICAL);
47 vscrollbar->callback (vscrollbarCallback, this); 48 vscrollbar->callback (vscrollbarCallback, this);
49 vscrollbar->hide();
48 add (vscrollbar); 50 add (vscrollbar);
49 51
50 scrollX = scrollY = scrollDX = scrollDY = 0; 52 scrollX = scrollY = scrollDX = scrollDY = 0;
51 dragScrolling = 0; 53 dragScrolling = 0;
52 54
68 void FltkViewport::adjustScrollbarsAndGadgetsAllocation () 70 void FltkViewport::adjustScrollbarsAndGadgetsAllocation ()
69 { 71 {
70 int hdiff = 0, vdiff = 0; 72 int hdiff = 0, vdiff = 0;
71 int visibility = 0; 73 int visibility = 0;
72 74
75 _MSG(" >>FltkViewport::adjustScrollbarsAndGadgetsAllocation\n");
73 if (hscrollbar->visible ()) 76 if (hscrollbar->visible ())
74 visibility |= 1; 77 visibility |= 1;
75 if (vscrollbar->visible ()) 78 if (vscrollbar->visible ())
76 visibility |= 2; 79 visibility |= 2;
77 80
382 385
383 void FltkViewport::setViewportSize (int width, int height, 386 void FltkViewport::setViewportSize (int width, int height,
384 int hScrollbarThickness, 387 int hScrollbarThickness,
385 int vScrollbarThickness) 388 int vScrollbarThickness)
386 { 389 {
387 if (hScrollbarThickness > 0) 390 int adjustReq =
388 hscrollbar->show (); 391 (hscrollbar->visible() ? !hScrollbarThickness : hScrollbarThickness) ||
389 else 392 (vscrollbar->visible() ? !vScrollbarThickness : vScrollbarThickness);
390 hscrollbar->hide (); 393
391 if (vScrollbarThickness > 0) 394 _MSG("FltkViewport::setViewportSize old_w,old_h=%dx%d -> w,h=%dx%d\n"
392 vscrollbar->show (); 395 "\t hThick=%d hVis=%d, vThick=%d vVis=%d, adjustReq=%d\n",
393 else 396 w(),h(),width,height,
394 vscrollbar->hide (); 397 hScrollbarThickness,hscrollbar->visible(),
398 vScrollbarThickness,vscrollbar->visible(), adjustReq);
399
400 (hScrollbarThickness > 0) ? hscrollbar->show () : hscrollbar->hide ();
401 (vScrollbarThickness > 0) ? vscrollbar->show () : vscrollbar->hide ();
395 402
396 /* If no scrollbar, go to the beginning */ 403 /* If no scrollbar, go to the beginning */
397 scroll(hScrollbarThickness ? 0 : -scrollX, 404 scroll(hScrollbarThickness ? 0 : -scrollX,
398 vScrollbarThickness ? 0 : -scrollY); 405 vScrollbarThickness ? 0 : -scrollY);
406
407 /* Adjust when scrollbar visibility changes */
408 if (adjustReq)
409 adjustScrollbarsAndGadgetsAllocation ();
399 } 410 }
400 411
401 void FltkViewport::updateCanvasWidgets (int dx, int dy) 412 void FltkViewport::updateCanvasWidgets (int dx, int dy)
402 { 413 {
403 // scroll all child widgets except scroll bars 414 // scroll all child widgets except scroll bars