Browse Source

+ wide and combining character support in TInputLine.HandleEvent.MousePos. This
means cursor positioning and text selection with the mouse now works properly
with these special unicode characters

git-svn-id: branches/unicodekvm@48810 -

nickysn 4 years ago
parent
commit
fe312ab99f
1 changed files with 28 additions and 0 deletions
  1. 28 0
      packages/fv/src/dialogs.inc

+ 28 - 0
packages/fv/src/dialogs.inc

@@ -1661,6 +1661,33 @@ Delta, Anchor, OldCurPos, OldFirstPos, OldSelStart, OldSelEnd: Sw_Integer;
         MouseDelta := 0;
         MouseDelta := 0;
    END;
    END;
 
 
+{$ifdef FV_UNICODE}
+   FUNCTION MousePos: Sw_Integer;
+   VAR Skip, Pos: Sw_Integer;
+       Mouse : TPoint;
+       EGC: Sw_String;
+   BEGIN
+     MakeLocal(Event.Where, Mouse);
+     if Mouse.X < 1 then Mouse.X := 1;
+     Skip := FirstPos;
+     Pos := FirstPos;
+     for EGC in TUnicodeStringExtendedGraphemeClustersEnumerator.Create(Data) do
+       begin
+         if Skip > 0 then
+           Dec(Skip, Length(EGC))
+         else
+           begin
+             Dec(Mouse.X, StrWidth(EGC));
+             if Mouse.X <= 0 then
+               break;
+             Inc(Pos, Length(EGC));
+           end;
+       end;
+     if Pos < 0 then Pos := 0;
+     if Pos > Length(Data) then Pos := Length(Data);
+     MousePos := Pos;
+   END;
+{$else FV_UNICODE}
    FUNCTION MousePos: Sw_Integer;
    FUNCTION MousePos: Sw_Integer;
    VAR Pos: Sw_Integer;
    VAR Pos: Sw_Integer;
        Mouse : TPoint;
        Mouse : TPoint;
@@ -1672,6 +1699,7 @@ Delta, Anchor, OldCurPos, OldFirstPos, OldSelStart, OldSelEnd: Sw_Integer;
      if Pos > Length(Data Sw_PString_DeRef) then Pos := Length(Data Sw_PString_DeRef);
      if Pos > Length(Data Sw_PString_DeRef) then Pos := Length(Data Sw_PString_DeRef);
      MousePos := Pos;
      MousePos := Pos;
    END;
    END;
+{$endif FV_UNICODE}
 
 
    PROCEDURE DeleteSelect;
    PROCEDURE DeleteSelect;
    BEGIN
    BEGIN