aboutsummaryrefslogtreecommitdiff
path: root/dw/textblock.cc
diff options
context:
space:
mode:
authorjcid <devnull@localhost>2008-09-28 20:56:55 +0200
committerjcid <devnull@localhost>2008-09-28 20:56:55 +0200
commit943d83abb4a2b16e4b53eae51da95e15c7d33955 (patch)
treeaacc34f8f2bb4bb42f275012bf433903de8673ff /dw/textblock.cc
parent99376eefe2531e798b9b26518f48e05bab72ae45 (diff)
- Added link color change as visual feedback for a clicked link.
Diffstat (limited to 'dw/textblock.cc')
-rw-r--r--dw/textblock.cc53
1 files changed, 53 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();
}
// ----------------------------------------------------------------------