Solved? How to code for start of drag

Ross Boylan RossBoylan at stanfordalumni.org
Fri Aug 3 08:17:15 UTC 2001


How do I get the code that does the first part of drag and drop to
kick in?  Here's a tentative answer; I welcome corrections.

I have two morphs.  I want to click on the inner morph and, if I keep
the mouse down, drag it out.  I seem to be having problems getting the
click-drag hooked into the start of the drag code.

After experimenting, it seems the key is to capture the mouseDown
event (via #handlesMouseDown:) and then
mouseDown: evt
	^self grabMorph: evt

Should I be using grabTransform in here?  Is this the right idea?  (I
was inspired by browsing senders of #grabMorph:).

My outer morph (Morph subclass: MorphA) is initialized with
initialize
	|b|
	super initialize.
	self color: self defaultColor.
	self extent: 100 at 100;
		enableDragNDrop.
	b _ MorphB new.
	b center: self center;
		extent: self extent / 3.0.
	self addMorphFront: b.

On the one hand, I thought that drag and drop was supposed to work
pretty automatically.  On the other, I don't see how it could: if I
click on a morph I may want to popup a menu, perform some action, or
drag it, and it seems that needs to be in the code.

If I get past this to a real world example, I'll also have several
levels of nesting.  For example if D is in C in B in A, and I want to
be able to drag D out (really a copy of it), which of A, B, and C need
changes to support it?  I was going to research this on my own, when I
discovered I couldn't even handle the B in A case :(.

P.S. As others have noted David Smith's stuff on the swiki doesn't
conform to current protocols.  I'm running 3.1 alpha #4173.




More information about the Squeak-dev mailing list