Pages: 1
Print
Author Topic: Disable Drag&Drop for Images in XMAX  (Read 219 times)
MichaelLohr
Member

Posts: 4


« on: June 08, 2017, 02:41:29 AM »

Hello,

we are using XMAX Version 10 as embedded contol in a win forms application.

If the user drag and drops a image from the windows explorer into the XMAX control a "Graphic" element showing
the image is inserted.
Is is possible to prevent this behaviour by configuration or code.

I tried to register for the "OnDragDrop"-Event but this is only fired after the "Graphic" element is still inserted.

Do you have any suggestions to solve this problem.
Thanks in advance.

Best regards,
Michael


Logged
XMetaLOldTimer
Global Moderator
Member

Posts: 51


« Reply #1 on: June 08, 2017, 04:12:36 PM »

You should be able to cancel the drop but you need to implement the _IXMetaLControlEvents::OnDrop event sink function in your application.  The XMAX OnDrop event sink has this signature:

HRESULT OnDrop(IDataObject* dropDataObject, LONG keyState, LONG X, LONG Y, IntegerRefVar* dropEffect, Range* dropPoint, BoolRefVar* handled)

If you set "handled" to VARIANT_TRUE and dropEffect to DROPEFFECT_NONE (from Win32 constants), that should do it.

Regards,
Addam
Logged

Addam Smith, XMetaL Project Lead & Architect
JustSystems Canada Inc.
MichaelLohr
Member

Posts: 4


« Reply #2 on: June 13, 2017, 09:16:48 AM »

Hi Addam,

Unfortunately neither the OnDrop event nor the OnDragOver is thrown if I drop a image from outside the XMAX windows ( from the windows explorer).
These events are only working if I do a drag drop action inside the XMAX control for example dragging an element from one parent to another.

Do you have any other ideas who to solve this.

Best regards,
Michael
Logged
XMetaLOldTimer
Global Moderator
Member

Posts: 51


« Reply #3 on: June 13, 2017, 08:55:59 PM »

I put together a HTML sample to try this out and I am seeing the same behavior as you (re: OnDragOver and OnDrop event sinks are NOT called).  

So, I started up the debugger and internally, XMAX (and Author) handles this kind of drag'n'drop using the Windows WM_DROPFILES message.  The code will fire the On_Drop_Files event macro, if present, to permit hooking into this behavior.  XMAX cannot fully utilize this event macro because certain APIs are missing (re: Application.DropFileCount and Application.DropFileName).  Nevertheless, there is a way to disable this functionality by adding an empty doc-level "On_Drop_Files" event macro to your customization's *.mcr file.   Two caveats:

1. This disables dropping of ALL file types into the XMAX window.
2. The system still shows the drop cursor as a plus sign indicating the drop is allowed (eventhough nothing happens later).

  
Regards,
Addam
« Last Edit: June 13, 2017, 09:26:14 PM by XMetaLOldTimer » Logged

Addam Smith, XMetaL Project Lead & Architect
JustSystems Canada Inc.
MichaelLohr
Member

Posts: 4


« Reply #4 on: June 19, 2017, 03:27:23 AM »

Hi Addam,

Thanks for your information.
I'm pretty new to XMAX development.
How do I use this *.mcr file?
I can only see a *.ctm file next to my xsd. Do you have any documentation regarding the *.mcr file?

Best regards,
Michael

Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2481



WWW
« Reply #5 on: June 19, 2017, 05:19:19 PM »

The documentation for all of the customization files supported by XMetaL software (all three editors) is included with XMetaL Developer in the Programmers Guide and the Customization Guide.

When using XMetaL Developer to create an MCR file you start with individual script files (in any scripting language you have a scripting engine installed for, but most often JScript or VBScript) and XMetaL Developer then compiles those into an MCR file when you build your project.

If you don't have XMetaL Developer but do have access to an installation of XMetaL Author Essential or Enterprise there are lots of MCR files included in those installations you could use as examples.

The MCR file format is a simple XML structure containing multiple macros. Each contains a separate script and some metadata that identifies the script language, gives the macro a name, a keyboard shortcut and a few other pieces of metadata that are not really useful for XMAX usage but that may come into play with XMetaL Author Essential or Enterprise.

Here's the simplest of examples of a file containing 2 macros:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MACROS SYSTEM "macros.dtd">
<MACROS>
   <MACRO name="Test 1" lang="JScript"><![CDATA[
      //use JScript to display an alert dialog containing some text
      ActiveDocument.Host.Alert("This is test 1");
   ]]></MACRO>

   <MACRO name="Test 2" lang="VBScript"><![CDATA[
      'use VBScript to display an alert dialog containing some text
      ActiveDocument.Host.Alert "This is test 2"
   ]]></MACRO>
</MACROS>


In the case of Addam's suggestion you would use name="On_Drop_Files" for the macro name. When the macro's name matches an event macro's name (as documented in the Programmers Guide) it fires when that event is triggered.

All other macros are effectively "user triggered" (vs "event triggered"). In the case of XMetaL Author Essential and Enterprise a dialog is available that lists all macros and the user can select one to run, or the user may use a shortcut key to trigger the macro (if defined, which in my example is not the case). XMAX does not provide this type of UI so it would be up to you (as a developer) to expose something like this to the user from your application's own UI. Your code would call XMAX's Run method (see the Programmers Guide) and specify a macro to run. The API method named "Run" can be used to run any macro (in all three editors).
« Last Edit: June 19, 2017, 05:21:37 PM by Derek Read » Logged
MichaelLohr
Member

Posts: 4


« Reply #6 on: June 20, 2017, 02:55:58 AM »

Hi Derek,

Thanks a lot for your help.
The suggestion provided with the On_Drop_Files event macro worked for me.

Best regards,
Michael
Logged
Pages: 1
Print
Jump to: