SubCanvas.st
author Claus Gittinger <cg@exept.de>
Fri, 21 May 1999 18:26:11 +0200
changeset 1383 1c0ffdda1a92
parent 1216 c9f8253a9e7c
child 1412 b426fae6edcf
permissions -rw-r--r--
care for nil client.

"
 COPYRIGHT (c) 1998 by eXept Software AG
              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.
"


ScrollableView subclass:#SubCanvas
	instanceVariableNames:'builder spec client clientHolder specHolder'
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Basic'
!

!SubCanvas class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1998 by eXept Software AG
              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
"
    a view for a subApplication.

    [author:]
        Claus Atzkern
"

! !

!SubCanvas methodsFor:'accessing'!

builder
    "return the value of the instance variable 'builder' (automatically generated)"

    ^ builder!

client
    "return the value of the instance variable 'client' (automatically generated)"

    ^ client!

client:anApplicationModel
    "release existing components and generate new components from
     the applications windowSpec."

    ^ self client:anApplicationModel spec:#windowSpec
!

client:anApplication spec:aWindowSpecOrSelector
    "release existing components and generate new components from
     the applications windowSpec."

    |aBuilder|

    (anApplication notNil and:[anApplication respondsTo:#builder]) ifTrue:[
        aBuilder := anApplication builder
    ] ifFalse:[
        aBuilder := UIBuilder new
    ].
  ^ self client:anApplication spec:aWindowSpecOrSelector builder:aBuilder
!

client:anApplication spec:aWindowSpecOrSpecSymbol builder:aBuilder
    "release existing components and generate new components from
     the given windowSpec, using the given builder."

    builder  := aBuilder.
    spec     := aWindowSpecOrSpecSymbol.

    "/ check for master application
    (anApplication notNil and:[anApplication masterApplication isNil]) ifTrue:[
        client := nil.
        client := self application.
        client ~~ anApplication ifTrue:[
            anApplication masterApplication:client
        ]
    ].
    client := anApplication.
    self rebuild.
  ^ builder
!

spec
    "return the value of the instance variable 'spec' (automatically generated)"

    ^ spec!

spec:something
    "set the value of the instance variable 'spec' (automatically generated)"

    spec := something.
    self rebuild.
!

widget
    "ST80 compatibility. 
     I am my own widget"

    ^ self

    "Created: / 10.3.1998 / 16:20:52 / stefan"
! !

!SubCanvas methodsFor:'accessing channels'!

clientHolder
    ^ clientHolder
!

clientHolder:aValueHolder

    clientHolder notNil ifTrue:[
        clientHolder removeDependent:self
    ].
    (clientHolder := aValueHolder) notNil ifTrue:[
        clientHolder addDependent:self
    ].
    self updateFromChannels
!

specHolder
    ^ specHolder
!

specHolder:aValueHolder

    specHolder notNil ifTrue:[
        specHolder removeDependent:self
    ].
    (specHolder := aValueHolder) notNil ifTrue:[
        specHolder addDependent:self
    ].
    self updateFromChannels
! !

!SubCanvas methodsFor:'building'!

rebuild
    "rebuild
    "
    |subSpec savedView builderClass|

    scrolledView notNil ifTrue:[
        scrolledView destroySubViews
    ].

    spec notNil ifTrue:[
        (subSpec := spec) isSymbol ifTrue:[
            client isNil ifTrue:[
                'SubCanvas [warning]: no client - cannot build spec' infoPrintCR.
                ^ self
            ].
            (subSpec := client class interfaceSpecFor:spec) isNil ifTrue:[
                "/ Transcript showCR:'SubCanvas: nil spec'.
                ^ self
            ]
        ].

        builder isNil ifTrue:[
            client isNil ifTrue:[
                builderClass := UIBuilder
            ] ifFalse:[
                builderClass := client builderClass
            ].
            builder := builderClass new.
        ].

        "/ old:
"/         builder buildFromSpec:subSpec in:scrolledView.

        "/ new (let app know (somehow) that this is a build
        "/ for a subcanvas (i.e. it can redefine the buildSubCanvase-method
        "/:
        savedView := builder window.
        builder window:scrolledView.
        client buildSubCanvas:subSpec withBuilder:builder.
        builder window:savedView.

        self realized ifTrue:[
            scrolledView realizeAllSubViews
        ]
    ]

    "Modified: / 20.6.1998 / 14:29:00 / cg"
!

releaseAllComponents
    scrolledView destroySubViews.
    builder := nil.
    spec    := nil.
    client  := nil.
! !

!SubCanvas methodsFor:'change & update'!

update:something with:aParameter from:changedObject
    "one of my models changed its value
    "
    (changedObject == clientHolder or:[changedObject == specHolder]) ifTrue:[
        self updateFromChannels
    ] ifFalse:[
        super update:something with:aParameter from:changedObject.
    ]

!

updateFromChannels
    "update canvas from channel
    "
    |client spec|

    clientHolder isNil ifTrue:[
        client := self application
    ] ifFalse:[
        client := clientHolder value
    ].

    specHolder isNil ifTrue:[
        spec := #windowSpec
    ] ifFalse:[
        spec := specHolder value
    ].
    (client notNil and:[spec notNil]) ifTrue:[
        self client:client spec:spec
    ] ifFalse:[
        self client:nil
    ]


! !

!SubCanvas methodsFor:'initialization'!

destroy
    clientHolder notNil ifTrue:[
        clientHolder removeDependent:self.
        clientHolder := nil.
    ].
    specHolder notNil ifTrue:[
        specHolder removeDependent:self.
        specHolder := nil.
    ].
    super destroy.
!

initialize
    super initialize.
    self scrolledView:View new.
    spec := #windowSpec.
! !

!SubCanvas methodsFor:'queries'!

application
    "return the application, under which this view was opened,
    "

    client notNil ifTrue:[
        ^ client
    ].
    ^ super application

! !

!SubCanvas class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libwidg2/SubCanvas.st,v 1.11 1999-05-21 16:26:11 cg Exp $'
! !