#include <table.hh>
Classes | |
| struct | Child |
| class | TableIterator |
Public Member Functions | |
| Table (bool limitTextWidth) | |
| ~Table () | |
| core::Iterator * | iterator (core::Content::Type mask, bool atEnd) |
| Return an iterator for this widget. | |
| void | addCell (Widget *widget, int colspan, int rowspan) |
| void | addRow (core::style::Style *style) |
| TableCell * | getCellRef () |
Static Public Attributes | |
| static int | CLASS_ID = -1 |
Protected Member Functions | |
| void | sizeRequestImpl (core::Requisition *requisition) |
| See Sizes of Dillo Widgets. | |
| void | getExtremesImpl (core::Extremes *extremes) |
| See Sizes of Dillo Widgets. | |
| void | sizeAllocateImpl (core::Allocation *allocation) |
| See Sizes of Dillo Widgets. | |
| void | resizeDrawImpl () |
| Called after sizeAllocateImpl() to redraw necessary areas. By default the whole widget is redrawn. | |
| void | setWidth (int width) |
| void | setAscent (int ascent) |
| void | setDescent (int descent) |
| void | draw (core::View *view, core::Rectangle *area) |
| void | removeChild (Widget *child) |
Private Types | |
| enum | { LEN_AUTO = -1, LEN_ABS = -2 } |
Private Member Functions | |
| bool | childDefined (int n) |
| void | reallocChildren (int newNumCols, int newNumRows) |
| void | calcCellSizes () |
| void | forceCalcCellSizes () |
| void | apportionRowSpan () |
| void | calcColumnExtremes () |
| Fills dw::Table::colExtremes, only if recalculation is necessary. | |
| void | forceCalcColumnExtremes () |
| Fills dw::Table::colExtremes in all cases. | |
| void | apportion2 (int totalWidth, int forceTotalWidth) |
| Apportionment function for AUTO-length columns. 'extremes' comes filled, 'result' comes defined for percentage columns. | |
| void | apportion_percentages2 (int totalWidth, int forceTotalWidth) |
| void | setCumHeight (int row, int value) |
| void | setColWidth (int col, int value) |
Private Attributes | |
| bool | limitTextWidth |
| bool | rowClosed |
| int | availWidth |
| int | availAscent |
| int | availDescent |
| int | numRows |
| int | numCols |
| int | curRow |
| int | curCol |
| lout::misc::SimpleVector < Child * > * | children |
| int | redrawX |
| int | redrawY |
| lout::misc::SimpleVector < core::Extremes > * | colExtremes |
| The extremes of all columns. | |
| lout::misc::SimpleVector< int > * | colWidths |
| The widths of all columns. | |
| lout::misc::SimpleVector< int > * | cumHeight |
| lout::misc::SimpleVector< int > * | rowSpanCells |
| lout::misc::SimpleVector< int > * | colSpanCells |
| lout::misc::SimpleVector< int > * | baseline |
| lout::misc::SimpleVector < core::style::Style * > * | rowStyle |
| int | hasColPercent |
| lout::misc::SimpleVector< float > * | colPercents |
Friends | |
| class | TableIterator |
The dw::Table widget is used to render HTML tables.
Each cell is itself a separate widget. Any widget may be used, however, in dillo, only instances of dw::Textblock and dw::TableCell are used as children of dw::Table.
The following diagram shows the dependencies between the different functions, which are related to size calculation. Click on the boxes for more information.
[A] In this case, the new calculation is not forced, but only done, when necessary.
[B] In this case, the new calculation is allways necessary, since [C] is the case.
[C] Whether this function is called, depends on NEEDS_RESIZE / EXTREMES_CHANGED.
and
, which represent the column minima and maxima, and a total width
, apportionment means to calculate column widths
, with
and
There are different algorithms for apportionment, a simple one is recommended in the HTML 4.0.1 specification (http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.5.2.2):
This one is used currently, but another one will be used soon, which is described below. The rest of this chapter is independent of the exact apportionment algorithm.
When referring to the apportionment function, we will call it
and write something like this:
It is implemented by dw::Table::apportion.
only for cells
with colspan = 1.
(but not
) are calculated from cells with colspan > 1. (In the following formulas, the cell at
always span from
to
.) If the minimal width of the column exceeds the sum of the column minima calculated in the last step:
then the minimal width of this cell is apportioned to the columns:
then
is apportioned in a simple way:
After this,
is then the maximum of all
.
For the maxima, there is no
, but it has to be assured, that the maximum is always greater than or equal to the minimum.
Generally, if absolute widths are specified, they are, instead of the results of dw::core::Widget::getExtremes, taken for the minimal and maximal width of a cell (minus the box difference, i.e. the difference between content size and widget size). If the content width specification is smaller than the minimal content width of the widget (determined by dw::core::Widget::getExtremes), the latter is used instead.
If percentage widths are specified, they are also collected, as column maxima. A similar method as for the extremes is used, for cells with colspan > 1:
The total width is
In any case, it is corrected, if it is less than the minimal width (but not if it is greater than the maximal width).
.
The following algorithms are used to solve collisions between different size specifications (absolute and percentage). Generally, inherent sizes and specified absolute sizes are preferred.
with only those columns
with no percentage width specification.
with only those columns
with a percentage width specification.
: In this case, the percentage widths can be used without any modification, by setting the extremes:
for only those columns
with a percentage width specification.
: In this case, the widths for these columns must be cut down:
with
in both cases for only those columns
with a percentage width specification.
(
and
are set temporarily here, the notation should be a bit clearer.)
The column widths are now simply calculated by applying the apportionment function.
...
The algorithm described here tends to result in more homogeneous column widths.
The following rule leads to well-defined
: All columns
have have the same width
, except:
, or
.
Furthermore,
is
of columns not having
as width, and
of columns not having
as width.
Of course,
must be the case.
Based on an initial value
,
can iteratively adjusted, based on these rules.
Currently, DwTable supports only the separated borders model (see CSS specification). Borders, paddings, spacing is done by creating dw::core::style::Style structures with values equivalent to following CSS:
TABLE {
border: outset table-border;
border-collapse: separate;
border-spacing: table-cellspacing;
background-color: table-bgcolor;
}
TD TH {
border: inset table-border;
padding: table-cellspacing;
background-color: td/th-bgcolor;
}
Here, foo-bar refers to the attribute bar of the tag foo foo. Look at the HTML parser for more details.
anonymous enum [private] |
| dw::Table::Table | ( | bool | limitTextWidth | ) |
References availAscent, availDescent, availWidth, baseline, dw::core::Widget::BLOCK_LEVEL, children, CLASS_ID, colExtremes, colPercents, colSpanCells, colWidths, cumHeight, curCol, curRow, hasColPercent, numCols, numRows, redrawX, redrawY, lout::identity::IdentifiableObject::registerName(), rowClosed, rowSpanCells, rowStyle, dw::core::Widget::setButtonSensitive(), dw::core::Widget::setFlags(), and dw::core::Widget::USES_HINTS.
| dw::Table::~Table | ( | ) |
References baseline, dw::Table::Child::cell, dw::Table::Child::CELL, children, colExtremes, colPercents, colSpanCells, colWidths, cumHeight, lout::misc::SimpleVector< T >::get(), rowSpanCells, rowStyle, lout::misc::SimpleVector< T >::size(), dw::Table::Child::SPAN_SPACE, dw::Table::Child::type, and dw::core::style::Style::unref().
| void dw::Table::addCell | ( | Widget * | widget, | |
| int | colspan, | |||
| int | rowspan | |||
| ) |
References addRow(), dw::core::style::StyleAttrs::backgroundColor, dw::Table::Child::cell, dw::Table::Child::CELL, children, curCol, curRow, lout::misc::SimpleVector< T >::get(), MAX, numCols, numRows, dw::core::Widget::queueResize(), reallocChildren(), rowClosed, rowStyle, lout::misc::SimpleVector< T >::set(), dw::Table::Child::SPAN_SPACE, dw::Table::Child::spanSpace, and dw::Table::Child::type.
| void dw::Table::addRow | ( | core::style::Style * | style | ) |
References curCol, curRow, lout::misc::SimpleVector< T >::get(), numCols, numRows, reallocChildren(), dw::core::style::Style::ref(), rowClosed, rowStyle, lout::misc::SimpleVector< T >::set(), and dw::core::style::Style::unref().
Referenced by addCell().
| void dw::Table::apportion2 | ( | int | totalWidth, | |
| int | forceTotalWidth | |||
| ) | [private] |
Apportionment function for AUTO-length columns. 'extremes' comes filled, 'result' comes defined for percentage columns.
References availWidth, colExtremes, colPercents, colWidths, dw::core::Widget::extremes, lout::misc::SimpleVector< T >::get(), lout::misc::SimpleVector< T >::getRef(), LEN_ABS, LEN_AUTO, MAX, dw::core::Extremes::maxWidth, dw::core::Extremes::minWidth, numCols, setColWidth(), lout::misc::SimpleVector< T >::setSize(), and lout::misc::SimpleVector< T >::size().
Referenced by apportion_percentages2(), and forceCalcCellSizes().
| void dw::Table::apportion_percentages2 | ( | int | totalWidth, | |
| int | forceTotalWidth | |||
| ) | [private] |
References apportion2(), availWidth, colExtremes, colPercents, colWidths, lout::misc::SimpleVector< T >::get(), lout::misc::SimpleVector< T >::getRef(), dw::core::Widget::getStyle(), hasColPercent, dw::core::style::isPerLength(), LEN_ABS, LEN_AUTO, MAX, dw::core::Extremes::maxWidth, lout::misc::min(), dw::core::Extremes::minWidth, numCols, setColWidth(), and lout::misc::SimpleVector< T >::size().
Referenced by forceCalcCellSizes().
| void dw::Table::apportionRowSpan | ( | ) | [private] |
References dw::core::Requisition::ascent, dw::Table::Child::cell, children, cumHeight, dw::core::Requisition::descent, lout::misc::SimpleVector< T >::get(), dw::core::Widget::getStyle(), numCols, numRows, rowSpanCells, setCumHeight(), and lout::misc::SimpleVector< T >::size().
Referenced by forceCalcCellSizes().
| void dw::Table::calcCellSizes | ( | ) | [private] |
References forceCalcCellSizes(), and dw::core::Widget::needsResize().
Referenced by sizeAllocateImpl().
| void dw::Table::calcColumnExtremes | ( | ) | [private] |
Fills dw::Table::colExtremes, only if recalculation is necessary.
References dw::core::Widget::extremesChanged(), and forceCalcColumnExtremes().
| bool dw::Table::childDefined | ( | int | n | ) | [inline, private] |
| void dw::Table::draw | ( | core::View * | view, | |
| core::Rectangle * | area | |||
| ) | [protected, virtual] |
Area is given in widget coordinates.
Implements dw::core::Widget.
References dw::Table::Child::cell, childDefined(), children, cumHeight, dw::core::Widget::drawBox(), dw::core::Widget::drawWidgetBox(), lout::misc::SimpleVector< T >::get(), dw::core::Widget::getContentWidth(), dw::core::Widget::getStyle(), numRows, rowStyle, lout::misc::SimpleVector< T >::size(), and dw::core::Widget::Widget().
| void dw::Table::forceCalcCellSizes | ( | ) | [private] |
References dw::core::style::absLengthVal(), apportion2(), apportion_percentages2(), apportionRowSpan(), dw::core::Requisition::ascent, availWidth, baseline, dw::Table::Child::cell, childDefined(), children, colWidths, cumHeight, curCol, dw::core::Requisition::descent, dw::core::Widget::extremes, lout::misc::SimpleVector< T >::get(), dw::core::Widget::getExtremes(), dw::core::Widget::getStyle(), hasColPercent, lout::misc::SimpleVector< T >::increase(), dw::core::style::isAbsLength(), dw::core::style::isPerLength(), dw::core::style::LENGTH_AUTO, MAX, dw::core::Extremes::maxWidth, lout::misc::min(), dw::core::Extremes::minWidth, numCols, numRows, dw::core::style::perLengthVal(), rowSpanCells, lout::misc::SimpleVector< T >::set(), setCumHeight(), lout::misc::SimpleVector< T >::setSize(), and lout::misc::SimpleVector< T >::size().
Referenced by calcCellSizes(), and sizeRequestImpl().
| void dw::Table::forceCalcColumnExtremes | ( | ) | [private] |
Fills dw::Table::colExtremes in all cases.
References dw::core::style::absLengthVal(), dw::Table::Child::cell, childDefined(), children, colExtremes, colPercents, colSpanCells, lout::misc::SimpleVector< T >::get(), lout::misc::SimpleVector< T >::getRef(), dw::core::Widget::getStyle(), hasColPercent, lout::misc::SimpleVector< T >::increase(), dw::core::style::isAbsLength(), dw::core::style::isPerLength(), LEN_AUTO, MAX, dw::core::Extremes::maxWidth, dw::core::Extremes::minWidth, numCols, numRows, dw::core::style::perLengthVal(), lout::misc::SimpleVector< T >::set(), lout::misc::SimpleVector< T >::setSize(), and lout::misc::SimpleVector< T >::size().
Referenced by calcColumnExtremes(), and getExtremesImpl().
| TableCell * dw::Table::getCellRef | ( | ) |
| void dw::Table::getExtremesImpl | ( | core::Extremes * | extremes | ) | [protected, virtual] |
Reimplemented from dw::core::Widget.
References dw::core::style::absLengthVal(), colExtremes, forceCalcColumnExtremes(), lout::misc::SimpleVector< T >::getRef(), dw::core::Widget::getStyle(), dw::core::style::isAbsLength(), MAX, dw::core::Extremes::maxWidth, dw::core::Extremes::minWidth, and numCols.
| core::Iterator * dw::Table::iterator | ( | core::Content::Type | mask, | |
| bool | atEnd | |||
| ) | [virtual] |
Return an iterator for this widget.
mask can narrow the types returned by the iterator, this can enhance performance quite much, e.g. when only searching for child widgets.
With atEnd == false, the iterator starts before the beginning, i.e. the first call of dw::core::Iterator::next will let the iterator point on the first piece of contents. Likewise, With atEnd == true, the iterator starts after the last piece of contents, call dw::core::Iterator::prev in this case.
Implements dw::core::Widget.
References TableIterator.
| void dw::Table::reallocChildren | ( | int | newNumCols, | |
| int | newNumRows | |||
| ) | [private] |
References dw::Table::Child::cell, dw::Table::Child::CELL, children, dw::Table::Child::colspanOrig, lout::misc::SimpleVector< T >::get(), numCols, numRows, rowStyle, lout::misc::SimpleVector< T >::set(), lout::misc::SimpleVector< T >::setSize(), dw::Table::Child::SPAN_SPACE, dw::Table::Child::spanSpace, and dw::Table::Child::type.
| void dw::Table::removeChild | ( | Widget * | child | ) | [protected] |
| void dw::Table::resizeDrawImpl | ( | ) | [protected, virtual] |
Called after sizeAllocateImpl() to redraw necessary areas. By default the whole widget is redrawn.
Reimplemented from dw::core::Widget.
References dw::core::Widget::allocation, dw::core::Widget::getHeight(), dw::core::Widget::queueDrawArea(), redrawX, and redrawY.
| void dw::Table::setAscent | ( | int | ascent | ) | [protected, virtual] |
| void dw::Table::setColWidth | ( | int | col, | |
| int | value | |||
| ) | [inline, private] |
References colWidths, lout::misc::SimpleVector< T >::get(), lout::misc::min(), redrawX, and lout::misc::SimpleVector< T >::set().
Referenced by apportion2(), and apportion_percentages2().
| void dw::Table::setCumHeight | ( | int | row, | |
| int | value | |||
| ) | [inline, private] |
References cumHeight, lout::misc::SimpleVector< T >::get(), lout::misc::min(), redrawY, and lout::misc::SimpleVector< T >::set().
Referenced by apportionRowSpan(), and forceCalcCellSizes().
| void dw::Table::setDescent | ( | int | descent | ) | [protected, virtual] |
| void dw::Table::setWidth | ( | int | width | ) | [protected, virtual] |
Reimplemented from dw::core::Widget.
References availWidth, limitTextWidth, and dw::core::Widget::queueResize().
| void dw::Table::sizeAllocateImpl | ( | core::Allocation * | allocation | ) | [protected, virtual] |
Reimplemented from dw::core::Widget.
References dw::core::Requisition::ascent, dw::core::Allocation::ascent, calcCellSizes(), dw::Table::Child::cell, childDefined(), children, colWidths, cumHeight, dw::core::Allocation::descent, lout::misc::SimpleVector< T >::get(), dw::core::Widget::getStyle(), numCols, numRows, dw::core::Allocation::width, dw::core::Allocation::x, and dw::core::Allocation::y.
| void dw::Table::sizeRequestImpl | ( | core::Requisition * | requisition | ) | [protected, virtual] |
Implements dw::core::Widget.
References dw::core::Requisition::ascent, colWidths, cumHeight, dw::core::Requisition::descent, forceCalcCellSizes(), lout::misc::SimpleVector< T >::get(), dw::core::Widget::getStyle(), numCols, numRows, and dw::core::Requisition::width.
friend class TableIterator [friend] |
Referenced by iterator().
int dw::Table::availAscent [private] |
Referenced by setAscent(), and Table().
int dw::Table::availDescent [private] |
Referenced by setDescent(), and Table().
int dw::Table::availWidth [private] |
Referenced by apportion2(), apportion_percentages2(), forceCalcCellSizes(), setWidth(), and Table().
lout::misc::SimpleVector<int>* dw::Table::baseline [private] |
Referenced by forceCalcCellSizes(), Table(), and ~Table().
lout::misc::SimpleVector<Child*>* dw::Table::children [private] |
Referenced by addCell(), apportionRowSpan(), childDefined(), draw(), forceCalcCellSizes(), forceCalcColumnExtremes(), getCellRef(), dw::Table::TableIterator::next(), dw::Table::TableIterator::prev(), reallocChildren(), sizeAllocateImpl(), Table(), dw::Table::TableIterator::TableIterator(), and ~Table().
int dw::Table::CLASS_ID = -1 [static] |
The extremes of all columns.
Referenced by apportion2(), apportion_percentages2(), forceCalcColumnExtremes(), getExtremesImpl(), Table(), and ~Table().
lout::misc::SimpleVector<float>* dw::Table::colPercents [private] |
Referenced by apportion2(), apportion_percentages2(), forceCalcColumnExtremes(), Table(), and ~Table().
lout::misc::SimpleVector<int>* dw::Table::colSpanCells [private] |
If a Cell has colspan > 1, it goes into this array
Referenced by forceCalcColumnExtremes(), Table(), and ~Table().
lout::misc::SimpleVector<int>* dw::Table::colWidths [private] |
The widths of all columns.
Referenced by apportion2(), apportion_percentages2(), forceCalcCellSizes(), setColWidth(), sizeAllocateImpl(), sizeRequestImpl(), Table(), and ~Table().
lout::misc::SimpleVector<int>* dw::Table::cumHeight [private] |
Row cumulative height array: cumHeight->size() is numRows + 1, cumHeight->get(0) is 0, cumHeight->get(numRows) is the total table height.
Referenced by apportionRowSpan(), draw(), forceCalcCellSizes(), setCumHeight(), sizeAllocateImpl(), sizeRequestImpl(), Table(), and ~Table().
int dw::Table::curCol [private] |
Referenced by addCell(), addRow(), forceCalcCellSizes(), getCellRef(), and Table().
int dw::Table::curRow [private] |
int dw::Table::hasColPercent [private] |
Referenced by apportion_percentages2(), forceCalcCellSizes(), forceCalcColumnExtremes(), and Table().
bool dw::Table::limitTextWidth [private] |
Referenced by setWidth().
int dw::Table::numCols [private] |
int dw::Table::numRows [private] |
int dw::Table::redrawX [private] |
Referenced by resizeDrawImpl(), setColWidth(), and Table().
int dw::Table::redrawY [private] |
Referenced by resizeDrawImpl(), setCumHeight(), and Table().
bool dw::Table::rowClosed [private] |
lout::misc::SimpleVector<int>* dw::Table::rowSpanCells [private] |
If a Cell has rowspan > 1, it goes into this array
Referenced by apportionRowSpan(), forceCalcCellSizes(), Table(), and ~Table().
1.5.9