ExternalTopView.st
author Claus Gittinger <cg@exept.de>
Tue, 13 Jul 1999 17:38:21 +0200
changeset 1201 d8c4b4f52e7e
parent 1103 b98a73cd2ed1
child 1567 968c81db4d2c
permissions -rw-r--r--
code cleanup

"
 COPYRIGHT (c) 1999 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.
"


TopView subclass:#ExternalTopView
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Graphics-Support'
!

!ExternalTopView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1999 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
"
    Represents a view as created by some other application.
    This is a support-class to allow ST/X views to be created
    inside other applications.

    A simple demoApplication is found in goodies/stxInExternalWindow
    (which uses Demos::PlayInAlienWindow as a startup anchor)

    [author:]
        Claus Gittinger (cg@exept.de)

    [see also:]

    [instance variables:]
        none added here

    [class variables:]
        none added here
"
! !

!ExternalTopView class methodsFor:'instance creation'!

newWithID:anAlienWindowID
    "create and return a new externalTopView - the windowID
     as passed in must be from an alien programs view"

    ^ self new setWindowID:anAlienWindowID
! !

!ExternalTopView methodsFor:'private'!

checkWindowStillAlive
    "check for a destroyed topView 
     (must poll, since we do not get any events from X)"

    |prevHandler ok|

"/    Transcript showCR:'check ...'.

    ok := device isValidWindowId:drawableId.

    ok ifFalse:[
"/        Transcript showCR:'no ...'.
        self destroyed.
    ] ifTrue:[
        Processor 
            addTimedBlock:[self checkWindowStillAlive]
            for:nil
            afterMilliseconds:1000
    ]
! !

!ExternalTopView methodsFor:'private accessing'!

setWindowID:aWindowID
    drawableId := aWindowID.
    realized := shown := true.
! !

!ExternalTopView methodsFor:'queries'!

isExternalTopView
    "return true, if this is an external topView - always true here"

    ^ true
! !

!ExternalTopView methodsFor:'redefined'!

destroyView
    "never destroyed by ST/X - instead, the view is under
     control of the host application ..."

    realized := false.
    drawableId := nil.
!

open
    "redefined to start a watch timeout for closed windows;
     this is required, since we wont get any closeRequest event for
     external windows (as all of its events are handled by the alien
     application)"

    super open.
    self checkWindowStillAlive
!

unmap
    "redefined as a noop;
     ExternalTopViews are never unmapped by ST/X - instead, the view is under
     control of the host application ..."


! !

!ExternalTopView methodsFor:'special'!

becomeParentOf:anSTXWindow
    "add myself to the windowGroup of anSTXWindow ...
     and reparent anSTXWindow to be the (only) child of myself"

    |wg oldTopView|

    anSTXWindow createWithAllSubViews.

    oldTopView := anSTXWindow topView.

    wg := anSTXWindow windowGroup.
    wg notNil ifTrue:[
        wg addTopView:self.
    ].

    oldTopView == anSTXWindow ifTrue:[
        oldTopView container:self.
    ].

    self open. "/ not really an open; however it starts its event handler

    wg isNil ifTrue:[
        oldTopView windowGroup:self windowGroup.
    ].

    anSTXWindow device 
        reparentWindow:anSTXWindow id
        to:self id.

    self addSubView:anSTXWindow.
    anSTXWindow enableEvent:#structureNotify.

    anSTXWindow realize.
    anSTXWindow map.
    wg notNil ifTrue:[
        wg removeView:oldTopView.
        wg addView:oldTopView.
    ].

    anSTXWindow origin:0.0 @ 0.0 corner:1.0 @ 1.0.


! !

!ExternalTopView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview2/ExternalTopView.st,v 1.10 1999-02-17 00:09:13 cg Exp $'
! !