aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-08-16 18:17:47 +0200
committerSebastian Geerken <devnull@localhost>2013-08-16 18:17:47 +0200
commita5e77bdac14a79d6c8a09a6db8f1a2307b1537f3 (patch)
treec00e1260cd8328e35295afe30e0ae451d3b7a8a0
parent183e15f49625b3a15a9b2e511970c988d7164c23 (diff)
Fixed a bug in DeepIterator (level calculation should regard generators).
-rw-r--r--dw/iterator.cc38
-rw-r--r--dw/iterator.hh6
-rw-r--r--dw/widget.cc19
-rw-r--r--dw/widget.hh1
4 files changed, 54 insertions, 10 deletions
diff --git a/dw/iterator.cc b/dw/iterator.cc
index b5b9b292..18d62a49 100644
--- a/dw/iterator.cc
+++ b/dw/iterator.cc
@@ -207,10 +207,9 @@ void Iterator::scrollTo (Iterator *it1, Iterator *it2, int start, int end,
void Iterator::print ()
{
- printf ("in the %s %p, mask ", widget->getClassName(), widget);
- Content::printMask (mask);
- printf (", pointing at ");
- Content::print (&content);
+ misc::StringBuffer sb;
+ intoStringBuffer (&sb);
+ printf ("%s", sb.getChars ());
}
// -------------------
@@ -481,6 +480,14 @@ Widget *DeepIterator::getRespectiveParent (Widget *widget, Content::Type mask)
widget->getGenerator() : widget->getParent();
}
+int DeepIterator::getRespectiveLevel (Widget *widget, Content::Type mask)
+{
+ // Similar to getRespectiveParent.
+
+ return (mask & Content::WIDGET_OOF_REF) ?
+ widget->getGeneratorLevel() : widget->getLevel();
+}
+
/**
* \brief Create a new deep iterator from an existing dw::core::Iterator.
*
@@ -497,6 +504,11 @@ Widget *DeepIterator::getRespectiveParent (Widget *widget, Content::Type mask)
*/
DeepIterator::DeepIterator (Iterator *it)
{
+ //printf ("Starting creating DeepIterator %p ...\n", this);
+ //printf ("Initial iterator: ");
+ //it->print ();
+ //printf ("\n");
+
// Widgets out of flow are either followed widtin containers, or
// generators. Both (and also nothing at all) is not allowed. See
// also comment in getRespectiveParent.
@@ -543,12 +555,12 @@ DeepIterator::DeepIterator (Iterator *it)
// \todo There may be a faster way instead of iterating through the
// parent widgets.
- //printf ("STARTING WITH: ");
+ //printf ("Starting with: ");
//it->print ();
//printf ("\n");
// Construct the iterators.
- int thisLevel = it->getWidget()->getLevel (), level;
+ int thisLevel = getRespectiveLevel (it->getWidget()), level;
Widget *w;
for (w = it->getWidget (), level = thisLevel;
getRespectiveParent (w) != NULL;
@@ -559,7 +571,7 @@ DeepIterator::DeepIterator (Iterator *it)
stack.put (it, level - 1);
while (true) {
- //printf (" ");
+ //printf (" ");
//it->print ();
//printf ("\n");
@@ -571,16 +583,22 @@ DeepIterator::DeepIterator (Iterator *it)
break;
}
+ //printf (" %d: ", level - 1);
+ //it->print ();
+ //printf ("\n");
}
stack.put (it, thisLevel);
content = *(it->getContent());
}
+
+ //printf ("... done creating DeepIterator %p.\n", this);
}
DeepIterator::~DeepIterator ()
{
+ //printf ("Deleting DeepIterator %p ...\n", this);
}
object::Object *DeepIterator::clone ()
@@ -615,11 +633,11 @@ int DeepIterator::compareTo (object::Comparable *other)
assert (stack.size() > 0);
assert (otherDeepIterator->stack.size() > 0);
- //printf ("Equal? The %s %p and the %s %p?\n",
+ //printf ("Equal? The %s %p (of %p) and the %s %p (of %p)?\n",
// stack.get(0)->getWidget()->getClassName(),
- // stack.get(0)->getWidget(),
+ // stack.get(0)->getWidget(), this,
// otherDeepIterator->stack.get(0)->getWidget()->getClassName(),
- // otherDeepIterator->stack.get(0)->getWidget());
+ // otherDeepIterator->stack.get(0)->getWidget(), otherDeepIterator);
assert (stack.get(0)->getWidget()
== otherDeepIterator->stack.get(level)->getWidget());
diff --git a/dw/iterator.hh b/dw/iterator.hh
index 44cb6042..abf31d0b 100644
--- a/dw/iterator.hh
+++ b/dw/iterator.hh
@@ -170,11 +170,17 @@ private:
bool hasContents;
inline DeepIterator () { }
+
static Widget *getRespectiveParent (Widget *widget, Content::Type mask);
inline Widget *getRespectiveParent (Widget *widget) {
return getRespectiveParent (widget, mask);
}
+ static int getRespectiveLevel (Widget *widget, Content::Type mask);
+ inline int getRespectiveLevel (Widget *widget) {
+ return getRespectiveLevel (widget, mask);
+ }
+
public:
DeepIterator(Iterator *it);
~DeepIterator();
diff --git a/dw/widget.cc b/dw/widget.cc
index 42566a17..f5bca367 100644
--- a/dw/widget.cc
+++ b/dw/widget.cc
@@ -478,6 +478,25 @@ int Widget::getLevel ()
}
/**
+ * \brief Get the level of the widget within the tree, regarting the
+ * generators, not the parents.
+ *
+ * The root widget has the level 0.
+ */
+int Widget::getGeneratorLevel ()
+{
+ Widget *widget = this;
+ int level = 0;
+
+ while (widget->getGenerator ()) {
+ level++;
+ widget = widget->getGenerator ();
+ }
+
+ return level;
+}
+
+/**
* \brief Get the widget with the highest level, which is a direct ancestor of
* widget1 and widget2.
*/
diff --git a/dw/widget.hh b/dw/widget.hh
index a99e12ab..18d74026 100644
--- a/dw/widget.hh
+++ b/dw/widget.hh
@@ -309,6 +309,7 @@ public:
inline Widget *getParent () { return parent; }
Widget *getTopLevel ();
int getLevel ();
+ int getGeneratorLevel ();
Widget *getNearestCommonAncestor (Widget *otherWidget);
inline Widget *getGenerator () { return generator ? generator : parent; }