Dillo v3.1.1-117-gc0464026
Loading...
Searching...
No Matches
oofposrelmgr.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2015 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 "oofposrelmgr.hh"
21
22using namespace dw::core;
23using namespace lout::object;
24using namespace lout::misc;
25
26namespace dw {
27
28namespace oof {
29
31 OOFPositionedMgr (container)
32{
33 DBG_OBJ_CREATE ("dw::oof::OOFPosRelMgr");
34}
35
40
41
43{
44 DBG_OBJ_ENTER ("resize.oofm", 0, "markSizeChange", "%d", ref);
45 Child *child = children->get(ref);
46 DBG_OBJ_MSGF ("resize.oofm", 1, "generator = %p, externalIndex = %d",
47 child->generator, child->externalIndex);
50}
51
53{
54}
55
57{
58 DBG_OBJ_ENTER ("resize.oofm", 0, "calcWidgetRefSize", "%p", widget);
59
60 widget->sizeRequest (size);
61
62 // In some cases, the widget has been enlarged for widgets out of
63 // flow. Partly, this is done by adding "extra space"; however, at
64 // this point, the extra space is not relevant here. See
65 // "oofawarewidget.cc" for a calculation of RequisitionWithoutOOF.
66 // (Notice also that Widget::sizeRequest has to be called in all
67 // cases.)
68
70 *size = *((OOFAwareWidget*)widget)->getRequisitionWithoutOOF ();
71
72
73 DBG_OBJ_LEAVE_VAL ("%d * (%d + %d)",
74 size->width, size->ascent, size->descent);
75}
76
77
79{
80 DBG_OBJ_ENTER0 ("resize.oofm", 0, "sizeAllocateChildren");
81
82 for (int i = 0; i < children->size (); i++) {
83 Child *child = children->get(i);
84
85 Requisition childReq;
86 child->widget->sizeRequest (&childReq);
87
88 Allocation childAlloc;
89 childAlloc.x = containerAllocation.x + getChildPosX (child);
90 childAlloc.y = containerAllocation.y + getChildPosY (child);
91 childAlloc.width = childReq.width;
92 childAlloc.ascent = childReq.ascent;
93 childAlloc.descent = childReq.descent;
94 child->widget->sizeAllocate (&childAlloc);
95 }
96
98}
99
100void OOFPosRelMgr::getSize (Requisition *containerReq, int *oofWidth,
101 int *oofHeight)
102{
103 DBG_OBJ_ENTER ("resize.oofm", 0, "getSize", "%d * (%d + %d)",
104 containerReq->width, containerReq->ascent,
105 containerReq->descent);
106
107 *oofWidth = *oofHeight = 0;
108
109 for (int i = 0; i < children->size (); i++) {
110 Child *child = children->get(i);
111
112 // Children whose position cannot be determined will be
113 // considered later in sizeAllocateEnd.
114 if (posXDefined (child) && posYDefined (child)) {
115 Requisition childReq;
116 child->widget->sizeRequest (&childReq);
117 *oofWidth = max (*oofWidth, getChildPosX (child) + childReq.width);
118 *oofHeight = max (*oofHeight,
119 getChildPosY (child) + childReq.ascent
120 + childReq.descent);
121
122 child->consideredForSize = true;
123 } else
124 child->consideredForSize = false;
125 }
126
127 DBG_OBJ_LEAVE_VAL ("%d * %d", *oofWidth, *oofHeight);
128}
129
130void OOFPosRelMgr::getExtremes (Extremes *containerExtr, int *oofMinWidth,
131 int *oofMaxWidth)
132{
133 *oofMinWidth = *oofMaxWidth = 0;
134
135 for (int i = 0; i < children->size (); i++) {
136 Child *child = children->get(i);
137
138 // Children whose position cannot be determined will be
139 // considered later in sizeAllocateEnd.
140 if (posXDefined (child)) {
141 Extremes childExtr;
142 child->widget->getExtremes (&childExtr);
143
144 // Put the extremes of the container in relation to the extremes
145 // of the child, as in OOFPosAbsLikeMgr::getExtremes (see
146 // comment there).
147 *oofMinWidth = max (*oofMinWidth,
148 getChildPosX (child, containerExtr->minWidth)
149 + childExtr.minWidth);
150 *oofMaxWidth = max (*oofMaxWidth,
151 getChildPosX (child, containerExtr->maxWidth)
152 + childExtr.maxWidth);
153
154 child->consideredForExtremes = true;
155 } else
156 child->consideredForExtremes = false;
157 }
158}
159
161{
162 return false;
163}
164
166{
167 return false;
168}
169
170int OOFPosRelMgr::getChildPosX (Child *child, int refWidth)
171{
172 DBG_OBJ_ENTER ("resize.oofm", 0, "getChildPosX", "[%p], %d",
173 child->widget, refWidth);
174
175 int gx = generatorPosX (child);
176 int dim = getChildPosDim (child->widget->getStyle()->left,
177 child->widget->getStyle()->right,
178 child->x,
179 refWidth
180 - child->widget->getStyle()->boxDiffWidth ());
181
182 DBG_OBJ_LEAVE_VAL ("%d + %d = %d", gx, dim, gx + dim);
183 return gx + dim;
184}
185
186
187int OOFPosRelMgr::getChildPosY (Child *child, int refHeight)
188{
189 DBG_OBJ_ENTER ("resize.oofm", 0, "getChildPosY", "[%p], %d",
190 child->widget, refHeight);
191
192 int gy = generatorPosY (child);
193 int dim = getChildPosDim (child->widget->getStyle()->top,
194 child->widget->getStyle()->bottom,
195 child->y,
196 refHeight
197 - child->widget->getStyle()->boxDiffHeight ());
198
199 DBG_OBJ_LEAVE_VAL ("%d + %d = %d", gy, dim, gy + dim);
200 return gy + dim;
201}
202
204 style::Length negCssValue, int refPos,
205 int refLength)
206{
207 // posCssValue refers to "left" or "top", negCssValue refers to "right" or
208 // "bottom". The former values are preferred ("left" over "right" etc.),
209 // which should later depend on the CSS value "direction".
210
211 DBG_OBJ_ENTER ("resize.oofm", 0, "getChildPosDim",
212 "<i>%d</i>, <i>%d</i>, %d, %d",
213 posCssValue, negCssValue, refPos, refLength);
214
215 int diff;
216 if (getPosBorder (posCssValue, refLength, &diff))
217 DBG_OBJ_MSGF ("resize.oofm", 1, "posCssValue: diff = %d", diff);
218 else {
219 if (getPosBorder (negCssValue, refLength, &diff)) {
220 DBG_OBJ_MSGF ("resize.oofm", 1, "negCssValue: diff = %d", diff);
221 diff *= -1;
222 } else
223 diff = 0;
224 }
225
226 DBG_OBJ_LEAVE_VAL ("%d + %d = %d", refPos, diff, refPos + diff);
227 return refPos + diff;
228}
229
231{
232 return false;
233}
234
235int OOFPosRelMgr::getAvailWidthOfChild (Widget *child, bool forceValue)
236{
237 notImplemented("OOFPosRelMgr::getAvailWidthOfChild");
238 return 0;
239}
240
241int OOFPosRelMgr::getAvailHeightOfChild (Widget *child, bool forceValue)
242{
243 notImplemented ("OOFPosRelMgr::getAvailHeightOfChild");
244 return 0;
245}
246
247} // namespace oof
248
249} // namespace dw
The base class of all dillo widgets.
Definition widget.hh:44
void sizeAllocate(Allocation *allocation)
Wrapper for Widget::sizeAllocateImpl, calls the latter only when needed.
Definition widget.cc:1209
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
style::Style * getStyle()
Definition widget.hh:482
void getExtremes(Extremes *extremes, int numPos=0, Widget **references=NULL, int *x=NULL, int *y=NULL)
Wrapper for Widget::getExtremesImpl().
Definition widget.cc:1093
Base class for widgets which can act as container and generator for widgets out of flow.
virtual void widgetRefSizeChanged(int externalIndex)
Called by an implementation of dw::oof::OutOfFlowMgr (actually only OOFPosRelMgr) for the generator o...
int getChildPosDim(core::style::Length posCssValue, core::style::Length negCssValue, int refPos, int refLength)
bool posYAbsolute(Child *child)
int getAvailWidthOfChild(core::Widget *child, bool forceValue)
void getExtremes(core::Extremes *containerExtr, int *oofMinWidth, int *oofMaxWidth)
void markExtremesChange(int ref)
bool dealingWithSizeOfChild(core::Widget *child)
void getSize(core::Requisition *containerReq, int *oofWidth, int *oofHeight)
void calcWidgetRefSize(core::Widget *widget, core::Requisition *size)
int getChildPosX(Child *child, int refWidth)
OOFPosRelMgr(OOFAwareWidget *container)
int getChildPosY(Child *child, int refHeight)
int getAvailHeightOfChild(core::Widget *child, bool forceValue)
void markSizeChange(int ref)
bool posXAbsolute(Child *child)
bool posXDefined(Child *child)
bool posYDefined(Child *child)
lout::container::typed::Vector< Child > * children
int generatorPosX(Child *child)
int generatorPosY(Child *child)
bool getPosBorder(core::style::Length cssValue, int refLength, int *result)
core::Allocation containerAllocation
bool instanceOf(int otherClassId)
Returns, whether this class is an instance of the class, given by otherClassId, or of a sub class of ...
Definition identity.cc:105
#define DBG_OBJ_ENTER0(aspect, prio, funname)
#define DBG_OBJ_DELETE()
#define DBG_OBJ_CREATE(klass)
#define DBG_OBJ_MSGF(aspect, prio, fmt,...)
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt,...)
#define DBG_OBJ_LEAVE()
#define DBG_OBJ_LEAVE_VAL(fmt,...)
int Length
Type for representing all lengths within dw::core::style.
Definition style.hh:429
The core of Dw is defined in this namespace.
Definition core.hh:23
Dw is in this namespace, or sub namespaces of this one.
Miscellaneous stuff, which does not fit anywhere else.
Definition misc.cc:31
void notImplemented(const char *name)
Definition misc.hh:76
T max(T a, T b)
Definition misc.hh:41
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