aboutsummaryrefslogtreecommitdiff
path: root/dw
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-01-06 12:02:29 +0100
committerSebastian Geerken <devnull@localhost>2013-01-06 12:02:29 +0100
commitb9222b1aa44b4c69778445bbaea324a5712cea0a (patch)
tree823224ce8ed13aec165df5dc8a0c1c73110249d7 /dw
parentcc89e1ccf89b1d684d7615a4ea8e526b7345cd38 (diff)
Make DeepIterator able to follow widget references; activated this for findtext.
Diffstat (limited to 'dw')
-rw-r--r--dw/findtext.cc6
-rw-r--r--dw/iterator.cc35
-rw-r--r--dw/iterator.hh4
3 files changed, 33 insertions, 12 deletions
diff --git a/dw/findtext.cc b/dw/findtext.cc
index ad136431..9e9076dc 100644
--- a/dw/findtext.cc
+++ b/dw/findtext.cc
@@ -91,8 +91,7 @@ FindtextState::Result FindtextState::search (const char *key, bool caseSens,
if (iterator)
delete iterator;
- /** \todo Reactivate followReferences = true, as soon as it works. */
- iterator = new CharIterator (widget, false);
+ iterator = new CharIterator (widget, true);
if (backwards) {
/* Go to end */
@@ -124,8 +123,7 @@ FindtextState::Result FindtextState::search (const char *key, bool caseSens,
} else {
// Nothing found anymore, reset the state for the next trial.
delete iterator;
- /** \todo Reactivate followReferences = true, as soon as it works. */
- iterator = new CharIterator (widget, false);
+ iterator = new CharIterator (widget, true);
if (backwards) {
/* Go to end */
while (iterator->next ()) ;
diff --git a/dw/iterator.cc b/dw/iterator.cc
index 78ac55f6..9ad4d5a9 100644
--- a/dw/iterator.cc
+++ b/dw/iterator.cc
@@ -425,8 +425,9 @@ Iterator *DeepIterator::searchSideward (Iterator *it, Content::Type mask,
/* Nothing found, go upwards in the tree (if possible). */
it2->unref ();
- if (it->getWidget()->getParent ()) {
- it2 = it->getWidget()->getParent()->iterator (mask, false);
+ Widget *respParent = getRespectiveParent (it->getWidget(), it->getMask());
+ if (respParent) {
+ it2 = respParent->iterator (mask, false);
while (true) {
if (!it2->next ())
misc::assertNotReached ();
@@ -449,6 +450,19 @@ Iterator *DeepIterator::searchSideward (Iterator *it, Content::Type mask,
return NULL;
}
+Widget *DeepIterator::getRespectiveParent (Widget *widget, Content::Type mask)
+{
+ // Return, depending on which is requested indirectly (follow
+ // references or containments) the parent (container) or the
+ // generator. At this point, the type of the parent/generator is
+ // not known (since the parent/generator is not known), so we have
+ // to examine the mask. This is the reason why only one of
+ // WIDGET_OOF_CONT and WIDGET_OOF_REF is allowed.
+
+ return (mask & Content::WIDGET_OOF_REF) ?
+ widget->getGenerator() : widget->getParent();
+}
+
/**
* \brief Create a new deep iterator from an existing dw::core::Iterator.
*
@@ -465,9 +479,13 @@ Iterator *DeepIterator::searchSideward (Iterator *it, Content::Type mask,
*/
DeepIterator::DeepIterator (Iterator *it)
{
- // Handling widget references will be a bit more complicated, so we
- // prohibit it at this point.
- assert ((it->getMask() & Content::WIDGET_OOF_REF) == 0);
+ // 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.
+ int oofMask =
+ it->getMask() & (Content::WIDGET_OOF_CONT | Content::WIDGET_OOF_REF);
+ assert (oofMask == Content::WIDGET_OOF_CONT ||
+ oofMask == Content::WIDGET_OOF_REF);
//DEBUG_MSG (1, "a_Dw_ext_iterator_new: %s\n", a_Dw_iterator_text (it));
@@ -514,9 +532,10 @@ DeepIterator::DeepIterator (Iterator *it)
// Construct the iterators.
int thisLevel = it->getWidget()->getLevel (), level;
Widget *w;
- for (w = it->getWidget (), level = thisLevel; w->getParent() != NULL;
- w = w->getParent (), level--) {
- Iterator *it = w->getParent()->iterator (mask, false);
+ for (w = it->getWidget (), level = thisLevel;
+ getRespectiveParent (w) != NULL;
+ w = getRespectiveParent (w), level--) {
+ Iterator *it = getRespectiveParent(w)->iterator (mask, false);
//printf (" parent: %s %p\n", w->getClassName (), w);
diff --git a/dw/iterator.hh b/dw/iterator.hh
index 3b2fa6c2..9d284fed 100644
--- a/dw/iterator.hh
+++ b/dw/iterator.hh
@@ -169,6 +169,10 @@ private:
bool hasContents;
inline DeepIterator () { }
+ static Widget *getRespectiveParent (Widget *widget, Content::Type mask);
+ inline Widget *getRespectiveParent (Widget *widget) {
+ return getRespectiveParent (widget, mask);
+ }
public:
DeepIterator(Iterator *it);