29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

displayed. The second component added to the compositePart is <strong>an</strong>other composed text (displaying the<br />

string Goodbye). However this time, the string is being bordered. That is, a box is being drawn around<br />

that string as a border. This border is actually h<strong><strong>an</strong>d</strong>led by a Wrapper (Wrappers provide needed<br />

bookkeeping information such as tr<strong>an</strong>slation, clipping, borders, etc.). Note that the border is specified<br />

relative to the size of the encapsulating window (this is why the rect<strong>an</strong>gle specifying the border is<br />

specified as 0.2 by 0.3 to 0.5 by 0.6. This me<strong>an</strong>s that the top right h<strong><strong>an</strong>d</strong> corner of the border should start<br />

at a position which is 20% of the width of the window by 30% of its depth <strong><strong>an</strong>d</strong> should extend to a<br />

position which is 50% of its width <strong><strong>an</strong>d</strong> 60% of its depth (note windows have their zero, zero position in<br />

the top left h<strong><strong>an</strong>d</strong> corner of the window).<br />

The third part of the source code in Figure 26.9 adds the compositePart (containing the two strings)<br />

to the scheduled window <strong><strong>an</strong>d</strong> opens t he scheduled window. The result of opening the window is<br />

illustrated in Figure 26.10.<br />

Figure 26.10: A simple window<br />

An import<strong>an</strong>t point to note is that although a view c<strong>an</strong> co ntain multiple subviews which it<br />

coordinates, only the views are connected; the associated controllers are not. This is illustrated in Figure<br />

26.11. Finally, views c<strong>an</strong> only have one controller <strong><strong>an</strong>d</strong> one model. Controllers c<strong>an</strong> also only have one<br />

view <strong><strong>an</strong>d</strong> one model. However, models may have <strong>an</strong>y number of views associated with them.<br />

26.5 The controller hierarchy<br />

To determine which controller should respond to the user input, there is a controller hierarchy which<br />

mirrors the view hierarchy. At the root of this tree is the controller associated with the top component.<br />

This controller tries to find a sub controller which will accept control. If none will accept control then it<br />

must process the input. Controllers wil l only accept control if the cursor is within their view. Upon<br />

accepting control the first thing a controller will do is see if a subcontroller will accept control. Once a<br />

controller has control, it will retain control until the cursor leaves its view. Any input from the user will<br />

then be h<strong><strong>an</strong>d</strong>led by the appropriate controller.<br />

view1<br />

controller1<br />

view3<br />

view2<br />

controller3<br />

controller2<br />

Figure 26.11: The view-subview / controller relationships<br />

The actual mech<strong>an</strong>ism through which this is performed is slightly complicated, however, basically,<br />

whenever the cursor enters a window a control m<strong>an</strong>ager (see the class ControlM<strong>an</strong>ager for further<br />

details) passes control to that window. This is done by asking each window controller whether it w<strong>an</strong>ts<br />

to take control or not (via a message isControlW<strong>an</strong>ted). The first controller that requests control is<br />

given control. This is done via the message startUp.<br />

It is then up to the windows controller to decide how it will h<strong><strong>an</strong>d</strong>le this control. Typically it<br />

determines whic h of its subcomponents w<strong>an</strong>ts to gain control via the message<br />

subViewW<strong>an</strong>tingControl. The window (or top component) then asks its components whether they<br />

w<strong>an</strong>t control (using the objectW<strong>an</strong>tingControl message). The components (or views) then ask<br />

their controllers whether they w<strong>an</strong>t control. If the controller identifies that it should have control, then it<br />

takes over the primary control operation.<br />

221

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!