richmemo: efficient way of setting attributes
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4377 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
180a1d049d
commit
3e0fabe544
@ -850,6 +850,16 @@ begin
|
|||||||
|
|
||||||
if (ModifyMask = []) or (TextLength = 0) then Exit;
|
if (ModifyMask = []) or (TextLength = 0) then Exit;
|
||||||
|
|
||||||
|
if TWSCustomRichMemoClass(WidgetSetClass).isInternalChange(Self, ModifyMask) then
|
||||||
|
begin
|
||||||
|
// more effecient from OS view
|
||||||
|
TWSCustomRichMemoClass(WidgetSetClass).SetTextAttributesInternal(Self,
|
||||||
|
TextStart, TextLength, ModifyMask, fnt);
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// manually looping from text ranges and re-applying
|
||||||
|
// all the style. changing only the ones that in the mask
|
||||||
i := TextStart;
|
i := TextStart;
|
||||||
j := TextStart + TextLength;
|
j := TextStart + TextLength;
|
||||||
while i < j do begin
|
while i < j do begin
|
||||||
|
@ -72,6 +72,11 @@ type
|
|||||||
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;
|
||||||
|
|
||||||
|
class function isInternalChange(const AWinControl: TWinControl; Params: TTextModifyMask): Boolean; override;
|
||||||
|
class procedure SetTextAttributesInternal(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
|
const AModifyMask: TTextModifyMask; const Params: TIntFontParams); override;
|
||||||
|
|
||||||
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
const Params: TIntFontParams); override;
|
const Params: TIntFontParams); override;
|
||||||
class procedure SetHideSelection(const ACustomEdit: TCustomEdit; AHideSelection: Boolean); override;
|
class procedure SetHideSelection(const ACustomEdit: TCustomEdit; AHideSelection: Boolean); override;
|
||||||
@ -583,6 +588,37 @@ begin
|
|||||||
RichEditManager.SetEventMask(AWinControl.Handle,eventmask);
|
RichEditManager.SetEventMask(AWinControl.Handle,eventmask);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TWin32WSCustomRichMemo.isInternalChange(
|
||||||
|
const AWinControl: TWinControl; Params: TTextModifyMask): Boolean;
|
||||||
|
begin
|
||||||
|
Result:=True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TWin32WSCustomRichMemo.SetTextAttributesInternal(
|
||||||
|
const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
|
const AModifyMask: TTextModifyMask; const Params: TIntFontParams);
|
||||||
|
var
|
||||||
|
OrigStart : Integer;
|
||||||
|
OrigLen : Integer;
|
||||||
|
eventmask : longword;
|
||||||
|
NeedLock : Boolean;
|
||||||
|
begin
|
||||||
|
eventmask := RichEditManager.SetEventMask(AWinControl.Handle, 0);
|
||||||
|
RichEditManager.GetSelection(AWinControl.Handle, OrigStart, OrigLen);
|
||||||
|
|
||||||
|
NeedLock := (OrigStart <> TextStart) or (OrigLen <> TextLen);
|
||||||
|
if NeedLock then begin
|
||||||
|
LockRedraw( TCustomRichMemo(AWinControl), AWinControl.Handle);
|
||||||
|
RichEditManager.SetSelection(AWinControl.Handle, TextStart, TextLen);
|
||||||
|
RichEditManager.SetSelectedTextStyle(AWinControl.Handle, Params, True, AModifyMask);
|
||||||
|
RichEditManager.SetSelection(AWinControl.Handle, OrigStart, OrigLen);
|
||||||
|
UnlockRedraw( TCustomRichMemo(AWinControl), AWinControl.Handle);
|
||||||
|
end else
|
||||||
|
RichEditManager.SetSelectedTextStyle(AWinControl.Handle, Params, True, AModifyMask);
|
||||||
|
|
||||||
|
RichEditManager.SetEventMask(AWinControl.Handle, eventmask);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
class procedure TWin32WSCustomRichMemo.SetHideSelection(
|
class procedure TWin32WSCustomRichMemo.SetHideSelection(
|
||||||
const ACustomEdit: TCustomEdit; AHideSelection: Boolean);
|
const ACustomEdit: TCustomEdit; AHideSelection: Boolean);
|
||||||
|
@ -164,7 +164,8 @@ type
|
|||||||
|
|
||||||
class function GetTextLength(RichEditWnd: Handle): Integer;
|
class function GetTextLength(RichEditWnd: Handle): Integer;
|
||||||
class function SetDefaultTextStyle(RichEditWnd: Handle; Params: TIntFontParams): Boolean; virtual;
|
class function SetDefaultTextStyle(RichEditWnd: Handle; Params: TIntFontParams): Boolean; virtual;
|
||||||
class function SetSelectedTextStyle(RichEditWnd: Handle; Params: TIntFontParams): Boolean; virtual;
|
class function SetSelectedTextStyle(RichEditWnd: Handle; Params: TIntFontParams;
|
||||||
|
useMask: Boolean = false; AModifyMask: TTextModifyMask = []): Boolean; virtual;
|
||||||
class function GetSelectedTextStyle(RichEditWnd: Handle; var Params: TIntFontParams): Boolean; virtual;
|
class function GetSelectedTextStyle(RichEditWnd: Handle; var Params: TIntFontParams): Boolean; virtual;
|
||||||
class procedure SetTextUIStyle(RichEditWnd: Handle; const ui: TTextUIParam); virtual;
|
class procedure SetTextUIStyle(RichEditWnd: Handle; const ui: TTextUIParam); virtual;
|
||||||
class function GetTextUIStyle(RichEditWnd: Handle; var ui: TTextUIParam): Boolean; virtual;
|
class function GetTextUIStyle(RichEditWnd: Handle; var ui: TTextUIParam): Boolean; virtual;
|
||||||
@ -377,7 +378,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
class function TRichEditManager.SetSelectedTextStyle(RichEditWnd: Handle;
|
class function TRichEditManager.SetSelectedTextStyle(RichEditWnd: Handle;
|
||||||
Params: TIntFontParams): Boolean;
|
Params: TIntFontParams; useMask: Boolean; AModifyMask: TTextModifyMask): Boolean;
|
||||||
var
|
var
|
||||||
w : WPARAM;
|
w : WPARAM;
|
||||||
fmt : TCHARFORMAT2;
|
fmt : TCHARFORMAT2;
|
||||||
@ -392,25 +393,35 @@ begin
|
|||||||
FillChar(fmt, sizeof(fmt), 0);
|
FillChar(fmt, sizeof(fmt), 0);
|
||||||
fmt.cbSize := sizeof(fmt);
|
fmt.cbSize := sizeof(fmt);
|
||||||
|
|
||||||
fmt.dwMask := fmt.dwMask or CFM_COLOR;
|
if not useMask or (tmm_Color in AModifyMask) then begin
|
||||||
fmt.crTextColor := Params.Color;
|
fmt.dwMask := fmt.dwMask or CFM_COLOR;
|
||||||
|
fmt.crTextColor := Params.Color;
|
||||||
|
end;
|
||||||
|
|
||||||
fmt.dwMask := fmt.dwMask or CFM_FACE;
|
if not useMask or (tmm_Name in AModifyMask) then begin
|
||||||
// keep last char for Null-termination?
|
fmt.dwMask := fmt.dwMask or CFM_FACE;
|
||||||
CopyStringToCharArray(Params.Name, fmt.szFaceName, LF_FACESIZE-1);
|
// keep last char for Null-termination?
|
||||||
|
CopyStringToCharArray(Params.Name, fmt.szFaceName, LF_FACESIZE-1);
|
||||||
|
end;
|
||||||
|
|
||||||
fmt.dwMask := fmt.dwMask or CFM_SIZE;
|
if not useMask or (tmm_Size in AModifyMask) then begin
|
||||||
fmt.yHeight := Params.Size * TwipsInFontSize;
|
fmt.dwMask := fmt.dwMask or CFM_SIZE;
|
||||||
|
fmt.yHeight := Params.Size * TwipsInFontSize;
|
||||||
|
end;
|
||||||
|
|
||||||
fmt.dwMask := fmt.dwMask or CFM_EFFECTS or CFM_SUBSCRIPT or CFM_SUPERSCRIPT;
|
if not useMask or (tmm_Styles in AModifyMask) then begin
|
||||||
fmt.dwEffects := FontStylesToEffects(Params.Style) or VScriptPosToEffects(Params.VScriptPos);
|
fmt.dwMask := fmt.dwMask or CFM_EFFECTS or CFM_SUBSCRIPT or CFM_SUPERSCRIPT;
|
||||||
|
fmt.dwEffects := FontStylesToEffects(Params.Style) or VScriptPosToEffects(Params.VScriptPos);
|
||||||
|
end;
|
||||||
|
|
||||||
if Params.HasBkClr then begin
|
if not useMask or (tmm_BackColor in AModifyMask) then begin
|
||||||
fmt.dwMask := fmt.dwMask or CFM_BACKCOLOR;
|
if Params.HasBkClr then begin
|
||||||
fmt.crBackColor := Params.BkColor;
|
fmt.dwMask := fmt.dwMask or CFM_BACKCOLOR;
|
||||||
end else begin
|
fmt.crBackColor := Params.BkColor;
|
||||||
fmt.dwMask := fmt.dwMask or CFM_BACKCOLOR;
|
end else begin
|
||||||
fmt.dwEffects := fmt.dwEffects or CFE_AUTOBACKCOLOR;
|
fmt.dwMask := fmt.dwMask or CFM_BACKCOLOR;
|
||||||
|
fmt.dwEffects := fmt.dwEffects or CFE_AUTOBACKCOLOR;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := SendMessage(RichEditWnd, EM_SETCHARFORMAT, w, PtrInt(@fmt))>0;
|
Result := SendMessage(RichEditWnd, EM_SETCHARFORMAT, w, PtrInt(@fmt))>0;
|
||||||
|
@ -59,6 +59,11 @@ type
|
|||||||
class function GetStyleRange(const AWinControl: TWinControl; TextStart: Integer; var RangeStart, RangeLen: Integer): Boolean; virtual;
|
class function GetStyleRange(const AWinControl: TWinControl; TextStart: Integer; var RangeStart, RangeLen: Integer): Boolean; virtual;
|
||||||
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
|
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
|
||||||
var Params: TIntFontParams): Boolean; virtual;
|
var Params: TIntFontParams): Boolean; virtual;
|
||||||
|
|
||||||
|
class function isInternalChange(const AWinControl: TWinControl; Params: TTextModifyMask): Boolean; virtual;
|
||||||
|
class procedure SetTextAttributesInternal(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
|
const AModifyMask: TTextModifyMask; const Params: TIntFontParams); virtual;
|
||||||
|
|
||||||
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
const Params: TIntFontParams); virtual;
|
const Params: TIntFontParams); virtual;
|
||||||
class function GetParaAlignment(const AWinControl: TWinControl; TextStart: Integer;
|
class function GetParaAlignment(const AWinControl: TWinControl; TextStart: Integer;
|
||||||
@ -155,9 +160,22 @@ begin
|
|||||||
Result := false;
|
Result := false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TWSCustomRichMemo.isInternalChange(
|
||||||
|
const AWinControl: TWinControl; Params: TTextModifyMask): Boolean;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TWSCustomRichMemo.SetTextAttributesInternal(
|
||||||
|
const AWinControl: TWinControl; TextStart, TextLen: Integer;
|
||||||
|
const AModifyMask: TTextModifyMask; const Params: TIntFontParams);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
class procedure TWSCustomRichMemo.SetTextAttributes(const AWinControl: TWinControl;
|
class procedure TWSCustomRichMemo.SetTextAttributes(const AWinControl: TWinControl;
|
||||||
TextStart, TextLen: Integer;
|
TextStart, TextLen: Integer;
|
||||||
{Mask: TTextStyleMask;} const Params: TIntFontParams);
|
const Params: TIntFontParams);
|
||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user