PopUpView.st
author claus
Fri, 16 Jul 1993 11:42:20 +0200
changeset 0 48194c26a46c
child 2 b35336ab0de3
permissions -rw-r--r--
Initial revision

"
 COPYRIGHT (c) 1989-93 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:#PopUpView
       instanceVariableNames:'shadowView haveControl'
       classVariableNames:'PopShadow'
       poolDictionaries:''
       category:'Views-Basic'
!

PopUpView comment:'

COPYRIGHT (c) 1989-93 by Claus Gittinger
              All Rights Reserved

this class implements an abstract superclass for all views which bypass the window manager
and pop up on top of the screen. These are: PopUpMenus, Alertboxes etc...

class variables:

PopShadow       <Boolean>       if true, popupviews show a shadow

%W% %E%

written spring/summer 89 by claus
'!

Smalltalk at:#ActiveGrab put:nil!

!PopUpView class methodsFor:'defaults'!

defaultExtent
    ^ (Display width // 2) @ (Display height // 2)
! !

!PopUpView class methodsFor:'initialization'!

initialize
    super initialize.
    PopShadow := Resource name:'POPUP_SHADOW' 
                       default:View3D
                      fromFile:'Smalltalk.rs'
! !

!PopUpView methodsFor:'initialization / release'!

initialize
    |c|

    super initialize.
    c := device center.
    left := c x - (width // 2).
    top := c y - (height // 2).
    self is3D ifTrue:[
        borderWidth := 0.
        self level:2
    ] ifFalse:[
        borderWidth := 1
    ].

    PopShadow ifTrue:[
        shadowView := (ShadowView on:device) for:self.
        device hasGreyscales ifTrue:[
            shadowView paint:(Color darkGrey)
        ]
    ].
    haveControl := false
!

destroy
    haveControl := false.
    super destroy.
    shadowView notNil ifTrue:[shadowView destroy]
!

create
    super create.
    self saveUnder:true
! !

!PopUpView methodsFor:'dispatching'!

modalLoop
    haveControl := true.

    "this is a kludge - we do not have multiple processes, therefore
     we start another dispatch loop, which exits when control is lost"

    device dispatchFor:nil "drawableId" while:[haveControl]
! !

!PopUpView methodsFor:'private'!

takeControl
^ self.
    haveControl := true.

    "this is a kludge - we do not have multiple processes, therefore
     we start another dispatch loop, which exits when control is lost"

    device dispatchFor:drawableId while:[haveControl]
!

leaveControl
    haveControl := false
! !

!PopUpView methodsFor:'realize / unrealize'!

mapped
    "wait till visible for grabbing"

    super mapped.
    device grabPointerIn:drawableId.
    ActiveGrab := self.
!

realize
    shadowView notNil ifTrue:[shadowView realize].
    self raise.
    super realize.

    "get the pointer into my window"
"
    device grabPointerIn:drawableId.
    ActiveGrab := self.
"
    "and handle events for me"
    self takeControl
!

unrealize
    shadowView notNil ifTrue:[shadowView unrealize].
    haveControl := false.
    ActiveGrab := nil.
    device ungrabPointer.
    super unrealize
! !

!PopUpView methodsFor:'accessing'!

heightIncludingBorder
    ^ height
!

widthIncludingBorder
    ^ width
!

createOnTop
    ^ true
! !