Edit Rename Changes History Upload Download Back to Top

VisualWorks UI Events

VisualWorks Smalltalk is a portable Smalltalk implementation that runs on many Unixes, Mac and Windows. All that changes between platforms is the virtual machine, and this is the interface between the host environment and the Smalltalk environment. In the case of UI events, the VM handles all events for all the Smalltalk windows.

Smalltalk in VisualWorks uses green threads. That is, from the operating system point of view there is only one real thread executing Smalltalk code. This makes the system nicely deterministic.

All UI events (mouse, keyboard and damage) flow into the Smalltalk system via a single instance of the class InputState. For each event, the InputState is invoked by the VM and is given a window handle (which maps to a Window instance in the image) and an Array which contains the details of the event.

Each event needs to get to the Smalltalk code which represents the window as seen by a user. To see how the event gets there we need to understand a little of how windows work in VisualWorks. Here are the key players and what they do:

Now we have all the players in the game, lets have a look at how things unfold. We assume that an ApplicationModel has been started and that the Builder has created the ApplicationWindow and set it up to run.

The following happens in a process called the "event loop"

  1. The VM receives an event from the OS
  2. The VM passes the event Array and ApplicationWindow to the InputState
  3. The InputState asks the subject ApplicationWindow for the EventSensor and passes the event to it.
  4. The EventSensor creates an instance of Event corresponding to the values in the Array passed in by the VM
  5. The EventSensor asks the ApplicatioWindow to add the new event to the EventQueue of it's WindowManager.
There is also one process for each WindowManager in which the WindowManager loops pulling events out of the queue. It goes like this:

  1. The WindowManager pulls the next Event from it's EventQueue
  2. The WindowManager identifies the ApplicationWindow which is the subject of the Event.
  3. The WindowManager hands the Event to the ApplicationWindow for action
  4. The ApplicationWindow calls the logic in the ApplicationModel which corresponds to the Event (e.g. a button being clicked, or a character being entered).
  5. Once the Event has been completely handled, the ApplicationWindow returns control to the WindowManager which starts the loop again

Edit Rename Changes History Upload Download Back to Top