diff options
author | Sebastian Geerken <devnull@localhost> | 2014-06-22 21:08:05 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-06-22 21:08:05 +0200 |
commit | df401973a3c0ef4e4c77de91e53567e86ac57dd7 (patch) | |
tree | 2b7ca08b929b4dba0ffaeceb0c6c1bed30518138 | |
parent | cdb265fcafd2c363f1a809afa702163d430e151d (diff) |
More work on tables. (Also reactivated Table::getAvailWidthOfChild, which was removed accidently.)
-rw-r--r-- | dw/alignedtablecell.hh | 6 | ||||
-rw-r--r-- | dw/simpletablecell.hh | 7 | ||||
-rw-r--r-- | dw/table.cc | 81 | ||||
-rw-r--r-- | dw/table.hh | 6 | ||||
-rw-r--r-- | dw/widget.hh | 6 |
5 files changed, 94 insertions, 12 deletions
diff --git a/dw/alignedtablecell.hh b/dw/alignedtablecell.hh index 59878290..caf59307 100644 --- a/dw/alignedtablecell.hh +++ b/dw/alignedtablecell.hh @@ -12,9 +12,6 @@ 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 (); @@ -26,6 +23,9 @@ public: AlignedTableCell(AlignedTableCell *ref, bool limitTextWidth); ~AlignedTableCell(); + int applyPerWidth (int containerWidth, core::style::Length perWidth); + int applyPerHeight (int containerHeight, core::style::Length perHeight); + bool isBlockLevel (); }; diff --git a/dw/simpletablecell.hh b/dw/simpletablecell.hh index 4701a90e..a452add9 100644 --- a/dw/simpletablecell.hh +++ b/dw/simpletablecell.hh @@ -7,16 +7,15 @@ 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; SimpleTableCell (bool limitTextWidth); ~SimpleTableCell (); + int applyPerWidth (int containerWidth, core::style::Length perWidth); + int applyPerHeight (int containerHeight, core::style::Length perHeight); + bool isBlockLevel (); }; diff --git a/dw/table.cc b/dw/table.cc index 5dacc35d..824759db 100644 --- a/dw/table.cc +++ b/dw/table.cc @@ -201,6 +201,68 @@ void Table::resizeDrawImpl () redrawY = getHeight (); } +int Table::getAvailWidthOfChild (Widget *child, bool forceValue) +{ + 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 { + int containerContentWidth = availWidth - boxDiffWidth (); + width = child->applyPerWidth (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; +} + int Table::applyPerWidth (int containerWidth, core::style::Length perWidth) { return core::style::multiplyWithPerLength (containerWidth, perWidth); @@ -538,6 +600,9 @@ void Table::forceCalcCellSizes (bool calcHeights) rowSpanCells->setSize (0); baseline->setSize (numRows); + misc::SimpleVector<int> *oldColWidths = colWidths; + colWidths = new misc::SimpleVector <int> (8); + apportion2 (totalWidth, getStyle()->width != core::style::LENGTH_AUTO, 0, colExtremes->size() - 1, colWidths, 0, true); @@ -551,6 +616,22 @@ void Table::forceCalcCellSizes (bool calcHeights) DBG_OBJ_SET_BOOL ("colWidthsUpToDateWidthColExtremes", colWidthsUpToDateWidthColExtremes); + for (int col = 0; col < numCols; col++) { + if (col >= oldColWidths->size () || col >= colWidths->size () || + oldColWidths->get (col) != colWidths->get (col)) { + // Column width has changed, tell children about this. + for (int row = 0; row < numRows; row++) { + int n = row * numCols + col; + // TODO: Columns spanning several rows are only regarded + // when the first column is affected. + if (childDefined (n)) + children->get(n)->cell.widget->containerSizeChanged (); + } + } + } + + delete oldColWidths; + if (calcHeights) { setCumHeight (0, 0); for (int row = 0; row < numRows; row++) { diff --git a/dw/table.hh b/dw/table.hh index e76116fb..5288c986 100644 --- a/dw/table.hh +++ b/dw/table.hh @@ -428,8 +428,7 @@ protected: void sizeAllocateImpl (core::Allocation *allocation); void resizeDrawImpl (); - int applyPerWidth (int containerWidth, core::style::Length perWidth); - int applyPerHeight (int containerHeight, core::style::Length perHeight); + int getAvailWidthOfChild (Widget *child, bool forceValue); void containerSizeChangedForChildren (); bool usesAvailWidth (); @@ -450,6 +449,9 @@ public: Table(bool limitTextWidth); ~Table(); + int applyPerWidth (int containerWidth, core::style::Length perWidth); + int applyPerHeight (int containerHeight, core::style::Length perHeight); + core::Iterator *iterator (core::Content::Type mask, bool atEnd); void addCell (Widget *widget, int colspan, int rowspan); diff --git a/dw/widget.hh b/dw/widget.hh index 0d9e4e5f..00fc2aa5 100644 --- a/dw/widget.hh +++ b/dw/widget.hh @@ -314,9 +314,6 @@ 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, @@ -448,6 +445,9 @@ public: void correctRequisition (Requisition *requisition, void (*splitHeightFun) (int, int*, int*)); void correctExtremes (Extremes *extremes); + + virtual int applyPerWidth (int containerWidth, style::Length perWidth); + virtual int applyPerHeight (int containerHeight, style::Length perHeight); virtual bool isBlockLevel (); virtual bool isPossibleContainer (); |