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'
|
Caption = 'Rich Text Edit Dialog'
|
||||||
ClientHeight = 275
|
ClientHeight = 275
|
||||||
ClientWidth = 538
|
ClientWidth = 538
|
||||||
OnResize = FormResize
|
LCLVersion = '1.7'
|
||||||
LCLVersion = '1.3'
|
|
||||||
object btnLoad: TButton
|
object btnLoad: TButton
|
||||||
Left = 455
|
Left = 8
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 8
|
Top = 243
|
||||||
Width = 75
|
Width = 75
|
||||||
Anchors = [akTop, akRight]
|
Anchors = [akLeft, akBottom]
|
||||||
Caption = 'Load'
|
Caption = 'Load'
|
||||||
OnClick = btnLoadClick
|
OnClick = btnLoadClick
|
||||||
TabOrder = 0
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
object btnClear: TButton
|
object btnClear: TButton
|
||||||
Left = 376
|
Left = 168
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 8
|
Top = 243
|
||||||
Width = 75
|
Width = 75
|
||||||
Anchors = [akTop, akRight]
|
Anchors = [akLeft, akBottom]
|
||||||
Caption = 'Clear'
|
Caption = 'Clear'
|
||||||
OnClick = btnClearClick
|
OnClick = btnClearClick
|
||||||
TabOrder = 1
|
TabOrder = 3
|
||||||
end
|
end
|
||||||
object RichMemo1: TRichMemo
|
object RichMemo1: TRichMemo
|
||||||
Left = 8
|
Left = 8
|
||||||
@@ -38,28 +37,30 @@ object RTFEditDialog: TRTFEditDialog
|
|||||||
Lines.Strings = (
|
Lines.Strings = (
|
||||||
'RichMemo1'
|
'RichMemo1'
|
||||||
)
|
)
|
||||||
|
OnChange = RichMemo1Change
|
||||||
ScrollBars = ssAutoBoth
|
ScrollBars = ssAutoBoth
|
||||||
TabOrder = 2
|
TabOrder = 0
|
||||||
|
ZoomFactor = 1
|
||||||
end
|
end
|
||||||
object btnOk: TButton
|
object btnOk: TButton
|
||||||
Left = 8
|
Left = 376
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 243
|
Top = 243
|
||||||
Width = 75
|
Width = 75
|
||||||
Anchors = [akLeft, akBottom]
|
Anchors = [akRight, akBottom]
|
||||||
Caption = 'OK'
|
Caption = 'OK'
|
||||||
ModalResult = 1
|
ModalResult = 1
|
||||||
TabOrder = 3
|
TabOrder = 4
|
||||||
end
|
end
|
||||||
object btnCancel: TButton
|
object btnCancel: TButton
|
||||||
Left = 88
|
Left = 455
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 243
|
Top = 243
|
||||||
Width = 75
|
Width = 75
|
||||||
Anchors = [akLeft, akBottom]
|
Anchors = [akRight, akBottom]
|
||||||
Caption = 'Cancel'
|
Caption = 'Cancel'
|
||||||
ModalResult = 2
|
ModalResult = 2
|
||||||
TabOrder = 4
|
TabOrder = 5
|
||||||
end
|
end
|
||||||
object btnJA: TSpeedButton
|
object btnJA: TSpeedButton
|
||||||
Left = 288
|
Left = 288
|
||||||
@@ -246,6 +247,17 @@ object RTFEditDialog: TRTFEditDialog
|
|||||||
Caption = 'Color'
|
Caption = 'Color'
|
||||||
OnClick = btnColorClick
|
OnClick = btnColorClick
|
||||||
end
|
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
|
object RtfOpenDialog: TOpenDialog
|
||||||
Filter = 'Rich-text file (*.rtf)|*.rtf|Any file (*.*)|*.*'
|
Filter = 'Rich-text file (*.rtf)|*.rtf|Any file (*.*)|*.*'
|
||||||
left = 32
|
left = 32
|
||||||
@@ -284,4 +296,10 @@ object RTFEditDialog: TRTFEditDialog
|
|||||||
left = 32
|
left = 32
|
||||||
top = 64
|
top = 64
|
||||||
end
|
end
|
||||||
|
object RtfSaveDialog: TSaveDialog
|
||||||
|
Filter = 'Rich-text file (*.rtf)|*.rtf'
|
||||||
|
Options = [ofOverwritePrompt, ofEnableSizing, ofViewDetail]
|
||||||
|
left = 120
|
||||||
|
top = 168
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@@ -5,8 +5,7 @@ unit RtfEditPropDialog;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
|
SysUtils, Forms, Graphics, Dialogs, StdCtrls, Buttons, RichMemo, RichMemoUtils;
|
||||||
Buttons, RichMemo, RichMemoUtils;
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@@ -21,6 +20,7 @@ type
|
|||||||
btnClear: TButton;
|
btnClear: TButton;
|
||||||
btnOk: TButton;
|
btnOk: TButton;
|
||||||
btnCancel: TButton;
|
btnCancel: TButton;
|
||||||
|
btnSave: TButton;
|
||||||
ColorDialog1: TColorDialog;
|
ColorDialog1: TColorDialog;
|
||||||
FontDialog1: TFontDialog;
|
FontDialog1: TFontDialog;
|
||||||
RtfOpenDialog: TOpenDialog;
|
RtfOpenDialog: TOpenDialog;
|
||||||
@@ -30,6 +30,7 @@ type
|
|||||||
btnUnderline: TSpeedButton;
|
btnUnderline: TSpeedButton;
|
||||||
btnFont: TSpeedButton;
|
btnFont: TSpeedButton;
|
||||||
btnColor: TSpeedButton;
|
btnColor: TSpeedButton;
|
||||||
|
RtfSaveDialog: TSaveDialog;
|
||||||
procedure btnCAClick(Sender: TObject);
|
procedure btnCAClick(Sender: TObject);
|
||||||
procedure btnClearClick(Sender: TObject);
|
procedure btnClearClick(Sender: TObject);
|
||||||
procedure btnItalicClick(Sender: TObject);
|
procedure btnItalicClick(Sender: TObject);
|
||||||
@@ -37,23 +38,19 @@ type
|
|||||||
procedure btnLAClick(Sender: TObject);
|
procedure btnLAClick(Sender: TObject);
|
||||||
procedure btnLoadClick(Sender: TObject);
|
procedure btnLoadClick(Sender: TObject);
|
||||||
procedure btnRAClick(Sender: TObject);
|
procedure btnRAClick(Sender: TObject);
|
||||||
procedure FormResize(Sender: TObject);
|
procedure btnSaveClick(Sender: TObject);
|
||||||
procedure btnBoldClick(Sender: TObject);
|
procedure btnBoldClick(Sender: TObject);
|
||||||
procedure btnUnderlineClick(Sender: TObject);
|
procedure btnUnderlineClick(Sender: TObject);
|
||||||
procedure btnFontClick(Sender: TObject);
|
procedure btnFontClick(Sender: TObject);
|
||||||
procedure btnColorClick(Sender: TObject);
|
procedure btnColorClick(Sender: TObject);
|
||||||
|
procedure RichMemo1Change(Sender: TObject);
|
||||||
private
|
private
|
||||||
{ private declarations }
|
|
||||||
procedure FontStyleModify(fs: TFontStyle);
|
procedure FontStyleModify(fs: TFontStyle);
|
||||||
public
|
|
||||||
{ public declarations }
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
RTFEditDialog: TRTFEditDialog = nil;
|
RTFEditDialog: TRTFEditDialog = nil;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
@@ -75,6 +72,7 @@ end;
|
|||||||
procedure TRTFEditDialog.btnClearClick(Sender: TObject);
|
procedure TRTFEditDialog.btnClearClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
RichMemo1.Clear;
|
RichMemo1.Clear;
|
||||||
|
RichMemo1Change(Sender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRTFEditDialog.btnItalicClick(Sender: TObject);
|
procedure TRTFEditDialog.btnItalicClick(Sender: TObject);
|
||||||
@@ -100,20 +98,12 @@ begin
|
|||||||
RichMemo1.SelLength, paRight);
|
RichMemo1.SelLength, paRight);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRTFEditDialog.FormResize(Sender: TObject);
|
procedure TRTFEditDialog.btnSaveClick(Sender: TObject);
|
||||||
const
|
|
||||||
SpaceOffset = 4;
|
|
||||||
var
|
|
||||||
w2 : integer;
|
|
||||||
begin
|
begin
|
||||||
w2:=RichMemo1.ClientWidth div 2;
|
if RtfSaveDialog.FileName = '' then
|
||||||
{$ifdef darwin}
|
RtfSaveDialog.FileName := 'New document.rtf';
|
||||||
btnCancel.Left:=w2 - SpaceOffset - btnCancel.Width;
|
if RtfSaveDialog.Execute and (RtfSaveDialog.FileName <> '') then
|
||||||
btnOk.Left:= w2 + SpaceOffset;
|
SaveRTFFile( RichMemo1, RtfSaveDialog.FileName);
|
||||||
{$else}
|
|
||||||
btnOk.Left:=w2 - SpaceOffset - btnOk.Width;
|
|
||||||
btnCancel.Left:= w2 + SpaceOffset;
|
|
||||||
{$endif}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRTFEditDialog.btnBoldClick(Sender: TObject);
|
procedure TRTFEditDialog.btnBoldClick(Sender: TObject);
|
||||||
@@ -156,6 +146,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TRTFEditDialog.RichMemo1Change(Sender: TObject);
|
||||||
|
begin
|
||||||
|
btnSave.Enabled := RichMemo1.Lines.Count > 0;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TRTFEditDialog.FontStyleModify(fs: TFontStyle);
|
procedure TRTFEditDialog.FontStyleModify(fs: TFontStyle);
|
||||||
var
|
var
|
||||||
f : TFontParams;
|
f : TFontParams;
|
||||||
|
@@ -50,6 +50,8 @@ function InsertImageFromFileNoResize (const ARichMemo: TCustomRichMemo; APos: In
|
|||||||
|
|
||||||
procedure LoadRTFFile(const ARichMemo: TCustomRichMemo; const FileNameUTF8: string);
|
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;
|
procedure InsertStyledText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; AStyle: TFontStyles;
|
||||||
InsPos : Integer = -1 );
|
InsPos : Integer = -1 );
|
||||||
procedure InsertColorStyledText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; AColor: TColor; AStyle: TFontStyles;
|
procedure InsertColorStyledText(const ARichMemo: TCustomRichMemo; const TextUTF8: String; AColor: TColor; AStyle: TFontStyles;
|
||||||
@@ -138,6 +140,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
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
|
initialization
|
||||||
if not Assigned(InsertImageFromFile) then
|
if not Assigned(InsertImageFromFile) then
|
||||||
|
Reference in New Issue
Block a user