diff options
author | jcid <devnull@localhost> | 2008-09-28 20:56:55 +0200 |
---|---|---|
committer | jcid <devnull@localhost> | 2008-09-28 20:56:55 +0200 |
commit | 943d83abb4a2b16e4b53eae51da95e15c7d33955 (patch) | |
tree | aacc34f8f2bb4bb42f275012bf433903de8673ff | |
parent | 99376eefe2531e798b9b26518f48e05bab72ae45 (diff) |
- Added link color change as visual feedback for a clicked link.
-rw-r--r-- | dw/textblock.cc | 53 | ||||
-rw-r--r-- | lout/identity.cc | 1 |
2 files changed, 54 insertions, 0 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index 0ada8027..59080d35 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -1906,11 +1906,64 @@ void Textblock::flush () void Textblock::changeLinkColor (int link, int newColor) { + int from = -1, to; + core::style::StyleAttrs style_attrs; + core::style::Style *visited_style; + + //printf("Textblock::changeLinkColor link=%d\n", link); + + /* Find the first and last word of this link (binary search) */ + int min = 0, max = words->size() - 1, i, d; + while (min <= max) { + i = (min + max) / 2; + for (d = i; d > min && words->getRef(d)->style->x_link == -1; --d); + //printf(" changeLinkColor: min=%d max=%d i=%d d=%d s=%d\n", + // min,max,i,d,i-d); + if (words->getRef(d)->style->x_link == -1) { + min = i + 1; + continue; + } + /* found a link */ + if (words->getRef(d)->style->x_link < link) { + min = d + 1; + } else if (words->getRef(d)->style->x_link > link) { + max = d - 1; + } else { + for (; d > 0 && words->getRef(d-1)->style->x_link == link; --d); + from = d; + for (; d < max && words->getRef(d+1)->style->x_link == link; ++d); + to = d; + break; + } + } + + if (from != -1) { + style_attrs = *words->getRef(from)->style; + style_attrs.color = + core::style::Color::createSimple (layout, newColor); + visited_style = core::style::Style::create (layout, &style_attrs); + changeWordStyle (from, to, visited_style, false, false); + visited_style->unref(); + } } void Textblock::changeWordStyle (int from, int to, core::style::Style *style, bool includeFirstSpace, bool includeLastSpace) { + Word *word; + int wordIndex; + + /** \todo handle: includeFirstSpace and includeLastSpace */ + + if (from < 0 || to < from || to >= words->size()) + return; + for (wordIndex = from; wordIndex <= to; wordIndex++) { + word = words->getRef (wordIndex); + word->style->unref(); + style->ref(); + word->style = style; + } + queueDraw(); } // ---------------------------------------------------------------------- diff --git a/lout/identity.cc b/lout/identity.cc index 5e4965f1..b124d6ad 100644 --- a/lout/identity.cc +++ b/lout/identity.cc @@ -75,6 +75,7 @@ void IdentifiableObject::registerName (const char *className, int *classId) ConstString *key = new ConstString (className); classesByName->put (key, klass); classesById->put (klass); + *classId = klass->id; } this->classId = klass->id; |