annotate 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
rev   line source
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
1 /*
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
2 * Dillo Widget
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
3 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
5 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
9 * (at your option) any later version.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
10 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
14 * GNU General Public License for more details.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
15 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
972
d7dbd3dcfa38 Updated the GPL copyright note in the source files
Detlef Riekenberg <wine.dev@web.de>
parents: 930
diff changeset
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
18 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
19
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
20
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
21
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
22 #include "fltkviewport.hh"
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
23
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
24 #include <FL/Fl.H>
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
25 #include <FL/fl_draw.H>
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
26
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
27 #include <stdio.h>
772
c1104104babf Added lout/msg.h and normalized debug messages to use it.
Jorge Arellano Cid <jcid@dillo.org>
parents: 347
diff changeset
28 #include "../lout/msg.h"
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
29
1347
4704ad910042 remove "using namespace" statements from header files
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1212
diff changeset
30 using namespace lout;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
31 using namespace lout::object;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
32 using namespace lout::container::typed;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
33
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
34 namespace dw {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
35 namespace fltk {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
36
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
37 FltkViewport::FltkViewport (int X, int Y, int W, int H, const char *label):
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
38 FltkWidgetView (X, Y, W, H, label)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
39 {
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
40 hscrollbar = new Fl_Scrollbar (x (), y (), 1, 1);
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
41 hscrollbar->type(FL_HORIZONTAL);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
42 hscrollbar->callback (hscrollbarCallback, this);
2009
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
43 hscrollbar->hide();
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
44 add (hscrollbar);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
45
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
46 vscrollbar = new Fl_Scrollbar (x (), y(), 1, 1);
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
47 vscrollbar->type(FL_VERTICAL);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
48 vscrollbar->callback (vscrollbarCallback, this);
2009
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
49 vscrollbar->hide();
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
50 add (vscrollbar);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
51
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
52 scrollX = scrollY = scrollDX = scrollDY = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
53 dragScrolling = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
54
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
55 gadgetOrientation[0] = GADGET_HORIZONTAL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
56 gadgetOrientation[1] = GADGET_HORIZONTAL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
57 gadgetOrientation[2] = GADGET_VERTICAL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
58 gadgetOrientation[3] = GADGET_HORIZONTAL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
59
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
60 gadgets =
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
61 new container::typed::List <object::TypedPointer < Fl_Widget> >
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
62 (true);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
63 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
64
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
65 FltkViewport::~FltkViewport ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
66 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
67 delete gadgets;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
68 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
69
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
70 void FltkViewport::adjustScrollbarsAndGadgetsAllocation ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
71 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
72 int hdiff = 0, vdiff = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
73 int visibility = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
74
2009
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
75 _MSG(" >>FltkViewport::adjustScrollbarsAndGadgetsAllocation\n");
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
76 if (hscrollbar->visible ())
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
77 visibility |= 1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
78 if (vscrollbar->visible ())
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
79 visibility |= 2;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
80
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
81 if (gadgets->size () > 0) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
82 switch (gadgetOrientation [visibility]) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
83 case GADGET_VERTICAL:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
84 hdiff = SCROLLBAR_THICKNESS;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
85 vdiff = SCROLLBAR_THICKNESS * gadgets->size ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
86 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
87
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
88 case GADGET_HORIZONTAL:
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
89 hdiff = SCROLLBAR_THICKNESS * gadgets->size ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
90 vdiff = SCROLLBAR_THICKNESS;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
91 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
92 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
93 } else {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
94 hdiff = vscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
95 vdiff = hscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
96 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
97
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
98 hscrollbar->resize(x (), y () + h () - SCROLLBAR_THICKNESS,
1838
d93c6f5e65ac fix scrollbars
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1837
diff changeset
99 w () - hdiff, SCROLLBAR_THICKNESS);
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
100 vscrollbar->resize(x () + w () - SCROLLBAR_THICKNESS, y (),
1838
d93c6f5e65ac fix scrollbars
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1837
diff changeset
101 SCROLLBAR_THICKNESS, h () - vdiff);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
102
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
103 int X = x () + w () - SCROLLBAR_THICKNESS;
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
104 int Y = y () + h () - SCROLLBAR_THICKNESS;
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
105 for (Iterator <TypedPointer < Fl_Widget> > it = gadgets->iterator ();
928
7771cf243ca6 's/if(/if (/g' 's/for(/for (/g' 's/while(/while (/g', and indentation.
Jorge Arellano Cid <jcid@dillo.org>
parents: 772
diff changeset
106 it.hasNext (); ) {
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
107 Fl_Widget *widget = it.getNext()->getTypedValue ();
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
108 widget->resize(x (), y (), SCROLLBAR_THICKNESS, SCROLLBAR_THICKNESS);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
109
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
110 switch (gadgetOrientation [visibility]) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
111 case GADGET_VERTICAL:
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
112 Y -= SCROLLBAR_THICKNESS;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
113 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
114
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
115 case GADGET_HORIZONTAL:
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
116 X -= SCROLLBAR_THICKNESS;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
117 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
118 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
119 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
120 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
121
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
122 void FltkViewport::adjustScrollbarValues ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
123 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
124 hscrollbar->value (scrollX, hscrollbar->w (), 0, canvasWidth);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
125 vscrollbar->value (scrollY, vscrollbar->h (), 0, canvasHeight);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
126 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
127
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
128 void FltkViewport::hscrollbarChanged ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
129 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
130 scroll (hscrollbar->value () - scrollX, 0);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
131 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
132
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
133 void FltkViewport::vscrollbarChanged ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
134 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
135 scroll (0, vscrollbar->value () - scrollY);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
136 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
137
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
138 void FltkViewport::vscrollbarCallback (Fl_Widget *vscrollbar,void *viewportPtr)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
139 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
140 ((FltkViewport*)viewportPtr)->vscrollbarChanged ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
141 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
142
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
143 void FltkViewport::hscrollbarCallback (Fl_Widget *hscrollbar,void *viewportPtr)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
144 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
145 ((FltkViewport*)viewportPtr)->hscrollbarChanged ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
146 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
147
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
148 // ----------------------------------------------------------------------
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
149
1833
5b8f66e6f715 view changes
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1808
diff changeset
150 void FltkViewport::resize(int X, int Y, int W, int H)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
151 {
1837
5e2048737b54 Fl_Group::resize() before adjustScrollbarsAndGadgetsAllocation()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1833
diff changeset
152 bool dimension_changed = W != w() || H != h();
5e2048737b54 Fl_Group::resize() before adjustScrollbarsAndGadgetsAllocation()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1833
diff changeset
153
5e2048737b54 Fl_Group::resize() before adjustScrollbarsAndGadgetsAllocation()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1833
diff changeset
154 Fl_Group::resize(X, Y, W, H);
5e2048737b54 Fl_Group::resize() before adjustScrollbarsAndGadgetsAllocation()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1833
diff changeset
155 if (dimension_changed) {
1833
5b8f66e6f715 view changes
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1808
diff changeset
156 theLayout->viewportSizeChanged (this, W, H);
5b8f66e6f715 view changes
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1808
diff changeset
157 adjustScrollbarsAndGadgetsAllocation ();
5b8f66e6f715 view changes
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1808
diff changeset
158 }
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
159 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
160
1833
5b8f66e6f715 view changes
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1808
diff changeset
161 void FltkViewport::draw_area (void *data, int x, int y, int w, int h)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
162 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
163 FltkViewport *vp = (FltkViewport*) data;
1833
5b8f66e6f715 view changes
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1808
diff changeset
164 fl_push_clip(x, y, w, h);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
165
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
166 vp->FltkWidgetView::draw ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
167
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
168 for (Iterator <TypedPointer < Fl_Widget> > it = vp->gadgets->iterator();
928
7771cf243ca6 's/if(/if (/g' 's/for(/for (/g' 's/while(/while (/g', and indentation.
Jorge Arellano Cid <jcid@dillo.org>
parents: 772
diff changeset
169 it.hasNext (); ) {
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
170 Fl_Widget *widget = it.getNext()->getTypedValue ();
928
7771cf243ca6 's/if(/if (/g' 's/for(/for (/g' 's/while(/while (/g', and indentation.
Jorge Arellano Cid <jcid@dillo.org>
parents: 772
diff changeset
171 vp->draw_child (*widget);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
172 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
173
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
174 fl_pop_clip();
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
175
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
176 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
177
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
178 void FltkViewport::draw ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
179 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
180 int hdiff = vscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
181 int vdiff = hscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
182 int d = damage();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
183
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
184 if (d & FL_DAMAGE_SCROLL) {
1849
a2e5201f8fe7 fix scroll performance
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1846
diff changeset
185 clear_damage (FL_DAMAGE_SCROLL);
1945
b24a5b73ff10 Made the status bar visible and operative.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1907
diff changeset
186 fl_scroll(x(), y(), w() - hdiff, h() - vdiff,
b24a5b73ff10 Made the status bar visible and operative.
Jorge Arellano Cid <jcid@dillo.org>
parents: 1907
diff changeset
187 -scrollDX, -scrollDY, draw_area, this);
1849
a2e5201f8fe7 fix scroll performance
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1846
diff changeset
188 clear_damage (d & ~FL_DAMAGE_SCROLL);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
189 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
190
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
191 if (d) {
1846
769c8d16469c adjust FltkView to global coordinates in fltk-1.3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1844
diff changeset
192 draw_area(this, x(), y(), w () - hdiff, h () - vdiff);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
193
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
194 if (d == FL_DAMAGE_CHILD) {
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
195 if (hscrollbar->damage ())
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
196 draw_child (*hscrollbar);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
197 if (vscrollbar->damage ())
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
198 draw_child (*vscrollbar);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
199 } else {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
200 draw_child (*hscrollbar);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
201 draw_child (*vscrollbar);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
202 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
203 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
204
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
205 scrollDX = 0;
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
206 scrollDY = 0;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
207 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
208
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
209 int FltkViewport::handle (int event)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
210 {
772
c1104104babf Added lout/msg.h and normalized debug messages to use it.
Jorge Arellano Cid <jcid@dillo.org>
parents: 347
diff changeset
211 _MSG("FltkViewport::handle %d\n", event);
1838
d93c6f5e65ac fix scrollbars
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1837
diff changeset
212
1897
1c43a1bdc29d don't send viewport events to scrollbars while doing middle-click page dragging.
corvid <corvid@lavabit.com>
parents: 1896
diff changeset
213 if (!dragScrolling &&
1996
e80effb57d8a check scrollbar visibility before sending it events
corvid <corvid@lavabit.com>
parents: 1946
diff changeset
214 ((vscrollbar->visible() && Fl::event_inside(vscrollbar)) ||
e80effb57d8a check scrollbar visibility before sending it events
corvid <corvid@lavabit.com>
parents: 1946
diff changeset
215 (hscrollbar->visible() && Fl::event_inside(hscrollbar))))
1896
48dd3b970e4b use Fl_Group::handle() to pass events to scrollbars
corvid <corvid@lavabit.com>
parents: 1850
diff changeset
216 return Fl_Group::handle(event);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
217
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
218 switch(event) {
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
219 case FL_KEYBOARD:
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
220 /* Tell fltk we want to receive KEYBOARD events as SHORTCUT.
1209
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
221 * As we don't know the exact keybindings set by the user, we ask
1790
45b10f359e51 keys and mouse buttons
corvid <corvid@lavabit.com>
parents: 1674
diff changeset
222 * for all of them (except Tab to keep form navigation). */
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
223 if (Fl::event_key() != FL_Tab)
1209
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
224 return 0;
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
225 break;
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
226
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
227 case FL_FOCUS:
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
228 /** \bug Draw focus box. */
1673
cde7dddff1e7 fix focus handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
229 break;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
230
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
231 case FL_UNFOCUS:
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
232 /** \bug Undraw focus box. */
1673
cde7dddff1e7 fix focus handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1347
diff changeset
233 break;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
234
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
235 case FL_PUSH:
1907
5f92140e4bce view and form widget focusing
corvid <corvid@lavabit.com>
parents: 1901
diff changeset
236 if (FltkWidgetView::handle (event) == 0 &&
5f92140e4bce view and form widget focusing
corvid <corvid@lavabit.com>
parents: 1901
diff changeset
237 Fl::event_button() == FL_MIDDLE_MOUSE) {
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
238 /* pass event so that middle click can open link in new window */
1907
5f92140e4bce view and form widget focusing
corvid <corvid@lavabit.com>
parents: 1901
diff changeset
239 dragScrolling = 1;
5f92140e4bce view and form widget focusing
corvid <corvid@lavabit.com>
parents: 1901
diff changeset
240 dragX = Fl::event_x();
5f92140e4bce view and form widget focusing
corvid <corvid@lavabit.com>
parents: 1901
diff changeset
241 dragY = Fl::event_y();
5f92140e4bce view and form widget focusing
corvid <corvid@lavabit.com>
parents: 1901
diff changeset
242 setCursor (core::style::CURSOR_MOVE);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
243 }
1907
5f92140e4bce view and form widget focusing
corvid <corvid@lavabit.com>
parents: 1901
diff changeset
244 return 1;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
245 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
246
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
247 case FL_DRAG:
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
248 if (Fl::event_button() == FL_MIDDLE_MOUSE) {
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
249 if (dragScrolling) {
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
250 scroll(dragX - Fl::event_x(), dragY - Fl::event_y());
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
251 dragX = Fl::event_x();
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
252 dragY = Fl::event_y();
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
253 return 1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
254 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
255 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
256 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
257
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
258 case FL_MOUSEWHEEL:
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
259 return (Fl::event_dx() ? hscrollbar : vscrollbar)->handle(event);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
260 break;
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
261
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
262 case FL_RELEASE:
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
263 if (Fl::event_button() == FL_MIDDLE_MOUSE) {
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
264 dragScrolling = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
265 setCursor (core::style::CURSOR_DEFAULT);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
266 }
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
267 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
268
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
269 case FL_ENTER:
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
270 /* could be the result of, e.g., closing another window. */
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
271 mouse_x = Fl::event_x();
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
272 mouse_y = Fl::event_y();
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
273 positionChanged();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
274 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
275
1791
corvid <corvid@lavabit.com>
parents: 1790
diff changeset
276 case FL_LEAVE:
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
277 mouse_x = mouse_y = -1;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
278 break;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
279 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
280
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
281 return FltkWidgetView::handle (event);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
282 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
283
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
284 // ----------------------------------------------------------------------
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
285
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
286 void FltkViewport::setCanvasSize (int width, int ascent, int descent)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
287 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
288 FltkWidgetView::setCanvasSize (width, ascent, descent);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
289 adjustScrollbarValues ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
290 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
291
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
292 /*
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
293 * This is used to simulate mouse motion (e.g., when scrolling).
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
294 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
295 void FltkViewport::positionChanged ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
296 {
1946
217ce29096c3 no motionNotify when drag scrolling
corvid <corvid@lavabit.com>
parents: 1945
diff changeset
297 if (mouse_x != -1 && dragScrolling == false)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
298 (void)theLayout->motionNotify (this,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
299 translateViewXToCanvasX (mouse_x),
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
300 translateViewYToCanvasY (mouse_y),
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
301 (core::ButtonState)0);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
302 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
303
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
304 /*
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
305 * For scrollbars, this currently sets the same step to both vertical and
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
306 * horizontal. It may me differentiated if necessary.
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
307 */
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
308 void FltkViewport::setScrollStep(int step)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
309 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
310 vscrollbar->linesize(step);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
311 hscrollbar->linesize(step);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
312 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
313
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
314 bool FltkViewport::usesViewport ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
315 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
316 return true;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
317 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
318
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
319 int FltkViewport::getHScrollbarThickness ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
320 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
321 return SCROLLBAR_THICKNESS;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
322 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
323
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
324 int FltkViewport::getVScrollbarThickness ()
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
325 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
326 return SCROLLBAR_THICKNESS;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
327 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
328
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
329 void FltkViewport::scrollTo (int x, int y)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
330 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
331 int hdiff = vscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
332 int vdiff = hscrollbar->visible () ? SCROLLBAR_THICKNESS : 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
333
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
334 x = misc::min (x, canvasWidth - w() + hdiff);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
335 x = misc::max (x, 0);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
336
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
337 y = misc::min (y, canvasHeight - h() + vdiff);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
338 y = misc::max (y, 0);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
339
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
340 if (x == scrollX && y == scrollY) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
341 return;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
342 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
343
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
344 /* multiple calls to scroll can happen before a redraw occurs.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
345 * scrollDX / scrollDY can therefore be non-zero here.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
346 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
347 updateCanvasWidgets (x - scrollX, y - scrollY);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
348 scrollDX += x - scrollX;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
349 scrollDY += y - scrollY;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
350
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
351 scrollX = x;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
352 scrollY = y;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
353
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
354 adjustScrollbarValues ();
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
355 damage(FL_DAMAGE_SCROLL);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
356 theLayout->scrollPosChanged (this, scrollX, scrollY);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
357 positionChanged();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
358 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
359
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
360 void FltkViewport::scroll (int dx, int dy)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
361 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
362 scrollTo (scrollX + dx, scrollY + dy);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
363 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
364
1209
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
365 void FltkViewport::scroll (core::ScrollCommand cmd)
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
366 {
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
367 if (cmd == core::SCREEN_UP_CMD) {
1901
249bbc275f58 a little overlap when paging up/down
corvid <corvid@lavabit.com>
parents: 1897
diff changeset
368 scroll (0, -h () + vscrollbar->linesize ());
1209
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
369 } else if (cmd == core::SCREEN_DOWN_CMD) {
1901
249bbc275f58 a little overlap when paging up/down
corvid <corvid@lavabit.com>
parents: 1897
diff changeset
370 scroll (0, h () - vscrollbar->linesize ());
1209
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
371 } else if (cmd == core::LINE_UP_CMD) {
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
372 scroll (0, (int) -vscrollbar->linesize ());
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
373 } else if (cmd == core::LINE_DOWN_CMD) {
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
374 scroll (0, (int) vscrollbar->linesize ());
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
375 } else if (cmd == core::LEFT_CMD) {
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
376 scroll ((int) -hscrollbar->linesize (), 0);
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
377 } else if (cmd == core::RIGHT_CMD) {
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
378 scroll ((int) hscrollbar->linesize (), 0);
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
379 } else if (cmd == core::TOP_CMD) {
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
380 scrollTo (scrollX, 0);
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
381 } else if (cmd == core::BOTTOM_CMD) {
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
382 scrollTo (scrollX, canvasHeight); /* gets adjusted in scrollTo () */
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
383 }
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
384 }
6b35322fb5f2 keybindings for scrolling
corvid <corvid@lavabit.com>
parents: 972
diff changeset
385
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
386 void FltkViewport::setViewportSize (int width, int height,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
387 int hScrollbarThickness,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
388 int vScrollbarThickness)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
389 {
2009
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
390 int adjustReq =
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
391 (hscrollbar->visible() ? !hScrollbarThickness : hScrollbarThickness) ||
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
392 (vscrollbar->visible() ? !vScrollbarThickness : vScrollbarThickness);
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
393
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
394 _MSG("FltkViewport::setViewportSize old_w,old_h=%dx%d -> w,h=%dx%d\n"
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
395 "\t hThick=%d hVis=%d, vThick=%d vVis=%d, adjustReq=%d\n",
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
396 w(),h(),width,height,
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
397 hScrollbarThickness,hscrollbar->visible(),
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
398 vScrollbarThickness,vscrollbar->visible(), adjustReq);
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
399
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
400 (hScrollbarThickness > 0) ? hscrollbar->show () : hscrollbar->hide ();
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
401 (vScrollbarThickness > 0) ? vscrollbar->show () : vscrollbar->hide ();
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
402
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
403 /* If no scrollbar, go to the beginning */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
404 scroll(hScrollbarThickness ? 0 : -scrollX,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
405 vScrollbarThickness ? 0 : -scrollY);
2009
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
406
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
407 /* Adjust when scrollbar visibility changes */
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
408 if (adjustReq)
234097ef5e23 Bug fix: resize the viewport internally (when attached to a layout)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1996
diff changeset
409 adjustScrollbarsAndGadgetsAllocation ();
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
410 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
411
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
412 void FltkViewport::updateCanvasWidgets (int dx, int dy)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
413 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
414 // scroll all child widgets except scroll bars
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
415 for (int i = children () - 1; i > 0; i--) {
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
416 Fl_Widget *widget = child (i);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
417
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 928
diff changeset
418 if (widget == hscrollbar || widget == vscrollbar)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
419 continue;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
420
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
421 widget->position(widget->x () - dx, widget->y () - dy);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
422 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
423 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
424
1850
dd9528825b2f view coordinates are now relative to the window (standard with fltk-1.3)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1849
diff changeset
425 int FltkViewport::translateViewXToCanvasX (int X)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
426 {
1850
dd9528825b2f view coordinates are now relative to the window (standard with fltk-1.3)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1849
diff changeset
427 return X - x () + scrollX;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
428 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
429
1850
dd9528825b2f view coordinates are now relative to the window (standard with fltk-1.3)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1849
diff changeset
430 int FltkViewport::translateViewYToCanvasY (int Y)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
431 {
1850
dd9528825b2f view coordinates are now relative to the window (standard with fltk-1.3)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1849
diff changeset
432 return Y - y () + scrollY;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
433 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
434
1850
dd9528825b2f view coordinates are now relative to the window (standard with fltk-1.3)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1849
diff changeset
435 int FltkViewport::translateCanvasXToViewX (int X)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
436 {
1850
dd9528825b2f view coordinates are now relative to the window (standard with fltk-1.3)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1849
diff changeset
437 return X + x () - scrollX;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
438 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
439
1850
dd9528825b2f view coordinates are now relative to the window (standard with fltk-1.3)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1849
diff changeset
440 int FltkViewport::translateCanvasYToViewY (int Y)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
441 {
1850
dd9528825b2f view coordinates are now relative to the window (standard with fltk-1.3)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1849
diff changeset
442 return Y + y () - scrollY;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
443 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
444
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
445 // ----------------------------------------------------------------------
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
446
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
447 void FltkViewport::setGadgetOrientation (bool hscrollbarVisible,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
448 bool vscrollbarVisible,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
449 FltkViewport::GadgetOrientation
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
450 gadgetOrientation)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
451 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
452 this->gadgetOrientation[(hscrollbarVisible ? 0 : 1) |
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
453 (vscrollbarVisible ? 0 : 2)] = gadgetOrientation;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
454 adjustScrollbarsAndGadgetsAllocation ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
455 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
456
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
457 void FltkViewport::addGadget (Fl_Widget *gadget)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
458 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
459 /** \bug Reparent? */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
460
1808
392d177f0643 some fltkviewport
corvid <corvid@lavabit.com>
parents: 1792
diff changeset
461 gadgets->append (new TypedPointer < Fl_Widget> (gadget));
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
462 adjustScrollbarsAndGadgetsAllocation ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
463 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
464
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
465
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
466 } // namespace fltk
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
467 } // namespace dw