ModalBox.st
author claus
Wed, 13 Oct 1993 03:44:47 +0100
changeset 6 7ee0cfde237d
parent 5 e5942fea6925
child 12 9f0995fac1fa
permissions -rw-r--r--
*** empty log message ***

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

StandardSystemView subclass:#ModalBox
       instanceVariableNames:'haveControl shadowView'
       classVariableNames:'PopShadow'
       poolDictionaries:''
       category:'Views-Basic'
!

ModalBox comment:'

COPYRIGHT (c) 1990 by Claus Gittinger
              All Rights Reserved

$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.4 1993-10-13 02:43:51 claus Exp $

written Jan 90 by claus
'!

!ModalBox class methodsFor:'documentation'!

documentation
"
this class implements modal boxes; ModalBoxes are different from
others, in that they take complete control over the display, until 
all processing is done (i.e. other views will not get any events
while the box is active).

class variables:

PopShadow       <Boolean>       if true, modalBoxes will show a shadow

"
! !

!ModalBox class methodsFor:'initialization'!

initialize
    super initialize.
    PopShadow := self classResources name:'POPUP_SHADOW' default:false
! !

!ModalBox class methodsFor:'instance creation'!

new
    ^ super on:ModalDisplay
! !

!ModalBox methodsFor:'initialize / release'!

initialize
    super initialize.

    haveControl := false.
    self is3D ifTrue:[
        borderWidth := 0.
        self level:2
    ].

    PopShadow ifTrue:[
        shadowView := (ShadowView on:device) for:self
    ]
!

initEvents
    super initEvents.
    self enableKeyEvents
!

addToCurrentProject
    "ignored here"

    ^ self
!

destroy
    super destroy.
    shadowView notNil ifTrue:[shadowView destroy]
!

create
    super create.
    PopShadow ifFalse:[
        self saveUnder:true
    ]
!

createOnTop
    ^ true
! !

!ModalBox methodsFor:'show / hide'!

mapped
    "wait till visible for grabbing"

    super mapped.
    device grabKeyboardIn:drawableId.
    device setInputFocusTo:drawableId.
!

show
    "make myself visible and take control"

    self fixSize.
    shadowView notNil ifTrue:[shadowView realize].
    self raise.
    self realize.
    self takeControl
!

showAt:aPoint
    self origin:aPoint.
    ((top + height) > (device height)) ifTrue:[
        self top:(device height - height)
    ].
    ((left + width) > (device width)) ifTrue:[
        self left:(device width - width)
    ].
    (top < 0) ifTrue:[
        self top:0
    ].
    (left < 0) ifTrue:[
        self left:0
    ].
    self show
!

showAtPointer
    self showAt:(device pointerPosition - ((width // 2) @ (height // 2)))
!

showAtPointerNotCovering:aView
    |x y|

    x := device pointerPosition x - (width // 2).
    y := device pointerPosition y - (height // 2).
    (((x @ y) corner:((x + width) @ (y + height))) intersects:
     (aView origin corner: aView corner)) ifTrue:[
        x := aView origin x + aView width
    ].
    self showAt:(x @ y)
!

hide
    "make myself invisible and leave control"

    self unrealize.
    device synchronizeOutput.
    shadowView notNil ifTrue:[shadowView unrealize].
    self leaveControl.
! !

!ModalBox methodsFor:'private'!

takeControl
    haveControl := true.

"
    device grabKeyboardIn:drawableId.
    device setInputFocusTo:drawableId.
"

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

    device dispatchWhile:[haveControl]
!

leaveControl
    haveControl := false.
    device ungrabKeyboard
! !