[Example] How to paste RVF without images
Posted: Thu Feb 16, 2012 4:01 pm
Code: Select all
uses CRVData, RVMarker, RVItem;
// Removing all images from RVData
procedure RemoveImages(RVData: TCustomRVData);
var i,r,c: Integer;
table: TRVTableItemInfo;
{..............................................}
procedure DeleteItem(i: Integer);
var SameAsPrev, BR, PageBreak: Boolean;
begin
SameAsPrev := RVData.GetItem(i).SameAsPrev;
BR := RVData.GetItem(i).BR;
PageBreak := RVData.GetItem(i).PageBreakBefore;
RVData.DeleteItems(i, 1);
if (i<RVData.ItemCount) and RVData.GetItem(i).SameAsPrev then begin
RVData.GetItem(i).SameAsPrev := SameAsPrev;
RVData.GetItem(i).BR := BR;
RVData.GetItem(i).PageBreakBefore := PageBreak;
end;
end;
{..............................................}
function ListHasImages(ListInfo: TRVListInfo): Boolean;
var i: Integer;
begin
Result := True;
for i := 0 to ListInfo.Levels.Count-1 do
if not ListInfo.Levels[i].UsesFont then
exit;
Result := False;
end;
begin
for i := RVData.ItemCount-1 downto 0 do
case RVData.GetItemStyle(i) of
rvsPicture, rvsHotPicture, rvsBullet, rvsHotspot:
DeleteItem(i);
rvsListMarker:
begin
r := TRVMarkerItemInfo(RVData.GetItem(i)).ListNo;
if (r>=0) and (r<=RVData.GetRVStyle.ListStyles.Count) and
ListHasImages(RVData.GetRVStyle.ListStyles[r]) then
DeleteItem(i);
end;
rvsTable:
begin
Table := TRVTableItemInfo(RVData.GetItem(i));
Table.State := Table.State - [rvtsInserted];
Table.BackgroundImageFileName := '';
Table.BackgroundImage := nil;
Table.BackgroundStyle := rvbsColor;
Table.State := Table.State + [rvtsInserted];
for r := 0 to Table.RowCount-1 do
for c := 0 to Table.ColCount-1 do
if Table.Cells[r,c]<>nil then begin
Table.Cells[r,c].BackgroundImageFileName := '';
Table.Cells[r,c].BackgroundImage := nil;
Table.Cells[r,c].BackgroundStyle := rvbsColor;
RemoveImages(Table.Cells[r,c].GetRVData);
end;
end;
end;
end;
// pasting RVF without images in rve
procedure PasteRVFWithoutImages(rve: TCustomRichViewEdit);
var tmprve: TRichViewEdit;
Stream: TMemoryStream;
begin
if rve.ReadOnly or not rve.CanPasteRVF then
exit;
tmprve := TRichViewEdit.Create(nil);
try
tmprve.Visible := False;
tmprve.Parent := rve.Parent;
tmprve.AssignEvents(rve);
tmprve.RVFOptions := rve.RVFOptions-[rvfoSaveTextStyles, rvfoSaveParaStyles];
tmprve.RVFParaStylesReadMode := rve.RVFParaStylesReadMode;
tmprve.RVFTextStylesReadMode := rve.RVFTextStylesReadMode;
tmprve.Style := rve.Style;
tmprve.PasteRVF;
RemoveImages(tmprve.RVData);
Stream := TMemoryStream.Create;
try
tmprve.SaveRVFToStream(Stream, False);
Stream.Position := 0;
rve.InsertRVFFromStreamEd(Stream);
finally
Stream.Free;
end;
finally
tmprve.Free;
end;
end;
// Assign this code to OnPaste event:
procedure TForm3.RichViewEdit1Paste(Sender: TCustomRichViewEdit;
var DoDefault: Boolean);
begin
if RichViewEdit1.CanPasteRVF then begin
PasteRVFWithoutImages(RichViewEdit1);
DoDefault := False;
end;
end;