changeset 1454:4f088370cfda

Separate Anchors out from Words The reason for this is that they were in the way when adding parbreaks. http://lists.auriga.wearlab.de/pipermail/dillo-dev/2009-November/007044.html
author corvid <corvid@lavabit.com>
date Mon, 30 Nov 2009 19:48:43 +0000
parents 328111d18d57
children 193c0699f16a
files dw/textblock.cc dw/textblock.hh dw/types.hh
diffstat 3 files changed, 35 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/dw/textblock.cc	Sun Nov 29 21:40:02 2009 +0100
+++ b/dw/textblock.cc	Mon Nov 30 19:48:43 2009 +0000
@@ -58,6 +58,7 @@
     */
    lines = new misc::SimpleVector <Line> (1);
    words = new misc::SimpleVector <Word> (1);
+   anchors = new misc::SimpleVector <Anchor> (1);
 
    //DBG_OBJ_SET_NUM(page, "num_lines", num_lines);
 
@@ -99,16 +100,19 @@
       Word *word = words->getRef (i);
       if (word->content.type == core::Content::WIDGET)
          delete word->content.widget;
-      else if (word->content.type == core::Content::ANCHOR)
-         /* This also frees the names (see removeAnchor() and related). */
-         removeAnchor(word->content.anchor);
-
       word->style->unref ();
       word->spaceStyle->unref ();
    }
 
+   for (int i = 0; i < anchors->size(); i++) {
+      Anchor *anchor = anchors->getRef (i);
+      /* This also frees the names (see removeAnchor() and related). */
+      removeAnchor(anchor->name);
+   }
+
    delete lines;
    delete words;
+   delete anchors;
 
    /* Make sure we don't own widgets anymore. Necessary before call of
       parent class destructor. (???) */
@@ -407,11 +411,6 @@
             word->content.widget->sizeAllocate (&childAllocation);
             break;
 
-         case core::Content::ANCHOR:
-            changeAnchor (word->content.anchor,
-                          lineYOffsetCanvasAllocation (line, allocation));
-            break;
-
          default:
             // make compiler happy
             break;
@@ -420,6 +419,19 @@
          xCursor += (word->size.width + word->effSpace);
       }
    }
+
+   for (int i = 0; i < anchors->size(); i++) {
+      Anchor *anchor = anchors->getRef(i);
+      int y;
+
+      if (anchor->wordIndex >= words->size()) {
+         y = allocation->y + allocation->ascent + allocation->descent;
+      } else {
+         Line *line = lines->getRef(findLineOfWord (anchor->wordIndex));
+         y = lineYOffsetCanvasAllocation (line, allocation);
+      }
+      changeAnchor (anchor->name, y);
+   }
 }
 
 void Textblock::resizeDrawImpl ()
@@ -1649,7 +1661,6 @@
  */
 bool Textblock::addAnchor (const char *name, core::style::Style *style)
 {
-   Word *word;
    char *copy;
    int y;
 
@@ -1671,10 +1682,12 @@
        */
       return false;
    else {
-      word = addWord (0, 0, 0, style);
-      word->content.type = core::Content::ANCHOR;
-      word->content.anchor = copy;
-      wordWrap (words->size () - 1);
+      Anchor *anchor;
+
+      anchors->increase();
+      anchor = anchors->getRef(anchors->size() - 1);
+      anchor->name = copy;
+      anchor->wordIndex = words->size();
       return true;
    }
 }
--- a/dw/textblock.hh	Sun Nov 29 21:40:02 2009 +0100
+++ b/dw/textblock.hh	Mon Nov 30 19:48:43 2009 +0000
@@ -172,6 +172,12 @@
                                          later set by a_Dw_page_add_space */
    };
 
+   struct Anchor
+   {
+      char *name;
+      int wordIndex;
+   };
+
    class TextblockIterator: public core::Iterator
    {
    private:
@@ -239,6 +245,7 @@
 
    lout::misc::SimpleVector <Line> *lines;
    lout::misc::SimpleVector <Word> *words;
+   lout::misc::SimpleVector <Anchor> *anchors;
 
    struct {int index, nChar;}
       hlStart[core::HIGHLIGHT_NUM_LAYERS], hlEnd[core::HIGHLIGHT_NUM_LAYERS];
--- a/dw/types.hh	Sun Nov 29 21:40:02 2009 +0100
+++ b/dw/types.hh	Mon Nov 30 19:48:43 2009 +0000
@@ -179,8 +179,7 @@
       END               = 1 << 1,
       TEXT              = 1 << 2,
       WIDGET            = 1 << 3,
-      ANCHOR            = 1 << 4,
-      BREAK             = 1 << 5,
+      BREAK             = 1 << 4,
       ALL               = 0xff,
       REAL_CONTENT      = 0xff ^ (START | END),
       SELECTION_CONTENT = TEXT | WIDGET | BREAK
@@ -193,7 +192,6 @@
    union {
       const char *text;
       Widget *widget;
-      char *anchor;
       int breakSpace;
    };
 };