documentor; extras/html: Made it easier to position caret at beginning or end of...
[sdk] / extras / html / lines.ec
index b8a9917..3623820 100644 (file)
@@ -81,7 +81,7 @@ Block GetNextBlock(Block block)
    return block;
 }
 
-int ComputeLine(Surface surface, Block startBlock, int startTextPos, Block * nextBlock, int * nextTextPos, int * centered, int * w, 
+int ComputeLine(Surface surface, Block startBlock, int startTextPos, Block * nextBlock, int * nextTextPos, int * centered, int * w,
    int maxW, int maxH, uint flags, int y, OldList leftObjects, OldList rightObjects, bool * changeLine, bool computeStartY, int sy, int sx)
 {
    int h = 0;
@@ -180,7 +180,7 @@ int ComputeLine(Surface surface, Block startBlock, int startTextPos, Block * nex
                   len = (nextSpace - (text + textPos)) + 1;
                else
                   len = block.textLen - textPos;
-               
+
                surface.TextExtent(text + textPos, len, &w, &th);
 
                if(x + width + w > maxW && x > 0)
@@ -243,7 +243,7 @@ int ComputeLine(Surface surface, Block startBlock, int startTextPos, Block * nex
                ComputeTable(surface, block, textPos, &width, &height, maxW, maxH, flags, y + sy, x + sx);
                surface.font = font;
                x += width;
-            
+
                *nextBlock = NextBlockUp(surface, block, centered, flags);
                *nextTextPos = 0;
                h = Max(h, height);
@@ -316,9 +316,9 @@ void RenderLine(HTMLView browser, Surface surface, int x, int y, int w, int h, B
 {
    int textPos = startTextPos;
    Block block = startBlock;
-   bool lineComplete = false;
    int startSel, endSel;
    Block startSelBlock = null, endSelBlock = null;
+   int prevGlyph = 0;
    if(browser.textBlock != browser.selBlock || browser.curPosition != browser.selPosition)
       browser.NormalizeSelection(&startSelBlock, &startSel, &endSelBlock, &endSel);
 
@@ -385,7 +385,7 @@ void RenderLine(HTMLView browser, Surface surface, int x, int y, int w, int h, B
             {
                surface.Bevel(false, dx, dy, bw, bh);
                if(browser.missing.bitmap)
-                  surface.Blit(browser.missing.bitmap, dx + 5, dy + 5, 0,0, 
+                  surface.Blit(browser.missing.bitmap, dx + 5, dy + 5, 0,0,
                      browser.missing.bitmap.width, browser.missing.bitmap.height);
             }
             surface.SetForeground(fg);
@@ -403,7 +403,7 @@ void RenderLine(HTMLView browser, Surface surface, int x, int y, int w, int h, B
                int l = startSel - textPos;
                if(block.text)
                {
-                  surface.TextExtent(block.text + textPos, l, &tw, &th);
+                  surface.TextExtent2(block.text + textPos, l, &tw, &th, prevGlyph, &prevGlyph, null);
                   surface.WriteText(x, y + h - th, block.text + textPos, l);
                   x += tw;
                }
@@ -423,7 +423,7 @@ void RenderLine(HTMLView browser, Surface surface, int x, int y, int w, int h, B
                   surface.foreground = white;
                   surface.textOpacity = true;
                }
-               surface.TextExtent(block.text + textPos, len, &tw, &th);
+               surface.TextExtent2(block.text + textPos, len, &tw, &th, prevGlyph, &prevGlyph, null);
                surface.WriteText(x, y + h - th, block.text + textPos, len);
                x += tw;
                if(browser.isSelected)
@@ -442,7 +442,7 @@ void RenderLine(HTMLView browser, Surface surface, int x, int y, int w, int h, B
                int l = endPos - textPos;
                if(block.text)
                {
-                  surface.TextExtent(block.text + textPos, l, &tw, &th);
+                  surface.TextExtent2(block.text + textPos, l, &tw, &th, prevGlyph, &prevGlyph, null);
                   surface.WriteText(x, y + h - th, block.text + textPos, l);
                   x += tw;
                }
@@ -457,7 +457,6 @@ void RenderLine(HTMLView browser, Surface surface, int x, int y, int w, int h, B
             break;
         case TABLE:
             RenderTable(browser, surface, x, y, w, h, left, right, block);
-            lineComplete = true;
             block = NextBlockUp(surface, block, null, RenderFlags { render = true });
             textPos = 0;
             break;
@@ -474,13 +473,12 @@ void RenderLine(HTMLView browser, Surface surface, int x, int y, int w, int h, B
    }
 }
 
-bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos, 
+bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
               Block endBlock, int endTextPos, int left, int right, int pickX, int pickY, Block* pickBlock, int * pickTextPos)
 {
    bool result = false;
    int textPos = startTextPos;
    Block block = startBlock;
-   bool lineComplete = false;
 
    for(;!result;)
    {
@@ -548,7 +546,8 @@ bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Blo
             surface.TextExtent(block.text + textPos, len, &tw, &th);
             // eSurface_WriteText(surface, x, y + h - th, block.text + textPos, len);
 
-            if(pickX >= x && pickY >= y+h-th && pickX < x + tw && pickY < y+h)
+            if(block.text[0] == ' ' && block.text[1] == 0) pickX += tw; else
+            if(pickX >= x && pickY >= y+h-th && pickX < x + tw + 2 && pickY < y+h)
             {
                result = true;
                *pickBlock = block;
@@ -565,7 +564,6 @@ bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Blo
             break;
         case TABLE:
             result = PickTable(browser, surface, x, y, w, h, left, right, block, pickX, pickY, pickBlock, pickTextPos);
-            lineComplete = true;
             block = NextBlockUp(surface, block, null, RenderFlags { render = true });
             textPos = 0;
             break;
@@ -583,13 +581,12 @@ bool PickLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Blo
    return result;
 }
 
-              
-void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos, 
+
+void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h, Block startBlock, int startTextPos,
                   Block endBlock, int endTextPos, int left, int right)
 {
    int textPos = startTextPos;
    Block block = startBlock;
-   bool lineComplete = false;
 
    for(;;)
    {
@@ -604,22 +601,18 @@ void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h,
             {
                Window parent = block.window.parent;
                block.window.Move(
-                  x + parent.scroll.x, y + parent.scroll.y, 
+                  x + parent.scroll.x, y + parent.scroll.y,
                   block.window.size.w, block.window.size.h);
                //block.window.visible = false;
                x += block.window.size.w;
-               if(block.inputType == text)
-               {
-                  printf("");
-               }
             }
             break;
          }
          case IMAGE:
          {
             int bw = block.pWidth ? (w * block.pWidth / 100) : block.w;
-            int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
-            int dx, dy;
+            //int bh = block.pHeight ? (h * block.pHeight / 100) : block.h;
+            int dx;//, dy;
 
             switch(block.halign)
             {
@@ -637,12 +630,14 @@ void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h,
                   break;
             }
 
+            /*
             switch(block.valign)
             {
                case bottom: dy = y + h - bh; break;
                case top: dy = y; break;
                case middle: dy = y + (h - bh) / 2; break;
             }
+            */
 
             x += bw;
             break;
@@ -667,7 +662,6 @@ void PositionLine(HTMLView browser, Surface surface, int x, int y, int w, int h,
             break;
         case TABLE:
             PositionTable(browser, surface, x, y, w, h, left, right, block);
-            lineComplete = true;
             block = NextBlockUp(surface, block, null, RenderFlags { render = true });
             textPos = 0;
             break;