Classes to know are:
Much of the drawing protocol is defined in abstract classes. These can be subclassed to support drawing on canvases other than bitmaps and views.
For example, a public domain goodie adds support to draw on a Postscript printer page. Therefore, the same piece of code that did the view redraw can now be used to send a hardcopy to the printer.
Most of the graphics functionality is implemented in the GraphicsContext
and DeviceDrawable
classes - these keep a handle to the actual underlying
drawing device (i.e. a bitmap, a view or a postscript printers page), and
forward low level drawing requests to that device.
Press here for more details about:
GraphicsContext
or:
DeviceDrawable
.
The View class provides the most of the GUI functionality
- although in a very generic and abstract way.
It deals with resizing, redrawing, startup and closedown of views.
Most other GUI components inherit (i.e. are subclassed) from this class.
All user interface components in Smalltalk/X
are implemented as (direct or indirect) subclasses of View
.
Therefore, starting with View, you will find all components (such as Buttons,
ScrollBars, TextViews etc.) in the subclass hierarchy.
The most heavily used protocol:
aView := <someViewClass> new
newView := <someViewClass> new.
outerView addSubView: newView.
aView := <someViewClass> in: anotherView
newView := <someViewClass> new.
newView origin: <topLeftOriginPoint>.
newView corner: <bottomRightCornerPoint>.
otherView addSubView: newView.
aView := <someViewClass>
origin: <originPoint> corner: <cornerPoint> in: outerView
aView inset: <numberOfPixels>
aView level: <numberOfPixels>
aView destroy
aView viewBackground: aColorOrBitmap
aView paint: aColorOrBitmap.
aView displayLineFrom: startPoint to: endPoint.
Press here for more details about:
the View classes protocol
.
Instances of this class represent topViews on your display screen. TopViews are the outer frames, which typically have a window title, can be iconified, and are managed by the displays window manager.
This class provides protocol to define a views icon, window title and
position on the screen. On systems which support this (i.e. X displays with
Shape extension) arbitrary shaped views (like round clocks) are supported.
Also iconification, icon windows, size constrains and manual focus change
via the keyboard are supported.
The most useful protocol:
aTopView := StandardSystemView new
aTopView := StandardSystemView extent: <extentPoint>.
aTopView := StandardSystemView new.
aTopView label: 'hello world'.
aTopView icon: (Image fromFile:'... someFilename ...').
aTopView iconLabel: 'hello'.
#open
message - and called opening the view.
Views can be opened modeless (the new view is handled by an independent
process and control returns immediately to the sender of the open message) or
modal (the new view is handled by the calling process; control
returns when the new view is closed).
By default, all dialog views open up modal, all other views
open modeless. However, you can send all an explicit openModeless
or #openModal
message to get around that default behavior.
aTopView open
aTopView openModeless
aTopView openModal
#open
message - the reason is that the open operation starts a new
process for the view. By default, the new process executes at the same priority as
the currently running process - therefore, the actual opening will be done
later, when the current process is suspended (typically, when it waits for
input).
If you want to draw into the new view (from the creating process) right after the open message, you have to make certain that the new view is really open.
aTopView openAndWait
Press here for more details about:
StandardSystemView
or:
TopView
or:
DialogBox
.
Typical uses:
|topView|
topView := StandardSystemView new.
topView extent:200@200.
topView open.
|topView|
topView := StandardSystemView new.
topView extent:400@200.
topView label:'my first view'.
topView icon:(Image fromFile:'bitmaps/hello_world.icon').
topView iconLabel:'myView'.
topView open.
|topView innerView|
topView := StandardSystemView new.
topView extent:400@200.
topView label:'my first view'.
topView icon:(Image fromFile:'bitmaps/hello_world.icon').
topView iconLabel:'myView'.
innerView := View origin:10@10 corner:0.5@0.5 in:topView.
innerView viewBackground:(Color red).
topView open.
|topView panel button1 button2|
topView := StandardSystemView extent:400@200.
topView label:'buttons'.
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:topView.
panel inset:10.
panel level:-1.
button1 := Button label:'press me' in:panel.
button1 action:[ Transcript showCR:'hello there' ].
button1 foregroundColor:(Color blue).
button2 := Button label:'close me' in:panel.
button2 action:[ topView destroy ].
button2 backgroundColor:(Color red).
button2 foregroundColor:(Color white).
button2 enteredBackgroundColor:(Color red lightened).
topView open.
|topView menu fileMenu model|
model := 'some model'.
topView := StandardSystemView extent:200@200.
topView label:'Demo'.
menu := PullDownMenu in:topView.
menu labels:#('file' 'edit')
selectors:#(file edit).
"/
"/ direct action on the edit item
"/
menu
actionAt:#edit put:[ Transcript showCR:'edit action' ].
"/
"/ submenu on the file item
"/
menu at:#file
putLabels:#('new'
'-'
'open ...'
'-'
'quit'
)
selectors:#(new
nil
open
nil
quit
).
fileMenu := menu subMenuAt:#file.
fileMenu
actionAt:#new put:[ Transcript showCR:'new action ...' ].
fileMenu
actionAt:#open put:[ Transcript showCR:'open action ...' ].
fileMenu
actionAt:#quit put:[ topView destroy ].
topView open.
Copyright © 1995 Claus Gittinger Development & Consulting
<cg at exept.de>