Just dragEdit

Do you want to move your object around the window? It's so easy, just add the following code to the object script:

on mouseDown
  grab me
end mouseDown

That is all!

If you want to force an element to stay on a horizontal or vertical line, don't use grab, use instead just mouseMove like this:

on mousemove X,Y
  set the loc of me to X,256     
end mousemove

this way you don't need grab and your object will be always at 256 pixel from the top of the window, scrolling horizontally

Drag and drop from external programs and appsEdit

When we copy or move files, and in slang is called drag and drop.

This works even if we have to interface with other programs, not written by us, or the operating system itself.

The drag and drop can be divided into two different types of operations: the data coming into our program or the data come from our program.

Data coming into our programEdit

Now look at the case that the data come into our program, for example the user drags an icon of the desktop image to import it into our program.


Drag and Drop in our app

The object that contains the code for importing can be anything other than a card or one stack ; This allows us to define which parts of the window of our program can import data from outside. We could choose a rectangular opaque element.

At this point we have to figure out what to do with the data imported: if we want to import an image, we must ensure that there is an image; if we want to import the text, we have to check that there are texts; if we want to import other file types, simply implement controls on the file name or path.









When the user tries to drag an icon within our program, activates the message DragEnter. This message can be useful for making the controls and set the type of action that we want to impose. When you use the drag end we drop the icon symbol that changes depending on the type of DragAction want to do: move, copy, link, none.

If we set as DragAction action none , we reject the drag and drop and display, the prohibited icon. The drag and drop so will not happen. If we want to check that the data is of the images in the message DragEnter:

on dragEnter
  if "image" is in keys(the dragData) or "files" is in keys(the dragData) then
    set the dragAction to "copy"
     set the dragAction to "none"
  end if
end dragEnter

on dragLeave
 set the dragAction to "none"
end dragLeave

We imposed that if all the data that we drag the mouse contains the images.

The analysis of the data being transported occurs by controlling dragData , this special data container is an array that can hold various items:

  • text : if the data contains the text
  • html : it contains text formatted as HTML
  • RTF : it contains text in RTF fromato The styled text being dragged, in the same format as the RTFText
  • Unicode : unicode text format
  • image : the image data (JPEG, GIF, BMP)
  • files : full path of the file, including the name, one per line.
  • styles : text with the formatting Livecoe
  • private: an internal system that you can set yourself, valid only between LiveCode applications.

Usually if you drag the icon from the desktop, we have the file path ( file ) not the image.

Data come from our programEdit

For the output data just use the message DragStart , such as a text field you can put:

on dragStart
   set the dragData to the selectedText of me
end dragStart