Wednesday, March 22, 2006

Advanced Xailer Techniques, Drag and Drop operations

Xailer let you to perform 3 kinds of different Drag & Drop operations:

  • Dragging files from the Windows explorer into the Xailer program
  • Dragging elements inside a TreeView
  • Dragging controls over other controls
The most basic drag & drop operation is the drag of files from within the Windows Explorer into your Xailer Application, its functionality is limited because only let you "to send" a file name or a list of file names to a control, and let it to process them. It works in a very easy way, just set the lDragAcceptFiles property to TRUE, and finally catch the event OnDropFiles, in such event, we will recieve an array with a list of the file names and maybe we could handle it like this:

METHOD ListBox1DropFiles( oSender, aFiles, aPoint ) CLASS ...

Aeval( aFiles, {|v| oSender:AddItem( v ) } )

RETURN Nil


In this sample, we are adding into a TListBox control, the name of files dragged into the control.

The second Drag & Drop system in Xailer is used to perform drag & drop operations among elements inside a TreeView control, you just have to set lDragDropItem property to TRUE. However, the TreeView control has some other events to give more flexibility and power to this kind of operations:

  • OnBeginDragItem: This event is launches whenever you start a Drag&Drop operation between two TreeView items, recieves as a second parameter, after oSender, the TTreeViewItem object which launched the event.
  • OnDragOverItem: This event is launched when, inside a Drag&Drop between items, the cursor is over a certain item. It recieves as a second parameter, after oSender, the TTreeViewItem objetct where the cursor is over. If it returns FALSE, you will see the "prohibited" cursor, indicating that is not possible to perform the D&D operation over that item.
  • OnEndDragItem: This event is launched when a D&D operation is finished between items. It recieves as a second parameter, after the oSender object, two TTreeViewItem objects, one called oItemFrom, the one that launched the event, and other called oItemTo, the object where the mouse was dropped. If it returns NIL, o this event is not captured, oItemFrom will move right after oItemTo. Catching this event, is possible to reject the Drop operation or, instead of move the item after the oItemTo, it moves to a child branch of the oItemTo.
The third way to perform D&D opeartions in Xailer, allows you to do it between Xailer controls, even if these controls are in different forms. To acomplish this task, Xailer has these events, at TControl class level, so they are inherited to all the classes from it:

  • OnBeginDrag: Is launched when there's a request to begin a D&D operation. If returns .T., this means that the D&D opearation is allowed and you notice it inmediatly because the mouse cursor changes its shape.
  • OnDragOver: Is launched when the mouse cursos moves over a control, and a D&D operation has been started. It recieves as a second parameter, after oSender, the control which started the D&D operation. If returns .T. this means that the D&D operation can be performed, and you notice it because the mouse cursor shape changes to the oCursorDropYes. If this event is not trapped, or returns a value different of TRUE, the mouse cursos shape change to oCursorDropNo.
  • OnEndDrag: This event is launched when you release the mouse left button over a control, and previously a D&D operation has been started. It recieves as a second parameter, after the oSender, the control which starte the D&D operation.

Please notice that the second and third ways cannot be used together, this means that you cannot perform a D&D between controls and at the same time do a D&D between TreeViewItems.

You can find a sample of D&D in the directory \Samples\DragDrop showing you the 3 ways at the same time.

0 Comments:

Post a Comment

<< Home