summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/oofawarewidget.hh8
-rw-r--r--dw/oofposabslikemgr.cc557
-rw-r--r--dw/oofposabslikemgr.hh52
-rw-r--r--dw/oofposabsmgr.cc2
-rw-r--r--dw/oofposfixedmgr.cc2
-rw-r--r--dw/oofpositionedmgr.cc565
-rw-r--r--dw/oofpositionedmgr.hh44
-rw-r--r--dw/oofposrelmgr.cc87
-rw-r--r--dw/oofposrelmgr.hh15
9 files changed, 700 insertions, 632 deletions
diff --git a/dw/oofawarewidget.hh b/dw/oofawarewidget.hh
index 249dfe9a..9ac83eee 100644
--- a/dw/oofawarewidget.hh
+++ b/dw/oofawarewidget.hh
@@ -175,9 +175,6 @@ protected:
void notifySetAsTopLevel();
void notifySetParent();
- int getAvailWidthOfChild (Widget *child, bool forceValue);
- int getAvailHeightOfChild (Widget *child, bool forceValue);
-
void removeChild (Widget *child);
@@ -231,6 +228,11 @@ public:
static inline bool testWidgetOutOfFlow (Widget *widget)
{ return testStyleOutOfFlow (widget->getStyle ()); }
+ // These two methods (which are protected in Widget) are made public
+ // for OOFPosRelMgr.
+ int getAvailWidthOfChild (Widget *child, bool forceValue);
+ int getAvailHeightOfChild (Widget *child, bool forceValue);
+
bool doesWidgetOOFInterruptDrawing (Widget *widget);
void draw (core::View *view, core::Rectangle *area,
diff --git a/dw/oofposabslikemgr.cc b/dw/oofposabslikemgr.cc
index f73b34d2..aed328ee 100644
--- a/dw/oofposabslikemgr.cc
+++ b/dw/oofposabslikemgr.cc
@@ -18,6 +18,10 @@
*/
#include "oofposabslikemgr.hh"
+#include "oofawarewidget.hh"
+
+using namespace dw::core;
+using namespace lout::misc;
namespace dw {
@@ -34,6 +38,559 @@ OOFPosAbsLikeMgr::~OOFPosAbsLikeMgr ()
DBG_OBJ_DELETE ();
}
+void OOFPosAbsLikeMgr::calcWidgetRefSize (Widget *widget, Requisition *size)
+{
+ size->width = size->ascent = size->descent = 0;
+}
+
+void OOFPosAbsLikeMgr::sizeAllocateStart (OOFAwareWidget *caller,
+ Allocation *allocation)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0, "sizeAllocateStart",
+ "%p, (%d, %d, %d * (%d + %d))",
+ caller, allocation->x, allocation->y, allocation->width,
+ allocation->ascent, allocation->descent);
+
+ if (caller == container) {
+ if (containerAllocationState == NOT_ALLOCATED)
+ containerAllocationState = IN_ALLOCATION;
+ containerAllocation = *allocation;
+ }
+
+ DBG_OBJ_LEAVE ();
+}
+
+void OOFPosAbsLikeMgr::sizeAllocateEnd (OOFAwareWidget *caller)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0, "sizeAllocateEnd", "%p", caller);
+
+ if (caller == container) {
+ sizeAllocateChildren ();
+
+ bool sizeChanged = doChildrenExceedContainer ();
+ bool extremesChanged = haveExtremesChanged ();
+
+ // Consider children which were ignored in getSize (see comment
+ // there). The respective widgets were not allocated before if
+ // and only if containerAllocationState == IN_ALLOCATION. For
+ // the generator (and reference widget), this is the case as
+ // long as sizeRequest is immediately followed by sizeAllocate
+ // (as in resizeIdle).
+
+ bool notAllChildrenConsideredBefore = false;
+ for (int i = 0;
+ !notAllChildrenConsideredBefore && i < children->size(); i++)
+ if (!isPosCalculable (children->get(i),
+ containerAllocationState != IN_ALLOCATION))
+ notAllChildrenConsideredBefore = true;
+
+ if (sizeChanged || notAllChildrenConsideredBefore || extremesChanged)
+ container->oofSizeChanged (extremesChanged);
+
+ containerAllocationState = WAS_ALLOCATED;
+ }
+
+ DBG_OBJ_LEAVE ();
+}
+
+void OOFPosAbsLikeMgr::sizeAllocateChildren ()
+{
+ DBG_OBJ_ENTER0 ("resize.oofm", 0, "sizeAllocateChildren");
+
+ int refWidth = container->getAvailWidth (true) - containerBoxDiffWidth ();
+ int refHeight = container->getAvailHeight (true) - containerBoxDiffHeight ();
+
+ for (int i = 0; i < children->size(); i++) {
+ Child *child = children->get (i);
+
+ int x, y, width, ascent, descent;
+ calcPosAndSizeChildOfChild (child, refWidth, refHeight, &x, &y, &width,
+ &ascent, &descent);
+
+ Allocation childAllocation;
+ childAllocation.x = containerAllocation.x + x + containerBoxOffsetX ();
+ childAllocation.y = containerAllocation.y + y + containerBoxOffsetY ();
+ childAllocation.width = width;
+ childAllocation.ascent = ascent;
+ childAllocation.descent = descent;
+
+ child->widget->sizeAllocate (&childAllocation);
+ }
+
+ DBG_OBJ_LEAVE ();
+}
+
+bool OOFPosAbsLikeMgr::doChildrenExceedContainer ()
+{
+ DBG_OBJ_ENTER0 ("resize.oofm", 0, "doChildrenExceedContainer");
+
+ // This method is called to determine whether the *requisition* of
+ // the container must be recalculated. So, we check the allocations
+ // of the children against the *requisition* of the container,
+ // which may (e. g. within tables) differ from the new allocation.
+ // (Generally, a widget may allocated at a different size.)
+
+ Requisition containerReq;
+ container->sizeRequest (&containerReq);
+ bool exceeds = false;
+
+ DBG_OBJ_MSG_START ();
+
+ for (int i = 0; i < children->size () && !exceeds; i++) {
+ Child *child = children->get (i);
+ Allocation *childAlloc = child->widget->getAllocation ();
+ DBG_OBJ_MSGF ("resize.oofm", 2,
+ "Does childAlloc = (%d, %d, %d * %d) exceed container "
+ "alloc+req = (%d, %d, %d * %d)?",
+ childAlloc->x, childAlloc->y, childAlloc->width,
+ childAlloc->ascent + childAlloc->descent,
+ containerAllocation.x, containerAllocation.y,
+ containerReq.width,
+ containerReq.ascent + containerReq.descent);
+ if (childAlloc->x + childAlloc->width
+ > containerAllocation.x + containerReq.width ||
+ childAlloc->y + childAlloc->ascent + childAlloc->descent
+ > containerAllocation.y +
+ containerReq.ascent + containerReq.descent) {
+ exceeds = true;
+ DBG_OBJ_MSG ("resize.oofm", 2, "Yes.");
+ } else
+ DBG_OBJ_MSG ("resize.oofm", 2, "No.");
+ }
+
+ DBG_OBJ_MSG_END ();
+
+ DBG_OBJ_MSGF ("resize.oofm", 1, "=> %s", exceeds ? "true" : "false");
+ DBG_OBJ_LEAVE ();
+
+ return exceeds;
+}
+
+bool OOFPosAbsLikeMgr::haveExtremesChanged ()
+{
+ DBG_OBJ_ENTER0 ("resize.oofm", 0, "haveExtremesChanged");
+
+ Extremes containerExtr;
+ container->getExtremes (&containerExtr);
+ bool changed = false;
+
+ DBG_OBJ_MSG_START ();
+
+ // Search for children which have not yet been considered by
+ // getExtremes(). Cf. sizeAllocateEnd().
+
+ for (int i = 0; i < children->size () && !changed; i++)
+ if (!isHPosCalculable (children->get (i),
+ containerAllocationState == IN_ALLOCATION))
+ changed = true;
+
+ DBG_OBJ_MSG_END ();
+
+ DBG_OBJ_LEAVE_VAL ("%s", boolToStr (changed));
+ return changed;
+}
+
+
+void OOFPosAbsLikeMgr::getSize (Requisition *containerReq, int *oofWidth,
+ int *oofHeight)
+{
+ DBG_OBJ_ENTER0 ("resize.oofm", 0, "getSize");
+
+ *oofWidth = *oofHeight = 0;
+
+ int refWidth = container->getAvailWidth (true);
+ int refHeight = container->getAvailHeight (true);
+
+ for (int i = 0; i < children->size(); i++) {
+ Child *child = children->get(i);
+
+ // The position of a child (which goes into the return value of
+ // this method) can only be determined when the following
+ // condition (if clause) is is fulfilled. Other children will be
+ // considered later in sizeAllocateEnd.
+ if (isPosCalculable (child,
+ containerAllocationState != NOT_ALLOCATED &&
+ child->generator->wasAllocated ())) {
+ int x, y, width, ascent, descent;
+ calcPosAndSizeChildOfChild (child, refWidth, refHeight, &x, &y, &width,
+ &ascent, &descent);
+ *oofWidth = max (*oofWidth, x + width) + containerBoxDiffWidth ();
+ *oofHeight =
+ max (*oofHeight, y + ascent + descent) + containerBoxDiffHeight ();
+ }
+ }
+
+ DBG_OBJ_MSGF ("resize.oofm", 0, "=> %d * %d", *oofWidth, *oofHeight);
+ DBG_OBJ_LEAVE ();
+}
+
+void OOFPosAbsLikeMgr::getExtremes (Extremes *containerExtr, int *oofMinWidth,
+ int *oofMaxWidth)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0, "getExtremes", "(%d / %d), ...",
+ containerExtr->minWidth, containerExtr->maxWidth);
+
+ *oofMinWidth = *oofMaxWidth = 0;
+
+ for (int i = 0; i < children->size(); i++) {
+ Child *child = children->get(i);
+
+ // If clause: see getSize().
+ if (isHPosCalculable (child,
+ containerAllocationState != NOT_ALLOCATED
+ && child->generator->wasAllocated ())) {
+ int x, width;
+ Extremes childExtr;
+ child->widget->getExtremes (&childExtr);
+
+ // Here, we put the extremes of the container in relation to
+ // the extremes of the child, as sizes are put in relation
+ // for calculating the size. In one case, the allocation is
+ // used: when neither "left" nor "right" is set, and so the
+ // position told by the generator is used.
+ //
+ // If you look at the Textblock widget, you'll find that this
+ // is always boxOffsetX(), and the horizontal position of a
+ // textblock within its parent is also constant; so this is
+ // not a problem.
+ //
+ // (TODO What about a table cell within a table?)
+
+ calcHPosAndSizeChildOfChild (child, containerExtr->minWidth,
+ childExtr.minWidth, &x, &width);
+ *oofMinWidth = max (*oofMinWidth, x + width);
+
+ calcHPosAndSizeChildOfChild (child, containerExtr->maxWidth,
+ childExtr.maxWidth, &x, &width);
+ *oofMaxWidth = max (*oofMaxWidth, x + width);
+ }
+ }
+
+ *oofMinWidth += containerBoxDiffWidth ();
+ *oofMaxWidth += containerBoxDiffWidth ();
+
+ DBG_OBJ_MSGF ("resize.oofm", 0, "=> %d / %d", *oofMinWidth, *oofMaxWidth);
+ DBG_OBJ_LEAVE ();
+}
+
+int OOFPosAbsLikeMgr::getAvailWidthOfChild (Widget *child, bool forceValue)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0,
+ "OOFPositionedMgr/getAvailWidthOfChild", "%p, %s",
+ child, forceValue ? "true" : "false");
+
+ int width;
+
+ if (child->getStyle()->width == style::LENGTH_AUTO &&
+ child->getStyle()->minWidth == style::LENGTH_AUTO &&
+ child->getStyle()->maxWidth == style::LENGTH_AUTO) {
+ // TODO This should (perhaps?) only used when 'width' is undefined.
+ // TODO Is "boxDiffWidth()" correct here?
+ DBG_OBJ_MSG ("resize.oofm", 1, "no specification");
+ if (forceValue) {
+ int availWidth = container->getAvailWidth (true);
+ width = max (availWidth - containerBoxDiffWidth ()
+ // Regard an undefined value as 0:
+ - max (getPosLeft (child, availWidth), 0),
+ - max (getPosRight (child, availWidth), 0),
+ 0);
+ } else
+ width = -1;
+ } else {
+ if (forceValue) {
+ int availWidth = container->getAvailWidth (true);
+ child->calcFinalWidth (child->getStyle(),
+ availWidth - containerBoxDiffWidth (), NULL,
+ 0, true, &width);
+ } else
+ width = -1;
+ }
+
+ if (width != -1)
+ width = max (width, child->getMinWidth (NULL, forceValue));
+
+ DBG_OBJ_MSGF ("resize.oofm", 1, "=> %d", width);
+ DBG_OBJ_LEAVE ();
+
+ return width;
+}
+
+int OOFPosAbsLikeMgr::getAvailHeightOfChild (Widget *child, bool forceValue)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0,
+ "OOFPositionedMgr/getAvailHeightOfChild", "%p, %s",
+ child, forceValue ? "true" : "false");
+
+ int height;
+
+ if (child->getStyle()->height == style::LENGTH_AUTO &&
+ child->getStyle()->minHeight == style::LENGTH_AUTO &&
+ child->getStyle()->maxHeight == style::LENGTH_AUTO) {
+ // TODO This should (perhaps?) only used when 'height' is undefined.
+ // TODO Is "boxDiffHeight()" correct here?
+ DBG_OBJ_MSG ("resize.oofm", 1, "no specification");
+ if (forceValue) {
+ int availHeight = container->getAvailHeight (true);
+ height = max (availHeight - containerBoxDiffHeight ()
+ // Regard an undefined value as 0:
+ - max (getPosTop (child, availHeight), 0),
+ - max (getPosBottom (child, availHeight), 0),
+ 0);
+ } else
+ height = -1;
+ } else {
+ if (forceValue) {
+ int availHeight = container->getAvailHeight (true);
+ height = child->calcHeight (child->getStyle()->height, true,
+ availHeight - containerBoxDiffHeight (),
+ NULL, true);
+ } else
+ height = -1;
+ }
+
+ DBG_OBJ_MSGF ("resize.oofm", 1, "=> %d", height);
+ DBG_OBJ_LEAVE ();
+
+ return height;
+}
+
+bool OOFPosAbsLikeMgr::isHPosComplete (Child *child)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0, "isHPosComplete", "[%p]", child->widget);
+ bool b =
+ (style::isAbsLength (child->widget->getStyle()->left) ||
+ style::isPerLength (child->widget->getStyle()->left)) &&
+ (style::isAbsLength (child->widget->getStyle()->right) ||
+ style::isPerLength (child->widget->getStyle()->right));
+ DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
+ return b;
+}
+
+bool OOFPosAbsLikeMgr::isVPosComplete (Child *child)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0, "isVPosComplete", "[%p]", child->widget);
+ bool b =
+ (style::isAbsLength (child->widget->getStyle()->top) ||
+ style::isPerLength (child->widget->getStyle()->top)) &&
+ (style::isAbsLength (child->widget->getStyle()->bottom) ||
+ style::isPerLength (child->widget->getStyle()->bottom));
+ DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
+ return b;
+}
+
+bool OOFPosAbsLikeMgr::isHPosCalculable (Child *child, bool allocated)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0, "isHPosCalculable", "[%p], %s",
+ child->widget, boolToStr (allocated));
+ bool b =
+ allocated || (isHPosComplete (child) && child->reference == container);
+ DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
+ return b;
+}
+
+bool OOFPosAbsLikeMgr::isVPosCalculable (Child *child, bool allocated)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0, "isVPosCalculable", "[%p], %s",
+ child->widget, boolToStr (allocated));
+ bool b =
+ allocated || (isVPosComplete (child) && child->reference == container);
+ DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
+ return b;
+}
+
+bool OOFPosAbsLikeMgr::isPosCalculable (Child *child, bool allocated)
+{
+ DBG_OBJ_ENTER ("resize.oofm", 0, "isPosCalculable", "[%p], %s",
+ child->widget, boolToStr (allocated));
+ bool b = isHPosCalculable (child, allocated) &&
+ isVPosCalculable (child, allocated);
+ DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
+ return b;
+}
+
+void OOFPosAbsLikeMgr::calcPosAndSizeChildOfChild (Child *child, int refWidth,
+ int refHeight, int *xPtr,
+ int *yPtr, int *widthPtr,
+ int *ascentPtr,
+ int *descentPtr)
+{
+ // *xPtr and *yPtr refer to reference area; caller must adjust them.
+
+ DBG_OBJ_ENTER ("resize.oofm", 0, "calcPosAndSizeChildOfChild",
+ "[%p], %d, %d, ...", child->widget, refWidth, refHeight);
+
+ // TODO (i) Consider {min|max}-{width|heigt}. (ii) Height is always
+ // apportioned to descent (ascent is preserved), which makes sense
+ // when the children are textblocks. (iii) Consider minimal width
+ // (getMinWidth)?
+
+ Requisition childRequisition;
+ child->widget->sizeRequest (&childRequisition);
+
+ calcHPosAndSizeChildOfChild (child, refWidth, childRequisition.width,
+ xPtr, widthPtr);
+ calcVPosAndSizeChildOfChild (child, refHeight, childRequisition.ascent,
+ childRequisition.descent, yPtr, ascentPtr,
+ descentPtr);
+
+ DBG_OBJ_LEAVE ();
+}
+
+void OOFPosAbsLikeMgr::calcHPosAndSizeChildOfChild (Child *child, int refWidth,
+ int origChildWidth,
+ int *xPtr, int *widthPtr)
+{
+ assert (refWidth != -1 || (xPtr == NULL && widthPtr == NULL));
+
+ int width;
+ bool widthDefined;
+ if (style::isAbsLength (child->widget->getStyle()->width)) {
+ DBG_OBJ_MSGF ("resize.oofm", 1, "absolute width: %dpx",
+ style::absLengthVal (child->widget->getStyle()->width));
+ width = style::absLengthVal (child->widget->getStyle()->width)
+ + child->widget->boxDiffWidth ();
+ widthDefined = true;
+ } else if (style::isPerLength (child->widget->getStyle()->width)) {
+ DBG_OBJ_MSGF ("resize.oofm", 1, "percentage width: %g%%",
+ 100 * style::perLengthVal_useThisOnlyForDebugging
+ (child->widget->getStyle()->width));
+ width = style::multiplyWithPerLength (refWidth,
+ child->widget->getStyle()->width)
+ + child->widget->boxDiffWidth ();
+ widthDefined = true;
+ } else {
+ DBG_OBJ_MSG ("resize.oofm", 1, "width not specified");
+ width = origChildWidth;
+ widthDefined = false;
+ }
+
+ int left = getPosLeft (child->widget, refWidth),
+ right = getPosRight (child->widget, refWidth);
+ DBG_OBJ_MSGF ("resize.oofm", 1,
+ "=> left = %d, right = %d, width = %d (defined: %s)",
+ left, right, width, widthDefined ? "true" : "false");
+
+ if (xPtr) {
+ if (left == -1 && right == -1) {
+ assert (child->generator == container ||
+ (containerAllocationState != NOT_ALLOCATED
+ && child->generator->wasAllocated ()));
+ *xPtr =
+ child->x + (child->generator == container ? 0 :
+ child->generator->getAllocation()->x
+ - (containerAllocation.x + containerBoxOffsetX ()));
+ } else {
+ assert (child->reference == container ||
+ (containerAllocationState != NOT_ALLOCATED
+ && child->reference->wasAllocated ()));
+ int xBase = child->reference == container ? 0 :
+ child->generator->getAllocation()->x - containerAllocation.x;
+ DBG_OBJ_MSGF ("resize.oofm", 0, "=> xBase = %d", xBase);
+
+ if (left == -1 && right != -1)
+ *xPtr = xBase + refWidth - width - right;
+ else if (left != -1 && right == -1)
+ *xPtr = xBase + left;
+ else {
+ *xPtr = xBase + left;
+ if (!widthDefined) {
+ width = refWidth - (left + right);
+ DBG_OBJ_MSGF ("resize.oofm", 0, "=> width (corrected) = %d",
+ width);
+ }
+ }
+ }
+
+ DBG_OBJ_MSGF ("resize.oofm", 0, "=> x = %d", *xPtr);
+ }
+
+ if (widthPtr)
+ *widthPtr = width;
+}
+
+void OOFPosAbsLikeMgr::calcVPosAndSizeChildOfChild (Child *child, int refHeight,
+ int origChildAscent,
+ int origChildDescent,
+ int *yPtr, int *ascentPtr,
+ int *descentPtr)
+{
+ assert (refHeight != -1 ||
+ (yPtr == NULL && ascentPtr == NULL && descentPtr == NULL));
+
+ int ascent = origChildAscent, descent = origChildDescent;
+ bool heightDefined;
+
+ if (style::isAbsLength (child->widget->getStyle()->height)) {
+ DBG_OBJ_MSGF ("resize.oofm", 1, "absolute height: %dpx",
+ style::absLengthVal (child->widget->getStyle()->height));
+ int height = style::absLengthVal (child->widget->getStyle()->height)
+ + child->widget->boxDiffHeight ();
+ splitHeightPreserveAscent (height, &ascent, &descent);
+ heightDefined = true;
+ } else if (style::isPerLength (child->widget->getStyle()->height)) {
+ DBG_OBJ_MSGF ("resize.oofm", 1, "percentage height: %g%%",
+ 100 * style::perLengthVal_useThisOnlyForDebugging
+ (child->widget->getStyle()->height));
+ int height =
+ style::multiplyWithPerLength (refHeight,
+ child->widget->getStyle()->height)
+ + child->widget->boxDiffHeight ();
+ splitHeightPreserveAscent (height, &ascent, &descent);
+ heightDefined = true;
+ } else {
+ DBG_OBJ_MSG ("resize.oofm", 1, "height not specified");
+ heightDefined = false;
+ }
+
+ int top = getPosTop (child->widget, refHeight),
+ bottom = getPosBottom (child->widget, refHeight);
+ DBG_OBJ_MSGF ("resize.oofm", 1,
+ "=> top = %d, bottom = %d, height = %d + %d (defined: %s)",
+ top, bottom, ascent, descent,
+ heightDefined ? "true" : "false");
+
+ if (yPtr) {
+ if (top == -1 && bottom == -1) {
+ assert (child->generator == container ||
+ (containerAllocationState != NOT_ALLOCATED
+ && child->generator->wasAllocated ()));
+ *yPtr =
+ child->y + (child->generator == container ? 0 :
+ child->generator->getAllocation()->y
+ - (containerAllocation.y + containerBoxOffsetY ()));
+ } else {
+ assert (child->reference == container ||
+ (containerAllocationState != NOT_ALLOCATED
+ && child->reference->wasAllocated ()));
+ int yBase = child->reference == container ? 0 :
+ child->generator->getAllocation()->y - containerAllocation.y;
+ DBG_OBJ_MSGF ("resize.oofm", 0, "=> yBase = %d", yBase);
+
+ if (top == -1 && bottom != -1)
+ *yPtr = yBase + refHeight - (ascent + descent) - bottom;
+ else if (top != -1 && bottom == -1)
+ *yPtr = yBase + top;
+ else {
+ *yPtr = yBase + top;
+ if (!heightDefined) {
+ int height = refHeight - (top + bottom);
+ splitHeightPreserveAscent (height, &ascent, &descent);
+ DBG_OBJ_MSGF ("resize.oofm", 0,
+ "=> ascent + descent (corrected) = %d + %d",
+ ascent, descent);
+ }
+ }
+ }
+
+ DBG_OBJ_MSGF ("resize.oofm", 0, "=> y = %d", *yPtr);
+ }
+
+ if (ascentPtr)
+ *ascentPtr = ascent;
+ if (descentPtr)
+ *descentPtr = descent;
+}
+
} // namespace oof
} // namespace dw
diff --git a/dw/oofposabslikemgr.hh b/dw/oofposabslikemgr.hh
index 0c0e7fef..61c3ed8c 100644
--- a/dw/oofposabslikemgr.hh
+++ b/dw/oofposabslikemgr.hh
@@ -9,9 +9,61 @@ namespace oof {
class OOFPosAbsLikeMgr: public OOFPositionedMgr
{
+protected:
+ virtual int containerBoxOffsetX () = 0;
+ virtual int containerBoxOffsetY () = 0;
+ virtual int containerBoxRestWidth () = 0;
+ virtual int containerBoxRestHeight () = 0;
+
+ inline int containerBoxDiffWidth ()
+ { return containerBoxOffsetX () + containerBoxRestWidth (); }
+ inline int containerBoxDiffHeight ()
+ { return containerBoxOffsetY () + containerBoxRestHeight (); }
+
+ enum { NOT_ALLOCATED, IN_ALLOCATION, WAS_ALLOCATED }
+ containerAllocationState;
+
+
+ bool doChildrenExceedContainer ();
+ bool haveExtremesChanged ();
+ void sizeAllocateChildren ();
+
+ bool isHPosComplete (Child *child);
+ bool isVPosComplete (Child *child);
+
+ bool isHPosCalculable (Child *child, bool allocated);
+ bool isVPosCalculable (Child *child, bool allocated);
+
+ bool isPosCalculable (Child *child, bool allocated);
+
+ void calcPosAndSizeChildOfChild (Child *child, int refWidth, int refHeight,
+ int *xPtr, int *yPtr, int *widthPtr,
+ int *ascentPtr, int *descentPtr);
+ void calcHPosAndSizeChildOfChild (Child *child, int refWidth,
+ int origChildWidth, int *xPtr,
+ int *widthPtr);
+ void calcVPosAndSizeChildOfChild (Child *child, int refHeight,
+ int origChildAscent, int origChildDescent,
+ int *yPtr, int *ascentPtr,
+ int *descentPtr);
+
+
public:
OOFPosAbsLikeMgr (OOFAwareWidget *container);
~OOFPosAbsLikeMgr ();
+
+ void calcWidgetRefSize (core::Widget *widget, core::Requisition *size);
+
+ void sizeAllocateStart (OOFAwareWidget *caller,
+ core::Allocation *allocation);
+ void sizeAllocateEnd (OOFAwareWidget *caller);
+ void getSize (core::Requisition *containerReq, int *oofWidth,
+ int *oofHeight);
+ void getExtremes (core::Extremes *containerExtr,
+ int *oofMinWidth, int *oofMaxWidth);
+
+ int getAvailWidthOfChild (core::Widget *child, bool forceValue);
+ int getAvailHeightOfChild (core::Widget *child, bool forceValue);
};
} // namespace oof
diff --git a/dw/oofposabsmgr.cc b/dw/oofposabsmgr.cc
index a0b8b721..5dc8e7f4 100644
--- a/dw/oofposabsmgr.cc
+++ b/dw/oofposabsmgr.cc
@@ -25,7 +25,7 @@ namespace dw {
namespace oof {
OOFPosAbsMgr::OOFPosAbsMgr (OOFAwareWidget *container) :
- OOFPositionedMgr (container)
+ OOFPosAbsLikeMgr (container)
{
DBG_OBJ_CREATE ("dw::OOFPosAbsMgr");
}
diff --git a/dw/oofposfixedmgr.cc b/dw/oofposfixedmgr.cc
index ea5f9b5c..ef26de41 100644
--- a/dw/oofposfixedmgr.cc
+++ b/dw/oofposfixedmgr.cc
@@ -24,7 +24,7 @@ namespace dw {
namespace oof {
OOFPosFixedMgr::OOFPosFixedMgr (OOFAwareWidget *container) :
- OOFPositionedMgr (container)
+ OOFPosAbsLikeMgr (container)
{
DBG_OBJ_CREATE ("dw::OOFPosFixedMgr");
}
diff --git a/dw/oofpositionedmgr.cc b/dw/oofpositionedmgr.cc
index 270e8c84..1d2248d7 100644
--- a/dw/oofpositionedmgr.cc
+++ b/dw/oofpositionedmgr.cc
@@ -39,8 +39,6 @@ OOFPositionedMgr::OOFPositionedMgr (OOFAwareWidget *container)
children = new Vector<Child> (1, false);
childrenByWidget = new HashTable<TypedPointer<Widget>, Child> (true, true);
- containerAllocationState =
- container->wasAllocated () ? WAS_ALLOCATED : NOT_ALLOCATED;
containerAllocation = *(container->getAllocation());
DBG_OBJ_SET_NUM ("children.size", children->size());
@@ -54,84 +52,6 @@ OOFPositionedMgr::~OOFPositionedMgr ()
DBG_OBJ_DELETE ();
}
-void OOFPositionedMgr::sizeAllocateStart (OOFAwareWidget *caller,
- Allocation *allocation)
-{
- DBG_OBJ_ENTER ("resize.oofm", 0, "sizeAllocateStart",
- "%p, (%d, %d, %d * (%d + %d))",
- caller, allocation->x, allocation->y, allocation->width,
- allocation->ascent, allocation->descent);
-
- if (caller == container) {
- if (containerAllocationState == NOT_ALLOCATED)
- containerAllocationState = IN_ALLOCATION;
- containerAllocation = *allocation;
- }
-
- DBG_OBJ_LEAVE ();
-}
-
-void OOFPositionedMgr::sizeAllocateEnd (OOFAwareWidget *caller)
-{
- DBG_OBJ_ENTER ("resize.oofm", 0, "sizeAllocateEnd", "%p", caller);
-
- if (caller == container) {
- sizeAllocateChildren ();
-
- bool sizeChanged = doChildrenExceedContainer ();
- bool extremesChanged = haveExtremesChanged ();
-
- // Consider children which were ignored in getSize (see comment
- // there). The respective widgets were not allocated before if
- // and only if containerAllocationState == IN_ALLOCATION. For
- // the generator (and reference widget), this is the case as
- // long as sizeRequest is immediately followed by sizeAllocate
- // (as in resizeIdle).
-
- bool notAllChildrenConsideredBefore = false;
- for (int i = 0;
- !notAllChildrenConsideredBefore && i < children->size(); i++)
- if (!isPosCalculable (children->get(i),
- containerAllocationState != IN_ALLOCATION))
- notAllChildrenConsideredBefore = true;
-
- if (sizeChanged || notAllChildrenConsideredBefore || extremesChanged)
- container->oofSizeChanged (extremesChanged);
-
- containerAllocationState = WAS_ALLOCATED;
- }
-
- DBG_OBJ_LEAVE ();
-}
-
-
-void OOFPositionedMgr::sizeAllocateChildren ()
-{
- DBG_OBJ_ENTER0 ("resize.oofm", 0, "sizeAllocateChildren");
-
- int refWidth = container->getAvailWidth (true) - containerBoxDiffWidth ();
- int refHeight = container->getAvailHeight (true) - containerBoxDiffHeight ();
-
- for (int i = 0; i < children->size(); i++) {
- Child *child = children->get (i);
-
- int x, y, width, ascent, descent;
- calcPosAndSizeChildOfChild (child, refWidth, refHeight, &x, &y, &width,
- &ascent, &descent);
-
- Allocation childAllocation;
- childAllocation.x = containerAllocation.x + x + containerBoxOffsetX ();
- childAllocation.y = containerAllocation.y + y + containerBoxOffsetY ();
- childAllocation.width = width;
- childAllocation.ascent = ascent;
- childAllocation.descent = descent;
-
- child->widget->sizeAllocate (&childAllocation);
- }
-
- DBG_OBJ_LEAVE ();
-}
-
void OOFPositionedMgr::containerSizeChangedForChildren ()
{
DBG_OBJ_ENTER0 ("resize", 0, "containerSizeChangedForChildren");
@@ -142,77 +62,6 @@ void OOFPositionedMgr::containerSizeChangedForChildren ()
DBG_OBJ_LEAVE ();
}
-bool OOFPositionedMgr::doChildrenExceedContainer ()
-{
- DBG_OBJ_ENTER0 ("resize.oofm", 0, "doChildrenExceedContainer");
-
- // This method is called to determine whether the *requisition* of
- // the container must be recalculated. So, we check the allocations
- // of the children against the *requisition* of the container,
- // which may (e. g. within tables) differ from the new allocation.
- // (Generally, a widget may allocated at a different size.)
-
- Requisition containerReq;
- container->sizeRequest (&containerReq);
- bool exceeds = false;
-
- DBG_OBJ_MSG_START ();
-
- for (int i = 0; i < children->size () && !exceeds; i++) {
- Child *child = children->get (i);
- Allocation *childAlloc = child->widget->getAllocation ();
- DBG_OBJ_MSGF ("resize.oofm", 2,
- "Does childAlloc = (%d, %d, %d * %d) exceed container "
- "alloc+req = (%d, %d, %d * %d)?",
- childAlloc->x, childAlloc->y, childAlloc->width,
- childAlloc->ascent + childAlloc->descent,
- containerAllocation.x, containerAllocation.y,
- containerReq.width,
- containerReq.ascent + containerReq.descent);
- if (childAlloc->x + childAlloc->width
- > containerAllocation.x + containerReq.width ||
- childAlloc->y + childAlloc->ascent + childAlloc->descent
- > containerAllocation.y +
- containerReq.ascent + containerReq.descent) {
- exceeds = true;
- DBG_OBJ_MSG ("resize.oofm", 2, "Yes.");
- } else
- DBG_OBJ_MSG ("resize.oofm", 2, "No.");
- }
-
- DBG_OBJ_MSG_END ();
-
- DBG_OBJ_MSGF ("resize.oofm", 1, "=> %s", exceeds ? "true" : "false");
- DBG_OBJ_LEAVE ();
-
- return exceeds;
-}
-
-bool OOFPositionedMgr::haveExtremesChanged ()
-{
- DBG_OBJ_ENTER0 ("resize.oofm", 0, "haveExtremesChanged");
-
- Extremes containerExtr;
- container->getExtremes (&containerExtr);
- bool changed = false;
-
- DBG_OBJ_MSG_START ();
-
- // Search for children which have not yet been considered by
- // getExtremes(). Cf. sizeAllocateEnd().
-
- for (int i = 0; i < children->size () && !changed; i++)
- if (!isHPosCalculable (children->get (i),
- containerAllocationState == IN_ALLOCATION))
- changed = true;
-
- DBG_OBJ_MSG_END ();
-
- DBG_OBJ_LEAVE_VAL ("%s", boolToStr (changed));
- return changed;
-}
-
-
void OOFPositionedMgr::draw (View *view, Rectangle *area,
DrawingContext *context)
{
@@ -271,11 +120,6 @@ int OOFPositionedMgr::addWidgetOOF (Widget *widget, OOFAwareWidget *generator,
return subRef;
}
-void OOFPositionedMgr::calcWidgetRefSize (Widget *widget, Requisition *size)
-{
- size->width = size->ascent = size->descent = 0;
-}
-
void OOFPositionedMgr::moveExternalIndices (OOFAwareWidget *generator,
int oldStartIndex, int diff)
{
@@ -337,94 +181,11 @@ void OOFPositionedMgr::tellPosition (Widget *widget, int x, int y)
DBG_OBJ_LEAVE ();
}
-void OOFPositionedMgr::getSize (Requisition *containerReq, int *oofWidth,
- int *oofHeight)
-{
- DBG_OBJ_ENTER0 ("resize.oofm", 0, "getSize");
-
- *oofWidth = *oofHeight = 0;
-
- int refWidth = container->getAvailWidth (true);
- int refHeight = container->getAvailHeight (true);
-
- for (int i = 0; i < children->size(); i++) {
- Child *child = children->get(i);
-
- // The position of a child (which goes into the return value of
- // this method) can only be determined when the following
- // condition (if clause) is is fulfilled. Other children will be
- // considered later in sizeAllocateEnd.
- if (isPosCalculable (child,
- containerAllocationState != NOT_ALLOCATED &&
- child->generator->wasAllocated ())) {
- int x, y, width, ascent, descent;
- calcPosAndSizeChildOfChild (child, refWidth, refHeight, &x, &y, &width,
- &ascent, &descent);
- *oofWidth = max (*oofWidth, x + width) + containerBoxDiffWidth ();
- *oofHeight =
- max (*oofHeight, y + ascent + descent) + containerBoxDiffHeight ();
- }
- }
-
- DBG_OBJ_MSGF ("resize.oofm", 0, "=> %d * %d", *oofWidth, *oofHeight);
- DBG_OBJ_LEAVE ();
-}
-
bool OOFPositionedMgr::containerMustAdjustExtraSpace ()
{
return true;
}
-void OOFPositionedMgr::getExtremes (Extremes *containerExtr, int *oofMinWidth,
- int *oofMaxWidth)
-{
- DBG_OBJ_ENTER ("resize.oofm", 0, "getExtremes", "(%d / %d), ...",
- containerExtr->minWidth, containerExtr->maxWidth);
-
- *oofMinWidth = *oofMaxWidth = 0;
-
- for (int i = 0; i < children->size(); i++) {
- Child *child = children->get(i);
-
- // If clause: see getSize().
- if (isHPosCalculable (child,
- containerAllocationState != NOT_ALLOCATED
- && child->generator->wasAllocated ())) {
- int x, width;
- Extremes childExtr;
- child->widget->getExtremes (&childExtr);
-
- // Here, we put the extremes of the container in relation to
- // the extremes of the child, as sizes are put in relation
- // for calculating the size. In one case, the allocation is
- // used: when neither "left" nor "right" is set, and so the
- // position told by the generator is used.
- //
- // If you look at the Textblock widget, you'll find that this
- // is always boxOffsetX(), and the horizontal position of a
- // textblock within its parent is also constant; so this is
- // not a problem.
- //
- // (TODO What about a table cell within a table?)
-
- calcHPosAndSizeChildOfChild (child, containerExtr->minWidth,
- childExtr.minWidth, &x, &width);
- *oofMinWidth = max (*oofMinWidth, x + width);
-
- calcHPosAndSizeChildOfChild (child, containerExtr->maxWidth,
- childExtr.maxWidth, &x, &width);
- *oofMaxWidth = max (*oofMaxWidth, x + width);
- }
- }
-
- *oofMinWidth += containerBoxDiffWidth ();
- *oofMaxWidth += containerBoxDiffWidth ();
-
- DBG_OBJ_MSGF ("resize.oofm", 0, "=> %d / %d", *oofMinWidth, *oofMaxWidth);
- DBG_OBJ_LEAVE ();
-}
-
-
int OOFPositionedMgr::getLeftBorder (OOFAwareWidget *widget, int y, int h,
OOFAwareWidget *lastGen, int lastExtIndex)
{
@@ -489,85 +250,14 @@ bool OOFPositionedMgr::dealingWithSizeOfChild (Widget *child)
return true;
}
-int OOFPositionedMgr::getAvailWidthOfChild (Widget *child, bool forceValue)
+int OOFPositionedMgr::getNumWidgets ()
{
- DBG_OBJ_ENTER ("resize.oofm", 0,
- "OOFPositionedMgr/getAvailWidthOfChild", "%p, %s",
- child, forceValue ? "true" : "false");
-
- int width;
-
- if (child->getStyle()->width == style::LENGTH_AUTO &&
- child->getStyle()->minWidth == style::LENGTH_AUTO &&
- child->getStyle()->maxWidth == style::LENGTH_AUTO) {
- // TODO This should (perhaps?) only used when 'width' is undefined.
- // TODO Is "boxDiffWidth()" correct here?
- DBG_OBJ_MSG ("resize.oofm", 1, "no specification");
- if (forceValue) {
- int availWidth = container->getAvailWidth (true);
- width = max (availWidth - containerBoxDiffWidth ()
- // Regard an undefined value as 0:
- - max (getPosLeft (child, availWidth), 0),
- - max (getPosRight (child, availWidth), 0),
- 0);
- } else
- width = -1;
- } else {
- if (forceValue) {
- int availWidth = container->getAvailWidth (true);
- child->calcFinalWidth (child->getStyle(),
- availWidth - containerBoxDiffWidth (), NULL,
- 0, true, &width);
- } else
- width = -1;
- }
-
- if (width != -1)
- width = max (width, child->getMinWidth (NULL, forceValue));
-
- DBG_OBJ_MSGF ("resize.oofm", 1, "=> %d", width);
- DBG_OBJ_LEAVE ();
-
- return width;
+ return children->size();
}
-int OOFPositionedMgr::getAvailHeightOfChild (Widget *child, bool forceValue)
+Widget *OOFPositionedMgr::getWidget (int i)
{
- DBG_OBJ_ENTER ("resize.oofm", 0,
- "OOFPositionedMgr/getAvailHeightOfChild", "%p, %s",
- child, forceValue ? "true" : "false");
-
- int height;
-
- if (child->getStyle()->height == style::LENGTH_AUTO &&
- child->getStyle()->minHeight == style::LENGTH_AUTO &&
- child->getStyle()->maxHeight == style::LENGTH_AUTO) {
- // TODO This should (perhaps?) only used when 'height' is undefined.
- // TODO Is "boxDiffHeight()" correct here?
- DBG_OBJ_MSG ("resize.oofm", 1, "no specification");
- if (forceValue) {
- int availHeight = container->getAvailHeight (true);
- height = max (availHeight - containerBoxDiffHeight ()
- // Regard an undefined value as 0:
- - max (getPosTop (child, availHeight), 0),
- - max (getPosBottom (child, availHeight), 0),
- 0);
- } else
- height = -1;
- } else {
- if (forceValue) {
- int availHeight = container->getAvailHeight (true);
- height = child->calcHeight (child->getStyle()->height, true,
- availHeight - containerBoxDiffHeight (),
- NULL, true);
- } else
- height = -1;
- }
-
- DBG_OBJ_MSGF ("resize.oofm", 1, "=> %d", height);
- DBG_OBJ_LEAVE ();
-
- return height;
+ return children->get(i)->widget;
}
int OOFPositionedMgr::getPosBorder (style::Length cssValue, int refLength)
@@ -581,253 +271,6 @@ int OOFPositionedMgr::getPosBorder (style::Length cssValue, int refLength)
return -1;
}
-bool OOFPositionedMgr::isHPosComplete (Child *child)
-{
- DBG_OBJ_ENTER ("resize.oofm", 0, "isHPosComplete", "[%p]", child->widget);
- bool b =
- (style::isAbsLength (child->widget->getStyle()->left) ||
- style::isPerLength (child->widget->getStyle()->left)) &&
- (style::isAbsLength (child->widget->getStyle()->right) ||
- style::isPerLength (child->widget->getStyle()->right));
- DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
- return b;
-}
-
-bool OOFPositionedMgr::isVPosComplete (Child *child)
-{
- DBG_OBJ_ENTER ("resize.oofm", 0, "isVPosComplete", "[%p]", child->widget);
- bool b =
- (style::isAbsLength (child->widget->getStyle()->top) ||
- style::isPerLength (child->widget->getStyle()->top)) &&
- (style::isAbsLength (child->widget->getStyle()->bottom) ||
- style::isPerLength (child->widget->getStyle()->bottom));
- DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
- return b;
-}
-
-bool OOFPositionedMgr::isHPosCalculable (Child *child, bool allocated)
-{
- DBG_OBJ_ENTER ("resize.oofm", 0, "isHPosCalculable", "[%p], %s",
- child->widget, boolToStr (allocated));
- bool b =
- allocated || (isHPosComplete (child) && child->reference == container);
- DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
- return b;
-}
-
-bool OOFPositionedMgr::isVPosCalculable (Child *child, bool allocated)
-{
- DBG_OBJ_ENTER ("resize.oofm", 0, "isVPosCalculable", "[%p], %s",
- child->widget, boolToStr (allocated));
- bool b =
- allocated || (isVPosComplete (child) && child->reference == container);
- DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
- return b;
-}
-
-bool OOFPositionedMgr::isPosCalculable (Child *child, bool allocated)
-{
- DBG_OBJ_ENTER ("resize.oofm", 0, "isPosCalculable", "[%p], %s",
- child->widget, boolToStr (allocated));
- bool b = isHPosCalculable (child, allocated) &&
- isVPosCalculable (child, allocated);
- DBG_OBJ_LEAVE_VAL ("%s", boolToStr (b));
- return b;
-}
-
-void OOFPositionedMgr::calcPosAndSizeChildOfChild (Child *child, int refWidth,
- int refHeight, int *xPtr,
- int *yPtr, int *widthPtr,
- int *ascentPtr,
- int *descentPtr)
-{
- // *xPtr and *yPtr refer to reference area; caller must adjust them.
-
- DBG_OBJ_ENTER ("resize.oofm", 0, "calcPosAndSizeChildOfChild",
- "[%p], %d, %d, ...", child->widget, refWidth, refHeight);
-
- // TODO (i) Consider {min|max}-{width|heigt}. (ii) Height is always
- // apportioned to descent (ascent is preserved), which makes sense
- // when the children are textblocks. (iii) Consider minimal width
- // (getMinWidth)?
-
- Requisition childRequisition;
- child->widget->sizeRequest (&childRequisition);
-
- calcHPosAndSizeChildOfChild (child, refWidth, childRequisition.width,
- xPtr, widthPtr);
- calcVPosAndSizeChildOfChild (child, refHeight, childRequisition.ascent,
- childRequisition.descent, yPtr, ascentPtr,
- descentPtr);
-
- DBG_OBJ_LEAVE ();
-}
-
-void OOFPositionedMgr::calcHPosAndSizeChildOfChild (Child *child, int refWidth,
- int origChildWidth,
- int *xPtr, int *widthPtr)
-{
- assert (refWidth != -1 || (xPtr == NULL && widthPtr == NULL));
-
- int width;
- bool widthDefined;
- if (style::isAbsLength (child->widget->getStyle()->width)) {
- DBG_OBJ_MSGF ("resize.oofm", 1, "absolute width: %dpx",
- style::absLengthVal (child->widget->getStyle()->width));
- width = style::absLengthVal (child->widget->getStyle()->width)
- + child->widget->boxDiffWidth ();
- widthDefined = true;
- } else if (style::isPerLength (child->widget->getStyle()->width)) {
- DBG_OBJ_MSGF ("resize.oofm", 1, "percentage width: %g%%",
- 100 * style::perLengthVal_useThisOnlyForDebugging
- (child->widget->getStyle()->width));
- width = style::multiplyWithPerLength (refWidth,
- child->widget->getStyle()->width)
- + child->widget->boxDiffWidth ();
- widthDefined = true;
- } else {
- DBG_OBJ_MSG ("resize.oofm", 1, "width not specified");
- width = origChildWidth;
- widthDefined = false;
- }
-
- int left = getPosLeft (child->widget, refWidth),
- right = getPosRight (child->widget, refWidth);
- DBG_OBJ_MSGF ("resize.oofm", 1,
- "=> left = %d, right = %d, width = %d (defined: %s)",
- left, right, width, widthDefined ? "true" : "false");
-
- if (xPtr) {
- if (left == -1 && right == -1) {
- assert (child->generator == container ||
- (containerAllocationState != NOT_ALLOCATED
- && child->generator->wasAllocated ()));
- *xPtr =
- child->x + (child->generator == container ? 0 :
- child->generator->getAllocation()->x
- - (containerAllocation.x + containerBoxOffsetX ()));
- } else {
- assert (child->reference == container ||
- (containerAllocationState != NOT_ALLOCATED
- && child->reference->wasAllocated ()));
- int xBase = child->reference == container ? 0 :
- child->generator->getAllocation()->x - containerAllocation.x;
- DBG_OBJ_MSGF ("resize.oofm", 0, "=> xBase = %d", xBase);
-
- if (left == -1 && right != -1)
- *xPtr = xBase + refWidth - width - right;
- else if (left != -1 && right == -1)
- *xPtr = xBase + left;
- else {
- *xPtr = xBase + left;
- if (!widthDefined) {
- width = refWidth - (left + right);
- DBG_OBJ_MSGF ("resize.oofm", 0, "=> width (corrected) = %d",
- width);
- }
- }
- }
-
- DBG_OBJ_MSGF ("resize.oofm", 0, "=> x = %d", *xPtr);
- }
-
- if (widthPtr)
- *widthPtr = width;
-}
-
-void OOFPositionedMgr::calcVPosAndSizeChildOfChild (Child *child, int refHeight,
- int origChildAscent,
- int origChildDescent,
- int *yPtr, int *ascentPtr,
- int *descentPtr)
-{
- assert (refHeight != -1 ||
- (yPtr == NULL && ascentPtr == NULL && descentPtr == NULL));
-
- int ascent = origChildAscent, descent = origChildDescent;
- bool heightDefined;
-
- if (style::isAbsLength (child->widget->getStyle()->height)) {
- DBG_OBJ_MSGF ("resize.oofm", 1, "absolute height: %dpx",
- style::absLengthVal (child->widget->getStyle()->height));
- int height = style::absLengthVal (child->widget->getStyle()->height)
- + child->widget->boxDiffHeight ();
- splitHeightPreserveAscent (height, &ascent, &descent);
- heightDefined = true;
- } else if (style::isPerLength (child->widget->getStyle()->height)) {
- DBG_OBJ_MSGF ("resize.oofm", 1, "percentage height: %g%%",
- 100 * style::perLengthVal_useThisOnlyForDebugging
- (child->widget->getStyle()->height));
- int height =
- style::multiplyWithPerLength (refHeight,
- child->widget->getStyle()->height)
- + child->widget->boxDiffHeight ();
- splitHeightPreserveAscent (height, &ascent, &descent);
- heightDefined = true;
- } else {
- DBG_OBJ_MSG ("resize.oofm", 1, "height not specified");
- heightDefined = false;
- }
-
- int top = getPosTop (child->widget, refHeight),
- bottom = getPosBottom (child->widget, refHeight);
- DBG_OBJ_MSGF ("resize.oofm", 1,
- "=> top = %d, bottom = %d, height = %d + %d (defined: %s)",
- top, bottom, ascent, descent,
- heightDefined ? "true" : "false");
-
- if (yPtr) {
- if (top == -1 && bottom == -1) {
- assert (child->generator == container ||
- (containerAllocationState != NOT_ALLOCATED
- && child->generator->wasAllocated ()));
- *yPtr =
- child->y + (child->generator == container ? 0 :
- child->generator->getAllocation()->y
- - (containerAllocation.y + containerBoxOffsetY ()));
- } else {
- assert (child->reference == container ||
- (containerAllocationState != NOT_ALLOCATED
- && child->reference->wasAllocated ()));
- int yBase = child->reference == container ? 0 :
- child->generator->getAllocation()->y - containerAllocation.y;
- DBG_OBJ_MSGF ("resize.oofm", 0, "=> yBase = %d", yBase);
-
- if (top == -1 && bottom != -1)
- *yPtr = yBase + refHeight - (ascent + descent) - bottom;
- else if (top != -1 && bottom == -1)
- *yPtr = yBase + top;
- else {
- *yPtr = yBase + top;
- if (!heightDefined) {
- int height = refHeight - (top + bottom);
- splitHeightPreserveAscent (height, &ascent, &descent);
- DBG_OBJ_MSGF ("resize.oofm", 0,
- "=> ascent + descent (corrected) = %d + %d",
- ascent, descent);
- }
- }
- }
-
- DBG_OBJ_MSGF ("resize.oofm", 0, "=> y = %d", *yPtr);
- }
-
- if (ascentPtr)
- *ascentPtr = ascent;
- if (descentPtr)
- *descentPtr = descent;
-}
-
-int OOFPositionedMgr::getNumWidgets ()
-{
- return children->size();
-}
-
-Widget *OOFPositionedMgr::getWidget (int i)
-{
- return children->get(i)->widget;
-}
-
} // namespace oof
} // namespace dw
diff --git a/dw/oofpositionedmgr.hh b/dw/oofpositionedmgr.hh
index 9fa80cf5..00941da5 100644
--- a/dw/oofpositionedmgr.hh
+++ b/dw/oofpositionedmgr.hh
@@ -25,29 +25,14 @@ protected:
};
virtual bool isReference (core::Widget *widget) = 0;
- virtual int containerBoxOffsetX () = 0;
- virtual int containerBoxOffsetY () = 0;
- virtual int containerBoxRestWidth () = 0;
- virtual int containerBoxRestHeight () = 0;
-
- inline int containerBoxDiffWidth ()
- { return containerBoxOffsetX () + containerBoxRestWidth (); }
- inline int containerBoxDiffHeight ()
- { return containerBoxOffsetY () + containerBoxRestHeight (); }
OOFAwareWidget *container;
- enum { NOT_ALLOCATED, IN_ALLOCATION, WAS_ALLOCATED }
- containerAllocationState;
core::Allocation containerAllocation;
lout::container::typed::Vector<Child> *children;
lout::container::typed::HashTable<lout::object::TypedPointer
<dw::core::Widget>,
Child> *childrenByWidget;
-
- bool doChildrenExceedContainer ();
- bool haveExtremesChanged ();
- void sizeAllocateChildren ();
inline int getPosLeft (core::Widget *child, int availWidth)
{ return getPosBorder (child->getStyle()->left, availWidth); }
@@ -60,32 +45,10 @@ protected:
int getPosBorder (core::style::Length cssValue, int refLength);
- bool isHPosComplete (Child *child);
- bool isVPosComplete (Child *child);
-
- bool isHPosCalculable (Child *child, bool allocated);
- bool isVPosCalculable (Child *child, bool allocated);
-
- bool isPosCalculable (Child *child, bool allocated);
-
- void calcPosAndSizeChildOfChild (Child *child, int refWidth, int refHeight,
- int *xPtr, int *yPtr, int *widthPtr,
- int *ascentPtr, int *descentPtr);
- void calcHPosAndSizeChildOfChild (Child *child, int refWidth,
- int origChildWidth, int *xPtr,
- int *widthPtr);
- void calcVPosAndSizeChildOfChild (Child *child, int refHeight,
- int origChildAscent, int origChildDescent,
- int *yPtr, int *ascentPtr,
- int *descentPtr);
-
public:
OOFPositionedMgr (OOFAwareWidget *container);
~OOFPositionedMgr ();
- void sizeAllocateStart (OOFAwareWidget *caller,
- core::Allocation *allocation);
- void sizeAllocateEnd (OOFAwareWidget *caller);
void containerSizeChangedForChildren ();
void draw (core::View *view, core::Rectangle *area,
core::DrawingContext *context);
@@ -99,17 +62,12 @@ public:
int externalIndex);
int addWidgetOOF (core::Widget *widget, OOFAwareWidget *generator,
int externalIndex);
- void calcWidgetRefSize (core::Widget *widget, core::Requisition *size);
void moveExternalIndices (OOFAwareWidget *generator, int oldStartIndex,
int diff);
void tellPosition (core::Widget *widget, int x, int y);
- void getSize (core::Requisition *containerReq, int *oofWidth,
- int *oofHeight);
bool containerMustAdjustExtraSpace ();
- void getExtremes (core::Extremes *containerExtr,
- int *oofMinWidth, int *oofMaxWidth);
int getLeftBorder (OOFAwareWidget *widget, int y, int h,
OOFAwareWidget *lastGen, int lastExtIndex);
@@ -133,8 +91,6 @@ public:
bool mayAffectBordersAtAll ();
bool dealingWithSizeOfChild (core::Widget *child);
- int getAvailWidthOfChild (core::Widget *child, bool forceValue);
- int getAvailHeightOfChild (core::Widget *child, bool forceValue);
int getNumWidgets ();
core::Widget *getWidget (int i);
diff --git a/dw/oofposrelmgr.cc b/dw/oofposrelmgr.cc
index ecb47ba4..3777755c 100644
--- a/dw/oofposrelmgr.cc
+++ b/dw/oofposrelmgr.cc
@@ -20,6 +20,10 @@
#include "oofposrelmgr.hh"
#include "oofawarewidget.hh"
+using namespace dw::core;
+using namespace lout::object;
+using namespace lout::misc;
+
namespace dw {
namespace oof {
@@ -50,8 +54,7 @@ void OOFPosRelMgr::markExtremesChange (int ref)
{
}
-void OOFPosRelMgr::calcWidgetRefSize (core::Widget *widget,
- core::Requisition *size)
+void OOFPosRelMgr::calcWidgetRefSize (Widget *widget, Requisition *size)
{
DBG_OBJ_ENTER ("resize.oofm", 0, "calcWidgetRefSize", "%p", widget);
widget->sizeRequest (size);
@@ -59,36 +62,84 @@ void OOFPosRelMgr::calcWidgetRefSize (core::Widget *widget,
size->width, size->ascent, size->descent);
}
-bool OOFPosRelMgr::isReference (core::Widget *widget)
+
+void OOFPosRelMgr::sizeAllocateStart (OOFAwareWidget *caller,
+ Allocation *allocation)
{
- // TODO Remove soon. This implementation will imply reference = container.
- return false;
+ containerAllocation = *allocation;
}
-// TODO: Check all containerBox* implementations.
+void OOFPosRelMgr::sizeAllocateEnd (OOFAwareWidget *caller)
+{
+ if (caller == container) {
+ for (int i = 0; i < children->size (); i++) {
+ Child *child = children->get(i);
+
+ Requisition childReq;
+ child->widget->sizeRequest (&childReq);
+
+ Allocation childAlloc;
+ childAlloc.x = containerAllocation.x +
+ container->getStyle()->boxOffsetX () + child->x;
+ childAlloc.y = containerAllocation.y +
+ container->getStyle()->boxOffsetY () + child->y;
+ childAlloc.width = childReq.width;
+ childAlloc.ascent = childReq.ascent;
+ childAlloc.descent = childReq.descent;
+ child->widget->sizeAllocate (&childAlloc);
+ }
+ }
+}
-int OOFPosRelMgr::containerBoxOffsetX ()
+void OOFPosRelMgr::getSize (Requisition *containerReq, int *oofWidth,
+ int *oofHeight)
{
- return container->getParent () ?
- container->boxOffsetX () - container->getStyle()->padding.left : 0;
+ *oofWidth = *oofHeight = 0;
+
+ for (int i = 0; i < children->size (); i++) {
+ Child *child = children->get(i);
+ Requisition childReq;
+ child->widget->sizeRequest (&childReq);
+ *oofWidth = max (*oofWidth, child->x + childReq.width);
+ *oofHeight = max (*oofHeight,
+ child->y + childReq.ascent + childReq.descent);
+ }
}
-int OOFPosRelMgr::containerBoxOffsetY ()
+void OOFPosRelMgr::getExtremes (Extremes *containerExtr, int *oofMinWidth,
+ int *oofMaxWidth)
{
- return container->getParent () ?
- container->boxOffsetY () - container->getStyle()->padding.top : 0;
+ *oofMinWidth = *oofMaxWidth = 0;
+
+ for (int i = 0; i < children->size (); i++) {
+ Child *child = children->get(i);
+ Extremes childExtr;
+ child->widget->getExtremes (&childExtr);
+ *oofMinWidth = max (*oofMinWidth, child->x + childExtr.minWidth);
+ *oofMaxWidth = max (*oofMaxWidth, child->x + childExtr.maxWidth);
+ }
}
-int OOFPosRelMgr::containerBoxRestWidth ()
+int OOFPosRelMgr::getAvailWidthOfChild (Widget *child, bool forceValue)
{
- return container->getParent () ?
- container->boxRestWidth () - container->getStyle()->padding.right : 0;
+ TypedPointer<Widget> key (child);
+ Child *tshild = childrenByWidget->get (&key);
+ assert (tshild);
+ return tshild->generator->getAvailWidthOfChild (child, forceValue);
}
-int OOFPosRelMgr::containerBoxRestHeight ()
+int OOFPosRelMgr::getAvailHeightOfChild (Widget *child, bool forceValue)
{
- return container->getParent () ?
- container->boxRestHeight () - container->getStyle()->padding.bottom : 0;
+ TypedPointer<Widget> key (child);
+ Child *tshild = childrenByWidget->get (&key);
+ assert (tshild);
+ return tshild->generator->getAvailHeightOfChild (child, forceValue);
+}
+
+bool OOFPosRelMgr::isReference (Widget *widget)
+{
+ // TODO Remove soon. This implementation will imply reference = container.
+ return false;
}
} // namespace oof
diff --git a/dw/oofposrelmgr.hh b/dw/oofposrelmgr.hh
index 6f712a84..90323094 100644
--- a/dw/oofposrelmgr.hh
+++ b/dw/oofposrelmgr.hh
@@ -11,10 +11,6 @@ class OOFPosRelMgr: public OOFPositionedMgr
{
protected:
bool isReference (core::Widget *widget);
- int containerBoxOffsetX ();
- int containerBoxOffsetY ();
- int containerBoxRestWidth ();
- int containerBoxRestHeight ();
public:
OOFPosRelMgr (OOFAwareWidget *container);
@@ -23,6 +19,17 @@ public:
void markSizeChange (int ref);
void markExtremesChange (int ref);
void calcWidgetRefSize (core::Widget *widget, core::Requisition *size);
+
+ void sizeAllocateStart (OOFAwareWidget *caller,
+ core::Allocation *allocation);
+ void sizeAllocateEnd (OOFAwareWidget *caller);
+ void getSize (core::Requisition *containerReq, int *oofWidth,
+ int *oofHeight);
+ void getExtremes (core::Extremes *containerExtr, int *oofMinWidth,
+ int *oofMaxWidth);
+
+ int getAvailWidthOfChild (core::Widget *child, bool forceValue);
+ int getAvailHeightOfChild (core::Widget *child, bool forceValue);
};
} // namespace oof