You've already forked lazarus-ccr
fixed win32 style-ranging bug, reported by Dusan aka dusanx
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@895 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -34,7 +34,7 @@ uses
|
|||||||
// Win32WidgetSet
|
// Win32WidgetSet
|
||||||
Win32WSControls, Win32Int,
|
Win32WSControls, Win32Int,
|
||||||
// RichMemo headers
|
// RichMemo headers
|
||||||
WSRichMemo, Win32RichMemoProc;
|
WSRichMemo, Win32RichMemoProc, Win32WSStdCtrls;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -42,6 +42,9 @@ type
|
|||||||
|
|
||||||
TWin32WSCustomRichMemo = class(TWSCustomRichMemo)
|
TWin32WSCustomRichMemo = class(TWSCustomRichMemo)
|
||||||
published
|
published
|
||||||
|
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
|
||||||
|
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
|
||||||
|
|
||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; override;
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; override;
|
||||||
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
|
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
|
||||||
var Params: TIntFontParams): Boolean; override;
|
var Params: TIntFontParams): Boolean; override;
|
||||||
@ -64,29 +67,51 @@ const
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
procedure LockRedraw(AHandle: Integer);
|
procedure LockRedraw(AHandle: HWND);
|
||||||
begin
|
begin
|
||||||
SendMessage(AHandle, WM_SETREDRAW, 0, 0);
|
SendMessage(AHandle, WM_SETREDRAW, 0, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure UnlockRedraw(AHandle: Integer; Invalidate: Boolean = true);
|
procedure UnlockRedraw(AHandle: HWND; NeedInvalidate: Boolean = true);
|
||||||
begin
|
begin
|
||||||
SendMessage(AHandle, WM_SETREDRAW, 1, 0);
|
SendMessage(AHandle, WM_SETREDRAW, 1, 0);
|
||||||
if Invalidate then InvalidateRect(AHandle, nil, false);
|
if NeedInvalidate then
|
||||||
|
Windows.InvalidateRect(AHandle, nil, true);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RichEditProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
|
function RichEditProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
|
||||||
LParam: Windows.LParam): LResult; stdcall;
|
LParam: Windows.LParam): LResult; stdcall;
|
||||||
begin
|
begin
|
||||||
if Msg = WM_PAINT then
|
if Msg = WM_PAINT then begin
|
||||||
//todo: LCL WM_PAINT handling prevents richedit from drawing correctly
|
//todo: LCL WM_PAINT handling prevents richedit from drawing correctly
|
||||||
Result := CallDefaultWindowProc(Window, Msg, WParam, LParam)
|
Result := CallDefaultWindowProc(Window, Msg, WParam, LParam)
|
||||||
else
|
//Result := WindowProc(Window, Msg, WParam, LParam)
|
||||||
|
end else
|
||||||
Result := WindowProc(Window, Msg, WParam, LParam);
|
Result := WindowProc(Window, Msg, WParam, LParam);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TWin32WSCustomRichMemo }
|
{ TWin32WSCustomRichMemo }
|
||||||
|
|
||||||
|
class procedure TWin32WSCustomRichMemo.SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer);
|
||||||
|
var
|
||||||
|
range : Tcharrange;
|
||||||
|
begin
|
||||||
|
range.cpMin := NewStart;
|
||||||
|
range.cpMax := NewStart;
|
||||||
|
SendMessage(ACustomEdit.Handle, EM_EXSETSEL, 0, LPARAM(@range));
|
||||||
|
InvalidateRect(ACustomEdit.Handle, nil, false);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TWin32WSCustomRichMemo.SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer);
|
||||||
|
var
|
||||||
|
range : Tcharrange;
|
||||||
|
begin
|
||||||
|
SendMessage(ACustomEdit.Handle, EM_EXGETSEL, 0, LPARAM(@range));
|
||||||
|
range.cpMax := range.cpMin + NewLength;
|
||||||
|
SendMessage(ACustomEdit.Handle, EM_EXSETSEL, 0, LPARAM(@range));
|
||||||
|
InvalidateRect(ACustomEdit.Handle, nil, false);
|
||||||
|
end;
|
||||||
|
|
||||||
class function TWin32WSCustomRichMemo.CreateHandle(const AWinControl: TWinControl;
|
class function TWin32WSCustomRichMemo.CreateHandle(const AWinControl: TWinControl;
|
||||||
const AParams: TCreateParams): HWND;
|
const AParams: TCreateParams): HWND;
|
||||||
var
|
var
|
||||||
@ -194,23 +219,48 @@ begin
|
|||||||
RichEditManager.SetHideSelection(AWinControl.Handle, AHideSelection);
|
RichEditManager.SetHideSelection(AWinControl.Handle, AHideSelection);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure InitScrollInfo(var info: TScrollInfo);
|
||||||
|
begin
|
||||||
|
FillChar(info, sizeof(info), 0);
|
||||||
|
info.cbSize := sizeof(info);
|
||||||
|
info.fMask := SIF_ALL;
|
||||||
|
end;
|
||||||
|
|
||||||
class function TWin32WSCustomRichMemo.GetStyleRange(
|
class function TWin32WSCustomRichMemo.GetStyleRange(
|
||||||
const AWinControl: TWinControl; TextStart: Integer; var RangeStart,
|
const AWinControl: TWinControl; TextStart: Integer; var RangeStart,
|
||||||
RangeLen: Integer): Boolean;
|
RangeLen: Integer): Boolean;
|
||||||
var
|
var
|
||||||
OrigStart : Integer;
|
OrigStart : Integer;
|
||||||
OrigLen : Integer;
|
OrigLen : Integer;
|
||||||
|
hInfo : TScrollInfo;
|
||||||
|
vInfo : TScrollInfo;
|
||||||
|
hVisible : Boolean;
|
||||||
|
vVisible : Boolean;
|
||||||
begin
|
begin
|
||||||
if not Assigned(RichEditManager) or not Assigned(AWinControl) then begin
|
if not Assigned(RichEditManager) or not Assigned(AWinControl) then begin
|
||||||
Result := false;
|
Result := false;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
RichEditManager.GetSelection(AWinControl.Handle, OrigStart, OrigLen);
|
RichEditManager.GetSelection(AWinControl.Handle, OrigStart, OrigLen);
|
||||||
LockRedraw(AWinControl.Handle);
|
LockRedraw(AWinControl.Handle);
|
||||||
|
InitScrollInfo(hInfo);
|
||||||
|
InitScrollInfo(vInfo);
|
||||||
|
hVisible:=GetScrollbarVisible(AWinControl.Handle, SB_Horz);
|
||||||
|
vVisible:=GetScrollbarVisible(AWinControl.Handle, SB_Vert);
|
||||||
|
GetScrollInfo(AWinControl.Handle, SB_Horz, hInfo);
|
||||||
|
GetScrollInfo(AWinControl.Handle, SB_Vert, vInfo);
|
||||||
|
|
||||||
RichEditManager.SetSelection(AWinControl.Handle, TextStart, 1);
|
RichEditManager.SetSelection(AWinControl.Handle, TextStart, 1);
|
||||||
Result := RichEditManager.GetStyleRange(AWinControl.Handle, TextStart, RangeStart, RangeLen);
|
try
|
||||||
|
Result := RichEditManager.GetStyleRange(AWinControl.Handle, TextStart, RangeStart, RangeLen);
|
||||||
|
except
|
||||||
|
end;
|
||||||
|
|
||||||
|
if hVisible then SetScrollInfo(AWinControl.Handle, SB_Horz, hInfo, false);
|
||||||
|
if vVisible then SetScrollInfo(AWinControl.Handle, SB_Vert, vInfo, false);
|
||||||
RichEditManager.SetSelection(AWinControl.Handle, OrigStart, OrigLen);
|
RichEditManager.SetSelection(AWinControl.Handle, OrigStart, OrigLen);
|
||||||
UnlockRedraw(AWinControl.Handle);
|
UnlockRedraw(AWinControl.Handle, false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TWin32WSCustomRichMemo.LoadRichText(
|
class function TWin32WSCustomRichMemo.LoadRichText(
|
||||||
|
@ -183,13 +183,19 @@ begin
|
|||||||
Result := true;
|
Result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
type
|
||||||
|
gettextlengthex = packed record
|
||||||
|
flags : DWORD;
|
||||||
|
codepage : LongWord;
|
||||||
|
end;
|
||||||
|
Tgettextlengthex = gettextlengthex;
|
||||||
|
|
||||||
class function TRichEditManager.GetStyleRange(RichEditWnd: Handle; TextStart: Integer;
|
class function TRichEditManager.GetStyleRange(RichEditWnd: Handle; TextStart: Integer;
|
||||||
var RangeStart, RangeLen: Integer): Boolean;
|
var RangeStart, RangeLen: Integer): Boolean;
|
||||||
var
|
var
|
||||||
len : integer;
|
len : integer;
|
||||||
fmt : TCHARFORMAT;
|
fmt : TCHARFORMAT;
|
||||||
textlen : TGETTEXTEX;
|
textlen : Tgettextlengthex;
|
||||||
sel : TCHARRANGE;
|
sel : TCHARRANGE;
|
||||||
d : Integer;
|
d : Integer;
|
||||||
last : Integer;
|
last : Integer;
|
||||||
|
Reference in New Issue
Block a user