aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dw/alignedtablecell.cc12
-rw-r--r--dw/alignedtablecell.hh3
-rw-r--r--dw/ruler.cc4
-rw-r--r--dw/simpletablecell.cc12
-rw-r--r--dw/simpletablecell.hh4
-rw-r--r--dw/table.cc155
-rw-r--r--dw/table.hh9
-rw-r--r--dw/textblock.cc1
-rw-r--r--dw/widget.cc83
-rw-r--r--dw/widget.hh13
10 files changed, 93 insertions, 203 deletions
diff --git a/dw/alignedtablecell.cc b/dw/alignedtablecell.cc
index 1fba7588..a9f091f3 100644
--- a/dw/alignedtablecell.cc
+++ b/dw/alignedtablecell.cc
@@ -50,6 +50,18 @@ bool AlignedTableCell::isBlockLevel ()
return false;
}
+int AlignedTableCell::applyPerWidth (int containerWidth,
+ core::style::Length perWidth)
+{
+ return core::style::multiplyWithPerLength (containerWidth, perWidth);
+}
+
+int AlignedTableCell::applyPerHeight (int containerHeight,
+ core::style::Length perHeight)
+{
+ return core::style::multiplyWithPerLength (containerHeight, perHeight);
+}
+
int AlignedTableCell::wordWrap(int wordIndex, bool wrapAll)
{
Textblock::Word *word;
diff --git a/dw/alignedtablecell.hh b/dw/alignedtablecell.hh
index eafff468..59878290 100644
--- a/dw/alignedtablecell.hh
+++ b/dw/alignedtablecell.hh
@@ -12,6 +12,9 @@ private:
int charWordIndex, charWordPos;
protected:
+ int applyPerWidth (int containerWidth, core::style::Length perWidth);
+ int applyPerHeight (int containerHeight, core::style::Length perHeight);
+
int wordWrap (int wordIndex, bool wrapAll);
int getValue ();
diff --git a/dw/ruler.cc b/dw/ruler.cc
index 82cc3299..2459c1bd 100644
--- a/dw/ruler.cc
+++ b/dw/ruler.cc
@@ -34,8 +34,8 @@ Ruler::Ruler ()
void Ruler::sizeRequestImpl (core::Requisition *requisition)
{
- requisition->width = lout::misc::max (getAvailWidth (true),
- getStyle()->boxDiffWidth ());
+ requisition->width =
+ lout::misc::max (getAvailWidth (true), getStyle()->boxDiffWidth ());
requisition->ascent = getStyle()->boxOffsetY ();
requisition->descent = getStyle()->boxRestHeight ();
}
diff --git a/dw/simpletablecell.cc b/dw/simpletablecell.cc
index 3a356cbc..083deaed 100644
--- a/dw/simpletablecell.cc
+++ b/dw/simpletablecell.cc
@@ -43,4 +43,16 @@ bool SimpleTableCell::isBlockLevel ()
return false;
}
+int SimpleTableCell::applyPerWidth (int containerWidth,
+ core::style::Length perWidth)
+{
+ return core::style::multiplyWithPerLength (containerWidth, perWidth);
+}
+
+int SimpleTableCell::applyPerHeight (int containerHeight,
+ core::style::Length perHeight)
+{
+ return core::style::multiplyWithPerLength (containerHeight, perHeight);
+}
+
} // namespace dw
diff --git a/dw/simpletablecell.hh b/dw/simpletablecell.hh
index a97464e4..4701a90e 100644
--- a/dw/simpletablecell.hh
+++ b/dw/simpletablecell.hh
@@ -7,6 +7,10 @@ namespace dw {
class SimpleTableCell: public Textblock
{
+protected:
+ int applyPerWidth (int containerWidth, core::style::Length perWidth);
+ int applyPerHeight (int containerHeight, core::style::Length perHeight);
+
public:
static int CLASS_ID;
diff --git a/dw/table.cc b/dw/table.cc
index b71d030a..5dacc35d 100644
--- a/dw/table.cc
+++ b/dw/table.cc
@@ -201,155 +201,14 @@ void Table::resizeDrawImpl ()
redrawY = getHeight ();
}
-int Table::getAvailWidthOfChild (Widget *child, bool forceValue)
+int Table::applyPerWidth (int containerWidth, core::style::Length perWidth)
{
- DBG_OBJ_MSGF ("resize", 0, "<b>getAvailWidthOfChild</b> (%p, %s)",
- child, forceValue ? "true" : "false");
- DBG_OBJ_MSG_START ();
-
- int width;
-
- if (core::style::isAbsLength (child->getStyle()->width)) {
- DBG_OBJ_MSG ("resize", 1, "absolute length");
- width = core::style::absLengthVal (child->getStyle()->width)
- + child->boxDiffWidth ();
- } else if (core::style::isPerLength (child->getStyle()->width)) {
- DBG_OBJ_MSG ("resize", 1, "percentage length");
- int availWidth = getAvailWidth (forceValue);
- if (availWidth == -1)
- width = -1;
- else {
- // Within tables, a percentage 'width' specifies the total
- // width, not the content width.
- int containerContentWidth = availWidth - boxDiffWidth ();
- width = core::style::multiplyWithPerLength (containerContentWidth,
- child->getStyle()->width);
- }
- } else {
- DBG_OBJ_MSG ("resize", 1, "no length specified");
-
- width = -1;
-
- 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);
- }
- }
-
- DBG_OBJ_MSGF ("resize", 1, "=> %d", width);
- DBG_OBJ_MSG_END ();
- return width;
-}
-
-void Table::correctRequisitionOfChild (Widget *child,
- core::Requisition *requisition,
- void (*splitHeightFun)(int height,
- int *ascent,
- int *descent))
-{
- // (Mostly copied from Widget::correctRequisitionOfChild; could be
- // cleaned up a bit.)
-
- // TODO Correct by extremes?
-
- DBG_OBJ_MSGF ("resize", 0,
- "<b>correctRequisitionOfChild</b> (%p, %d * (%d + %d), ...)",
- child, requisition->width, requisition->ascent,
- requisition->descent);
- DBG_OBJ_MSG_START ();
-
- if (core::style::isAbsLength (child->getStyle()->width))
- requisition->width = core::style::absLengthVal (child->getStyle()->width)
- + child->boxDiffWidth ();
- else if (core::style::isPerLength (child->getStyle()->width)) {
- int availWidth = getAvailWidth (false);
- if (availWidth != -1) {
- // Within tables, a percentage 'width' specifies the total
- // width, not the content width.
- int containerWidth = availWidth - boxDiffWidth ();
- requisition->width =
- core::style::multiplyWithPerLength (containerWidth,
- child->getStyle()->width);
- }
- }
-
- // TODO Perhaps split first, then add box ascent and descent.
- if (core::style::isAbsLength (child->getStyle()->height))
- splitHeightFun (core::style::absLengthVal (child->getStyle()->height)
- + child->boxDiffHeight (),
- &requisition->ascent, &requisition->descent);
- else if (core::style::isPerLength (child->getStyle()->height)) {
- int availHeight = getAvailHeight (false);
- if (availHeight != -1) {
- int containerHeight = availHeight - boxDiffHeight ();
- splitHeightFun (core::style::multiplyWithPerLength
- (containerHeight, child->getStyle()->height)
- + child->boxDiffHeight (),
- &requisition->ascent, &requisition->descent);
- }
- }
-
- DBG_OBJ_MSGF ("resize", 1, "=> %d * (%d + %d)",
- requisition->width, requisition->ascent,
- requisition->descent);
- DBG_OBJ_MSG_END ();
+ return core::style::multiplyWithPerLength (containerWidth, perWidth);
}
-void Table::correctExtremesOfChild (Widget *child, core::Extremes *extremes)
+int Table::applyPerHeight (int containerHeight, core::style::Length perHeight)
{
- // (Mostly copied from Widget::correctExtremesOfChild; could be
- // cleaned up a bit.)
-
- // TODO Extremes only corrected?
-
- DBG_OBJ_MSGF ("resize", 0,
- "<b>correctExtremedOfChild</b> (%p, %d / %d)",
- child, extremes->minWidth, extremes->maxWidth);
- DBG_OBJ_MSG_START ();
-
- if (core::style::isAbsLength (child->getStyle()->width))
- extremes->minWidth =extremes->maxWidth =
- core::style::absLengthVal (child->getStyle()->width)
- + child->boxDiffWidth ();
- else if (core::style::isPerLength (child->getStyle()->width)) {
- int availWidth = getAvailWidth (false);
- if (availWidth != -1) {
- // Within tables, a percentage 'width' specifies the total
- // width, not the content width.
- int containerWidth = availWidth - boxDiffWidth ();
- extremes->minWidth =extremes->maxWidth =
- core::style::multiplyWithPerLength (containerWidth,
- child->getStyle()->width);
- }
- }
-
- DBG_OBJ_MSGF ("resize", 1, "=> %d / %d",
- extremes->minWidth, extremes->maxWidth);
- DBG_OBJ_MSG_END ();
+ return core::style::multiplyWithPerLength (containerHeight, perHeight);
}
void Table::containerSizeChangedForChildren ()
@@ -667,11 +526,13 @@ void Table::forceCalcCellSizes (bool calcHeights)
if (totalWidth < extremes.minWidth)
totalWidth = extremes.minWidth;
- totalWidth -= ((numCols + 1) * getStyle()->hBorderSpacing
- + getStyle()->boxDiffWidth ());
DBG_OBJ_MSGF ("resize", 1, "(ii) totalWidth = %d", totalWidth);
+ totalWidth -= ((numCols + 1) * getStyle()->hBorderSpacing + boxDiffWidth ());
+
+ DBG_OBJ_MSGF ("resize", 1, "(iii) totalWidth = %d", totalWidth);
+
colWidths->setSize (numCols, 0);
cumHeight->setSize (numRows + 1, 0);
rowSpanCells->setSize (0);
diff --git a/dw/table.hh b/dw/table.hh
index cc2aec1b..e76116fb 100644
--- a/dw/table.hh
+++ b/dw/table.hh
@@ -428,13 +428,8 @@ protected:
void sizeAllocateImpl (core::Allocation *allocation);
void resizeDrawImpl ();
- int getAvailWidthOfChild (Widget *child, bool forceValue);
- void correctRequisitionOfChild (Widget *child,
- core::Requisition *requisition,
- void (*splitHeightFun)(int height,
- int *ascent,
- int *descent));
- void correctExtremesOfChild (Widget *child, core::Extremes *extremes);
+ int applyPerWidth (int containerWidth, core::style::Length perWidth);
+ int applyPerHeight (int containerHeight, core::style::Length perHeight);
void containerSizeChangedForChildren ();
bool usesAvailWidth ();
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 5bd0a346..21a9371b 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -1018,7 +1018,6 @@ core::Iterator *Textblock::iterator (core::Content::Type mask, bool atEnd)
return new TextblockIterator (this, mask, atEnd);
}
-
/**
* Calculate the size of a widget within the page.
* (Subject of change in the near future!)
diff --git a/dw/widget.cc b/dw/widget.cc
index 0d84ad2f..7d6bc98b 100644
--- a/dw/widget.cc
+++ b/dw/widget.cc
@@ -498,9 +498,7 @@ int Widget::getAvailWidth (bool forceValue)
DBG_OBJ_MSGF ("resize", 1, "percentage width: %g%%",
100 * style::perLengthVal_useThisOnlyForDebugging
(getStyle()->width));
- width = style::multiplyWithPerLength (viewportWidth,
- getStyle()->width)
- + boxDiffWidth ();
+ width = applyPerWidth (viewportWidth, getStyle()->width);
} else {
DBG_OBJ_MSG ("resize", 1, "no specification");
width = viewportWidth;
@@ -509,7 +507,7 @@ int Widget::getAvailWidth (bool forceValue)
}
DBG_OBJ_MSG_END ();
} else {
- DBG_OBJ_MSG ("resize", 1, "delegatet to container");
+ DBG_OBJ_MSG ("resize", 1, "delegated to container");
DBG_OBJ_MSG_START ();
width = container->getAvailWidthOfChild (this, forceValue);
DBG_OBJ_MSG_END ();
@@ -545,9 +543,7 @@ int Widget::getAvailHeight (bool forceValue)
// something like canvasWidthGreater (analogue to
// canvasHeightGreater) would be complicated and lead to
// possibly contradictory self-references.
- height = style::multiplyWithPerLength (layout->viewportHeight,
- getStyle()->height)
- + boxDiffHeight ();
+ height = applyPerHeight (layout->viewportHeight, getStyle()->height);
else
height = layout->viewportHeight;
} else
@@ -560,8 +556,7 @@ int Widget::getAvailHeight (bool forceValue)
}
void Widget::correctRequisition (Requisition *requisition,
- void (*splitHeightFun)(int height, int *ascent,
- int *descent))
+ void (*splitHeightFun) (int, int *, int *))
{
// TODO Correct by extremes?
@@ -582,9 +577,7 @@ void Widget::correctRequisition (Requisition *requisition,
int viewportWidth =
layout->viewportWidth - (layout->canvasHeightGreater ?
layout->vScrollbarThickness : 0);
- requisition->width =
- style::multiplyWithPerLength (viewportWidth, getStyle()->width)
- + boxDiffWidth ();
+ requisition->width = applyPerWidth (viewportWidth, getStyle()->width);
}
// TODO Perhaps split first, then add box ascent and descent.
@@ -603,9 +596,8 @@ void Widget::correctRequisition (Requisition *requisition,
// to be clarified.
// For layout->viewportHeight, see comment in getAvailHeight().
- splitHeightFun (style::multiplyWithPerLength (layout->viewportHeight,
- getStyle()->height)
- + boxDiffHeight (),
+ splitHeightFun (applyPerHeight (layout->viewportHeight,
+ getStyle()->height),
&requisition->ascent, &requisition->descent);
#endif
}
@@ -635,8 +627,7 @@ void Widget::correctExtremes (Extremes *extremes)
layout->viewportWidth - (layout->canvasHeightGreater ?
layout->vScrollbarThickness : 0);
extremes->minWidth = extremes->maxWidth =
- style::multiplyWithPerLength (viewportWidth, getStyle()->width)
- + boxDiffWidth ();
+ applyPerWidth (viewportWidth, getStyle()->width);
}
} else
container->correctExtremesOfChild (this, extremes);
@@ -1148,6 +1139,18 @@ void Widget::markExtremesChange (int ref)
{
}
+int Widget::applyPerWidth (int containerWidth, style::Length perWidth)
+{
+ return style::multiplyWithPerLength (containerWidth, perWidth)
+ + boxDiffWidth ();
+}
+
+int Widget::applyPerHeight (int containerHeight, style::Length perHeight)
+{
+ return style::multiplyWithPerLength (containerHeight, perHeight)
+ + boxDiffHeight ();
+}
+
int Widget::getAvailWidthOfChild (Widget *child, bool forceValue)
{
// This is a halfway suitable implementation for all
@@ -1180,9 +1183,8 @@ int Widget::getAvailWidthOfChild (Widget *child, bool forceValue)
DBG_OBJ_MSGF ("resize", 1, "percentage width: %g%%",
100 * style::perLengthVal_useThisOnlyForDebugging
(child->getStyle()->width));
- width = style::multiplyWithPerLength (containerContentWidth,
- child->getStyle()->width)
- + child->boxDiffWidth ();
+ width = child->applyPerWidth (containerContentWidth,
+ child->getStyle()->width);
} else {
DBG_OBJ_MSG ("resize", 1, "no specification");
// Some widgets will use the whole width, so this is a
@@ -1223,9 +1225,8 @@ int Widget::getAvailHeightOfChild (Widget *child, bool forceValue)
availHeight, boxDiffHeight (), containerContentHeight);
if (style::isPerLength (child->getStyle()->height))
- height = style::multiplyWithPerLength (containerContentHeight,
- child->getStyle()->height)
- + child->boxDiffHeight ();
+ height = child->applyPerHeight (containerContentHeight,
+ child->getStyle()->height);
else
// Although no widget will probably use the whole height, we
// have to return some value here.
@@ -1240,9 +1241,8 @@ int Widget::getAvailHeightOfChild (Widget *child, bool forceValue)
}
void Widget::correctRequisitionOfChild (Widget *child, Requisition *requisition,
- void (*splitHeightFun)(int height,
- int *ascent,
- int *descent))
+ void (*splitHeightFun) (int, int*,
+ int*))
{
// Again, a suitable implementation for all widgets (perhaps).
@@ -1261,10 +1261,8 @@ void Widget::correctRequisitionOfChild (Widget *child, Requisition *requisition,
int availWidth = getAvailWidth (false);
if (availWidth != -1) {
int containerWidth = availWidth - boxDiffWidth ();
- requisition->width =
- style::multiplyWithPerLength (containerWidth,
- child->getStyle()->width)
- + child->boxDiffWidth ();
+ requisition->width = child->applyPerWidth (containerWidth,
+ child->getStyle()->width);
}
}
@@ -1277,9 +1275,8 @@ void Widget::correctRequisitionOfChild (Widget *child, Requisition *requisition,
int availHeight = getAvailHeight (false);
if (availHeight != -1) {
int containerHeight = availHeight - boxDiffHeight ();
- splitHeightFun (style::multiplyWithPerLength
- (containerHeight, child->getStyle()->height)
- + child->boxDiffHeight (),
+ splitHeightFun (child->applyPerHeight (containerHeight,
+ child->getStyle()->height),
&requisition->ascent, &requisition->descent);
}
}
@@ -1301,20 +1298,26 @@ void Widget::correctExtremesOfChild (Widget *child, Extremes *extremes)
child, extremes->minWidth, extremes->maxWidth);
DBG_OBJ_MSG_START ();
- if (style::isAbsLength (child->getStyle()->width))
+ if (style::isAbsLength (child->getStyle()->width)) {
+ DBG_OBJ_MSGF ("resize", 1, "absolute width: %dpx",
+ style::absLengthVal (child->getStyle()->width));
extremes->minWidth =extremes->maxWidth =
style::absLengthVal (child->getStyle()->width)
+ child->boxDiffWidth ();
- else if (style::isPerLength (child->getStyle()->width)) {
+ } else if (style::isPerLength (child->getStyle()->width)) {
+ DBG_OBJ_MSGF ("resize", 1, "percentage width: %g%%",
+ 100 * style::perLengthVal_useThisOnlyForDebugging
+ (child->getStyle()->width));
int availWidth = getAvailWidth (false);
if (availWidth != -1) {
int containerWidth = availWidth - boxDiffWidth ();
+ DBG_OBJ_MSGF ("resize", 1, "containerWidth = %d - %d = %d",
+ availWidth, boxDiffWidth (), containerWidth);
extremes->minWidth =extremes->maxWidth =
- style::multiplyWithPerLength (containerWidth,
- child->getStyle()->width)
- + child->boxDiffWidth ();
+ child->applyPerWidth (containerWidth, child->getStyle()->width);
}
- }
+ } else
+ DBG_OBJ_MSG ("resize", 1, "no specification");
DBG_OBJ_MSGF ("resize", 1, "=> %d / %d",
extremes->minWidth, extremes->maxWidth);
@@ -1389,6 +1392,8 @@ void Widget::removeChild (Widget *child)
misc::assertNotReached ();
}
+// ----------------------------------------------------------------------
+
void splitHeightPreserveAscent (int height, int *ascent, int *descent)
{
*descent = height - *ascent;
diff --git a/dw/widget.hh b/dw/widget.hh
index 814771b5..0d9e4e5f 100644
--- a/dw/widget.hh
+++ b/dw/widget.hh
@@ -314,14 +314,15 @@ protected:
*/
virtual void markExtremesChange (int ref);
+ virtual int applyPerWidth (int containerWidth, style::Length perWidth);
+ virtual int applyPerHeight (int containerHeight, style::Length perHeight);
+
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,
- int *ascent,
- int
- *descent));
+ void (*splitHeightFun) (int, int*,
+ int*));
virtual void correctExtremesOfChild (Widget *child, Extremes *extremes);
virtual void containerSizeChangedForChildren ();
@@ -445,8 +446,7 @@ public:
int getAvailWidth (bool forceValue);
int getAvailHeight (bool forceValue);
void correctRequisition (Requisition *requisition,
- void (*splitHeightFun)(int height, int *ascent,
- int *descent));
+ void (*splitHeightFun) (int, int*, int*));
void correctExtremes (Extremes *extremes);
virtual bool isBlockLevel ();
@@ -514,7 +514,6 @@ public:
void splitHeightPreserveAscent (int height, int *ascent, int *descent);
void splitHeightPreserveDescent (int height, int *ascent, int *descent);
-
} // namespace core
} // namespace dw