diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-09-23 10:21:56 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-09-23 10:21:56 +0200 |
commit | 3a6ee1212cc7a5119eeb9687ad295a50fffaebdd (patch) | |
tree | 461490415163f7d4e78ffe4dcf2ada2df6df7fb4 /src | |
parent | 8e3dd5465895395d649800f47820ef5e72826a1e (diff) | |
download | fpGUI-3a6ee1212cc7a5119eeb9687ad295a50fffaebdd.tar.xz |
memo: Implemented SelectionText() function.
Also improved DoCopy to rather use SelectionText instead of
duplicating code.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/fpg_memo.pas | 109 |
1 files changed, 47 insertions, 62 deletions
diff --git a/src/gui/fpg_memo.pas b/src/gui/fpg_memo.pas index b3c34513..994959e7 100644 --- a/src/gui/fpg_memo.pas +++ b/src/gui/fpg_memo.pas @@ -110,7 +110,7 @@ type constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure UpdateScrollBars; - function SelectionText: string; + function SelectionText: TfpgString; procedure CopyToClipboard; procedure CutToClipboard; procedure PasteFromClipboard; @@ -569,58 +569,11 @@ begin end; procedure TfpgMemo.DoCopy; -var - n: integer; - selsl: integer; - selsp: integer; - selel: integer; - selep: integer; - ls: string; - len: integer; - st: integer; - s: string; begin if FSelEndLine < 0 then Exit; - if (FSelStartLine shl 16) + FSelStartPos <= (FSelEndLine shl 16) + FSelEndPos then - begin - selsl := FSelStartLine; - selsp := FSelStartPos; - selel := FSelEndLine; - selep := FSelEndPos; - end - else - begin - selel := FSelStartLine; - selep := FSelStartPos; - selsl := FSelEndLine; - selsp := FSelEndPos; - end; - - s := ''; - - for n := selsl to selel do - begin - if n > selsl then - s := s + #13#10; - - ls := GetLineText(n); - - if selsl < n then - st := 0 - else - st := selsp; - - if selel > n then - len := UTF8Length(ls) - else - len := selep - st; - - s := s + UTF8Copy(ls, st + 1, len); - end; - - fpgClipboard.Text := s; + fpgClipboard.Text := SelectionText; end; procedure TfpgMemo.DoPaste(const AText: TfpgString); @@ -1585,23 +1538,55 @@ begin end; end; -function TfpgMemo.SelectionText: string; +function TfpgMemo.SelectionText: TfpgString; +var + n: integer; + selsl: integer; + selsp: integer; + selel: integer; + selep: integer; + ls: string; + len: integer; + st: integer; + s: TfpgString; begin - { - if FSelOffset <> 0 then + if (FSelStartLine shl 16) + FSelStartPos <= (FSelEndLine shl 16) + FSelEndPos then begin - if FSelOffset < 0 then - begin - Result := Copy(FText,1+FSelStart + FSelOffset,-FSelOffset); - end - else - begin - result := Copy(FText,1+FSelStart,FSelOffset); - end; + selsl := FSelStartLine; + selsp := FSelStartPos; + selel := FSelEndLine; + selep := FSelEndPos; end else -} - Result := ''; + begin + selel := FSelStartLine; + selep := FSelStartPos; + selsl := FSelEndLine; + selsp := FSelEndPos; + end; + + s := ''; + for n := selsl to selel do + begin + if n > selsl then + s := s + LineEnding; + + ls := GetLineText(n); + + if selsl < n then + st := 0 + else + st := selsp; + + if selel > n then + len := UTF8Length(ls) + else + len := selep - st; + + s := s + UTF8Copy(ls, st + 1, len); + end; + + Result := s; end; procedure TfpgMemo.CopyToClipboard; |