Contents

Class View


Inheritance:

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:

  1. Adding subViews to a View.
  2. Positioning subViews within a View.
  3. Deleting subViews from a View.
  4. Transforming a View.
  5. Displaying a View.

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.

Instance Variables:

Public Instance Protocol:

Subview Creation Protocol

Testing

Accessing

View Layout Protocol

Layout of Subviews:

There are two different approaches:

  1. The top view is not given a window rectangle
  2. The top view is given a window rectangle.

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

The Display Framework:

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.


Contents