*** Hi Ian,
This is an excellent question ‘cause it shows up the current obscurity of the answer.
The secret you need to know its that the object that dispatches the mouse events looks high and low for someone to handle it. When an unspecial morph is clicked on the fellow who handles it is the paste up morph that holds the morph. The pasteup morph usually lifts the morph and puts it in the hand, which then moves it and eventually drops it somewhere.
So check out PasteUpMorph>>mouseDown: etc.
The second useful secret to know is that you can make a morph special by going to its menu and giving it a mouseUp action. Then the morph is highlighted when the mouse is over it and pressing the mouse will prime and the action which will happen if the mouse is released while you are still in the object.
Or... The third useful secret is you can make a morph special by giving on: #mouseDown send: #selector to: anObject with: argument works also for #mouseUp and mouseMove and a bunch of other things. The special morph now has an EventHandler which gets first crack at events before the PasteUpMorph of the first secret.
look at the implementers and senders of #on:send: ...
Or... The last not so useful secret is you could try to write handlers to make your morph special. This is not so useful because it takes full understanding of a lot of subtleties. And if you can actually understand what you are doing you will probably get distracted in fixing the bugs you will run across.
For this look at morphs that have their own handlers and imitate.
You are usually best off working with secret three.
Yours in curiosity and service, --Jerome Peace
[Newbies] How do you find which code runs when you click on something?
Matthew Fulmer tapplek at gmail.com Wed Jun 27 00:26:41 UTC 2007
On Tue, Jun 26, 2007 at 09:47:29PM +0100, Ian
Oversby
wrote:
Hi,
I'm trying to find out which code is run when I
click
on something
in Squeak. I've tried selecting the menu from the
middle button
and then selecting debug ->explore morph. Is this
the best
way? Does it work for all morphs? How can I add
new
menu
items which run arbitrary code?
I tried exploring the morph, and also browsing the
class
protocol (select the object in the
inspector/explorer,
and press cmd-p). I limited the inheritance chain to
StringMorph,
and examined the "event handlers" method category. I
looked
at the mouseUp handler (mouse up is the usual place where actions are invoked), and the last line looked promising: "self invokeWithEvent: t1". I highlighted that and pressed cmd-m to jump to that method. The last few lines looked like
the
real work. So I put a "self halt." right above the Cursor normal showWhile: [...] block and saved (cmd-s). Now,
whenever
I hit a menu item, I get a debugger ready to execute the
menu
command.
Whenever you are done, hit any menu item, remove the "self halt." in the debugger window, save, and proceed.
Hope that helps.
-- Matthew Fulmer -- http://mtfulmer.wordpress.com/ Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808
***
____________________________________________________________________________________ Pinpoint customers who are looking for what you sell. http://searchmarketing.yahoo.com/
beginners@lists.squeakfoundation.org