SimpleView.st
changeset 7618 50ccaeb61be1
parent 7617 3bcc92c94b66
child 7622 c75552e285e5
equal deleted inserted replaced
7617:3bcc92c94b66 7618:50ccaeb61be1
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     4  COPYRIGHT (c) 1989 by Claus Gittinger
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
 11225 
 11227 
 11226     "Created: / 10.12.1995 / 14:06:45 / cg"
 11228     "Created: / 10.12.1995 / 14:06:45 / cg"
 11227     "Modified: / 9.7.1998 / 01:20:57 / cg"
 11229     "Modified: / 9.7.1998 / 01:20:57 / cg"
 11228 !
 11230 !
 11229 
 11231 
 11230 openModal:aBlock inGroup:aWindowGroup
 11232 openModal:aBlock inGroup:activeWindowGroup
 11231     "create a new windowgroup, but start processing in the current process -
 11233     "create a new windowgroup, but start processing in the current process -
 11232      actually suspending event processing for the main group.
 11234      actually suspending event processing for the main group.
 11233      Stay in this modal loop while aBlock evaluates to true AND the receiver is
 11235      Stay in this modal loop while aBlock evaluates to true AND the receiver is
 11234      visible.
 11236      visible.
 11235      (i.e. control is returned to the sender when the receiver is closed)
 11237      (i.e. control is returned to the sender when the receiver is closed)
 11239     |tops mainView previousGroup mainGroup cursorChanged isPopup makeTransient transientFor|
 11241     |tops mainView previousGroup mainGroup cursorChanged isPopup makeTransient transientFor|
 11240 
 11242 
 11241     StandardSystemView cancelAutoRaise.
 11243     StandardSystemView cancelAutoRaise.
 11242 
 11244 
 11243     isPopup := self isPopUpView.
 11245     isPopup := self isPopUpView.
 11244     aWindowGroup notNil ifTrue:[
 11246     activeWindowGroup notNil ifTrue:[
 11245 	mainGroup := aWindowGroup mainGroup.
 11247         mainGroup := activeWindowGroup mainGroup.
 11246 	mainView := mainGroup mainView.
 11248         mainView := mainGroup mainView.
 11247     ].
 11249     ].
 11248 
 11250 
 11249     "/ set the windowgroup BEFORE sending the aboutToOpen notification
 11251     "/ set the windowgroup BEFORE sending the aboutToOpen notification
 11250     "/ (so the handler sees me with a wGroup, sensor etc).
 11252     "/ (so the handler sees me with a wGroup, sensor etc).
 11251     "/ this allows for the handler to enqueue an event,
 11253     "/ this allows for the handler to enqueue an event,
 11252     "/ or to add event hooks.
 11254     "/ or to add event hooks.
 11253     Processor activeProcessIsSystemProcess ifTrue:[
 11255     Processor activeProcessIsSystemProcess ifTrue:[
 11254 	"
 11256         "
 11255 	 put myself into the modal group, let it handle events for
 11257          put myself into the modal group, let it handle events for
 11256 	 me as well. This is only a half way solution, since the view
 11258          me as well. This is only a half way solution, since the view
 11257 	 is not modal at all ... however, the only situation
 11259          is not modal at all ... however, the only situation
 11258 	 where this happens is with modal boxes popped while in a
 11260          where this happens is with modal boxes popped while in a
 11259 	 modal browser. You will forgive me for that inconvenience.
 11261          modal browser. You will forgive me for that inconvenience.
 11260 	"
 11262         "
 11261 	windowGroup := aWindowGroup.
 11263         windowGroup := activeWindowGroup.
 11262 	aWindowGroup notNil ifTrue:[aWindowGroup addTopView:self].
 11264         activeWindowGroup notNil ifTrue:[activeWindowGroup addTopView:self].
 11263     ] ifFalse:[
 11265     ] ifFalse:[
 11264 	previousGroup := WindowGroup activeGroup.
 11266         previousGroup := activeWindowGroup.
 11265     ].
 11267     ].
 11266 
 11268 
 11267     windowGroup isNil ifTrue:[
 11269     windowGroup isNil ifTrue:[
 11268 	"/ create a new window group put myself into it
 11270         "/ create a new window group put myself into it
 11269 	windowGroup := self windowGroupClass new.
 11271         windowGroup := self windowGroupClass new.
 11270 	windowGroup
 11272         windowGroup
 11271 	    addTopView:self;
 11273             addTopView:self;
 11272 	    setPreviousGroup:previousGroup.
 11274             setPreviousGroup:previousGroup.
 11273 
 11275 
 11274 	superView notNil ifTrue:[
 11276         superView notNil ifTrue:[
 11275 	    "/
 11277             "/
 11276 	    "/ special: this is a modal subview,
 11278             "/ special: this is a modal subview,
 11277 	    "/ prevent the view from reassigning its windowGroup when realized
 11279             "/ prevent the view from reassigning its windowGroup when realized
 11278 	    "/ (subviews normally place themself into the superviews group)
 11280             "/ (subviews normally place themself into the superviews group)
 11279 	    "/
 11281             "/
 11280 	    windowGroup isForModalSubview:true.
 11282             windowGroup isForModalSubview:true.
 11281 	].
 11283         ].
 11282     ].
 11284     ].
 11283 
 11285 
 11284     makeTransient := true.
 11286     makeTransient := true.
 11285     transientFor := mainView.
 11287     transientFor := mainView.
 11286     isPopup ifFalse:[
 11288     isPopup ifFalse:[
 11287 	"/ the following allows for knowledgable programmers to suppress dialog boxes,
 11289         "/ the following allows for knowledgable programmers to suppress dialog boxes,
 11288 	"/ or to patch common controls right before opening...
 11290         "/ or to patch common controls right before opening...
 11289 	(Dialog aboutToOpenBoxNotificationSignal raiseRequestWith:self) == #abort ifTrue:[
 11291         (Dialog aboutToOpenBoxNotificationSignal raiseRequestWith:self) == #abort ifTrue:[
 11290 	    ^ self
 11292             ^ self
 11291 	].
 11293         ].
 11292 	windowGroup isNil ifTrue:[
 11294         windowGroup isNil ifTrue:[
 11293 	    "/ the aboutToOpenBoxNotificationSignal handler destroyed me (although it should proceed with #abort)!!
 11295             "/ the aboutToOpenBoxNotificationSignal handler destroyed me (although it should proceed with #abort)!!
 11294 	    "/ Transcript showCR:(self class name,': box opening suppressed by aboutToOpenBoxNotificationSignal handler').
 11296             "/ Transcript showCR:(self class name,': box opening suppressed by aboutToOpenBoxNotificationSignal handler').
 11295 	    ^ self.
 11297             ^ self.
 11296 	].
 11298         ].
 11297 
 11299 
 11298 	"/ the following allows for hooks to add a bell sound or other whenever a dialog opens
 11300         "/ the following allows for hooks to add a bell sound or other whenever a dialog opens
 11299 	device modalWindowListenersDo:[:listener | listener aboutToOpenWindow:self].
 11301         device modalWindowListenersDo:[:listener | listener aboutToOpenWindow:self].
 11300 
 11302 
 11301 	"/ the following raises the corresponding mainview, so the dialog shows above
 11303         "/ the following raises the corresponding mainview, so the dialog shows above
 11302 	"/ any currently covered view. However, be careful if being debugged, or if this dialog
 11304         "/ any currently covered view. However, be careful if being debugged, or if this dialog
 11303 	"/ is opened by an already open dialog.
 11305         "/ is opened by an already open dialog.
 11304 	(mainView isNil or:[mainView windowGroup isInModalLoop]) ifTrue:[
 11306         (mainView isNil or:[mainView windowGroup isInModalLoop]) ifTrue:[
 11305 	    (previousGroup notNil and:[previousGroup isModal]) ifTrue:[
 11307             (previousGroup notNil and:[previousGroup isModal]) ifTrue:[
 11306 		transientFor := previousGroup mainView.
 11308                 transientFor := previousGroup mainView.
 11307 	    ].
 11309             ].
 11308 	].
 11310         ].
 11309 
 11311 
 11310 	transientFor notNil ifTrue:[
 11312         transientFor notNil ifTrue:[
 11311 	    (transientFor windowGroup isInModalLoop
 11313             (transientFor windowGroup isInModalLoop
 11312 		or:[ transientFor windowGroup isDebugged
 11314                 or:[ transientFor windowGroup isDebugged
 11313 		or:[ WindowGroup activeGroup isDebugged
 11315                 or:[ activeWindowGroup isDebugged
 11314 	    ]]) ifFalse:[
 11316             ]]) ifFalse:[
 11315 		self tracePoint:#cg message:'activate'.
 11317                 self tracePoint:#cg message:'activate'.
 11316 		self debuggingCodeFor:#cg is:[ Transcript showCR:transientFor; showCR:transientFor windowGroup. ].
 11318                 self debuggingCodeFor:#cg is:[ Transcript showCR:transientFor; showCR:transientFor windowGroup. ].
 11317 		transientFor activate; setForegroundWindow.
 11319                 transientFor activate; setForegroundWindow.
 11318 "/            ] ifTrue:[
 11320 "/            ] ifTrue:[
 11319 "/                makeTransient := false.
 11321 "/                makeTransient := false.
 11320 	    ]
 11322             ]
 11321 	].
 11323         ].
 11322     ].
 11324     ].
 11323     "/ makeTransient ifTrue:[
 11325     "/ makeTransient ifTrue:[
 11324 	transientFor notNil ifTrue:[
 11326         transientFor notNil ifTrue:[
 11325 	    "set the transient property.
 11327             "set the transient property.
 11326 	     This is currently used for X, to tell the Window Manager
 11328              This is currently used for X, to tell the Window Manager
 11327 	     That this view should be always on top of the mainView"
 11329              That this view should be always on top of the mainView"
 11328 	    self drawableId isNil ifTrue:[self create].
 11330             self drawableId isNil ifTrue:[self create].
 11329 	    device setTransient:self drawableId for:transientFor id.
 11331             device setTransient:self drawableId for:transientFor id.
 11330 	].
 11332         ].
 11331     "/ ].
 11333     "/ ].
 11332 
 11334 
 11333     self raise.
 11335     self raise.
 11334 
 11336 
 11335     Processor activeProcessIsSystemProcess ifTrue:[
 11337     Processor activeProcessIsSystemProcess ifTrue:[
 11336 	self realize
 11338         self realize
 11337     ] ifFalse:[
 11339     ] ifFalse:[
 11338 	"
 11340         "
 11339 	 show a stop-cursor in the suspended window groups
 11341          show a stop-cursor in the suspended window groups
 11340 	"
 11342         "
 11341 	(mainGroup notNil and:[isPopup not]) ifTrue:[
 11343         (mainGroup notNil and:[isPopup not]) ifTrue:[
 11342 	    mainGroup showCursor:(Cursor stop).
 11344             mainGroup showCursor:(Cursor stop).
 11343 	    previousGroup ~~ mainGroup ifTrue:[
 11345             previousGroup ~~ mainGroup ifTrue:[
 11344 		previousGroup showCursor:(Cursor stop).
 11346                 previousGroup showCursor:(Cursor stop).
 11345 	    ].
 11347             ].
 11346 	    cursorChanged := true.
 11348             cursorChanged := true.
 11347 	].
 11349         ].
 11348 
 11350 
 11349 	"
 11351         "
 11350 	 go dispatch events in this new group
 11352          go dispatch events in this new group
 11351 	 (thus current windowgroup is blocked from interaction)
 11353          (thus current windowgroup is blocked from interaction)
 11352 	"
 11354         "
 11353 	AbortOperationRequest handle:[:ex |
 11355         AbortOperationRequest handle:[:ex |
 11354 	    "/ the dialog/popup is aborted - hide it. Care for another abort during the hide.
 11356             "/ the dialog/popup is aborted - hide it. Care for another abort during the hide.
 11355 	    AbortOperationRequest handle:[:ex2 |
 11357             AbortOperationRequest handle:[:ex2 |
 11356 		"/ an aborted hide (possibly due to a cancelled user confirmation or similar)
 11358                 "/ an aborted hide (possibly due to a cancelled user confirmation or similar)
 11357 		self breakPoint:#cg.
 11359                 self breakPoint:#cg.
 11358 		ex exit.
 11360                 ex exit.
 11359 	    ] do:[
 11361             ] do:[
 11360 		self hide.
 11362                 self hide.
 11361 		realized ifTrue:[
 11363                 realized ifTrue:[
 11362 		    "/ self halt. "/ hide handled and closeRequest not wanted:
 11364                     "/ self halt. "/ hide handled and closeRequest not wanted:
 11363 		    ex exit.
 11365                     ex exit.
 11364 		].
 11366                 ].
 11365 	    ].
 11367             ].
 11366 	] do:[
 11368         ] do:[
 11367 	    [
 11369             [
 11368 		[
 11370                 [
 11369 		    windowGroup startupModal:[realized and:aBlock] forGroup:aWindowGroup
 11371                     windowGroup startupModal:[realized and:aBlock] forGroup:activeWindowGroup
 11370 		] ifCurtailed:[
 11372                 ] ifCurtailed:[
 11371 		    self hide.
 11373                     self hide.
 11372 		]
 11374                 ]
 11373 	    ] ensure:[
 11375             ] ensure:[
 11374 		aWindowGroup notNil ifTrue:[
 11376                 activeWindowGroup notNil ifTrue:[
 11375 		    aWindowGroup graphicsDevice sync.  "that's a round trip - make sure that all drawing has been processed"
 11377                     activeWindowGroup graphicsDevice sync.  "that's a round trip - make sure that all drawing has been processed"
 11376 		    "/ ensure that eventListener runs here ...
 11378                     "/ ensure that eventListener runs here ...
 11377 		    Delay waitForMilliseconds:50.
 11379                     Delay waitForMilliseconds:50.
 11378 		    aWindowGroup processExposeEvents.
 11380                     activeWindowGroup processExposeEvents.
 11379 
 11381 
 11380 		    (self isPopUpView or:[ReturnFocusWhenClosingModalBoxes]) ifTrue:[
 11382                     (self isPopUpView or:[ReturnFocusWhenClosingModalBoxes]) ifTrue:[
 11381 			"
 11383                         "
 11382 			 return the input focus to the previously active group's top.
 11384                          return the input focus to the previously active group's top.
 11383 			 This helps with window managers which need an explicit click
 11385                          This helps with window managers which need an explicit click
 11384 			 on the view for the focus.
 11386                          on the view for the focus.
 11385 			 Only do this, if the previous group is still having the focus.
 11387                          Only do this, if the previous group is still having the focus.
 11386 			 (i.e. no other view was opened in the meantime)
 11388                          (i.e. no other view was opened in the meantime)
 11387 			"
 11389                         "
 11388 			aWindowGroup graphicsDevice focusView isNil ifTrue:[
 11390                         activeWindowGroup graphicsDevice focusView isNil ifTrue:[
 11389 			    tops := aWindowGroup topViews.
 11391                             tops := activeWindowGroup topViews.
 11390 			    (tops notEmptyOrNil) ifTrue:[
 11392                             (tops notEmptyOrNil) ifTrue:[
 11391 				tops first getKeyboardFocus
 11393                                 tops first getKeyboardFocus
 11392 			    ].
 11394                             ].
 11393 			].
 11395                         ].
 11394 		    ].
 11396                     ].
 11395 
 11397 
 11396 		    "
 11398                     "
 11397 		     restore cursors in the changed groups
 11399                      restore cursors in the changed groups
 11398 		    "
 11400                     "
 11399 		    cursorChanged notNil ifTrue:[
 11401                     cursorChanged notNil ifTrue:[
 11400 			mainGroup restoreCursors.
 11402                         mainGroup restoreCursors.
 11401 			previousGroup ~~ mainGroup ifTrue:[
 11403                         previousGroup ~~ mainGroup ifTrue:[
 11402 			    previousGroup restoreCursors.
 11404                             previousGroup restoreCursors.
 11403 			].
 11405                         ].
 11404 		    ].
 11406                     ].
 11405 		].
 11407                 ].
 11406 		Dialog boxClosedNotificationSignal raiseRequestWith:self.
 11408                 Dialog boxClosedNotificationSignal raiseRequestWith:self.
 11407 	    ]
 11409             ]
 11408 	].
 11410         ].
 11409     ]
 11411     ]
 11410 
 11412 
 11411     "Created: / 10-12-1995 / 14:06:14 / cg"
 11413     "Created: / 10-12-1995 / 14:06:14 / cg"
 11412     "Modified: / 29-08-2013 / 16:17:10 / cg"
 11414     "Modified: / 29-08-2013 / 16:17:10 / cg"
 11413 !
 11415 !