diff options
author | Sebastian Geerken <devnull@localhost> | 2015-12-30 23:23:26 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2015-12-30 23:23:26 +0100 |
commit | 0a654860a53d5f44276d2637901feee5cba46747 (patch) | |
tree | 3f5f976633bda3145bd796aa4f7d19c06f7438a1 /dw | |
parent | 91ae5fed75491a199a86372648956db16bcdaf7d (diff) |
SRDOP: fix floats within textblocks not necessarily allocating the availabke width.
Diffstat (limited to 'dw')
-rw-r--r-- | dw/alignedtablecell.cc | 4 | ||||
-rw-r--r-- | dw/alignedtablecell.hh | 4 | ||||
-rw-r--r-- | dw/listitem.cc | 2 | ||||
-rw-r--r-- | dw/listitem.hh | 4 | ||||
-rw-r--r-- | dw/oofawarewidget.cc | 12 | ||||
-rw-r--r-- | dw/oofawarewidget.hh | 4 | ||||
-rw-r--r-- | dw/ooffloatsmgr.cc | 39 | ||||
-rw-r--r-- | dw/simpletablecell.cc | 4 | ||||
-rw-r--r-- | dw/simpletablecell.hh | 4 | ||||
-rw-r--r-- | dw/tablecell.hh | 2 | ||||
-rw-r--r-- | dw/textblock.cc | 68 | ||||
-rw-r--r-- | dw/textblock.hh | 4 |
12 files changed, 103 insertions, 48 deletions
diff --git a/dw/alignedtablecell.cc b/dw/alignedtablecell.cc index b5e321b7..25fca497 100644 --- a/dw/alignedtablecell.cc +++ b/dw/alignedtablecell.cc @@ -56,9 +56,9 @@ bool AlignedTableCell::isBlockLevel () return tablecell::isBlockLevel (); } -bool AlignedTableCell::mustBeWidenedToAvailWidth () +bool AlignedTableCell::usesMaxGeneratorWidth () { - return tablecell::mustBeWidenedToAvailWidth (); + return tablecell::usesMaxGeneratorWidth (); } int AlignedTableCell::getAvailWidthOfChild (Widget *child, bool forceValue) diff --git a/dw/alignedtablecell.hh b/dw/alignedtablecell.hh index 8d8e91f5..0bcdbb5c 100644 --- a/dw/alignedtablecell.hh +++ b/dw/alignedtablecell.hh @@ -25,8 +25,6 @@ protected: bool adjustExtraSpaceWhenCorrectingRequisitionByOOF (); - bool mustBeWidenedToAvailWidth (); - int wordWrap (int wordIndex, bool wrapAll); int getValue (); @@ -42,6 +40,8 @@ public: int applyPerHeight (int containerHeight, core::style::Length perHeight); bool isBlockLevel (); + + bool usesMaxGeneratorWidth (); }; } // namespace dw diff --git a/dw/listitem.cc b/dw/listitem.cc index 8bd2a93a..4d6794d8 100644 --- a/dw/listitem.cc +++ b/dw/listitem.cc @@ -40,7 +40,7 @@ ListItem::~ListItem() DBG_OBJ_DELETE (); } -bool ListItem::mustBeWidenedToAvailWidth () +bool ListItem::usesMaxGeneratorWidth () { return true; } diff --git a/dw/listitem.hh b/dw/listitem.hh index 9736c25f..49a3c3a4 100644 --- a/dw/listitem.hh +++ b/dw/listitem.hh @@ -9,8 +9,6 @@ namespace dw { class ListItem: public AlignedTextblock { protected: - bool mustBeWidenedToAvailWidth (); - int getValue (); void setMaxValue (int maxValue, int value); @@ -20,6 +18,8 @@ public: ListItem(ListItem *ref, bool limitTextWidth); ~ListItem(); + bool usesMaxGeneratorWidth (); + void initWithWidget (core::Widget *widget, core::style::Style *style); void initWithText (const char *text, core::style::Style *style); }; diff --git a/dw/oofawarewidget.cc b/dw/oofawarewidget.cc index a35b4c32..a90fbfb9 100644 --- a/dw/oofawarewidget.cc +++ b/dw/oofawarewidget.cc @@ -585,6 +585,18 @@ int OOFAwareWidget::getGeneratorWidth () return 0; } +int OOFAwareWidget::getMaxGeneratorWidth () +{ + assertNotReached (); + return 0; +} + +bool OOFAwareWidget::usesMaxGeneratorWidth () +{ + assertNotReached (); + return false; +} + bool OOFAwareWidget::isPossibleContainer (int oofmIndex) { return oofmIndex != OOFM_FLOATS; diff --git a/dw/oofawarewidget.hh b/dw/oofawarewidget.hh index 4492bac5..3bdd52ab 100644 --- a/dw/oofawarewidget.hh +++ b/dw/oofawarewidget.hh @@ -298,6 +298,10 @@ public: * position floats. */ virtual int getGeneratorWidth (); + + virtual int getMaxGeneratorWidth (); + + virtual bool usesMaxGeneratorWidth (); virtual bool isPossibleContainer (int oofmIndex); diff --git a/dw/ooffloatsmgr.cc b/dw/ooffloatsmgr.cc index 65c6c3ed..5b4aee9a 100644 --- a/dw/ooffloatsmgr.cc +++ b/dw/ooffloatsmgr.cc @@ -419,9 +419,11 @@ void OOFFloatsMgr::sizeAllocateFloats (Side side) int OOFFloatsMgr::calcFloatX (Float *vloat) { DBG_OBJ_ENTER ("resize.common", 0, "calcFloatX", "%p", vloat->getWidget ()); - int x; + int x, effGeneratorWidth; OOFAwareWidget *generator = vloat->generator; + ensureFloatSize (vloat); + switch (vloat->getWidget()->getStyle()->vloat) { case FLOAT_LEFT: // Left floats are always aligned on the left side of the generator @@ -432,17 +434,40 @@ int OOFFloatsMgr::calcFloatX (Float *vloat) // ... but when the float exceeds the line break width of the container, // it is corrected (but not left of the container). This way, we save // space and, especially within tables, avoid some problems. - if (x + vloat->size.width > container->getGeneratorWidth ()) - x = max (0, container->getGeneratorWidth () - vloat->size.width); + if (x + vloat->size.width > container->getMaxGeneratorWidth ()) + x = max (0, container->getMaxGeneratorWidth () - vloat->size.width); break; case FLOAT_RIGHT: // Similar for right floats, but in this case, floats are shifted to the // right when they are too big (instead of shifting the generator to the // right). - x = max (generator->getGeneratorX (oofmIndex) - + generator->getGeneratorWidth () - vloat->size.width - - generator->getStyle()->boxRestWidth(), + + // (The following code for calculating effGeneratorWidth, is quite + // specific for textblocks; this also applies for the comments. Both may + // be generalized, but actually, only textblocks play a role here.) + + if (vloat->generator->usesMaxGeneratorWidth ()) + // For most textblocks, the line break width is used for calculating + // the x position. (This changed for GROWS, where the width of a + // textblock is often smaller that the line break.) + effGeneratorWidth = vloat->generator->getMaxGeneratorWidth (); + else + // For some textblocks, like inline blocks, the line break width would + // be too large for right floats in some cases. + // + // (i) Consider a small inline block with only a few words in one + // line, narrower that line break width minus float width. In this + // case, the sum should be used. + // + // (ii) If there is more than one line, the line break will already be + // exceeded, and so be smaller that GB width + float width. + effGeneratorWidth = + min (vloat->generator->getGeneratorWidth () + vloat->size.width, + vloat->generator->getMaxGeneratorWidth ()); + + x = max (generator->getGeneratorX (oofmIndex) + effGeneratorWidth + - vloat->size.width - generator->getStyle()->boxRestWidth(), // Do not exceed container allocation: 0); break; @@ -453,7 +478,7 @@ int OOFFloatsMgr::calcFloatX (Float *vloat) break; } - DBG_OBJ_LEAVE (); + DBG_OBJ_LEAVE_VAL ("%d", x); return x; } diff --git a/dw/simpletablecell.cc b/dw/simpletablecell.cc index f39d94b5..1466439b 100644 --- a/dw/simpletablecell.cc +++ b/dw/simpletablecell.cc @@ -50,9 +50,9 @@ bool SimpleTableCell::isBlockLevel () return tablecell::isBlockLevel (); } -bool SimpleTableCell::mustBeWidenedToAvailWidth () +bool SimpleTableCell::usesMaxGeneratorWidth () { - return tablecell::mustBeWidenedToAvailWidth (); + return tablecell::usesMaxGeneratorWidth (); } int SimpleTableCell::getAvailWidthOfChild (Widget *child, bool forceValue) diff --git a/dw/simpletablecell.hh b/dw/simpletablecell.hh index 6e9f0f8f..2985a420 100644 --- a/dw/simpletablecell.hh +++ b/dw/simpletablecell.hh @@ -21,8 +21,6 @@ protected: bool adjustExtraSpaceWhenCorrectingRequisitionByOOF (); - bool mustBeWidenedToAvailWidth (); - public: static int CLASS_ID; @@ -33,6 +31,8 @@ public: int applyPerHeight (int containerHeight, core::style::Length perHeight); bool isBlockLevel (); + + bool usesMaxGeneratorWidth (); }; } // namespace dw diff --git a/dw/tablecell.hh b/dw/tablecell.hh index 1300a944..38907b71 100644 --- a/dw/tablecell.hh +++ b/dw/tablecell.hh @@ -7,7 +7,7 @@ namespace dw { namespace tablecell { -inline bool mustBeWidenedToAvailWidth () { return true; } +inline bool usesMaxGeneratorWidth () { return true; } bool getAdjustMinWidth (); bool isBlockLevel (); diff --git a/dw/textblock.cc b/dw/textblock.cc index 11888b76..d9552826 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -352,7 +352,7 @@ void Textblock::sizeRequestImpl (core::Requisition *requisition, int numPos, requisition->descent = boxRestHeight (); } - if (mustBeWidenedToAvailWidth ()) { + if (usesMaxGeneratorWidth ()) { DBG_OBJ_MSGF ("resize", 1, "before considering lineBreakWidth (= %d): %d * (%d + %d)", lineBreakWidth, requisition->width, requisition->ascent, @@ -399,24 +399,6 @@ core::Widget *Textblock::sizeRequestReference (int index) return sizeReferences[index]; } -bool Textblock::mustBeWidenedToAvailWidth () -{ - DBG_OBJ_ENTER0 ("resize", 0, "mustBeWidenedToAvailWidth"); - bool toplevel = getParent () == NULL, - block = getStyle()->display == core::style::DISPLAY_BLOCK, - vloat = testWidgetFloat (this), - abspos = testWidgetAbsolutelyPositioned (this), - fixpos = testWidgetFixedlyPositioned (this), - // In detail, this depends on what the respective OOFM does - // with the child widget: - result = toplevel || (block && !(vloat || abspos || fixpos)); - DBG_OBJ_LEAVE_VAL ("%s (toplevel: %s, block: %s, float: %s, abspos: %s, " - "fixpos: %s)", - boolToStr(result), boolToStr(toplevel), boolToStr(block), - boolToStr(vloat), boolToStr(abspos), boolToStr(fixpos)); - return result; -} - int Textblock::calcVerticalBorder (int widgetPadding, int widgetBorder, int widgetMargin, int lineBorderTotal, int lineMarginTotal) @@ -778,7 +760,7 @@ int Textblock::getAvailWidthOfChild (Widget *child, bool forceValue) width = Widget::getAvailWidthOfChild (child, forceValue); if (forceValue && this == child->getContainer () && - !mustBeWidenedToAvailWidth ()) { + !usesMaxGeneratorWidth ()) { core::Extremes extremes; getExtremes (&extremes); if (width > extremes.maxWidth - boxDiffWidth () - leftInnerPadding) @@ -824,7 +806,7 @@ bool Textblock::affectsSizeChangeContainerChild (Widget *child) // See Textblock::getAvailWidthOfChild() and Textblock::oofSizeChanged(): // Extremes changes affect the size of the child, too: bool ret; - if (!mustBeWidenedToAvailWidth () && + if (!usesMaxGeneratorWidth () && (extremesQueued () || extremesChanged ())) ret = true; else @@ -3136,7 +3118,7 @@ void Textblock::oofSizeChanged (bool extremesChanged) // See Textblock::getAvailWidthOfChild(): Extremes changes may become also // relevant for the children, under certain conditions: - if (extremesChanged && !mustBeWidenedToAvailWidth ()) + if (extremesChanged && !usesMaxGeneratorWidth ()) containerSizeChanged (); DBG_OBJ_LEAVE (); @@ -3184,15 +3166,47 @@ int Textblock::getGeneratorRest (int oofmIndex) int Textblock::getGeneratorWidth () { + DBG_OBJ_ENTER0 ("resize", 0, "Textblock::getGeneratorWidth"); + // Cf. sizeRequestImpl. - if (mustBeWidenedToAvailWidth ()) - return lineBreakWidth; - else { - int w = lines->size () > 0 ? lines->getLastRef()->maxLineWidth : 0; - return min (w + leftInnerPadding + boxDiffWidth (), lineBreakWidth); + if (usesMaxGeneratorWidth ()) { + return lineBreakWidth; + DBG_OBJ_LEAVE_VAL ("%d", lineBreakWidth); + } else { + int w0 = lines->size () > 0 ? lines->getLastRef()->maxLineWidth : 0, + w = min (w0 + leftInnerPadding + boxDiffWidth (), lineBreakWidth); + DBG_OBJ_LEAVE_VAL ("min (%d + %d + %d, %d) = %d", + w0, leftInnerPadding, boxDiffWidth (), lineBreakWidth, + w); + return w; } } +int Textblock::getMaxGeneratorWidth () +{ + DBG_OBJ_ENTER0 ("resize", 0, "Textblock::getMaxGeneratorWidth"); + DBG_OBJ_LEAVE_VAL ("%d", lineBreakWidth); + return lineBreakWidth; +} + +bool Textblock::usesMaxGeneratorWidth () +{ + DBG_OBJ_ENTER0 ("resize", 0, "usesMaxGeneratorWidth"); + bool toplevel = getParent () == NULL, + block = getStyle()->display == core::style::DISPLAY_BLOCK, + vloat = testWidgetFloat (this), + abspos = testWidgetAbsolutelyPositioned (this), + fixpos = testWidgetFixedlyPositioned (this), + // In detail, this depends on what the respective OOFM does + // with the child widget: + result = toplevel || (block && !(vloat || abspos || fixpos)); + DBG_OBJ_LEAVE_VAL ("%s (toplevel: %s, block: %s, float: %s, abspos: %s, " + "fixpos: %s)", + boolToStr(result), boolToStr(toplevel), boolToStr(block), + boolToStr(vloat), boolToStr(abspos), boolToStr(fixpos)); + return result; +} + bool Textblock::isPossibleContainer (int oofmIndex) { return true; diff --git a/dw/textblock.hh b/dw/textblock.hh index 532e1f84..69e3ef89 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -821,8 +821,6 @@ protected: int numSizeRequestReferences (); Widget *sizeRequestReference (int index); - virtual bool mustBeWidenedToAvailWidth (); - void getExtremesSimpl (core::Extremes *extremes); int numGetExtremesReferences (); @@ -908,6 +906,8 @@ public: int getGeneratorX (int oofmIndex); int getGeneratorY (int oofmIndex); int getGeneratorWidth (); + int getMaxGeneratorWidth (); + bool usesMaxGeneratorWidth (); bool isPossibleContainer (int oofmIndex); bool isPossibleContainerParent (int oofmIndex); }; |