diff options
-rw-r--r-- | dw/outofflowmgr.cc | 136 | ||||
-rw-r--r-- | dw/outofflowmgr.hh | 45 | ||||
-rw-r--r-- | dw/textblock.cc | 6 |
3 files changed, 104 insertions, 83 deletions
diff --git a/dw/outofflowmgr.cc b/dw/outofflowmgr.cc index 0c9a92be..4bd6b7ff 100644 --- a/dw/outofflowmgr.cc +++ b/dw/outofflowmgr.cc @@ -445,6 +445,8 @@ OutOfFlowMgr::TBInfo::TBInfo (OutOfFlowMgr *oofm, Textblock *textblock, leftFloatsGB = new SortedFloatsVector (oofm, LEFT, SortedFloatsVector::GB); rightFloatsGB = new SortedFloatsVector (oofm, RIGHT, SortedFloatsVector::GB); + + updateAllocation (); } OutOfFlowMgr::TBInfo::~TBInfo () @@ -490,8 +492,7 @@ OutOfFlowMgr::OutOfFlowMgr (Textblock *containingBlock) absolutelyPositioned = new Vector<AbsolutelyPositioned> (1, true); containingBlockWasAllocated = containingBlock->wasAllocated (); - if (containingBlockWasAllocated) - containingBlockAllocation = *(containingBlock->getAllocation()); + containingBlockAllocation = *(containingBlock->getAllocation()); addWidgetInFlow (containingBlock, NULL, 0); } @@ -521,72 +522,87 @@ OutOfFlowMgr::~OutOfFlowMgr () DBG_OBJ_DELETE (); } -void OutOfFlowMgr::sizeAllocateStart (Allocation *containingBlockAllocation) +void OutOfFlowMgr::sizeAllocateStart (Textblock *caller, Allocation *allocation) { - DBG_OBJ_MSG ("resize.oofm", 0, "<b>sizeAllocateStart</b>"); - this->containingBlockAllocation = *containingBlockAllocation; - containingBlockWasAllocated = true; -} - -void OutOfFlowMgr::sizeAllocateEnd () -{ - DBG_OBJ_MSG ("resize.oofm", 0, "<b>sizeAllocateEnd</b>"); + DBG_OBJ_MSGF ("resize.oofm", 0, + "<b>sizeAllocateStart</b> (%p, (%d, %d, %d * (%d + %d)))", + caller, allocation->x, allocation->y, allocation->width, + allocation->ascent, allocation->descent); DBG_OBJ_MSG_START (); - // Move floats from GB lists to the one CB list. - moveFromGBToCB (LEFT); - moveFromGBToCB (RIGHT); + getTextblock(caller)->allocation = *allocation; + getTextblock(caller)->wasAllocated = true; - // Floats and absolutely positioned blocks have to be allocated - sizeAllocateFloats (LEFT); - sizeAllocateFloats (RIGHT); - sizeAllocateAbsolutelyPositioned (); - - // Textblocks have already been allocated here. - - // Check changes of both textblocks and floats allocation. (All is checked - // by hasRelationChanged (...).) - for (lout::container::typed::Iterator<TypedPointer <Textblock> > it = - tbInfosByTextblock->iterator (); - it.hasNext (); ) { - TypedPointer <Textblock> *key = it.getNext (); - TBInfo *tbInfo = tbInfosByTextblock->get (key); - Textblock *tb = key->getTypedValue(); - - int minFloatPos; - Widget *minFloat; - if (hasRelationChanged (tbInfo, &minFloatPos, &minFloat)) - tb->borderChanged (minFloatPos, minFloat); + if (caller == containingBlock) { + containingBlockAllocation = *allocation; + containingBlockWasAllocated = true; } - - // Store some information for later use. - for (lout::container::typed::Iterator<TypedPointer <Textblock> > it = - tbInfosByTextblock->iterator (); - it.hasNext (); ) { - TypedPointer <Textblock> *key = it.getNext (); - TBInfo *tbInfo = tbInfosByTextblock->get (key); - Textblock *tb = key->getTypedValue(); - - tbInfo->updateAllocation (); - tbInfo->availWidth = tb->getAvailWidth (); - } - - // There are cases where some allocated floats (TODO: later also absolutely - // positioned elements?) exceed the CB allocation. - bool sizeChanged = doFloatsExceedCB (LEFT) || doFloatsExceedCB (RIGHT); - // Similar for extremes. (TODO: here also absolutely positioned elements?) - bool extremesChanged = - haveExtremesChanged (LEFT) || haveExtremesChanged (RIGHT); + DBG_OBJ_MSG_END (); +} - for (int i = 0; i < leftFloatsCB->size(); i++) - leftFloatsCB->get(i)->updateAllocation (); +void OutOfFlowMgr::sizeAllocateEnd (Textblock *caller) +{ + DBG_OBJ_MSGF ("resize.oofm", 0, "<b>sizeAllocateEnd</b> (%p)", caller); + DBG_OBJ_MSG_START (); - for (int i = 0; i < rightFloatsCB->size(); i++) - rightFloatsCB->get(i)->updateAllocation (); - - if (sizeChanged || extremesChanged) - containingBlock->oofSizeChanged (extremesChanged); + if (caller == containingBlock) { + // Move floats from GB lists to the one CB list. + moveFromGBToCB (LEFT); + moveFromGBToCB (RIGHT); + + // Floats and absolutely positioned blocks have to be allocated + sizeAllocateFloats (LEFT); + sizeAllocateFloats (RIGHT); + sizeAllocateAbsolutelyPositioned (); + + // Textblocks have already been allocated here. + + // Check changes of both textblocks and floats allocation. (All + // is checked by hasRelationChanged (...).) + for (lout::container::typed::Iterator<TypedPointer <Textblock> > it = + tbInfosByTextblock->iterator (); + it.hasNext (); ) { + TypedPointer <Textblock> *key = it.getNext (); + TBInfo *tbInfo = tbInfosByTextblock->get (key); + Textblock *tb = key->getTypedValue(); + + int minFloatPos; + Widget *minFloat; + if (hasRelationChanged (tbInfo, &minFloatPos, &minFloat)) + tb->borderChanged (minFloatPos, minFloat); + } + + // Store some information for later use. + for (lout::container::typed::Iterator<TypedPointer <Textblock> > it = + tbInfosByTextblock->iterator (); + it.hasNext (); ) { + TypedPointer <Textblock> *key = it.getNext (); + TBInfo *tbInfo = tbInfosByTextblock->get (key); + Textblock *tb = key->getTypedValue(); + + tbInfo->updateAllocation (); + tbInfo->availWidth = tb->getAvailWidth (); + } + + // There are cases where some allocated floats (TODO: later also + // absolutely positioned elements?) exceed the CB allocation. + bool sizeChanged = doFloatsExceedCB (LEFT) || doFloatsExceedCB (RIGHT); + + // Similar for extremes. (TODO: here also absolutely positioned + // elements?) + bool extremesChanged = + haveExtremesChanged (LEFT) || haveExtremesChanged (RIGHT); + + for (int i = 0; i < leftFloatsCB->size(); i++) + leftFloatsCB->get(i)->updateAllocation (); + + for (int i = 0; i < rightFloatsCB->size(); i++) + rightFloatsCB->get(i)->updateAllocation (); + + if (sizeChanged || extremesChanged) + containingBlock->oofSizeChanged (extremesChanged); + } DBG_OBJ_MSG_END (); } diff --git a/dw/outofflowmgr.hh b/dw/outofflowmgr.hh index c5c560c7..109351d5 100644 --- a/dw/outofflowmgr.hh +++ b/dw/outofflowmgr.hh @@ -19,14 +19,10 @@ private: Textblock *containingBlock; - // These two values are set by sizeAllocateStart(), and they are - // accessable also within sizeAllocateEnd(), and also for the - // containing block, for which allocation and WAS_ALLOCATED is set - // *after* sizeAllocateEnd(). See the two inline functions - // wasAllocated(Widget*) and getAllocation(Widget*) (further down) - // for usage. - core::Allocation containingBlockAllocation; + // These two values are redundant to TBInfo::wasAllocated and + // TBInfo::allocation, for some special cases. bool containingBlockWasAllocated; + core::Allocation containingBlockAllocation; class WidgetInfo: public lout::object::Object { @@ -174,6 +170,15 @@ private: TBInfo *parent; int parentExtIndex; + + // These two values are set by sizeAllocateStart(), and they are + // accessable also within sizeAllocateEnd() for the same + // textblock, for which allocation and WAS_ALLOCATED is set + // *after* sizeAllocateEnd(). See the two functions + // wasAllocated(Widget*) and getAllocation(Widget*) (further + // down) for usage. + bool wasAllocated; + core::Allocation allocation; // These two lists store all floats generated by this textblock, // as long as this textblock is not allocates. @@ -184,6 +189,10 @@ private: ~TBInfo (); inline Textblock *getTextblock () { return (Textblock*)getWidget (); } + inline void updateAllocation () { + wasAllocated = getWidget()->wasAllocated (); + allocation = *(getWidget()->getAllocation ()); + } }; class AbsolutelyPositioned: public lout::object::Object @@ -219,21 +228,19 @@ private: /** * Variant of Widget::wasAllocated(), which can also be used within - * OOFM::sizeAllocateEnd(), and also for the generating block. + * OOFM::sizeAllocateEnd(). */ - inline bool wasAllocated (core::Widget *widget) { - return widget->wasAllocated () || - (widget == (core::Widget*)containingBlock && - containingBlockWasAllocated); } + inline bool wasAllocated (Textblock *textblock) { + return getTextblock(textblock)->wasAllocated; + } /** * Variant of Widget::getAllocation(), which can also be used - * within OOFM::sizeAllocateEnd(), and also for the generating - * block. + * within OOFM::sizeAllocateEnd(). */ - inline core::Allocation *getAllocation (core::Widget *widget) { - return widget == (core::Widget*)containingBlock ? - &containingBlockAllocation : widget->getAllocation (); } + inline core::Allocation *getAllocation (Textblock *textblock) { + return &(getTextblock(textblock)->allocation); + } void moveExternalIndices (SortedFloatsVector *list, int oldStartIndex, int diff); @@ -362,8 +369,8 @@ public: OutOfFlowMgr (Textblock *containingBlock); ~OutOfFlowMgr (); - void sizeAllocateStart (core::Allocation *containingBlockAllocation); - void sizeAllocateEnd (); + void sizeAllocateStart (Textblock *caller, core::Allocation *allocation); + void sizeAllocateEnd (Textblock *caller); void draw (core::View *view, core::Rectangle *area); void markSizeChange (int ref); diff --git a/dw/textblock.cc b/dw/textblock.cc index 49030d26..47f7d7b7 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -492,8 +492,7 @@ void Textblock::sizeAllocateImpl (core::Allocation *allocation) showMissingLines (); - if(outOfFlowMgr) - outOfFlowMgr->sizeAllocateStart (allocation); + containingBlock->outOfFlowMgr->sizeAllocateStart (this, allocation); int lineIndex, wordIndex; Line *line; @@ -591,8 +590,7 @@ void Textblock::sizeAllocateImpl (core::Allocation *allocation) } } - if(outOfFlowMgr) - outOfFlowMgr->sizeAllocateEnd (); + containingBlock->outOfFlowMgr->sizeAllocateEnd (this); for (int i = 0; i < anchors->size(); i++) { Anchor *anchor = anchors->getRef(i); |