General XMetaL Discussion
MichaelLohr June 8, 2017 at 8:41 am
Disable Drag&Drop for Images in XMAXJune 8, 2017 at 8:41 amParticipants 5Replies 6Last Activity 5 years, 3 months ago
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.
MichaelXMetaLOldTimer June 8, 2017 at 10:12 pm
Reply to: Disable Drag&Drop for Images in XMAXJune 8, 2017 at 10:12 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.
AddamMichaelLohr June 13, 2017 at 3:16 pm
Reply to: Disable Drag&Drop for Images in XMAXJune 13, 2017 at 3:16 pm
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.
MichaelXMetaLOldTimer June 14, 2017 at 2:55 am
Reply to: Disable Drag&Drop for Images in XMAXJune 14, 2017 at 2:55 am
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).
AddamMichaelLohr June 19, 2017 at 9:27 am
Reply to: Disable Drag&Drop for Images in XMAXJune 19, 2017 at 9:27 am
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?
MichaelDerek Read June 19, 2017 at 11:19 pm
Reply to: Disable Drag&Drop for Images in XMAXJune 19, 2017 at 11: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:
//use JScript to display an alert dialog containing some text
ActiveDocument.Host.Alert("This is test 1");
'use VBScript to display an alert dialog containing some text
ActiveDocument.Host.Alert "This is test 2"
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).
- You must be logged in to reply to this topic.