mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-04 19:00:27 +02:00
Win32: fix Win32MemoStrings Insert/Delete/SelStart/LineStart/LineLength for MBC charsets (issue #0019716)
git-svn-id: trunk@46042 -
This commit is contained in:
parent
bc3115ff03
commit
acde1c2b82
@ -36,12 +36,27 @@ type
|
|||||||
|
|
||||||
function TWin32MemoStrings.GetLineLength(Index: Integer): Integer;
|
function TWin32MemoStrings.GetLineLength(Index: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
|
//{$ifdef WindowsUnicodeSupport}{$else}{$endif WindowsUnicodeSupport}
|
||||||
|
{$ifdef WindowsUnicodeSupport}
|
||||||
|
if UnicodeEnabledOS then
|
||||||
|
Result := SendMessageW(FHandle, EM_LINELENGTH, SendMessageW(FHandle, EM_LINEINDEX, Index, 0), 0)
|
||||||
|
else
|
||||||
|
Result := SendMessage(FHandle, EM_LINELENGTH, SendMessage(FHandle, EM_LINEINDEX, Index, 0), 0);
|
||||||
|
{$else}
|
||||||
Result := SendMessage(FHandle, EM_LINELENGTH, SendMessage(FHandle, EM_LINEINDEX, Index, 0), 0);
|
Result := SendMessage(FHandle, EM_LINELENGTH, SendMessage(FHandle, EM_LINEINDEX, Index, 0), 0);
|
||||||
|
{$endif WindowsUnicodeSupport}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWin32MemoStrings.GetLineStart(Index: Integer): Integer;
|
function TWin32MemoStrings.GetLineStart(Index: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef WindowsUnicodeSupport}
|
||||||
|
if UnicodeEnabledOS then
|
||||||
|
Result := SendMessageW(FHandle, EM_LINEINDEX, Index, 0)
|
||||||
|
else
|
||||||
|
Result := SendMessage(FHandle, EM_LINEINDEX, Index, 0);
|
||||||
|
{$else}
|
||||||
Result := SendMessage(FHandle, EM_LINEINDEX, Index, 0);
|
Result := SendMessage(FHandle, EM_LINEINDEX, Index, 0);
|
||||||
|
{$endif WindowsUnicodeSupport}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWin32MemoStrings.GetTextStr: string;
|
function TWin32MemoStrings.GetTextStr: string;
|
||||||
@ -159,8 +174,21 @@ begin
|
|||||||
LineStart := GetLineStart(Index);
|
LineStart := GetLineStart(Index);
|
||||||
LineEnd := GetLineStart(Index+1);
|
LineEnd := GetLineStart(Index+1);
|
||||||
if LineEnd < 0 then LineEnd := LineStart+GetLineLength(Index);
|
if LineEnd < 0 then LineEnd := LineStart+GetLineLength(Index);
|
||||||
|
{$ifdef WindowsUnicodeSupport}
|
||||||
|
if UnicodeEnabledOS then
|
||||||
|
begin
|
||||||
|
SendMessageW(FHandle, EM_SETSEL, LineStart, LineEnd);
|
||||||
|
SendMessageW(FHandle, EM_REPLACESEL,0 , lparam(PWChar('')));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
SendMessage(FHandle, EM_SETSEL, LineStart, LineEnd);
|
||||||
|
SendMessage(FHandle, EM_REPLACESEL,0 , lparam(PChar('')));
|
||||||
|
end;
|
||||||
|
{$else}
|
||||||
SendMessage(FHandle, EM_SETSEL, LineStart, LineEnd);
|
SendMessage(FHandle, EM_SETSEL, LineStart, LineEnd);
|
||||||
SendMessage(FHandle, EM_REPLACESEL,0 , lparam(PChar('')));
|
SendMessage(FHandle, EM_REPLACESEL,0 , lparam(PChar('')));
|
||||||
|
{$endif WindowsUnicodeSupport}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWin32MemoStrings.Insert(Index: integer; const S: string);
|
procedure TWin32MemoStrings.Insert(Index: integer; const S: string);
|
||||||
@ -174,31 +202,48 @@ begin
|
|||||||
//insert with LineEnding
|
//insert with LineEnding
|
||||||
LineStart := GetLineStart(Index);
|
LineStart := GetLineStart(Index);
|
||||||
NewLine := S+LineEnding;
|
NewLine := S+LineEnding;
|
||||||
SendMessage(FHandle, EM_SETSEL, LineStart, LineStart);
|
{$ifdef WindowsUnicodeSupport}
|
||||||
{$ifdef WindowsUnicodeSupport}
|
|
||||||
if UnicodeEnabledOS
|
if UnicodeEnabledOS
|
||||||
then SendMessageW(FHandle, EM_REPLACESEL, 0, lparam(PWideChar(UTF8ToUTF16(NewLine))))
|
then
|
||||||
else SendMessage(FHandle, EM_REPLACESEL, 0, lparam(Utf8ToAnsi(NewLine)));
|
begin
|
||||||
{$else}
|
SendMessageW(FHandle, EM_SETSEL, LineStart, LineStart);
|
||||||
|
SendMessageW(FHandle, EM_REPLACESEL, 0, lparam(PWideChar(UTF8ToUTF16(NewLine))))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
SendMessage(FHandle, EM_SETSEL, LineStart, LineStart);
|
||||||
|
SendMessage(FHandle, EM_REPLACESEL, 0, lparam(Utf8ToAnsi(NewLine)))
|
||||||
|
end;
|
||||||
|
{$else}
|
||||||
|
SendMessage(FHandle, EM_SETSEL, LineStart, LineStart);
|
||||||
SendMessage(FHandle, EM_REPLACESEL, 0, lparam(PChar(NewLine)));
|
SendMessage(FHandle, EM_REPLACESEL, 0, lparam(PChar(NewLine)));
|
||||||
{$endif}
|
{$endif WindowsUnicodeSupport}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
//append with a preceding LineEnding
|
//append with a preceding LineEnding
|
||||||
LineStart := GetLineStart(Index-1)+GetLineLength(Index-1);
|
LineStart := GetLineStart(Index-1)+GetLineLength(Index-1);
|
||||||
|
{$ifdef WindowsUnicodeSupport}
|
||||||
|
if UnicodeEnabledOS then
|
||||||
|
SendMessageW(FHandle, EM_SETSEL, LineStart, LineStart)
|
||||||
|
else
|
||||||
|
SendMessage(FHandle, EM_SETSEL, LineStart, LineStart);
|
||||||
|
{$else}
|
||||||
SendMessage(FHandle, EM_SETSEL, LineStart, LineStart);
|
SendMessage(FHandle, EM_SETSEL, LineStart, LineStart);
|
||||||
|
{$endif WindowsUnicodeSupport}
|
||||||
if GetRealCount = Count then
|
if GetRealCount = Count then
|
||||||
NewLine := LineEnding+S+LineEnding
|
NewLine := LineEnding+S+LineEnding
|
||||||
else
|
else
|
||||||
NewLine := S+LineEnding;
|
NewLine := S+LineEnding;
|
||||||
{$ifdef WindowsUnicodeSupport}
|
{$ifdef WindowsUnicodeSupport}
|
||||||
if UnicodeEnabledOS
|
if UnicodeEnabledOS
|
||||||
then SendMessageW(FHandle, EM_REPLACESEL, 0, lparam(PWideChar(UTF8ToUTF16(NewLine))))
|
then
|
||||||
else SendMessage(FHandle, EM_REPLACESEL, 0, lparam(Utf8ToAnsi(NewLine)));
|
SendMessageW(FHandle, EM_REPLACESEL, 0, lparam(PWideChar(UTF8ToUTF16(NewLine))))
|
||||||
{$else}
|
else
|
||||||
|
SendMessage(FHandle, EM_REPLACESEL, 0, lparam(Utf8ToAnsi(NewLine)));
|
||||||
|
{$else}
|
||||||
SendMessage(FHandle, EM_REPLACESEL, 0, lparam(PChar(NewLine)));
|
SendMessage(FHandle, EM_REPLACESEL, 0, lparam(PChar(NewLine)));
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user