[squeak-dev] Event handling challenges

Trygve Reenskaug trygver at ifi.uio.no
Fri Jun 19 08:58:59 UTC 2020


Hi,
I'm grateful for your many responses to my cry for help. None of your 
suggestions gave a solution, but they gave useful entry points into very 
complex material. I made a small script that creates a light blue 
playfield, an instance of /PasteUpMorphXX/, a subclass of 
/PasteUpMorph/. It has 2 morphs inside it: a green CircleMorph and XXX, 
a TextMorphXX that is positioned by the user:

The example illustrates 2 problems:

1./The playfield grabs the Workspace when it is positioned within it, 
but the playfield should have ignored it./
The problem requires that I must distinguish between friend and foe. I 
do not want to create subclasses of all friends, and have chosen to tag 
the friends instead:
/    friend setProperty: #homeCanvas toValue: playfield/*/
/*

*/
/*

*/PasteUpMorphXX>>wantsDroppedMorph: aMorph event: evt/*/
^(aMorph valueOfProperty: #homeCanvas ifAbsent: [nil]) == self
/*
/    PasteUpMorphXX>>rejectDropEvent: anEvent/*/
self dpsTrace: anEvent levels: 10 //“see note below”.
((self valueOfProperty: #homeCanvas ifAbsent: [nil]) == self)
ifTrue: [anEvent wasHandled: true].

/

/2./The TextMorphXX grabs the cursor, making it into a Text cursor.
StringMorph has an inst.var. 'hasFocus' that takes care of such problems.
This inst.var. is missing in TextMorph and this method seems to solve my 
problem
*/    TextMorphXX>>processEvent: anEvent using: defaultDispatcher
/*/^#rejected/

That's all. The small script works as specified, and it is time to 
revert to porting SRE. This is a prerequisite for porting Loke, a 
personal computer for laypeople living in the connected society. Their 
computer shall be equally available on their several devices. A 
proof-of-concept Loke exists in 'Squeak3.10.2' as a non-intrusive 
program. I want to make it generally available in a modern Squeak for 
people to play with.


Thanks for your help

--Trygve


Note: When dpsTrace:levels: was executed, the stack depth was 47. (I 
have attached it for your enjoyment). I thought I understood the 
principle of event handling: The Hand picks up a sensor event and passes 
it to the top-level morph. From there, it is passed down the submorphs 
until it is handled. In this case, the path is: 
/_World-aPasteUpMorphXX-aTextMorhXXX_//./Yet, the Morphic event handling 
manages to create a stack with a depth of 47 before it asks if it may 
drop a morph. Not easy to grok, IMO.

This open-access article describes Loke
https://doi.org/10.1007/s10270-019-00768-3 
<https://doi.org/10.1007/s10270-019-00768-3>

The SRE User Manual
http://folk.uio.no/trygver/2005/babyuml/tweakComponents.pdf



On 2020.06.15 15:25, Trygve Reenskaug wrote:
> /The figures were missing when this message reached me. I resend 
> itwith the figures attached.
> -------------------------------------
> /
> Hi Squeakers,
> My SRE context browser is a tool for drawing a snapshot of a selected 
> structure of interlinked objects where each object is shown as a 
> rectangular symbol. This diagram shows an object with its class and 
> superclass objects:
>
>
> SRE has worked for years, last in 'Squeak3.10.2'. In 'Squeak5.3', the 
> same program went into an infinite loop. It transpired that 
> /myClass>>processEvent: anEvent using: defaultDispatcher/ had become a 
> new thing called an event filter and needed to return an Event or a 
> Symbol. That problem fixed; the program still misbehaves. The problem 
> seems to be with event handling. I have never been into that corner of 
> Smalltalk but have read some Squeak documentation. I have not found 
> any concrete code.  I realize that I will never understand Squeak's 
> event handling by reading code, code comments, and even the 
> documentation I have found. There has apparently been a significant 
> increase in complexity lately. An example: In 3,10,2, class 
> /MorphicEventDispatcher /has 4 methods. In 5,3, it has 16.
>
> Here's the beginning of my challenges with 5.3: I find two anomalies 
> in a diagram with just one symbol:
>
>  1.     When I move some other window to a position within the
>     diagram, the diagram grabs it and makes it a submorph of itself. 
>     In 3.10.2, the diagram ignores it.
>  2.     The cursor becomes a text cursor when I move the mouse across
>     a symbol.
>
> I have no explanation for either anomaly. My SRE code is a kludge and 
> is almost unreadable. It is hard to formulate a question without the 
> whole code as a background, and I have tried to reproduce them in a 
> simple example. I managed to reproduce the first, but not the second 
> anomaly. In a workspace, copy, select, and do it. The XXX-symbol 
> becomes attached to the cursor, and I place it in the blue background.
>
>     joe := PasteUpMorph new color: Color lightBlue.
>     joe bounds: (500 at 400 corner: 800 at 600).
>     joe dropEnabled: true.
>     joe openInWorld.
>     circle := CircleMorph new.
>     joe addMorphCentered: circle.
>     tex := TextMorphXX new
>             contents: 'XXX';
>             borderWidth: 1;
>             color: Color red;
>             extent: 100 at 100.
>     tex openInHand.
>
> There is only one  method in class TextMorphXX (sco TextMorph):
>
>     processEvent: anEvent using: defaultDispatcher
>         ^#rejected
>
>
>
> I move some background window,  actually a collapsed Monticello thing, 
> to Joe's position, Joe grabs it and makes it into a submorph. Any 
> hints about how to proceed will be greatly appreciated.
> --Trygve
>
-- 

/The essence of object orientation is that objects collaborateto achieve 
a goal. /
Trygve Reenskaug mailto: trygver at ifi.uio.no <mailto:%20trygver at ifi.uio.no>
Morgedalsvn. 5A http://folk.uio.no/trygver/
N-0378 Oslo http://fullOO.info
Norway                     Tel: (+47) 468 58 625

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200619/eb768563/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hmmeggpnegmdaifp.jpg
Type: image/jpeg
Size: 5362 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200619/eb768563/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clfapgjkmegmpnfm.gif
Type: image/gif
Size: 14037 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200619/eb768563/attachment-0001.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ojfapckoaibeechh.png
Type: image/png
Size: 42394 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200619/eb768563/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stack-1.docx
Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Size: 15738 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200619/eb768563/attachment-0001.docx>
-------------- next part --------------
PasteUpMorph subclass: #PasteUpMorphXX
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: '000-EventExperiments'!
!PasteUpMorphXX commentStamp: 'TRee 6/19/2020 10:55' prior: 0!
This sco PasteUpMorph is fixed so that ignores Morphs that are moved onto it.

!


!PasteUpMorphXX methodsFor: 'events-processing' stamp: 'TRee 6/18/2020 16:02'!
rejectDropEvent: anEvent
	self dpsTrace: anEvent levels: 10.
	((self valueOfProperty: #homeCanvas ifAbsent: [nil]) == self)
		ifTrue: [anEvent wasHandled: true].


"copy of original"
	"This hook allows the receiver to repel a drop operation currently executed. The method is called prior to checking children so the receiver must validate that the event was really designated for it.
	Note that the ordering of the tests below is designed to avoid a (possibly expensive) #fullContainsPoint: test. If the receiver doesn't want to repel the morph anyways we don't need to check after all."

"	(self repelsMorph: anEvent contents event: anEvent) ifFalse:[^self]. "
"	(self fullContainsPoint: anEvent position) ifFalse:[^self]." "not for me"
	"Throw it away"
"	anEvent wasHandled: true.
	anEvent contents rejectDropMorphEvent: anEvent."! !

!PasteUpMorphXX methodsFor: 'events-processing' stamp: 'TRee 6/18/2020 16:03'!
wantsDroppedMorph: aMorph event: evt
	self dpsTrace: evt levels: 100.
	^(aMorph valueOfProperty: #homeCanvas ifAbsent: [nil]) == self
	! !


!PasteUpMorphXX methodsFor: 'testing' stamp: 'TRee 6/17/2020 15:46'!
run 
	" PasteUpMorphXX new run "
| circle joe tex |
joe := PasteUpMorphXX new color: Color lightBlue.
joe bounds: (500 at 400 corner: 800 at 600).
joe 
	dragEnabled: true;
	dropEnabled: true.
"joe hasFocus."
joe openInWorld.

	circle := CircleMorph new.
	circle setProperty: #homeCanvas toValue: joe.
	joe addMorphCentered: circle.

 	tex := TextMorphXX new
		contents: 'XXX';
		borderWidth: 1;
		color: Color red;
		extent: 100 at 100.
	tex setProperty: #homeCanvas toValue: joe.
	joe addMorphCentered: tex.
	
	tex openInHand.
	
	
	
	
	" (CircleMorph new color: Color blue) openInHand. "


"joe explore.
tex explore.

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

This is the only method in class TextMorphXX (sco TextMorph)

TextMorphXX>>processEvent: anEvent using: defaultDispatcher
	^#rejected
	
	Smalltalk version 'Squeak5.3'"! !


TextMorph subclass: #TextMorphXX
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: '000-EventExperiments'!
!TextMorphXX commentStamp: 'TRee 6/19/2020 10:57' prior: 0!
This sco TextMorph does not grab the cursor when the nouse is moved over it.!


!TextMorphXX methodsFor: 'events-processing' stamp: 'TRee 6/17/2020 08:28'!
processEvent: anEvent using: defaultDispatcher
	^#rejected! !


More information about the Squeak-dev mailing list