Dillo v3.1.1-111-gd4f56d0d
Loading...
Searching...
No Matches
oofpositionedmgr.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2013-2014 Sebastian Geerken <sgeerken@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "oofpositionedmgr.hh"
21#include "../lout/debug.hh"
22
23using namespace lout::object;
24using namespace lout::container::typed;
25using namespace lout::misc;
26using namespace dw::core;
27using namespace dw::core::style;
28
29namespace dw {
30
31namespace oof {
32
34 int externalIndex)
35{
36 this->widget = widget;
37 this->generator = generator;
38 this->externalIndex = externalIndex;
39
40 x = y = 0;
41
42 // Initially, this child does not actually have been considered,
43 // but since adding a new element will force a size/extremes
44 // calculation, this is equivalent.
46}
47
70
78
80 Allocation *allocation)
81{
82 DBG_OBJ_ENTER ("resize.oofm", 0, "sizeAllocateStart",
83 "%p, (%d, %d, %d * (%d + %d))",
84 caller, allocation->x, allocation->y, allocation->width,
85 allocation->ascent, allocation->descent);
86
87 if (caller == container) {
90 containerAllocation = *allocation;
91 }
92
94}
95
96
98{
99 DBG_OBJ_ENTER ("resize.oofm", 0, "sizeAllocateEnd", "%p", caller);
100
101 if (caller == container) {
103
104 bool extremesChanged = !allChildrenConsideredForExtremes ();
105 if (extremesChanged || doChildrenExceedContainer () ||
107 container->oofSizeChanged (extremesChanged);
108
110 }
111
112 DBG_OBJ_LEAVE ();
113}
114
116{
117 DBG_OBJ_ENTER0 ("resize.oofm", 0, "doChildrenExceedContainer");
118
119 // This method is called to determine whether the *requisition* of
120 // the container must be recalculated. So, we check the allocations
121 // of the children against the *requisition* of the container,
122 // which may (e. g. within tables) differ from the new allocation.
123 // (Generally, a widget may allocated at a different size.)
124
125 Requisition containerReq;
126 container->sizeRequest (&containerReq);
127 bool exceeds = false;
128
130
131 for (int i = 0; i < children->size () && !exceeds; i++) {
132 Child *child = children->get (i);
133 Allocation *childAlloc = child->widget->getAllocation ();
134 DBG_OBJ_MSGF ("resize.oofm", 2,
135 "Does childAlloc = (%d, %d, %d * %d) exceed container "
136 "alloc+req = (%d, %d, %d * %d)?",
137 childAlloc->x, childAlloc->y, childAlloc->width,
138 childAlloc->ascent + childAlloc->descent,
140 containerReq.width,
141 containerReq.ascent + containerReq.descent);
142 if (childAlloc->x + childAlloc->width
143 > containerAllocation.x + containerReq.width ||
144 childAlloc->y + childAlloc->ascent + childAlloc->descent
146 containerReq.ascent + containerReq.descent) {
147 exceeds = true;
148 DBG_OBJ_MSG ("resize.oofm", 2, "Yes.");
149 } else
150 DBG_OBJ_MSG ("resize.oofm", 2, "No.");
151 }
152
154
155 DBG_OBJ_MSGF ("resize.oofm", 1, "=> %s", exceeds ? "true" : "false");
156 DBG_OBJ_LEAVE ();
157
158 return exceeds;
159}
160
162{
163 DBG_OBJ_ENTER0 ("resize", 0, "containerSizeChangedForChildren");
164
165 for (int i = 0; i < children->size(); i++)
166 children->get(i)->widget->containerSizeChanged ();
167
168 DBG_OBJ_LEAVE ();
169}
170
172 DrawingContext *context)
173{
174 DBG_OBJ_ENTER ("draw", 0, "draw", "%d, %d, %d * %d",
175 area->x, area->y, area->width, area->height);
176
177 for (int i = 0; i < children->size(); i++) {
178 Child *child = children->get(i);
179
180 Rectangle childArea;
181 if (!context->hasWidgetBeenProcessedAsInterruption (child->widget) &&
183 child->widget->intersects (container, area, &childArea))
184 child->widget->draw (view, &childArea, context);
185 }
186
187 DBG_OBJ_LEAVE ();
188}
189
191 OOFAwareWidget *parent,
192 int externalIndex)
193{
194}
195
197 int externalIndex)
198{
199 DBG_OBJ_ENTER ("construct.oofm", 0, "addWidgetOOF", "%p, %p, %d",
200 widget, generator, externalIndex);
201
202 Child *child = new Child (widget, generator, externalIndex);
203 children->put (child);
204 childrenByWidget->put (new TypedPointer<Widget> (widget), child);
205
206 int subRef = children->size() - 1;
207 DBG_OBJ_SET_NUM ("children.size", children->size());
208 DBG_OBJ_ARRSET_PTR ("children", children->size() - 1, widget);
209
210 DBG_OBJ_SET_PTR_O (widget, "<Positioned>.generator", generator);
211 DBG_OBJ_SET_NUM_O (widget, "<Positioned>.externalIndex", externalIndex);
212
213 DBG_OBJ_MSGF ("construct.oofm", 1, "=> %d", subRef);
214 DBG_OBJ_LEAVE ();
215 return subRef;
216}
217
219 int oldStartIndex, int diff)
220{
221 for (int i = 0; i < children->size (); i++) {
222 Child *child = children->get (i);
223 if (child->externalIndex >= oldStartIndex) {
224 child->externalIndex += diff;
225 DBG_OBJ_SET_NUM_O (child->widget, "<Positioned>.externalIndex",
226 child->externalIndex);
227 }
228 }
229}
230
232{
233}
234
235
239
242 *context)
243{
244 DBG_OBJ_ENTER ("events", 0, "getWidgetAtPoint", "%d, %d", x, y);
245
246 Widget *widgetAtPoint = NULL;
247
248 for (int i = children->size() - 1; widgetAtPoint == NULL && i >= 0; i--) {
249 Widget *childWidget = children->get(i)->widget;
250 if (!context->hasWidgetBeenProcessedAsInterruption (childWidget) &&
252 widgetAtPoint = childWidget->getWidgetAtPoint (x, y, context);
253 }
254
255 DBG_OBJ_MSGF ("events", 0, "=> %p", widgetAtPoint);
256 DBG_OBJ_LEAVE ();
257
258 return widgetAtPoint;
259}
260
261void OOFPositionedMgr::tellPosition1 (Widget *widget, int x, int y)
262{
263}
264
265void OOFPositionedMgr::tellPosition2 (Widget *widget, int x, int y)
266{
267 DBG_OBJ_ENTER ("resize.oofm", 0, "tellPosition2", "%p, %d, %d",
268 widget, x, y);
269
270 TypedPointer<Widget> key (widget);
271 Child *child = childrenByWidget->get (&key);
272 assert (child);
273
274 child->x = x;
275 child->y = y;
276
277 DBG_OBJ_SET_NUM_O (child->widget, "<Positioned>.x", x);
278 DBG_OBJ_SET_NUM_O (child->widget, "<Positioned>.y", y);
279
280 DBG_OBJ_LEAVE ();
281}
282
284 Widget *widget, int x, int y)
285{
286 // Nothing to do.
287}
288
290 Widget *widget, int x, int y)
291{
292 // TODO
293}
294
296{
297 return true;
298}
299
301 int lastExtIndex)
302{
303 return 0;
304}
305
307 int lastExtIndex)
308{
309 return 0;
310}
311
313 int lastExtIndex)
314{
315 return false;
316}
317
319 int lastExtIndex)
320{
321 return false;
322}
323
324
326 int lastExtIndex)
327{
328 return 0;
329}
330
332 OOFAwareWidget *lastGen,
333 int lastExtIndex)
334{
335 return 0;
336}
337
339{
340 return 0;
341}
342
344{
345 return false;
346}
347
349{
350 return false;
351}
352
354{
355 return false;
356}
357
359{
360 return true;
361}
362
364{
365 return children->size();
366}
367
369{
370 return children->get(i)->widget;
371}
372
373bool OOFPositionedMgr::getPosBorder (style::Length cssValue, int refLength,
374 int *result)
375{
376 if (style::isAbsLength (cssValue)) {
377 *result = style::absLengthVal (cssValue);
378 return true;
379 } else if (style::isPerLength (cssValue)) {
380 *result = style::multiplyWithPerLength (refLength, cssValue);
381 return true;
382 } else
383 // "false" means "undefined":
384 return false;
385}
386
388{
389 for (int i = 0; i < children->size(); i++)
390 if (!children->get(i)->consideredForSize)
391 return false;
392 return true;
393}
394
396{
397 for (int i = 0; i < children->size(); i++)
398 if (!children->get(i)->consideredForExtremes)
399 return false;
400 return true;
401}
402
403} // namespace oof
404
405} // namespace dw
Set at the top when drawing.
Definition types.hh:295
Set at the top when getting the widget at the point.
Definition types.hh:313
dw::core::Shape implemtation for simple rectangles.
Definition types.hh:70
static bool handledByStackingContextMgr(Widget *widget)
bool hasWidgetBeenProcessedAsInterruption(Widget *widget)
Definition types.hh:277
An interface to encapsulate platform dependent drawing.
Definition view.hh:17
The base class of all dillo widgets.
Definition widget.hh:44
Allocation * getAllocation()
Definition widget.hh:484
bool intersects(Widget *refWidget, Rectangle *area, Rectangle *intersection)
Calculates the intersection of the visible allocation (i.
Definition widget.cc:151
virtual void draw(View *view, Rectangle *area, DrawingContext *context)=0
Area is given in widget coordinates.
void sizeRequest(Requisition *requisition, int numPos=0, Widget **references=NULL, int *x=NULL, int *y=NULL)
This method is a wrapper for Widget::sizeRequestImpl(); it calls the latter only when needed.
Definition widget.cc:550
virtual Widget * getWidgetAtPoint(int x, int y, GettingWidgetAtPointContext *context)
Definition widget.cc:223
bool wasAllocated()
Definition widget.hh:475
Base class for widgets which can act as container and generator for widgets out of flow.
virtual void oofSizeChanged(bool extremesChanged)
Called by an implementation of dw::oof::OutOfFlowMgr when the size of the container has changed,...
Child(core::Widget *widget, OOFAwareWidget *generator, int externalIndex)
core::Widget * getWidget(int i)
int getLeftBorder(int y, int h, OOFAwareWidget *lastGen, int lastExtIndex)
Get the left border for the vertical position of y, for a height of h", based on floats; relative to ...
void tellPosition1(core::Widget *widget, int x, int y)
Called before tellPosition2, see there for more.
bool hasFloatRight(int y, int h, OOFAwareWidget *lastGen, int lastExtIndex)
Return whether there is a float on the right side.
lout::container::typed::HashTable< lout::object::TypedPointer< dw::core::Widget >, Child > * childrenByWidget
bool affectsRightBorder(core::Widget *widget)
lout::container::typed::Vector< Child > * children
virtual void sizeAllocateChildren()=0
void addWidgetInFlow(OOFAwareWidget *widget, OOFAwareWidget *parent, int externalIndex)
int getLeftFloatHeight(int y, int h, OOFAwareWidget *lastGen, int lastExtIndex)
Assuming there is a float on the left side, return the rest height of it.
bool affectsLeftBorder(core::Widget *widget)
bool getPosBorder(core::style::Length cssValue, int refLength, int *result)
int addWidgetOOF(core::Widget *widget, OOFAwareWidget *generator, int externalIndex)
core::Allocation containerAllocation
void sizeAllocateEnd(OOFAwareWidget *caller)
enum dw::oof::OOFPositionedMgr::@14 containerAllocationState
int getRightFloatHeight(int y, int h, OOFAwareWidget *lastGen, int lastExtIndex)
Assuming there is a float on the right side, return the rest height of it.
void draw(core::View *view, core::Rectangle *area, core::DrawingContext *context)
void tellPosition2(core::Widget *widget, int x, int y)
Called after tellPosition1.
OOFPositionedMgr(OOFAwareWidget *container)
int getRightBorder(int y, int h, OOFAwareWidget *lastGen, int lastExtIndex)
Get the right border for the vertical position of y, for a height of h, based on floats; relative to ...
int getClearPosition(OOFAwareWidget *widget)
Return value is relative to the calling generator (not container).
void tellIncompletePosition1(core::Widget *generator, core::Widget *widget, int x, int y)
void moveExternalIndices(OOFAwareWidget *generator, int oldStartIndex, int diff)
bool hasFloatLeft(int y, int h, OOFAwareWidget *lastGen, int lastExtIndex)
Return whether there is a float on the left side.
bool dealingWithSizeOfChild(core::Widget *child)
void tellIncompletePosition2(core::Widget *generator, core::Widget *widget, int x, int y)
void sizeAllocateStart(OOFAwareWidget *caller, core::Allocation *allocation)
core::Widget * getWidgetAtPoint(int x, int y, core::GettingWidgetAtPointContext *context)
Typed version of container::untyped::HashTable.
Definition container.hh:536
Typed version of container::untyped::Vector.
Definition container.hh:447
A typed version of object::Pointer.
Definition object.hh:116
#define DBG_OBJ_ENTER0(aspect, prio, funname)
#define DBG_OBJ_DELETE()
#define DBG_OBJ_CREATE(klass)
#define DBG_OBJ_MSG_END()
#define DBG_OBJ_MSGF(aspect, prio, fmt,...)
#define DBG_OBJ_SET_NUM(var, val)
#define DBG_OBJ_MSG(aspect, prio, msg)
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt,...)
#define DBG_OBJ_LEAVE()
#define DBG_OBJ_MSG_START()
#define DBG_OBJ_ARRSET_PTR(var, ind, val)
#define DBG_OBJ_SET_NUM_O(obj, var, val)
#define DBG_OBJ_SET_PTR_O(obj, var, val)
Anything related to Dillo Widget styles is defined here.
Definition style.cc:34
int multiplyWithPerLength(int x, Length l)
Multiply an int with a percentage length, returning int.
Definition style.hh:474
int Length
Type for representing all lengths within dw::core::style.
Definition style.hh:429
bool isPerLength(Length l)
Returns true if l is a percentage.
Definition style.hh:446
bool isAbsLength(Length l)
Returns true if l is an absolute length.
Definition style.hh:443
int absLengthVal(Length l)
Returns the value of a length in pixels, as an integer.
Definition style.hh:452
The core of Dw is defined in this namespace.
Definition core.hh:23
Dw is in this namespace, or sub namespaces of this one.
This namespace provides thin wrappers, implemented as C++ templates, to gain type-safety.
Definition container.hh:387
Miscellaneous stuff, which does not fit anywhere else.
Definition misc.cc:31
Here, some common classes (or interfaces) are defined, to standardize the access to other classes.
Definition object.cc:30
Represents the allocation, i.e.
Definition types.hh:164