This is an automated email from the ASF dual-hosted git repository.

yishayw pushed a commit to branch d_and_d_improvemets
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/d_and_d_improvemets by this 
push:
     new 17045f6170 Use mx drag beads for mx components - multi selection
17045f6170 is described below

commit 17045f6170070b9f287a4f55723bd8dca6166576
Author: Yishay Weiss <[email protected]>
AuthorDate: Thu Nov 3 15:19:01 2022 +0200

    Use mx drag beads for mx components - multi selection
---
 .../MXRoyale/src/main/royale/mx/controls/Tree.as   |  16 +-
 .../beads/TreeMultiSelectionDragSourceBead.as      | 300 ++++++++++++++++
 .../beads/TreeMultiSelectionDropTargetBead.as      | 400 +++++++++++++++++++++
 .../beads/XMLTreeMultiSelectionDropTargetBead.as   |  93 +++++
 4 files changed, 799 insertions(+), 10 deletions(-)

diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Tree.as 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Tree.as
index 554db2024c..5972aaf62c 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Tree.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Tree.as
@@ -81,17 +81,12 @@ use namespace mx_internal;
 
 import org.apache.royale.events.Event;
 import org.apache.royale.html.beads.DataGridDrawingLayerBead;
-import mx.controls.beads.TreeSingleSelectionDragSourceBead;
 import org.apache.royale.utils.getOrAddBeadByType;
-import org.apache.royale.html.beads.SingleSelectionDropTargetBead;
 import org.apache.royale.html.beads.SingleSelectionDropIndicatorBead;
-import org.apache.royale.html.beads.SingleSelectionDragImageBead;
-import mx.controls.beads.XMLTreeSingleSelectionDragSourceBead;
-import mx.controls.beads.TreeSingleSelectionDropTargetBead;
-import mx.controls.beads.XMLTreeSingleSelectionDropTargetBead;
-import org.apache.royale.html.beads.MultiSelectionTreeDragSourceBead;
 import org.apache.royale.html.beads.MultiSelectionDragImageBead;
-import org.apache.royale.html.beads.SensitiveMultiSelectionDropTargetBead;
+import org.apache.royale.html.beads.MultiSelectionDragSourceBead;
+import mx.controls.beads.TreeMultiSelectionDropTargetBead;
+import mx.controls.beads.XMLTreeMultiSelectionDropTargetBead;
 
 //--------------------------------------
 //  Events
@@ -3739,7 +3734,8 @@ public class Tree extends List
     override protected function setDropEnabled():void
     {
         getOrAddBeadByType(DataGridDrawingLayerBead, this);
-        getOrAddBeadByType(SensitiveMultiSelectionDropTargetBead, this);
+        getOrAddBeadByType(TreeMultiSelectionDropTargetBead, this);
+        getOrAddBeadByType(XMLTreeMultiSelectionDropTargetBead, this);
         getOrAddBeadByType(SingleSelectionDropIndicatorBead, this);
     }
 
@@ -3749,7 +3745,7 @@ public class Tree extends List
     override protected function setDragEnabled():void
     {
         // getOrAddBeadByType(TreeSingleSelectionDragSourceBead, this);
-        getOrAddBeadByType(MultiSelectionTreeDragSourceBead, this);
+        getOrAddBeadByType(MultiSelectionDragSourceBead, this);
         getOrAddBeadByType(MultiSelectionDragImageBead, this);
     }
 }
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/TreeMultiSelectionDragSourceBead.as
 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/TreeMultiSelectionDragSourceBead.as
new file mode 100644
index 0000000000..6f4a18c540
--- /dev/null
+++ 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/TreeMultiSelectionDragSourceBead.as
@@ -0,0 +1,300 @@
+
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package mx.controls.beads
+{
+       import org.apache.royale.core.IBead;
+       import org.apache.royale.core.IChild;
+       import org.apache.royale.core.IDataProviderModel;
+       import org.apache.royale.core.IDragInitiator;
+       import org.apache.royale.core.IIndexedItemRenderer;
+       import org.apache.royale.core.IItemRenderer;
+       import org.apache.royale.core.IMultiSelectionModel;
+       import org.apache.royale.core.IStrand;
+       import org.apache.royale.events.DragEvent;
+       import org.apache.royale.events.Event;
+       import org.apache.royale.events.EventDispatcher;
+       import org.apache.royale.events.IEventDispatcher;
+       import org.apache.royale.html.beads.controllers.DragMouseController;
+       import org.apache.royale.utils.getParentOrSelfByType;
+       import org.apache.royale.html.util.getModelByType;
+       import mx.collections.IList;
+       import org.apache.royale.utils.sendStrandEvent;
+       import org.apache.royale.events.ValueEvent;
+
+       /**
+        * The start event is dispatched when a DragStart event happens. The 
DragEvent.dragSource
+        * is set before this event is dispatched. A listener for this event 
can then decide if
+        * if the drag-drop action should continue or not. If not, the event 
should be cancelled.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       [Event(name="start", type="org.apache.royale.events.Event")]
+
+       /**
+        * The accept event is dispatched when the drop happens but just before 
the data being
+        * dragged as been incorporated into the drop target's data source. 
Cancelling this event
+        * prevents that from happening.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       [Event(name="accept", type="org.apache.royale.events.Event")]
+
+       /**
+        * The complete event is dispatched when the entire drag-and-drop 
operation has completed
+        * from the drag source's perspective.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       [Event(name="complete", type="org.apache.royale.events.Event")]
+
+       /**
+        * The dragMove event is dispatched while the drag action moves.
+        * 
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       [Event(name="dragMove", type="org.apache.royale.events.DragEvent")]
+
+       /**
+        * The dragEnd event is dispatched while the drag action stops.
+        * This is dispatched even when the drag event is aborted.
+        * 
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       [Event(name="dragEnd", type="org.apache.royale.events.DragEvent")]
+       /**
+        *  The TreeMultiSelectionDragSourceBead brings drag capability to 
multi-selection Tree components.
+        *  By adding this bead, a user can drag a row of the Tree to a new 
location within the tree. This bead
+        *  should be used in conjunction with 
TreeSingleSelectionDropTargetBead.
+        *
+        *  This bead adds a new event to the strand, "dragImageNeeded", which 
is dispatched on the strand
+        *  just prior to the dragImage's appearance. An event listener can 
create its own dragImage if the
+        *  default, taken from the data item, is not suitable.
+        *
+        *  @see org.apache.royale.html.beads.SingleSelectionDropTargetBead.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       public class TreeMultiSelectionDragSourceBead extends EventDispatcher 
implements IBead, IDragInitiator
+       {
+               /**
+                * Constructor
+            *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.10
+                */
+               public function TreeMultiSelectionDragSourceBead()
+               {
+                       super();
+               }
+
+               private var _strand:IStrand;
+               private var _dragController:DragMouseController;
+               private var continueDragOperation:Boolean = true;
+
+               private var _dragType:String = "move";
+
+               /**
+                * The type of drag and drop operation: move or copy.
+            *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.10
+                */
+               public function get dragType():String
+               {
+                       return _dragType;
+               }
+               public function set dragType(value:String):void
+               {
+                       _dragType = value;
+               }
+
+               private var _approveDragStart:Function;
+               /**
+                * Provides the ability to approve (or prevent) a mouseDown 
event being considered
+                * as the start of a drag sequence. This can be useful for 
renderers with some controls
+                * that must remain interactive, so that dragging is only 
supported by other parts of the renderer.
+                * The function should return true for the mouseDown event to 
be approved as the possible start
+                * of a drag sequence
+                *
+                * @param value a function that takes a MouseEvent as a 
parameter and returns a Boolean value that
+                * pre-approves a mouseDown event (or not)
+                */
+               public function set approveDragStart(value:Function):void{
+                       if (_dragController) {
+                               _dragController.approveDragStart=value
+                       } else {
+                               _approveDragStart = value;
+                       }
+               }
+               public function get approveDragStart():Function{
+                       return _dragController? 
_dragController.approveDragStart :_approveDragStart;
+               }
+
+               private var _explicitTopmostDispatcher:IEventDispatcher;
+               /**
+                * Provides the ability to specify a non-default 
topMostEventDispatcher.
+                * A Basic Royale application looks on the document.body tag 
for an associated Royale EventDispatcher instance,
+                * and the default behaviour is to consider that to be valid.
+                * Other Application types may not be associated with the body 
tag, so this provides a way to explicitly specify
+                * the top level instance.
+                *
+                */
+               public function set 
explicitTopmostDispatcher(value:IEventDispatcher):void{
+                       if (_dragController) {
+                               _dragController.topMostDispatcher = value;
+                               _explicitTopmostDispatcher = null;
+                       }
+                       else _explicitTopmostDispatcher = value;
+               }
+               public function get 
explicitTopmostDispatcher():IEventDispatcher{
+                       return _dragController? 
_dragController.topMostDispatcher :_explicitTopmostDispatcher;
+               }
+
+               /**
+                * @private
+                */
+               public function set strand(value:IStrand):void
+               {
+                       _strand = value;
+                       _dragController = new DragMouseController();
+                       _dragController.topMostDispatcher = 
_explicitTopmostDispatcher;
+                       _dragController.approveDragStart = _approveDragStart;
+                       _strand.addBead(_dragController);
+
+                       _dragController.addEventListener(DragEvent.DRAG_START, 
handleDragStart);
+                       _dragController.addEventListener(DragEvent.DRAG_MOVE, 
handleDragMove);
+                       _dragController.addEventListener(DragEvent.DRAG_END, 
handleDragEnd);
+               }
+
+
+               /**
+                * @private
+                *  @royaleignorecoercion org.apache.royale.core.IChild
+                *  @royaleignorecoercion 
org.apache.royale.core.IIndexedItemRenderer
+                */
+               private function handleDragStart(event:DragEvent):void
+               {
+                       //trace("TreeMultiSelectionDragSourceBead received the 
DragStart");
+
+                       DragEvent.dragInitiator = this;
+                       DragMouseController.dragImageOffsetX = 0;
+                       DragMouseController.dragImageOffsetY = -30;
+
+                       var relatedObject:Object = event.relatedObject;
+                       var itemRenderer:IIndexedItemRenderer = 
getParentOrSelfByType(relatedObject as IChild, IItemRenderer) as 
IIndexedItemRenderer;
+
+                       if (itemRenderer) {
+                               DragEvent.dragSource = itemRenderer.data;
+                               sendStrandEvent(_strand, new 
ValueEvent("dragSourceSet", itemRenderer));
+                       }
+
+                       var newEvent:Event = new Event("start", false, true);
+                       continueDragOperation = true;
+                       dispatchEvent(newEvent);
+                       if (newEvent.defaultPrevented) {
+                               continueDragOperation = false;
+                       }
+               }
+
+               /**
+                * @private
+                */
+               protected function handleDragMove(event:DragEvent):void
+               {
+                       dispatchEvent(event);
+               }
+
+               /**
+                * @private
+                */
+               protected function handleDragEnd(event:DragEvent):void
+               {
+                       dispatchEvent(event);
+               }
+
+               /* IDragInitiator */
+
+               /**
+                * Handles pre-drop actions.
+            *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.10
+                *  @royaleignorecoercion Array
+                *  @royaleignorecoercion 
org.apache.royale.core.IMultiSelectionModel
+                *  @royaleignorecoercion 
org.apache.royale.core.IDataProviderModel
+                *  @royaleignorecoercion mx.collections.IList
+                */
+               public function acceptingDrop(dropTarget:Object, 
type:String):void
+               {
+                       if (!continueDragOperation) return;
+
+                       //trace("TreeMultiSelectionDragSourceBead accepting 
drop of type "+type);
+                       var newEvent:Event = new Event("accept", false, true);
+                       dispatchEvent(newEvent);
+                       if (newEvent.defaultPrevented) return;
+                       
+                       var dataProviderModel:IDataProviderModel = 
getModelByType(_strand,IDataProviderModel) as IDataProviderModel;
+                       if (dataProviderModel is IMultiSelectionModel) {
+                               (dataProviderModel as 
IMultiSelectionModel).selectedIndices = null;
+                       }
+
+                       if (dragType == "copy") return;
+                       sendStrandEvent(_strand, new 
Event("acceptingMoveDrop"));
+               }
+
+               /**
+                * Handles post-drop actions.
+            *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.10
+                */
+               public function acceptedDrop(dropTarget:Object, 
type:String):void
+               {
+                       dispatchEvent(new Event("complete"));
+               }
+
+       }
+}
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/TreeMultiSelectionDropTargetBead.as
 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/TreeMultiSelectionDropTargetBead.as
new file mode 100644
index 0000000000..d5943e2b22
--- /dev/null
+++ 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/TreeMultiSelectionDropTargetBead.as
@@ -0,0 +1,400 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package mx.controls.beads 
+{
+       import mx.collections.IList;
+
+       import org.apache.royale.utils.getOrAddBeadByType;
+       import org.apache.royale.core.DropType;
+       import org.apache.royale.core.IBead;
+       import org.apache.royale.core.IDataProviderModel;
+       import org.apache.royale.core.IIndexedItemRenderer;
+       import org.apache.royale.core.IItemRenderer;
+       import org.apache.royale.core.IItemRendererOwnerView;
+       import org.apache.royale.core.IMultiSelectionModel;
+       import org.apache.royale.core.IStrand;
+       import org.apache.royale.core.IUIBase;
+       import org.apache.royale.core.UIBase;
+       import org.apache.royale.events.DragEvent;
+       import org.apache.royale.events.Event;
+       import org.apache.royale.events.EventDispatcher;
+       import org.apache.royale.geom.Point;
+       import org.apache.royale.html.beads.IDrawingLayerBead;
+       import org.apache.royale.html.beads.SingleSelectionDropIndicatorBead;
+       import org.apache.royale.html.beads.controllers.DropMouseController;
+       import org.apache.royale.html.util.getModelByType;
+       import org.apache.royale.utils.PointUtils;
+       import org.apache.royale.utils.sendEvent;
+       import org.apache.royale.utils.sendStrandEvent;
+       import org.apache.royale.events.ValueEvent;
+       import org.apache.royale.core.IChild;
+       import mx.core.FlexGlobals;
+
+
+       /**
+        * The enter event is dispatched when a DragEnter has been detected in 
the drop target
+        * strand. This event can be used to determine if the strand can and 
will accept the data
+        * being dragged onto it. If the data cannot be used by the drop target 
strand this event
+        * should be cancelled.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9
+        */
+       [Event(name="enter", type="org.apache.royale.events.Event")]
+
+       /**
+        * The exit event is sent when the drag goes outside of the drop target 
space.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9
+        */
+       [Event(name="exit", type="org.apache.royale.events.Event")]
+
+       /**
+        * The over event is dispatched while the drag is happening over the 
drop target space. This
+        * event may be cancelled if that particular area of the drop target 
cannot accept the
+        * drag source data.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9
+        */
+       [Event(name="over", type="org.apache.royale.events.Event")]
+
+       /**
+        * The drop event is dispatched just prior to incorporating the drag 
source data into the drop
+        * target's dataProvider. This event may be cancelled to prevent that 
from happening.
+        * Note that a "exit" event always precedes this event to allow any 
drag-drop graphics
+        * to be cleared.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9
+        */
+       [Event(name="drop", type="org.apache.royale.events.Event")]
+
+       /**
+        * The complete event is dispatched when the drop operation has 
completed from the drop
+        * target's perspective.
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9
+        */
+       [Event(name="complete", type="org.apache.royale.events.Event")]
+
+       /**
+        *  The TreeMultiSelectionDropTargetBead enables items to be dropped 
onto multi-selection Tree
+        *  components. This bead can be used with MultiSelectionDragSourceBead 
to enable the re-arrangement
+        *  of rows within the same tree.
+     *
+        *  @see org.apache.royale.html.beads.SingleSelectionDropIndicatorBead
+     *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       public class TreeMultiSelectionDropTargetBead extends EventDispatcher 
implements IBead
+       {
+               /**
+                * Constructor
+            *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.10
+                */
+               public function TreeMultiSelectionDropTargetBead()
+               {
+                       super();
+               }
+
+               private var _dropController:DropMouseController;
+               private var _itemRendererOwnerView:IItemRendererOwnerView;
+               private var _dropIndicatorBead:SingleSelectionDropIndicatorBead;
+               private var _dropIndicator:UIBase;
+               private var lastItemVisited:Object;
+               private var indicatorVisible:Boolean = false;
+
+               private var _strand:IStrand;
+
+               /**
+                * @private
+                */
+               public function set strand(value:IStrand):void
+               {
+                       _strand = value;
+
+                       _dropController = 
getOrAddBeadByType(DropMouseController, value) as DropMouseController;
+
+                       _dropController.addEventListener(DragEvent.DRAG_ENTER, 
handleDragEnter);
+                       _dropController.addEventListener(DragEvent.DRAG_EXIT, 
handleDragExit);
+                       _dropController.addEventListener(DragEvent.DRAG_OVER, 
handleDragOver);
+                       _dropController.addEventListener(DragEvent.DRAG_DROP, 
handleDragDrop);
+               }
+
+               private var _dropDirection: String = "horizontal";
+
+               /**
+                * The direction the drop indicator should display. 
"horizontal" (default) or "vertical".
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9
+                */
+               public function get dropDirection():String
+               {
+                       return _dropDirection;
+               }
+               public function set dropDirection(value:String):void
+               {
+                       _dropDirection = value;
+               }
+
+               protected var _indicatorParent:UIBase;
+
+               /**
+                * @private
+                * @royaleignorecoercion 
org.apache.royale.html.beads.IDrawingLayerBead
+                */
+               protected function get indicatorParent():UIBase
+               {
+                       if (_indicatorParent == null) {
+                               var layerBead:IDrawingLayerBead = 
_strand.getBeadByType(IDrawingLayerBead) as IDrawingLayerBead;
+                               if (layerBead != null) {
+                                       _indicatorParent = layerBead.layer;
+                               }
+                       }
+                       return _indicatorParent;
+               }
+               /**
+                * @private
+                * @royaleignorecoercion 
org.apache.royale.core.IItemRendererOwnerView
+                */
+               private function get 
itemRendererOwnerView():IItemRendererOwnerView
+               {
+                       if (!_itemRendererOwnerView)
+                               _itemRendererOwnerView = 
_strand.getBeadByType(IItemRendererOwnerView) as IItemRendererOwnerView;
+                       return _itemRendererOwnerView;
+               }
+
+               /**
+                * @private
+                * @royaleignorecoercion 
org.apache.royale.html.beads.SingleSelectionDropIndicatorBead
+                */
+               protected function getDropIndicator(ir:Object, width:Number, 
height:Number):UIBase
+               {
+                       if (_dropIndicatorBead == null) {
+                               _dropIndicatorBead = 
_strand.getBeadByType(SingleSelectionDropIndicatorBead) as 
SingleSelectionDropIndicatorBead;
+                               if (_dropIndicatorBead == null) return null;
+                       }
+                       _dropIndicator = 
_dropIndicatorBead.getDropIndicator(ir, width, height);
+                       return _dropIndicator;
+               }
+
+               /**
+                * @private
+                * @royaleignorecoercion org.apache.royale.core.IUIBase
+                * @royaleignorecoercion org.apache.royale.core.IItemRenderer
+                */
+               private function handleDragEnter(event:DragEvent):void
+               {
+                       //trace("TreeMultiSelectionDropTargetBead received 
DragEnter via: "+event.relatedObject.toString());
+                       var newEvent:Event = new Event("enter", false, true);
+                       dispatchEvent(newEvent);
+                       if (newEvent.defaultPrevented) return;
+
+                       var pt0:Point;
+                       var pt1:Point;
+                       var pt2:Point;
+
+                       _dropController.acceptDragDrop(event.relatedObject as 
IUIBase, DropType.COPY);
+
+                       var startHere:Object = event.relatedObject;
+                       while( !(startHere is IItemRenderer) && startHere != 
null) {
+                               startHere = startHere.parent;
+                       }
+
+                       if (startHere is IItemRenderer) {
+                               var ir:IItemRenderer = startHere as 
IItemRenderer;
+                               lastItemVisited = ir;
+                       } else if (itemRendererOwnerView && 
itemRendererOwnerView.numItemRenderers > 0)
+                       {
+                               // as long as we're assuming the last item is 
dropped into in case there's no item renderer under mouse
+                               // this is needed
+                               lastItemVisited = 
itemRendererOwnerView.getItemRendererAt(itemRendererOwnerView.numItemRenderers 
- 1);
+                       }
+
+                       if (lastItemVisited && !indicatorVisible && 
indicatorParent) {
+                               var di:UIBase = 
getDropIndicator(lastItemVisited, (dropDirection == "horizontal") ? 
indicatorParent.width : 4,
+                                                                    
(dropDirection == "horizontal") ? 4 : indicatorParent.height);
+                               indicatorVisible = true;
+                               displayDropIndicator(lastItemVisited as 
IUIBase);
+
+                               if (indicatorParent != null) {
+                                       indicatorParent.addElement(di);
+                               }
+                       }
+
+               }
+
+               /**
+                * @private
+                */
+               private function handleDragExit(event:DragEvent):void
+               {
+                       //trace("TreeMultiSelectionDropTargetBead received 
DragExit via: "+event.relatedObject.toString());
+                       dispatchEvent(new Event("exit", false, true));
+
+                       if (indicatorVisible) {
+                               if (indicatorParent != null) {
+                                       
indicatorParent.removeElement(_dropIndicator);
+                               }
+                               indicatorVisible = false;
+                       }
+               }
+
+               /**
+                * @private
+                * @royaleignorecoercion org.apache.royale.core.IUIBase
+                */
+               private function handleDragOver(event:DragEvent):void
+               {
+                       //trace("TreeMultiSelectionDropTargetBead received 
DragOver via: "+event.relatedObject.toString());
+                       var newEvent:Event = new Event("over", false, true);
+                       dispatchEvent(newEvent);
+                       if (event.defaultPrevented) {
+                               return;
+                       }
+
+                       var startHere:Object = event.relatedObject;
+                       while( !(startHere is IItemRenderer) && startHere != 
null) {
+                               startHere = startHere.parent;
+                       }
+
+                       if ((startHere is IItemRenderer) && _dropIndicator != 
null && indicatorParent) {
+                               displayDropIndicator(startHere as IUIBase);
+                               lastItemVisited = startHere;
+
+                       }
+                       else if (lastItemVisited && _dropIndicator != null && 
indicatorParent) {
+                               displayDropIndicator(lastItemVisited as 
IUIBase);
+                       }
+               }
+
+               /**
+                * @private
+                * @royaleignorecoercion mx.collections.IList
+                * @royaleignorecoercion 
org.apache.royale.core.IDataProviderModel
+                * @royaleignorecoercion 
org.apache.royale.core.IIndexedItemRenderer
+                * @royaleignorecoercion 
org.apache.royale.core.IMultiSelectionModel
+                */
+               private function handleDragDrop(event:DragEvent):void
+               {
+                       //trace("TreeMultiSelectionDropTargetBead received 
DragDrop via: "+event.relatedObject.toString());
+
+                       handleDragExit(event);
+
+                       var newEvent:Event = new Event("drop", false, true);
+                       dispatchEvent(newEvent);
+                       if (newEvent.defaultPrevented) {
+                               return;
+                       }
+
+
+                       var startHere:Object = event.relatedObject;
+                       var child:IChild = startHere as IChild;
+                       while(child && child != _strand) {
+                               if (child is IIndexedItemRenderer)
+                               {
+                                       startHere = child;
+                               }
+                               child = child.parent as IChild;
+                       }
+
+                       if (DragEvent.dragInitiator) {
+                               DragEvent.dragInitiator.acceptingDrop(_strand, 
"object");
+                       }
+
+                       var dragSource:Object = DragEvent.dragSource;
+                       sendStrandEvent(_strand, new ValueEvent( 
"handlingDragDrop", startHere));
+
+
+                       // Let the dragInitiator know the drop has been 
completed.
+                       if (DragEvent.dragInitiator) {
+                               DragEvent.dragInitiator.acceptedDrop(_strand, 
"object");
+                       }
+                       
+                       var dataProviderModel:IDataProviderModel = 
getModelByType(_strand,IDataProviderModel) as IDataProviderModel;
+                       if (dataProviderModel is IMultiSelectionModel) {
+                               (dataProviderModel as 
IMultiSelectionModel).selectedItems = dragSource as Array;
+                       }
+
+                       // is this event necessary? isn't "complete" enough?
+                       sendStrandEvent(_strand,"dragDropAccepted");
+                       sendEvent(this,"complete");
+               }
+
+               COMPILE::SWF
+               private function displayDropIndicator(item:IUIBase):void
+               {
+                       var pt0:Point;
+                       var pt1:Point;
+                       var pt2:Point;
+
+                       if (dropDirection == "horizontal") {
+                               pt0 = new Point(0, item.y+item.height);
+                               pt1 = PointUtils.localToGlobal(pt0, 
item.parent);
+                               pt2 = PointUtils.globalToLocal(pt1, 
indicatorParent);
+                               _dropIndicator.x = 0;
+                               _dropIndicator.y = pt2.y - 1;
+                       }
+                       else {
+                               pt0 = new Point(item.x, 0);
+                               pt1 = PointUtils.localToGlobal(pt0, 
item.parent);
+                               pt2 = PointUtils.globalToLocal(pt1, 
indicatorParent);
+                               _dropIndicator.x = pt2.x - 1;
+                               _dropIndicator.y = 0;
+                       }
+               }
+
+               COMPILE::JS
+               private function displayDropIndicator(item:IUIBase):void
+               {
+                       var pt:Point = PointUtils.localToGlobal(new Point(0,0), 
item);
+                       pt = PointUtils.globalToLocal(pt,indicatorParent);
+                       if (dropDirection == "horizontal") {
+                               _dropIndicator.x = 0;
+                               _dropIndicator.y = pt.y;
+                       } else {
+                               _dropIndicator.x = pt.x;
+                               _dropIndicator.y = 0;
+                       }
+               }
+       }
+}
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/XMLTreeMultiSelectionDropTargetBead.as
 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/XMLTreeMultiSelectionDropTargetBead.as
new file mode 100644
index 0000000000..abcc51f65c
--- /dev/null
+++ 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/XMLTreeMultiSelectionDropTargetBead.as
@@ -0,0 +1,93 @@
+
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package mx.controls.beads
+{
+       import org.apache.royale.core.IBead;
+       import org.apache.royale.core.IDataProviderModel;
+       import org.apache.royale.core.IStrand;
+       import org.apache.royale.events.IEventDispatcher;
+       import org.apache.royale.events.ValueEvent;
+       import org.apache.royale.html.util.getModelByType;
+       import org.apache.royale.core.IItemRenderer;
+       import org.apache.royale.events.DragEvent;
+       import org.apache.royale.html.beads.DragBead;
+
+       /**
+        *  The XMLTreeMultiSelectionDragSourceBead handles drag source 
operaions special to XML data
+        *
+        *  @see org.apache.royale.html.beads.MultiSelectionDropTargetBead.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       public class XMLTreeMultiSelectionDropTargetBead implements IBead
+       {
+               /**
+                * Constructor
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.10
+                */
+               public function XMLTreeMultiSelectionDropTargetBead()
+               {
+                       super();
+               }
+
+               private var _strand:IStrand;
+               private var _draggedXML:XML;
+
+               /**
+                * @private
+                */
+               public function set strand(value:IStrand):void
+               {
+                       _strand = value;
+                       (value as 
IEventDispatcher).addEventListener("handlingDragDrop", handlingDragDropHandler);
+               }
+
+               /**
+                * @private
+                */
+               private function handlingDragDropHandler(event:ValueEvent):void
+               {
+                       var dataProviderModel:IDataProviderModel = 
getModelByType(_strand,IDataProviderModel) as IDataProviderModel;
+                       if (event.value)
+                       {
+                               var targetXML:XML = (event.value as 
IItemRenderer).data as XML;
+                               if (targetXML)
+                               {
+                                       var parent:XML = targetXML.parent() as 
XML;
+                                       var dragSources:Array = 
DragEvent.dragSource as Array;
+                                       for (var i:int = 0; i < 
dragSources.length; i++)
+                                       {
+                                               if (parent && dragSources[i] is 
XML)
+                                               {
+                                                       
parent.insertChildBefore(targetXML, dragSources[i] as XML);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}

Reply via email to