You've already forked lazarus-ccr
richmemo: modified patch by Silvio Clécio (#30852). (removed the use of Default() intrinsic, since it's not available in FPC 2.6.4. It's also a responsibility of GetTextAttributes function to fully initialized TFontParams structure).
* added SaveRTFFile function to utilities * modified IDE RTF editor to allow saving a file git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5305 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -6,27 +6,26 @@ object RTFEditDialog: TRTFEditDialog
|
||||
Caption = 'Rich Text Edit Dialog'
|
||||
ClientHeight = 275
|
||||
ClientWidth = 538
|
||||
OnResize = FormResize
|
||||
LCLVersion = '1.3'
|
||||
LCLVersion = '1.7'
|
||||
object btnLoad: TButton
|
||||
Left = 455
|
||||
Left = 8
|
||||
Height = 25
|
||||
Top = 8
|
||||
Top = 243
|
||||
Width = 75
|
||||
Anchors = [akTop, akRight]
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'Load'
|
||||
OnClick = btnLoadClick
|
||||
TabOrder = 0
|
||||
TabOrder = 1
|
||||
end
|
||||
object btnClear: TButton
|
||||
Left = 376
|
||||
Left = 168
|
||||
Height = 25
|
||||
Top = 8
|
||||
Top = 243
|
||||
Width = 75
|
||||
Anchors = [akTop, akRight]
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'Clear'
|
||||
OnClick = btnClearClick
|
||||
TabOrder = 1
|
||||
TabOrder = 3
|
||||
end
|
||||
object RichMemo1: TRichMemo
|
||||
Left = 8
|
||||
@ -38,28 +37,30 @@ object RTFEditDialog: TRTFEditDialog
|
||||
Lines.Strings = (
|
||||
'RichMemo1'
|
||||
)
|
||||
OnChange = RichMemo1Change
|
||||
ScrollBars = ssAutoBoth
|
||||
TabOrder = 2
|
||||
TabOrder = 0
|
||||
ZoomFactor = 1
|
||||
end
|
||||
object btnOk: TButton
|
||||
Left = 8
|
||||
Left = 376
|
||||
Height = 25
|
||||
Top = 243
|
||||
Width = 75
|
||||
Anchors = [akLeft, akBottom]
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'OK'
|
||||
ModalResult = 1
|
||||
TabOrder = 3
|
||||
TabOrder = 4
|
||||
end
|
||||
object btnCancel: TButton
|
||||
Left = 88
|
||||
Left = 455
|
||||
Height = 25
|
||||
Top = 243
|
||||
Width = 75
|
||||
Anchors = [akLeft, akBottom]
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'Cancel'
|
||||
ModalResult = 2
|
||||
TabOrder = 4
|
||||
TabOrder = 5
|
||||
end
|
||||
object btnJA: TSpeedButton
|
||||
Left = 288
|
||||
@ -246,6 +247,17 @@ object RTFEditDialog: TRTFEditDialog
|
||||
Caption = 'Color'
|
||||
OnClick = btnColorClick
|
||||
end
|
||||
object btnSave: TButton
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 88
|
||||
Height = 25
|
||||
Top = 243
|
||||
Width = 75
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'Save'
|
||||
OnClick = btnSaveClick
|
||||
TabOrder = 2
|
||||
end
|
||||
object RtfOpenDialog: TOpenDialog
|
||||
Filter = 'Rich-text file (*.rtf)|*.rtf|Any file (*.*)|*.*'
|
||||
left = 32
|
||||
@ -284,4 +296,10 @@ object RTFEditDialog: TRTFEditDialog
|
||||
left = 32
|
||||
top = 64
|
||||
end
|
||||
object RtfSaveDialog: TSaveDialog
|
||||
Filter = 'Rich-text file (*.rtf)|*.rtf'
|
||||
Options = [ofOverwritePrompt, ofEnableSizing, ofViewDetail]
|
||||
left = 120
|
||||
top = 168
|
||||
end
|
||||
end
|
||||
|
@ -5,8 +5,7 @@ unit RtfEditPropDialog;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
||||
Buttons, RichMemo, RichMemoUtils;
|
||||
SysUtils, Forms, Graphics, Dialogs, StdCtrls, Buttons, RichMemo, RichMemoUtils;
|
||||
|
||||
type
|
||||
|
||||
@ -21,6 +20,7 @@ type
|
||||
btnClear: TButton;
|
||||
btnOk: TButton;
|
||||
btnCancel: TButton;
|
||||
btnSave: TButton;
|
||||
ColorDialog1: TColorDialog;
|
||||
FontDialog1: TFontDialog;
|
||||
RtfOpenDialog: TOpenDialog;
|
||||
@ -30,6 +30,7 @@ type
|
||||
btnUnderline: TSpeedButton;
|
||||
btnFont: TSpeedButton;
|
||||
btnColor: TSpeedButton;
|
||||
RtfSaveDialog: TSaveDialog;
|
||||
procedure btnCAClick(Sender: TObject);
|
||||
procedure btnClearClick(Sender: TObject);
|
||||
procedure btnItalicClick(Sender: TObject);
|
||||
@ -37,23 +38,19 @@ type
|
||||
procedure btnLAClick(Sender: TObject);
|
||||
procedure btnLoadClick(Sender: TObject);
|
||||
procedure btnRAClick(Sender: TObject);
|
||||
procedure FormResize(Sender: TObject);
|
||||
procedure btnSaveClick(Sender: TObject);
|
||||
procedure btnBoldClick(Sender: TObject);
|
||||
procedure btnUnderlineClick(Sender: TObject);
|
||||
procedure btnFontClick(Sender: TObject);
|
||||
procedure btnColorClick(Sender: TObject);
|
||||
procedure RichMemo1Change(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
procedure FontStyleModify(fs: TFontStyle);
|
||||
public
|
||||
{ public declarations }
|
||||
|
||||
end;
|
||||
|
||||
var
|
||||
RTFEditDialog: TRTFEditDialog = nil;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
@ -75,6 +72,7 @@ end;
|
||||
procedure TRTFEditDialog.btnClearClick(Sender: TObject);
|
||||
begin
|
||||
RichMemo1.Clear;
|
||||
RichMemo1Change(Sender);
|
||||
end;
|
||||
|
||||
procedure TRTFEditDialog.btnItalicClick(Sender: TObject);
|
||||
@ -100,20 +98,12 @@ begin
|
||||
RichMemo1.SelLength, paRight);
|
||||
end;
|
||||
|
||||
procedure TRTFEditDialog.FormResize(Sender: TObject);
|
||||
const
|
||||
SpaceOffset = 4;
|
||||
var
|
||||
w2 : integer;
|
||||
procedure TRTFEditDialog.btnSaveClick(Sender: TObject);
|
||||
begin
|
||||
w2:=RichMemo1.ClientWidth div 2;
|
||||
{$ifdef darwin}
|
||||
btnCancel.Left:=w2 - SpaceOffset - btnCancel.Width;
|
||||
btnOk.Left:= w2 + SpaceOffset;
|
||||
{$else}
|
||||
btnOk.Left:=w2 - SpaceOffset - btnOk.Width;
|
||||
btnCancel.Left:= w2 + SpaceOffset;
|
||||
{$endif}
|
||||
if RtfSaveDialog.FileName = '' then
|
||||
RtfSaveDialog.FileName := 'New document.rtf';
|
||||
if RtfSaveDialog.Execute and (RtfSaveDialog.FileName <> '') then
|
||||
SaveRTFFile( RichMemo1, RtfSaveDialog.FileName);
|
||||
end;
|
||||
|
||||
procedure TRTFEditDialog.btnBoldClick(Sender: TObject);
|
||||
@ -156,6 +146,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRTFEditDialog.RichMemo1Change(Sender: TObject);
|
||||
begin
|
||||
btnSave.Enabled := RichMemo1.Lines.Count > 0;
|
||||
end;
|
||||
|
||||
procedure TRTFEditDialog.FontStyleModify(fs: TFontStyle);
|
||||
var
|
||||
f : TFontParams;
|
||||
|
@ -50,6 +50,8 @@ function InsertImageFromFileNoResize (const ARichMemo: TCustomRichMemo; APos: In
|
||||
|
||||
procedure LoadRTFFile(const ARichMemo: TCustomRichMemo; const FileNameUTF8: string);
|
||||
|
||||
procedure SaveRTFFile(const ARichMemo: TCustomRichMemo; const FileNameUTF8: string);
|
||||
|
||||
procedure InsertStyledText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; AStyle: TFontStyles;
|
||||
InsPos : Integer = -1 );
|
||||
procedure InsertColorStyledText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; AColor: TColor; AStyle: TFontStyles;
|
||||
@ -138,6 +140,19 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure SaveRTFFile(const ARichMemo: TCustomRichMemo; const FileNameUTF8: string);
|
||||
var
|
||||
fs : TFileStream;
|
||||
begin
|
||||
if not Assigned(ARichMemo) then Exit;
|
||||
fs:= TFileStream.Create( UTF8Decode(FileNameUTF8), fmCreate);
|
||||
try
|
||||
ARichMemo.SaveRichText(fs);
|
||||
finally
|
||||
fs.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
if not Assigned(InsertImageFromFile) then
|
||||
|
Reference in New Issue
Block a user