Object » View
Instances of (subclasses of) View are intended to be components in a structured picture. Each View in the structured picture can contain other Views as sub-components. These sub-components are called subViews. A View can be a subView of only one View. This View is called its superView. The set of Views in a structured picture forms a hierarchy. The one View in the hierarchy that has no superView is called the topView of the structured picture. A View in a structured picture with no subViews is called a bottom View. A View and all of its subViews, and all of their subViews and so on, are treated as a unit in many operations on the View. For example, if a View is displayed, all of its subViews are displayed as well. There are several categories of operations that can be performed on a View. Among these are the following:
Each View has its own coordinate system. In order to change from one coordinate system to another, each View has two transformations associated with it. The local transformation is a WindowingTransformation that maps objects in the coordinate system of the View to objects in the coordinate system of the superView of the View. The displayTransformation is a WindowingTransformation that maps objects in the coordinate system of the View to objects in the display screen coordinate system.
The part of the space that is to be made visible is represented by the window of the View. The window of a View is a Rectangle expressed in the coordinate system of the View. The area occupied by a View in the coordinate system of its superView is called its viewport. The viewport of a View is its window transformed by its local transformation. The region of the display screen occupied by a View is called its display box. The display box of a View can include a border. The width of the border expressed in display screen coordinates is called the border width of the View. The color of the border is called the border color. The region of the display box of a View excluding the border is called the inset display box. The color of the inset display box is called the inside color of the View.
View is the superclass of all specialized view classes. Among the specialized view classes you find classes to display text, selection lists, switches and images. It should be mentioned that View is not an abstract class: It can be used as a container for other subviews. The use of a View instance as a subview container can significantly simplify the view layout definition for a complicated window.
Views are one constituent element in the model-view-controller pattern. A view acts as an observer of its model.
model - isKindOf: Model
An object that has the responsibility to provide the information to be
displayed by
the view.
controller - isKindOf: Controller
The controller that is associated with the view.
The following assertion should hold:
controller view == self.
superView - nil or isKindOf:
View
The view that contains the view. The topmost view of a window has no
superview.
The following assertion should hold:
superView isNil or: [superView subViews includes: self]
subViews - OrderedCollection
A collection of all subviews of the view. This variable is initialized
to an empty OrderedCollection, but some instance methods
replace this collection with nil.
Specifically, for a collapsed StandardSystemView,
this instance variable is nil.
The following assertion should hold:
subViews isNil or: [subViews allSatisfy: [:sv | (sv isKindOf: View) and: [sv superView == self]] ]
transformation - WindowingTransformation
The local transformation of the view. It maps objects in the coordinate
system of the View
to objects in the coordinate system of the superView of the View. This
transformation is used to implement both vertical and horizontal
scrolling.
viewport - Rectangle
This rectangle is expressed in the coordinates of the superview. It
describes the area that is occupied by the view in its superview.
window - Rectangle
The part of the space that is to be displayed by the view. This
rectangle
is expressed in the coordinates of the view.
This rectangle is affected by the generic scrolling method in View.
Some subclasses
redefine scrolling and do not use the instance variable window
to record the
current scroll position.
displayTransformation - WindowingTransformation
This transformation maps objects (mostly points and rectangles) in the
coordinates of the view
to objects in the display screen coordinate system.
insetDisplayBox - Rectangle
This rectangle defines the display area that the view is allowed to
paint into.
borderWidth - Integer
or Rectangle
An integer value of this variable defines the width of all four border
lines. A rectangle
defines individual widths of the border lines.
borderColor - Color
The color that is used to draw the view border
insideColor - Color
The color that is used to fill the inset display box of the view.
boundingBox - Rectangle
Answer the minimum Rectangle that encloses
the bounding
boxes of the receiver's subViews. If the receiver has no subViews, then
the bounding box is the receiver's window.
This rectangle is used for scrolling. (see ScrollController for details.)
controller: aController
add a controller to the view.
model: aModel
add a model to the view and register the view as an observer
of the model.
model: aModel controller: aController
add a model and a controller to the view. The view is registered
as an observe of the model. The controller is initialized to
cooperate with both the view and the model.
foregroundColor: aColor
set the foreground color of the view.
backgroundColor: aColor
set the background color of the view.
borderWidth: anInteger
set the border width of all four borders to anInteger.
borderWidthLeft: anInteger1 right:
anInteger2 top: anInteger3
bottom: anInteger4
set the border widths of the four borders individually.
addSubView: aView
Remove aView from the tree of Views it is in (if any) and adds it to the
rear of the list of subViews of the receiver. Set the superView of aView
to be the receiver. It is typically used to build up a hierarchy of Views
(a structured picture). An error notification is generated if aView is the
same as the receiver or its superView, and so on.
addSubView: aView above: lowerView
Adds a view so that it is placed above lowerView.
addSubView: aView below: upperView
Adds a view so that it is placed below upperView.
addSubView: aView toLeftOf: rightView
Adds a view so that it is placed left of rightView.
addSubView: aView toRightOf: leftView
Adds a view so that it is placed right of leftView.
lock
For a unlocked view, this method computes and stores the display
transformation and the inset display box.
The method also computes and stores the display transformations
and inset display boxes of all direct and indirect subviews.
unlock
For a locked view, this method deletes the display
transformation and the inset display box. These
view elements are automatically recomputed and stored in
the instance as soon as they are needed.
The method also deletes the display transformations
and inset display boxes of all direct and indirect subviews.
isLocked
Answer whether the receiver is locked. A locked view has
a valid precomputed display transformation (which is stored
in instance variable displayTransformation) and a
valid precomputed inset display box that is stored in instance variable
insetDisplayBox.
The display transformation and inset display box become undefined when
the transformation of the View (or the transformation of a View in its
superView chain) is changed, or when the superView of the View is
changed, or any other change to the View that affects the display
screen coordinates of the View. The locking and unlocking of a View is
handled automatically by the internal methods of the View, but can also
be done explicitly if desired (with View>>lock, and
View>>unlock).
isUnlocked
Answer whether the receiver is unlocked. A view is unlocke
if either its display transformation or its inset display box
is undefined.
removeFromSuperView
***.
releaseSubViews
Release (see View|releaseSubView:) all subViews.
releaseSubView: aView
Delete aView from the view's list of subViews and send it the message
'release' (so that it can break up cycles with subViews, etc.).
release
disconnect the receiver (a view) from its model and from its
controller. The subviews of the receiver are likewise disconnected
from their models and controllers. Subclasses may redefine this
method, but a redefined method should include the expression
super release to ensure complete cleanup. A view that
registers itself as a dependent to a second data source
has to redefine the method release to disconnect
itself from that second data source when it is released.
isTopView
answers true if the receiver is the topView, and false otherwise.
isObscured
answers true if the receiver's inset display box is partly or
completely
covered by a scheduled window. Occlusion by subviews of the receivers
topView is not checked. Strange things may happen when an obscured
view is refreshed.
topView
answers the topView of the receiver. This method can be used to
find out whether a window is the currently active window.
For the active window, this condition holds:
self topView controller == ScheduledControllers activeController
window: aRectangle
Sets the preferred display rectangle to a copy of aRectangle.
(A copy
is used to avoid strange effects when aRectangle is modified.)
There are two different approaches:
It is often not necessary to specify a window rectangle for the top view. This is why we explain this approach first.
| topView subView1 subView2 | topView := View new. subView1 := View new. subView2 := View new. topView borderWidth: 1. subView1 insideColor: Color green. subView2 insideColor: Color red. subView1 window: (0 @ 0 extent: 20 @ 100). topView addSubView: subView1. subView2 window: (0 @ 0 extent: 80 @ 100). topView addSubView: subView2 toRightOf: subView1. topView display
When a display window is defined for the top view, the display windows of the subviews are defined in coordinates of the display window of the top view. When we follow this approach, we use only the method addSubView:, not the methods that specify placement relative to a second subview.
| topView subView1 subView2 | topView := View new. subView1 := View new. subView2 := View new. topView borderWidth: 1; window: (0 @ 0 extent: 200 @ 200). subView1 insideColor: Color green. subView2 insideColor: Color red. subView1 window: (5 @ 5 extent: 90 @ 190). topView addSubView: subView1. subView2 window: (105 @ 5 extent: 90 @ 190). topView addSubView: subView2. topView display
Smalltalk-80 provided a very convenient method to place a subview:
addSubView: aView in: aRelativeRectangle borderWidth: width "11/3/96 ssa - added for compatibility." "Make 'aView' into a subview. Use 'aRelativeRectangle' and the super view's window to compute (1) a viewport within the superview for 'aView' and (2) the window extent for 'aView'. Note: defining the windowing transformation and deriving the viewport is logically equivalent but does not seem to be easily done" | subViewPort myWindow | self addSubView: aView ifCyclic: [self error: 'cycle in subView structure.']. aView borderWidth: width. myWindow := self window. subViewPort := (aRelativeRectangle scaleBy: myWindow extent) translateBy: myWindow origin. aView window: aView window viewport: subViewPort
You can use the change set addSubView.1.cs to load this method into your image.
Example:
| v v1 v2 | v := View new. v1 := View new. v2 := View new. v borderWidth: 1. v1 insideColor: Color green. v2 insideColor: Color red. v window: v window viewport: (20 @ 20 corner: 150 @ 100). v addSubView: v1 in: (0 @ 0 extent: 0.5 @ 0.5) borderWidth: 2. v addSubView: v2 in: (0.5 @ 0.5 extent: 1 @ 1) borderWidth: 2. v display
An instance of View cannot be installed as a movable object on the display screen. Movable views (application windows) are instances of either StandardSystemView or ColorSystemView. These specialized views implement the protocol that is needed for cooperation with the window manager. The following example shows how such a view is created. To install the view on the display screen, you send the message open to the view controller. The controller registers itself with an instance of ControlManager, the window manager that has the responsibility to manage all views that the user has placed on the display screen.
| topView container1 container2 | topView := StandardSystemView new. topView label: 'View with containers'; borderWidth: 1. topView addSubView: ((container1 := View new) borderWidth: 1; window: (0 @ 0 extent: 200@40) ). topView addSubView: ((container2 := View new) borderWidth: 1; window: (0 @ 0 extent: 200@80) ) below: container1. topView controller open
Class View implements a set of methods that are used to display the content of a view. Subviews are required to follow the conventions of that framework.
There are two visual presentations of a view: The emphasized presentation and the deemphasized one. The emphasized presentation should be used for the active window, the deemphasized presentation should be used for all deactivated windows.
display
This method displays the view border, the view content and all
subviews. There is normally no need to redefine the methods displayBorder
and displaySubViews. The method View>>displayView
does nothing, this is a default for views that are entirely drawn by
their subviews.
Views that are not completely drawn by their subviews have to redefine
this method.
displayView
This method displays the content of a view. It should draw only into
the
rectangle that is answered by the method insetDisplayRect.
emphasize
This method emphasizes the view and then all its subviews.
emphasizeView
This method is used to add emphasis to an already drawn presentation
of the view.
deEmphasize
This method removes emphasis from the view itself and from all its
subviews.
deEmphasizeView
This method is used to remove emphasis from a completely drawn
emphasized presentation of the view.
displayDeEmphasized
This method displays the view border, the view content and all subviews
and removes emphasis.
displayViewDeEmphasized
This method displays the view content (without the subviews) and
removes emphasis.
update
The method implements the reaction to an unspecified change of
the model. The default behavior of View is to translate
the unspecified update request into a more specific one by
sending
self update: self.
The message update is normally sent from a model to inform the view about a change of the model that may or may not require a reaction from the side of the view.
update: aParameter
The method implements the reaction to a change of the model that is
further described by the value of aParameter.
The default behavior of View is to do nothing.
The message update: is normally sent from a model to inform the
view about a
change of the model that may or may not require a reaction from the
side of the view. The receiver may use the value of aParameter
to decide what to do. Some
subviews react to fixed symbols, others compare aParameter
with a stored value.
Usually an action from the side of the view includes a refresh of
the view. For most views the refresh can be accomplished with displayView,
a view that has to refresh all its subviews may
do that with display. It is not always
clear whether an update
method should do an emphasize.
defaultControllerClass
Answer a class that responds to the class method new.
The class is used to create a default controller when no
controller is given. The instance protocol of View
defines Controller as the default
controller class. This controller is suitable for