1#ifndef __DW_TEXTBLOCK_HH__
2#define __DW_TEXTBLOCK_HH__
7#include "../lout/misc.hh"
232 int totalWidth, idealWidth, totalStretchability, totalShrinkability;
266 int totalStretchability,
int totalShrinkability);
318 void getBgArea (
int *x,
int *y,
int *width,
int *height);
319 void getRefArea (
int *xRef,
int *yRef,
int *widthRef,
int *heightRef);
321 void draw (
int x,
int y,
int width,
int height);
330 void getBgArea (
int *x,
int *y,
int *width,
int *height);
608 lout::misc::SimpleVector <Line> *
lines;
611 lout::misc::NotSoSimpleVector <Word> *
words;
624 int widgetMargin,
int lineBorderTotal,
625 int lineMarginTotal);
628 Line *
addLine (
int firstWord,
int lastWord,
int newLastOofPos,
629 bool temporary,
int minHeight);
639 int x,
int yBase,
int width);
642 const char *text,
int start,
int len,
bool isStart,
646 void drawWord0 (
int wordIndex1,
int wordIndex2,
647 const char *text,
int totalWidth,
bool drawHyphen,
651 int xWidget,
int yWidgetBase);
672 void fillWord (
int wordNo,
int width,
int ascent,
int descent,
676 int breakPenalty1,
int breakPenalty2,
bool forceBreak);
680 int textWidth (
const char *text,
int start,
int len,
749 if (
lines->size() == 0)
775 virtual int wordWrap (
int wordIndex,
bool wrapAll);
780 int *searchUntil,
bool tempNewLine,
781 int penaltyIndex,
bool borderIsCalculated,
782 bool *thereWillBeMoreSpace,
bool wrapAll,
783 int *diffWords,
int *wordIndexEnd,
784 int *lastFloatPos,
bool regardBorder,
785 int *height,
int *breakPos);
786 int searchBreakPos (
int wordIndex,
int firstIndex,
int *searchUntil,
787 bool tempNewLine,
int penaltyIndex,
788 bool thereWillBeMoreSpace,
bool wrapAll,
789 int *diffWords,
int *wordIndexEnd,
790 int *addIndex1 = NULL);
791 int searchMinBap (
int firstWord,
int lastWordm,
int penaltyIndex,
792 bool thereWillBeMoreSpace,
bool correctAtEnd);
820 Widget **references,
int *x,
int *y);
861 int numBreaks,
int *breakPos,
900 bool includeFirstSpace,
bool includeLastSpace);
914#define DBG_SET_WORD_PENALTY(n, i, is) \
916 if (words->getRef(n)->badnessAndPenalty.getPenalty (i) == INT_MIN) \
917 DBG_OBJ_ARRATTRSET_SYM ("words", n, "penalty." is, "-inf"); \
918 else if (words->getRef(n)->badnessAndPenalty.getPenalty (i) == INT_MAX) \
919 DBG_OBJ_ARRATTRSET_SYM ("words", n, "penalty." is, "inf"); \
921 DBG_OBJ_ARRATTRSET_NUM ("words", n, "penalty." is, \
922 words->getRef(n)->badnessAndPenalty \
927#define DBG_OBJ_ARRATTRSET_WREF(var, ind, attr, wref) \
928 RTFL_OBJ_PRINT ("set", "p:s.d.s:p (p, d)", this, var, ind, attr, wref, \
929 wref->widget, wref->parentRef)
931#define DBG_OBJ_ARRATTRSET_WREF(var, ind, attr, wref) STMT_NOP
934#define DBG_SET_WORD(n) \
936 switch (words->getRef(n)->content.type) { \
937 case ::dw::core::Content::TEXT: \
938 DBG_OBJ_ARRATTRSET_SYM ("words", n, "type", "TEXT"); \
939 DBG_OBJ_ARRATTRSET_STR ("words", n, \
940 "text/widget/widgetReference/breakSpace", \
941 words->getRef(n)->content.text); \
943 case ::dw::core::Content::WIDGET_IN_FLOW: \
944 DBG_OBJ_ARRATTRSET_SYM ("words", n, "type", "WIDGET_IN_FLOW"); \
945 DBG_OBJ_ARRATTRSET_PTR ("words", n, \
946 "text/widget/widgetReference/breakSpace", \
947 words->getRef(n)->content.widget); \
949 case ::dw::core::Content::WIDGET_OOF_REF: \
950 DBG_OBJ_ARRATTRSET_SYM ("words", n, "type", "WIDGET_OOF_REF"); \
951 DBG_OBJ_ARRATTRSET_WREF ("words", n, \
952 "text/widget/widgetReference/breakSpace", \
953 words->getRef(n)->content.widgetReference); \
955 case ::dw::core::Content::BREAK: \
956 DBG_OBJ_ARRATTRSET_SYM ("words", n, "type", "BREAK"); \
957 DBG_OBJ_ARRATTRSET_NUM ("words", n, \
958 "text/widget/widgetReference/breakSpace", \
959 words->getRef(n)->content.breakSpace); \
962 DBG_OBJ_ARRATTRSET_SYM ("words", n, "type", "???"); \
963 DBG_OBJ_ARRATTRSET_SYM ("words", n, \
964 "text/widget/widgetReference/breakSpace", \
967 DBG_SET_WORD_PENALTY (n, 0, "0"); \
968 DBG_SET_WORD_PENALTY (n, 1, "1"); \
971#define DBG_SET_WORD_SIZE(n) \
973 DBG_OBJ_ARRATTRSET_NUM ("words", n, "size.width", \
974 words->getRef(n)->size.width); \
975 DBG_OBJ_ARRATTRSET_NUM ("words", n, "size.ascent", \
976 words->getRef(n)->size.ascent); \
977 DBG_OBJ_ARRATTRSET_NUM ("words", n, "size.descent", \
978 words->getRef(n)->size.descent); \
981#define DBG_MSG_WORD(aspect, prio, prefix, n, suffix) \
983 if ((n) < 0 || (n) >= words->size ()) \
984 DBG_OBJ_MSG (aspect, prio, prefix "undefined (wrong index)" suffix); \
986 switch (words->getRef(n)->content.type) { \
987 case ::dw::core::Content::TEXT: \
988 DBG_OBJ_MSGF (aspect, prio, prefix "TEXT / \"%s\"" suffix, \
989 words->getRef(n)->content.text); \
991 case ::dw::core::Content::WIDGET_IN_FLOW: \
992 DBG_OBJ_MSGF (aspect, prio, prefix "WIDGET_IN_FLOW / %p" suffix, \
993 words->getRef(n)->content.widget); \
995 case ::dw::core::Content::WIDGET_OOF_REF: \
996 DBG_OBJ_MSGF (aspect, prio, \
997 prefix "WIDGET_OOF_REF / %p (%p, %d)" suffix,\
998 words->getRef(n)->content.widgetReference, \
999 words->getRef(n)->content.widgetReference->widget, \
1000 words->getRef(n)->content.widgetReference \
1003 case ::dw::core::Content::BREAK: \
1004 DBG_OBJ_MSGF (aspect, prio, prefix "BREAK / %d" suffix, \
1005 words->getRef(n)->content.breakSpace); \
1008 DBG_OBJ_MSG (aspect, prio, prefix "??? / ???" suffix); \
Base class (rather a tag interface) for those widgets regarding borders defined by floats,...
int penaltyValue(int index, int infLevel)
enum dw::Textblock::BadnessAndPenalty::@29 badnessState
bool lineMustBeBroken(int penaltyIndex)
int compareTo(int penaltyIndex, BadnessAndPenalty *other)
bool lineCanBeBroken(int penaltyIndex)
void intoStringBuffer(lout::misc::StringBuffer *sb)
void setPenalty(int penalty)
void calcBadness(int totalWidth, int idealWidth, int totalStretchability, int totalShrinkability)
int badnessValue(int infLevel)
void setPenalties(int penalty1, int penalty2)
Sets the penalty, multiplied by 100.
void setSinglePenalty(int index, int penalty)
SpaceImgRenderer(Textblock *textblock, int wordNo)
void getBgArea(int *x, int *y, int *width, int *height)
Return the area covered by the background image.
core::style::Style * getStyle()
Return the style this background image is part of.
void unhighlight(int direction, core::HighlightLayer layer)
Shrink highlighted region to no longer contain the current content.
lout::object::Object * clone()
Return an exact copy of the object.
static TextblockIterator * createWordIndexIterator(Textblock *textblock, core::Content::Type mask, int wordIndex)
void highlight(int start, int end, core::HighlightLayer layer)
Extend highlighted region to contain part of the current content.
void getContentInFlow(int index, core::Content *content)
Implementation used for words.
bool readyToDraw()
If this method returns false, nothing is done at all.
void draw(int x, int y, int width, int height)
Draw (or queue for drawing) an area, which is given in canvas coordinates.
void setData(int xWordWidget, int lineNo)
void getBgArea(int *x, int *y, int *width, int *height)
Return the area covered by the background image.
void getRefArea(int *xRef, int *yRef, int *widthRef, int *heightRef)
Return the "reference area".
core::style::Style * getStyle()
Return the style this background image is part of.
A Widget for rendering text blocks, i.e.
void drawLine(Line *line, core::View *view, core::Rectangle *area, core::DrawingContext *context)
int findParagraphOfWord(int wordIndex)
Find the paragraph of word wordIndex.
void drawWord0(int wordIndex1, int wordIndex2, const char *text, int totalWidth, bool drawHyphen, core::style::Style *style, core::View *view, core::Rectangle *area, int xWidget, int yWidgetBase)
TODO Comment.
void calcTextSizes(const char *text, size_t textLen, core::style::Style *style, int numBreaks, int *breakPos, core::Requisition *wordSize)
void initLine1Offset(int wordIndex)
int searchBreakPos(int wordIndex, int firstIndex, int *searchUntil, bool tempNewLine, int penaltyIndex, bool thereWillBeMoreSpace, bool wrapAll, int *diffWords, int *wordIndexEnd, int *addIndex1=NULL)
void breakAdded()
Called directly after a (line or paragraph) break has been added.
void removeTemporaryLines()
void getExtremesSimpl(core::Extremes *extremes)
Simple variant, to be implemented by widgets with extremes not depending on positions.
struct dw::Textblock::@28 hlEnd[core::HIGHLIGHT_NUM_LAYERS]
void changeWordStyle(int from, int to, core::style::Style *style, bool includeFirstSpace, bool includeLastSpace)
int newLineLeftFloatHeight
void accumulateWordData(int wordIndex)
void addWidget(core::Widget *widget, core::style::Style *style)
Add a widget (word type) to the page.
void getWordExtremes(Word *word, core::Extremes *extremes)
Get the extremes of a word within a textblock.
void addSpace(core::style::Style *style)
?
lout::misc::NotSoSimpleVector< Word > * words
int wrapWordOofRef(int wordIndex, bool wrapAll)
void handleWordExtremes(int wordIndex)
Counter part to wordWrap(), but for extremes, not size calculation.
core::SizeParams sizeRequestParams
int yOffsetOfLineCreated(Line *line)
Includes margin, border, and padding.
int lineYOffsetWidget(int lineIndex)
void correctLastWordExtremes()
Called when something changed for the last word (space, hyphens etc.).
virtual int wordWrap(int wordIndex, bool wrapAll)
void addText(const char *text, core::style::Style *style)
int getLineStretchability(int lastWordIndex)
void setWordImgRenderer(int wordNo)
void enterNotifyImpl(core::EventCrossing *event)
void changeLinkColor(int link, int newColor)
bool isHyphenationCandidate(Word *word)
void widgetRefSizeChanged(int externalIndex)
Called by an implementation of dw::oof::OutOfFlowMgr (actually only OOFPosRelMgr) for the generator o...
Widget * getExtremesReference(int index)
See Sizes of Dillo Widgets (or Size requisitions depending on positions).
void handOverBreak(core::style::Style *style)
This function "hands" the last break of a page "over" to a parent page.
void processWord(int wordIndex)
Line * addLine(int firstWord, int lastWord, int newLastOofPos, bool temporary, int minHeight)
static bool mustAddBreaks(core::style::Style *style)
int considerHyphenation(int firstIndex, int breakPos)
Suggest a word to hyphenate, when breaking at breakPos is planned.
void markSizeChange(int ref)
See Sizes of Dillo Widgets.
bool calcSizeOfWidgetInFlow(int wordIndex, Widget *widget, core::Requisition *size)
Calculate the size of a widget, and return whether it has to be positioned at the top of the line.
void oofSizeChanged(bool extremesChanged)
Called by an implementation of dw::oof::OutOfFlowMgr when the size of the container has changed,...
int numGetExtremesReferences()
See Sizes of Dillo Widgets (or Size requisitions depending on positions).
int getGeneratorX(int oofmIndex)
Return position relative to container, not regarding margin/border/padding, Called by OOFFloatsMgr to...
bool newLineHasFloatRight
void fillParagraphs()
Counter part to rewrap(), but for extremes, not size calculation.
static void setStretchabilityFactor(int stretchabilityFactor)
void calcBorders(int lastOofRef, int height)
void rewrap()
Rewrap the page from the line from which this is necessary.
void drawSpace(int wordIndex, core::View *view, core::Rectangle *area, int xWidget, int yWidgetBase)
void sizeAllocateImpl(core::Allocation *allocation)
See Sizes of Dillo Widgets.
static const char * hyphenDrawChar
The character which is used to draw a hyphen at the end of a line, either caused by automatic hyphena...
bool findSizeRequestReference(int oofmIndex, int *xRef=NULL, int *yRef=NULL)
core::Iterator * iterator(core::Content::Type mask, bool atEnd)
Return an iterator for this widget.
void calcExtraSpaceImpl(int numPos, Widget **references, int *x, int *y)
int findLineIndexWhenNotAllocated(int y)
int lineYOffsetWidget(Line *line, core::Allocation *allocation)
void cleanupWord(int wordNo)
void calcTextOffset(int lineIndex, int totalWidth)
Word * findWord(int x, int y, bool *inSpace)
Find the index of the word, or -1.
void balanceBreakPosAndHeight(int wordIndex, int firstIndex, int *searchUntil, bool tempNewLine, int penaltyIndex, bool borderIsCalculated, bool *thereWillBeMoreSpace, bool wrapAll, int *diffWords, int *wordIndexEnd, int *lastFloatPos, bool regardBorder, int *height, int *breakPos)
static void setPenaltyHyphen(int penaltyHyphen)
bool mustBorderBeRegarded(int lineNo)
void calcTextSize(const char *text, size_t len, core::style::Style *style, core::Requisition *size, bool isStart, bool isEnd)
Calculate the size of a text word.
void notifySetParent()
This method is called after a widget has been added to a parent.
RegardingBorder * getWidgetRegardingBorderForLine(Line *line)
void setBreakOption(Word *word, core::style::Style *style, int breakPenalty1, int breakPenalty2, bool forceBreak)
Set a break option, if allowed by the style.
void accumulateWordForLine(int lineIndex, int wordIndex)
void drawWord(Line *line, int wordIndex1, int wordIndex2, core::View *view, core::Rectangle *area, int xWidget, int yWidgetBase)
Draw a word of text.
int lineYOffsetCanvas(int lineIndex)
bool isBreakAllowedInWord(Word *word)
int numSizeRequestReferences()
See Sizes of Dillo Widgets (or Size requisitions depending on positions).
static void setPenaltyEmDashLeft(int penaltyLeftEmDash)
int searchMinBap(int firstWord, int lastWordm, int penaltyIndex, bool thereWillBeMoreSpace, bool correctAtEnd)
int lineYOffsetWidget(int lineIndex, core::Allocation *allocation)
int getAvailHeightOfChild(core::Widget *child, bool forceValue)
int getLineShrinkability(int lastWordIndex)
int lineYOffsetWidget(Line *line)
lout::misc::SimpleVector< Anchor > * anchors
int lineYOffsetCanvas(Line *line)
static int getSpaceStretchability(struct Word *word)
bool affectsSizeChangeContainerChild(Widget *child)
int yOffsetOfLineToBeCreated(int *lastMargin=NULL)
Includes margin, border, and padding.
void setSpaceImgRenderer(int wordNo)
static int stretchabilityFactor
...
static void setPenaltyHyphen2(int penaltyHyphen2)
bool addAnchor(const char *name, core::style::Style *style)
Add an anchor to the page.
static void setPenaltyEmDashRight2(int penaltyRightEmDash2)
void addText(const char *text, size_t len, core::style::Style *style)
Add a word to the page structure.
int getGeneratorY(int oofmIndex)
Return position relative to container, not regarding margin/border/padding, Called by OOFFloatsMgr to...
bool mustBorderBeRegarded(Line *line)
Of nested text blocks, only the most inner one must regard the borders of floats.
bool findSizeRequestReference(Widget *reference, int *xRef=NULL, int *yRef=NULL)
void drawText(core::View *view, core::style::Style *style, core::style::Color::Shading shading, int x, int y, const char *text, int start, int len, bool isStart, bool isEnd)
void addBreakOption(core::style::Style *style, bool forceBreak)
Add a break option (see setBreakOption() for details).
void moveWordIndices(int wordIndex, int num, int *addIndex1=NULL)
int calcVerticalBorder(int widgetPadding, int widgetBorder, int widgetMargin, int lineBorderTotal, int lineMarginTotal)
int getMaxGeneratorWidth()
int getGeneratorRest(int oofmIndex)
static int penalties[PENALTY_NUM][2]
The penalties for hyphens and other, multiplied by 100.
int hyphenateWord(int wordIndex, int *addIndex1=NULL)
void leaveNotifyImpl(core::EventCrossing *event)
int calcLineBreakWidth(int lineIndex)
void resizeDrawImpl()
Called after sizeAllocateImpl() to redraw necessary areas.
bool isBreakAllowed(core::style::Style *style)
static void setPenaltyEmDashRight(int penaltyRightEmDash)
bool usesAvailWidth()
Must be implemengted by a method returning true, when getAvailWidth() is called.
void addText0(const char *text, size_t len, short flags, core::style::Style *style, core::Requisition *size)
Add a word (without hyphens) to the page structure.
Widget * getWidgetAtPointLevel(int x, int y, int level, core::GettingWidgetAtPointContext *context)
int getGeneratorWidth()
Return width including margin/border/padding Called by OOFFloatsMgr to position floats.
struct dw::Textblock::@28 hlStart[core::HIGHLIGHT_NUM_LAYERS]
void decorateText(core::View *view, core::style::Style *style, core::style::Color::Shading shading, int x, int yBase, int width)
int findLineOfWord(int wordIndex)
Find the line of word wordIndex.
int wrapWordInFlow(int wordIndex, bool wrapAll)
void removeChild(Widget *child)
int textWidth(const char *text, int start, int len, core::style::Style *style, bool isStart, bool isEnd)
void notifySetAsTopLevel()
This method is called after a widget has been set as the top of a widget tree.
int newLineRightFloatHeight
void addParbreak(int space, core::style::Style *style)
Cause a paragraph break.
void fillSpace(int wordNo, core::style::Style *style)
int calcLinePartHeight(int firstWord, int lastWord)
Widget * sizeReferences[NUM_OOFM]
bool buttonPressImpl(core::EventButton *event)
void queueDrawRange(int index1, int index2)
Widget * sizeRequestReference(int index)
See Sizes of Dillo Widgets (or Size requisitions depending on positions).
bool isPossibleOOFContainer(int oofmIndex)
void containerSizeChangedForChildren()
void updateReference(int ref)
Update content in flow, down from ref.
bool usesMaxGeneratorWidth()
void alignLine(int lineIndex)
Align the line.
void fillWord(int wordNo, int width, int ascent, int descent, short flags, core::style::Style *style)
int calcPenaltyIndexForNewLine()
bool motionNotifyImpl(core::EventMotion *event)
bool sendSelectionEvent(core::SelectionState::EventType eventType, core::MousePositionEvent *event)
Send event to selection.
void addLinebreak(core::style::Style *style)
int findLineIndexWhenAllocated(int y)
void removeSpaceImgRenderer(int wordNo)
void initWord(int wordNo)
Basic initialization, which is neccessary before fillWord.
void sizeRequestImpl(core::Requisition *requisition, int numPos, Widget **references, int *x, int *y)
The ascent of a textblock is the ascent of the first line, plus padding/border/margin.
bool buttonReleaseImpl(core::EventButton *event)
Word * addWord(int width, int ascent, int descent, short flags, core::style::Style *style)
Add a new word (text, widget etc.) to a page.
int getAvailWidthOfChild(core::Widget *child, bool forceValue)
Computes the content width available of a child widget.
void removeWordImgRenderer(int wordNo)
static DivChar divChars[NUM_DIV_CHARS]
void markExtremesChange(int ref)
See Sizes of Dillo Widgets.
lout::misc::SimpleVector< Paragraph > * paragraphs
void justifyLine(Line *line, int diff)
static int getSpaceShrinkability(struct Word *word)
void drawLevel(core::View *view, core::Rectangle *area, int level, core::DrawingContext *context)
bool ignoreLine1OffsetSometimes
int lineYOffsetCanvas(Line *line, core::Allocation *allocation)
lout::misc::SimpleVector< Line > * lines
bool isPossibleOOFContainerParent(int oofmIndex)
int findLineIndex(int y)
Find the first line index that includes y, which is given in widget coordinates.
Set at the top when drawing.
Represents a enter or leave notify event.
Represents a mouse motion event.
Set at the top when getting the widget at the point.
Iterators are used to iterate through the contents of a widget.
Base class for all mouse events related to a specific position.
dw::core::Shape implemtation for simple rectangles.
Hold arguments passed to dw::core::Widget::sizeRequest and dw::core::Widget::getExtremes,...
An interface to encapsulate platform dependent drawing.
A class for fast concatenation of a large number of strings.
This is the base class for many other classes, which defines very common virtual methods.
Dw is in this namespace, or sub namespaces of this one.
enum dw::Textblock::Line::@31 alignment
int lastOofRefPositionedBeforeThisLine
int totalHeight(int marginNextLine)
Returns the difference between two vertical lines positions: height of this line plus space below thi...
int maxParAdjustmentWidth
SpaceImgRenderer * spaceImgRenderer
core::style::Style * style
WordImgRenderer * wordImgRenderer
@ DIV_CHAR_AT_EOL
Must be drawn with a hyphen, when at the end of the line.
@ UNBREAKABLE_FOR_MIN_WIDTH
@ CAN_BE_HYPHENATED
Can be hyphenated automatically.
@ PERM_DIV_CHAR
Is or ends with a "division character", which is part of the word.
@ DRAW_AS_ONE_TEXT
This word must be drawn, together with the following word(s), by only one call of View::drawText(),...
BadnessAndPenalty badnessAndPenalty
int totalSpaceStretchability
core::style::Style * spaceStyle
int totalSpaceShrinkability
Represents the allocation, i.e.