dillo
3.0.5
About: dillo is a small, fast, extensible Web browser particularly suitable for older or smaller computers and embedded systems (but only limited or no support for frames, CSS, JavaScript, Java).
![]() ![]() |
A Widget for rendering tables. More...
#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. More... | |
void | addCell (Widget *widget, int colspan, int rowspan) |
void | addRow (core::style::Style *style) |
TableCell * | getCellRef () |
![]() | |
void | setDeleteCallback (DW_Callback_t func, void *data) |
Widget () | |
~Widget () | |
bool | needsResize () |
bool | needsAllocate () |
bool | extremesChanged () |
bool | wasAllocated () |
bool | usesHints () |
bool | hasContents () |
bool | blockLevel () |
void | setParent (Widget *parent) |
style::Style * | getStyle () |
Allocation * | getAllocation () |
void | sizeRequest (Requisition *requisition) |
This method is a wrapper for Widget::sizeRequestImpl(); it calls the latter only when needed. More... | |
void | getExtremes (Extremes *extremes) |
Wrapper for Widget::getExtremesImpl(). More... | |
void | sizeAllocate (Allocation *allocation) |
Wrapper for Widget::sizeAllocateImpl, calls the latter only when needed. More... | |
bool | intersects (Rectangle *area, Rectangle *intersection) |
Calculates the intersection of widget->allocation and area, returned in intersection (in widget coordinates!). More... | |
bool | buttonPress (EventButton *event) |
bool | buttonRelease (EventButton *event) |
bool | motionNotify (EventMotion *event) |
void | enterNotify (EventCrossing *event) |
void | leaveNotify (EventCrossing *event) |
virtual void | setStyle (style::Style *style) |
Change the style of a widget. More... | |
void | setBgColor (style::Color *bgColor) |
Set the background "behind" the widget, if it is not the background of the parent widget, e.g. the background of a table row. More... | |
style::Color * | getBgColor () |
Get the actual background of a widget. More... | |
void | drawBox (View *view, style::Style *style, Rectangle *area, int x, int y, int width, int height, bool inverse) |
Draw borders and background of a widget part, which allocation is given by (x, y, width, height) (widget coordinates). More... | |
void | drawWidgetBox (View *view, Rectangle *area, bool inverse) |
Draw borders and background of a widget. More... | |
void | drawSelected (View *view, Rectangle *area) |
void | setButtonSensitive (bool buttonSensitive) |
bool | isButtonSensitive () |
Widget * | getParent () |
Widget * | getTopLevel () |
Get the widget at the root of the tree, this widget is part from. More... | |
int | getLevel () |
Get the level of the widget within the tree. More... | |
Widget * | getNearestCommonAncestor (Widget *otherWidget) |
Get the widget with the highest level, which is a direct ancestor of widget1 and widget2. More... | |
Layout * | getLayout () |
virtual Widget * | getWidgetAtPoint (int x, int y, int level) |
Search recursively through widget. More... | |
void | scrollTo (HPosition hpos, VPosition vpos, int x, int y, int width, int height) |
void | getPaddingArea (int *xPad, int *yPad, int *widthPad, int *heightPad) |
Return the padding area (content plus padding). More... | |
virtual void | removeChild (Widget *child) |
![]() | |
IdentifiableObject () | |
virtual void | intoStringBuffer (misc::StringBuffer *sb) |
Store a textual representation of the object in a misc::StringBuffer. More... | |
int | getClassId () |
Returns the class identifier. More... | |
const char * | getClassName () |
Return the name, under which the class of this object was registered. More... | |
bool | instanceOf (int otherClassId) |
Returns, whether this class is an instance of the class, given by otherClassId, or of a sub class of this class. More... | |
![]() | |
virtual | ~Object () |
The destructor is defined as virtual (but not abstract), so that destruction of Object's works properly. More... | |
virtual bool | equals (Object *other) |
Returns, whether two objects are equal. More... | |
virtual int | hashValue () |
Return a hash value for the object. More... | |
virtual Object * | clone () |
Return an exact copy of the object. More... | |
const char * | toString () |
Use object::Object::intoStringBuffer to return a textual representation of the object. More... | |
virtual size_t | sizeOf () |
Return the number of bytes, this object totally uses. More... | |
Static Public Attributes | |
static int | CLASS_ID = -1 |
![]() | |
static int | CLASS_ID = -1 |
Protected Member Functions | |
void | sizeRequestImpl (core::Requisition *requisition) |
See Sizes of Dillo Widgets. More... | |
void | getExtremesImpl (core::Extremes *extremes) |
See Sizes of Dillo Widgets. More... | |
void | sizeAllocateImpl (core::Allocation *allocation) |
See Sizes of Dillo Widgets. More... | |
void | resizeDrawImpl () |
Called after sizeAllocateImpl() to redraw necessary areas. By default the whole widget is redrawn. More... | |
void | setWidth (int width) |
void | setAscent (int ascent) |
void | setDescent (int descent) |
void | draw (core::View *view, core::Rectangle *area) |
void | removeChild (Widget *child) |
![]() | |
int | getHeight () |
int | getContentWidth () |
int | getContentHeight () |
void | setFlags (Flags f) |
void | unsetFlags (Flags f) |
void | queueDraw () |
void | queueDrawArea (int x, int y, int width, int height) |
void | queueResize (int ref, bool extremesChanged) |
This method should be called, when a widget changes its size. More... | |
virtual void | markSizeChange (int ref) |
See Sizes of Dillo Widgets. More... | |
virtual void | markExtremesChange (int ref) |
See Sizes of Dillo Widgets. More... | |
virtual bool | buttonPressImpl (EventButton *event) |
virtual bool | buttonReleaseImpl (EventButton *event) |
virtual bool | motionNotifyImpl (EventMotion *event) |
virtual void | enterNotifyImpl (EventCrossing *event) |
virtual void | leaveNotifyImpl (EventCrossing *event) |
char * | addAnchor (const char *name) |
char * | addAnchor (const char *name, int y) |
void | changeAnchor (char *name, int y) |
void | removeAnchor (char *name) |
void | setCursor (style::Cursor cursor) |
bool | selectionHandleEvent (SelectionState::EventType eventType, Iterator *it, int charPos, int linkNo, MousePositionEvent *event) |
![]() | |
void | registerName (const char *className, int *classId) |
This method must be called in the constructor for the sub class. See class comment for details. More... | |
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. More... | |
void | forceCalcColumnExtremes () |
Fills dw::Table::colExtremes in all cases. More... | |
void | apportion2 (int totalWidth, int forceTotalWidth) |
Apportionment function for AUTO-length columns. 'extremes' comes filled, 'result' comes defined for percentage columns. More... | |
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. More... | |
lout::misc::SimpleVector< int > * | colWidths |
The widths of all columns. More... | |
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< core::style::Length > * | colPercents |
Friends | |
class | TableIterator |
Additional Inherited Members | |
![]() | |
int | parentRef |
This value is defined by the parent widget, and used for incremential resizing. More... | |
![]() | |
enum | Flags { NEEDS_RESIZE = 1 << 0, NEEDS_ALLOCATE = 1 << 1, EXTREMES_CHANGED = 1 << 2, USES_HINTS = 1 << 3, HAS_CONTENTS = 1 << 4, WAS_ALLOCATED = 1 << 5, BLOCK_LEVEL = 1 << 6 } |
![]() | |
WidgetImgRenderer * | widgetImgRenderer |
Allocation | allocation |
The current allocation: size and position, always relative to the canvas. More... | |
Layout * | layout |
A Widget for rendering tables.
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.
Given two array \(e_{i,\min}\) and \(e_{i,\max}\), which represent the column minima and maxima, and a total width \(W\), apportionment means to calculate column widths \(w_{i}\), with
\[e_{i,\min} \le w_{i} \le e_{i,\max}\]
and
\[\sum w_{i} = W\]
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):
\[w_{i} = e_{i,\min} + {e_{i,\max} - e_{i,\min}\over\sum e_{i,\max} - \sum e_{i,\min}} (W - \sum e_{i,\min})\]
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 \(a_i (W, (e_{i,\min}), (e_{i,\min}))\) and write something like this:
\[w_{i} = a_i (W, (e_{i,\min}), (e_{i,\max})) \]
It is implemented by dw::Table::apportion.
The sizes, which all other sizes depend on, are column extremes, which define, how wide a column may be at min and at max. They are calculated in the following way:
First, only cells with colspan = 1 are regarded:
\[ e_{\hbox{base},i,\min} = \max \{ e_{\hbox{cell},i,j,\min} \} \]
\[ e_{\hbox{base},i,\max} = \max \{ e_{\hbox{cell},i,j,\max} \} \]
only for cells \((i, j)\) with colspan = 1.
Then, \(e_{\hbox{span},i,\min}\) (but not \(e_{\hbox{span},i,\max}\)) are calculated from cells with colspan > 1. (In the following formulas, the cell at \((i_1, j)\) always span from \(i_1\) to \(i_2\).) If the minimal width of the column exceeds the sum of the column minima calculated in the last step:
\[e_{\hbox{cell},i_1,j,\min} > \sum_{i=i_1}^{i=i_2} e_{\hbox{base},i,\min}\]
then the minimal width of this cell is apportioned to the columns:
\[e_{\hbox{cell},i_1,j,\min} > \sum_{i=i_1}^{i=i_2} e_{\hbox{base},i,\max}\]
then \(e_{\hbox{cell},i_1,j,\min}\) is apportioned in a simple way:\[e_{\hbox{span},i,j,\min} = e_{\hbox{base},i,\max} {e_{\hbox{span},i,j,\min} \over \sum_{i=i_1}^{i=i_2} e_{\hbox{base},i,\max}}\]
\[e_{\hbox{span},i,j,\min} = a_i (e_{\hbox{cell},i_1,j,\min}, (e_{\hbox{cell},i_1,j,\min} \ldots e_{\hbox{cell},i_2,j,\min}), (e_{\hbox{cell},i_1,j,\max} \ldots e_{\hbox{cell},i_2,j,\max}))\]
After this, \(e_{\hbox{span},i,\min}\) is then the maximum of all \(e_{\hbox{span},i,j,\min}\).
Finally, the maximum of both is used.
\[ e_{i,\min} = \max \{ e_{\hbox{base},i,\min}, e_{\hbox{span},i,\min} \} \]
\[ e_{i,\max} = \max \{ e_{\hbox{base},i,\max}, e_{i,\min} \} \]
For the maxima, there is no \(e_{\hbox{span},i,\max}\), 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:
\[w_{\hbox{span},i,j,\%} = a_i (w_{\hbox{cell},i_1,j,\%}, (e_{\hbox{cell},i_1,j,\min} \ldots e_{\hbox{cell},i_2,j,\min}), (e_{\hbox{cell},i_1,j,\max} \ldots e_{\hbox{cell},i_2,j,\max}))\]
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).
Details on differences because of styles are omitted. Below, this total width is called \(W\).
The following algorithms are used to solve collisions between different size specifications (absolute and percentage). Generally, inherent sizes and specified absolute sizes are preferred.
First, calculate the sum of the minimal widths, for columns, where no percentage width has been specified. The difference to the total width is at max available to the columns with percentage width specifications:
\[W_{\hbox{columns}_\%,\hbox{available}} = W - \sum e_{i,\min}\]
with only those columns \(i\) with no percentage width specification.
Then, calculate the sum of the widths, which the columns with percentage width specification would allocate, when fully adhering to them:
\[W_{\hbox{columns}_\%,\hbox{best}} = W \sum w_{i,\%}\]
with only those columns \(i\) with a percentage width specification.
Two cases are distinguished:
\(W_{\hbox{columns}_\%,\hbox{available}} \ge W_{\hbox{columns}_\%,\hbox{best}}\): In this case, the percentage widths can be used without any modification, by setting the extremes:
\[e_{i,\min} = e_{i,\max} = W w_{i,\%}\]
for only those columns \(i\) with a percentage width specification.
\[e_{i,\min} = e_{i,\max} = w_{i,\%} {W_{\hbox{columns}_\%,\hbox{available}} \over w_{\hbox{total},\%}}\]
with\[w_{\hbox{total},\%} = \sum w_{i,\%}\]
in both cases for only those columns \(i\) with a percentage width specification.( \(e_{i,\min}\) and \(e_{i,\max}\) 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 \(w_{i}\): All columns \(i\) have have the same width \(w\), except:
Furthermore, \(w\) is
Of course, \(\sum w_{i} = W\) must be the case.
Based on an initial value \(w = {W\over n}\), \(w\) 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.
dw::Table::Table | ( | bool | limitTextWidth | ) |
Definition at line 33 of file table.cc.
References DBG_OBJ_CREATE.
dw::Table::~Table | ( | ) |
Definition at line 72 of file table.cc.
References DBG_OBJ_DELETE.
void dw::Table::addCell | ( | Widget * | widget, |
int | colspan, | ||
int | rowspan | ||
) |
Definition at line 273 of file table.cc.
References _MSG, dw::Table::Child::cell, lout::misc::max(), MSG, MSG_WARN, dw::Table::Child::spanSpace, and dw::Table::Child::type.
void dw::Table::addRow | ( | core::style::Style * | style | ) |
Definition at line 378 of file table.cc.
References dw::core::style::Style::ref().
|
private |
Apportionment function for AUTO-length columns. 'extremes' comes filled, 'result' comes defined for percentage columns.
Definition at line 847 of file table.cc.
References _MSG, dw::core::style::isAbsLength(), dw::core::style::LENGTH_AUTO, lout::misc::max(), and MSG.
|
private |
Definition at line 927 of file table.cc.
References _MSG, dw::core::style::isAbsLength(), dw::core::style::isPerLength(), dw::core::style::LENGTH_AUTO, lout::misc::max(), lout::misc::min(), MSG, dw::core::style::multiplyWithPerLength(), and dw::core::style::perLengthVal().
|
private |
Definition at line 578 of file table.cc.
References _MSG, dw::core::Requisition::ascent, dw::core::Requisition::descent, and MSG.
|
private |
Fills dw::Table::colExtremes, only if recalculation is necessary.
|
inlineprivate |
Definition at line 400 of file table.hh.
References children, and dw::Table::Child::SPAN_SPACE.
|
protectedvirtual |
Area is given in widget coordinates.
Implements dw::core::Widget.
Definition at line 231 of file table.cc.
References dw::core::Rectangle::draw().
|
private |
Definition at line 490 of file table.cc.
References _MSG, dw::core::style::absLengthVal(), dw::core::Requisition::ascent, dw::core::Requisition::descent, dw::core::style::isAbsLength(), dw::core::style::isPerLength(), dw::core::style::LENGTH_AUTO, lout::misc::max(), dw::core::Extremes::maxWidth, lout::misc::min(), dw::core::Extremes::minWidth, and dw::core::style::multiplyWithPerLength().
|
private |
Fills dw::Table::colExtremes in all cases.
Definition at line 651 of file table.cc.
References _MSG, dw::core::style::absLengthVal(), dw::core::style::isAbsLength(), dw::core::style::isPerLength(), dw::core::style::LENGTH_AUTO, lout::misc::max(), dw::core::Extremes::maxWidth, dw::core::Extremes::minWidth, MSG, and dw::core::style::perLengthVal().
TableCell * dw::Table::getCellRef | ( | ) |
Definition at line 396 of file table.cc.
References lout::identity::IdentifiableObject::instanceOf().
|
protectedvirtual |
Reimplemented from dw::core::Widget.
Definition at line 124 of file table.cc.
References _MSG, dw::core::style::absLengthVal(), dw::core::style::isAbsLength(), lout::misc::max(), dw::core::Extremes::maxWidth, and dw::core::Extremes::minWidth.
|
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.
|
private |
Definition at line 412 of file table.cc.
References dw::Table::Child::spanSpace, and dw::Table::Child::type.
|
protected |
|
protectedvirtual |
Called after sizeAllocateImpl() to redraw necessary areas. By default the whole widget is redrawn.
Reimplemented from dw::core::Widget.
|
protectedvirtual |
Reimplemented from dw::core::Widget.
|
inlineprivate |
Definition at line 426 of file table.hh.
References colWidths, lout::misc::SimpleVector< T >::get(), lout::misc::min(), redrawX, and lout::misc::SimpleVector< T >::set().
|
inlineprivate |
Definition at line 418 of file table.hh.
References cumHeight, lout::misc::SimpleVector< T >::get(), lout::misc::min(), redrawY, and lout::misc::SimpleVector< T >::set().
|
protectedvirtual |
Reimplemented from dw::core::Widget.
|
protectedvirtual |
|
protectedvirtual |
Reimplemented from dw::core::Widget.
Definition at line 153 of file table.cc.
References dw::core::Allocation::ascent, dw::core::Requisition::ascent, dw::core::Allocation::descent, dw::core::Allocation::width, dw::core::Allocation::x, and dw::core::Allocation::y.
|
protectedvirtual |
Implements dw::core::Widget.
Definition at line 105 of file table.cc.
References dw::core::Requisition::ascent, dw::core::Requisition::descent, and dw::core::Requisition::width.
|
friend |
|
private |
|
private |
Definition at line 362 of file table.hh.
Referenced by childDefined(), dw::Table::TableIterator::next(), dw::Table::TableIterator::prev(), and dw::Table::TableIterator::TableIterator().
|
private |
|
private |
|
private |
|
private |
|
private |
Row cumulative height array: cumHeight->size() is numRows + 1, cumHeight->get(0) is 0, cumHeight->get(numRows) is the total table height.
Definition at line 381 of file table.hh.
Referenced by setCumHeight().
|
private |
|
private |
Definition at line 364 of file table.hh.
Referenced by setColWidth().
|
private |
Definition at line 364 of file table.hh.
Referenced by setCumHeight().
|
private |
|
private |