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 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;
|
||||
j := TextStart + TextLength;
|
||||
while i < j do begin
|
||||
|
@ -72,6 +72,11 @@ type
|
||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; override;
|
||||
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
|
||||
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;
|
||||
const Params: TIntFontParams); override;
|
||||
class procedure SetHideSelection(const ACustomEdit: TCustomEdit; AHideSelection: Boolean); override;
|
||||
@ -583,6 +588,37 @@ begin
|
||||
RichEditManager.SetEventMask(AWinControl.Handle,eventmask);
|
||||
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(
|
||||
const ACustomEdit: TCustomEdit; AHideSelection: Boolean);
|
||||
|
@ -164,7 +164,8 @@ type
|
||||
|
||||
class function GetTextLength(RichEditWnd: Handle): Integer;
|
||||
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 procedure SetTextUIStyle(RichEditWnd: Handle; const ui: TTextUIParam); virtual;
|
||||
class function GetTextUIStyle(RichEditWnd: Handle; var ui: TTextUIParam): Boolean; virtual;
|
||||
@ -377,7 +378,7 @@ begin
|
||||
end;
|
||||
|
||||
class function TRichEditManager.SetSelectedTextStyle(RichEditWnd: Handle;
|
||||
Params: TIntFontParams): Boolean;
|
||||
Params: TIntFontParams; useMask: Boolean; AModifyMask: TTextModifyMask): Boolean;
|
||||
var
|
||||
w : WPARAM;
|
||||
fmt : TCHARFORMAT2;
|
||||
@ -391,26 +392,36 @@ begin
|
||||
|
||||
FillChar(fmt, sizeof(fmt), 0);
|
||||
fmt.cbSize := sizeof(fmt);
|
||||
|
||||
fmt.dwMask := fmt.dwMask or CFM_COLOR;
|
||||
fmt.crTextColor := Params.Color;
|
||||
|
||||
fmt.dwMask := fmt.dwMask or CFM_FACE;
|
||||
// keep last char for Null-termination?
|
||||
CopyStringToCharArray(Params.Name, fmt.szFaceName, LF_FACESIZE-1);
|
||||
|
||||
fmt.dwMask := fmt.dwMask or CFM_SIZE;
|
||||
fmt.yHeight := Params.Size * TwipsInFontSize;
|
||||
|
||||
fmt.dwMask := fmt.dwMask or CFM_EFFECTS or CFM_SUBSCRIPT or CFM_SUPERSCRIPT;
|
||||
fmt.dwEffects := FontStylesToEffects(Params.Style) or VScriptPosToEffects(Params.VScriptPos);
|
||||
if not useMask or (tmm_Color in AModifyMask) then begin
|
||||
fmt.dwMask := fmt.dwMask or CFM_COLOR;
|
||||
fmt.crTextColor := Params.Color;
|
||||
end;
|
||||
|
||||
if Params.HasBkClr then begin
|
||||
fmt.dwMask := fmt.dwMask or CFM_BACKCOLOR;
|
||||
fmt.crBackColor := Params.BkColor;
|
||||
end else begin
|
||||
fmt.dwMask := fmt.dwMask or CFM_BACKCOLOR;
|
||||
fmt.dwEffects := fmt.dwEffects or CFE_AUTOBACKCOLOR;
|
||||
if not useMask or (tmm_Name in AModifyMask) then begin
|
||||
fmt.dwMask := fmt.dwMask or CFM_FACE;
|
||||
// keep last char for Null-termination?
|
||||
CopyStringToCharArray(Params.Name, fmt.szFaceName, LF_FACESIZE-1);
|
||||
end;
|
||||
|
||||
if not useMask or (tmm_Size in AModifyMask) then begin
|
||||
fmt.dwMask := fmt.dwMask or CFM_SIZE;
|
||||
fmt.yHeight := Params.Size * TwipsInFontSize;
|
||||
end;
|
||||
|
||||
if not useMask or (tmm_Styles in AModifyMask) then begin
|
||||
fmt.dwMask := fmt.dwMask or CFM_EFFECTS or CFM_SUBSCRIPT or CFM_SUPERSCRIPT;
|
||||
fmt.dwEffects := FontStylesToEffects(Params.Style) or VScriptPosToEffects(Params.VScriptPos);
|
||||
end;
|
||||
|
||||
if not useMask or (tmm_BackColor in AModifyMask) then begin
|
||||
if Params.HasBkClr then begin
|
||||
fmt.dwMask := fmt.dwMask or CFM_BACKCOLOR;
|
||||
fmt.crBackColor := Params.BkColor;
|
||||
end else begin
|
||||
fmt.dwMask := fmt.dwMask or CFM_BACKCOLOR;
|
||||
fmt.dwEffects := fmt.dwEffects or CFE_AUTOBACKCOLOR;
|
||||
end;
|
||||
end;
|
||||
|
||||
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 GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
|
||||
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;
|
||||
const Params: TIntFontParams); virtual;
|
||||
class function GetParaAlignment(const AWinControl: TWinControl; TextStart: Integer;
|
||||
@ -155,9 +160,22 @@ begin
|
||||
Result := false;
|
||||
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;
|
||||
TextStart, TextLen: Integer;
|
||||
{Mask: TTextStyleMask;} const Params: TIntFontParams);
|
||||
const Params: TIntFontParams);
|
||||
begin
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user