diff options
author | Sebastian Geerken <devnull@localhost> | 2014-09-13 00:23:00 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-09-13 00:23:00 +0200 |
commit | acedc140e545b34b46df551d79b4ef90638b36b6 (patch) | |
tree | 34621686c09f45a0df62706531e69ffc3cdc2ef2 /dw/textblock_iterator.cc | |
parent | f543038f3b597c34f67a4ca63efc2bbe59a78b05 (diff) |
OOFAwareWidgetIterator: extended and applied to TextblockIterator.
Diffstat (limited to 'dw/textblock_iterator.cc')
-rw-r--r-- | dw/textblock_iterator.cc | 174 |
1 files changed, 35 insertions, 139 deletions
diff --git a/dw/textblock_iterator.cc b/dw/textblock_iterator.cc index 0e66faed..34a76c08 100644 --- a/dw/textblock_iterator.cc +++ b/dw/textblock_iterator.cc @@ -33,138 +33,35 @@ namespace dw { Textblock::TextblockIterator::TextblockIterator (Textblock *textblock, core::Content::Type mask, bool atEnd): - core::Iterator (textblock, mask, atEnd) + OOFAwareWidgetIterator (textblock, mask, atEnd, textblock->words->size ()) { - if (atEnd) { - sectionIndex = NUM_SECTIONS - 1; - while (sectionIndex >= 0 && numParts (sectionIndex) == 0) - sectionIndex--; - index = numParts (sectionIndex); - } else { - sectionIndex = 0; - index = -1; - } - - content.type = atEnd ? core::Content::END : core::Content::START; -} - -Textblock::TextblockIterator::TextblockIterator (Textblock *textblock, - core::Content::Type mask, - int sectionIndex, int index): - core::Iterator (textblock, mask, false) -{ - this->sectionIndex = sectionIndex; - this->index = index; - - // TODO To be completely exact, sectionIndex should be considered here. - if (index < 0) - content.type = core::Content::START; - else if (index >= textblock->words->size()) - content.type = core::Content::END; - else - content = textblock->words->getRef(index)->content; -} - -int Textblock::TextblockIterator::numParts (int sectionIndex) -{ - Textblock *textblock = (Textblock*)getWidget(); - - if (sectionIndex == 0) - return textblock->words->size (); - else - return textblock->outOfFlowMgr[sectionIndex - 1] ? - textblock->outOfFlowMgr[sectionIndex - 1]->getNumWidgets () : 0; } -void Textblock::TextblockIterator::getPart (int sectionIndex, int index, - core::Content *content) +Textblock::TextblockIterator + *Textblock::TextblockIterator::createWordIndexIterator (Textblock *textblock, + core::Content::Type + mask, + int wordIndex) { - Textblock *textblock = (Textblock*)getWidget(); - - if (sectionIndex == 0) - *content = textblock->words->getRef(index)->content; - else { - content->type = core::Content::WIDGET_OOF_CONT; - content->widget = - textblock->outOfFlowMgr[sectionIndex - 1]->getWidget (index); - } + TextblockIterator *tbIt = new TextblockIterator (textblock, mask, false); + tbIt->setValues (0, wordIndex); + return tbIt; } - object::Object *Textblock::TextblockIterator::clone() { - return new TextblockIterator ((Textblock*)getWidget(), getMask(), - sectionIndex, index); -} - -int Textblock::TextblockIterator::compareTo(object::Comparable *other) -{ - TextblockIterator *otherTI = (TextblockIterator*)other; - - if (sectionIndex != otherTI->sectionIndex) - return sectionIndex - otherTI->sectionIndex; - else - return index - otherTI->index; -} - -bool Textblock::TextblockIterator::next () -{ - if (content.type == core::Content::END) - return false; - - do { - index++; - - if (index >= numParts(sectionIndex)) { - sectionIndex++; - while (sectionIndex < NUM_SECTIONS && numParts(sectionIndex) == 0) - sectionIndex++; - - if (sectionIndex == NUM_SECTIONS) { - content.type = core::Content::END; - return false; - } else - index = 0; - } - - getPart (sectionIndex, index, &content); - } while ((content.type & getMask()) == 0); - - return true; -} - -bool Textblock::TextblockIterator::prev () -{ - if (content.type == core::Content::START) - return false; - - do { - index--; - - if (index < 0) { - sectionIndex--; - while (sectionIndex >= 0 && numParts(sectionIndex) == 0) - sectionIndex--; - - if (sectionIndex < 0) { - content.type = core::Content::START; - return false; - } else - index = numParts(sectionIndex) - 1; - } - - getPart (sectionIndex, index, &content); - } while ((content.type & getMask()) == 0); - - return true; + TextblockIterator *tbIt = + new TextblockIterator ((Textblock*)getWidget(), getMask(), false); + cloneValues (tbIt); + return tbIt; } void Textblock::TextblockIterator::highlight (int start, int end, core::HighlightLayer layer) { - if (sectionIndex == 0) { + if (inFlow ()) { Textblock *textblock = (Textblock*)getWidget(); - int index1 = index, index2 = index; + int index = getInFlowIndex (), index1 = index, index2 = index; int oldStartIndex = textblock->hlStart[layer].index; int oldStartChar = textblock->hlStart[layer].nChar; @@ -194,17 +91,16 @@ void Textblock::TextblockIterator::highlight (int start, int end, oldEndIndex != textblock->hlEnd[layer].index || oldEndChar != textblock->hlEnd[layer].nChar) textblock->queueDrawRange (index1, index2); - } - - // TODO What about OOF widgets? + } else + highlightOOF (start, end, layer); } void Textblock::TextblockIterator::unhighlight (int direction, core::HighlightLayer layer) { - if (sectionIndex == 0) { + if (inFlow ()) { Textblock *textblock = (Textblock*)getWidget(); - int index1 = index, index2 = index; + int index = getInFlowIndex (), index1 = index, index2 = index; if (textblock->hlStart[layer].index > textblock->hlEnd[layer].index) return; @@ -234,23 +130,17 @@ void Textblock::TextblockIterator::unhighlight (int direction, oldEndIndex != textblock->hlEnd[layer].index || oldEndChar != textblock->hlEnd[layer].nChar) textblock->queueDrawRange (index1, index2); - } - - // TODO What about OOF widgets? + } else + unhighlightOOF (direction, layer); } void Textblock::TextblockIterator::getAllocation (int start, int end, core::Allocation *allocation) { - Textblock *textblock = (Textblock*)getWidget(); - - if (sectionIndex > 0) { - // TODO Consider start and end? - *allocation = - *(textblock->outOfFlowMgr[sectionIndex - 1]->getWidget(index) - ->getAllocation()); - } else { - int lineIndex = textblock->findLineOfWord (index); + if (inFlow ()) { + Textblock *textblock = (Textblock*)getWidget(); + int index = getInFlowIndex (), + lineIndex = textblock->findLineOfWord (index); Line *line = textblock->lines->getRef (lineIndex); Word *word = textblock->words->getRef (index); @@ -289,13 +179,19 @@ void Textblock::TextblockIterator::getAllocation (int start, int end, } allocation->ascent = word->size.ascent; allocation->descent = word->size.descent; - } + } else + getAllocationOOF (start, end, allocation); +} + +int Textblock::TextblockIterator::numContentsInFlow () +{ + return ((Textblock*)getWidget())->words->size (); } -void Textblock::TextblockIterator::print () +void Textblock::TextblockIterator::getContentInFlow (int index, + core::Content *content) { - Iterator::print (); - printf (", sectionIndex = %d, index = %d", sectionIndex, index); + *content = ((Textblock*)getWidget())->words->getRef(index)->content; } } // namespace dw |