Patches item #433195, was opened at 2001-06-14 10:59
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305757&aid=433195&group_id=5757

Category: DynAPI 2 Extension
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Scott Severtson (scottsevertson)
Assigned to: Nobody/Anonymous (nobody)
Summary: DragDrop requirements

Initial Comment:
Currently, drop events are fired only if the event 
source layer is release entirely within the listening 
layer.

Traditional drag-and-drop at the OS level accepts drop 
events if an element is dragged and released with just 
the mouse pointer inside the target. This includes 
Windows, Macintosh, and most X apps that support drag 
and drop.

The following changes will make this requirements 
change take effect.



dynapi\event\dragevent.js, line 121:
FROM:
if (lyr.parent.DragDrop) lyr.parent.DragDrop(lyr);

TO:
if (lyr.parent.DragDrop) lyr.parent.DragDrop(lyr, e);




dynapi\ext\dragdrop.js, lines 10-26:
FROM:
DynObject.prototype.DragDrop=function(s){
  if (!this.children.length>0) return false;
  var ch,chX,sX,sY;
  for (var i in this.children) {
    ch=this.children[i];
    chX=ch.getPageX();
    chY=ch.getPageY();
    sX=s.getPageX();
    sY=s.getPageY();
    if (chX<sX && chX+ch.w>sX+s.w && chY<sY && 
chY+ch.h>sY+s.h) {
      if (ch.DragDrop(s)) return true;
      ch.invokeEvent("drop");
      return true;
    }
  }
  return false;
};

TO:
DynObject.prototype.DragDrop=function(s,e){
  if (!this.children.length>0) return false;
  var ch,chX,chY,eX,eY;
  for (var i in this.children) {
    ch=this.children[i];
    chX=ch.getPageX();
    chY=ch.getPageY();
    eX=e.getX();
    eY=e.getY();
    if (chX<eX && chX+ch.w>eX && chY<eY && 
chY+ch.h>eY) {
      if (ch.DragDrop(s,e)) return true;
      ch.invokeEvent("drop");
      return true;
    }
  }
  return false;
};


Tested on Windows NT, IE 5.01 and NS 4.72.


Test Case:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript" 
SRC="dynapi/dynapi.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript"><!--
  DynAPI.setLibraryPath("dynapi/lib/");
  DynAPI.include("dynapi.api.*");
  DynAPI.include("dynapi.event.*");
  DynAPI.include("dynapi.ext.dragdrop");
//--></SCRIPT>
<SCRIPT LANGUAGE="JavaScript"><!--
DynAPI.onLoad = function() {
  myTarget1= new DynLayer
('Target1',200,300,50,50,'green')
  mySource1 = new DynLayer
('Source1',250,200,20,20,'#00FF99')
  myListenerDrop=new EventListener(myTarget1)
  myListenerDrop.ondrop=function(e) {
    alert("dropped");
  }
  myTarget1.addEventListener(myListenerDrop)

  DragEvent.enableDragEvents(mySource1)
  DynAPI.document.addChild(myTarget1)
  DynAPI.document.addChild(mySource1)
}
//--></SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>



----------------------------------------------------------------------

Comment By: Scott Severtson (scottsevertson)
Date: 2001-06-15 08:43

Message:
Logged In: YES 
user_id=159783

An updated version to address a bug in the previous patch 
to the dragdrop extension.

Bug: If Source is added to document before Target, "drop" 
event not fired on target.

Cause: Source object was found as a drop target before the 
targe. In other words, the drop event was fired, just not 
on the correct object.

Updated Patch:
DynObject.prototype.DragDrop=function(s,e){
  if (!this.children.length>0) return false;
  var ch,chX,chY,eX,eY;
  eX = e.getX();
  eY = e.getY();
  for (var i in this.children) {
    ch=this.children[i];
    if(ch!=s) {
      chX=ch.getPageX();
      chY=ch.getPageY();
      if (chX<eX && chX+ch.w>eX && chY<eY && chY+ch.h>eY)  {
        if (ch.DragDrop(s,e)) return true;
        ch.invokeEvent("drop");
        return true;
      }
    }
  }
  return false;
};


----------------------------------------------------------------------

Comment By: Ernest MacDougal Campbell III (emc3)
Date: 2001-06-14 12:48

Message:
Logged In: YES 
user_id=29866

Yeah, I was thinking about it a little, and I wasn't sure 
of the best place for the flag, either. Should it be on the 
layer being dragged (sourceLayer.DropAllOfMe)? Or should it 
be on the target layer (targetLayer.DropFullyContained)? My 
leaning is that it should be on the target layer.

As far as a flag name goes.... Maybe we could have 
a "DropType" property with possible values of "pointer" 
(mouse coords should be used) or "layer" (layer boundaries 
should be used), defaulting to "pointer". In the future, it 
might be possible to extend the DragDrop behavior to 
incorporate other dragtypes (eg. "overlap" => part of the 
source layer overlaps the target, but the mouse pointer is 
outside the target).


----------------------------------------------------------------------

Comment By: Scott Severtson (scottsevertson)
Date: 2001-06-14 12:15

Message:
Logged In: YES 
user_id=159783

Sounds good - I will defer to a formal project member, as 
they probably have a better sense of where the flag should 
live/naming conventions.

Just a heads up -- I've found a bug in drag and drop - if 
the drag Target is added to a document AFTER the drag 
Source, no drop event is fired. I'll do my best to track it 
down and submit a fix.

----------------------------------------------------------------------

Comment By: Ernest MacDougal Campbell III (emc3)
Date: 2001-06-14 12:05

Message:
Logged In: YES 
user_id=29866

Good catch. I'd like to suggest, however, having some sort 
of flag to allow the old behavior, for those who might want 
it. Sure, the developer could check the layer boundries on 
his own in his ondrop code, but if we've already got it 
coded, why make everybody re-invent the wheel?

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305757&aid=433195&group_id=5757

_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev

Reply via email to