[ENH] Drag/Drop: Morph>>aboutToDropInto:event:

David N. Smith (IBM) dnsmith at watson.ibm.com
Tue Jan 25 01:14:54 UTC 2000


At 19:08 -0500 1/23/2000, David N. Smith \(IBM\) wrote:
>All:
>
>I've been doing lots of dragging and dropping and I could not find a message that got sent to the morph that is about to be dropped into a target morph. There is one that happens just *after* the drop, but the dropped morph has already been accepted and side effects may have already happened.
>
>Note that this message is sent to the morph that is *about* to be dropped, not to the target.
>
>Answering true means that the dragged morph agrees to be dropped on the target morph. Otherwise, it has no say in where it gets dropped.
>...
>
>The change adds one tiny method to Morph, which always answers true, and three lines to HandMorph>>dropMorphsEvent: (a bit over half the way down, marked "DNS").
>
>Example:
>
>aboutToDropInto: targetMorph event: anEvent
>	" Only let us drop into a DavesWordRowMorph morph "
>
>	^ (targetMorph isKindOf: DavesWordRowMorph)
>		ifTrue: [ true ]
>		ifFalse: [
>			self slideBackToFormerSituation: anEvent.
>			false ]
>
>Dave

There is another message from today with lots of discussion about why one would want to let the dropped morph decide for itself if it wants to go where it's dropped.

The changes previously sent are repeated below with two trash can fixes that make the trash can close properly if a morph doesn't want dropped in the trash.



'From Squeak2.7 of 5 January 2000 [latest update: #1789] on 24 January 2000 at 7:57:56 pm'!

!TrashCanMorph methodsFor: 'event handling' stamp: 'dns 1/24/2000 19:55'!
mouseLeave: event
	"Present feedback for aborted deletion."
	| hand |
	enteredDragging := false.  "DNS"
	hand _ event hand.
	((hand submorphCount > 0) and:
	[hand submorphs first ~~ self])
		ifTrue:
			[Preferences soundsEnabled ifTrue: [self class playMouseLeaveSound].
			hand endDisplaySuppression.
			self state: #off]
		ifFalse:
			[self stopShowingStampIn: hand].
! !




'From Squeak2.7 of 5 January 2000 [latest update: #1789] on 24 January 2000 at 7:57:51 pm'!

!TrashCanMorph methodsFor: 'event handling' stamp: 'dns 1/24/2000 19:51'!
mouseEnter: event
	"Present feedback for potential deletion."
	| hand |
	enteredDragging ifTrue: [ "DNS"
		"This is a second entry; we're already here!!"
		event hand endDisplaySuppression.  "DNS"
		enteredDragging := false.  "DNS"
		self state: #off.  "DNS"
		^ self ]. "DNS"
	
	hand _ event hand.
	((hand submorphCount > 0) and:
	[hand submorphs first ~~ self])
		ifTrue: [
			enteredDragging := true.  "DNS"
			Preferences soundsEnabled ifTrue: [self class playMouseEnterSound].
			hand startDisplaySuppression.
			self world abandonAllHalos.
			self state: #pressed]
		ifFalse: [
			enteredDragging := false.  "DNS"
			self showStampIn: hand].
! !



'From Squeak2.7 of 5 January 2000 [latest update: #1789] on 24 January 2000 at 7:58:05 pm'!

!Morph methodsFor: 'dropping/grabbing' stamp: 'dns 1/23/2000 15:33'!
aboutToDropInto: targetMorph event: anEvent
	" Sent to the morph that is about to be dropped to see if it minds being dropped here. The default is true. (dns)"

	^ true! !



'From Squeak2.7 of 5 January 2000 [latest update: #1789] on 24 January 2000 at 7:58:20 pm'!

!HandMorph methodsFor: 'grabbing/dropping' stamp: 'dns 1/23/2000 15:29'!
dropMorphsEvent: evt
	"Drop all the morphs this hand is currently holding in response to the given event."
	"Details: All submorphs of the front-most composite morph under the hand are given an opportunity to accept the dropping morph. If none of these accepts it, or if there is no morph under the hand, then the morph drops into the world."

	| newOwner morphToDrop tfm localPt grabbedMorph pos |
	owner ifNil: [^ self].
	self changed.
	self submorphsReverseDo: [:m |
		"drop in reverse order to maintain back-to-front ordering"
		addedFlexAtGrab == true
			ifTrue: [pos _ m firstSubmorph position.
					grabbedMorph _ m removeFlexShell.
					self privateRemoveMorph: grabbedMorph.
					grabbedMorph position: pos  "undo offset from removeFlexShell"]
			ifFalse: [grabbedMorph _ m].
		newOwner _ self dropTargetFor: grabbedMorph event: evt.
		newOwner ifNil:  "Drop not allowed"
			[self rejectDropMorph: grabbedMorph event: evt.
			addedFlexAtGrab == true
			ifTrue: [self privateRemoveMorph: m.
					addedFlexAtGrab _ false].
			^ self].

		morphToDrop _ newOwner morphToDropFrom: grabbedMorph.
		morphToDrop == grabbedMorph ifFalse: [submorphs size == 1 ifTrue:
			[self privateRemoveMorph: m.
			m privateOwner: nil.
			addedFlexAtGrab _ false]].
		"the above says: the thing to drop is not what I was carrying; silently vaporize what I was carrying lest it cause trouble later; keep the owner/submorph relationship invariant, but don't go through the standard delete protocol"

		" Ask the dragged morph what it thinks about being dropped on the target. If it doesn't like it then return without doing a drop. "
		(morphToDrop aboutToDropInto: newOwner event: evt) == true ifFalse: [ "DNS"
			^ self ]. "DNS"

		tfm _ newOwner transformFromWorld.
		localPt _ tfm globalPointToLocal: self position.
		addedFlexAtGrab == true
			ifTrue: [morphToDrop position: localPt
						+ (morphToDrop position - (m transform globalPointToLocal: self position)).
					self privateRemoveMorph: m.
					addedFlexAtGrab _ false]
			ifFalse: [morphToDrop position: localPt + (morphToDrop position - self position)].
		newOwner acceptDroppingMorph: morphToDrop event: evt.
		morphToDrop justDroppedInto: newOwner event: evt.
		morphToDrop owner = self ifTrue: [self world addMorphFront: m]].
	self layoutChanged.
	formerOwner _ nil.
	formerPosition _ nil! !




_______________________________
David N. Smith
IBM T J Watson Research Center
Hawthorne, NY
_______________________________
Any opinions or recommendations
herein are those of the author  
and not of his employer.





More information about the Squeak-dev mailing list