DisplaySurface.st
changeset 5320 a222d6215ff0
parent 5208 004c601d0bc6
child 5344 2c3f14c132be
equal deleted inserted replaced
5319:da10fd2cd945 5320:a222d6215ff0
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 "{ Package: 'stx:libview' }"
    12 "{ Package: 'stx:libview' }"
    13 
    13 
    14 GraphicsMedium subclass:#DisplaySurface
    14 GraphicsMedium subclass:#DisplaySurface
    15 	instanceVariableNames:'viewBackground cursor eventMask moreAttributes unused1 uuid
    15 	instanceVariableNames:'viewBackground cursor eventMask moreAttributes renderer uuid
    16 		backed flags delegate updateRegion'
    16 		backed flags delegate updateRegion'
    17 	classVariableNames:'SaveUnderFlagMask GotExposeFlagMask'
    17 	classVariableNames:'SaveUnderFlagMask GotExposeFlagMask'
    18 	poolDictionaries:''
    18 	poolDictionaries:''
    19 	category:'Graphics-Support'
    19 	category:'Graphics-Support'
    20 !
    20 !
  1377      eventReceiver controller deviceMessage
  1377      eventReceiver controller deviceMessage
  1378      isKeyEvent isButtonEvent isMouseWheelEvent isPointerEvent
  1378      isKeyEvent isButtonEvent isMouseWheelEvent isPointerEvent
  1379      rect x y w h delegatedEvent rgn|
  1379      rect x y w h delegatedEvent rgn|
  1380 
  1380 
  1381     type == #damage ifTrue:[
  1381     type == #damage ifTrue:[
  1382         "/ OLDdamage scheme - this will vanish
  1382 	"/ OLDdamage scheme - this will vanish
  1383         self shown ifTrue:[
  1383 	self shown ifTrue:[
  1384             rect := argArray.
  1384 	    rect := argArray.
  1385             x := rect left.
  1385 	    x := rect left.
  1386             y := rect top.
  1386 	    y := rect top.
  1387             w := rect width.
  1387 	    w := rect width.
  1388             h := rect height.
  1388 	    h := rect height.
  1389             transformation notNil ifTrue:[
  1389 	    transformation notNil ifTrue:[
  1390                 self deviceExposeX:x y:y width:w height:h
  1390 		self deviceExposeX:x y:y width:w height:h
  1391             ] ifFalse:[
  1391 	    ] ifFalse:[
  1392                 self exposeX:x y:y width:w height:h
  1392 		self exposeX:x y:y width:w height:h
  1393             ]
  1393 	    ]
  1394         ].
  1394 	].
  1395         ^ self
  1395 	^ self
  1396     ].
  1396     ].
  1397 
  1397 
  1398     type == #newDamage ifTrue:[
  1398     type == #newDamage ifTrue:[
  1399         "/ New damage scheme
  1399 	"/ New damage scheme
  1400         rgn := updateRegion.
  1400 	rgn := updateRegion.
  1401         updateRegion := nil.
  1401 	updateRegion := nil.
  1402         self shown ifTrue:[
  1402 	self shown ifTrue:[
  1403             rgn notNil ifTrue:[
  1403 	    rgn notNil ifTrue:[
  1404                 rgn do:[:rect |
  1404 		rgn do:[:rect |
  1405                     "/ cg: I think the check for being realized may not be enough;
  1405 		    "/ cg: I think the check for being realized may not be enough;
  1406                     "/ there is a race here, if the view gets closed, while in the loop...
  1406 		    "/ there is a race here, if the view gets closed, while in the loop...
  1407                     realized ifTrue:[
  1407 		    realized ifTrue:[
  1408                         x := rect left.
  1408 			x := rect left.
  1409                         y := rect top.
  1409 			y := rect top.
  1410                         w := rect width.
  1410 			w := rect width.
  1411                         h := rect height.
  1411 			h := rect height.
  1412                         transformation notNil ifTrue:[
  1412 			transformation notNil ifTrue:[
  1413                             self deviceExposeX:x y:y width:w height:h
  1413 			    self deviceExposeX:x y:y width:w height:h
  1414                         ] ifFalse:[
  1414 			] ifFalse:[
  1415                             self exposeX:x y:y width:w height:h
  1415 			    self exposeX:x y:y width:w height:h
  1416                         ]
  1416 			]
  1417                     ]
  1417 		    ]
  1418                 ]
  1418 		]
  1419             ]
  1419 	    ]
  1420         ].
  1420 	].
  1421         ^ self
  1421 	^ self
  1422     ].
  1422     ].
  1423 
  1423 
  1424     isKeyEvent := isButtonEvent := isPointerEvent := isMouseWheelEvent := false.
  1424     isKeyEvent := isButtonEvent := isPointerEvent := isMouseWheelEvent := false.
  1425 
  1425 
  1426     (type == #'keyPress:x:y:') ifTrue:[
  1426     (type == #'keyPress:x:y:') ifTrue:[
  1427         isKeyEvent := true.
  1427 	isKeyEvent := true.
  1428         deviceMessage := #'deviceKeyPress:x:y:'.
  1428 	deviceMessage := #'deviceKeyPress:x:y:'.
  1429         delegateMessage := #'keyPress:x:y:view:'.
  1429 	delegateMessage := #'keyPress:x:y:view:'.
  1430         delegateQuery := #'handlesKeyPress:inView:'.
  1430 	delegateQuery := #'handlesKeyPress:inView:'.
  1431     ] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[
  1431     ] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[
  1432         isKeyEvent := true.
  1432 	isKeyEvent := true.
  1433         deviceMessage := #'deviceKeyRelease:x:y:'.
  1433 	deviceMessage := #'deviceKeyRelease:x:y:'.
  1434         delegateMessage := #'keyRelease:x:y:view:'.
  1434 	delegateMessage := #'keyRelease:x:y:view:'.
  1435         delegateQuery := #'handlesKeyRelease:inView:'.
  1435 	delegateQuery := #'handlesKeyRelease:inView:'.
  1436     ] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[
  1436     ] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[
  1437         isButtonEvent := true.
  1437 	isButtonEvent := true.
  1438         deviceMessage := #'deviceButtonMotion:x:y:'.
  1438 	deviceMessage := #'deviceButtonMotion:x:y:'.
  1439         delegateMessage := #'buttonMotion:x:y:view:'.
  1439 	delegateMessage := #'buttonMotion:x:y:view:'.
  1440         delegateQuery := #'handlesButtonMotion:inView:'.
  1440 	delegateQuery := #'handlesButtonMotion:inView:'.
  1441     ] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[
  1441     ] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[
  1442         isButtonEvent := true.
  1442 	isButtonEvent := true.
  1443         deviceMessage := #'deviceButtonPress:x:y:'.
  1443 	deviceMessage := #'deviceButtonPress:x:y:'.
  1444         delegateMessage := #'buttonPress:x:y:view:'.
  1444 	delegateMessage := #'buttonPress:x:y:view:'.
  1445         delegateQuery := #'handlesButtonPress:inView:'.
  1445 	delegateQuery := #'handlesButtonPress:inView:'.
  1446     ] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[
  1446     ] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[
  1447         isButtonEvent := true.
  1447 	isButtonEvent := true.
  1448         deviceMessage := #'deviceButtonRelease:x:y:'.
  1448 	deviceMessage := #'deviceButtonRelease:x:y:'.
  1449         delegateMessage := #'buttonRelease:x:y:view:'.
  1449 	delegateMessage := #'buttonRelease:x:y:view:'.
  1450         delegateQuery := #'handlesButtonRelease:inView:'.
  1450 	delegateQuery := #'handlesButtonRelease:inView:'.
  1451     ] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[
  1451     ] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[
  1452         isButtonEvent := true.
  1452 	isButtonEvent := true.
  1453         deviceMessage := #'deviceButtonShiftPress:x:y:'.
  1453 	deviceMessage := #'deviceButtonShiftPress:x:y:'.
  1454         delegateMessage := #'buttonShiftPress:x:y:view:'.
  1454 	delegateMessage := #'buttonShiftPress:x:y:view:'.
  1455         delegateQuery := #'handlesButtonShiftPress:inView:'.
  1455 	delegateQuery := #'handlesButtonShiftPress:inView:'.
  1456     ] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[
  1456     ] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[
  1457         isButtonEvent := true.
  1457 	isButtonEvent := true.
  1458         deviceMessage := #'deviceButtonMultiPress:x:y:'.
  1458 	deviceMessage := #'deviceButtonMultiPress:x:y:'.
  1459         delegateMessage := #'buttonMultiPress:x:y:view:'.
  1459 	delegateMessage := #'buttonMultiPress:x:y:view:'.
  1460         delegateQuery := #'handlesButtonMultiPress:inView:'.
  1460 	delegateQuery := #'handlesButtonMultiPress:inView:'.
  1461     ] ifFalse:[ (type == #mouseWheelMotion:x:y:amount:deltaTime:) ifTrue:[
  1461     ] ifFalse:[ (type == #mouseWheelMotion:x:y:amount:deltaTime:) ifTrue:[
  1462         isMouseWheelEvent := true.
  1462 	isMouseWheelEvent := true.
  1463         deviceMessage := type.
  1463 	deviceMessage := type.
  1464         delegateMessage := #mouseWheelMotion:x:y:amount:deltaTime:view:.
  1464 	delegateMessage := #mouseWheelMotion:x:y:amount:deltaTime:view:.
  1465         delegateQuery := #handlesMouseWheelMotion:inView:.
  1465 	delegateQuery := #handlesMouseWheelMotion:inView:.
  1466     ] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[
  1466     ] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[
  1467         isPointerEvent := true.
  1467 	isPointerEvent := true.
  1468         deviceMessage := #'devicePointerEnter:x:y:'.
  1468 	deviceMessage := #'devicePointerEnter:x:y:'.
  1469         delegateMessage := #'pointerEnter:x:y:view:'.
  1469 	delegateMessage := #'pointerEnter:x:y:view:'.
  1470         delegateQuery := #'handlesPointerEnter:inView:'.
  1470 	delegateQuery := #'handlesPointerEnter:inView:'.
  1471     ] ifFalse:[ (type == #'pointerLeave:') ifTrue:[
  1471     ] ifFalse:[ (type == #'pointerLeave:') ifTrue:[
  1472         isPointerEvent := true.
  1472 	isPointerEvent := true.
  1473         deviceMessage := type.
  1473 	deviceMessage := type.
  1474         delegateMessage := #'pointerLeave:view:'.
  1474 	delegateMessage := #'pointerLeave:view:'.
  1475         delegateQuery := #'handlesPointerLeave:inView:'.
  1475 	delegateQuery := #'handlesPointerLeave:inView:'.
  1476     ] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[
  1476     ] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[
  1477         deviceMessage := #'deviceExposeX:y:width:height:'.
  1477 	deviceMessage := #'deviceExposeX:y:width:height:'.
  1478     ] ifFalse:[ (type == #'graphicsExposeX:y:width:height:final:') ifTrue:[
  1478     ] ifFalse:[ (type == #'graphicsExposeX:y:width:height:final:') ifTrue:[
  1479         deviceMessage := #'deviceGraphicsExposeX:y:width:height:final:'.
  1479 	deviceMessage := #'deviceGraphicsExposeX:y:width:height:final:'.
  1480     ]]]]]]]]]]]].
  1480     ]]]]]]]]]]]].
  1481 
  1481 
  1482     "
  1482     "
  1483      if there is a focusView, and its a keyboard event, pass it
  1483      if there is a focusView, and its a keyboard event, pass it
  1484      to that view (or its controller, or its delegate).
  1484      to that view (or its controller, or its delegate).
  1485      In this case, a coordinate which is outside of
  1485      In this case, a coordinate which is outside of
  1486      the focusView (0 @ 0) is passed as x/y coordinates.
  1486      the focusView (0 @ 0) is passed as x/y coordinates.
  1487     "
  1487     "
  1488     ((isKeyEvent "or:[isMouseWheelEvent]")
  1488     ((isKeyEvent "or:[isMouseWheelEvent]")
  1489     and:[focusView notNil and:[self ~~ focusView]]) ifTrue:[
  1489     and:[focusView notNil and:[self ~~ focusView]]) ifTrue:[
  1490         delegatedEvent := ev shallowCopy.
  1490 	delegatedEvent := ev shallowCopy.
  1491         delegatedEvent delegatedFrom:ev.
  1491 	delegatedEvent delegatedFrom:ev.
  1492         delegatedEvent arguments:(ev arguments shallowCopy).
  1492 	delegatedEvent arguments:(ev arguments shallowCopy).
  1493         delegatedEvent x:-1; y:-1.
  1493 	delegatedEvent x:-1; y:-1.
  1494 
  1494 
  1495         focusView
  1495 	focusView
  1496             dispatchEvent:delegatedEvent
  1496 	    dispatchEvent:delegatedEvent
  1497             withFocusOn:nil
  1497 	    withFocusOn:nil
  1498             delegate:doDelegate.
  1498 	    delegate:doDelegate.
  1499         ^ self
  1499 	^ self
  1500     ].
  1500     ].
  1501 
  1501 
  1502     doDelegate ifTrue:[
  1502     doDelegate ifTrue:[
  1503         "
  1503 	"
  1504          handle delegated messages
  1504 	 handle delegated messages
  1505         "
  1505 	"
  1506         (isKeyEvent
  1506 	(isKeyEvent
  1507          or:[isButtonEvent
  1507 	 or:[isButtonEvent
  1508          or:[isMouseWheelEvent
  1508 	 or:[isMouseWheelEvent
  1509          or:[isPointerEvent]]]) ifTrue:[
  1509 	 or:[isPointerEvent]]]) ifTrue:[
  1510             delegate := self delegate.
  1510 	    delegate := self delegate.
  1511 
  1511 
  1512             "
  1512 	    "
  1513              what a kludge - sending to delegate requires
  1513 	     what a kludge - sending to delegate requires
  1514              another selector and an additional argument ...
  1514 	     another selector and an additional argument ...
  1515             "
  1515 	    "
  1516             (delegate notNil) ifTrue:[
  1516 	    (delegate notNil) ifTrue:[
  1517                 "
  1517 		"
  1518                  is the delegate interested in that event ?
  1518 		 is the delegate interested in that event ?
  1519                  (if it does not respond to the handlesXXX message, assume: NO)
  1519 		 (if it does not respond to the handlesXXX message, assume: NO)
  1520                 "
  1520 		"
  1521                 (delegate askFor:delegateQuery with:(argArray at:1) with:self) ifTrue:[
  1521 		(delegate askFor:delegateQuery with:(argArray at:1) with:self) ifTrue:[
  1522                     "
  1522 		    "
  1523                      mhmh ... have to convert to logical coordinates
  1523 		     mhmh ... have to convert to logical coordinates
  1524                     "
  1524 		    "
  1525                     transformation notNil ifTrue:[
  1525 		    transformation notNil ifTrue:[
  1526                         argArray size > 2 ifTrue:[
  1526 			argArray size > 2 ifTrue:[
  1527                             argArray at:2 put:(transformation applyInverseToX:(argArray at:2)).
  1527 			    argArray at:2 put:(transformation applyInverseToX:(argArray at:2)).
  1528                             argArray at:3 put:(transformation applyInverseToY:(argArray at:3)).
  1528 			    argArray at:3 put:(transformation applyInverseToY:(argArray at:3)).
  1529                         ].
  1529 			].
  1530                     ].
  1530 		    ].
  1531                     argArray isNil ifTrue:[
  1531 		    argArray isNil ifTrue:[
  1532                         delegate perform:delegateMessage with:self
  1532 			delegate perform:delegateMessage with:self
  1533                     ] ifFalse:[
  1533 		    ] ifFalse:[
  1534                         delegate perform:delegateMessage withArguments:(argArray copyWith:self)
  1534 			delegate perform:delegateMessage withArguments:(argArray copyWith:self)
  1535                     ].
  1535 		    ].
  1536                     ^ self
  1536 		    ^ self
  1537                 ]
  1537 		]
  1538             ].
  1538 	    ].
  1539         ].
  1539 	].
  1540     ].
  1540     ].
  1541 
  1541 
  1542     "
  1542     "
  1543      if I am not shown, ignore input events
  1543      if I am not shown, ignore input events
  1544     "
  1544     "
  1545     (isKeyEvent
  1545     (isKeyEvent
  1546      or:[isButtonEvent
  1546      or:[isButtonEvent
  1547      or:[isMouseWheelEvent
  1547      or:[isMouseWheelEvent
  1548      or:[isPointerEvent]]]) ifTrue:[
  1548      or:[isPointerEvent]]]) ifTrue:[
  1549         realized ifFalse:[
  1549 	realized ifFalse:[
  1550             ^ self
  1550 	    ^ self
  1551         ]
  1551 	]
  1552     ].
  1552     ].
  1553 
  1553 
  1554     "
  1554     "
  1555      if there is a controller, that one gets all user events
  1555      if there is a controller, that one gets all user events
  1556     "
  1556     "
  1557     eventReceiver := self.
  1557     eventReceiver := self.
  1558     (controller := self controller) notNil ifTrue:[
  1558     (controller := self controller) notNil ifTrue:[
  1559         (isKeyEvent
  1559 	(isKeyEvent
  1560          or:[isButtonEvent
  1560 	 or:[isButtonEvent
  1561          or:[isMouseWheelEvent
  1561 	 or:[isMouseWheelEvent
  1562          or:[isPointerEvent
  1562 	 or:[isPointerEvent
  1563          or:[(type == #focusIn)
  1563 	 or:[(type == #focusIn)
  1564          or:[(type == #focusOut)]]]]]) ifTrue:[
  1564 	 or:[(type == #focusOut)]]]]]) ifTrue:[
  1565             eventReceiver := controller.
  1565 	    eventReceiver := controller.
  1566         ]
  1566 	]
  1567     ].
  1567     ].
  1568 
  1568 
  1569     "
  1569     "
  1570      finally, another one:
  1570      finally, another one:
  1571      if I have a transformation, edit the selector from #foo to #deviceFoo...
  1571      if I have a transformation, edit the selector from #foo to #deviceFoo...
  1577      another context to any debuggers walkback, making things less clear.
  1577      another context to any debuggers walkback, making things less clear.
  1578     "
  1578     "
  1579     selector := type.
  1579     selector := type.
  1580 
  1580 
  1581     transformation notNil ifTrue:[
  1581     transformation notNil ifTrue:[
  1582         (isKeyEvent
  1582 	(isKeyEvent
  1583          or:[isButtonEvent
  1583 	 or:[isButtonEvent
  1584          or:[isMouseWheelEvent
  1584 	 or:[isMouseWheelEvent
  1585          or:[isPointerEvent
  1585 	 or:[isPointerEvent
  1586          or:[(type == #'exposeX:y:width:height:')
  1586 	 or:[(type == #'exposeX:y:width:height:')
  1587          or:[(type == #'graphicsExposeX:y:width:height:final:')]]]]]) ifTrue:[
  1587 	 or:[(type == #'graphicsExposeX:y:width:height:final:')]]]]]) ifTrue:[
  1588             selector := deviceMessage
  1588 	    selector := deviceMessage
  1589         ]
  1589 	]
  1590     ].
  1590     ].
  1591 
  1591 
  1592     eventReceiver perform:selector withArguments:argArray
  1592     eventReceiver perform:selector withArguments:argArray
  1593 
  1593 
  1594     "Created: / 20.5.1998 / 22:46:25 / cg"
  1594     "Created: / 20.5.1998 / 22:46:25 / cg"
  2508 ! !
  2508 ! !
  2509 
  2509 
  2510 !DisplaySurface class methodsFor:'documentation'!
  2510 !DisplaySurface class methodsFor:'documentation'!
  2511 
  2511 
  2512 version
  2512 version
  2513     ^ '$Header: /cvs/stx/stx/libview/DisplaySurface.st,v 1.141 2009-02-25 11:30:52 sr Exp $'
  2513     ^ '$Header: /cvs/stx/stx/libview/DisplaySurface.st,v 1.142 2009-08-07 10:51:34 sr Exp $'
  2514 ! !
  2514 ! !
  2515 
  2515 
  2516 DisplaySurface initialize!
  2516 DisplaySurface initialize!