richmemo: added design-time Rtf property and a property editor for it

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3806 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz
2014-11-28 15:06:44 +00:00
parent 8080fd856f
commit 385b0e79ab
6 changed files with 583 additions and 9 deletions

View File

@@ -130,7 +130,15 @@ type
property OnSelectionChange: TNotifyEvent read fOnSelectionChange write fOnSelectionChange;
end;
{ TRichMemo }
TRichMemo = class(TCustomRichMemo)
protected
// this is "design-time" property
fRtf: string; // initial RichText
function GetRTF: string; virtual;
procedure SetRTF(const AValue: string); virtual;
procedure UpdateRichMemo; override;
published
property Align;
property Alignment;
@@ -178,6 +186,7 @@ type
property PopupMenu;
property ParentShowHint;
property ReadOnly;
property Rtf: string read GetRTF write SetRTF;
property ScrollBars;
property ShowHint;
property TabOrder;
@@ -246,6 +255,59 @@ begin
FillChar(n, sizeof(n), 0);
end;
{ TRichMemo }
function TRichMemo.GetRTF: string;
var
st : TStringStream;
begin
if (csDesigning in ComponentState) or not HandleAllocated then
Result:=fRTF
else begin
try
st := TStringStream.Create('');
try
SaveRichText(st);
Result:=st.DataString;
finally
st.Free;
end;
except
Result:='';
end;
end;
end;
procedure TRichMemo.SetRTF(const AValue: string);
var
st : TStringStream;
begin
if (csDesigning in ComponentState) or not HandleAllocated then
fRTF:=AValue;
if HandleAllocated then
try
st := TStringStream.Create(AValue);
try
LoadRichText(st);
finally
st.Free;
end;
except
end;
if ([csDesigning, csLoading] * ComponentState = []) and HandleAllocated then begin
fRTF:=''; // reduce memory usage in run-time
end;
end;
procedure TRichMemo.UpdateRichMemo;
begin
inherited UpdateRichMemo;
// if fRTF is blank, Text property would be used
if fRTF<>'' then SetRTF(fRTF);
end;
{ TCustomRichMemo }
procedure TCustomRichMemo.SetHideSelection(AValue: Boolean);