ModalBox.st
changeset 89 ea2bf46eb669
parent 86 032006651226
child 113 60981f3775c6
--- a/ModalBox.st	Mon Feb 06 01:30:10 1995 +0100
+++ b/ModalBox.st	Mon Feb 06 01:38:04 1995 +0100
@@ -11,7 +11,7 @@
 "
 
 StandardSystemView subclass:#ModalBox
-       instanceVariableNames:'haveControl shadowView exclusiveKeyboard '
+       instanceVariableNames:'shadowView exclusiveKeyboard '
        classVariableNames:'UseTransientViews'
        poolDictionaries:''
        category:'Views-Basic'
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1990 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.15 1994-11-28 21:01:03 claus Exp $
+$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.16 1995-02-06 00:37:31 claus Exp $
 '!
 
 !ModalBox class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.15 1994-11-28 21:01:03 claus Exp $
+$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.16 1995-02-06 00:37:31 claus Exp $
 "
 !
 
@@ -52,55 +52,113 @@
     others, in that they take control over the current topview, until 
     all processing is done (i.e. the currently active topview and all of
     its subviews will not handle user events while the box is active).
+
+    ModalBoxes are either implemented as transient windows
+    (if UseTransientViews := true) or as override redirect views.
+    Some window managers have problems with either; so you may want to
+    change the default setting from your display.rc file.
 "
 ! !
 
 !ModalBox class methodsFor:'initialization'!
 
 initialize
-    UseTransientViews := false.
+    UseTransientViews := true.
+! !
+
+!ModalBox class methodsFor:'defaults'!
+
+defaultExtent
+    "this defines the defaultExtent for instances of me;
+     the value returned here is usually not correct for concrete subclasses,
+     so you better redefine this method"
+
+    ^ (Display pixelPerMillimeter * (60 @ 30)) rounded
+!
+
+useTransientViews:aBoolean 
+    "change the way modalBoxes are created on the Display.
+     If the argument is true, transient views are used; otherwise
+     override redirect views are used. Depending on your windowmanager,
+     either one may have problems. You may want to change the setting
+     from your display.rc or d_xxx.rc file."
+
+    UseTransientViews := aBoolean.
+
+    "
+     ModalBox useTransient:false
+     ModalBox useTransient:true 
+    "
 ! !
 
 !ModalBox methodsFor:'initialize / release'!
 
 initialize
-    |form resizeButton|
+    |form resizeButton moveButton|
 
     super initialize.
 
-    haveControl := false.
     exclusiveKeyboard := false.
     label := ' '.
 
+    label := 'Popup'.
+
     UseTransientViews ifFalse:[
 	(StyleSheet at:#popupShadow default:false) ifTrue:[
 	    shadowView := (ShadowView on:device) for:self
-	]
+	].
+
+	form := Form width:8 height:8 
+		     fromArray:#[2r00000000
+				 2r00000000 
+				 2r00000000 
+				 2r00000001
+				 2r00000011
+				 2r00000111 
+				 2r00001111
+				 2r00011111 
+				]
+		     on:device.
+	resizeButton := Button form:form in:self.
+	resizeButton origin:1.0 @ 1.0 corner:1.0@1.0.
+	resizeButton activeForegroundColor:(resizeButton foregroundColor).
+	resizeButton activeBackgroundColor:(resizeButton backgroundColor).
+	resizeButton enteredBackgroundColor:(resizeButton backgroundColor).
+	resizeButton leftInset:-8; topInset:-8.
+	resizeButton releaseAction:[].
+	resizeButton pressAction:[resizeButton turnOff; redraw. self doResize].
+	resizeButton borderWidth:0.
+	resizeButton onLevel:0; offLevel:0.
+	resizeButton cursor:(Cursor corner).
+
+	form := Form width:8 height:8 
+		     fromArray:#[2r11111000
+				 2r11110000 
+				 2r11100000 
+				 2r11000000
+				 2r10000000
+				 2r00000000 
+				 2r00000000
+				 2r00000000 
+				]
+		     on:device.
+	moveButton := Button form:form in:self.
+	moveButton origin:0.0 @ 0.0 corner:0.0@0.0.
+	moveButton activeForegroundColor:(moveButton foregroundColor).
+	moveButton activeBackgroundColor:(moveButton backgroundColor).
+	moveButton enteredBackgroundColor:(moveButton backgroundColor).
+	moveButton rightInset:-8; bottomInset:-8.
+	moveButton releaseAction:[].
+	moveButton pressAction:[moveButton turnOff; redraw. self doMove].
+	moveButton borderWidth:0.
+	moveButton onLevel:0; offLevel:0.
+	moveButton cursor:(Cursor origin)
     ].
 
-    form := Form width:8 height:8 
-		 fromArray:#[2r00000000
-			     2r00000000 
-			     2r00000000 
-			     2r00000001
-			     2r00000011
-			     2r00000111 
-			     2r00001111
-			     2r00011111 
-			    ]
-		 on:device.
-    resizeButton := Button form:form in:self.
-    resizeButton origin:1.0 @ 1.0 corner:1.0@1.0.
-    resizeButton activeForegroundColor:(resizeButton foregroundColor).
-    resizeButton leftInset:-8; topInset:-8.
-    resizeButton releaseAction:[].
-    resizeButton pressAction:[resizeButton turnOff; redraw. self doResize].
-    resizeButton borderWidth:0.
-    resizeButton onLevel:-2; offLevel:0.
-    resizeButton cursor:(Cursor corner)
 !
 
 initEvents
+    super initEvents.
     self enableEvent:#visibilityChange
 !
 
@@ -108,7 +166,9 @@
     super initStyle.
     ((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
 	borderWidth := 0.
-	self level:2
+	UseTransientViews ifFalse:[
+	    self level:2
+	]
     ]
 !
 
@@ -203,11 +263,13 @@
 	device grabKeyboardInView:self.
     ].
 
-    "
-     get the focus
-    "
-    device setInputFocusTo:drawableId.
-    self enableEnterLeaveEvents
+"/    UseTransientViews ifFalse:[
+	"
+	 get the focus
+	"
+	self getKeyboardFocus.
+	self enableEnterLeaveEvents
+"/    ]
 !
 
 fixPosition:aPoint
@@ -275,7 +337,6 @@
     ].
     self raise.
 
-    haveControl := true.
     mainGroup notNil ifTrue:[
 	"
 	 flush pending key & mouse events.
@@ -470,6 +531,7 @@
     |p|
 
     shadowView notNil ifTrue:[shadowView unrealize].
+    windowGroup notNil ifTrue:[windowGroup focusView:nil].
     self unrealize.
     device synchronizeOutput. 
 
@@ -513,7 +575,23 @@
     "
 ! !
 
-!ModalBox methodsFor:'event handling'!
+!ModalBox methodsFor:'move & resize'!
+
+doMove
+    "the move button was pressed"
+
+    |r|
+
+    r := device rectangleFromUser:(self origin corner:self corner).
+    shadowView notNil ifTrue:[
+	shadowView unrealize
+    ].
+    self origin:r origin extent:(r extent max:(100@100)).
+    shadowView notNil ifTrue:[
+	shadowView realize.
+	self raise
+    ].
+!
 
 doResize
     "the resize button was pressed"
@@ -529,6 +607,15 @@
 	shadowView realize.
 	self raise
     ].
+! !
+
+!ModalBox methodsFor:'event handling'!
+
+terminate
+    "this is the close from a windowmanager
+     (only if UseTransientViews == true)"
+
+    self hide
 !
 
 visibilityChange:how
@@ -537,7 +624,7 @@
      stay on top - but some window managers (fvwm) seem to ignore
      this ..."
 
-    "code below is not good, since it will lead to
+    "the code below is not good, since it will lead to
      oscillating raises when two modalBoxes are going to cover
      each other - see coveredBy:-handling ..."
 
@@ -581,12 +668,11 @@
 !
 
 pointerEnter:state x:x y:y
-    "
-     mhmh: this seems to be a special X kludge;
+    "mhmh: this seems to be a special X kludge;
      without the following, we will not regain input focus after
-     pointer is reentered"
+     pointer is reentered."
 
-    device setInputFocusTo:drawableId.
+    self getKeyboardFocus.
     super pointerEnter:state x:x y:y
 ! !
 
@@ -601,7 +687,6 @@
 	    g restoreCursors
 	]
     ].
-    haveControl := false.
     exclusiveKeyboard ifTrue:[
 	device ungrabKeyboard
     ]