DeviceWorkstation.st
changeset 3091 707f8b9fda46
parent 3078 9ee450338884
child 3100 0997eb19c9a4
equal deleted inserted replaced
3090:a051f6c87eba 3091:707f8b9fda46
  4606      with id aWindowId. Return true if ok, false if it failed for some reason."
  4606      with id aWindowId. Return true if ok, false if it failed for some reason."
  4607 
  4607 
  4608     ^ self grabPointerIn:aWindowId withCursor:nil pointerMode:#async keyboardMode:#sync confineTo:nil
  4608     ^ self grabPointerIn:aWindowId withCursor:nil pointerMode:#async keyboardMode:#sync confineTo:nil
  4609 !
  4609 !
  4610 
  4610 
  4611 grabPointerIn:aWindowId withCursor:aCursorIdOrNil
       
  4612     "grap the pointer; all pointer events will be reported to the view
       
  4613      with id aWindowId. Return true if ok, false if it failed for some reason."
       
  4614 
       
  4615     ^ self grabPointerIn:aWindowId withCursor:aCursorIdOrNil pointerMode:#async keyboardMode:#sync confineTo:nil
       
  4616 !
       
  4617 
       
  4618 grabPointerIn:aWindowId withCursor:cursorId pointerMode:pMode keyboardMode:kMode confineTo:confineId
  4611 grabPointerIn:aWindowId withCursor:cursorId pointerMode:pMode keyboardMode:kMode confineTo:confineId
  4619     "grap the pointer - all pointer events will be reported to aWindowId. The cursor will be set to cursorId
  4612     "grap the pointer - all pointer events will be reported to aWindowId. The cursor will be set to cursorId
  4620      for the duration of the grab. For pMode/kMode, see X documentation. The pointer is restricted to
  4613      for the duration of the grab. For pMode/kMode, see X documentation. The pointer is restricted to
  4621      confineId - if non-nil."
  4614      confineId - if non-nil."
  4622 
  4615 
  4623     ^ self subclassResponsibility
  4616     ^ self subclassResponsibility
  4624 !
  4617 !
  4625 
  4618 
       
  4619 grabPointerIn:aWindowId withCursorId:aCursorIdOrNil
       
  4620     "grap the pointer; all pointer events will be reported to the view
       
  4621      with id aWindowId. Return true if ok, false if it failed for some reason."
       
  4622 
       
  4623     ^ self grabPointerIn:aWindowId withCursor:aCursorIdOrNil pointerMode:#async keyboardMode:#sync confineTo:nil
       
  4624 !
       
  4625 
  4626 grabPointerInView:aView
  4626 grabPointerInView:aView
  4627     "grap the pointer; all pointer events will be reported to
  4627     "grap the pointer; all pointer events will be reported to
  4628      aView. Return true if ok, false if it failed for some reason."
  4628      aView. Return true if ok, false if it failed for some reason."
  4629 
  4629 
  4630     activePointerGrab notNil ifTrue:[
  4630     activePointerGrab notNil ifTrue:[
  4632 	activePointerGrab := nil
  4632 	activePointerGrab := nil
  4633     ].
  4633     ].
  4634     (self grabPointerIn:(aView id)) ifTrue:[
  4634     (self grabPointerIn:(aView id)) ifTrue:[
  4635 	activePointerGrab := aView.
  4635 	activePointerGrab := aView.
  4636 	^ true
  4636 	^ true
       
  4637     ].
       
  4638     ^ false
       
  4639 !
       
  4640 
       
  4641 grabPointerInView:aView withCursor:aCursor
       
  4642     "grap the pointer; all pointer events will be reported to
       
  4643      aView. Return true if ok, false if it failed for some reason."
       
  4644 
       
  4645     |cId|
       
  4646 
       
  4647     activePointerGrab notNil ifTrue:[
       
  4648         self ungrabPointer.
       
  4649         activePointerGrab := nil
       
  4650     ].
       
  4651     aCursor notNil ifTrue:[
       
  4652         cId := aCursor id.
       
  4653     ].
       
  4654     (self grabPointerIn:(aView id) withCursorId:cId) ifTrue:[
       
  4655         activePointerGrab := aView.
       
  4656         ^ true
  4637     ].
  4657     ].
  4638     ^ false
  4658     ^ false
  4639 !
  4659 !
  4640 
  4660 
  4641 setActivePointerGrab:aView
  4661 setActivePointerGrab:aView
  5085 
  5105 
  5086     "let user specify a rectangles origin on the screen, return the rectangle.
  5106     "let user specify a rectangles origin on the screen, return the rectangle.
  5087      Start with initialRectangle. 
  5107      Start with initialRectangle. 
  5088      Can be used for dragging operations."
  5108      Can be used for dragging operations."
  5089 
  5109 
  5090     |curs origin root rect|
  5110     |curs origin root rect prevGrab|
  5091 
  5111 
  5092     curs := Cursor origin onDevice:self.
  5112     curs := Cursor origin onDevice:self.
  5093 
  5113 
  5094     "
  5114     "
  5095      just in case; wait for button to be down ...
  5115      just in case; wait for button to be down ...
  5105 
  5125 
  5106     root clippedByChildren:false.
  5126     root clippedByChildren:false.
  5107     root foreground:blackColor background:whiteColor.
  5127     root foreground:blackColor background:whiteColor.
  5108 
  5128 
  5109     root xoring:[
  5129     root xoring:[
  5110 	|left right top bottom newOrigin newCorner p|
  5130         |left right top bottom newOrigin newCorner p|
  5111 
  5131 
  5112 	rect := origin extent:extent.
  5132         rect := origin extent:extent.
  5113 	root displayRectangle:rect.
  5133         root displayRectangle:rect.
  5114 
  5134 
  5115 	self 
  5135         prevGrab := activePointerGrab.
  5116 	    grabPointerIn:root id 
  5136         self grabPointerInView:root withCursor:curs.
  5117 	    withCursor:curs id
  5137 
  5118 	    pointerMode:#async 
  5138         [self leftButtonPressed] whileTrue:[
  5119 	    keyboardMode:#sync 
  5139             newOrigin := self pointerPosition.
  5120 	    confineTo:nil.
  5140 
  5121 
  5141             (newOrigin ~= origin) ifTrue:[
  5122 	[self leftButtonPressed] whileTrue:[
  5142                 root displayRectangle:rect.
  5123 	    newOrigin := self pointerPosition.
  5143 
  5124 
  5144                 self 
  5125 	    (newOrigin ~= origin) ifTrue:[
  5145                     grabPointerIn:root id 
  5126 		root displayRectangle:rect.
  5146                     withCursor:curs id
  5127 
  5147                     pointerMode:#async 
  5128 		self 
  5148                     keyboardMode:#sync 
  5129 		    grabPointerIn:root id 
  5149                     confineTo:nil.
  5130 		    withCursor:curs id
  5150 
  5131 		    pointerMode:#async 
  5151                 rect := newOrigin extent:extent.
  5132 		    keyboardMode:#sync 
  5152                 root displayRectangle:rect.
  5133 		    confineTo:nil.
  5153                 self disposeButtonEventsFor:nil.
  5134 
  5154                 self flush.
  5135 		rect := newOrigin extent:extent.
  5155                 origin := newOrigin.
  5136 		root displayRectangle:rect.
  5156             ] ifFalse:[
  5137 		self disposeButtonEventsFor:nil.
  5157                 Delay waitForSeconds:0.05
  5138 		self flush.
  5158             ]
  5139 		origin := newOrigin.
  5159         ].
  5140 	    ] ifFalse:[
  5160         root displayRectangle:rect.
  5141 		Delay waitForSeconds:0.05
       
  5142 	    ]
       
  5143 	].
       
  5144 	root displayRectangle:rect.
       
  5145 	self ungrabPointer.
       
  5146     ].
  5161     ].
  5147 
  5162 
  5148     self ungrabPointer.
  5163     self ungrabPointer.
       
  5164     prevGrab notNil ifTrue:[
       
  5165         self grabPointerInView:prevGrab.
       
  5166     ].
  5149 
  5167 
  5150     "flush all events pending on my display"
  5168     "flush all events pending on my display"
  5151 
  5169 
  5152     root clippedByChildren:true.
  5170     root clippedByChildren:true.
  5153 
  5171 
  5181     "{ Pragma: +optSpace }"
  5199     "{ Pragma: +optSpace }"
  5182 
  5200 
  5183     "let user specify a point on the screen (by pressing leftButton).
  5201     "let user specify a point on the screen (by pressing leftButton).
  5184      Show aCursor while waiting."
  5202      Show aCursor while waiting."
  5185 
  5203 
  5186     |p|
  5204     |p prevGrab|
  5187 
  5205 
       
  5206     prevGrab := activePointerGrab.
  5188     self ungrabPointer.
  5207     self ungrabPointer.
  5189     self grabPointerIn:(self rootWindowId) withCursor:((aCursor onDevice:self) id)
  5208     self grabPointerInView:(self rootView) withCursor:(aCursor onDevice:self).
  5190 	 pointerMode:#async keyboardMode:#sync confineTo:nil.
       
  5191     activePointerGrab := rootView.
       
  5192 
       
  5193     "
  5209     "
  5194      wait for leftButton ...
  5210      wait for leftButton ...
  5195     "
  5211     "
  5196     [self leftButtonPressed] whileFalse:[Delay waitForSeconds:0.05].
  5212     [self leftButtonPressed] whileFalse:[Delay waitForSeconds:0.05].
  5197 
  5213 
  5198     p := self pointerPosition.
  5214     p := self pointerPosition.
  5199 
  5215 
  5200     self ungrabPointer.
  5216     self ungrabPointer.
       
  5217     prevGrab notNil ifTrue:[
       
  5218         self grabPointerInView:prevGrab
       
  5219     ].
  5201 
  5220 
  5202     "flush all events pending on myself"
  5221     "flush all events pending on myself"
  5203     self disposeButtonEventsFor:nil.
  5222     self disposeButtonEventsFor:nil.
  5204     ^ p
  5223     ^ p
  5205 
  5224 
  5258 
  5277 
  5259     "let user specify a rectangle on the screen, return the rectangle.
  5278     "let user specify a rectangle on the screen, return the rectangle.
  5260      Start with initialRectangle. 
  5279      Start with initialRectangle. 
  5261      A helper for rectangleFromUser; can also be used for resizing operations."
  5280      A helper for rectangleFromUser; can also be used for resizing operations."
  5262 
  5281 
  5263     |curs1 origin corner root rect doRegrab|
  5282     |curs1 origin corner root rect doRegrab prevGrab|
  5264 
  5283 
  5265     "/ regrabbing leads to horrible flicker and
  5284     "/ regrabbing leads to horrible flicker and
  5266     "/ events being sent to applications under the mouse.
  5285     "/ events being sent to applications under the mouse.
  5267     "/ on windows displays.
  5286     "/ on windows displays.
  5268     doRegrab := self class ~~ WinWorkstation.
  5287     doRegrab := self class ~~ WinWorkstation.
  5269 
  5288 
  5270     keepExtent ifTrue:[
  5289     keepExtent ifTrue:[
  5271 	curs1 := Cursor origin 
  5290         curs1 := Cursor origin 
  5272     ] ifFalse:[    
  5291     ] ifFalse:[    
  5273 	curs1 := Cursor corner
  5292         curs1 := Cursor corner
  5274     ].
  5293     ].
  5275     curs1 := curs1 onDevice:self.
  5294     curs1 := curs1 onDevice:self.
  5276     root := self rootView.
  5295     root := self rootView.
  5277 
  5296 
  5278     "
  5297     "
  5282 
  5301 
  5283     root clippedByChildren:false.
  5302     root clippedByChildren:false.
  5284     root foreground:blackColor background:whiteColor.
  5303     root foreground:blackColor background:whiteColor.
  5285 
  5304 
  5286     root xoring:[
  5305     root xoring:[
  5287 	|left right top bottom newOrigin newCorner p curs|
  5306         |left right top bottom newOrigin newCorner p curs|
  5288 
  5307 
  5289 	keepExtent ifFalse:[
  5308         keepExtent ifFalse:[
  5290 	    corner := origin.
  5309             corner := origin.
  5291 	    rect := origin corner:corner.
  5310             rect := origin corner:corner.
  5292 	    root displayRectangle:rect.
  5311             root displayRectangle:rect.
  5293 	].
  5312         ].
  5294 
  5313 
  5295 	self 
  5314         prevGrab := activePointerGrab.
  5296 	    grabPointerIn:root id 
  5315         self grabPointerInView:root withCursor:curs1.
  5297 	    withCursor:curs1 id
  5316 
  5298 	    pointerMode:#async 
  5317         "
  5299 	    keyboardMode:#sync 
  5318          just in case; wait for button to be down ...
  5300 	    confineTo:nil.
  5319         "
  5301 
  5320         [self leftButtonPressed] whileFalse:[Delay waitForSeconds:0.05].
  5302 	"
  5321 
  5303 	 just in case; wait for button to be down ...
  5322         keepExtent ifTrue:[
  5304 	"
  5323             p := self pointerPosition.
  5305 	[self leftButtonPressed] whileFalse:[Delay waitForSeconds:0.05].
  5324             origin := p.
  5306 
  5325             corner := origin + initialRectangle extent.
  5307 	keepExtent ifTrue:[
  5326             rect := origin corner:corner.
  5308 	    p := self pointerPosition.
  5327             root displayRectangle:rect.
  5309 	    origin := p.
  5328         ].
  5310 	    corner := origin + initialRectangle extent.
  5329 
  5311 	    rect := origin corner:corner.
  5330         [self leftButtonPressed] whileTrue:[
  5312 	    root displayRectangle:rect.
  5331             left := initialRectangle origin x.
  5313 	].
  5332             top := initialRectangle origin y.
  5314 
  5333             right := initialRectangle corner x.
  5315 	[self leftButtonPressed] whileTrue:[
  5334             bottom := initialRectangle corner y.
  5316 	    left := initialRectangle origin x.
  5335 
  5317 	    top := initialRectangle origin y.
  5336             p := self pointerPosition.
  5318 	    right := initialRectangle corner x.
  5337             keepExtent ifTrue:[
  5319 	    bottom := initialRectangle corner y.
  5338                 newOrigin := p.
  5320 
  5339                 newCorner := newOrigin + initialRectangle extent.
  5321 	    p := self pointerPosition.
  5340                 curs := curs1.
  5322 	    keepExtent ifTrue:[
  5341             ] ifFalse:[
  5323 		newOrigin := p.
  5342                 p x < initialRectangle left ifTrue:[
  5324 		newCorner := newOrigin + initialRectangle extent.
  5343                     p y < initialRectangle top ifTrue:[
  5325 		curs := curs1.
  5344                         curs := Cursor topLeft.
  5326 	    ] ifFalse:[
  5345                         left := p x.
  5327 		p x < initialRectangle left ifTrue:[
  5346                         top := p y.
  5328 		    p y < initialRectangle top ifTrue:[
  5347                     ] ifFalse:[
  5329 			curs := Cursor topLeft.
  5348                         curs := Cursor bottomLeft.
  5330 			left := p x.
  5349                         left := p x.
  5331 			top := p y.
  5350                         bottom := p y
  5332 		    ] ifFalse:[
  5351                     ]
  5333 			curs := Cursor bottomLeft.
  5352                 ] ifFalse:[
  5334 			left := p x.
  5353                     p y < initialRectangle top ifTrue:[
  5335 			bottom := p y
  5354                         curs := Cursor topRight.
  5336 		    ]
  5355                         right := p x.
  5337 		] ifFalse:[
  5356                         top := p y
  5338 		    p y < initialRectangle top ifTrue:[
  5357                     ] ifFalse:[
  5339 			curs := Cursor topRight.
  5358                         curs := Cursor bottomRight.
  5340 			right := p x.
  5359                         right := p x.
  5341 			top := p y
  5360                         bottom := p y
  5342 		    ] ifFalse:[
  5361                     ]
  5343 			curs := Cursor bottomRight.
  5362                 ].
  5344 			right := p x.
  5363 
  5345 			bottom := p y
  5364                 newOrigin := left @ top.
  5346 		    ]
  5365                 newCorner := right @ bottom.
  5347 		].
  5366             ].
  5348 
  5367 
  5349 		newOrigin := left @ top.
  5368             ((newOrigin ~= origin) or:[newCorner ~= corner]) ifTrue:[
  5350 		newCorner := right @ bottom.
  5369                 root displayRectangle:rect.
  5351 	    ].
  5370                 doRegrab ifTrue:[
  5352 
  5371                     self grabPointerInView:root withCursor:curs1.
  5353 	    ((newOrigin ~= origin) or:[newCorner ~= corner]) ifTrue:[
  5372                 ].
  5354 		root displayRectangle:rect.
  5373 
  5355 		doRegrab ifTrue:[
  5374                 origin :=  newOrigin.
  5356 		    self grabPointerIn:root id 
  5375                 corner :=  newCorner.
  5357 			    withCursor:curs id
  5376                 rect := origin corner:corner.
  5358 			   pointerMode:#async 
  5377                 root displayRectangle:rect.
  5359 			  keyboardMode:#sync 
  5378                 self disposeButtonEventsFor:nil.
  5360 			     confineTo:nil.
  5379                 self flush.
  5361 		].
  5380             ] ifFalse:[
  5362 
  5381                 Delay waitForSeconds:0.05
  5363 		origin :=  newOrigin.
  5382             ]
  5364 		corner :=  newCorner.
  5383         ].
  5365 		rect := origin corner:corner.
  5384         root displayRectangle:rect.
  5366 		root displayRectangle:rect.
  5385     ].
  5367 		self disposeButtonEventsFor:nil.
  5386 
  5368 		self flush.
       
  5369 	    ] ifFalse:[
       
  5370 		Delay waitForSeconds:0.05
       
  5371 	    ]
       
  5372 	].
       
  5373 	root displayRectangle:rect.
       
  5374 	self ungrabPointer.
       
  5375     ].
       
  5376 
  5387 
  5377     self ungrabPointer.
  5388     self ungrabPointer.
       
  5389     prevGrab notNil ifTrue:[
       
  5390         self grabPointerInView:prevGrab
       
  5391     ].
  5378 
  5392 
  5379     "flush all events pending on my display"
  5393     "flush all events pending on my display"
  5380 
  5394 
  5381     root clippedByChildren:true.
  5395     root clippedByChildren:true.
  5382 
  5396 
  6821 ! !
  6835 ! !
  6822 
  6836 
  6823 !DeviceWorkstation class methodsFor:'documentation'!
  6837 !DeviceWorkstation class methodsFor:'documentation'!
  6824 
  6838 
  6825 version
  6839 version
  6826     ^ '$Header: /cvs/stx/stx/libview/DeviceWorkstation.st,v 1.353 1999-12-03 16:19:02 ps Exp $'
  6840     ^ '$Header: /cvs/stx/stx/libview/DeviceWorkstation.st,v 1.354 1999-12-08 20:46:22 ca Exp $'
  6827 ! !
  6841 ! !
  6828 DeviceWorkstation initialize!
  6842 DeviceWorkstation initialize!