Text and Image Drag&Drop...

General TRichView support forum. Please post your questions here
Post Reply
CrimsonKing
Posts: 7
Joined: Wed Nov 01, 2017 11:13 am

Text and Image Drag&Drop...

Post by CrimsonKing »

Hi~
First, Excuse me for my poor English.

I tried to drag Texts+Images from Internet Explorer(IE) and drop its to TRichviewEdit(RVE), but dropped only Texts to RVE.
Resultly, Texts or Images dropped to RVE only one at time.

How can I drag&drop Texts+Images to RVE at once? :(
Is it possible? :?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Text and Image Drag&Drop...

Post by Sergey Tkachenko »

If you drop a single image, IE provides it as a reference to a file (in its cache), so TRichView can easily read it.
If you drop a page fragment containing text and pictures, IE provides it as plain text, RTF, and HTML. By default, TRichViewEdit reads it as RTF.
This RTF contains references to picture URLs. TRichView cannot download it itself, you need to help it.

If you use RichViewActions, it's more simple. If you assign RVAControlPanel.DownloadInterface, RichViewActons download external images when you load, insert and paste files. However, to download them on drag&drop, you need to add code in OnBeforeOleDrop and OnAfterOleDrop, see http://www.trichview.com/help/idh_trich ... edrop.html
CrimsonKing
Posts: 7
Joined: Wed Nov 01, 2017 11:13 am

Re: Text and Image Drag&Drop...

Post by CrimsonKing »

Very Late, I see your kindly answer...

I did the test as you answered, but it doesn't work the way I want it to.
Text is dropping but images aren't downloaded.

I've looked at this document...

http://www.trichview.com/forums/viewtop ... ace#p31614

I tested using RVControlPanel, DownloadInterface and IndyHTTP. but it doesn't work like it should.
I set properties...
- rvControlPanel.DefaultControl := rve;
- rvControlPanel.DownloadInterface := rvDownloadInterface;
- rvDownloadInterface.IdHttp := IndyHttp;

It's my source code below...

Code: Select all

procedure TMyForm.rveBeforeOleDrop(Sender: TObject);
begin
  rvControlPanel.InitImportPictures(nil, nil);
  (Sender as TCustomRichViewEdit).OnImportPicture := rvControlPanel.DoImportPicture;
end;

procedure TMyForm.rveAfterOleDrop(Sender: TObject);
var
  W, X: Integer;
begin
  (Sender as TCustomRichViewEdit).OnImportPicture := nil;
  rvControlPanel.DoneImportPictures;
end;
And I try drop&drop to rve from Texts&Pictures in IE, but it doesn't work...
I don't know why rvControlPanel.DoImportPicture doesn't do anything.

Help me plz... :cry:
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Text and Image Drag&Drop...

Post by Sergey Tkachenko »

From which page do you drag?
CrimsonKing
Posts: 7
Joined: Wed Nov 01, 2017 11:13 am

Re: Text and Image Drag&Drop...

Post by CrimsonKing »

I scrap text & image from IE and drag & drop to rve.
For example...
sample1.JPG
sample1.JPG (46.87 KiB) Viewed 21859 times
https://www.nytimes.com/2017/11/11/wor ... e=article

The below picture is the result of rve.
rev.jpg
rev.jpg (88.71 KiB) Viewed 21859 times
CrimsonKing
Posts: 7
Joined: Wed Nov 01, 2017 11:13 am

Re: Text and Image Drag&Drop...

Post by CrimsonKing »

May I have an answer to this? :cry:
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Text and Image Drag&Drop...

Post by Sergey Tkachenko »

I tested, it works as expected. I attached a sample project.

Important note 1: it works only when dragging from Internet Explorer, because it provides RTF format when copying or dragging.
It does not work when dragging from other browsers (including Edge, FireFox and Chrome), because they do not provide RTF, so their content is inserted in TRichViewEdit as a plain text.

Important note 2: Internet Explorer does not provide RTF for "too complex" content, that includes many nested tables. So, if it does not work, try dragging a smaller fragment.

The problems above could be solved by using HTML format instead of RTF: all major browsers provide content as HTML.
For pasting, it's simple to do, especially using RichViewActions: assign TrvHtmlImporter, or (better) TrvHtmlViewImporter to RVAControlPanel.HTMLComponent.
For drag&drop, it's more difficult, it requires writing quite low-level code in OnOle*** events. Probably, in future versions, I'll simplify it.
Attachments
DDPictures.zip
(50.05 KiB) Downloaded 1304 times
Post Reply