dw::Textblock Class Reference

A Widget for rendering text blocks, i.e. paragraphs or sequences of paragraphs. More...

#include <textblock.hh>

List of all members.

Classes

struct  Anchor
struct  Line
class  TextblockIterator
struct  Word

Public Member Functions

 Textblock (bool limitTextWidth)
 ~Textblock ()
core::Iteratoriterator (core::Content::Type mask, bool atEnd)
 Return an iterator for this widget.
void flush ()
void addText (const char *text, size_t len, core::style::Style *style)
void addText (const char *text, core::style::Style *style)
void addWidget (core::Widget *widget, core::style::Style *style)
bool addAnchor (const char *name, core::style::Style *style)
void addSpace (core::style::Style *style)
void addParbreak (int space, core::style::Style *style)
void addLinebreak (core::style::Style *style)
core::WidgetgetWidgetAtPoint (int x, int y, int level)
 Search recursively through widget.
void handOverBreak (core::style::Style *style)
void changeLinkColor (int link, int newColor)
void changeWordStyle (int from, int to, core::style::Style *style, bool includeFirstSpace, bool includeLastSpace)

Static Public Attributes

static int CLASS_ID = -1

Protected Member Functions

void queueDrawRange (int index1, int index2)
void getWordExtremes (Word *word, core::Extremes *extremes)
void markChange (int ref)
void justifyLine (Line *line, int availWidth)
LineaddLine (int wordInd, bool newPar)
void calcWidgetSize (core::Widget *widget, core::Requisition *size)
void rewrap ()
void decorateText (core::View *view, core::style::Style *style, core::style::Color::Shading shading, int x, int yBase, int width)
void drawText (int wordIndex, core::View *view, core::Rectangle *area, int xWidget, int yWidgetBase)
void drawSpace (int wordIndex, core::View *view, core::Rectangle *area, int xWidget, int yWidgetBase)
void drawLine (Line *line, core::View *view, core::Rectangle *area)
int findLineIndex (int y)
int findLineOfWord (int wordIndex)
 Find the line of word wordIndex.
WordfindWord (int x, int y, bool *inSpace)
 Find the index of the word, or -1.
WordaddWord (int width, int ascent, int descent, core::style::Style *style)
void calcTextSize (const char *text, size_t len, core::style::Style *style, core::Requisition *size)
int lineXOffsetContents (Line *line)
 Returns the x offset (the indentation plus any offset needed for centering or right justification) for the line.
int lineXOffsetWidget (Line *line)
 Like lineXOffset, but relative to the allocation (i.e. including border etc.).
int lineYOffsetWidgetAllocation (Line *line, core::Allocation *allocation)
int lineYOffsetWidget (Line *line)
int lineYOffsetCanvasAllocation (Line *line, core::Allocation *allocation)
int lineYOffsetCanvas (Line *line)
int lineYOffsetWidgetI (int lineIndex)
int lineYOffsetCanvasI (int lineIndex)
bool sendSelectionEvent (core::SelectionState::EventType eventType, core::MousePositionEvent *event)
 Send event to selection.
virtual void wordWrap (int wordIndex)
void sizeRequestImpl (core::Requisition *requisition)
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 markSizeChange (int ref)
 See Sizes of Dillo Widgets.
void markExtremesChange (int ref)
 See Sizes of Dillo Widgets.
void setWidth (int width)
void setAscent (int ascent)
void setDescent (int descent)
void draw (core::View *view, core::Rectangle *area)
bool buttonPressImpl (core::EventButton *event)
bool buttonReleaseImpl (core::EventButton *event)
bool motionNotifyImpl (core::EventMotion *event)
void enterNotifyImpl (core::EventCrossing *event)
void leaveNotifyImpl (core::EventCrossing *event)
void removeChild (Widget *child)

Protected Attributes

bool hasListitemValue
int innerPadding
int line1Offset
int line1OffsetEff
bool ignoreLine1OffsetSometimes
bool mustQueueResize
bool limitTextWidth
int redrawY
int lastWordDrawn
int availWidth
int availAscent
int availDescent
int lastLineWidth
int lastLineParMin
int lastLineParMax
int wrapRef
lout::misc::SimpleVector< Line > * lines
lout::misc::SimpleVector< Word > * words
lout::misc::SimpleVector
< Anchor > * 
anchors
struct {
   int   index
   int   nChar
hlStart [core::HIGHLIGHT_NUM_LAYERS]
struct {
   int   index
   int   nChar
hlEnd [core::HIGHLIGHT_NUM_LAYERS]
int hoverLink

Friends

class TextblockIterator


Detailed Description

A Widget for rendering text blocks, i.e. paragraphs or sequences of paragraphs.

Signals

dw::Textblock uses the signals defined in dw::core::Layout::LinkReceiver, related to links. The coordinates are always -1.

Collapsing Spaces

The idea behind this is that every paragraph has a specific vertical space around and that they are combined to one space, according to rules stated below. A paragraph consists either of the lines between two paragraph breaks within a dw::Textblock, or of a dw::Textblock within a dw::Textblock, in a single line; the latter is used for indented boxes and list items.

The rules:

  1. If a paragraph is following by another, the space between them is the maximum of both box spaces:

    dw-textblock-collapsing-spaces-1-1.png

    are combined like this:

    dw-textblock-collapsing-spaces-1-2.png

  2. a) If one paragraph is the first paragraph within another, the upper space of these paragraphs collapse. b) The analogue is the case for the last box:

    dw-textblock-collapsing-spaces-2-1.png

    If B and C are put into A, the result is:

    dw-textblock-collapsing-spaces-2-2.png

For achieving this, there are some features of dw::Textblock:

Collapsing Margins

Collapsing margins, as defined in the CSS2 specification, are, supported in addition to collapsing spaces. Also, spaces and margins collapse themselves. I.e., the space between two paragraphs is the maximum of the space calculated as described in "Collapsing Spaces" and the space calculated according to the rules for collapsing margins.

(This is an intermediate hybrid state, collapsing spaces are used in the current version of dillo, while I implemented collapsing margins for the CSS prototype and integrated it already into the main trunk. For a pure CSS-based dillo, collapsing spaces will not be needed anymore, and may be removed for simplicity.)

Some Internals

There are 3 lists, dw::Textblock::words, dw::Textblock::lines, and dw::Textblock::anchors. The word list is quite static; only new words may be added. A word is either text, a widget, or a break.

Lines refer to the word list (first and last). They are completely redundant, i.e., they can be rebuilt from the words. Lines can be rewrapped either completely or partially (see "Incremental Resizing" below). For the latter purpose, several values are accumulated in the lines. See dw::Textblock::Line for details.

Anchors associate the anchor name with the index of the next word at the point of the anchor.

Incremental Resizing

dw::Textblock makes use of incremental resizing as described in Sizes of Dillo Widgets. The parentRef is, for children of a dw::Textblock, simply the number of the line.

Generally, there are three cases which may change the size of the widget:

The state of the size calculation is stored in wrapRef within dw::Textblock, which has the value -1 if no rewrapping of lines necessary, or otherwise the line from which a rewrap is necessary.


Constructor & Destructor Documentation

dw::Textblock::Textblock ( bool  limitTextWidth  ) 

dw::Textblock::~Textblock (  ) 


Member Function Documentation

bool dw::Textblock::addAnchor ( const char *  name,
core::style::Style style 
)

Add an anchor to the page. "name" is copied, so no strdup is necessary for the caller.

Return true on success, and false, when this anchor had already been added to the widget tree.

Todo:
It may be necessary for future uses to save the anchor in some way, e.g. when parts of the widget tree change.

References dw::core::Widget::allocation, anchors, lout::misc::SimpleVector< T >::getRef(), lout::misc::SimpleVector< T >::increase(), lines, lineYOffsetWidgetI(), dw::Textblock::Anchor::name, lout::misc::SimpleVector< T >::size(), dw::core::Widget::wasAllocated(), dw::Textblock::Anchor::wordIndex, and words.

Textblock::Line * dw::Textblock::addLine ( int  wordInd,
bool  newPar 
) [protected]

void dw::Textblock::addLinebreak ( core::style::Style style  ) 

void dw::Textblock::addParbreak ( int  space,
core::style::Style style 
)

void dw::Textblock::addSpace ( core::style::Style style  ) 

void dw::Textblock::addText ( const char *  text,
core::style::Style style 
) [inline]

References addText().

void dw::Textblock::addText ( const char *  text,
size_t  len,
core::style::Style style 
)

void dw::Textblock::addWidget ( core::Widget widget,
core::style::Style style 
)

Textblock::Word * dw::Textblock::addWord ( int  width,
int  ascent,
int  descent,
core::style::Style style 
) [protected]

bool dw::Textblock::buttonPressImpl ( core::EventButton event  )  [protected, virtual]

bool dw::Textblock::buttonReleaseImpl ( core::EventButton event  )  [protected, virtual]

void dw::Textblock::calcTextSize ( const char *  text,
size_t  len,
core::style::Style style,
core::Requisition size 
) [protected]

void dw::Textblock::calcWidgetSize ( core::Widget widget,
core::Requisition size 
) [protected]

void dw::Textblock::changeLinkColor ( int  link,
int  newColor 
)

void dw::Textblock::changeWordStyle ( int  from,
int  to,
core::style::Style style,
bool  includeFirstSpace,
bool  includeLastSpace 
)

void dw::Textblock::decorateText ( core::View view,
core::style::Style style,
core::style::Color::Shading  shading,
int  x,
int  yBase,
int  width 
) [protected]

void dw::Textblock::draw ( core::View view,
core::Rectangle area 
) [protected, virtual]

void dw::Textblock::drawLine ( Line line,
core::View view,
core::Rectangle area 
) [protected]

void dw::Textblock::drawSpace ( int  wordIndex,
core::View view,
core::Rectangle area,
int  xWidget,
int  yWidgetBase 
) [protected]

void dw::Textblock::drawText ( int  wordIndex,
core::View view,
core::Rectangle area,
int  xWidget,
int  yWidgetBase 
) [protected]

void dw::Textblock::enterNotifyImpl ( core::EventCrossing event  )  [protected, virtual]

Reimplemented from dw::core::Widget.

References hoverLink.

int dw::Textblock::findLineIndex ( int  y  )  [protected]

Find the first line index that includes y, relative to top of widget.

References index, lines, lineYOffsetWidgetI(), and lout::misc::SimpleVector< T >::size().

Referenced by draw(), findWord(), getWidgetAtPoint(), and sendSelectionEvent().

int dw::Textblock::findLineOfWord ( int  wordIndex  )  [protected]

Textblock::Word * dw::Textblock::findWord ( int  x,
int  y,
bool *  inSpace 
) [protected]

void dw::Textblock::flush (  ) 

void dw::Textblock::getExtremesImpl ( core::Extremes extremes  )  [protected, virtual]

core::Widget * dw::Textblock::getWidgetAtPoint ( int  x,
int  y,
int  level 
) [virtual]

void dw::Textblock::getWordExtremes ( Word word,
core::Extremes extremes 
) [protected]

void dw::Textblock::handOverBreak ( core::style::Style style  ) 

This function "hands" the last break of a page "over" to a parent page. This is used for "collapsing spaces".

References addParbreak(), dw::Textblock::Line::breakSpace, CLASS_ID, dw::core::Widget::getParent(), lout::misc::SimpleVector< T >::getRef(), lines, dw::core::Widget::parent, lout::misc::SimpleVector< T >::size(), and dw::core::Widget::Widget().

core::Iterator * dw::Textblock::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 TextblockIterator.

void dw::Textblock::justifyLine ( Line line,
int  availWidth 
) [protected]

void dw::Textblock::leaveNotifyImpl ( core::EventCrossing event  )  [protected, virtual]

int dw::Textblock::lineXOffsetContents ( Line line  )  [inline, protected]

Returns the x offset (the indentation plus any offset needed for centering or right justification) for the line.

The offset returned is relative to the page *content* (i.e. without border etc.).

References lout::misc::SimpleVector< T >::getRef(), innerPadding, dw::Textblock::Line::leftOffset, line1OffsetEff, and lines.

Referenced by lineXOffsetWidget().

int dw::Textblock::lineXOffsetWidget ( Line line  )  [inline, protected]

Like lineXOffset, but relative to the allocation (i.e. including border etc.).

References dw::core::Widget::getStyle(), and lineXOffsetContents().

Referenced by drawLine(), findWord(), dw::Textblock::TextblockIterator::getAllocation(), sendSelectionEvent(), and sizeAllocateImpl().

int dw::Textblock::lineYOffsetCanvas ( Line line  )  [inline, protected]

int dw::Textblock::lineYOffsetCanvasAllocation ( Line line,
core::Allocation allocation 
) [inline, protected]

Like lineYOffsetCanvas, but with the allocation as parameter.

References lineYOffsetWidgetAllocation(), and dw::core::Allocation::y.

Referenced by lineYOffsetCanvas(), and sizeAllocateImpl().

int dw::Textblock::lineYOffsetCanvasI ( int  lineIndex  )  [inline, protected]

int dw::Textblock::lineYOffsetWidget ( Line line  )  [inline, protected]

int dw::Textblock::lineYOffsetWidgetAllocation ( Line line,
core::Allocation allocation 
) [inline, protected]

int dw::Textblock::lineYOffsetWidgetI ( int  lineIndex  )  [inline, protected]

void dw::Textblock::markChange ( int  ref  )  [protected]

References lout::misc::min(), and wrapRef.

Referenced by markExtremesChange(), and markSizeChange().

void dw::Textblock::markExtremesChange ( int  ref  )  [protected, virtual]

See Sizes of Dillo Widgets.

Reimplemented from dw::core::Widget.

References markChange().

void dw::Textblock::markSizeChange ( int  ref  )  [protected, virtual]

See Sizes of Dillo Widgets.

Reimplemented from dw::core::Widget.

References markChange().

bool dw::Textblock::motionNotifyImpl ( core::EventMotion event  )  [protected, virtual]

void dw::Textblock::queueDrawRange ( int  index1,
int  index2 
) [protected]

void dw::Textblock::removeChild ( Widget *  child  )  [protected]

Bug:
Not implemented.

void dw::Textblock::resizeDrawImpl (  )  [protected, virtual]

void dw::Textblock::rewrap (  )  [protected]

bool dw::Textblock::sendSelectionEvent ( core::SelectionState::EventType  eventType,
core::MousePositionEvent event 
) [protected]

void dw::Textblock::setAscent ( int  ascent  )  [protected, virtual]

void dw::Textblock::setDescent ( int  descent  )  [protected, virtual]

void dw::Textblock::setWidth ( int  width  )  [protected, virtual]

void dw::Textblock::sizeAllocateImpl ( core::Allocation allocation  )  [protected, virtual]

void dw::Textblock::sizeRequestImpl ( core::Requisition requisition  )  [protected, virtual]

void dw::Textblock::wordWrap ( int  wordIndex  )  [protected, virtual]

Reimplemented in dw::TableCell.

References dw::core::style::absLengthVal(), addLine(), dw::core::Requisition::ascent, availWidth, dw::Textblock::Line::boxAscent, dw::Textblock::Line::boxDescent, dw::core::Content::BREAK, dw::core::Content::breakSpace, dw::Textblock::Line::breakSpace, dw::Textblock::Word::content, dw::Textblock::Line::contentAscent, dw::Textblock::Line::contentDescent, dw::core::Requisition::descent, dw::Textblock::Word::effSpace, dw::Textblock::Line::firstWord, dw::core::style::StyleAttrs::font, lout::misc::SimpleVector< T >::getRef(), dw::core::Widget::getStyle(), getWordExtremes(), hasListitemValue, ignoreLine1OffsetSometimes, innerPadding, dw::core::style::isPerLength(), justifyLine(), lastLineParMax, lastLineParMin, lastLineWidth, dw::Textblock::Line::lastWord, dw::core::Widget::layout, dw::Textblock::Line::leftOffset, limitTextWidth, line1Offset, line1OffsetEff, lines, dw::Textblock::Line::marginDescent, lout::misc::max(), dw::core::Extremes::maxWidth, dw::Textblock::Line::maxWordMin, dw::core::Extremes::minWidth, mustQueueResize, dw::Textblock::Word::origSpace, dw::Textblock::Line::parMin, dw::core::style::perLengthVal(), lout::misc::roundInt(), lout::misc::SimpleVector< T >::size(), dw::Textblock::Word::size, dw::Textblock::Word::style, dw::core::style::TEXT_ALIGN_CENTER, dw::core::style::TEXT_ALIGN_JUSTIFY, dw::core::style::TEXT_ALIGN_LEFT, dw::core::style::TEXT_ALIGN_RIGHT, dw::core::style::TEXT_ALIGN_STRING, dw::core::style::StyleAttrs::textAlign, dw::core::Content::type, dw::core::style::StyleAttrs::valign, dw::core::style::VALIGN_SUB, dw::core::style::VALIGN_SUPER, dw::core::style::WHITE_SPACE_NOWRAP, dw::core::style::WHITE_SPACE_PRE, dw::core::style::StyleAttrs::whiteSpace, dw::core::Content::widget, dw::core::Content::WIDGET, dw::core::Requisition::width, and words.

Referenced by addLinebreak(), addParbreak(), addText(), addWidget(), and rewrap().


Friends And Related Function Documentation

friend class TextblockIterator [friend]

Referenced by iterator(), and sendSelectionEvent().


Member Data Documentation

int dw::Textblock::availAscent [protected]

int dw::Textblock::availDescent [protected]

int dw::Textblock::availWidth [protected]

int dw::Textblock::CLASS_ID = -1 [static]

Reimplemented from dw::core::Widget.

Reimplemented in dw::AlignedTextblock, dw::ListItem, and dw::TableCell.

Referenced by addParbreak(), handOverBreak(), and Textblock().

struct { ... } dw::Textblock::hlEnd[core::HIGHLIGHT_NUM_LAYERS] [protected]

struct { ... } dw::Textblock::hlStart[core::HIGHLIGHT_NUM_LAYERS] [protected]

int dw::Textblock::hoverLink [protected]

Referenced by Textblock(), and wordWrap().

int dw::Textblock::innerPadding [protected]

Referenced by addLine(), rewrap(), Textblock(), and wordWrap().

Referenced by setWidth(), and wordWrap().

int dw::Textblock::line1Offset [protected]

int dw::Textblock::redrawY [protected]

int dw::Textblock::wrapRef [protected]


The documentation for this class was generated from the following files:

Generated on Wed Sep 7 02:00:37 2011 for Dillo by  doxygen 1.5.9