diff options
author | Sebastian Geerken <devnull@localhost> | 2016-04-03 13:57:49 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2016-04-03 13:57:49 +0200 |
commit | ac5f6eb878e615789029fd5cd36fb9d65c78277c (patch) | |
tree | cf342d71590857230a2b726c29a30c268facd830 | |
parent | c242567805390620f4c47d17af68bb81b715efa2 (diff) |
Replace OOFAwareWidget::borderChanged by OOFAwareWidget::updateReference.
-rw-r--r-- | dw/oofawarewidget.cc | 4 | ||||
-rw-r--r-- | dw/oofawarewidget.hh | 10 | ||||
-rw-r--r-- | dw/ooffloatsmgr.cc | 17 | ||||
-rw-r--r-- | dw/textblock.cc | 150 | ||||
-rw-r--r-- | dw/textblock.hh | 4 |
5 files changed, 19 insertions, 166 deletions
diff --git a/dw/oofawarewidget.cc b/dw/oofawarewidget.cc index 6912108a..f33df546 100644 --- a/dw/oofawarewidget.cc +++ b/dw/oofawarewidget.cc @@ -545,9 +545,9 @@ void OOFAwareWidget::removeChild (Widget *child) assert (isWidgetOOF (child)); } -void OOFAwareWidget::borderChanged (int oofmIndex, int y, Widget *widgetOOF) +void OOFAwareWidget::updateReference (int ref) { - notImplemented ("OOFAwareWidget::borderChanged"); + notImplemented ("OOFAwareWidget::updateReference"); } void OOFAwareWidget::widgetRefSizeChanged (int externalIndex) diff --git a/dw/oofawarewidget.hh b/dw/oofawarewidget.hh index 2c33d386..9d5fa38a 100644 --- a/dw/oofawarewidget.hh +++ b/dw/oofawarewidget.hh @@ -249,15 +249,9 @@ public: core::DrawingContext *context); /** - * 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 updateReference (int ref); /** * Called by an implementation of dw::oof::OutOfFlowMgr (actually only diff --git a/dw/ooffloatsmgr.cc b/dw/ooffloatsmgr.cc index 5c704ee9..0f9a6faa 100644 --- a/dw/ooffloatsmgr.cc +++ b/dw/ooffloatsmgr.cc @@ -647,15 +647,22 @@ void OOFFloatsMgr::markSizeChange (int ref) vloat->dirty = true; DBG_OBJ_SET_BOOL_O (vloat->getWidget (), "<Float>.dirty", vloat->dirty); + assert (vloat->getWidget()->getWidgetReference() != NULL); + int first = findTBInfo (vloat->yReal); // The determination of the last element could perhaps be optimized, but we // do not yet know the *new* height of the float. int last = tbInfos->size () - 1; - for (int i = first; i <= last; i++) { - OOFAwareWidget *oofaw = tbInfos->get(i)->getOOFAwareWidget(); - DBG_OBJ_MSGF ("resize.oofm", 1, "calling borderChanged for %p", oofaw); - oofaw->borderChanged (oofmIndex, vloat->yReal, vloat->getWidget ()); - } + + DBG_OBJ_MSGF ("resize.oofm", 1, "updating from %d to %d", first, last); + + if (first <= last) + tbInfos->get(first)->getOOFAwareWidget() + ->updateReference (vloat->getWidget()->getWidgetReference() + ->parentRef); + + for (int i = first + 1; i <= last; i++) + tbInfos->get(first)->getOOFAwareWidget()->updateReference(0); DBG_OBJ_LEAVE (); } diff --git a/dw/textblock.cc b/dw/textblock.cc index f4a53f7f..f0bdf72a 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -2988,155 +2988,9 @@ void Textblock::queueDrawRange (int index1, int index2) DBG_OBJ_LEAVE (); } -void Textblock::borderChanged (int oofmIndex, int y, Widget *widgetOOF) +void Textblock::updateReference (int ref) { - 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.widgetReference->widget == widgetOOF) - 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; - } - - 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.widgetReference->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); - } - } - - 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, - widgetOOF->getGenerator() == this ? "yes" : "no"); - - queueResize (makeParentRefInFlow (realWrapLineIndex), true); - - // 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 (); + queueResize (ref, false); } void Textblock::widgetRefSizeChanged (int externalIndex) diff --git a/dw/textblock.hh b/dw/textblock.hh index 2c13e2c8..01f7d9f3 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -764,8 +764,6 @@ protected: RegardingBorder *getWidgetRegardingBorderForLine (int lineNo); RegardingBorder *getWidgetRegardingBorderForLine (int firstWord, int lastWord); - void printBorderChangedErrorAndAbort (int y, Widget *vloat, - int wrapLineIndex); int yOffsetOfLineToBeCreated (int *lastMargin = NULL); int yOffsetOfLineCreated (Line *line); @@ -901,7 +899,7 @@ public: void changeWordStyle (int from, int to, core::style::Style *style, bool includeFirstSpace, bool includeLastSpace); - void borderChanged (int oofmIndex, int y, core::Widget *widgetOOF); + void updateReference (int ref); void widgetRefSizeChanged (int externalIndex); void clearPositionChanged (); void oofSizeChanged (bool extremesChanged); |