aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2014-09-23 12:35:35 +0200
committerSebastian Geerken <devnull@localhost>2014-09-23 12:35:35 +0200
commit43298239a35f6b75dfc3cb7e392deafb0bb1528c (patch)
tree905f535c5e1b5d0f7635a91c6fcc71fbe396162b
parentafbbb4180fd2f4ab7bc534811ebfc0ede00d8a93 (diff)
More work on Widget::extraSpace.
-rw-r--r--dw/textblock.cc55
-rw-r--r--dw/textblock.hh9
-rw-r--r--dw/textblock_linebreaking.cc2
-rw-r--r--dw/widget.cc70
-rw-r--r--dw/widget.hh11
5 files changed, 103 insertions, 44 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index efa21342..b5d9cea7 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -265,8 +265,8 @@ Textblock::Textblock (bool limitTextWidth)
lineBreakWidth = -1;
DBG_OBJ_SET_NUM ("lineBreakWidth", lineBreakWidth);
- verticalOffset = 0;
- DBG_OBJ_SET_NUM ("verticalOffset", verticalOffset);
+ clearPosition = 0;
+ DBG_OBJ_SET_NUM ("clearPosition", clearPosition);
this->limitTextWidth = limitTextWidth;
@@ -359,7 +359,7 @@ void Textblock::sizeRequestImpl (core::Requisition *requisition)
leftInnerPadding, boxDiffWidth ());
requisition->width += leftInnerPadding + boxDiffWidth ();
- requisition->ascent += verticalOffset + boxOffsetY ();
+ requisition->ascent += boxOffsetY ();
requisition->descent += boxRestHeight ();
if (mustBeWidenedToAvailWidth ()) {
@@ -523,7 +523,7 @@ void Textblock::sizeAllocateImpl (core::Allocation *allocation)
// Reconstruct the initial size; see
// Textblock::sizeRequestImpl.
(lines->size () > 0 ? lines->getRef(0)->boxAscent : 0)
- + verticalOffset + boxOffsetY ());
+ + boxOffsetY ());
childBaseAllocation.descent =
allocation->ascent + allocation->descent - childBaseAllocation.ascent;
@@ -682,6 +682,12 @@ void Textblock::sizeAllocateImpl (core::Allocation *allocation)
DBG_OBJ_LEAVE ();
}
+void Textblock::calcExtraSpaceImpl ()
+{
+ OOFAwareWidget::calcExtraSpaceImpl ();
+ extraSpace.top = misc::max (extraSpace.top, clearPosition);
+}
+
int Textblock::getAvailWidthOfChild (Widget *child, bool forceValue)
{
DBG_OBJ_ENTER ("resize", 0, "Textblock/getAvailWidthOfChild", "%p, %s",
@@ -1498,9 +1504,7 @@ int Textblock::findLineIndexWhenNotAllocated (int y)
if (lines->size() == 0)
return -1;
else
- return findLineIndex (y,
- lines->getRef(0)->boxAscent + verticalOffset +
- boxOffsetY());
+ return findLineIndex (y, lines->getRef(0)->boxAscent + boxOffsetY());
}
int Textblock::findLineIndexWhenAllocated (int y)
@@ -1652,15 +1656,7 @@ void Textblock::draw (core::View *view, core::Rectangle *area)
int lineIndex;
Line *line;
- // Instead of drawWidgetBox, use drawBox to include verticalOffset.
- if (getParent() == NULL) {
- // The toplevel (parent == NULL) widget is a special case, which
- // we leave to drawWidgetBox; verticalOffset will here always 0.
- assert (verticalOffset == 0);
- drawWidgetBox (view, area, false);
- } else
- drawBox (view, getStyle(), area, 0, verticalOffset, allocation.width,
- getHeight() - verticalOffset, false);
+ drawWidgetBox (view, area, false);
if (stackingContextMgr)
stackingContextMgr->drawBottom (view, area);
@@ -2818,13 +2814,13 @@ void Textblock::queueDrawRange (int index1, int index2)
}
}
-void Textblock::setVerticalOffset (int verticalOffset)
+void Textblock::setClearPosition (int clearPosition)
{
- DBG_OBJ_ENTER ("resize", 0, "setVerticalOffset", "%d", verticalOffset);
+ DBG_OBJ_ENTER ("resize", 0, "setClearPosition", "%d", clearPosition);
- if (this->verticalOffset != verticalOffset) {
- this->verticalOffset = verticalOffset;
- DBG_OBJ_SET_NUM ("verticalOffset", verticalOffset);
+ if (this->clearPosition != clearPosition) {
+ this->clearPosition = clearPosition;
+ DBG_OBJ_SET_NUM ("clearPosition", clearPosition);
mustQueueResize = true;
queueDraw (); // Could perhaps be optimized.
}
@@ -3065,19 +3061,16 @@ int Textblock::yOffsetOfPossiblyMissingLine (int lineNo)
int result;
if (lineNo == 0) {
- result = verticalOffset + boxOffsetY();
- DBG_OBJ_MSGF ("line.yoffset", 1, "first line: %d + %d = %d",
- verticalOffset, boxOffsetY(), result);
+ result = boxOffsetY();
+ DBG_OBJ_MSGF ("line.yoffset", 1, "first line: %d", result);
} else {
Line *prevLine = lines->getRef (lineNo - 1);
- result = verticalOffset + boxOffsetY() +
- prevLine->top + prevLine->boxAscent + prevLine->boxDescent +
- prevLine->breakSpace;
+ result = boxOffsetY() + prevLine->top + prevLine->boxAscent +
+ prevLine->boxDescent + prevLine->breakSpace;
DBG_OBJ_MSGF ("line.yoffset", 1,
- "other line: %d + %d + %d + (%d + %d) + %d = %d",
- verticalOffset, boxOffsetY(),
- prevLine->top, prevLine->boxAscent, prevLine->boxDescent,
- prevLine->breakSpace, result);
+ "other line: %d + %d + (%d + %d) + %d = %d",
+ boxOffsetY(), prevLine->top, prevLine->boxAscent,
+ prevLine->boxDescent, prevLine->breakSpace, result);
}
DBG_OBJ_LEAVE ();
diff --git a/dw/textblock.hh b/dw/textblock.hh
index 499992c1..d376ba48 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -522,8 +522,9 @@ protected:
/* This value is (currently) set by setAscent(). */
int lineBreakWidth;
- // Additional vertical offset, used for the "clear" attribute.
- int verticalOffset;
+ // Vertical offset at the top, used for the "clear" attribute. Goes
+ // into "extraSpace".
+ int clearPosition;
int wrapRefLines, wrapRefParagraphs; /* 0-based. Important: Both
are the line numbers, not
@@ -572,7 +573,7 @@ protected:
void calcBorders (int lastOofRef, int height);
void showMissingLines ();
void removeTemporaryLines ();
- void setVerticalOffset (int verticalOffset);
+ void setClearPosition (int clearPosition);
void decorateText (core::View *view, core::style::Style *style,
core::style::Color::Shading shading,
@@ -749,6 +750,8 @@ protected:
void getExtremesImpl (core::Extremes *extremes);
void sizeAllocateImpl (core::Allocation *allocation);
+ void calcExtraSpaceImpl ();
+
int getAvailWidthOfChild (core::Widget *child, bool forceValue);
int getAvailHeightOfChild (core::Widget *child, bool forceValue);
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index 6066d246..af8fd33d 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -1947,7 +1947,7 @@ void Textblock::initNewLine ()
misc::max (clearPosition,
searchOutOfFlowMgr(i)->getClearPosition (this));
- setVerticalOffset (misc::max (clearPosition, 0));
+ setClearPosition (misc::max (clearPosition, 0));
}
calcBorders (lines->size() > 0 ?
diff --git a/dw/widget.cc b/dw/widget.cc
index 054ad7bf..993c4f9c 100644
--- a/dw/widget.cc
+++ b/dw/widget.cc
@@ -512,6 +512,7 @@ void Widget::sizeRequest (Requisition *requisition)
}
if (needsResize ()) {
+ calcExtraSpace ();
/** \todo Check requisition == &(this->requisition) and do what? */
sizeRequestImpl (requisition);
this->requisition = *requisition;
@@ -922,6 +923,8 @@ void Widget::getExtremes (Extremes *extremes)
}
if (extremesChanged ()) {
+ calcExtraSpace ();
+
// For backward compatibility (part 1/2):
extremes->minWidthIntrinsic = extremes->maxWidthIntrinsic = -1;
@@ -951,6 +954,24 @@ void Widget::getExtremes (Extremes *extremes)
}
/**
+ * \brief Calculates dw::core::Widget::extraSpace.
+ *
+ * Delegated to dw::core::Widget::calcExtraSpaceImpl. Called both from
+ * dw::core::Widget::sizeRequest and dw::core::Widget::getExtremes.
+ */
+void Widget::calcExtraSpace ()
+{
+ extraSpace.top = extraSpace.right = extraSpace.bottom = extraSpace.left = 0;
+ calcExtraSpaceImpl ();
+
+ DBG_OBJ_SET_NUM ("extraSpace.top", extraSpace.top);
+ DBG_OBJ_SET_NUM ("extraSpace.bottom", extraSpace.bottom);
+ DBG_OBJ_SET_NUM ("extraSpace.left", extraSpace.left);
+ DBG_OBJ_SET_NUM ("extraSpace.right", extraSpace.right);
+
+}
+
+/**
* \brief Wrapper for Widget::sizeAllocateImpl, calls the latter only when
* needed.
*/
@@ -1236,8 +1257,10 @@ void Widget::drawWidgetBox (View *view, Rectangle *area, bool inverse)
canvasArea.width = area->width;
canvasArea.height = area->height;
- style::drawBorder (view, layout, &canvasArea, allocation.x, allocation.y,
- allocation.width, getHeight (), style, inverse);
+ int xMar, yMar, widthMar, heightMar;
+ getMarginArea (&xMar, &yMar, &widthMar, &heightMar);
+ style::drawBorder (view, layout, &canvasArea, xMar, yMar, widthMar,
+ heightMar, style, inverse);
int xPad, yPad, widthPad, heightPad;
getPaddingArea (&xPad, &yPad, &widthPad, &heightPad);
@@ -1411,6 +1434,24 @@ void Widget::scrollTo (HPosition hpos, VPosition vpos,
x + allocation.x, y + allocation.y, width, height);
}
+void Widget::getMarginArea (int *xMar, int *yMar, int *widthMar, int *heightMar)
+{
+ *xMar = allocation.x + extraSpace.left;
+ *yMar = allocation.y + extraSpace.top;
+ *widthMar = allocation.width - (extraSpace.left + extraSpace.right);
+ *heightMar = getHeight () - (extraSpace.top + extraSpace.bottom);
+}
+
+void Widget::getBorderArea (int *xBor, int *yBor, int *widthBor, int *heightBor)
+{
+ getMarginArea (xBor, yBor, widthBor, heightBor);
+
+ *xBor += style->margin.left;
+ *yBor += style->margin.top;
+ *widthBor -= style->margin.left + style->margin.right;
+ *heightBor -= style->margin.top + style->margin.bottom;
+}
+
/**
* \brief Return the padding area (content plus padding).
*
@@ -1420,18 +1461,31 @@ void Widget::scrollTo (HPosition hpos, VPosition vpos,
void Widget::getPaddingArea (int *xPad, int *yPad, int *widthPad,
int *heightPad)
{
- *xPad = allocation.x + style->margin.left + style->borderWidth.left;
- *yPad = allocation.y + style->margin.top + style->borderWidth.top;
- *widthPad = allocation.width - style->margin.left - style->borderWidth.left
- - style->margin.right - style->borderWidth.right;
- *heightPad = getHeight () - style->margin.top - style->borderWidth.top
- - style->margin.bottom - style->borderWidth.bottom;
+ getBorderArea (xPad, yPad, widthPad, heightPad);
+
+ *xPad += style->borderWidth.left;
+ *yPad += style->borderWidth.top;
+ *widthPad -= style->borderWidth.left + style->borderWidth.right;
+ *heightPad -= style->borderWidth.top + style->borderWidth.bottom;
}
void Widget::sizeAllocateImpl (Allocation *allocation)
{
}
+/**
+ * \brief The actual implementation for calculating
+ * dw::core::Widget::extraSpace.
+ *
+ * The implementation gets a clean value of
+ * dw::core::Widget::extraSpace, which is only corrected. To make sure
+ * all possible influences are considered, the implementation of the
+ * base class should be called, too.
+ */
+void Widget::calcExtraSpaceImpl ()
+{
+}
+
void Widget::markSizeChange (int ref)
{
}
diff --git a/dw/widget.hh b/dw/widget.hh
index 46fdf856..88219764 100644
--- a/dw/widget.hh
+++ b/dw/widget.hh
@@ -187,7 +187,10 @@ protected:
/**
* \brief Space around the margin box. Allocation is extraSpace +
- * margin + border + padding + contents;
+ * margin + border + padding + contents.
+ *
+ * See also dw::core::Widget::calcExtraSpace and
+ * dw::core::Widget::calcExtraSpaceImpl.
*/
style::Box extraSpace;
@@ -275,6 +278,8 @@ protected:
*/
virtual void getExtremesImpl (Extremes *extremes) = 0;
+ virtual void calcExtraSpaceImpl ();
+
/**
* \brief See \ref dw-widget-sizes.
*/
@@ -427,6 +432,8 @@ public:
void getExtremes (Extremes *extremes);
void sizeAllocate (Allocation *allocation);
+ void calcExtraSpace ();
+
int getAvailWidth (bool forceValue);
int getAvailHeight (bool forceValue);
virtual bool getAdjustMinWidth () { return Widget::adjustMinWidth; }
@@ -489,6 +496,8 @@ public:
void scrollTo (HPosition hpos, VPosition vpos,
int x, int y, int width, int height);
+ void getMarginArea (int *xMar, int *yMar, int *widthMar, int *heightMar);
+ void getBorderArea (int *xBor, int *yBor, int *widthBor, int *heightBor);
void getPaddingArea (int *xPad, int *yPad, int *widthPad, int *heightPad);
/**