Mercurial > dillo_port1.3
changeset 358:37c640e78da0
- Added link color change as visual feedback for a clicked link.
author | jcid |
---|---|
date | Sun, 28 Sep 2008 20:56:55 +0200 |
parents | 09a79e1ffea2 |
children | b9142bae5429 |
files | dw/textblock.cc lout/identity.cc |
diffstat | 2 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/dw/textblock.cc Sat Sep 27 23:44:24 2008 +0200 +++ b/dw/textblock.cc Sun Sep 28 20:56:55 2008 +0200 @@ -1906,11 +1906,64 @@ 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(); } // ----------------------------------------------------------------------