diff options
-rw-r--r-- | dw/oofawarewidget.hh | 4 | ||||
-rw-r--r-- | dw/table.hh | 11 | ||||
-rw-r--r-- | dw/table_iterator.cc | 115 | ||||
-rw-r--r-- | dw/types.hh | 4 |
4 files changed, 47 insertions, 87 deletions
diff --git a/dw/oofawarewidget.hh b/dw/oofawarewidget.hh index e21124c1..96c83e26 100644 --- a/dw/oofawarewidget.hh +++ b/dw/oofawarewidget.hh @@ -41,6 +41,10 @@ namespace oof { * dw::core::Widget::correctExtremesOfChild? Currently, all widgets * are used the default implementation.) * + * Also, iterators have to consider widgets out of flow; + * dw::oof::OOFAwareWidget::OOFAwareWidgetIterator is recommended as + * base class. + * * For both generators * and containers of floats (which is only implemented by * dw::Textblock) it gets a bit more complicated. diff --git a/dw/table.hh b/dw/table.hh index dffec1be..c47ff465 100644 --- a/dw/table.hh +++ b/dw/table.hh @@ -339,20 +339,17 @@ private: }; }; - class TableIterator: public core::Iterator + class TableIterator: public OOFAwareWidgetIterator { - private: - int index; + protected: + int numContentsInFlow (); + void getContentInFlow (int index, core::Content *content); public: TableIterator (Table *table, core::Content::Type mask, bool atEnd); - TableIterator (Table *table, core::Content::Type mask, int index); lout::object::Object *clone(); - int compareTo(lout::object::Comparable *other); - bool next (); - bool prev (); void highlight (int start, int end, core::HighlightLayer layer); void unhighlight (int direction, core::HighlightLayer layer); void getAllocation (int start, int end, core::Allocation *allocation); diff --git a/dw/table_iterator.cc b/dw/table_iterator.cc index 4da0ef4f..9ba61619 100644 --- a/dw/table_iterator.cc +++ b/dw/table_iterator.cc @@ -28,107 +28,62 @@ namespace dw { Table::TableIterator::TableIterator (Table *table, core::Content::Type mask, bool atEnd): - core::Iterator (table, mask, atEnd) + OOFAwareWidgetIterator (table, mask, atEnd, table->children->size ()) { - index = atEnd ? table->children->size () : -1; - content.type = atEnd ? core::Content::END : core::Content::START; -} - -Table::TableIterator::TableIterator (Table *table, - core::Content::Type mask, int index): - core::Iterator (table, mask, false) -{ - this->index = index; - - if (index < 0) - content.type = core::Content::START; - else if (index >= table->children->size ()) - content.type = core::Content::END; - else { - content.type = core::Content::WIDGET_IN_FLOW; - content.widget = table->children->get(index)->cell.widget; - } } object::Object *Table::TableIterator::clone() { - return new TableIterator ((Table*)getWidget(), getMask(), index); -} - -int Table::TableIterator::compareTo(object::Comparable *other) -{ - return index - ((TableIterator*)other)->index; + TableIterator *tIt = + new TableIterator ((Table*)getWidget(), getMask(), false); + cloneValues (tIt); + return tIt; } -bool Table::TableIterator::next () -{ - Table *table = (Table*)getWidget(); - - if (content.type == core::Content::END) - return false; - - // tables only contain widgets (in flow): - if ((getMask() & core::Content::WIDGET_IN_FLOW) == 0) { - content.type = core::Content::END; - return false; - } - - do { - index++; - if (index >= table->children->size ()) { - content.type = core::Content::END; - return false; - } - } while (table->children->get(index) == NULL || - table->children->get(index)->type != Child::CELL); - - content.type = core::Content::WIDGET_IN_FLOW; - content.widget = table->children->get(index)->cell.widget; - return true; -} - -bool Table::TableIterator::prev () -{ - Table *table = (Table*)getWidget(); - - if (content.type == core::Content::START) - return false; - - // tables only contain widgets (in flow): - if ((getMask() & core::Content::WIDGET_IN_FLOW) == 0) { - content.type = core::Content::START; - return false; - } - - do { - index--; - if (index < 0) { - content.type = core::Content::START; - return false; - } - } while (table->children->get(index) == NULL || - table->children->get(index)->type != Child::CELL); - - content.type = core::Content::WIDGET_IN_FLOW; - content.widget = table->children->get(index)->cell.widget; - return true; -} void Table::TableIterator::highlight (int start, int end, core::HighlightLayer layer) { - /** todo Needs this an implementation? */ + if (inFlow ()) { + /** todo Needs this an implementation? */ + } else + highlightOOF (start, end, layer); } void Table::TableIterator::unhighlight (int direction, core::HighlightLayer layer) { + if (inFlow ()) { + // ??? + } else + unhighlightOOF (direction, layer); } void Table::TableIterator::getAllocation (int start, int end, core::Allocation *allocation) { - /** \bug Not implemented. */ + if (inFlow ()) { + /** \bug Not implemented. */ + } else + getAllocationOOF (start, end, allocation); +} + +int Table::TableIterator::numContentsInFlow () +{ + return ((Table*)getWidget())->children->size (); +} + +void Table::TableIterator::getContentInFlow (int index, + core::Content *content) +{ + Table *table = (Table*)getWidget(); + + if (table->children->get(index) != NULL && + table->children->get(index)->type == Child::CELL) { + content->type = core::Content::WIDGET_IN_FLOW; + content->widget = table->children->get(index)->cell.widget; + } else + content->type = core::Content::INVALID; } } // namespace dw diff --git a/dw/types.hh b/dw/types.hh index 36d6caa1..081b8db4 100644 --- a/dw/types.hh +++ b/dw/types.hh @@ -207,6 +207,10 @@ struct Content WIDGET_OOF_REF = 1 << 5, BREAK = 1 << 6, + /** \brief can be used internally, but should never be exposed, + e. g. by iterators */ + INVALID = 1 << 7, + ALL = 0xff, REAL_CONTENT = 0xff ^ (START | END), SELECTION_CONTENT = TEXT | BREAK, // WIDGET_* must be set additionally |