Drag & Drop to a Window
Any window can be used as a drag and drop target. An example can be seen in the Idea Studio, where you can drag an image from any Windows folder directly to your editing canvas to both import the image and draw it on the canvas.
Not all object types can be imported.
To add this functionality, you must include two call-back modules in the module that controls the window. These are OLEDrag and OLEDrop. OLEDrag is not strictly necessary, but without it users will have no visual reference that a drag and drop operation is under way.
In the following example, the parameters shown are required to make the call-backs work. The content of the modules is entirely up to you.
It is a requirement that these modules operate as subroutines.
Example:
{=========================== System =================================} {====================================================================} ( System { Provides access to system library functions }; Layer { Provides access to the application layer }; ) [ Graphics Module { Contains user graphics }; WinTitle = "IDropTarget Test" { Window title }; RunningOnVIC { TRUE if this is a VIC session }; ] Init [ If 1 Main; [ RunningOnVIC = IsVICSession(); ] ] Main [ Window( 0, 0 { Upper left corner }, 800, 600 { View area }, 800, 600 { Virtual area }, Graphics() { Start user graphics }, {65432109876543210} 0b00010000000110011, Concat(WinTitle, RunningOnVIC ? " - %S" : ""), 0, 1); ] < {======================== System\Graphics =============================} { This module handles all of the graphics for the application } {======================================================================} Graphics [ OLEDrag MODULE { Called when a droppable object passes over }; OLEDrop MODULE { Called when a droppable object is dropped here}; PlaceImage MODULE { Draws an image in the position it was dropped }; PROTECTED PlacedImages { Dictionary of dropped image objects }; PROTECTED CurrentDragItem { Storage for current droppable obj if any }; PROTECTED CurrentDragImage { Image being dragged if applicable }; PROTECTED DragX { Current drag X position }; PROTECTED DragY { Current drag Y position }; PROTECTED ImgSzX { Current image width }; PROTECTED ImgSzY { Current image height }; PROTECTED Base { This object }; CONSTANT #CF_TEXT = 1 { Text clipboard format }; CONSTANT #CF_HDROP = 15 { File drop clipboard format }; ] Init [ If 1 Main; [ PlacedImages = Dictionary(); Base = Self(); ] ] Main [ ZText(10, 30, "Click and drag MSDN_Butterfly.jpg from the app folder", 0, 0); ZText(10, 45, "onto this window.", 0, 0); ZText(10, 60, "Does the image appear and track to the cursor (roughly)", 0, 0); ZText(10, 75, "when the mouse is over this window?", 0, 0); ZText(10, 90, "Release the mouse button, dropping the image.", 0, 0); ZText(10, 105, "Does a copy of the image appear in the dropped position?", 0, 0); ZText(10, 120, "If the answer to both questions above is yes then this", 0, 0); ZText(10, 135, "test is a success, otherwise it fails. Feel free to try", 0, 0); ZText(10, 150, "other files. Only images should be processed by this test.", 0, 0); { The following code draws a copy of the image on the page positioned to match the last reported drag position. The image is drawn extending up and left from the position. } ImgSzX = BitmapInfo(CurrentDragImage, 0); ImgSzY = BitmapInfo(CurrentDragImage, 1); GUIBitmap(0, 1, 1, 0, 1 - (DragX - ImgSzX), DragY, DragX, 1 - (DragY - ImgSzY), 1, 0, 0 { No overall scaling, trajectory, or rotation }, 1, 0 { visibility, reserved }, 0, 0, 0 { No activation or focus }, CurrentDragImage); ] < {============================== OLEDrag ==============================} { Called in response to an IDropTarget drag notification. } {=====================================================================} OLEDrag ( Type { The clipboard format of the data parameter }; Data { The data passed, data type varies (see above) }; KeyState { Keyboard key press enumeration }; X { X-coordinate of the cursor }; Y { Y-coordinate of the cursor }; Mode { Op code: 0=drop, 1=enter, 2=over, 3=exit }; ) Main [ If 1; [ { When a drag enters a window it reports the data, but does not during drag over or exit operations. Grab a copy of the image during the enter and remove it upon exit. } IfElse(Mode == 1 && Type == #CF_HDROP, Execute( { Only try to make a bitmap if given a file name } CurrentDragItem = Data; CurrentDragImage = MakeBitmap(CurrentDragItem); ); { Else } IfThen(Mode == 3, CurrentDragItem = CurrentDragImage = Invalid; )); { Update the drag position, technically this is only necessary because XLoc etc. don't report mouse position during a drag. } DragX = X; DragY = Y; Return(Invalid); ] ] { End of System\Graphics\OLEDrag } > < {============================== OLEDrop ===============================} { Called in response to an IDropTarget drop notification. } {======================================================================} OLEDrop ( Type { The clipboard format of the data parameter }; Data { The data passed, data type varies (see above) }; KeyState { Keyboard key press enumeration }; X { X-coordinate of the cursor }; Y { Y-coordinate of the cursor }; Mode { Op code: 0=drop, 1=enter, 2=over, 3=exit };
) [ PROTECTED Image { Image loaded from the file }; ] Main [ If 1; [ { The imae is being dropped, cease to draw the drag-tracking image } CurrentDragItem = CurrentDragImage = Invalid; { Add a copy of the image to the window at the current coordinates. } IfThen(Type == #CF_HDROP { Only do this if we were passed a file name }, Image = MakeBitmap(Data); IfThen(Valid(Image), PlacedImages[GetGUID(1)] = Launch(\PlaceImage, Base, Base, Image, X, Y); ); ); Return(Invalid;); ] ] { End of System\Graphics\OLEDrop } > < {=========================== PlaceImage ===============================} { Draws an image on the window at with a lower right corner at the given pos. } {======================================================================} PlaceImage ( Image { Image to be placed }; X { Right side of the placement }; Y { Left side of the placement }; ) [ PROTECTED ImgSzX { Current image width }; PROTECTED ImgSzY { Current image height }; ] Main [ { Draw an image extending up and left from the given position. This just makes things easy given the way that the image is being traced during the drag. } ImgSzX = BitmapInfo(Image, 0); ImgSzY = BitmapInfo(Image, 1); GUIBitmap(0, 1, 1, 0, 1 - (X - ImgSzX), Y, X, 1 - (Y - ImgSzY), 1, 0, 0 { No overall scaling, trajectory, or rotation }, 1, 0 { visibility, reserved }, 0, 0, 0 { No activation or focus }, Image); ] { End of System\Graphics\PlaceImage } > { End of System\Graphics } >