displayOn: aDisplayMedium

at: aPoint

clippingBox: aRectangle

rule: aCompositionRule

mask: aMotif

displays the receiver on the argument a DisplayMedium at the position aPoint, without exceeding the limits of aRectangle and applying the mask aMotif with the composition rule aCompositionRule,

follow: aBlock while: aBlockCondition

so long as evaluation of the block aBlockCondition returns true, the block aBlock is evaluated to give the position at which the receiver must be displayed and the zone hidden by the receiver at the previous evaluation is redisplayed,

valueAt: aPoint

returns 0 or 1 depending on whether the pixel located at the position aPoint in the receiver is white or black,

valueAt: aPoint put: aBit

sets the pixel located at the position aPoint in the receiver to white or black depending on whether the argument aBit is 0 or 1.

### 15.2.4 The class Cursor

The class Cursor is a subclass of the class Form. Depending on the system status, different cursors appear. These cursors indicate, by their position, the place on the screen pointed to by the mouse, and by their form the status of the system. The cursor forms occupy 16 x 16 pixels.

The message cursorLink: sent to the class Cursor allows movement of the cursor to be linked or not to the movement of the mouse, depending on whether its argument is true or false.

The messages supported by the class cursor are:

show

where the receiver becomes the current cursor,

showGridded: aPoint

the receiver becomes the current cursor, with its position being a multiple of the argument aPoint,

showWhile: aBlock

the receiver becomes the current cursor while the block given as argument is evaluated, after which the current cursor becomes the previous cursor.

### 15.2.5 The class DisplayScreen

The class DisplayScreen is a subclass of the class DisplayMedium. The instances of the class DisplayScreen serve to represent the complete screen (the screen is a rectangular form comprising a certain number of pixels; it may therefore be likened to an instance of the class
Form). There is in the Smalltalk system a single instance of the class DisplayScreen referenced by the global variable Display. Note the following message:

flash: aRectangle

which causes to flash that part of the screen corresponding to the rectangle given as argument.

### 15.2.6 The class Path

The class Path is a subclass of the class DisplayObject which is used to draw a form along the length of a "trajectory". A trajectory is an OrderedCollection of points. The instances of the class Path have two instance variables that are a form and a trajectory. The messages of the class Path may be divided into the following categories.

#### Access

The messages that allow access to the characteristics of the instances are:

form

returns the form referenced by the receiver,

form: aForm

replaces the form referenced by the receiver by the form
aForm,

at: anIndex

returns the point of the trajectory referenced by the receiver of index anIndex,

at: anIndex put: aPoint

replaces the trajectory point of index anIndex by the
point aPoint,

size

returns the number of points of the trajectory referenced by the receiver.

#### Test

The message empty returns true if the trajectory referenced by the receiver contains no point.

#### Add

The message add: adds the point given as argument at the end of the trajectory referenced by the receiver.

#### Remove

The message removeAllSuchThat: removes from the trajectory referenced by the receiver all the points for which evaluation of the block given as argument returns true.

#### Enumeration

The three messages that allow the points of a trajectory to be handled successively are:

do: aBlock
evaluates the block given as argument for each point of
the trajectory referenced by the receiver,

collect: aBlock

evaluates the block given as argument for each point of
the trajectory referenced by the receiver and returns an
instance of OrderedCollection containing the results of
each evaluation,

select: aBlock

evaluates the block given as argument for each point of
the trajectory referenced by the receiver and returns an
instance of OrderedCollection containing the points for
which the evaluation has returned true.

The subclasses of the class Path correspond to particular trajectories. These are:

- straight lines

- arcs of circles

- circles

### 15.2.6.1 The class Line

The class Line is a subclass of the class Path that allows rectilinear trajectories to be represented by giving the two extremities of the trajectory. The additional messages implemented in this class are:

beginPoint

returns the first point of the receiver,

endPoint

returns the second point of the receiver,

beginPoint: aPoint

replaces the first point of the receiver by the point
aPoint,

endPoint: aPoint

replaces the second point of the receiver by the point
aPoint.

### 15.2.6.2 The classes Arc and Circle

The classes Arc and Circle are subclasses of the class Path which allow sections of circles and circles to be represented.

## 15.3 The class BitBlt

The class BitBlt is a subclass of the class Object. (The name BitBlt stands for Bit Block Transfer, a technique for altering and copying rectangular areas of a picture.) The instances of the class are objects that are capable of transferring pixels of one form to another form, while respecting certain constraints given by their instance variables. The instance variables that control pixel transfer are:

destForm

which is a form in which the transferred pixels will be
stored,

sourceForm
which is a form from which the pixels to be transferred are taken,

halftoneForm

which is the motif with which the starting form will be composed. There are four possible cases:

- sourceForm and halftoneForm are equal to nil; the form transferred will be a black form

- sourceForm is equal to nil; the form transferred will be the motif propagated in all directions

- halftoneForm is equal to nil; the form transferred will be the sourceForm

- halftoneForm and sourceForm are not nil; the form transferred will be obtained by making a logical AND between the sourceForm and the motif propagated in all directions.

combinationRule

which is an integer representing the composition rule of the starting form and arrival form (cf composition rules defined in 15.2.2).

sourceX, sourceY, width, height

which are four integers designating the region of the starting form from which the pixels will be copied,

destX, destY

which are two integers designating the region of the destination form where the pixels will be placed,

clipX, clipY, clipWidth, clipHeight

which are four integers that limit the region that can be altered by the copy.

The message that makes the copy, while respecting the constraints imposed by the instance variables, is copy-Bits. Generally, the call to BitBlt is made by other classes like Form, Line, etc., and the user does not have to invoke it explicitly.

The class BitBlt implements another important message:

drawFrom: aStartPoint to: anEndPoint

which allows a form to be propagated between the two points given as argument.

## 15.4 The class Pen

The class Pen is a subclass of the class BitBlt. The instances of the class Pen simulate a stylus that can be moved on the screen and which leaves a trace, or does not, depending upon whether it is lowered or raised.

Since the class Pen is a subclass of the class BitBlt, drawing operations are carried out more quickly using it rather than instances of the class Line.

The instances of the class Pen have four instance variables:

penDown
which is a boolean indicating whether the stylus is lowered or raised,

location

which is a point indicating the current stylus position,

direction

which is an angle expressed in degrees indicating the direction of the stylus trace,

frame

which is a rectangle indicating the limits within which the stylus can trace.

The messages of the class Pen may be divided into the following categories.

### Access

The messages that allow access to the characteristics of the stylus are:

down

lowers the receiver,

up

raises the receiver,

location

returns the current position of the receiver,

direction

returns the direction in degrees of the trace of the receiver,

turn: anAngleInDegrees

adds to the current direction of the trace of the receiver the argument anAngleInDegrees, which is equivalent to turning the angle anAngleInDegrees in relation to its current direction,

north

orients the trace of the receiver towards the top of the screen,

frame

returns the rectangle in which the receiver may trace,

frame: aRectangle

replaces the rectangle in which the receiver may trace by the argument aRectangle,

defaultNib: aWidth

replaces the width of the receiver by the argument aWidth,

colour: aMotif

replaces the motif of the receiver by the motif given as argument.

### Movement

The messages that allow the stylus to be moved are:

place: aPoint

replaces the current position of the receiver by the point aPoint,

home
places the receiver at the centre of the rectangle in
which it may trace,

go: aDistance

moves in the current direction by a distance aDistance,
tracing if the receiver is lowered,

goto: aPoint

moves in a straight line to the point given as argument,
tracing if the receiver is lowered.
# 16 Basic Elements of the Interface

Every information system has an interface to allow communication with a user. This interface usually consists of a keyboard and a screen.

There are two basic types of screen, a character type and a graphics type. Smalltalk uses a graphics screen.

Two technologies are used for graphics screens, depending on their function - vector scan screens and raster scan screens. The former allow lines to be drawn very quickly, and they are used for CAD and similar applications. The latter manipulate points; if these points are individually accessible, such screens are said to be bit-mapped. It is this last type of screen that we find in the Smalltalk system.

The number of points on the screen depends on the machine and the Smalltalk system can adapt itself to this number of points.

The Smalltalk system uses a standard keyboard as input device, but another device, commonly known as a "mouse", is also required.

## 16.1 Mouse

A mouse is a device that allows the user to designate a point on the screen by moving the mouse around on a flat surface. The mouse incorporates buttons that cause different operations to occur when they are pressed. There are usually three buttons in the Smalltalk system.

These buttons are identified by colour:

* the left button is the red button (redButton),

* the centre button is the yellow button (yellowButton),

* the right button is the blue button (blueButton).

In the Smalltalk system each button has a particular function:

* the red button is used to select or designate a visible area,

* the yellow button is used to call up the menu that allows the inside of the viewed area to be changed,

* the blue button is used to call up the menu that allows the viewed area itself to be changed.

## 16.2 Windows

A window is a rectangular portion of the screen in which
a program specific to this window runs, independently of the content of other windows. For each application there are specialised windows. For example, there are windows in which text can be edited and others in which drawings can be edited.

In the Smalltalk system, activities are not assigned to the screen but to the individual windows that go to make up the screen.

A window is said to be active when the user can interact with the contents of that window. There can be only one window active at a time.

When windows are superimposed, the active window is the one that is visible.

If there is no active window, as soon as the cursor moves inside a window, that window becomes active. To change windows, the cursor must be placed in an inactive window and a button on the mouse pressed. If one of the mouse buttons is pressed with the cursor outside any window, there is no longer any window active.

### 16.3 Pop-up menus

A pop-up menu is a window that appears at the cursor position when the yellow or blue button on the mouse is pressed. This menu remains displayed for as long as the user holds the button down.

These menus offer a list of commands. To select a command the user must move the cursor to the command that he wishes to execute and then release the button. Positioning the cursor on the command has the effect of inverting the display of this command line. If the user releases the button without selecting any command, the pop-up menu disappears and no command is executed.

Pop-up menus are instances of the class `PopUpMenu` which is a subclass of the class `Object`.

### 16.4 Standard windows

One of the important window classes is the class `StandardSystemView`. The instances of this class are windows that have a title indicating the functions of the view. These windows can be manipulated; they can be moved, altered in size, etc. These actions are carried out by means of a pop-up menu which appears on the screen when the blue button is pressed while within the window. The diagram below shows a menu example that appears when the blue button is pressed in a standard window:

<figure><img src="image_19.png" /></figure>
The actions possible are:

under

calls for a window below the cursor to be activated. If there are several inactive windows under the cursor, one of these will be activated. If there is no inactive window under the cursor, this command has no effect,

move

moves the active window without altering its size. The window follows the movement of the cursor until the red button is pressed,

frame

changes the dimensions of the active window. An origin cursor follows the movement of the mouse until the red button is pressed. The position thus obtained corresponds to the top left corner of the window. Subsequently, a corner cursor follows the movement of the mouse for as long as the red button remains pressed. The new position obtained corresponds to the bottom right corner bottom of the window.

collapse

removes all of the window except its title. To make this window reappear, the command frame must be used to change its dimensions,

close

causes the window to disappear completely from the screen.

## 16.5 The system menu

The system menu is the pop-up menu that appears when the yellow button is pressed outside any window. This is the menu that, for example, is used to create windows or to exit the Smalltalk system. The diagram below shows an example of a system menu.

<figure><img src="image_20.png" /></figure>

The commands offered by this menu are:

restore display

redisplays the complete screen, beginning with the background in a grey motif, then displaying all the windows,

exit project
allows you to exit from the current project. A project is a list of windows that relate to a particular application. When you return to a project, the screen is cleared and the windows of this project are displayed. When you have entered a project, the system menu is the same, `project`

opens a window that will allow entry to a project, `file list`

opens an access window to the external files, `browser`

opens a window that allows classes and methods to be edited, `workspace`

opens a window that allows text to be edited and expressions evaluated, `system transcript`

opens a window used by the Smalltalk system to display its messages, `system workspace`

opens a text window whose contents are initialised by the Smalltalk system with a number of expressions that are useful to know, `save`

allows the Smalltalk virtual image to be saved to a file, `quit`

allows you to quit the Smalltalk system.
# 17 Text Editing Windows

Numerous types of window use a text editor. Whatever the window type, the editor used is always the same.

To edit text, the user can use the keyboard and the mouse. The keyboard provides the means of entering new characters, while the mouse allows a section of text to be selected with the red button or commands to be executed using the yellow button.

If a section of text is too long to be displayed all at once in the window, there needs to be a means of displaying only part while retaining easy access to the remainder. This is what happens on a conventional word processor page, where at most 24 lines are displayed, but the rest of the text can be accessed by means of arrow keys. In the Smalltalk system, the windows have another means of accessing a particular section of text.

## 17.1 Scrollbars

A "scrollbar" is a rectangular area that appears on the left of an editing window of active text when the cursor is located inside the window.

Whenever the cursor moves outside of this window, the scrollbar disappears, only to reappear again when the cursor returns to the window.

This scrollbar represents the totality of the text. It contains a grey rectangle whose position in the scrollbar represents the position of the text shown on the screen relative to the text in its entirety. Its height, in relation to the height of the scrollbar, represents the proportion of text shown on the screen in relation to the text in its entirety.

To access a particular section of text, the rectangle within the scrollbar must be moved. When the mouse points to the interior of the scrollbar, there are three different cursors, depending on the relative position of the cursor and of the interior rectangle.

If the mouse points to the left of the rectangle, the down cursor appears. If the user presses the red button, the inside rectangle moves up and the text displayed in the text window moves down, as shown in the following diagram.
Workspace

<figure><img src="image_21.png" /></figure>

This
is
a window for editing
text

If the mouse points to the right of the interior
rectangle, the up cursor appears. If the user presses
the red button, the interior rectangle moves down and
the text displayed in the text window moves up, as shown
below.

Workspace

<figure><img src="image_22.png" /></figure>

This
is
a window for editing
text

If the mouse points along the same level as the
interior rectangle, the marker cursor appears. If the
user presses the red button, the interior rectangle
centres itself on the cursor and causes the text to
move, as shown below.
<figure><img src="image_23.png" /></figure>

## 17.2 How to select text

Selecting part of a text means choosing a continuous section of text with a view to manipulating it with an edit command.

In a text window there is a special cursor that indicates the position of the next text input. This cursor is shaped like an inverted "v", as can be seen on the previous three diagrams. This cursor can be moved around in the window by pressing and releasing the red button on the mouse until the correct position for the mouse cursor is found. There are several ways of selecting a text; these are described in the following paragraphs.

<figure><img src="image_24.png" /></figure>
The mouse cursor is placed at a position on the text, the red button is pressed without being released and the mouse cursor is moved to another position on the text, then the button is released. The text located between these two positions will be displayed in reverse video, as shown in the figure on page 124 (bottom).

The mouse cursor is placed on a word, the red button is pressed and released twice without moving the mouse. This will select a complete word, as shown below.

<figure><img src="image_25.png" /></figure>

<figure><img src="image_26.png" /></figure>
The cursor is placed at the beginning or at the end of the text, the red button is pressed and released twice without moving the mouse. This will select all of the text, as shown on page 125.

The cursor is placed after or in front of a carriage return, the red button is pressed and released twice without moving the mouse. This will select that section of text that extends backwards or forwards to the next carriage return, as shown below.

Workspace

<figure><img src="image_27.png" /></figure>

This

is

a window for editing

text

<figure><img src="image_28.png" /></figure>

Workspace

<figure><img src="image_29.png" /></figure>

init: aNode

firstNode ← aNode.

aNode addDependent: self.

self at: firstNode put: (Node new position:

0@0).

self calculatePositionAfter: 0@0
The cursor is placed after or in front of a delimiter, the red button is pressed and released twice without moving the mouse. This will select that portion of text located between delimiters, as shown in the example at the foot of page 126.

If the Escape key on the keyboard is pressed, all text entered since the last use of the mouse buttons will be selected.

If the text contains a selected section and the user enters characters via the keyboard, the entered characters will replace those in the selected section.

### 17.3 Edit commands

The edit commands can be accessed by a menu that appears when the yellow button is pressed. Each command is executed as soon as the button is released. This menu is illustrated below.

<figure><img src="image_30.png" /></figure>

The commands are:

cut

removes the selected section from the text,

copy

places a copy of the selected text in a buffer,

paste

replaces the selected text with the contents of the buffer,

again

re-executes the last command,

undo

cancels the effect of the last command.

### 17.4 Workspaces

A workspace is a text-editing window which makes it possible to evaluate expressions contained in a selected section of text. Smalltalk expressions can be evaluated
by two commands that can be accessed via the yellow button menu. They are:

doIt

which evaluates the selected text, and

printIt

which evaluates the selected text and displays the text that describes the object returned by the last evaluation. The returned text becomes the current selection.

When a text is evaluated, the text expressions are compiled. If there is a syntax error, an error message is displayed immediately in front of the position corresponding to the detected error. This message becomes the selected section of text, which allows it to be amended immediately or replaced with other text.

In the basic version of Smalltalk-80, when there is an unknown variable in an expression, a menu appears offering a choice of possible declarations for this variable. This menu also offers the possibility of correcting the variable name or of abandoning the evaluation.

More recent versions of Smalltalk-80 consider that variables can be local to a workspace. These variables will be defined when first assigned and will be stored in a dictionary local to the workspace.

During evaluation of expressions, the scrollbar disappears from the window. It reappears when the evaluation is finished.

## 17.5 System workspace

The System workspace is a workspace whose contents consists of expressions that it may be useful to know in order to change certain operating parameters in Smalltalk. The parameters that can be changed are, for example:

the size of the screen

the "sources" and "changes" files

The System workspace also contains expressions for reconstructing an image after an accidental break.
# 18 Browsers

The browsers are windows that allow access to the classes and methods. A browser has two possible uses; it allows the user to:

- consult or change the existing classes and methods. Since the Smalltalk environment is itself written in Smalltalk, the user has access to all of its code. From this point of view Smalltalk can be regarded as a self-documented language. The advantage of having access to the existing classes encourages the reuse of code. It is not advisable to change the existing classes or methods, as any such changes could have consequences well beyond any that could be foreseen.

- create new classes or new methods. In the Smalltalk environment, the building of an application amounts to enriching the environment with new classes and new methods.

## 18.1 Description

A browser is made up of five main windows. Four of these give access to the following lists:

- list of categories of classes,

- list of classes belonging to the selected category,

- list of categories of methods or protocols of the selected class,

- list of methods of the selected protocol.

The fifth window, located beneath the other four, is a Smalltalk code editing window, the contents of which will be interpreted according to the options selected from the lists.

There are two additional windows located under the list of classes; the one on the left contains the 'instance' text, that on the right the 'class' text. These two windows allow access to a class or to its metaclass, depending on whether the left or right window is selected (indicated by reverse video). If the left window is selected, the methods displayed are the instance methods; if the right window is selected, the class methods are displayed. These two windows cannot be selected simultaneously.

Each window has a particular menu linked to the central button on the mouse. The diagram below shows these different menus.
<figure><img src="image_31.png" /></figure>

## 18.2 The categories of class

The categories of class group together the classes by function. Once again, be reminded that the categories have no influence on the behaviour of the system. The list of these categories appears in the left window. The menu in this window, linked to the central button, contains eight functions, namely:

### file out

which, for all classes of the selected category, outputs the text of the class and its methods to a file. This file can then be reread by the message `fileIn`. The name of the file produced is the name of the category with the suffix `.st`,

### print out

which causes the same action as the function `file out`, except that in this case the file created cannot be read. Special formatting is inserted into the text so that when printed it can be more easily read by humans. In particular, the names of methods appear in bold characters. The name of the file produced is the name of the category with the suffix `.pp`. (Note that the exact nature of this option varies from machine type to type, so your machine may do something different.)

### spawn

which opens a browser dedicated to the selected category,

### rename

which allows the name of the selected category to be changed,

### remove
which removes the selected category, along with all the
classes that belong to it,

update

which updates the list of categories. This list may have
been changed in another browser or by reading a file,

edit all

which presents the list of categories and their classes
in the Smalltalk code editing window of the browser.
This list can then be changed using the menu available
in that window.

18.3 The classes

The list of classes of the selected category appears in
the second window. If no class category is selected,
this window is empty. The functions offered by the menu
in this window are:

file out

as before, this outputs the definition of the selected
class and the text of its methods to an external file.
The name of the file produced is the name of the class
concatenated with the suffix `.st`,

print out

as for the class categories, this outputs the definition
of the selected class and the text of its methods to an
external file. The name of the file produced is the name
of the class with the suffix `.pp`,

spawn

opens a browser dedicated to the selected class, as
shown in the diagram below for the class Point:

<figure><img src="image_32.png" /></figure>
## spawn hierarchy

opens a browser on the hierarchy of the selected class (that is, its subclasses and superclasses), as shown in the following diagram:

<figure><img src="image_33.png" /></figure>

## hierarchy

displays in the code window the hierarchy of the selected class; the depth of the classes in their hierarchy is represented by indentation of the text,

## definition

displays in the text window the definition of the selected class,

## comment

displays in the code window the commentary relating to

<figure><img src="image_34.png" /></figure>
the selected class. This can then be changed, protocols

displays in the code window the list of protocols and methods belonging to these protocols, as shown on page 132 (foot). The name of a protocol is a string of characters, whereas the name of a method is a symbol.

inst var refs

causes a pop-up menu to appear containing the list of named instance variables of the selected class and of its superclasses. It is then possible to select one of the variables from the offered menu, which has the effect of opening a browser on the list of methods that make reference to this variable. The following two diagrams show the selection of the instance variable labelText from the class StandardSystemView:

<figure><img src="image_35.png" /></figure>
### class var refs

causes a pop-up menu to appear containing the list of class variables of the selected class and its super-classes. It is then possible to select one of the class variables from the menu, which has the effect of opening a browser on the list of methods that make reference to this variable.

### class refs

opens a browser on the list of methods that make reference to the selected class, as shown in the diagram below:

<figure><img src="image_36.png" /></figure>

### rename

allows the name of the selected class to be changed. If any methods make reference to this class, a browser is opened on the list of these methods,

### remove

removes the selected class and its subclasses if they exist.

## 18.4 Protocols

The third window contains the list of protocols of the selected class. If no class is selected, this window is empty. The reader is reminded that the sole function of protocols in the system is to clarify the presentation of the methods in browsers. The functions offered by this menu are:

### file out

which outputs the text of all the methods belonging to the selected protocol. The name of the file produced is the name of the class concatenated with the name of the protocol, concatenated with the string `.st`,
print out

causes the same action as file out, but produces a
formatted text,

spawn

opens a browser on the list of methods of the selected protocol. The figure below shows an opened browser on the protocol comparing of the class Point:

<figure><img src="image_37.png" /></figure>

add protocol

allows a protocol to be added to the list of existing protocols. The name of this protocol is requested in an edit window,

rename

allows the name of the selected protocol to be changed,

remove

removes the selected protocol, together with the list of all its methods.

## 18.5 Methods

The list of methods belonging to the selected protocol is given in the right window. If no protocol is selected, this window is empty. The functions offered by the menu are:

file out

which allows the text of the selected method to be output. The name of the file produced is the name of the class, concatenated with the name of the method, concatenated with the string `.st`,

print out

causes the same action as file out, but produces a formatted text,

spawn

opens a browser on the selected method,

senders

opens a browser on the list of methods that send the message with the same name as the selected method,
implementors

opens a browser on the list of methods with the same name as the selected method,

messages

causes a menu to appear giving the list of all the messages sent in the selected method. Using this menu, it is possible to access all the implementations of one of the messages given in the menu,

move

allows the selected method to be moved. If it is moved to another class, it is copied; if its protocol is changed, it is simply moved,

remove

removes the selected method.

## 18.6 The code window

The Smalltalk code window, which appears in the browser, is like the text windows described in the previous chapter. In addition to its editing functions, this window offers three more functions in its menu:

format

this function relates exclusively to methods and will thus only be valid when a method is displayed. Its purpose is to present the code of the method in the clearest possible form. To achieve this, the name of the method is shown in bold and some conventions in its presentation are observed; the most important of these are:

- there is only one statement per line

- loops are shown with additional indentation.

The figure below shows the effect of the formatting on a method.

<figure><img src="image_38.png" /></figure>
spawn

which opens a new browser on the selected method,
explain

this function is very useful; it allows the nature of
the selected word to be explained. Only one word can be
selected at a time. The following example shows the
explanation provided by the system for the word 'x'.
This word can be explained in two ways: x is an instance
variable of the class Point, and x is a message defined
in the class Point.

<figure><img src="image_39.png" /></figure>

Depending upon the options chosen from the list at
the top, the code window has two main uses, described in
the following sections.

### 18.6.1 Editing a class

When a category is selected, without a class being
selected, a text giving the general form of a class is
displayed; this can be changed. To capture this newly
defined class, the accept function accessible via the
middle button must be used.

When a class is selected, without a protocol being
selected, the definition of this class appears in the
text window. It is then possible to change and accept
it, as before.

### 18.6.2 Editing a method

When a protocol is selected, without a method being
selected, the general form of a method is displayed in
the text window. The user may change this general form
in order to produce a new method. If the name of the
method that is displayed is the same as that of a method
already in existence in this class, the newly accepted
method will replace the old. To compile the method, the accept option (via the centre button) must be used.

When a method is selected, the text of this method is displayed in the text window. This text may then be changed. If the method name is changed, a new method will be created.
# 19 Other Windows

## 19.1 Inspectors

Just as a browser allows classes to be accessed and changed, so an inspector allows access to any object in the system. It provides access to all the instance variables of the object inspected and all the Smalltalk objects can be inspected. Inspectors are used chiefly during the development phase of an application.

To open an inspector on an object, the message `inspect has to be sent to it`. For example:

`#(1 2 3 4) inspect`

opens an inspector on the receiver of the message,

`Set someInstance inspect`

opens an inspector on an instance of the class `Set`.

### 19.1.1 Description

An inspector type window consists of two subwindows, as shown in the figure below.

<figure><img src="image_40.png" /></figure>
The left window contains a list made up of the symbol self, representing the object inspected, and the list of names of its instance variables. In the case where the inspected object has indexed instance variables, the latter are represented by their index.

In the left window, the menu linked to the middle button offers the choice of inspecting the object that is selected. If the selected object is self, a second inspector will be opened on the same object.

The right window is a text window which contains the textual description of the object that is selected from the list on the left. The reader is reminded that this textual description is obtained by sending the message printString to the selected object.

The menu in this window, linked to the middle button, offers the usual functions suggested in a text window, namely:

- three text-editing functions: cut, copy and paste

- two evaluation functions: do it and print it

- two functions for manipulating the window contents: accept and cancel. The contents are the text that appears when it is open.

In contrast to the text windows that we have met before (for example, workspaces), evaluations in an inspector are carried out in the context of the inspected object, that is, at the time of evaluation references can be made to an object contained in the list on the left. In particular, an expression can be built by sending a message to self or to one of its instance variables, which is not the case in a workspace.

The function accept assigns the result of the evaluation of the text present in the text window to the variable selected from the list on the left.

### 19.1.2 Other inspectors

We have seen how in order to inspect an object the message inspect has to be sent to it. The method for responding to this message is defined in the class Object; thus all objects can be inspected. In some classes, this message is redefined, which allows the opening of windows adapted to certain types of objects.

Dictionaries have special inspectors that allow keys to be manipulated. The following figure shows an inspector on a well known dictionary, namely the dictionary called Smalltalk, which contains all the global variables in the system, it will be recalled. In the left window the keys of the dictionary appear, while in the right window the value assigned to the selected key appears.

The left window offers the following options:

inspect

which opens an inspector on the selected variable,
references

which opens a browser on all the methods that refer to the selected variable,

add field

which allows a key to be added to the dictionary,

remove

which removes the selected key from the dictionary.

<figure><img src="image_41.png" /></figure>

Views (instances of the class View) also have special inspectors which allow access to the model and to the controller assigned to the view to form a MVC (model-view-controller) system. The MVC system is described in detail in chapter 21.

The figure below shows an inspector on an instance of

<figure><img src="image_42.png" /></figure>
BrowserView, which is the view assigned to a browser. This inspector is in fact made up of three inspectors on the three objects of the MVC system.

## 19.2 Debuggers

Development tools are very important tools in programming environments and in Smalltalk they have been very carefully designed.

Debuggers are windows that serve to visualise the methods and variables implicated in the evaluation of an expression during the actual evaluation. A debugger can be opened from a window called a Notifier, in which the menu, controlled by the middle button, offers two actions:

* proceed

which resumes the interrupted activity,

* debug

which opens a debugger on the interrupted context.

The Notifier contains the list of the last methods that were used before the interruption, as shown in the following figure.

### User Interrupt

```SmallInteger>>digitMultiply:neg:
SmallInteger(Number)>>to:do:
SmallInteger(Integer)>>digitMultiply:neg:
SmallInteger(Integer)>>proceed
SmallInteger>>* debug
```

### User Interrupt

<figure><img src="image_43.png" /></figure>
Several circumstances can cause the opening of a
 Notifier. These are usually:

- an object does not understand a message that it receives,

- the user causes interruption of an activity by pressing control C,

- an object receives a halt message.

A debugger type window is made up of several subwindows, as shown in the bottom figure on page 142. The six windows involved are described below.

### 19.2.1 List of methods

This list contains the name of the last methods that were active before the interruption. When the user selects one of the methods contained in the list, the text of this method appears in the code window located below, with the expression that was being evaluated when the interruption occurred highlighted. This subwindow contains a menu controlled by the middle button which offers the following options:

- full stack

which completes the list of methods by adding to it all the methods that were active within the process,

- proceed

- which resumes execution of the interrupted process,
- restart

- which restarts evaluation of the selected method from the beginning,
- senders

- which opens a browser on the list of methods that send a message with the same name as the selected method,
- implementors

- which opens a browser on the list of methods with the same name as the selected method,
- messages

- which cause a pop-up menu to appear giving the list of all messages sent from the selected method. From this menu it is possible to access all the implementations of a message present in the menu,
- step

- which causes the next expression to be evaluated. The selected part in the code window is updated,
- send

### 19.2.2 The code window

This window is located under the window that provides the list of methods that have been used. When a method is selected from the list of methods, its text appears in the code window, as in a browser. The expression that
was being evaluated at the time of the interruption is shown in inverse video. The functions offered in the menu, which is controlled by the centre button, are the same as those offered in the code window of a browser.

### 19.2.3 Inspector of the receiver

This inspector is an inspector which describes the receiver of the message selected from the list at the top. In this window it is possible to access all the instance variables of the receiver and change them.

### 19.2.4 Inspector of local variables

The inspector enables access to the arguments of the method selected from the list of methods, as well as access to all its local variables. It is possible to consult or change these variables.

## 19.3 Views of external files

These windows, called 'fileLists', allow access to the file system underlying the Smalltalk virtual machine. The windows allow access to both directories and files. They are used in particular for integrating new classes into the system; rather than transfer complete images, it is more economical to transfer definitions of classes and methods that have been obtained by means of a fileOut.

The fileList type windows are made up of three sub-windows, as shown in the following figure.

The top window is a text window in which the user enters the name of the file that is to be accessed. The character '*' can be used to replace any character string when designating the file; for example:

*.st

designates all the files suffixed by '.st', that is, all the files obtained by a fileOut in a browser.

Once the name of the file(s) has been entered, the user can obtain a list of all the filenames matching the name entered by using the accept function controlled by the middle button.

The central window contains the list of the files whose name is compatible with the filename specification of the top window.

If there are files whose name corresponds to the name in the top window, the menu controlled by the middle button offers the following options:

get contents

allows the text from the selected file to be loaded into the bottom window,

fileIn

this operation carries out the opposite function to the browser fileOut; it allows the text of the selected file
<figure><img src="image_44.png" /></figure>

to be compiled. The latter must contain the definitions of classes and methods; that is, it must have been obtained by a `fileOut`,

### copy name

which allows the name of the selected file to be copied into a text buffer (this is the equivalent of the copy function in a text window),

### rename

which allows the name of the selected file to be changed. The name of a new file must not be the name of a file that already exists,

### remove

which allows the selected file to be destroyed.

When the name of the top window does not correspond to any existing file, the central window contains a list, whose only element is the name entered in the top window, together with a menu whose options are:

### copy name

which allows, as before, the name of the selected file to be copied into the text buffer,

### rename

which allows the selected file to be renamed,

### new file

which allows a new file to be created whose name will be
the selected name

new directory

which allows a new directory to be created whose name
will be the selected name.

The bottom window is a text window; it contains the
text of the selected file in the central window if the
option 'get contents' has been used in this window. The
menu offered is the one generally offered in this type
of window, but it contains three additional options,
namely:

file it in

which allows the selected text to be compiled by
interpreting it as text defining classes and methods,
that is, this text must be in the format of the external
files,

put

which writes the text in the bottom window to the
selected external file,

get

which replaces the text in the bottom window with the
text from the selected file.

Form Editor

<figure><img src="image_45.png" /></figure>

<figure><img src="image_46.png" /></figure>

<figure><img src="image_47.png" /></figure>

<figure><img src="image_48.png" /></figure>

<figure><img src="image_49.png" /></figure>

<figure><img src="image_50.png" /></figure>

<figure><img src="image_51.png" /></figure>

<figure><img src="image_52.png" /></figure>

<figure><img src="image_53.png" /></figure>

<figure><img src="image_54.png" /></figure>

<figure><img src="image_55.png" /></figure>

<figure><img src="image_56.png" /></figure>

<figure><img src="image_57.png" /></figure>

<figure><img src="image_58.png" /></figure>

<figure><img src="image_59.png" /></figure>

<figure><img src="image_60.png" /></figure>

<figure><img src="image_61.png" /></figure>

<figure><img src="image_62.png" /></figure>

<figure><img src="image_63.png" /></figure>

<figure><img src="image_64.png" /></figure>

<figure><img src="image_65.png" /></figure>
## 19.4 Graphics editors

The Smalltalk system has two graphics editors that allow a form to be drawn. Such forms are instances of the class Form (see chapter 15) or of one of its subclasses.

All the entities displayed on the screen are forms (drawing, cursor, character font) and can therefore be edited graphically.

### 19.4.1 The Form Editor

This editor consists of two windows, one containing the form to be edited and the other a graphics menu from which the user selects the functions required to draw on the form. To edit a form with this graphics editor necessitates sending it the message edit. The figure on page 146 illustrates the graphics editor.

To select an option from the graphics menu the user places the cursor on the option and presses the red button on the mouse. The options in this menu are as follows:

<figure><img src="image_66.png" /></figure>

allows selection of the pattern that will serve as the paintbrush. This pattern is obtained by designating a rectangle on the screen.

<figure><img src="image_67.png" /></figure>

indicates that the paintbrush is to be copied at the position indicated by the mouse as soon as the red button is pressed.

<figure><img src="image_68.png" /></figure>

indicates that the paintbrush is to be copied at the position indicated by the mouse as long as the red button is pressed.

<figure><img src="image_69.png" /></figure>

indicates that the paintbrush is to be copied along the line defined by two presses on the red button.

<figure><img src="image_70.png" /></figure>

allows a curve to be drawn with the paintbrush.

<figure><img src="image_71.png" /></figure>

allows a rectangle to be filled with the selected pattern.

<figure><img src="image_72.png" /></figure>

indicates that paintbrush overwrites the background when it is applied.

<figure><img src="image_73.png" /></figure>

indicates that the paintbrush is ORed on to the background.

<figure><img src="image_74.png" /></figure>

indicates that paintbrush is XORed on to the background.
<figure><img src="image_75.png" /></figure>

indicates that paintbrush is ANDed on to the background.

<figure><img src="image_76.png" /></figure>

allows part of the drawing to be edited with the bit editor (see next section).

<figure><img src="image_77.png" /></figure>

initialises the fill colour with a white pattern.

<figure><img src="image_78.png" /></figure>

initialises the fill colour with a light grey pattern.

<figure><img src="image_79.png" /></figure>

initialises the fill colour with a grey pattern.

<figure><img src="image_80.png" /></figure>

initialises the fill colour with a dark grey pattern.

<figure><img src="image_81.png" /></figure>

initialises the fill colour with a black pattern.

<figure><img src="image_82.png" /></figure>

allows the horizontal grid to be used.

<figure><img src="image_83.png" /></figure>

allows the vertical grid to be used.

<figure><img src="image_84.png" /></figure>

allows the minimum number of points between two lines and two columns of the grid to be set.

<figure><img src="image_85.png" /></figure>

allows the edited form to be output to an external file.

<figure><img src="image_86.png" /></figure>

allows a form to be read in from an external file.

The menu linked to the yellow button has two options, namely:

accept

which allows the existing drawing form to be replaced by the one currently shown on the screen,

cancel

which replaces the drawing on the screen with the original edited drawing.

### 19.4.2 The Bit Editor

There is a second graphics editor called by the message bitEdit which allows access to each pixel of the drawing. In this case, the drawing is enlarged and each pixel is represented by a square of 8 x 8 points. The figure below shows an example of the use of this editor.
<figure><img src="image_87.png" /></figure>

This view is made up of two subviews, one giving access to the enlarged drawing and the other which lets you choose to draw in either black or white. The menu, controlled by the yellow button, is the same as that offered by the editor edit. This editor is generally used for small size forms; for example, it can be used to create a new cursor:

Cursor new bitEdit
# 20 Management of User Events

In order to interact with the Smalltalk system, the user can use two different devices - the keyboard and the mouse. Any alteration to the state of the keyboard or the mouse is called a user event. The user events that are possible are:

- a movement of the mouse,

- the pressing of one of the mouse buttons,

- the striking of a key on the keyboard.

Within the Smalltalk system there are several classes that define methods for detecting and managing user events. Because only one user may interact with a Smalltalk system at once, these classes have only one instance.

## 20.1 The class InputState

The class *InputState*, which is a subclass of the class *Object*, interfaces Smalltalk with the hardware that detects user events. There is in the system one instance of this class which at any time represents the status of the keyboard and the mouse. This class has a class variable called *InputProcess*, which references the process reading the status of the keyboard and the mouse; this process is an instance of *Process* (cf chapter 13).

## 20.2 The class InputSensor

The class *InputSensor*, which is a subclass of the class *Object*, interfaces between the user and the instance of *InputState* that represents the status of the keyboard and the mouse. It has a class variable called *CurrentInputState*, which references the instance of the class *InputState*. This class supports the methods that allow the keyboard and the mouse to be tested.

Because there is only one keyboard and one mouse, this class only has one instance that is referenced by the global variable called *Sensor*. To test the status of the keyboard or the mouse, messages have to be sent to the global variable *Sensor*. The messages understood by *Sensor* are:

anyButtonPressed

returns true if one of the buttons on the mouse is pressed,
noButtonPressed
returns true if none of the buttons on the mouse is pressed,
redButtonPressed
returns true if the red button on the mouse is pressed,
yellowButtonPressed
returns true if the yellow button on the mouse is pressed,
blueButtonPressed
returns true if the blue button on the mouse is pressed,
waitButton
waits for one of the buttons on the mouse to be pressed and returns the cursor position,
waitNoButton
waits until none of the buttons on the mouse is pressed and returns the cursor position,
keyboardPressed
returns true if one of the keys on the keyboard has been pressed,
keyboard
waits until a character is struck on the keyboard and returns this character,
keyboardPeek
reads a character from the keyboard queue without removing it from the queue,
keyboardNext
reads a character from the keyboard queue and withdraws it from this queue,
cursorPoint
returns the current cursor position,
cursorPoint: aPoint
places the cursor at the position given as argument,
currentCursor
returns the current cursor,
currentCursor: aCursor
replaces the current cursor by the argument aCursor.
For example:
Sensor waitButton.
Display reverse.
Sensor waitNoButton.
Display reverse
reverses the screen as soon as one of the mouse buttons is pressed and keeps it in this state until the button is released.
## 21 Model-View-Controller System

In the preceding chapters we have met several different window types in the Smalltalk system, each designed to solve a particular problem. The programmer can also build special windows for his own individual applications. We recall that a window specifies a part of the screen in which interaction takes place between the user and the application.

In this chapter we shall see how interactive applications in the Smalltalk system are constructed and how to build new ones.

Within Smalltalk all interactive applications are built to the same plan, called the MVC system. The approach is based on the following three entities:

- the object on which the work is to be done,

- an output interface that serves to present this object to the user,

- an input interface that allows interaction with the object or with its representation.

In the Smalltalk system, the object on which the work is to be done is called the **model**, the output interface is called the **view**, and the input interface is called the **controller**.

Whenever the model is changed, its representation must be updated. For this updating to be automatic, a dependency must be established between the view and the model that it represents. The concepts of dependence were examined in chapter 7 on the class Object.

In addition to the dependency of the view on the model, the view and the controller must be aware of one another and aware of the model on which they are to work.

The basic classes that allow views and controllers to be defined are the classes **View** and **Controller**. These two classes are subclasses of the class **Object**. The relationships between a model, its view and its controller are shown in the following figure.

### 21.1 The class View

The instances of the class View are windows. Two of the instance variables of this class are model and con-
<figure><img src="image_88.png" /></figure>

troller, which refer respectively to the model and the controller assigned to the view.

When several objects are to be represented in the same view, the view can be divided into several subviews. Thus, a hierarchy of views is defined, since a subview is a completely separate view. To implement this hierarchy each view has a list of subviews and one superview. The following figure shows the relationships between models, views and controllers in the case where a view is made up of several subviews.

<figure><img src="image_89.png" /></figure>

### 21.1.1 The class WindowingTransformation

The coordinates of a view may be defined in several coordinate systems:

- in its own coordinate system,

- in the coordinate system of its superview,

- in the coordinate system of the screen.

In order to move from one coordinate system to another, simple geometric transformations are used.

The class WindowingTransformation is a subclass of the class Object whose instances serve to represent the
geometric transformations consisting of a translation and a scaling factor. The two instance variables of this class are `scale` and `translation`. These geometric transformations will be used to change coordinate system in a view.

The messages that allow new geometric transformations to be created are:

`identity`

which returns a transformation without translation and with an enlarging factor of 1,

`scale: anEnlargingFactor translation: aTranslation`

which returns an initialised geometric translation with the arguments of the method,

`window: aWindow viewport: aViewporter`

which returns a transformation to move from the rectangle `aWindow` to the rectangle `aViewporter`. This method is the one that constructs the transformation for passing the coordinates of a view to the coordinates of its superview.

The messages that can be sent to the instances of `WindowingTransformation` are:

`applyTo: aPoint`

which returns the point obtained by applying the geometric transformation to the point `aPoint`,

`applyInverseTo: aPoint`

which returns the point obtained by applying the inverse geometric transformation to the point `aPoint`,

`compose: aGeometricTransformation`

which returns a new instance of `WindowingTransformation` obtained by composing the receiver and the argument `aGeometricTransformation`.

### 21.1.2 Instance variables of the class View

The instance variables of the class `View` are:

`model`

which is the object represented by the view,

`controller`

which is the controller that allows interaction with the view or with the model,

`superView`

which is the superview of the view,

`subViews`

which is an instance of `OrderedCollection` containing the subviews of the view,

`transformation`

which is an instance of `WindowTransformation` allowing transfer from the coordinate system belonging to the view (given by `window`) to the coordinate system belonging to the superview,

`viewporter`

which is a rectangle giving the coordinates of the view
expressed in the coordinate system of the superview,
window

which is a rectangle giving the coordinate system of the
view,
`displayTransformation`

which is an instance of `WindowTransformation` allowing
transfer from the coordinate system belonging to the
view (given by window) to the coordinate system of the
screen,
`borderWidth`

which may be a number, a point or a rectangle, giving
the width of the border that encloses the view,
`borderColour`

which is a motif giving the colour of the border,
`insetDisplayBox`

which is a rectangle expressed in the screen coordinates
representing the interior rectangle of the view (the
view without its border),
`insideColour`

which is a motif giving the background colour of the
interior of the view,
`boundingBox`

which is the minimum rectangle expressed in the view co-
ordinates containing the view and its subviews.

The following figure recapitulates the different co-
ordinate systems in which the position of a point can be
expressed and the transformations that allow transfer
from one system to another.

<figure><img src="image_90.png" /></figure>

The coordinates belonging to a view are indicated
inside the view and the coordinates of that view within
its superview are shown outside.
### 21.1.3 Messages understood by instances of View

The class `View`, which is the basis of the entire windowing system, supports a large number of messages. These messages are divided into several categories which are examined in the following sections.

#### Manipulation of views and subviews

`add SubView: aView`

adds the argument `aView` to the list of subviews of the receiver,

`add SubView: aView align: aPoint with: anOtherPoint`

adds the argument `aView` to the list of subviews of the receiver, by fixing the viewport such that the point `aPoint`, expressed in the coordinate system of `aView`, is located at the point `anOtherPoint`, expressed in the receiver's coordinate system,

`add SubView: aView below: aPoint`

adds the argument `aView` to the list of subviews of the receiver, by fixing the viewport such that the origin of the view `aView` is located at the point `aPoint`, expressed in the receiver coordinate system,

`first SubView`

returns the first subview of the receiver,

`last SubView`

returns the last subview of the receiver,

`removeFrom Super View`

removes the receiver from the list of subviews of its superview, if it exists,

`remove SubView: aView`

removes the argument `aView` from the list of subviews of the receiver,

`reset SubViews`

removes all the subviews from the list of subviews of the receiver,

`super View`

returns the superview of the receiver,

`super View: aView`

replaces the superview of the receiver by the view given as argument,

`top View`

returns the main view of the hierarchy of views containing the receiver,

`is Top View`

returns true if the receiver has no superview,

`release`

before removing a view, one must also remove the dependence of this view in relation to the model, together with all the dependencies of its subviews; this is the function of the message release.
### Access to coordinate systems

`displayBox`

returns the rectangle containing the receiver,

`insetDisplayBox`

returns the rectangle interior to the receiver,

`window`

returns the coordinate system of the receiver,

`window: aRectangle`

replaces the coordinate system of the receiver by that
given as argument,

`window: aRectangle viewport: anOtherRectangle`

replaces the coordinate system of the receiver and the
coordinates of the receiver within its superview by the
coordinates given as argument,

`viewport`

returns the coordinates of the receiver expressed in the
coordinate system of its superview,

`boundingBox`

returns the minimum rectangle containing the receiver
and its subviews,

`containsPoint: aPoint`

returns true if the point given as argument is within
the receiver.

### Access to the controller

`controller`

returns the controller assigned to the receiver,

`controller: aController`

replaces the controller of the receiver by the controller given as argument,

`defaultController`

returns a new controller which is a default instance of
the class.

`defaultControllerClass`

returns the class of the controller.

### Access to the model

`model`

returns the object represented by the receiver,

`model: anObject`

replaces the object represented by the receiver by the
object given as argument,

`model: anObject controller: aController`

replaces the object represented by the receiver and the
assigned controller by the objects given as argument.

### Display

`borderColour: aMotif`

replaces the motif that provides the border colour of
the receiver by the motif given as argument,

`borderWidth: aWidth`
replaces the width of the receiver border by the width
given as argument,

clear: aMotif

fills the area of screen occupied by the receiver with
the motif given as argument,

clearInside

fills the interior of the receiver with the motif given
by the instance variable insideColour,

clearInside: aMotif

fills the interior of the receiver with the motif given
as argument,

display

displays the receiver border, the receiver itself, and
its subviews,

displayBorder

displays the receiver border,

flash

makes that part of the screen occupied by the receiver
flash,

highlight

inverts that part of the screen occupied by the receiv-
er,

insideColour

returns the motif that defines the background colour of
the receiver,

insideColour: aMotif

replaces the background colour of the receiver by the
motif given as argument.

The class View has several subclasses which allow
different types of object to be represented (text,
forms, list, etc). Interaction varies, according to the
object represented; it is therefore necessary to assign
a specific controller to each view. All its controllers
are defined in subclasses of the class Controller.

## 21.2 The class Controller

The class Controller is a subclass of the class Object.
Defined in this class are the basic operations for
controlling interactions and locating the active con-
troller.

### 21.2.1 Instance variables of Controller

This class has three instance variables:

model

which is the object to be interacted with,

view

which is the view representing the model,

sensor

which is a reference to the global variable Sensor, the
only instance of the class InputSensor; use of such a
reference saves time in locating this object.
### 21.2.2 Messages understood by instances of Controller

The messages supported by the class Controller are:

`controlActivity`

finds the subview of the view assigned to the receiver which requires control and activates the controller assigned to this subview,

`controlInitialize`

this message is sent to the receiver when the latter has just been activated, thus allowing certain parameters to be set,

`controlTerminate`

this message is sent to the receiver just before the latter is deactivated, thus allowing certain parameters to be restored,

`controlLoop`

loops for as long as the view assigned to the receiver contains the cursor, in order to discover which of the subviews wishes to take control (perhaps none),

`startUp`

this message is sent to a controller to activate it; the method sends to the controller the messages `controlInitialize`, `controlLoop` and `controlTerminate`.

`isControlActive`

returns true if the view is to retain control,

`model`

returns the object with which the receiver is interacting,

`model: anObject`

replaces the object with which the receiver interacts by the object given as argument,

`view`

returns the view assigned to the receiver,

`view: aView`

replaces the view assigned to the receiver with the view given as argument,

`release`

removes the references of the receiver to the view and the model.

To activate a controller, the message `startUp` must be sent to it. The `startUp` method is written as follows:

`startUp`

`self controlInitialize.`

`self controlLoop.`

`self controlTerminate.`

The methods `controlInitialize` and `controlTerminate` are redefined in the subclasses of Controller. For example, for the class `ScrollController`, which controls scrolling in a text window, these methods cause the `scrollBar` to appear on the left of the view when the controller is first activated and disappear at the end.
The controlLoop method is written as follows:

### controlLoop

[self isControlActive] whileTrue:
    [Processor yield.
    self controlActivity]

When the cursor moves from one view to another, it is necessary to be able to change the active controller in order to interact with the view on which the cursor is located. There is within the Smalltalk system a class called **ControlManager** whose task is to control the activation of the different controllers.

## 21.3 The class ControlManager

The class ControlManager is a subclass of the class Object. The instance of the class ControlManager which controls the controllers at any given moment is referenced by the global variable called ScheduledControllers.

Its instance variables are:

scheduledControllers

which references the list of controllers that may be activated; this list further contains an instance of **ScreenController** which controls the screen apart from any window,

activeController

which references the active controller,

activeControllerProcess

which references the process connected to the active controller; a new process is executed every time that the active controller changes,

screenController

which references an instance of the class ScreenController that controls those parts of the screen not occupied by a window.

When there is no longer an active controller, the instance of ControlManager referenced by ScheduledControllers decides to which window it should hand over control.

If there is no window that wishes to take control, it hands control to the screen as soon as the user presses the yellow button on the mouse.

Each project contains a collection of windows and is directed by an instance of the class ControlManager that belongs to it. When a project is changed, the ControlManager of this project is still referenced by the global variable ScheduledControllers.

When the controller of a window is activated, it will decide itself whether it is to retain control or hand it to one of the subviews of the window.

## 21.4 The class MouseMenuController

The class MouseMenuController is a subclass of the class
Controller. The instances of this class handle mouse
events. The instance variables of this class are:

redButtonMenu

which is a PopUpMenu that appears whenever the user
presses the red button,

redButtonMessages

which is an array of symbols corresponding to the
messages that will be sent to the controller if one of
the menu options assigned to the red button is selected,

yellowButtonMenu

which is a PopUpMenu that appears whenever the user
presses the yellow button,

yellowButtonMessages

which is an array of symbols corresponding to the
messages that will be sent to the controller if one of
the yellow button menu options is selected,

blueButtonMenu

which is a PopUpMenu that appears whenever the user
presses the blue button,

blueButtonMessages

which is an array of symbols corresponding to the messages
that will be sent to the controller if one of the blue
button menu options is selected.

If no menu is to be assigned to a mouse button, the
instance variable containing the menu corresponding to
this button will be set to nil.

The messages understood by the instances of the class
MenuMenuController are:

redButtonMenu: aMenu

redButtonMessages: an Array Of Messages

allows initialisation of the red button menu and list of
messages,

yellowButtonMenu: aMenu

yellowButtonMessages: an Array Of Messages

allows initialisation of the yellow button menu and list
of messages,

blueButtonMenu: aMenu

blueButtonMessages: an Array Of Messages

allows initialisation of the blue button menu and list
of messages,

redButtonActivity

this message is sent to the receiver when the red button
is pressed,

yellowButtonActivity

this message is sent to the receiver when the yellow
button is pressed,

blueButtonActivity

this message is sent to the receiver when the blue
button is pressed,

For the preceding three messages, if there is a menu
assigned to the button, then the menu is displayed for
as long as the button is held down. When it is released, if one of the options was selected, the corresponding message is sent to the receiver.

Almost all the controllers are instances of MenuController or of its subclasses, because almost all of them use the mouse.

The two important subclasses of this class are:

ScrollController

whose instances allow control of the scrollbar that appears to the left of windows that require scrolling,

StandardSystemController

whose instances allow screen windows to be manipulated (movement, changing size, closing, etc.).

## 21.5 The classes StandardSystemView and StandardSystem-Controller

These two classes implement the basic mechanisms that allow windows to be defined and controlled in the most general sense.

A window in the Smalltalk system is made up of a rectangle defining a part of the screen, surmounted by another rectangle containing the name of the window.

We have already seen how a window may contain subwindows which may themselves contain other windows. The window located at the top of the hierarchy, again called topView, is generally an instance of the class StandardSystemView. Only these windows may be deactivated or reactivated by the ControlManager.

The class StandardSystemView is a subclass of the class View. The additional messages supported by this class are:

label

returns the name of the receiver,

label: aString

replaces the name of the receiver by the string given as argument,

labelDisplayBox

returns the rectangle containing the name,

reverseLabel

inverts the name of the receiver,

expand

changes the size of the receiver interactively,

minimumSize

returns the minimum size of the receiver that is used when beginning to interact with it,

minimumSize: aSize

fixes the minimum size of the receiver,

maximumSize

returns the maximum size of the receiver that is used when beginning to interact with it,

maximumSize: aSize
fixes the maximum size of the receiver.

The class `StandardSystemController` is a subclass of the class `MenuController` whose instances generally control the windows that are instances of the class `StandardSystemView`. It has two class variables, namely:

`ScheduledBlueButtonMenu`

which is the `PopUpMenu` that is assigned by default to the blue button for all instances of this class,

`ScheduledBlueButtonMessages`

which is an array of messages sent to the receiver according to the command selected from the menu assigned to the blue button.

It has an instance variable called `status` which provides the status of the controller. The different possible states of a window are:

`open`

which is the status of the controller when interaction with the designated window is begun,

`closed`

which is the status of the controller when the designated window is closed (it is no longer visible on the screen),

`active`

which is the status of the controller when the designated window is active (that is, when the user can interact with this window),

`inactive`

which is the status of the controller when the designated window is no longer active.

To open a window, the message `open` must be sent to its controller.

### 21.6 Text-scrolling windows

When a section of text is too long to appear in a window in its entirety, it is only possible to display part of it, while allowing access to the remainder using a `scrollbar`.

The control mechanisms for the `scrollbar` are implemented in the class `ScrollController` which is a subclass of the class `MenuController`.

When a window has a `scrollbar`, the latter is only visible when the cursor is located within the window. Before making the `scrollbar` appear, the `ScrollController` saves the area of the screen that will be covered by the `scrollbar` in an instance variable called `savedArea`. When the `ScrollController` makes the `scrollbar` disappear, it redisplays the form contained in `savedArea`.

In the `Smalltalk` system the `scrollbars` are used in two types of window:

- text-editing windows
- windows for selecting an element from a list (see figure below).

<figure><img src="image_91.png" /></figure>

The two subclasses of the class ScrollController that allow management of these two types of view are the classes ParagraphEditor and ListController.

### 21.6.1 Text-editing windows

We have seen that, in order to represent sections of text on the screen, we may use instances of the class DisplayText. To present a text in a window, it also has to be formatted; that is, there has to be automatic control for moving to a new line when a line is filled or a word will not fit on the current line. The objects that allow formatted text to be produced are instances of the class Paragraph.

#### 21.6.1.1 Paragraphs

The class Paragraph is a subclass of DisplayText, whose instances responds to certain additional messages.

A paragraph may be created from a section of text or from a string of characters by sending them the message asParagraph, for example:

```
'this is a string of characters' asParagraph
returns a paragraph that represents the receiver.
```

As the text of a paragraph is formatted, there are several ways of putting this text in shape, and the messages that allow choice of page layout are:

```
centred
```

which allows the text to be centred on a line,

```
justified
```

which allows the text to be aligned on the left and right margins,

```
leftFlush
```

which allows the text to be aligned on the left margin;

this is the default option,

```
rightFlush
```

which allows the text to be aligned on the right margin.

When the size of a text window changes (for example, with the option frame via the blue button), the text formatting of the text in this window must also be changed. There is a message that allows a section of text to be reformatted, namely:

```
recomposeIn: aRectangle clippingBox: anOtherRectangle
which recalculates the page layout for the paragraph, so
```
that the lines will fit into the limits of the argument aRectangle and the display is restricted to the argument anOtherRectangle.

The controllers that allow a paragraph to be edited are instances of the class ParagraphEditor, which is a subclass of ScrollController. These controllers respond to a significant number of messages which the user has no need to access; these are therefore not described in this chapter.

In a text-editing window, the trio model-view-controller is made up of:

- a section of text or a string of characters for the model,

- an instance of View or of one of its subclasses, which displays the paragraph created from the model, for the view,

- an instance of ParagraphEditor or of one of its subclasses for the controller.

### 21.6.1.2 StringHolder StringHolderView

#### StringHolderController

These three classes make up a trio of model-view-controller that allow the text of the model to be edited in a text-editing window.

The class StringHolder is a subclass of the class Object, whose instance variables are:

contents

which is the string of characters that is edited,

isLocked

which is a boolean that indicates whether the text of the view is the same as that of contents.

The class StringHolderView is a subclass of View. One of its instance variables, called displayContents, references the paragraph that represents the formatted text of the model. The instances of StringHolderView are not main views (main views are generally instances of StandardSystemView), but simply subviews.

The class StringHolderController is a subclass of the class ParagraphEditor which allows the paragraph assigned to the model to be edited.

### 21.6.2 Lists

Lists are views which contain one or more lines of text and from which it is possible to select a line. For example, lists may be found in the four windows at the top of a browser; these allow access to the categories, classes, protocols and methods.

The MVC trio assigned to the control of a list consists of:

- an object that may in certain cases be considered as
a list,

- a view that is an instance of a subclass of **ListView**,

- a controller that is an instance of a subclass of **ListController**.

The subclasses of **ListView** and **ListController** that allow any lists to be manipulated are **SelectionInListView** and **SelectionInListController**.

The object which represents the model may be any object that responds to the messages that cause the system to:

- return the selected element

- change the selected element

- return the list of all elements

- return a menu assigned to the centre button which allows action on the elements in the list.

The name of the messages that will cause the above functions to occur will be given to the view at the time that it is created. Views of this type are rather special, because their model may belong to any class; they are said to be 'pluggable' views.

To create a view of this type, a message consisting of the following various selectors must be sent to the class **SelectionInListView**:

on: anObject
printItems: aBoolean
oneItem: anOtherBoolean
aspect: aspectMessage
change: changeMessage
list: listMessage
menu: menuMessage
initialSelection: selectionMessage

which returns an instance of **SelectionInListView** whose model is the argument anObject.

The argument aBoolean determines if the text of the view must be obtained by sending the message printString to all the elements in the list or if these elements are already strings of characters.

The argument anOtherBoolean determines if the list contains one and only one element.

The argument aspectMessage is the message that will be sent to the model to access the element selected from the list.

The argument changeMessage is a message to an argument that will be sent to the model to change the selected element.

The argument listMessage is the message that will be sent to the model to access the list of elements.

The argument menuMessage is the message that will be sent to the model to have a menu assigned to the centre button.

The argument selectionMessage is the message that
will be sent to the model to access the element selected at the start.

## 21.6 Example

The following review example shows how to construct an application that will allow a list of curves to be manipulated in one window, while the selected curve is represented in a second window, as shown below.

<figure><img src="image_92.png" /></figure>

The equation of a curve may be represented by a block with one argument. The orientation of the axes in the view is that normally adopted in mathematics. The scale goes from 0 to 100 along the abscissa and the ordinate. To implement this application, only two classes are required, as shown below.

<figure><img src="image_93.png" /></figure>
The class CurveList is a subclass of Ordered-Collection whose elements will be the strings of characters that provide the equations of the curves.

<figure><img src="image_94.png" /></figure>

The class CurveListView is a subclass of View which simply serves to redefine the method displayView that allows a curve to be displayed.

To open a curves window it is simply a question of evaluating the following expression.

<figure><img src="image_95.png" /></figure>

The first method to be written is the method for creating a window. The text of this method appears in the window below.
<figure><img src="image_96.png" /></figure>

The window is made up of three views:

- a main view which is an instance of `StandardSystemView`; the coordinates of this view (given by `window:`) range from `0@0` to `1@1`,

- a subview (an instance of `SelectionInListView`) which allows the list of curves to be represented and manipulated; the coordinates of this view in its superview are `0@0` and `1@0.3`,

- a subview (an instance of `CurveListView`) which is the view in which the selected curve is drawn; the coordinates of this view in its superview are `0@0.3` and `1@1`. The coordinates belonging to this view range from `0@100` to `100@0`, which represent a conventional (mathematical) coordinate system (the axis of the abscissas from left to right, and the axis of the ordinates from bottom to top).

To create the instance of `SelectionInListView`, it was necessary to give the messages that will be sent to the model in order to access the list of curves; now, the methods that correspond to these methods must be defined. These methods will be defined within the model, namely `ListCurve`.

The method `curveList` allows access to the list of elements of `CurveList`; here, this list directly consists
of the receiver, as shown in the figure below.

<figure><img src="image_97.png" /></figure>

The method `curveMenu` returns a menu (instance of the class `SHAREMENU`) which is a subclass of `PopUpMenu` including an additional instance variable which references the list of messages assigned to the menu options. If no line is selected, the menu returned only includes the option to add a curve to the list. If a curve is selected from the list, the menu returned includes three options, allowing a curve to be added, removed, or the selected curve to be altered.

<figure><img src="image_98.png" /></figure>
The method `selectedCurve` returns the variable called `selectedCurve` (see below).

<figure><img src="image_99.png" /></figure>

The method which allows a different curve to be selected is described below. Note that sending the message changed to the receiver has the effect of updating the view; in fact, it should be recalled that there is a dependence between the model and its view, and therefore any alteration of the model is signalled to the view.

<figure><img src="image_100.png" /></figure>

There are two protocols in the class `CurveList`: the first, which contains the access methods, has already been described; the second contains the methods for manipulating the list.

To add a curve, its curve must be input in the form of a block; this block must have an argument which, during evaluation, will take the different values of the `abscissa`.

The class `FillInTheBlank` allows text in a window to
be captured; the window closes automatically when the capture is completed by using the accept option on the middle button or <return>. The expression

self changed: #selectedCurve redisplays the list.

<figure><img src="image_101.png" /></figure>

The following method allows a curve to be removed from the list.

<figure><img src="image_102.png" /></figure>

To alter a curve, a window needs to be opened on the text of the selected curve; then, once the text has been altered, the selected curve is replaced by the new text.

All the methods of CurveList are written; all that remains is to write the instance methods of CurveListView. The first of these methods is very simple, since it involves redefining the message update:. Remember that this message is sent to all the dependents of an object when the latter receives the message changed:. Here, any alteration of the model
<figure><img src="image_103.png" /></figure>

(that is, the list of curves), must be result in a
redisplay of the view.

<figure><img src="image_104.png" /></figure>

The method that displays the interior of a view is called `displayView`. Here, this method must be redefined in order to display the curve within the view.

The method begins by erasing the interior of the view, since if there is a selected curve it draws it. The first task to be done is to transform the string of characters that represents the curve into a block; to do this, the text of the curve must be evaluated.

The pen can then be placed on the first point and be made to draw straight lines between all the following points. The transformation called `displayTransformation` must be applied to all the points in order to transfer the coordinates of the view to the coordinates of the screen.
This example illustrates how it is possible to construct graphics applications quickly, using but a few classes and methods. It will be noted that some methods

<figure><img src="image_105.png" /></figure>

serve to redefine existing methods, which is a feature often found in Smalltalk, because an application is often defined by the differences it has in comparison with an existing application (differential programming).

This example is also typical of what might be an application prototype.

The constraints imposed on such prototypes are as follows:

- shorter realisation time

- ease of development

- minimum operation; that is, there is no need to wait for the complete realisation of the prototype before running those parts already defined.

The MVC system is fundamental to Smalltalk, because it provides a methodology for breaking down graphics and interactive applications. Given that there are more than 30 subclasses of the class View, as well as more than 30 subclasses of the class Controller, it has only been possible to discuss the main classes in this chapter.
# Index

@, 96
[, 15
^, 22

## A

accept, 30
activeProcess, 92
add:, 68
addFirst, 77
addLast, 77
add SubView:, 156
again, 28, 127
allInstances, 44
and, 111
applyTo:, 154
Arc, 88
arithmetic, 59
Array, 81
ArrayedCollection, 81-82
arrays, 14
asciiValue, 57
asDisplayText, 107
Association, 71
at:, 34, 72
at:put:, 34

## B

Bag, 71
Behavior, 41
binary message, 16
BitBlt, 114-115
Bit editor, 148-149
bit manipulation, 65
bitmap, 26
Bitmap, 105
black, 108
BlockContext, 91-92
blocks, 18-20
blueButtonActivity, 161
border:, 108
borderWidth:, 157
boundingBox, 155
browsers, 28, 129
ByteArray, 83

## C

calendar, 54
cascades, 18
category, 48, 130
changed, 37
Character, 31, 57
characters, 14
character strings, 14
Circle, 114
class, 10-12, 31
Class, 12, 40, 47
ClassDescription, 12, 47
class methods, 11
classes, 7, 10-11, 131
clearInside, 158
close, 89, 120
code window, 136, 143
coerce, 63
Collection, 67-70
comment, 48
compilation, 49
contains, 103
containsPoint:, 103
contents, 84
Control-C, 143
controlActivity, 159
controlInitialise, 159
controller, 152, 157
Controller, 152, 158
controlLoop, 159, 160
ControlManager, 160
control Terminate, 159
conversions, 56, 62
copy, 28, 32, 33, 127
corner:, 100
cornerBy:, 102
CurrentInputState, 150
Cursor, 112-113
cursorPoint, 151
cut, 28, 127
D

Date, 54
deepCopy, 33
dibugger, 30, 142
defaultControllerClass,
157
Delay, 93
dependencies, 36-37
destForm, 114
detect:, 69
Dictionary, 71-74
display, 6
displayAt:, 21, 106
displayOn.at:clippingBox:
  rule:mask:, 112
Display, 113
DisplayMedium, 107-110
DisplayObjecte, 105-106
DisplayScreen, 112
DisplayText, 196-107
displayTransformation, 155
dist., 97
do:, 69
doesNotUnderstand:, 22
doIt, 28, 128

E

edit commands, 127
enumeration, 64
equality, 33
equivalence, 33
erase, 111
error, 35
expandBy:, 102
explain, 137
extent:, 21, 100
ExternalStream, 88-89

F

false, 19
file "changes", 128
file "sources", 128
fileIn, 144
file list, 27
fileOut, 144
FileDirectory, 89
fileNamed:, 89
FileStream, 50, 89
fill:rule:mask:, 109
FillInTheBlank, 171
findFirst, 76

findLast, 76
first, 74
firstSubView, 156
flash:, 113
Float, 48, 59, 64
follow:while, 112
fork, 91
Form, 21, 110-112, 147-148
format, 136
Fraction, 48, 59, 64
frame, 116
fromDisplay, 110
fromUser, 110

G

get contents, 144
goto:, 117
graphics editors, 147
drid:, 97

H

halftoneForm, 115
halt, 143
height, 101, 106
hierarchy, 46, 132

I

IdentityDictionary, 74
ifTrue:ifFalse:, 19
includes:, 69
includesKey:, 73
indexOf:, 74
InputSensor, 150
InputState, 150
insetBy:, 102
insetDisplayBox, 157
inspect, 139
Inspectors, 139-141
Instance, 7, 9, 43
instances, 43-45, 67
Integer, 48, 59, 64
interface, 118
intersect:, 102
intersects:, 103
Interval, 80-81
isControlActive, 159
, 95
isKindOf:, 31
isMemberOf:, 31
isNil, 34
K

keyboard, 151
keyword messages, 16
keys, 72

L

label, 162
LargeNegativeInteger, 48, 59
LargePositiveInteger, 48, 59
last, 74
lastSubView, 156
Line, 114
LinkedList, 79-80
lists, 165
ListController, 164, 166
ListView, 166

M

Magnitude, 53
mathematics, 60
max:, 53
maximumSize:, 162
menus, 26, 119, 120-121
merge:, 102
messages, 6, 15, 21, 35
Metaclass, 12, 40, 50
metaclasses, 11
methods, 8, 21, 25
millisecondsToRun:, 56
min:, 53
minimumSize:, 162
model, 152, 157
mouse, 26, 118
MouseMenuController, 160-162
motif, 107
multiple inheritance, 50
MVC, 152

N

name, 48
new, 21, 43
newFileNamed:, 89
next, 84, 95
nextPutAll:, 84
nil, 23, 34
notNil, 34
now, 56

Number, 48, 59
numbers, 13

O

Object, 31
objects, 6
oldFileNamed:, 89
on:, 85
open, 89
OrderedCollection, 37, 77-78
origin, 100, 101
offset, 106
over, 111

P

padTo:, 88
Paragraph, 164-165
ParagraphEditor, 164
paste, 28, 127, 140
Path, 113-114
peek, 85, 95
Pen, 115-117
perform:, 36
pixel, 105
Point, 96-99
PopUpMenu, 119
PositionableStream, 85-86
primitives, 25, 38
prinIt, 28, 128
printString, 34
priority, 17, 92, 93
proceed, 142
Process, 91
Processor, 92
Processor-Scheduler, 92-93
protocol, 129, 134
pseudo-variables, 23

Q

quit, 27

R

raisedTo:, 16-17
Random, 48
readFrom:, 110
ReadStream, 87
ReadWriteStream, 88
receiver, 16, 24
Rectangle, 99-104
redButtonActivity, 161
reject:, 69
release, 159
remove:, 68, 73
removeFirst, 78
removeLast, 78
rename, 130
respondsTo:, 31
restore display, 27
resume, 92
reverse, 110, 111
reverseDo:, 77
rounding, 62
RunArray, 83

S
save, 27
savedArea, 163
ScheduledControllers, 160
ScreenController, 160
scrollbar, 122
ScrollController, 162, 163
select:, 69
 selectors, 16, 42
SelectionInListController, 166
SelectionInListView, 166
self, 23
Semaphore, 94
Sensor, 150-151
SequenceableCollection, 36, 74-77
Set, 71
shallowCopy, 32
SharedQueue, 95
showWhile:, 112
signal, 94
size, 34
skip, 86
skipTo:, 86
SmallInteger, 31, 48, 59
Smalltalk, 10
someInstance, 44
SortedCollection, 79-79
sourceForm, 114
spawn, 130
StandardSystemController, 162-163
StandardSystemView, 119-120, 162-163

startUp, 159
status, 163
storeString, 35
Stream, 84-85
String, 81
StringHolder, 165
 subclasses, 10
subViews, 154
super, 24
superclass, 10, 40, 46
superView, 154
suspend, 92
Symbol, 31, 83
symbols, 14

T
terminate, 92
terminateActive, 92
tests, 42, 61
Text, 42, 83
TextStyle, 107
Time, 54
timesRepeat:, 64
to:, 81
today, 54
topView, 156
transcript, 30
true, 19
truncateTo:, 97
truncation, 62

U
unary messages, 16
under, 111
undo, 28
update:, 37

V
value, 16
values, 72
variables, 9, 15
class, 9
global, 10
indexed instance, 9
named instance, 9
pool, 10
temporary, 22
View, 152-153, 154-158, 168
view, 152
vital machine, 92
W
wait, 94
waitButton, 151
whileFalse, 19-20
whileTrue:, 19-20
white, 108
width, 101, 106
window, 26, 118, 157
with:, 87
WindowingTransformation,
153-154

workspace, 27, 127-128
WriteStream, 87

X
x, 21 96

Y
yield, 92
y, 21, 96

yellowButtonActivity, 161