TopView.st
author Claus Gittinger <cg@exept.de>
Fri, 31 May 1996 09:06:14 +0200
changeset 775 fbabce661c52
parent 761 34d17118452a
child 907 6bc7254cdd6a
permissions -rw-r--r--
comment

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

View subclass:#TopView
	instanceVariableNames:'type'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Basic'
!

!TopView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    I am an abstract superclass of StandardSystemView and PopUpView;
    i.e. views which have no superview.

    Do not get confused by the name TopView - your applications
    topViews are typically instances of StandardSystemView.


    [see also:]
        StandardSystemView PopUpView DialogBox 
        ( introduction to view programming :html: programming/viewintro.html )

    [author:]
        Claus Gittinger
"
! !

!TopView class methodsFor:'defaults'!

defaultExtent
    "return the default extent of my instances.
     Topviews extents is 2/3 of screen by default"

    |display|

    display := Screen current.
    ^ (display width // 3 * 2) @ (display height // 3 * 2)

    "Modified: 22.4.1996 / 23:39:13 / cg"
! !

!TopView methodsFor:'accessing-behavior'!

beMaster
    "make this a master-view. All slave views within the same
     windowGroup will be closed if any master is closed."

    type := #master

    "
     see example in TopView>>beSlave
    "

    "Created: 10.12.1995 / 13:30:50 / cg"
!

bePartner
    "make this a partner-view. Each partner-view will automatically 
     close other partner views (within the same windowGroup) when closed."

    type := #partner 

    "
     create two topViews within the same group:
     if any of them is iconified/deiconified/closed, the other one is also

     |top1 top2|

     top1 := StandardSystemView new label:'partner'; extent:300@300.
     top2 := StandardSystemView new label:'partner'; extent:200@200.
     top1 bePartner.
     top2 bePartner.

     top1 open.
     top2 openInGroup:(top1 windowGroup)
    "

    "Created: 10.12.1995 / 13:29:59 / cg"
    "Modified: 25.5.1996 / 11:44:48 / cg"
!

beSlave
    "make this a slave-view. It will be closed automatically,
     whenever any master of the windowgroup is closed.
     See also: #bePartner"

    type := #slave 

    "
     create two topViews within the same group:
     the slave is allowed to be iconified/close independ of the master;
     but if the master is iconified, the slave is also.

     |top1 top2|

     top1 := StandardSystemView new label:'master'; extent:300@300.
     top2 := StandardSystemView new label:'slave'; extent:200@200.
     top1 beMaster.
     top2 beSlave.

     top1 open.
     top2 openInGroup:(top1 windowGroup)
    "

    "Created: 10.12.1995 / 13:29:10 / cg"
    "Modified: 25.5.1996 / 11:45:30 / cg"
!

focusSequence:aCollectionOfSubcomponents
    "define the sequence for stepping through my components."

    windowGroup isNil ifTrue:[
        windowGroup := WindowGroup new.
    ].
    windowGroup focusSequence:aCollectionOfSubcomponents.

    "Created: 6.3.1996 / 15:37:11 / cg"
    "Modified: 30.4.1996 / 15:41:40 / cg"
! !

!TopView methodsFor:'event handling'!

keyPress:key x:x y:y
    "notice: this is going to be moved into the upcoming 
     StandardSystemViewController."

    <resource: #keyboard ( #Tab #FocusNext #FocusPrevious #CursorDown #CursorUp ) >

    key == #Tab ifTrue:[
        windowGroup notNil ifTrue:[
            self sensor shiftDown ifTrue:[
                windowGroup focusPrevious
            ] ifFalse:[
                windowGroup focusNext
            ]
        ]
    ].
    (key == #FocusNext or:[key == #CursorDown]) ifTrue:[
        windowGroup notNil ifTrue:[
            windowGroup focusNext.
        ]
    ].
    (key == #FocusPrevious or:[key == #CursorUp])  ifTrue:[
        windowGroup notNil ifTrue:[
            windowGroup focusPrevious.
        ]
    ].

    "Created: 1.2.1996 / 22:08:30 / cg"
    "Modified: 7.3.1996 / 13:19:35 / cg"
!

showActivity:someMessage
    "some activityNotification shalt be communicated to
     the user. 
     Default for activity notifications here: ignore them"

    ^ self

    "Created: 16.12.1995 / 18:40:13 / cg"
    "Modified: 23.4.1996 / 21:38:27 / cg"
! !

!TopView methodsFor:'initialization'!

initialize
    "initialize the topViews position for the screens center"

    |screenCenter|

    super initialize.

    screenCenter := device center.
    left := screenCenter x - (width // 2).
    top := screenCenter y - (height // 2).
    type := #normal
! !

!TopView methodsFor:'misc'!

raiseDeiconified
    "deiconify & bring to front"

    self isCollapsed ifTrue:[
        self unmap.
        self realize.
    ].
    self raise

    "
     Transcript topView raiseDeiconified
    "

    "Modified: 3.5.1996 / 23:49:36 / stefan"
!

withCursor:aCursor do:aBlock
    "evaluate aBlock while showing aCursor in all my views.
     Return the value as returned by aBlock."

    windowGroup notNil ifTrue:[
	^ windowGroup withCursor:aCursor do:aBlock
    ].
    ^ super withCursor:aCursor do:aBlock
! !

!TopView methodsFor:'queries'!

heightIncludingBorder
    "return the views overall-height"

    ^ height
!

isCollapsed
    "ST80 compatibility: return true if the view is not shown (i.e. iconified)"

    ^ shown not
!

preferredExtent
    "return my preferred extent - this is the minimum size I would like to have.
     The default here is the classes default extent,
     however many subclasses redefine this to compute the actual value
     depending on the sizes of the contents or subcomponents."

    preferredExtent notNil ifTrue:[
        ^ preferredExtent
    ].
    ^ self class defaultExtent

    "Modified: 29.5.1996 / 12:10:32 / cg"
!

type
    "return the views type. This is one of #normal,
     #master, #slave or #partner."

    ^ type
!

widthIncludingBorder
    "return the views overall-width"

    ^ width
! !

!TopView methodsFor:'startup'!

openWithExtent:anExtent
    "set extent and open. The given extent overrides the 
     receivers preferredExtent.
     Added for ST-80 compatibility"

    self extent:anExtent; sizeFixed:true.
    self open
!

openWithPriority:aPriority
    "open the view, run the windowgroup process at
     other than UserScehdulingPriority."

    self open.
    windowGroup process priority:aPriority.

    "Created: 30.4.1996 / 15:34:44 / cg"
! !

!TopView methodsFor:'window events'!

destroy
    "the receiver is to be destroyed - look for partners and slaves"

    |wg|

    wg := windowGroup.                  "/ have to fetch windowGroup before;
    super destroy.                      "/ since destroy nils it

    "/
    "/ destroy slaves and partners
    "/
    self masterSlaveMessage:#destroy inGroup:wg 

"/    wg notNil ifTrue:[
"/        "/
"/        "/ if I am a master or partner, close all slaves
"/        "/
"/        (type == #master or:[type == #partner]) ifTrue:[
"/            wg slavesDo:[:v | v destroy].
"/        ].
"/        "/
"/        "/ if I am a partner, close all partners
"/        "/
"/        type == #partner ifTrue:[
"/            wg partnersDo:[:v | v ~~ self ifTrue:[v destroy]].
"/        ].
"/    ].
!

mapped
    "the receiver was mapped (i.e. deiconified or just created);
     look for partners and slaves."

    realized := true.
    super mapped.

    "/
    "/ remap slaves and partners
    "/
    self masterSlaveMessage:#remap inGroup:windowGroup

    "Modified: 31.5.1996 / 09:05:58 / cg"
!

masterSlaveMessage:aSelector inGroup:aWindowGroup
    "send aSelector to partners and/or slaves.
     This is a private helper for destroy / mapped / unmapped"

    aWindowGroup notNil ifTrue:[
	"/
	"/ if I am a master or partner, send to all slaves
	"/
	(type == #master or:[type == #partner]) ifTrue:[
	    aWindowGroup slavesDo:[:v | v perform:aSelector].
	].
	"/
	"/ if I am a partner, send to all partners
	"/
	type == #partner ifTrue:[
	    aWindowGroup partnersDo:[:v | v ~~ self ifTrue:[v perform:aSelector]].
	].
    ].
!

unmapped 
    "the recevier was unmapped (i.e. iconified);
     look for partners and slaves."

    super unmapped.

    "/
    "/ unmap slaves and partners
    "/
    self masterSlaveMessage:#unmap inGroup:windowGroup

    "Modified: 30.5.1996 / 09:37:22 / cg"
! !

!TopView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview/TopView.st,v 1.26 1996-05-31 07:06:14 cg Exp $'
! !