No exported image when cell is still edited

General TRichView support forum. Please post your questions here
Post Reply
wvd_vegt
Posts: 83
Joined: Tue Aug 30, 2005 7:39 am

No exported image when cell is still edited

Post by wvd_vegt »

Hi,

Got a small problem that when I export a TRichViewEdit to xhtml I'm not able to see any images inside a tablecell that has the cursor in it. Any idea how I can fix this?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you mean that if the caret is inside cell, images from this cell are not exported to HTML?
I cannot reproduce this problem (I tried to do it in the ActionTest demo).

Do you process OnHTMLSaveImage or OnSaveImage2 events?
wvd_vegt
Posts: 83
Joined: Tue Aug 30, 2005 7:39 am

Post by wvd_vegt »

Hi,

Not at work at the momement but i think I used both events. The disk files for the images are not created, though the links are there in xhtml.

When I move the caret to another cell it is exported correctly. Moving it back to a cell with an image in it fails again.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Probably your code in these events fails to work with editing cells.
Please post it here or send me by e-mail.
wvd_vegt
Posts: 83
Joined: Tue Aug 30, 2005 7:39 am

Post by wvd_vegt »

Hi,

Found a workaround by adding a rve.Delesect() call before saving.

But when I remove this code, it seems like the problem is solved anyway (restructured the GUI). My guess it that it was caused by the editor/cell still having focus when it was streamed. So problem fixed but I can't tell how.

The code used was (I'm saving swf and avi too) and the code is located in a TRvActionEvent (which might be the cause of the problem as the focus is still in the editor when pressed):

Code: Select all

procedure T_TaakEditor.DoPreview(rve: TRichViewEdit);
var
  ms                : TMemoryStream;
  sl                : TStringList;
  html              : IXMLDOMDocument;
  xslt              : IXMLDOMDocument;
begin
  ms := TMemoryStream.Create;
  sl := TStringList.Create;

  rve.Deselect;

  rve.OnSaveComponentToFile := rvSaveComponentToFile;
  rve.OnSaveImage2 := rvSaveImage2;
  rve.OnWriteHyperlink := rvWriteHyperlink;

  rve.RVData.Flags := rve.RVData.Flags + [rvflRoot];
  rve.SaveHTMLToStreamEx(ms,
    _Mainform.MyTempPath,
    rve.Name, ChangeFileExt(ExtractFileName(_Mainform.Storage1.FileName), '') + '_', '', '', '',
    [rvsoUTF8, rvsoXHTML]);
  ms.Seek(0, soFromBeginning);
  sl.LoadFromStream(ms);
  rve.OnWriteHyperlink := nil;
  rve.OnSaveImage2 := nil;
  rve.OnSaveComponentToFile := nil;

//some code ommited
end;

Code: Select all

procedure T_TaakEditor.rvSaveComponentToFile(Sender: TCustomRichView;
  Path: string; SaveMe: TPersistent; SaveFormat: TRVSaveFormat;
  var OutStr: string);
var
  scale             : string;
  urlStr            : string;
  Panel             : TPanel;
  Player            : TMediaPlayer;
begin
  if (SaveMe is TMyShockwaveFlash) and (saveFormat = rvsfHTML) then
    begin
      OutStr := Sender.RVData.GetNextFileName('', Path, '.swf', FlashCounter, True);
      urlStr := 'file://' + StringReplace(OutStr, '\', '/', [rfReplaceAll]);
      TMyShockwaveFlash(SaveMe).SaveFlash(OutStr);
      case TMyShockwaveFlash(SaveMe).ScaleMode of
        0: scale := 'ShowAll';
        1: scale := 'NoBorder';
        else
          scale := 'ExactFit';
      end;
      OutStr := Format('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
        'codebase="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0" ' +
        'width=%d height=%d>' +
        '<PARAM NAME="Quality" VALUE="high">' +
        '<PARAM NAME="Menu" VALUE="False">' +
        '<PARAM name="Movie" value="%s">' +
        '<PARAM name="Play" value="True">' +
        '<PARAM name="Scale" value="%s">' +
        '<PARAM name="Loop" value="True">' +
        '<EMBED src="%s" Quality=high swLiveConnect=FALSE Menu=FALSE WIDTH=%d HEIGHT=%d ' +
        'TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">' +
        '</EMBED></OBJECT>',
        [TMyShockwaveFlash(SaveMe).Width, TMyShockwaveFlash(SaveMe).Height,
        urlStr, scale,
          urlStr, TMyShockwaveFlash(SaveMe).Width, TMyShockwaveFlash(SaveMe).Height]);
    end;

  if (SaveMe is TPanel) and (saveFormat = rvsfHTML) then
    begin
      Panel := SaveMe as TPanel;
      Player := Panel.Components[1] as TMediaPlayer;
      urlStr := Player.FileName;                                                //veg:was ExtractRelativePath(Path, Player.FileName);
      urlStr := 'file://' + StringReplace(urlStr, '\', '/', [rfReplaceAll]);
      OutStr := Format(
        '<object type="video/avi" width="%d" height="%d">' +
        '<param name="filename" value="%s" />' +
        '<a href="%s">Video</a>' +
        '</object>',
        [Panel.Width, Panel.Height, urlStr, urlStr]);
    end;
end;

Code: Select all

procedure T_TaakEditor.rvWriteHyperlink(
  Sender: TCustomRichView; id: Integer; RVData: TCustomRVData;
  ItemNo: Integer; SaveFormat: TRVSaveFormat; var Target, Extras: string);
begin
  Target := PChar(RVData.GetItemTag(ItemNo));
  if (Pos('http://', LowerCase(Target)) = 0) then
    Target := 'http://' + Target;
end;

Code: Select all

procedure T_TaakEditor.rvSaveImage2(Sender: TCustomRichView; Graphic: TGraphic;
  SaveFormat: TRVSaveFormat; const Path, ImagePrefix: string; var
  ImageSaveNo: Integer; var Location: string; var DoDefault: Boolean);
begin
  Location := Sender.RVData.SavePicture(SaveFormat, ImagePrefix, Path, ImageSaveNo, True,
    clWhite, Graphic);
  Location := 'file://' + StringReplace(Path + Location, '\', '/', [rfReplaceAll]);
  DoDefault := False;
end;
Pieter E.
Posts: 835
Joined: Sun Aug 28, 2005 9:34 am

Post by Pieter E. »

Dear Sergey,

I've noticed the same problem when a tablecell contains an image and the cursor is still there, the image could not be taken. I think the problem is in the 'OnSaveImage2'-event. I use this event for converting the 'Graphic' to a 'MIMEEncodeString' for sending as an e-mail.

[edit] Adding 'rve->Deselect();' at the beginning of my source gives a solution, like Wim van der Vegt suggested. [/edit]

Pieter E.
Post Reply