HTMLViewer file drop

By default on Windows, you can drag a file from the OS over the HTMLViewer and it loads that file. How can I disable this?
In VB I set AllowDrop to false and that took care of it (http://msdn.microsoft.com/en-us/library/system.windows.uielement.allowdrop(v=vs.110).aspx). Don’t see that option in Xojo.

thanks

[quote=80594:@Adam Meyer]By default on Windows, you can drag a file from the OS over the HTMLViewer and it loads that file. How can I disable this?
In VB I set AllowDrop to false and that took care of it (http://msdn.microsoft.com/en-us/library/system.windows.uielement.allowdrop(v=vs.110).aspx). Don’t see that option in Xojo.

thanks[/quote]

  • Lay a canvas over the HTMLViewer. Make sure not to make it a child of the HTMLViewer (the HTMLViewer would be outlined red). Drop it over the window, make it larger than the HTMLViewer and slide it carefully over.
  • Add the following events to the canvas :

Sub Open() Me.AcceptFileDrop("") End Sub

and

Sub DropObject(obj As DragItem, action As Integer) obj = Nil End Sub

The HTMLViewer will not open files anymore.

Thanks, that worked.
But now I can’t click inside the HTML viewer at all.

Return false in the MouseDown event of the canvas and you should be able to click in the HTMLViewer.

Nope, still nothing. I also want to be able to scroll and use key events in the HTMLViewer as well.

Could be a difference between OSX and Windows then, returning false solves that problem for me on OSX.

Have you tried just implementing “CancelLoad” and returning true ?

Indeed, under Windows the canvas does not let clicks go through with MouseDown and MouseWheel returning False :frowning:

The HTMLViewer is a black box that does not offer any event or properties to distinguish between an URL dropped over it and a click or a LoadURL. There does not seem to be any way to prevent dropped shortcuts to open. Sorry. You found a sad Xojo limitation with no workaround.

I filed feature request #33226 to ask that HTMLViewer not accept file drop as default, as the method HTMLViewer.AcceptFileDrop is here to enable it, and is rendered the method purposeless.

I see that you had reviewed the 16087 bug report in 2011 :wink:

True in CancelLoad simply prevents ALL loading to take place :frowning:

You need to inject some JavaScript to disable the drag and drop in the HTMLViewer…

http://shaosean.tk/xojo/DisableDrop.xojo_binary_project.zip

Shao Sean, I admire your Java skills. Congratulations.

[quote=80734:@Michel Bujardet]
True in CancelLoad simply prevents ALL loading to take place :([/quote]

Cancel Load cancels loading whatever URLs you return true for

So you can look at the URL and determine IF you want to allow it to load or not

The reason I asked is I quickly whipped up a small example and did not return true in candle load & I could drag & drop whatever files from my Windows 7 desktop
When I simply returned true all the time none of the them would load

[quote=80757:@Norman Palardy]Cancel Load cancels loading whatever URLs you return true for

So you can look at the URL and determine IF you want to allow it to load or not[/quote]

The issue is simply to know if the URL comes from a dropped file, a LoadPage or a LoadURL, which there is no way to know :confused:

Sure there is
URLs from dropped files are file:// style
Everything else is something else NOT local

[quote=80759:@Norman Palardy]Sure there is
URLs from dropped files are file:// style
Everything else is something else NOT local[/quote]

Nope. Just tried. A dropped Internet shortcut gives a url as http://something and NOT file://

That said, Shao Sean offered a brilliant Java workaround to the OP. Solved :slight_smile:

Guess what I just found out ? Under Windows, when Rendered is set to Webkit, HTMLViewer stops accepting file drop. The solution was here all along, just with a small setting :slight_smile:

Mac accepts files drop whatever the Renderer, so Shao Sean solution or the canvas overlay workaround remain necessary.

Linux HTMLVIewer simply does not accept file drop…

An aside,
@Norman, I haven’t used them since Realbasic, and my computers not available right now, but are the undocumented _ (underscored) functions still available for HTMLViewer (like cancel javascript errors etc)?

[quote=80818:@Matthew Combatti]An aside,
@Norman, I haven’t used them since Realbasic, and my computers not available right now, but are the undocumented _ (underscored) functions still available for HTMLViewer (like cancel javascript errors etc)?[/quote]
You should never use those in any code anywhere
They are internal and should be private

The OP uses Windows, but while I was experimenting with Linux, I fiddled with the HTMLViewer drop file. And found fragmented issues (smile).

  • In Ubuntu 12.10, the HTMLViewer does not accept shortcuts at all.
  • In Fedora, same thing as Windows : shortcut drop opens the url, and the canvas overlay does not trap the file drop. But it traps click and mouse wheel, even though I return False in MouseDown and MouseWheel.
  • In Linux Mint 16 “petra” when a shortcut is brought over the HTMLViewer the cursor shows the file will be opened, but nothing happens. Even with HTMLViewer.AcceptFileDrop()

All these results happen with native renderer. Curiously, all these distributions use FireFox, but behavior changes.

In all these distributions Shao Sean example code does not compile : an indeterminate ProgressBar shows, then the IDE shows the code is running, but the debug app is not launched.

I use that code in my HTMLViewer sub-class and know that it does work on all three platforms, but I only use the WebKit renderer as using Native on Windows gives different results in my program… There is one thing though that I forgot when I did that sample code, there is one time where the code does not work and you will need to trap the CancelLoad event… (basically it happens when someone drops a file on the viewer that is not part of the DOM area)…