lazarus-ccr/components/richmemo/richmemoutils.pas
skalogryz 6946c8309a richmemo: added loadrtffile function
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3770 8e941d3f-bd1b-0410-a28a-d453659cc2b4
2014-11-24 07:53:27 +00:00

89 lines
3.0 KiB
ObjectPascal

{
richmemoutils.pas
Author: Dmitry 'skalogryz' Boyarintsev
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
unit RichMemoUtils;
interface
{$mode objfpc}{$h+}
uses
Types, SysUtils, Classes, LazFileUtils, RichMemo;
const
NoResize : TSize = ( cx: 0; cy : 0 );
var
{ Disclaimer: the function would insert an image file into RichMemo
(if implemented by the widgetset) But in a very inefficient way.
The image would be read again and the memory would be re-allocated for
the image every time. So please, don't use it for smileys in
your chat instant messaging. A better API (with data caching) is considered.
(That's why this method is not part of TCustomRichMemo class)
APos - position in the text
AImgSize - size to be inserted (in POINTS, not pixels!).
if both width and height are 0, the image would not be resized at all.
}
InsertImageFromFile : function (const ARichMemo: TCustomRichMemo; APos: Integer;
const FileNameUTF8: string;
const AImgSize: TSize
): Boolean = nil;
function InsertImageFromFileNoResize (const ARichMemo: TCustomRichMemo; APos: Integer;
const FileNameUTF8: string): Boolean;
procedure LoadRTFFile(const ARichMemo: TCustomRichMemo; const FileNameUTF8: string);
implementation
function InsertImageFileDummy(const ARichMemo: TCustomRichMemo; APos: Integer;
const FileNameUTF8: string;
const AImgSize: TSize): Boolean;
begin
Result:=false;
end;
function InsertImageFromFileNoResize (const ARichMemo: TCustomRichMemo; APos: Integer;
const FileNameUTF8: string): Boolean;
begin
Result:=InsertImageFromFile(ARichMemo, APos, FileNameUTF8, NoResize);
end;
procedure LoadRTFFile(const ARichMemo: TCustomRichMemo; const FileNameUTF8: string);
var
fs : THandleStream;
h : THandle;
begin
if not Assigned(ARichMemo) then Exit;
h:= FileOpenUTF8(FileNameUTF8, fmShareDenyNone or fmOpenRead);
fs := THandleStream.Create( h );
try
ARichMemo.LoadRichText(fs);
finally
fs.Free;
end;
FileClose(h);
end;
initialization
if not Assigned(InsertImageFromFile) then
InsertImageFromFile := @InsertImageFileDummy;
end.