diff options
Diffstat (limited to 'dw')
-rw-r--r-- | dw/oofawarewidget.cc | 4 | ||||
-rw-r--r-- | dw/oofawarewidget.hh | 12 | ||||
-rw-r--r-- | dw/ooffloatsmgr.cc | 522 | ||||
-rw-r--r-- | dw/ooffloatsmgr.hh | 64 | ||||
-rw-r--r-- | dw/oofpositionedmgr.cc | 21 | ||||
-rw-r--r-- | dw/oofpositionedmgr.hh | 24 | ||||
-rw-r--r-- | dw/outofflowmgr.hh | 26 | ||||
-rw-r--r-- | dw/textblock.cc | 270 | ||||
-rw-r--r-- | dw/textblock.hh | 2 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 15 |
10 files changed, 343 insertions, 617 deletions
diff --git a/dw/oofawarewidget.cc b/dw/oofawarewidget.cc index c1398a64..cd0380a0 100644 --- a/dw/oofawarewidget.cc +++ b/dw/oofawarewidget.cc @@ -206,7 +206,7 @@ void OOFAwareWidget::initOutOfFlowMgrs () { if (oofContainer[OOFM_FLOATS]->outOfFlowMgr[OOFM_FLOATS] == NULL) { oofContainer[OOFM_FLOATS]->outOfFlowMgr[OOFM_FLOATS] = - new OOFFloatsMgr (oofContainer[OOFM_FLOATS]); + new OOFFloatsMgr (oofContainer[OOFM_FLOATS], OOFM_FLOATS); DBG_OBJ_ASSOC (oofContainer[OOFM_FLOATS], oofContainer[OOFM_FLOATS]->outOfFlowMgr[OOFM_FLOATS]); } @@ -538,7 +538,7 @@ bool OOFAwareWidget::mustBeWidenedToAvailWidth () return false; } -void OOFAwareWidget::borderChanged (int y, Widget *vloat) +void OOFAwareWidget::borderChanged (int oofmIndex, int y, Widget *widgetOOF) { assertNotReached (); } diff --git a/dw/oofawarewidget.hh b/dw/oofawarewidget.hh index 3946c72b..835fbeff 100644 --- a/dw/oofawarewidget.hh +++ b/dw/oofawarewidget.hh @@ -247,7 +247,17 @@ public: core::DrawingContext *context); virtual bool mustBeWidenedToAvailWidth (); - virtual void borderChanged (int y, core::Widget *vloat); + + /** + * Called by an implementation of dw::oof::OutOfFlowMgr (actually only + * OOFFloatsMgr) when the border has changed due to a widget out of flow, or + * some widgets out of flow (actually floats). + * + * `y`, given relative to the container, denotes the minimal position (when + * more than one float caused this), `widgetOOF` the respective widget out of + * flow. + */ + virtual void borderChanged (int oofmIndex, int y, core::Widget *widgetOOF); virtual void widgetRefSizeChanged (int externalIndex); virtual void clearPositionChanged (); virtual void oofSizeChanged (bool extremesChanged); diff --git a/dw/ooffloatsmgr.cc b/dw/ooffloatsmgr.cc index 9cdb6786..ce32be77 100644 --- a/dw/ooffloatsmgr.cc +++ b/dw/ooffloatsmgr.cc @@ -102,136 +102,24 @@ void OOFFloatsMgr::Float::intoStringBuffer(StringBuffer *sb) sb->append (" }"); } -bool OOFFloatsMgr::Float::covers (OOFAwareWidget *textblock, int y, int h) +/** + * `y` is given relative to the container. + */ +bool OOFFloatsMgr::Float::covers (int y, int h) { DBG_OBJ_ENTER_O ("border", 0, getOOFFloatsMgr (), "covers", - "%p, %d, %d [vloat: %p]", - textblock, y, h, getWidget ()); - - bool b; - - if (textblock == generatingBlock) { - int reqyGB = y; - int flyGB = yReal; - getOOFFloatsMgr()->ensureFloatSize (this); - int flh = size.ascent + size.descent; - b = flyGB + flh > reqyGB && flyGB < reqyGB + h; - - DBG_OBJ_MSGF_O ("border", 1, getOOFFloatsMgr (), - "for generator: reqyGB = %d, flyGB = %d, " - "flh = %d + %d = %d => %s", - reqyGB, flyGB, size.ascent, size.descent, flh, - b ? "true" : "false"); - } else { - // (If the textblock were not allocated, the GB list would have - // been choosen instead of the CB list, and so this else-branch - // would not have been not executed.) - assert (getOOFFloatsMgr()->wasAllocated (textblock)); - - if (!getWidget()->wasAllocated ()) { - DBG_OBJ_MSG_O ("border", 1, getOOFFloatsMgr (), - "not generator (not allocated) => false"); - b = false; - } else { - Allocation *tba = getOOFFloatsMgr()->getAllocation(textblock), - *fla = getWidget()->getAllocation (); - int reqyCanv = tba->y + y; - int flyCanv = fla->y; - int flh = fla->ascent + fla->descent; - b = flyCanv + flh > reqyCanv && flyCanv < reqyCanv + h; - - DBG_OBJ_MSGF_O ("border", 1, getOOFFloatsMgr (), - "not generator (allocated): reqyCanv = %d + %d = %d, " - "flyCanv = %d, flh = %d + %d = %d => %s", - tba->y, y, reqyCanv, flyCanv, - fla->ascent, fla->descent, flh, b ? "true" : "false"); - } - } + "%d, %d [vloat: %p]", y, h, getWidget ()); - DBG_OBJ_LEAVE_O (getOOFFloatsMgr ()); + getOOFFloatsMgr()->ensureFloatSize (this); + bool b = yReal + size.ascent + size.descent > y && yReal < y + h; + DBG_OBJ_LEAVE_VAL_O (getOOFFloatsMgr (), "%s", b ? "true" : "false"); return b; } int OOFFloatsMgr::Float::ComparePosition::compare (Object *o1, Object *o2) { - Float *fl1 = (Float*)o1, *fl2 = (Float*)o2; - int r; - - DBG_OBJ_ENTER_O ("border", 1, oofm, - "ComparePosition/compare", "(#%d, #%d) [refTB = %p]", - fl1->index, fl2->index, refTB); - - if (refTB == fl1->generatingBlock && refTB == fl2->generatingBlock) { - DBG_OBJ_MSG_O ("border", 2, oofm, "refTB is generating both floats"); - r = fl1->yReal - fl2->yReal; - } else { - DBG_OBJ_MSG_O ("border", 2, oofm, "refTB is not generating both floats"); - DBG_OBJ_MSG_START_O (oofm); - - DBG_OBJ_MSGF_O ("border", 2, oofm, "generators are %p and %p", - fl1->generatingBlock, fl2->generatingBlock); - - // (i) Floats may not yet been allocated. Non-allocated floats - // do not have an effect yet, they are considered "at the end" - // of the list. - - // (ii) Float::widget is NULL for the key used for binary - // search. In this case, Float::yReal is used instead (which is - // set in SortedFloatsVector::find, too). The generator is the - // textblock, and should be allocated. (If not, the GB list - // would have been choosen instead of the CB list, and so this - // else-branch would not have been not executed.) - - bool a1 = fl1->getWidget () ? fl1->getWidget()->wasAllocated () : true; - bool a2 = fl2->getWidget () ? fl2->getWidget()->wasAllocated () : true; - - DBG_OBJ_MSGF_O ("border", 2, oofm, - "float 1 (%p) allocated: %s; float 2 (%p) allocated: %s", - fl1->getWidget (), a1 ? "yes" : "no", fl2->getWidget (), - a2 ? "yes" : "no"); - - if (a1 && a2) { - int fly1, fly2; - - if (fl1->getWidget()) { - fly1 = fl1->getWidget()->getAllocation()->y; - DBG_OBJ_MSGF_O ("border", 2, oofm, "fly1 = %d", fly1); - } else { - assert (oofm->wasAllocated (fl1->generatingBlock)); - fly1 = oofm->getAllocation(fl1->generatingBlock)->y + fl1->yReal; - DBG_OBJ_MSGF_O ("border", 2, oofm, "fly1 = %d + %d = %d", - oofm->getAllocation(fl1->generatingBlock)->y, - fl1->yReal, fly1); - } - - if (fl2->getWidget()) { - fly2 = fl2->getWidget()->getAllocation()->y; - DBG_OBJ_MSGF_O ("border", 2, oofm, "fly2 = %d", fly2); - } else { - assert (oofm->wasAllocated (fl2->generatingBlock)); - fly2 = oofm->getAllocation(fl2->generatingBlock)->y + fl2->yReal; - DBG_OBJ_MSGF_O ("border", 2, oofm, "fly2 = %d + %d = %d", - oofm->getAllocation(fl2->generatingBlock)->y, - fl2->yReal, fly2); - } - - r = fly1 - fly2; - - DBG_OBJ_MSGF_O ("border", 2, oofm, "r = %d - %d = %d", fly1, fly2, r); - } else if (a1 && !a2) - r = -1; - else if (!a1 && a2) - r = +1; - else // if (!a1 && !a2) - return 0; - - DBG_OBJ_MSG_END_O (oofm); - } - - DBG_OBJ_MSGF_O ("border", 1, oofm, "result: %d", r); - DBG_OBJ_LEAVE_O (oofm); - return r; + return ((Float*)o1)->yReal - ((Float*)o2)->yReal; } int OOFFloatsMgr::Float::CompareSideSpanningIndex::compare (Object *o1, @@ -340,55 +228,29 @@ int OOFFloatsMgr::SortedFloatsVector::findFloatIndex (OOFAwareWidget *lastGB, return r; } -int OOFFloatsMgr::SortedFloatsVector::find (OOFAwareWidget *textblock, int y, - int start, int end) +/** + * `y` is given relative to the container. + */ +int OOFFloatsMgr::SortedFloatsVector::find (int y, int start, int end) { - DBG_OBJ_ENTER_O ("border", 0, oofm, "find", "%p, %d, %d, %d", - textblock, y, start, end); + DBG_OBJ_ENTER_O ("border", 0, oofm, "find", "%d, %d, %d", y, start, end); Float key (oofm, NULL, NULL, 0); - key.generatingBlock = textblock; key.yReal = y; - key.index = -1; // for debugging - Float::ComparePosition comparator (oofm, textblock); + Float::ComparePosition comparator; int result = bsearch (&key, false, start, end, &comparator); - DBG_OBJ_MSGF_O ("border", 1, oofm, "=> result = %d", result); - DBG_OBJ_LEAVE_O (oofm); + DBG_OBJ_LEAVE_VAL_O (oofm, "%d", result); return result; } -int OOFFloatsMgr::SortedFloatsVector::findFirst (OOFAwareWidget *textblock, - int y, int h, +int OOFFloatsMgr::SortedFloatsVector::findFirst (int y, int h, OOFAwareWidget *lastGB, int lastExtIndex, int *lastReturn) { - DBG_OBJ_ENTER_O ("border", 0, oofm, "findFirst", "%p, %d, %d, %p, %d", - textblock, y, h, lastGB, lastExtIndex); - - DBG_IF_RTFL { - DBG_OBJ_MSG_O ("border", 2, oofm, "searching in list:"); - DBG_OBJ_MSG_START_O (oofm); - - for (int i = 0; i < size(); i++) { - DBG_OBJ_MSGF_O ("border", 2, oofm, - "%d: (%p, i = %d/%d, y = %d/%d, s = (%d * (%d + %d)), " - "%s, %s, ext = %d, GB = %p); widget at (%d, %d)", - i, get(i)->getWidget (), get(i)->index, - get(i)->sideSpanningIndex, get(i)->yReq, get(i)->yReal, - get(i)->size.width, get(i)->size.ascent, - get(i)->size.descent, - get(i)->dirty ? "dirty" : "clean", - get(i)->sizeChangedSinceLastAllocation ? "scsla" - : "sNcsla", - get(i)->externalIndex, get(i)->generatingBlock, - get(i)->getWidget()->getAllocation()->x, - get(i)->getWidget()->getAllocation()->y); - } - - DBG_OBJ_MSG_END_O (oofm); - } + DBG_OBJ_ENTER_O ("border", 0, oofm, "findFirst", "%d, %d, %p, %d", + y, h, lastGB, lastExtIndex); int last = findFloatIndex (lastGB, lastExtIndex); DBG_OBJ_MSGF_O ("border", 1, oofm, "last = %d", last); @@ -398,7 +260,7 @@ int OOFFloatsMgr::SortedFloatsVector::findFirst (OOFAwareWidget *textblock, if (lastReturn) *lastReturn = last; - int i = find (textblock, y, 0, last), result; + int i = find (y, 0, last), result; DBG_OBJ_MSGF_O ("border", 1, oofm, "i = %d", i); // Note: The smallest value of "i" is 0, which means that "y" is before or @@ -407,15 +269,14 @@ int OOFFloatsMgr::SortedFloatsVector::findFirst (OOFAwareWidget *textblock, // respectively, float is a candidate. Generally, both floats, before and // at the search position, are candidates. - if (i > 0 && get(i - 1)->covers (textblock, y, h)) + if (i > 0 && get(i - 1)->covers (y, h)) result = i - 1; - else if (i <= last && get(i)->covers (textblock, y, h)) + else if (i <= last && get(i)->covers (y, h)) result = i; else result = -1; - DBG_OBJ_MSGF_O ("border", 1, oofm, "=> result = %d", result); - DBG_OBJ_LEAVE_O (oofm); + DBG_OBJ_LEAVE_VAL_O (oofm, "%d", result); return result; } @@ -455,11 +316,12 @@ OOFFloatsMgr::TBInfo::~TBInfo () delete rightFloats; } -OOFFloatsMgr::OOFFloatsMgr (OOFAwareWidget *container) +OOFFloatsMgr::OOFFloatsMgr (OOFAwareWidget *container, int oofmIndex) { DBG_OBJ_CREATE ("dw::OOFFloatsMgr"); - this->container = (OOFAwareWidget*)container; + this->container = container; + this->oofmIndex = oofmIndex; leftFloats = new SortedFloatsVector (this, LEFT); rightFloats = new SortedFloatsVector (this, RIGHT); @@ -655,7 +517,7 @@ void OOFFloatsMgr::sizeAllocateFloats (Side side) Allocation childAllocation; childAllocation.x = cba->x + calcFloatX (vloat, side, gba->x - cba->x, getGBWidthForAllocation (vloat)); - childAllocation.y = gba->y + vloat->yReal; + childAllocation.y = cba->y + vloat->yReal; childAllocation.width = vloat->size.width; childAllocation.ascent = vloat->size.ascent; childAllocation.descent = vloat->size.descent; @@ -683,7 +545,7 @@ int OOFFloatsMgr::getGBWidthForAllocation (Float *vloat) /** * \brief ... * - * gbX is given relative to the CB, as is the return value. + * gbX is given relative to the container, as is the return value. */ int OOFFloatsMgr::calcFloatX (Float *vloat, Side side, int gbX, int gbWidth) { @@ -703,7 +565,7 @@ int OOFFloatsMgr::calcFloatX (Float *vloat, Side side, int gbX, int gbWidth) // container, it is corrected (but not left of the container). // This way, we save space and, especially within tables, avoid // some problems. - if (wasAllocated (container) && + if (wasAllocated (container) /* TODO: obsolete after SRDOP? */ && x + vloat->size.width > container->getLineBreakWidth ()) { x = max (0, container->getLineBreakWidth () - vloat->size.width); DBG_OBJ_MSGF ("resize.common", 1, @@ -895,10 +757,10 @@ void OOFFloatsMgr::markSizeChange (int ref) "<Float>.sizeChangedSinceLastAllocation", vloat->sizeChangedSinceLastAllocation); - // The generating block is told directly about this. (Others later, in - // sizeAllocateEnd.) Could be faster (cf. hasRelationChanged, which - // differentiates many special cases), but the size is not known yet, - vloat->generatingBlock->borderChanged (vloat->yReal, vloat->getWidget ()); + for (int i = 0; i < tbInfos->size (); i++) + tbInfos->get(i)->getOOFAwareWidget()->borderChanged (oofmIndex, + vloat->yReal, + vloat->getWidget ()); DBG_OBJ_LEAVE (); } @@ -1039,10 +901,6 @@ void OOFFloatsMgr::tellIncompletePosition2 (Widget *generator, Widget *widget, bool OOFFloatsMgr::collidesV (Float *vloat, Float *other, int *yReal) { - // Only checks vertical (possible) collisions, and only refers to - // vloat->yReal; never to vloat->allocation->y, even when the GBs are - // different. Used only in tellPosition. - DBG_OBJ_ENTER ("resize.oofm", 0, "collidesV", "#%d [%p], #%d [%p], ...", vloat->index, vloat->getWidget (), other->index, other->getWidget ()); @@ -1051,82 +909,24 @@ bool OOFFloatsMgr::collidesV (Float *vloat, Float *other, int *yReal) DBG_OBJ_MSGF ("resize.oofm", 1, "initial yReal = %d", vloat->yReal); - if (vloat->generatingBlock == other->generatingBlock) { - ensureFloatSize (other); - int otherBottomGB = - other->yReal + other->size.ascent + other->size.descent; - - DBG_OBJ_MSGF ("resize.oofm", 1, - "same generators: otherBottomGB = %d + (%d + %d) = %d", - other->yReal, other->size.ascent, other->size.descent, - otherBottomGB); + ensureFloatSize (other); + int otherBottomGB = other->yReal + other->size.ascent + other->size.descent; - if (vloat->yReal < otherBottomGB) { - *yReal = otherBottomGB; - result = true; - } else - result = false; - } else { - // If the other float is not allocated, there is no collision. The - // allocation of this float (vloat) is not used at all. - if (!other->getWidget()->wasAllocated ()) - result = false; - else { - assert (wasAllocated (vloat->generatingBlock)); - Allocation *gba = getAllocation (vloat->generatingBlock), - *flaOther = other->getWidget()->getAllocation (); + DBG_OBJ_MSGF ("resize.oofm", 1, "otherBottomGB = %d + (%d + %d) = %d", + other->yReal, other->size.ascent, other->size.descent, + otherBottomGB); - // TODO: The following comment is wrong after SRDOP. What is still - // relevant (especially in the second paragraph)? (Also, usage of - // allocation has to be reworked generally.) - // - // We distinguish two cases (by different values of useAllocation): - // (i) within tellPosition, GB allocation + yReal is used for the - // y position of the other float, while (ii) in checkAllocatedFloat- - // Collisions, the float allocation is used. The latter is necessary - // by the definition of this method, the former increases performance, - // as compared to using the float allocation, in some cases, as in - // this: - // - // When '<div><div style="float:left">[Some text]</div></div>' is - // repeated n times, the resize idle function (Layout::resizeIdle) - // would be repeated roughly n times, when also in case (i) the float - // allocation is used, since for the collision test of float n with - // float n - 1, the allocation of float n - 1 does not yet reflect the - // collision test between n - 1 and n - 2, but yReal does for n - 1. - // - // On the other hand, the GB allocations will most likely more stable - // than the float allocations. - // - // Cases where this is incorrect will hopefully be rare, and, in any - // case, corrected in sizeAllocateEnd, either because hasRelation- - // Changed returns true, or in checkAllocatedFloatCollisions. - - int otherFloatY = - getAllocation(other->generatingBlock)->y + other->yReal; - int otherBottomGB = - otherFloatY + flaOther->ascent + flaOther->descent - gba->y; - - DBG_OBJ_MSGF ("resize.oofm", 1, - "different generators: " - "otherBottomGB = %d + (%d + %d) - %d = %d", - otherFloatY, flaOther->ascent, flaOther->descent, gba->y, - otherBottomGB); - - if (vloat->yReal < otherBottomGB) { - *yReal = otherBottomGB; - result = true; - } else - result = false; - } - } + if (vloat->yReal < otherBottomGB) { + *yReal = otherBottomGB; + result = true; + } else + result = false; if (result) - DBG_OBJ_MSGF ("resize.oofm", 1, "collides: new yReal = %d", *yReal); + DBG_OBJ_LEAVE_VAL ("%s, %d", "true", *yReal); else - DBG_OBJ_MSG ("resize.oofm", 1, "does not collide"); + DBG_OBJ_LEAVE_VAL ("%s", "false"); - DBG_OBJ_LEAVE (); return result; } @@ -1241,57 +1041,33 @@ void OOFFloatsMgr::getFloatsSize (Requisition *cbReq, Side side, int *width, "float %p has generator %p (container is %p)", vloat->getWidget (), vloat->generatingBlock, container); - if (vloat->generatingBlock == container || - wasAllocated (vloat->generatingBlock)) { - ensureFloatSize (vloat); - int x, y; - - int effWidth; - if (container->mustBeWidenedToAvailWidth ()) - // 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.) - effWidth = vloat->generatingBlock->getLineBreakWidth (); - 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. - effWidth = min (cbReq->width + vloat->size.width, - vloat->generatingBlock->getLineBreakWidth ()); - - if (vloat->generatingBlock == container) { - x = calcFloatX (vloat, side, 0, effWidth); - y = vloat->yReal; - } else { - Allocation *gba = getAllocation(vloat->generatingBlock); - x = calcFloatX (vloat, side, gba->x - containerAllocation.x, - effWidth); - y = gba->y - containerAllocation.y + vloat->yReal; - } - - *width = max (*width, x + vloat->size.width); - *height = max (*height, y + vloat->size.ascent + vloat->size.descent); - - DBG_OBJ_MSGF ("resize.oofm", 1, - "considering float %p generated by %p: (%d + %d) * " - "(%d + (%d + %d)) => %d * %d", - vloat->getWidget (), vloat->generatingBlock, - x, vloat->size.width, - y, vloat->size.ascent, vloat->size.descent, - *width, *height); - } else - DBG_OBJ_MSGF ("resize.oofm", 1, - "considering float %p generated by %p: not allocated", - vloat->getWidget (), vloat->generatingBlock); + ensureFloatSize (vloat); + + int effWidth; + if (container->mustBeWidenedToAvailWidth ()) + // 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.) + effWidth = vloat->generatingBlock->getLineBreakWidth (); + 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. + effWidth = min (cbReq->width + vloat->size.width, + vloat->generatingBlock->getLineBreakWidth ()); + + *width = max (*width, + calcFloatX (vloat, side, 0, effWidth) + + vloat->size.width); + *height = max (*height, + vloat->yReal + + vloat->size.ascent + vloat->size.descent); } DBG_OBJ_LEAVE (); @@ -1406,34 +1182,33 @@ OOFFloatsMgr::TBInfo *OOFFloatsMgr::getOOFAwareWidget (OOFAwareWidget *widget) return tbInfo; } -int OOFFloatsMgr::getLeftBorder (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex) +int OOFFloatsMgr::getLeftBorder (int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex) { - int b = getBorder (textblock, LEFT, y, h, lastGB, lastExtIndex); - DBG_OBJ_MSGF ("border", 0, "left border (%p, %d, %d, %p, %d) => %d", - textblock, y, h, lastGB, lastExtIndex, b); + int b = getBorder (LEFT, y, h, lastGB, lastExtIndex); + DBG_OBJ_MSGF ("border", 0, "left border (%d, %d, %p, %d) => %d", + y, h, lastGB, lastExtIndex, b); return b; } -int OOFFloatsMgr::getRightBorder (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex) +int OOFFloatsMgr::getRightBorder (int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex) { - int b = getBorder (textblock, RIGHT, y, h, lastGB, lastExtIndex); - DBG_OBJ_MSGF ("border", 0, "right border (%p, %d, %d, %p, %d) => %d", - textblock, y, h, lastGB, lastExtIndex, b); + int b = getBorder (RIGHT, y, h, lastGB, lastExtIndex); + DBG_OBJ_MSGF ("border", 0, "right border (%d, %d, %p, %d) => %d", + y, h, lastGB, lastExtIndex, b); return b; } -int OOFFloatsMgr::getBorder (OOFAwareWidget *textblock, Side side, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex) +int OOFFloatsMgr::getBorder (Side side, int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex) { - DBG_OBJ_ENTER ("border", 0, "getBorder", "%p, %s, %d, %d, %p, %d", - textblock, side == LEFT ? "LEFT" : "RIGHT", y, h, - lastGB, lastExtIndex); + DBG_OBJ_ENTER ("border", 0, "getBorder", "%s, %d, %d, %p, %d", + side == LEFT ? "LEFT" : "RIGHT", y, h, lastGB, lastExtIndex); SortedFloatsVector *list = side == LEFT ? leftFloats : rightFloats; int last; - int first = list->findFirst (textblock, y, h, lastGB, lastExtIndex, &last); + int first = list->findFirst (y, h, lastGB, lastExtIndex, &last); DBG_OBJ_MSGF ("border", 1, "first = %d", first); @@ -1452,41 +1227,17 @@ int OOFFloatsMgr::getBorder (OOFAwareWidget *textblock, Side side, int y, int h, // float defined by lastGB and lastExtIndex. for (int i = first; covers && i <= last; i++) { Float *vloat = list->get(i); - covers = vloat->covers (textblock, y, h); + covers = vloat->covers (y, h); DBG_OBJ_MSGF ("border", 1, "float %d (%p) covers? %s.", i, vloat->getWidget(), covers ? "<b>yes</b>" : "no"); if (covers) { - int thisBorder; - if (vloat->generatingBlock == textblock) { - int borderIn = side == LEFT ? - vloat->generatingBlock->boxOffsetX() : - vloat->generatingBlock->boxRestWidth(); - thisBorder = vloat->size.width + borderIn; - DBG_OBJ_MSGF ("border", 1, "GB: thisBorder = %d + %d = %d", - vloat->size.width, borderIn, thisBorder); - } else { - assert (wasAllocated (vloat->generatingBlock)); - assert (vloat->getWidget()->wasAllocated ()); - - Allocation *tba = getAllocation(textblock), - *fla = vloat->getWidget()->getAllocation (); - if (side == LEFT) { - thisBorder = fla->x + fla->width - tba->x; - DBG_OBJ_MSGF ("border", 1, - "not GB: thisBorder = %d + %d - %d = %d", - fla->x, fla->width, tba->x, thisBorder); - } else { - // See also calcFloatX. - thisBorder = - tba->x + textblock->getLineBreakWidth () - fla->x; - DBG_OBJ_MSGF ("border", 1, - "not GB: thisBorder = %d + %d - %d " - "= %d", - tba->x, textblock->getLineBreakWidth (), fla->x, - thisBorder); - } - } + int borderIn = side == LEFT ? + vloat->generatingBlock->boxOffsetX() : + vloat->generatingBlock->boxRestWidth(); + int thisBorder = vloat->size.width + borderIn; + DBG_OBJ_MSGF ("border", 1, "GB: thisBorder = %d + %d = %d", + vloat->size.width, borderIn, thisBorder); border = max (border, thisBorder); DBG_OBJ_MSGF ("border", 1, "=> border = %d", border); @@ -1498,85 +1249,65 @@ int OOFFloatsMgr::getBorder (OOFAwareWidget *textblock, Side side, int y, int h, } } -bool OOFFloatsMgr::hasFloatLeft (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex) +bool OOFFloatsMgr::hasFloatLeft (int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex) { - bool b = hasFloat (textblock, LEFT, y, h, lastGB, lastExtIndex); - DBG_OBJ_MSGF ("border", 0, "has float left (%p, %d, %d, %p, %d) => %s", - textblock, y, h, lastGB, lastExtIndex, b ? "true" : "false"); + bool b = hasFloat (LEFT, y, h, lastGB, lastExtIndex); + DBG_OBJ_MSGF ("border", 0, "has float left (%d, %d, %p, %d) => %s", + y, h, lastGB, lastExtIndex, b ? "true" : "false"); return b; } -bool OOFFloatsMgr::hasFloatRight (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex) +bool OOFFloatsMgr::hasFloatRight (int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex) { - bool b = hasFloat (textblock, RIGHT, y, h, lastGB, lastExtIndex); - DBG_OBJ_MSGF ("border", 0, "has float right (%p, %d, %d, %p, %d) => %s", - textblock, y, h, lastGB, lastExtIndex, b ? "true" : "false"); + bool b = hasFloat (RIGHT, y, h, lastGB, lastExtIndex); + DBG_OBJ_MSGF ("border", 0, "has float right (%d, %d, %p, %d) => %s", + y, h, lastGB, lastExtIndex, b ? "true" : "false"); return b; } -bool OOFFloatsMgr::hasFloat (OOFAwareWidget *textblock, Side side, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex) +bool OOFFloatsMgr::hasFloat (Side side, int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex) { - DBG_OBJ_ENTER ("border", 0, "hasFloat", "%p, %s, %d, %d, %p, %d", - textblock, side == LEFT ? "LEFT" : "RIGHT", y, h, - lastGB, lastExtIndex); + DBG_OBJ_ENTER ("border", 0, "hasFloat", "%s, %d, %d, %p, %d", + side == LEFT ? "LEFT" : "RIGHT", y, h, lastGB, lastExtIndex); SortedFloatsVector *list = side == LEFT ? leftFloats : rightFloats; - int first = list->findFirst (textblock, y, h, lastGB, lastExtIndex, NULL); + int first = list->findFirst (y, h, lastGB, lastExtIndex, NULL); DBG_OBJ_MSGF ("border", 1, "first = %d", first); DBG_OBJ_LEAVE (); return first != -1; } -int OOFFloatsMgr::getLeftFloatHeight (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex) +int OOFFloatsMgr::getLeftFloatHeight (int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex) { - return getFloatHeight (textblock, LEFT, y, h, lastGB, lastExtIndex); + return getFloatHeight (LEFT, y, h, lastGB, lastExtIndex); } -int OOFFloatsMgr::getRightFloatHeight (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex) +int OOFFloatsMgr::getRightFloatHeight (int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex) { - return getFloatHeight (textblock, RIGHT, y, h, lastGB, lastExtIndex); + return getFloatHeight (RIGHT, y, h, lastGB, lastExtIndex); } -int OOFFloatsMgr::getFloatHeight (OOFAwareWidget *textblock, Side side, int y, - int h, OOFAwareWidget *lastGB, - int lastExtIndex) +int OOFFloatsMgr::getFloatHeight (Side side, int y, int h, + OOFAwareWidget *lastGB, int lastExtIndex) { - DBG_OBJ_ENTER ("border", 0, "getFloatHeight", "%p, %s, %d, %d, %p, %d", - textblock, side == LEFT ? "LEFT" : "RIGHT", y, h, - lastGB, lastExtIndex); + DBG_OBJ_ENTER ("border", 0, "getFloatHeight", "%s, %d, %d, %p, %d", + side == LEFT ? "LEFT" : "RIGHT", y, h, lastGB, lastExtIndex); SortedFloatsVector *list = side == LEFT ? leftFloats : rightFloats; - int first = list->findFirst (textblock, y, h, lastGB, lastExtIndex, NULL); + int first = list->findFirst (y, h, lastGB, lastExtIndex, NULL); assert (first != -1); /* This method must not be called when there is no float on the respective side. */ - Float *vloat = list->get(first); - int yRelToFloat; - - if (vloat->generatingBlock == textblock) { - yRelToFloat = y - vloat->yReal; - DBG_OBJ_MSGF ("border", 1, "caller is CB: yRelToFloat = %d - %d = %d", - y, vloat->yReal, yRelToFloat); - } else { - // The respective widgets are allocated; otherwise, hasFloat() would have - // returned false. - assert (wasAllocated (textblock)); - assert (vloat->getWidget()->wasAllocated ()); - - Allocation *tba = getAllocation(textblock), - *fla = vloat->getWidget()->getAllocation (); - yRelToFloat = tba->y + y - fla->y; - - DBG_OBJ_MSGF ("border", 1, - "caller is not CB: yRelToFloat = %d + %d - %d = %d", - tba->y, y, fla->y, yRelToFloat); - } + Float *vloat = list->get (first); + int yRelToFloat = y - vloat->yReal; + DBG_OBJ_MSGF ("border", 1, "caller is CB: yRelToFloat = %d - %d = %d", + y, vloat->yReal, yRelToFloat); ensureFloatSize (vloat); int height = vloat->size.ascent + vloat->size.descent - yRelToFloat; @@ -1639,6 +1370,10 @@ bool OOFFloatsMgr::mayAffectBordersAtAll () int OOFFloatsMgr::calcClearPosition (OOFAwareWidget *textblock, Side side) { + // TODO (SRDOP) Implementation + return 0; + +#if 0 DBG_OBJ_ENTER ("resize.oofm", 0, "getClearPosition", "%p, %s", textblock, side == LEFT ? "LEFT" : "RIGHT"); @@ -1682,6 +1417,7 @@ int OOFFloatsMgr::calcClearPosition (OOFAwareWidget *textblock, Side side) DBG_OBJ_LEAVE (); return pos; +#endif } void OOFFloatsMgr::ensureFloatSize (Float *vloat) diff --git a/dw/ooffloatsmgr.hh b/dw/ooffloatsmgr.hh index 583c044b..40e0cdc4 100644 --- a/dw/ooffloatsmgr.hh +++ b/dw/ooffloatsmgr.hh @@ -1,7 +1,6 @@ #ifndef __DW_OOFFLOATSMGR_HH__ #define __DW_OOFFLOATSMGR_HH__ - #include "outofflowmgr.hh" namespace dw { @@ -23,6 +22,7 @@ private: enum Side { LEFT, RIGHT }; OOFAwareWidget *container; + int oofmIndex; // These two values are redundant to TBInfo::wasAllocated and // TBInfo::allocation, for some special cases. @@ -49,20 +49,14 @@ private: public: class ComparePosition: public lout::object::Comparator { - private: - OOFFloatsMgr *oofm; - OOFAwareWidget *refTB; - public: - ComparePosition (OOFFloatsMgr *oofm, OOFAwareWidget *refTB) - { this->oofm = oofm; this->refTB = refTB; } - int compare(Object *o1, Object *o2); + int compare (Object *o1, Object *o2); }; class CompareSideSpanningIndex: public lout::object::Comparator { public: - int compare(Object *o1, Object *o2); + int compare (Object *o1, Object *o2); }; class CompareGBAndExtIndex: public lout::object::Comparator @@ -79,7 +73,7 @@ private: OOFAwareWidget *generatingBlock; int externalIndex; int index; // TODO Needed after SRDOP? - int yReq, yReal; // relative to generator, not container + int yReq, yReal; // relative to container int sideSpanningIndex; core::Requisition size; bool dirty, sizeChangedSinceLastAllocation; @@ -98,7 +92,7 @@ private: void intoStringBuffer(lout::misc::StringBuffer *sb); - bool covers (OOFAwareWidget *textblock, int y, int h); + bool covers (int y, int h); }; /** @@ -125,9 +119,9 @@ private: { this->oofm = oofm; this->side = side; } int findFloatIndex (OOFAwareWidget *lastGB, int lastExtIndex); - int find (OOFAwareWidget *textblock, int y, int start, int end); - int findFirst (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex, int *lastReturn); + int find (int y, int start, int end); + int findFirst (int y, int h, OOFAwareWidget *lastGB, int lastExtIndex, + int *lastReturn); int findLastBeforeSideSpanningIndex (int sideSpanningIndex); void put (Float *vloat); @@ -169,15 +163,15 @@ private: ~TBInfo (); inline bool isNowAllocated () { - return getOOFFloatsMgr()->wasAllocated (getOOFAwareWidget ()); } + return getOOFFloatsMgr()->wasAllocated (getOOFAwareWidget()); } inline int getNewXCB () { - return getOOFFloatsMgr()->getAllocation (getOOFAwareWidget ())->x - + return getOOFFloatsMgr()->getAllocation (getOOFAwareWidget())->x - getOOFFloatsMgr()->containerAllocation.x; } inline int getNewYCB () { - return getOOFFloatsMgr()->getAllocation (getOOFAwareWidget ())->y - + return getOOFFloatsMgr()->getAllocation (getOOFAwareWidget())->y - getOOFFloatsMgr()->containerAllocation.y; } inline int getNewWidth () { - return getOOFFloatsMgr()->getAllocation (getOOFAwareWidget ())->width; } + return getOOFFloatsMgr()->getAllocation (getOOFAwareWidget())->width; } inline int getNewHeight () { core::Allocation *allocation = getOOFFloatsMgr()->getAllocation (getOOFAwareWidget ()); @@ -245,13 +239,13 @@ private: TBInfo *getOOFAwareWidgetWhenRegistered (OOFAwareWidget *widget); inline bool isOOFAwareWidgetRegistered (OOFAwareWidget *widget) { return getOOFAwareWidgetWhenRegistered (widget) != NULL; } - int getBorder (OOFAwareWidget *textblock, Side side, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); - bool hasFloat (OOFAwareWidget *textblock, Side side, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); - int getFloatHeight (OOFAwareWidget *textblock, Side side, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); + int getBorder (Side side, int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex); + bool hasFloat (Side side, int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex); + int getFloatHeight (Side side, int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex); int calcClearPosition (OOFAwareWidget *textblock); int calcClearPosition (OOFAwareWidget *textblock, Side side); @@ -271,7 +265,7 @@ private: { return ref == -1 ? ref : (ref >> 1); } public: - OOFFloatsMgr (OOFAwareWidget *container); + OOFFloatsMgr (OOFAwareWidget *container, int oofmIndex); ~OOFFloatsMgr (); void sizeAllocateStart (OOFAwareWidget *caller, @@ -306,20 +300,16 @@ public: void getExtremes (core::Extremes *cbExtr, int *oofMinWidth, int *oofMaxWidth); - int getLeftBorder (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); - int getRightBorder (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); + int getLeftBorder (int y, int h, OOFAwareWidget *lastGB, int lastExtIndex); + int getRightBorder (int y, int h, OOFAwareWidget *lastGB, int lastExtIndex); - bool hasFloatLeft (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); - bool hasFloatRight (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); + bool hasFloatLeft (int y, int h, OOFAwareWidget *lastGB, int lastExtIndex); + bool hasFloatRight (int y, int h, OOFAwareWidget *lastGB, int lastExtIndex); - int getLeftFloatHeight (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); - int getRightFloatHeight (OOFAwareWidget *textblock, int y, int h, - OOFAwareWidget *lastGB, int lastExtIndex); + int getLeftFloatHeight (int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex); + int getRightFloatHeight (int y, int h, OOFAwareWidget *lastGB, + int lastExtIndex); bool affectsLeftBorder (core::Widget *widget); bool affectsRightBorder (core::Widget *widget); diff --git a/dw/oofpositionedmgr.cc b/dw/oofpositionedmgr.cc index 1ab7e06e..fb83cf15 100644 --- a/dw/oofpositionedmgr.cc +++ b/dw/oofpositionedmgr.cc @@ -287,39 +287,38 @@ bool OOFPositionedMgr::containerMustAdjustExtraSpace () return true; } -int OOFPositionedMgr::getLeftBorder (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) +int OOFPositionedMgr::getLeftBorder (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) { return 0; } -int OOFPositionedMgr::getRightBorder (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) +int OOFPositionedMgr::getRightBorder (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) { return 0; } -bool OOFPositionedMgr::hasFloatLeft (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) +bool OOFPositionedMgr::hasFloatLeft (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) { return false; } -bool OOFPositionedMgr::hasFloatRight (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) +bool OOFPositionedMgr::hasFloatRight (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) { return false; } -int OOFPositionedMgr::getLeftFloatHeight (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, +int OOFPositionedMgr::getLeftFloatHeight (int y, int h, OOFAwareWidget *lastGen, int lastExtIndex) { return 0; } -int OOFPositionedMgr::getRightFloatHeight (OOFAwareWidget *widget, int y, int h, +int OOFPositionedMgr::getRightFloatHeight (int y, int h, OOFAwareWidget *lastGen, int lastExtIndex) { diff --git a/dw/oofpositionedmgr.hh b/dw/oofpositionedmgr.hh index 09706235..f8ea0a3c 100644 --- a/dw/oofpositionedmgr.hh +++ b/dw/oofpositionedmgr.hh @@ -109,20 +109,16 @@ public: bool containerMustAdjustExtraSpace (); - int getLeftBorder (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex); - int getRightBorder (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex); - - bool hasFloatLeft (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex); - bool hasFloatRight (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex); - - int getLeftFloatHeight (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex); - int getRightFloatHeight (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex); + int getLeftBorder (int y, int h, OOFAwareWidget *lastGen, int lastExtIndex); + int getRightBorder (int y, int h, OOFAwareWidget *lastGen, int lastExtIndex); + + bool hasFloatLeft (int y, int h, OOFAwareWidget *lastGen, int lastExtIndex); + bool hasFloatRight (int y, int h, OOFAwareWidget *lastGen, int lastExtIndex); + + int getLeftFloatHeight (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex); + int getRightFloatHeight (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex); int getClearPosition (OOFAwareWidget *widget); diff --git a/dw/outofflowmgr.hh b/dw/outofflowmgr.hh index 88ec349d..5ded99d5 100644 --- a/dw/outofflowmgr.hh +++ b/dw/outofflowmgr.hh @@ -77,8 +77,8 @@ public: * but is 0 if there is no float, so a caller should also consider * other borders. */ - virtual int getLeftBorder (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) = 0; + virtual int getLeftBorder (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) = 0; /** * Get the right border for the vertical position of *y*, for a height @@ -86,8 +86,8 @@ public: * * See also getLeftBorder(). */ - virtual int getRightBorder (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) = 0; + virtual int getRightBorder (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) = 0; /** * Return whether there is a float on the left side. *y* is @@ -95,8 +95,8 @@ public: * * See also getLeftBorder(). */ - virtual bool hasFloatLeft (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) = 0; + virtual bool hasFloatLeft (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) = 0; /** * Return whether there is a float on the right side. *y* is @@ -104,8 +104,8 @@ public: * * See also hasFloatLeft(), getLeftBorder(); */ - virtual bool hasFloatRight (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) = 0; + virtual bool hasFloatRight (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) = 0; /** * Assuming there is a float on the left side, return the rest @@ -113,9 +113,8 @@ public: * * See also getLeftBorder(). */ - virtual int getLeftFloatHeight (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) - = 0; + virtual int getLeftFloatHeight (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) = 0; /** * Assuming there is a float on the right side, return the rest @@ -123,9 +122,8 @@ public: * * See also getLeftFloatHeight(), getLeftBorder(). */ - virtual int getRightFloatHeight (OOFAwareWidget *widget, int y, int h, - OOFAwareWidget *lastGen, int lastExtIndex) - = 0; + virtual int getRightFloatHeight (int y, int h, OOFAwareWidget *lastGen, + int lastExtIndex) = 0; virtual bool affectsLeftBorder (core::Widget *widget) = 0; virtual bool affectsRightBorder (core::Widget *widget) = 0; diff --git a/dw/textblock.cc b/dw/textblock.cc index 7dea2048..e66ab66a 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -2998,152 +2998,152 @@ bool Textblock::mustBeWidenedToAvailWidth () return result; } -/** - * Called by dw::OOFFloatsMgr when the border has changed due to a - * float (or some floats). - * - * "y", which given in widget coordinates, denotes the minimal - * position (when more than one float caused this), "vloat" the - * floating widget belonging to "y". - */ -void Textblock::borderChanged (int y, Widget *vloat) -{ - DBG_OBJ_ENTER ("resize", 0, "borderChanged", "%d, %p", y, vloat); - - int lineIndex = findLineIndex (y); - DBG_OBJ_MSGF ("resize", 1, "Line index: %d (of %d).", - lineIndex, lines->size ()); - - // Nothing to do at all, when lineIndex >= lines->size (), - // i. e. the change is below the bottom of this widget. - if (lineIndex < lines->size ()) { - int wrapLineIndex; - if (lineIndex < 0) - // Rewrap all. - wrapLineIndex = 0; - else - wrapLineIndex = lineIndex; - - int realWrapLineIndex = wrapLineIndex; - // The following two variables are only used for debugging: - int minWrapLineIndex = wrapLineIndex, maxWrapLineIndex = wrapLineIndex; - - if (vloat->getGenerator() == this && lines->size () > 0) { - bool found = false; - // Sometimes, the respective word is not yet part of a - // line. Nothing to do, but because of the assertion below - // (and also for performace reasons) this should be - // considered. TODO: Integrate this below. - for (int wordIndex = - lines->size() > 0 ? lines->getLastRef()->lastWord + 1 : 0; - !found && wordIndex < words->size(); wordIndex++) { - Word *word = words->getRef (wordIndex); - if (word->content.type == core::Content::WIDGET_OOF_REF && - word->content.widget == vloat) - found = true; - } - - // We search for the line of the float reference. There are - // two cases when this is not the line corresponsing to y: - // - // (1) When the float was moved down, due to collisions with - // other floats: in this case, the line number gets - // smaller (since the float reference is before). - // - // (2) In some cases, the line number may become larger, due - // to the per-line optimization of the words: initially, - // lines->size() - 1 is assigned, but it may happen that - // the float reference is put into another line. - // - // Only in the first case, a correction is neccessary, but a - // test for the second case is useful. (TODO: I've forgotten - // why a correction is neccessary.) - // - // Searched is done in the following order: - // - // - wrapLineIndex, - // - wrapLineIndex - 1, - // - wrapLineIndex + 1, - // - wrapLineIndex - 2, - // - wrapLineIndex + 2, - // - // etc. until either the float reference has been found or - // all lines have been searched (the latter triggers an - // abortion). - - bool exceedsBeginning = false, exceedsEnd = false; - for (int i = 0; !found; i++) { - bool exceeds; - int lineIndex2; - if (i % 2 == 0) { - // even: +0, +1, +2, ... - lineIndex2 = realWrapLineIndex + i / 2; - if (i > 0) - exceeds = exceedsEnd = lineIndex2 >= lines->size (); - else - exceeds = exceedsEnd = false; - } else { - // odd: -1, -2, ... - lineIndex2 = realWrapLineIndex - (i + 1) / 2; - exceeds = exceedsBeginning = lineIndex2 < 0; +void Textblock::borderChanged (int oofmIndex, int y, Widget *widgetOOF) +{ + DBG_OBJ_ENTER ("resize", 0, "borderChanged", "%s, %d, %p", + OOFM_NAME[oofmIndex], y, widgetOOF); + + // Calculate the widget coordinate of `y`. Since this method is only called + // for floats, `findSizeRequestReference` returning `false` means than + // `sizeRequest` has not been called yet, so queuing is not necessary. + int yRef; + if (findSizeRequestReference (oofmIndex, NULL, &yRef)) { + int yWidget = y - yRef; + int lineIndex = findLineIndex (yWidget); + DBG_OBJ_MSGF ("resize", 1, "Line index: %d (of %d).", + lineIndex, lines->size ()); + + // Nothing to do at all, when lineIndex >= lines->size (), + // i. e. the change is below the bottom of this widget. + if (lineIndex < lines->size ()) { + int wrapLineIndex; + if (lineIndex < 0) + // Rewrap all. + wrapLineIndex = 0; + else + wrapLineIndex = lineIndex; + + int realWrapLineIndex = wrapLineIndex; + // The following two variables are only used for debugging: + int minWrapLineIndex = wrapLineIndex, maxWrapLineIndex = wrapLineIndex; + + if (widgetOOF->getGenerator() == this && lines->size () > 0) { + bool found = false; + // Sometimes, the respective word is not yet part of a + // line. Nothing to do, but because of the assertion below + // (and also for performace reasons) this should be + // considered. TODO: Integrate this below. + for (int wordIndex = + lines->size() > 0 ? lines->getLastRef()->lastWord + 1 : 0; + !found && wordIndex < words->size(); wordIndex++) { + Word *word = words->getRef (wordIndex); + if (word->content.type == core::Content::WIDGET_OOF_REF && + word->content.widget == widgetOOF) + found = true; } - DBG_OBJ_MSGF ("resize", 2, - "lineIndex2 = %d (of %d), exceeds = %s, " - "exceedsBeginning = %s, exceedsEnd = %s", - lineIndex2, lines->size (), - exceeds ? "true" : "false", - exceedsBeginning ? "true" : "false", - exceedsEnd ? "true" : "false"); + // We search for the line of the float reference. There are + // two cases when this is not the line corresponsing to y: + // + // (1) When the float was moved down, due to collisions with + // other floats: in this case, the line number gets + // smaller (since the float reference is before). + // + // (2) In some cases, the line number may become larger, due + // to the per-line optimization of the words: initially, + // lines->size() - 1 is assigned, but it may happen that + // the float reference is put into another line. + // + // Only in the first case, a correction is neccessary, but a + // test for the second case is useful. (TODO: I've forgotten + // why a correction is neccessary.) + // + // Searched is done in the following order: + // + // - wrapLineIndex, + // - wrapLineIndex - 1, + // - wrapLineIndex + 1, + // - wrapLineIndex - 2, + // - wrapLineIndex + 2, + // + // etc. until either the float reference has been found or + // all lines have been searched (the latter triggers an + // abortion). + + bool exceedsBeginning = false, exceedsEnd = false; + for (int i = 0; !found; i++) { + bool exceeds; + int lineIndex2; + if (i % 2 == 0) { + // even: +0, +1, +2, ... + lineIndex2 = realWrapLineIndex + i / 2; + if (i > 0) + exceeds = exceedsEnd = lineIndex2 >= lines->size (); + else + exceeds = exceedsEnd = false; + } else { + // odd: -1, -2, ... + lineIndex2 = realWrapLineIndex - (i + 1) / 2; + exceeds = exceedsBeginning = lineIndex2 < 0; + } - if (exceedsBeginning && exceedsEnd) - break; + DBG_OBJ_MSGF ("resize", 2, + "lineIndex2 = %d (of %d), exceeds = %s, " + "exceedsBeginning = %s, exceedsEnd = %s", + lineIndex2, lines->size (), + exceeds ? "true" : "false", + exceedsBeginning ? "true" : "false", + exceedsEnd ? "true" : "false"); + + if (exceedsBeginning && exceedsEnd) + break; - if (!exceeds) { - Line *line = lines->getRef (lineIndex2); - for (int wordIndex = line->firstWord; - !found && wordIndex <= line->lastWord; wordIndex++) { - Word *word = words->getRef (wordIndex); - if (word->content.type == core::Content::WIDGET_OOF_REF && - word->content.widget == vloat) { - found = true; - // Correct only by smaller values (case (1) above): - realWrapLineIndex = - misc::min (realWrapLineIndex, lineIndex2); + if (!exceeds) { + Line *line = lines->getRef (lineIndex2); + for (int wordIndex = line->firstWord; + !found && wordIndex <= line->lastWord; wordIndex++) { + Word *word = words->getRef (wordIndex); + if (word->content.type == core::Content::WIDGET_OOF_REF && + word->content.widget == widgetOOF) { + found = true; + // Correct only by smaller values (case (1) above): + realWrapLineIndex = + misc::min (realWrapLineIndex, lineIndex2); + } } - } - minWrapLineIndex = misc::min (minWrapLineIndex, lineIndex2); - maxWrapLineIndex = misc::max (maxWrapLineIndex, lineIndex2); + minWrapLineIndex = misc::min (minWrapLineIndex, lineIndex2); + maxWrapLineIndex = misc::max (maxWrapLineIndex, lineIndex2); + } } - } - assert (found); - } - - DBG_OBJ_MSGF ("resize", 1, - "wrapLineIndex: corrected from %d to %d (%d lines total); " - "searched between %d and %d; this is the GB: %s", - wrapLineIndex, realWrapLineIndex, lines->size (), - minWrapLineIndex, maxWrapLineIndex, - vloat->getGenerator() == this ? "yes" : "no"); + assert (found); + } - queueResize (makeParentRefInFlow (realWrapLineIndex), true); + DBG_OBJ_MSGF ("resize", 1, + "wrapLineIndex: corrected from %d to %d (%d lines " + "total); searched between %d and %d; this is the GB: %s", + wrapLineIndex, realWrapLineIndex, lines->size (), + minWrapLineIndex, maxWrapLineIndex, + widgetOOF->getGenerator() == this ? "yes" : "no"); - // Notice that the line no. realWrapLineIndex may not exist yet. - if (realWrapLineIndex == 0) - lastWordDrawn = misc::min (lastWordDrawn, -1); - else - lastWordDrawn = - misc::min (lastWordDrawn, - lines->getRef(realWrapLineIndex - 1)->lastWord); - DBG_OBJ_SET_NUM ("lastWordDrawn", lastWordDrawn); + queueResize (makeParentRefInFlow (realWrapLineIndex), true); - // TODO Is the following necessary? Or even useless? - //redrawY = - // misc::min (redrawY, - // lineYOffsetWidget (lines->getRef (realWrapLineIndex))); - //DBG_OBJ_SET_NUM ("redrawY", redrawY); + // Notice that the line no. realWrapLineIndex may not exist yet. + if (realWrapLineIndex == 0) + lastWordDrawn = misc::min (lastWordDrawn, -1); + else + lastWordDrawn = + misc::min (lastWordDrawn, + lines->getRef(realWrapLineIndex - 1)->lastWord); + DBG_OBJ_SET_NUM ("lastWordDrawn", lastWordDrawn); + + // TODO Is the following necessary? Or even useless? + //redrawY = + // misc::min (redrawY, + // lineYOffsetWidget (lines->getRef (realWrapLineIndex))); + //DBG_OBJ_SET_NUM ("redrawY", redrawY); + } } DBG_OBJ_LEAVE (); diff --git a/dw/textblock.hh b/dw/textblock.hh index ddab6bca..106f65ba 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -904,7 +904,7 @@ public: bool includeFirstSpace, bool includeLastSpace); bool mustBeWidenedToAvailWidth (); - void borderChanged (int y, core::Widget *vloat); + void borderChanged (int oofmIndex, int y, core::Widget *widgetOOF); void widgetRefSizeChanged (int externalIndex); void clearPositionChanged (); void oofSizeChanged (bool extremesChanged); diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 03933830..81e60a71 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -2070,20 +2070,17 @@ void Textblock::calcBorders (int lastOofRef, int height) int y = yRef + yRel; bool thisHasLeft, thisHasRight; - thisHasLeft = oofm->hasFloatLeft (this, y, height, this, effOofRef); + thisHasLeft = oofm->hasFloatLeft (y, height, this, effOofRef); newLineHasFloatLeft = newLineHasFloatLeft || thisHasLeft; - thisHasRight = oofm->hasFloatRight (this, y, height, this, - effOofRef); + thisHasRight = oofm->hasFloatRight (y, height, this, effOofRef); newLineHasFloatRight = newLineHasFloatRight || thisHasRight; newLineLeftBorder = misc::max (newLineLeftBorder, - oofm->getLeftBorder (this, y, height, this, - effOofRef)); + oofm->getLeftBorder (y, height, this, effOofRef)); newLineRightBorder = misc::max (newLineRightBorder, - oofm->getRightBorder (this, y, height, this, - effOofRef)); + oofm->getRightBorder (y, height, this, effOofRef)); // TODO "max" is not really correct for the heights. (Does // not matter, since only one, the float manager, returns @@ -2091,12 +2088,12 @@ void Textblock::calcBorders (int lastOofRef, int height) if (thisHasLeft) newLineLeftFloatHeight = misc::max (newLineLeftFloatHeight, - oofm->getLeftFloatHeight (this, y, height, this, + oofm->getLeftFloatHeight (y, height, this, effOofRef)); if (thisHasRight) newLineRightFloatHeight = misc::max (newLineRightFloatHeight, - oofm->getRightFloatHeight (this, y, height, this, + oofm->getRightFloatHeight (y, height, this, effOofRef)); DBG_OBJ_MSGF ("construct.line", 1, |