diff options
-rw-r--r-- | dw/ruler.cc | 2 | ||||
-rw-r--r-- | dw/table.cc | 69 | ||||
-rw-r--r-- | dw/table.hh | 2 | ||||
-rw-r--r-- | dw/textblock.cc | 2 | ||||
-rw-r--r-- | dw/widget.cc | 102 | ||||
-rw-r--r-- | dw/widget.hh | 8 |
6 files changed, 108 insertions, 77 deletions
diff --git a/dw/ruler.cc b/dw/ruler.cc index b014654d..5525f21b 100644 --- a/dw/ruler.cc +++ b/dw/ruler.cc @@ -34,7 +34,7 @@ Ruler::Ruler () void Ruler::sizeRequestImpl (core::Requisition *requisition) { - requisition->width = lout::misc::max (getAvailWidth (), + requisition->width = lout::misc::max (getAvailWidth (true), getStyle()->boxDiffWidth ()); requisition->ascent = getStyle()->boxOffsetY (); requisition->descent = getStyle()->boxRestHeight (); diff --git a/dw/table.cc b/dw/table.cc index f6073b2d..e33e9a01 100644 --- a/dw/table.cc +++ b/dw/table.cc @@ -192,13 +192,12 @@ void Table::resizeDrawImpl () redrawY = getHeight (); } -int Table::getAvailWidthOfChild (Widget *child) +int Table::getAvailWidthOfChild (Widget *child, bool forceValue) { - DBG_OBJ_MSGF ("resize", 0, "<b>getAvailWidthOfChild</b> (%p)", child); + DBG_OBJ_MSGF ("resize", 0, "<b>getAvailWidthOfChild</b> (%p, %s)", + child, forceValue ? "true" : "false"); DBG_OBJ_MSG_START (); - calcCellSizes (false); - int width; if (core::style::isAbsLength (child->getStyle()->width)) { @@ -207,38 +206,48 @@ int Table::getAvailWidthOfChild (Widget *child) + child->boxDiffWidth (); } else if (core::style::isPerLength (child->getStyle()->width)) { DBG_OBJ_MSG ("resize", 1, "percentage length"); - int containerContentWidth = getAvailWidth () - boxDiffWidth (); - width = core::style::multiplyWithPerLength (containerContentWidth, - child->getStyle()->width) - + child->boxDiffWidth (); + int availWidth = getAvailWidth (forceValue); + if (availWidth == -1) + width = -1; + else { + int containerContentWidth = availWidth - boxDiffWidth (); + width = core::style::multiplyWithPerLength (containerContentWidth, + child->getStyle()->width) + + child->boxDiffWidth (); + } } else { - width = -1; DBG_OBJ_MSG ("resize", 1, "no length specified"); - // "child" is not a direct child, but a direct descendant. Search - // for the actual childs. - Widget *actualChild = child; - while (actualChild != NULL && actualChild->getParent () != this) - actualChild = actualChild->getParent (); - - assert (actualChild != NULL); + width = -1; - // TODO This is inefficient. (Use parentRef?) - for (int row = numRows - 1; width == -1 && row >= 0; row--) { - for (int col = 0; width == -1 && col < numCols; col++) { - int n = row * numCols + col; - if (childDefined (n) && - children->get(n)->cell.widget == actualChild) { - DBG_OBJ_MSGF ("resize", 1, "calculated from column %d", col); - width = (children->get(n)->cell.colspanEff - 1) - * getStyle()->hBorderSpacing; - for (int i = 0; i < children->get(n)->cell.colspanEff; i++) - width += colWidths->get (col + i); + if (forceValue) { + calcCellSizes (false); + + // "child" is not a direct child, but a direct descendant. Search + // for the actual childs. + Widget *actualChild = child; + while (actualChild != NULL && actualChild->getParent () != this) + actualChild = actualChild->getParent (); + + assert (actualChild != NULL); + + // TODO This is inefficient. (Use parentRef?) + for (int row = numRows - 1; width == -1 && row >= 0; row--) { + for (int col = 0; width == -1 && col < numCols; col++) { + int n = row * numCols + col; + if (childDefined (n) && + children->get(n)->cell.widget == actualChild) { + DBG_OBJ_MSGF ("resize", 1, "calculated from column %d", col); + width = (children->get(n)->cell.colspanEff - 1) + * getStyle()->hBorderSpacing; + for (int i = 0; i < children->get(n)->cell.colspanEff; i++) + width += colWidths->get (col + i); + } } } + + assert (width != -1); } - - assert (width != -1); } DBG_OBJ_MSGF ("resize", 1, "=> %d", width); @@ -534,7 +543,7 @@ void Table::forceCalcCellSizes (bool calcHeights) // Will also call calcColumnExtremes(), when needed. getExtremes (&extremes); - totalWidth = getAvailWidth (); + totalWidth = getAvailWidth (true); if (totalWidth < extremes.minWidth) totalWidth = extremes.minWidth; diff --git a/dw/table.hh b/dw/table.hh index caa66efe..847327c9 100644 --- a/dw/table.hh +++ b/dw/table.hh @@ -426,7 +426,7 @@ protected: void sizeAllocateImpl (core::Allocation *allocation); void resizeDrawImpl (); - int getAvailWidthOfChild (Widget *child); + int getAvailWidthOfChild (Widget *child, bool forceValue); bool isBlockLevel (); diff --git a/dw/textblock.cc b/dw/textblock.cc index b822ffb4..8772422a 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -333,7 +333,7 @@ void Textblock::sizeRequestImpl (core::Requisition *requisition) DBG_OBJ_MSG ("resize", 0, "<b>sizeRequestImpl</b> ()"); DBG_OBJ_MSG_START (); - lineBreakWidth = getAvailWidth (); + lineBreakWidth = getAvailWidth (true); rewrap (); showMissingLines (); diff --git a/dw/widget.cc b/dw/widget.cc index d3c13d4f..3a804bac 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -344,7 +344,7 @@ void Widget::sizeRequest (Requisition *requisition) * Return available width including margin/border/padding * (extraSpace?), not only the content width. */ -int Widget::getAvailWidth () +int Widget::getAvailWidth (bool forceValue) { // TODO Correct by extremes? @@ -369,7 +369,7 @@ int Widget::getAvailWidth () width = viewportWidth; } } else - width = container->getAvailWidthOfChild (this); + width = container->getAvailWidthOfChild (this, forceValue); DBG_OBJ_MSGF ("resize", 1, "=> %d", width); DBG_OBJ_MSG_END (); @@ -381,7 +381,7 @@ int Widget::getAvailWidth () * Return available height including margin/border/padding * (extraSpace?), not only the content height. */ -int Widget::getAvailHeight () +int Widget::getAvailHeight (bool forceValue) { // TODO Correct by ... not extremes, but ...? (Height extremes?) @@ -406,7 +406,7 @@ int Widget::getAvailHeight () else height = layout->viewportHeight; } else - height = container->getAvailHeightOfChild (this); + height = container->getAvailHeightOfChild (this, forceValue); DBG_OBJ_MSGF ("resize", 1, "=> %d", height); DBG_OBJ_MSG_END (); @@ -966,7 +966,7 @@ void Widget::markExtremesChange (int ref) { } -int Widget::getAvailWidthOfChild (Widget *child) +int Widget::getAvailWidthOfChild (Widget *child, bool forceValue) { // This is a halfway suitable implementation for all // containers. For simplification, this will be used during the @@ -974,7 +974,8 @@ int Widget::getAvailWidthOfChild (Widget *child) // TODO Correct by extremes? - DBG_OBJ_MSGF ("resize", 0, "<b>getAvailWidthOfChild</b> (%p)", child); + DBG_OBJ_MSGF ("resize", 0, "<b>getAvailWidthOfChild</b> (%p, %s)", + child, forceValue ? "true" : "false"); DBG_OBJ_MSG_START (); int width; @@ -983,15 +984,20 @@ int Widget::getAvailWidthOfChild (Widget *child) width = style::absLengthVal (child->getStyle()->width) + child->boxDiffWidth (); else { - int containerContentWidth = getAvailWidth () - boxDiffWidth (); - if (style::isPerLength (child->getStyle()->width)) - width = style::multiplyWithPerLength (containerContentWidth, - child->getStyle()->width) - + child->boxDiffWidth (); - else - // Some widgets will use the whole width, so this is a - // meaningful value. - width = containerContentWidth; + int availWidth = getAvailWidth (forceValue); + if (availWidth == -1) + width = -1; + else { + int containerContentWidth = availWidth - boxDiffWidth (); + if (style::isPerLength (child->getStyle()->width)) + width = style::multiplyWithPerLength (containerContentWidth, + child->getStyle()->width) + + child->boxDiffWidth (); + else + // Some widgets will use the whole width, so this is a + // meaningful value. + width = containerContentWidth; + } } DBG_OBJ_MSGF ("resize", 1, "=> %d", width); @@ -1000,13 +1006,14 @@ int Widget::getAvailWidthOfChild (Widget *child) return width; } -int Widget::getAvailHeightOfChild (Widget *child) +int Widget::getAvailHeightOfChild (Widget *child, bool forceValue) { // Again, a suitable implementation for all widgets (perhaps). // TODO Correct by extremes? (Height extemes?) - DBG_OBJ_MSGF ("resize", 0, "<b>getAvailHeightOfChild</b> (%p)", child); + DBG_OBJ_MSGF ("resize", 0, "<b>getAvailHeightOfChild</b> (%p, %s)", + child, forceValue ? "true" : "false"); DBG_OBJ_MSG_START (); int height; @@ -1015,15 +1022,20 @@ int Widget::getAvailHeightOfChild (Widget *child) height = style::absLengthVal (child->getStyle()->height) + child->boxDiffHeight (); else { - int containerContentHeight = getAvailHeight () - boxDiffHeight (); - if (style::isPerLength (child->getStyle()->height)) - height = style::multiplyWithPerLength (containerContentHeight, - child->getStyle()->height) - + child->boxDiffHeight (); - else - // Although no widget will probably use the whole height, we - // have to return some value here. - height = containerContentHeight; + int availHeight = getAvailHeight (forceValue); + if (availHeight == -1) + height = -1; + else { + int containerContentHeight = availHeight - boxDiffHeight (); + if (style::isPerLength (child->getStyle()->height)) + height = style::multiplyWithPerLength (containerContentHeight, + child->getStyle()->height) + + child->boxDiffHeight (); + else + // Although no widget will probably use the whole height, we + // have to return some value here. + height = containerContentHeight; + } } DBG_OBJ_MSGF ("resize", 1, "=> %d", height); @@ -1051,11 +1063,14 @@ void Widget::correctRequisitionOfChild (Widget *child, Requisition *requisition, requisition->width = style::absLengthVal (child->getStyle()->width) + child->boxDiffWidth (); else if (style::isPerLength (child->getStyle()->width)) { - int containerWidth = getAvailWidth () - boxDiffWidth (); - requisition->width = - style::multiplyWithPerLength (containerWidth, - child->getStyle()->width) - + child->boxDiffWidth (); + int availWidth = getAvailWidth (false); + if (availWidth != -1) { + int containerWidth = availWidth - boxDiffWidth (); + requisition->width = + style::multiplyWithPerLength (containerWidth, + child->getStyle()->width) + + child->boxDiffWidth (); + } } // TODO Perhaps split first, then add box ascent and descent. @@ -1064,11 +1079,14 @@ void Widget::correctRequisitionOfChild (Widget *child, Requisition *requisition, + child->boxDiffHeight (), &requisition->ascent, &requisition->descent); else if (style::isPerLength (child->getStyle()->height)) { - int containerHeight = getAvailHeight () - boxDiffHeight (); - splitHeightFun (style::multiplyWithPerLength (containerHeight, - child->getStyle()->height) - + child->boxDiffHeight (), - &requisition->ascent, &requisition->descent); + int availHeight = getAvailHeight (false); + if (availHeight != -1) { + int containerHeight = availHeight - boxDiffHeight (); + splitHeightFun (style::multiplyWithPerLength + (containerHeight, child->getStyle()->height) + + child->boxDiffHeight (), + &requisition->ascent, &requisition->descent); + } } DBG_OBJ_MSGF ("resize", 1, "=> %d * (%d + %d)", @@ -1093,10 +1111,14 @@ void Widget::correctExtremesOfChild (Widget *child, Extremes *extremes) style::absLengthVal (child->getStyle()->width) + child->boxDiffWidth (); else if (style::isPerLength (child->getStyle()->width)) { - int containerWidth = getAvailWidth () - boxDiffWidth (); - extremes->minWidth =extremes->maxWidth = - style::multiplyWithPerLength (containerWidth, child->getStyle()->width) - + child->boxDiffWidth (); + int availWidth = getAvailWidth (false); + if (availWidth != -1) { + int containerWidth = availWidth - boxDiffWidth (); + extremes->minWidth =extremes->maxWidth = + style::multiplyWithPerLength (containerWidth, + child->getStyle()->width) + + child->boxDiffWidth (); + } } DBG_OBJ_MSGF ("resize", 1, "=> %d / %d", diff --git a/dw/widget.hh b/dw/widget.hh index 326d00ec..7fe49c74 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -312,8 +312,8 @@ protected: */ virtual void markExtremesChange (int ref); - virtual int getAvailWidthOfChild (Widget *child); - virtual int getAvailHeightOfChild (Widget *child); + virtual int getAvailWidthOfChild (Widget *child, bool forceValue); + virtual int getAvailHeightOfChild (Widget *child, bool forceValue); virtual void correctRequisitionOfChild (Widget *child, Requisition *requisition, void (*splitHeightFun)(int height, @@ -434,8 +434,8 @@ public: void getExtremes (Extremes *extremes); void sizeAllocate (Allocation *allocation); - int getAvailWidth (); - int getAvailHeight (); + int getAvailWidth (bool forceValue); + int getAvailHeight (bool forceValue); void correctRequisition (Requisition *requisition, void (*splitHeightFun)(int height, int *ascent, int *descent)); |