ModalBox.st
changeset 89 ea2bf46eb669
parent 86 032006651226
child 113 60981f3775c6
equal deleted inserted replaced
88:8f9c629a4245 89:ea2bf46eb669
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 StandardSystemView subclass:#ModalBox
    13 StandardSystemView subclass:#ModalBox
    14        instanceVariableNames:'haveControl shadowView exclusiveKeyboard '
    14        instanceVariableNames:'shadowView exclusiveKeyboard '
    15        classVariableNames:'UseTransientViews'
    15        classVariableNames:'UseTransientViews'
    16        poolDictionaries:''
    16        poolDictionaries:''
    17        category:'Views-Basic'
    17        category:'Views-Basic'
    18 !
    18 !
    19 
    19 
    20 ModalBox comment:'
    20 ModalBox comment:'
    21 COPYRIGHT (c) 1990 by Claus Gittinger
    21 COPYRIGHT (c) 1990 by Claus Gittinger
    22 	      All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libview/ModalBox.st,v 1.15 1994-11-28 21:01:03 claus Exp $
    24 $Header: /cvs/stx/stx/libview/ModalBox.st,v 1.16 1995-02-06 00:37:31 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !ModalBox class methodsFor:'documentation'!
    27 !ModalBox class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libview/ModalBox.st,v 1.15 1994-11-28 21:01:03 claus Exp $
    45 $Header: /cvs/stx/stx/libview/ModalBox.st,v 1.16 1995-02-06 00:37:31 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
    51     this class implements modal boxes; ModalBoxes are different from
    51     this class implements modal boxes; ModalBoxes are different from
    52     others, in that they take control over the current topview, until 
    52     others, in that they take control over the current topview, until 
    53     all processing is done (i.e. the currently active topview and all of
    53     all processing is done (i.e. the currently active topview and all of
    54     its subviews will not handle user events while the box is active).
    54     its subviews will not handle user events while the box is active).
       
    55 
       
    56     ModalBoxes are either implemented as transient windows
       
    57     (if UseTransientViews := true) or as override redirect views.
       
    58     Some window managers have problems with either; so you may want to
       
    59     change the default setting from your display.rc file.
    55 "
    60 "
    56 ! !
    61 ! !
    57 
    62 
    58 !ModalBox class methodsFor:'initialization'!
    63 !ModalBox class methodsFor:'initialization'!
    59 
    64 
    60 initialize
    65 initialize
    61     UseTransientViews := false.
    66     UseTransientViews := true.
       
    67 ! !
       
    68 
       
    69 !ModalBox class methodsFor:'defaults'!
       
    70 
       
    71 defaultExtent
       
    72     "this defines the defaultExtent for instances of me;
       
    73      the value returned here is usually not correct for concrete subclasses,
       
    74      so you better redefine this method"
       
    75 
       
    76     ^ (Display pixelPerMillimeter * (60 @ 30)) rounded
       
    77 !
       
    78 
       
    79 useTransientViews:aBoolean 
       
    80     "change the way modalBoxes are created on the Display.
       
    81      If the argument is true, transient views are used; otherwise
       
    82      override redirect views are used. Depending on your windowmanager,
       
    83      either one may have problems. You may want to change the setting
       
    84      from your display.rc or d_xxx.rc file."
       
    85 
       
    86     UseTransientViews := aBoolean.
       
    87 
       
    88     "
       
    89      ModalBox useTransient:false
       
    90      ModalBox useTransient:true 
       
    91     "
    62 ! !
    92 ! !
    63 
    93 
    64 !ModalBox methodsFor:'initialize / release'!
    94 !ModalBox methodsFor:'initialize / release'!
    65 
    95 
    66 initialize
    96 initialize
    67     |form resizeButton|
    97     |form resizeButton moveButton|
    68 
    98 
    69     super initialize.
    99     super initialize.
    70 
   100 
    71     haveControl := false.
       
    72     exclusiveKeyboard := false.
   101     exclusiveKeyboard := false.
    73     label := ' '.
   102     label := ' '.
       
   103 
       
   104     label := 'Popup'.
    74 
   105 
    75     UseTransientViews ifFalse:[
   106     UseTransientViews ifFalse:[
    76 	(StyleSheet at:#popupShadow default:false) ifTrue:[
   107 	(StyleSheet at:#popupShadow default:false) ifTrue:[
    77 	    shadowView := (ShadowView on:device) for:self
   108 	    shadowView := (ShadowView on:device) for:self
    78 	]
   109 	].
    79     ].
   110 
    80 
   111 	form := Form width:8 height:8 
    81     form := Form width:8 height:8 
   112 		     fromArray:#[2r00000000
    82 		 fromArray:#[2r00000000
   113 				 2r00000000 
    83 			     2r00000000 
   114 				 2r00000000 
    84 			     2r00000000 
   115 				 2r00000001
    85 			     2r00000001
   116 				 2r00000011
    86 			     2r00000011
   117 				 2r00000111 
    87 			     2r00000111 
   118 				 2r00001111
    88 			     2r00001111
   119 				 2r00011111 
    89 			     2r00011111 
   120 				]
    90 			    ]
   121 		     on:device.
    91 		 on:device.
   122 	resizeButton := Button form:form in:self.
    92     resizeButton := Button form:form in:self.
   123 	resizeButton origin:1.0 @ 1.0 corner:1.0@1.0.
    93     resizeButton origin:1.0 @ 1.0 corner:1.0@1.0.
   124 	resizeButton activeForegroundColor:(resizeButton foregroundColor).
    94     resizeButton activeForegroundColor:(resizeButton foregroundColor).
   125 	resizeButton activeBackgroundColor:(resizeButton backgroundColor).
    95     resizeButton leftInset:-8; topInset:-8.
   126 	resizeButton enteredBackgroundColor:(resizeButton backgroundColor).
    96     resizeButton releaseAction:[].
   127 	resizeButton leftInset:-8; topInset:-8.
    97     resizeButton pressAction:[resizeButton turnOff; redraw. self doResize].
   128 	resizeButton releaseAction:[].
    98     resizeButton borderWidth:0.
   129 	resizeButton pressAction:[resizeButton turnOff; redraw. self doResize].
    99     resizeButton onLevel:-2; offLevel:0.
   130 	resizeButton borderWidth:0.
   100     resizeButton cursor:(Cursor corner)
   131 	resizeButton onLevel:0; offLevel:0.
       
   132 	resizeButton cursor:(Cursor corner).
       
   133 
       
   134 	form := Form width:8 height:8 
       
   135 		     fromArray:#[2r11111000
       
   136 				 2r11110000 
       
   137 				 2r11100000 
       
   138 				 2r11000000
       
   139 				 2r10000000
       
   140 				 2r00000000 
       
   141 				 2r00000000
       
   142 				 2r00000000 
       
   143 				]
       
   144 		     on:device.
       
   145 	moveButton := Button form:form in:self.
       
   146 	moveButton origin:0.0 @ 0.0 corner:0.0@0.0.
       
   147 	moveButton activeForegroundColor:(moveButton foregroundColor).
       
   148 	moveButton activeBackgroundColor:(moveButton backgroundColor).
       
   149 	moveButton enteredBackgroundColor:(moveButton backgroundColor).
       
   150 	moveButton rightInset:-8; bottomInset:-8.
       
   151 	moveButton releaseAction:[].
       
   152 	moveButton pressAction:[moveButton turnOff; redraw. self doMove].
       
   153 	moveButton borderWidth:0.
       
   154 	moveButton onLevel:0; offLevel:0.
       
   155 	moveButton cursor:(Cursor origin)
       
   156     ].
       
   157 
   101 !
   158 !
   102 
   159 
   103 initEvents
   160 initEvents
       
   161     super initEvents.
   104     self enableEvent:#visibilityChange
   162     self enableEvent:#visibilityChange
   105 !
   163 !
   106 
   164 
   107 initStyle
   165 initStyle
   108     super initStyle.
   166     super initStyle.
   109     ((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
   167     ((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
   110 	borderWidth := 0.
   168 	borderWidth := 0.
   111 	self level:2
   169 	UseTransientViews ifFalse:[
       
   170 	    self level:2
       
   171 	]
   112     ]
   172     ]
   113 !
   173 !
   114 
   174 
   115 reinitialize
   175 reinitialize
   116    super reinitialize.
   176    super reinitialize.
   201     "
   261     "
   202     exclusiveKeyboard ifTrue:[
   262     exclusiveKeyboard ifTrue:[
   203 	device grabKeyboardInView:self.
   263 	device grabKeyboardInView:self.
   204     ].
   264     ].
   205 
   265 
   206     "
   266 "/    UseTransientViews ifFalse:[
   207      get the focus
   267 	"
   208     "
   268 	 get the focus
   209     device setInputFocusTo:drawableId.
   269 	"
   210     self enableEnterLeaveEvents
   270 	self getKeyboardFocus.
       
   271 	self enableEnterLeaveEvents
       
   272 "/    ]
   211 !
   273 !
   212 
   274 
   213 fixPosition:aPoint
   275 fixPosition:aPoint
   214     "set origin to aPoint, but make sure, that the box is fully visible 
   276     "set origin to aPoint, but make sure, that the box is fully visible 
   215      by shifting it into the visible screen area if nescessary.
   277      by shifting it into the visible screen area if nescessary.
   273     ] ifFalse:[
   335     ] ifFalse:[
   274 	shadowView notNil ifTrue:[shadowView realize].
   336 	shadowView notNil ifTrue:[shadowView realize].
   275     ].
   337     ].
   276     self raise.
   338     self raise.
   277 
   339 
   278     haveControl := true.
       
   279     mainGroup notNil ifTrue:[
   340     mainGroup notNil ifTrue:[
   280 	"
   341 	"
   281 	 flush pending key & mouse events.
   342 	 flush pending key & mouse events.
   282 	 this avoids pre-characters 
   343 	 this avoids pre-characters 
   283 	 to be put into the view ...
   344 	 to be put into the view ...
   468     "make the receiver invisible and leave control"
   529     "make the receiver invisible and leave control"
   469 
   530 
   470     |p|
   531     |p|
   471 
   532 
   472     shadowView notNil ifTrue:[shadowView unrealize].
   533     shadowView notNil ifTrue:[shadowView unrealize].
       
   534     windowGroup notNil ifTrue:[windowGroup focusView:nil].
   473     self unrealize.
   535     self unrealize.
   474     device synchronizeOutput. 
   536     device synchronizeOutput. 
   475 
   537 
   476     (windowGroup notNil and:[(p := windowGroup previousGroup) notNil]) ifTrue:[
   538     (windowGroup notNil and:[(p := windowGroup previousGroup) notNil]) ifTrue:[
   477 	"
   539 	"
   511      b autoHideAfter:5 with:[].
   573      b autoHideAfter:5 with:[].
   512      b showAtCenter.
   574      b showAtCenter.
   513     "
   575     "
   514 ! !
   576 ! !
   515 
   577 
   516 !ModalBox methodsFor:'event handling'!
   578 !ModalBox methodsFor:'move & resize'!
   517 
   579 
   518 doResize
   580 doMove
   519     "the resize button was pressed"
   581     "the move button was pressed"
   520 
   582 
   521     |r|
   583     |r|
   522 
   584 
   523     r := device rectangleFromUser:(self origin corner:self corner).
   585     r := device rectangleFromUser:(self origin corner:self corner).
   524     shadowView notNil ifTrue:[
   586     shadowView notNil ifTrue:[
   527     self origin:r origin extent:(r extent max:(100@100)).
   589     self origin:r origin extent:(r extent max:(100@100)).
   528     shadowView notNil ifTrue:[
   590     shadowView notNil ifTrue:[
   529 	shadowView realize.
   591 	shadowView realize.
   530 	self raise
   592 	self raise
   531     ].
   593     ].
       
   594 !
       
   595 
       
   596 doResize
       
   597     "the resize button was pressed"
       
   598 
       
   599     |r|
       
   600 
       
   601     r := device rectangleFromUser:(self origin corner:self corner).
       
   602     shadowView notNil ifTrue:[
       
   603 	shadowView unrealize
       
   604     ].
       
   605     self origin:r origin extent:(r extent max:(100@100)).
       
   606     shadowView notNil ifTrue:[
       
   607 	shadowView realize.
       
   608 	self raise
       
   609     ].
       
   610 ! !
       
   611 
       
   612 !ModalBox methodsFor:'event handling'!
       
   613 
       
   614 terminate
       
   615     "this is the close from a windowmanager
       
   616      (only if UseTransientViews == true)"
       
   617 
       
   618     self hide
   532 !
   619 !
   533 
   620 
   534 visibilityChange:how
   621 visibilityChange:how
   535     "raise when covered - this should not be needed, since we
   622     "raise when covered - this should not be needed, since we
   536      have been created as override-redirect window (which should
   623      have been created as override-redirect window (which should
   537      stay on top - but some window managers (fvwm) seem to ignore
   624      stay on top - but some window managers (fvwm) seem to ignore
   538      this ..."
   625      this ..."
   539 
   626 
   540     "code below is not good, since it will lead to
   627     "the code below is not good, since it will lead to
   541      oscillating raises when two modalBoxes are going to cover
   628      oscillating raises when two modalBoxes are going to cover
   542      each other - see coveredBy:-handling ..."
   629      each other - see coveredBy:-handling ..."
   543 
   630 
   544 "/    how ~~ #fullyVisible ifTrue:[
   631 "/    how ~~ #fullyVisible ifTrue:[
   545 "/        self raise
   632 "/        self raise
   579 	self raise
   666 	self raise
   580     ]
   667     ]
   581 !
   668 !
   582 
   669 
   583 pointerEnter:state x:x y:y
   670 pointerEnter:state x:x y:y
   584     "
   671     "mhmh: this seems to be a special X kludge;
   585      mhmh: this seems to be a special X kludge;
       
   586      without the following, we will not regain input focus after
   672      without the following, we will not regain input focus after
   587      pointer is reentered"
   673      pointer is reentered."
   588 
   674 
   589     device setInputFocusTo:drawableId.
   675     self getKeyboardFocus.
   590     super pointerEnter:state x:x y:y
   676     super pointerEnter:state x:x y:y
   591 ! !
   677 ! !
   592 
   678 
   593 !ModalBox methodsFor:'private'!
   679 !ModalBox methodsFor:'private'!
   594 
   680 
   599 	g := windowGroup mainGroup.
   685 	g := windowGroup mainGroup.
   600 	g notNil ifTrue:[
   686 	g notNil ifTrue:[
   601 	    g restoreCursors
   687 	    g restoreCursors
   602 	]
   688 	]
   603     ].
   689     ].
   604     haveControl := false.
       
   605     exclusiveKeyboard ifTrue:[
   690     exclusiveKeyboard ifTrue:[
   606 	device ungrabKeyboard
   691 	device ungrabKeyboard
   607     ]
   692     ]
   608 ! !
   693 ! !