One thing you do get with lists and buttons is a tried-and-true definition of the protocol for their use. All of these objects are windows of some kind, and may have child windows themselves. Windows provide you with a pre-built set of functionality to deal with opening, re-sizing, invalidation-based redisplay, and many other features you only become aware of when you deviate from the norm.We set any Smalltalk code and method selectors in a monospace font, likeThis, so you can differentiate them from more normal text.Warning: Are you looking at this in a Help file? If so, you won’t be able to see the visual clues we supply in the margin of the printed manual. Sorry, but it is a limitation of the software we use to produce Help files. You should be able to tell from the text where we’re talking about platform-specific stuff.You will use an event model to “hook into” things that happen to GO’s. For example, when you want to know when someone double-clicks on a GO, you will simply tell the GO to let you (or any other object) know by sending a message. You need only look at the list of events that are triggered by various GO’s to be up and running (see the Summary of Events section). If you feel you need a quick refresher, read on, because unless you understand events, everything in GF/ST may look like it is happening by magic.In its broadest sense, GF/ST provides a framework for coordinating domain model objects, graphic objects, and user interactions. This is a familiar problem, and a generic solution for it has existed in Smalltalk for a long time in the form of Model-View-Controller programming, or MVC. MVC provides a way to couple objects loosely (i.e., loose coupling) via a dependency mechanism. These are two object-oriented buzzwords that you should know and understand regardless of what Smalltalk you use. For a more generic description of the problem and solution, you might want to check out the “Observer” pattern in Gamma et al’s book. The classic treatise on MVC is Krasner and Pope’s paper “A Cookbook for Using the Model-View-Controller Paradigm in Smalltalk-80.” The details are well beyond the scope of this manual, but it is extremely useful to understand the concepts, as they are closely related to the GF/ST event model. The general idea is this:You are an object that models some part of the problem domain (i.e., a domain model), and I am an object that depends on your state somehow. For example, I am a visual representation of your state (e.g., a view or a GO). It is a bad idea from the standpoint of reusability for you to know how I am displaying you, or even that I exist at all. On the other hand, it’s okay for me to know about you by holding onto you as one of my instance variables. We solve this problem using MVC. I tell you to add me as a dependent. You, as a good Smalltalk citizen, announce whenever your state changes in any interesting way. Through the MVC dependency mechanism, I will receive a message to update myself.You may not be aware of it, but MVC is implemented in all Smalltalk versions. Events work in much the same way -- “Hey, the mouse moved!”, “Someone resized me!”, and so on. The difference is that by using events, we can be much more specific about what has changed, what object should be notified, as well as the message and arguments that should be sent when an event occurs.There are two sides to using events: registering events as a public interface for a class, and hooking into them so you can be notified when an event occurs. When we create a class, instances of which will be triggering events, we publish a list of events that these instances will trigger in a class method called eventsTriggered. This list lets the outside world know what kind of events our object will be triggering as it changes state (e.g., #getMenu, #button1DoubleClick, and so on).When someone wants to be notified that your object triggered some event, they send it the message when:send:to: with the event name (a symbol) as the first argument, a selector (symbol) as the second argument, and the receiver object for the selector as the third argument. If the selector requires arguments, they use when:send:to:with: and include an array of arguments for the selector.Instead of using the MVC-style changed message to notify dependents that they have changed, subclasses of PsiEventModel trigger events that describe the kind of change that has occurred, using one of the following expressions:By sending the message when:send:to: or one of its variations to aModel, you are setting up the dependency relationship, just as any MVC programmer accomplishes using addDependent:.GO’s trigger a well-defined set of events which are documented in the Class Hierarchy and Events chapter of the manual. For example, when you create a GO, you can say:
|   |