diff options
Diffstat (limited to 'dw/textblock.hh')
-rw-r--r-- | dw/textblock.hh | 134 |
1 files changed, 77 insertions, 57 deletions
diff --git a/dw/textblock.hh b/dw/textblock.hh index 162088dc..6030ff63 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -4,7 +4,6 @@ #include <limits.h> #include "regardingborder.hh" -#include "outofflowmgr.hh" #include "../lout/misc.hh" // These were used when improved line breaking and hyphenation were implemented. @@ -24,10 +23,9 @@ namespace dw { * * <div style="border: 2px solid #ffff00; margin-top: 0.5em; * margin-bottom: 0.5em; padding: 0.5em 1em; background-color: - * #ffffe0"><b>Info:</b> The recent changes (line breaking and - * hyphenation on one hand, floats on the other hand) have not yet - * been incorporated into this documentation. See \ref - * dw-line-breaking and \ref dw-out-of-flow.</div> + * #ffffe0"><b>Info:</b> Some (not so) recent changes, line breaking + * and hyphenation, have not yet been incorporated into this + * documentation. See \ref dw-line-breaking.</div> * * <h3>Signals</h3> * @@ -164,11 +162,11 @@ namespace dw { * Anchors associate the anchor name with the index of the next word at * the point of the anchor. * - * <h4>Incremental Resizing</h4> + * <h3>Incremental Resizing</h3> * * dw::Textblock makes use of incremental resizing as described in \ref * dw-widget-sizes. The parentRef is, for children of a dw::Textblock, simply - * the number of the line. + * the number of the line. [<b>Update:</b> Incorrect; see \ref dw-out-of-flow.] * * Generally, there are three cases which may change the size of the * widget: @@ -195,6 +193,12 @@ namespace dw { * dw::Textblock, which has the value -1 if no rewrapping of lines * necessary, or otherwise the line from which a rewrap is necessary. * + * <h3>Widgets Ouf Of Flow</h3> + * + * See + * + * - dw::oof::OOFAwareWidget (base class) and + * - \ref dw-out-of-flow. */ class Textblock: public RegardingBorder { @@ -272,7 +276,6 @@ private: int compareTo (int penaltyIndex, BadnessAndPenalty *other); void intoStringBuffer(lout::misc::StringBuffer *sb); - void print (); }; enum { PENALTY_HYPHEN, PENALTY_EM_DASH_LEFT, PENALTY_EM_DASH_RIGHT, @@ -290,10 +293,8 @@ private: static const char *hyphenDrawChar; - Textblock *containingBlock; - OutOfFlowMgr *outOfFlowMgr; - protected: + /** * \brief Implementation used for words. */ @@ -316,8 +317,6 @@ protected: void getRefArea (int *xRef, int *yRef, int *widthRef, int *heightRef); core::style::Style *getStyle (); void draw (int x, int y, int width, int height); - - virtual void print (); }; class SpaceImgRenderer: public WordImgRenderer @@ -328,8 +327,6 @@ protected: void getBgArea (int *x, int *y, int *width, int *height); core::style::Style *getStyle (); - - void print (); }; struct Paragraph @@ -452,8 +449,13 @@ protected: WORD_START = 1 << 5, /* If a word represents a "real" text word, or (after * hyphenation) the last part of a "real" text word, this - * flag is set. Analogue to WORD_START. */ - WORD_END = 1 << 6 + * flag is set. Analogue to WORD_START. */ + WORD_END = 1 << 6, + /* This word is put at the top of the line, and at the + * left. This is necessary if the size of a child widget + * depends on the position, which, on the other hand, cannot + * be determined before the whole line is broken. */ + TOPLEFT_OF_LINE = 1 << 7 }; /* TODO: perhaps add a xLeft? */ @@ -496,38 +498,30 @@ protected: SpaceImgRenderer *spaceImgRenderer; }; - void printWordShort (Word *word); - void printWordFlags (short flags); - void printWordWithFlags (Word *word); - void printWord (Word *word); - struct Anchor { char *name; int wordIndex; }; - class TextblockIterator: public core::Iterator + class TextblockIterator: public OOFAwareWidgetIterator { - private: - bool oofm; - int index; + protected: + int numContentsInFlow (); + void getContentInFlow (int index, core::Content *content); public: TextblockIterator (Textblock *textblock, core::Content::Type mask, bool atEnd); - TextblockIterator (Textblock *textblock, core::Content::Type mask, - bool oofm, int index); + + static TextblockIterator *createWordIndexIterator + (Textblock *textblock, core::Content::Type mask, int wordIndex); lout::object::Object *clone(); - int compareTo(lout::object::Comparable *other); - bool next (); - bool prev (); void highlight (int start, int end, core::HighlightLayer layer); void unhighlight (int direction, core::HighlightLayer layer); void getAllocation (int start, int end, core::Allocation *allocation); - void print (); }; friend class TextblockIterator; @@ -582,12 +576,12 @@ protected: int redrawY; int lastWordDrawn; + bool sizeRequestPosDefined; + int sizeRequestX, sizeRequestY; + /* This value is (currently) set by setAscent(). */ int lineBreakWidth; - // Additional vertical offset, used for the "clear" attribute. - int verticalOffset; - int wrapRefLines, wrapRefParagraphs; /* 0-based. Important: Both are the line numbers, not the value stored in @@ -624,9 +618,10 @@ protected: int hoverLink; /* The link under the mouse pointer */ void queueDrawRange (int index1, int index2); + bool needsPositionForSize (); int calcVerticalBorder (int widgetPadding, int widgetBorder, int widgetMargin, int lineBorderTotal, - int lineMarginTotal); + int lineMarginTotal); void getWordExtremes (Word *word, core::Extremes *extremes); void justifyLine (Line *line, int diff); Line *addLine (int firstWord, int lastWord, int newLastOofPos, @@ -637,7 +632,6 @@ protected: void calcBorders (int lastOofRef, int height); void showMissingLines (); void removeTemporaryLines (); - void setVerticalOffset (int verticalOffset); void decorateText (core::View *view, core::style::Style *style, core::style::Color::Shading shading, @@ -654,7 +648,9 @@ protected: 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); + void drawLine (Line *line, core::View *view, core::Rectangle *area, + core::DrawingContext *context); + int findLineIndex (int y); int findLineIndexWhenNotAllocated (int y); int findLineIndexWhenAllocated (int y); @@ -684,6 +680,8 @@ protected: core::style::Style *style, bool isStart, bool isEnd); void calcTextSize (const char *text, size_t len, core::style::Style *style, core::Requisition *size, bool isStart, bool isEnd); + bool calcSizeOfWidgetInFlow (int wordIndex, Widget *widget, + core::Requisition *size); /** * Of nested text blocks, only the most inner one must regard the @@ -767,7 +765,8 @@ protected: int lastWord); void printBorderChangedErrorAndAbort (int y, Widget *vloat, int wrapLineIndex); - int yOffsetOfLineToBeCreated (); + int yOffsetOfLineToBeCreated (int *lastMargin = NULL); + int yOffsetOfLineCreated (Line *line); bool sendSelectionEvent (core::SelectionState::EventType eventType, core::MousePositionEvent *event); @@ -775,6 +774,7 @@ protected: void processWord (int wordIndex); virtual int wordWrap (int wordIndex, bool wrapAll); int wrapWordInFlow (int wordIndex, bool wrapAll); + int wrapWordOofRef (int wordIndex, bool wrapAll); void balanceBreakPosAndHeight (int wordIndex, int firstIndex, int *searchUntil, bool tempNewLine, int penaltyIndex, bool borderIsCalculated, @@ -809,10 +809,23 @@ protected: void alignLine (int lineIndex); void calcTextOffset (int lineIndex, int totalWidth); - void sizeRequestImpl (core::Requisition *requisition); + void drawLevel (core::View *view, core::Rectangle *area, int level, + core::DrawingContext *context); + + Widget *getWidgetAtPointLevel (int x, int y, int level, + core::GettingWidgetAtPointContext *context); + + void sizeRequestImpl (core::Requisition *requisition, bool posDefined, int x, + int y); + Widget *sizeRequestReference (); void getExtremesImpl (core::Extremes *extremes); void sizeAllocateImpl (core::Allocation *allocation); - int getAvailWidthOfChild (Widget *child, bool forceValue); + + void calcExtraSpaceImpl (); + + int getAvailWidthOfChild (core::Widget *child, bool forceValue); + int getAvailHeightOfChild (core::Widget *child, bool forceValue); + void containerSizeChangedForChildren (); bool affectsSizeChangeContainerChild (Widget *child); bool usesAvailWidth (); @@ -821,13 +834,8 @@ protected: void markSizeChange (int ref); void markExtremesChange (int ref); - void notifySetAsTopLevel(); - void notifySetParent(); - bool isBlockLevel (); - void draw (core::View *view, core::Rectangle *area); - bool buttonPressImpl (core::EventButton *event); bool buttonReleaseImpl (core::EventButton *event); bool motionNotifyImpl (core::EventMotion *event); @@ -842,7 +850,6 @@ protected: core::style::Style *style, int numBreaks, int *breakPos, core::Requisition *wordSize); - static bool isContainingBlock (Widget *widget); public: static int CLASS_ID; @@ -854,8 +861,12 @@ public: static void setPenaltyEmDashRight2 (int penaltyRightEmDash2); static void setStretchabilityFactor (int stretchabilityFactor); - Textblock(bool limitTextWidth); - ~Textblock(); + static inline bool mustAddBreaks (core::style::Style *style) + { return !testStyleOutOfFlow (style) || + testStyleRelativelyPositioned (style); } + + Textblock (bool limitTextWidth); + ~Textblock (); core::Iterator *iterator (core::Content::Type mask, bool atEnd); @@ -864,8 +875,6 @@ public: void addText (const char *text, size_t len, core::style::Style *style); inline void addText (const char *text, core::style::Style *style) { addText (text, strlen(text), style); } - static bool isStyleOutOfFlow (core::style::Style *style) - { return OutOfFlowMgr::isStyleOutOfFlow (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); @@ -873,21 +882,22 @@ public: void addParbreak (int space, core::style::Style *style); void addLinebreak (core::style::Style *style); - core::Widget *getWidgetAtPoint (int x, int y, int level); 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); - virtual bool mustBeWidenedToAvailWidth (); - + bool mustBeWidenedToAvailWidth (); void borderChanged (int y, core::Widget *vloat); + void widgetRefSizeChanged (int externalIndex); void clearPositionChanged (); void oofSizeChanged (bool extremesChanged); - inline int getLineBreakWidth () { return lineBreakWidth; } + int getLineBreakWidth (); + bool isPossibleContainer (int oofmIndex); + bool isPossibleContainerParent (int oofmIndex); }; -#define DBG_SET_WORD_PENALTY(n, i, is) \ +#define DBG_SET_WORD_PENALTY(n, i, is) \ D_STMT_START { \ if (words->getRef(n)->badnessAndPenalty.getPenalty (i) == INT_MIN) \ DBG_OBJ_ARRATTRSET_SYM ("words", n, "penalty." is, "-inf"); \ @@ -896,7 +906,7 @@ public: else \ DBG_OBJ_ARRATTRSET_NUM ("words", n, "penalty." is, \ words->getRef(n)->badnessAndPenalty \ - .getPenalty (i)); \ + .getPenalty (i)); \ } D_STMT_END #define DBG_SET_WORD(n) \ @@ -930,6 +940,16 @@ public: DBG_SET_WORD_PENALTY (n, 1, "1"); \ } D_STMT_END +#define DBG_SET_WORD_SIZE(n) \ + D_STMT_START { \ + DBG_OBJ_ARRATTRSET_NUM ("words", n, "size.width", \ + words->getRef(n)->size.width); \ + DBG_OBJ_ARRATTRSET_NUM ("words", n, "size.ascent", \ + words->getRef(n)->size.ascent); \ + DBG_OBJ_ARRATTRSET_NUM ("words", n, "size.descent", \ + words->getRef(n)->size.descent); \ + } D_STMT_END + #define DBG_MSG_WORD(aspect, prio, prefix, n, suffix) \ D_STMT_START { \ if ((n) < 0 || (n) >= words->size ()) \ |