1463 Delegation has higher priority than both controller or focusView |
1465 Delegation has higher priority than both controller or focusView |
1464 forwarding." |
1466 forwarding." |
1465 |
1467 |
1466 |delegate selector delegateMessage delegateQuery |
1468 |delegate selector delegateMessage delegateQuery |
1467 eventReceiver controller deviceMessage |
1469 eventReceiver controller deviceMessage |
1468 isKeyEvent isButtonEvent isMouseWheelEvent isPointerEvent |
1470 isKeyEvent isButtonEvent isMouseWheelEvent isPointerEvent isExposeEvent |
|
1471 |
1469 rect x y w h delegatedEvent rgn| |
1472 rect x y w h delegatedEvent rgn| |
1470 |
1473 |
1471 type == #damage ifTrue:[ |
1474 type == #damage ifTrue:[ |
1472 "/ OLDdamage scheme - this will vanish |
1475 "/ OLDdamage scheme - this will vanish |
1473 self shown ifTrue:[ |
1476 self shown ifTrue:[ |
1474 rect := argArray. |
1477 rect := argArray. |
1475 x := rect left. |
1478 x := rect left. |
1476 y := rect top. |
1479 y := rect top. |
1477 w := rect width. |
1480 w := rect width. |
1478 h := rect height. |
1481 h := rect height. |
1479 transformation notNil ifTrue:[ |
1482 transformation notNil ifTrue:[ |
1480 self deviceExposeX:x y:y width:w height:h |
1483 self deviceExposeX:x y:y width:w height:h |
1481 ] ifFalse:[ |
1484 ] ifFalse:[ |
1482 self exposeX:x y:y width:w height:h |
1485 self exposeX:x y:y width:w height:h |
1483 ] |
1486 ] |
1484 ]. |
1487 ]. |
1485 ^ self |
1488 ^ self |
1486 ]. |
1489 ]. |
1487 |
1490 |
1488 type == #newDamage ifTrue:[ |
1491 type == #newDamage ifTrue:[ |
1489 "/ New damage scheme |
1492 "/ New damage scheme |
1490 rgn := updateRegion. |
1493 rgn := updateRegion. |
1491 updateRegion := nil. |
1494 updateRegion := nil. |
1492 self shown ifTrue:[ |
1495 self shown ifTrue:[ |
1493 rgn notNil ifTrue:[ |
1496 rgn notNil ifTrue:[ |
1494 rgn do:[:rect | |
1497 rgn do:[:rect | |
1495 "/ cg: I think the check for being realized may not be enough; |
1498 "/ cg: I think the check for being realized may not be enough; |
1496 "/ there is a race here, if the view gets closed, while in the loop... |
1499 "/ there is a race here, if the view gets closed, while in the loop... |
1497 realized ifTrue:[ |
1500 realized ifTrue:[ |
1498 x := rect left. |
1501 x := rect left. |
1499 y := rect top. |
1502 y := rect top. |
1500 w := rect width. |
1503 w := rect width. |
1501 h := rect height. |
1504 h := rect height. |
1502 transformation notNil ifTrue:[ |
1505 transformation notNil ifTrue:[ |
1503 self deviceExposeX:x y:y width:w height:h |
1506 self deviceExposeX:x y:y width:w height:h |
1504 ] ifFalse:[ |
1507 ] ifFalse:[ |
1505 self exposeX:x y:y width:w height:h |
1508 self exposeX:x y:y width:w height:h |
1506 ] |
1509 ] |
1507 ] |
1510 ] |
1508 ] |
1511 ] |
1509 ] |
1512 ] |
1510 ]. |
1513 ]. |
1511 ^ self |
1514 ^ self |
1512 ]. |
1515 ]. |
1513 |
1516 |
1514 isKeyEvent := isButtonEvent := isPointerEvent := isMouseWheelEvent := false. |
1517 isKeyEvent := isButtonEvent := isPointerEvent := isMouseWheelEvent := isExposeEvent := false. |
1515 |
1518 |
1516 (type == #'keyPress:x:y:') ifTrue:[ |
1519 (type == #'keyPress:x:y:') ifTrue:[ |
1517 isKeyEvent := true. |
1520 isKeyEvent := true. |
1518 deviceMessage := #'deviceKeyPress:x:y:'. |
1521 deviceMessage := #'deviceKeyPress:x:y:'. |
1519 delegateMessage := #'keyPress:x:y:view:'. |
1522 delegateMessage := #'keyPress:x:y:view:'. |
1520 delegateQuery := #'handlesKeyPress:inView:'. |
1523 delegateQuery := #'handlesKeyPress:inView:'. |
1521 ] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[ |
1524 ] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[ |
1522 isKeyEvent := true. |
1525 isKeyEvent := true. |
1523 deviceMessage := #'deviceKeyRelease:x:y:'. |
1526 deviceMessage := #'deviceKeyRelease:x:y:'. |
1524 delegateMessage := #'keyRelease:x:y:view:'. |
1527 delegateMessage := #'keyRelease:x:y:view:'. |
1525 delegateQuery := #'handlesKeyRelease:inView:'. |
1528 delegateQuery := #'handlesKeyRelease:inView:'. |
1526 ] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[ |
1529 ] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[ |
1527 isButtonEvent := true. |
1530 isButtonEvent := true. |
1528 deviceMessage := #'deviceButtonMotion:x:y:'. |
1531 deviceMessage := #'deviceButtonMotion:x:y:'. |
1529 delegateMessage := #'buttonMotion:x:y:view:'. |
1532 delegateMessage := #'buttonMotion:x:y:view:'. |
1530 delegateQuery := #'handlesButtonMotion:inView:'. |
1533 delegateQuery := #'handlesButtonMotion:inView:'. |
1531 ] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[ |
1534 ] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[ |
1532 isButtonEvent := true. |
1535 isButtonEvent := true. |
1533 deviceMessage := #'deviceButtonPress:x:y:'. |
1536 deviceMessage := #'deviceButtonPress:x:y:'. |
1534 delegateMessage := #'buttonPress:x:y:view:'. |
1537 delegateMessage := #'buttonPress:x:y:view:'. |
1535 delegateQuery := #'handlesButtonPress:inView:'. |
1538 delegateQuery := #'handlesButtonPress:inView:'. |
1536 ] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[ |
1539 ] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[ |
1537 isButtonEvent := true. |
1540 isButtonEvent := true. |
1538 deviceMessage := #'deviceButtonRelease:x:y:'. |
1541 deviceMessage := #'deviceButtonRelease:x:y:'. |
1539 delegateMessage := #'buttonRelease:x:y:view:'. |
1542 delegateMessage := #'buttonRelease:x:y:view:'. |
1540 delegateQuery := #'handlesButtonRelease:inView:'. |
1543 delegateQuery := #'handlesButtonRelease:inView:'. |
1541 ] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[ |
1544 ] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[ |
1542 isButtonEvent := true. |
1545 isButtonEvent := true. |
1543 deviceMessage := #'deviceButtonShiftPress:x:y:'. |
1546 deviceMessage := #'deviceButtonShiftPress:x:y:'. |
1544 delegateMessage := #'buttonShiftPress:x:y:view:'. |
1547 delegateMessage := #'buttonShiftPress:x:y:view:'. |
1545 delegateQuery := #'handlesButtonShiftPress:inView:'. |
1548 delegateQuery := #'handlesButtonShiftPress:inView:'. |
1546 ] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[ |
1549 ] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[ |
1547 isButtonEvent := true. |
1550 isButtonEvent := true. |
1548 deviceMessage := #'deviceButtonMultiPress:x:y:'. |
1551 deviceMessage := #'deviceButtonMultiPress:x:y:'. |
1549 delegateMessage := #'buttonMultiPress:x:y:view:'. |
1552 delegateMessage := #'buttonMultiPress:x:y:view:'. |
1550 delegateQuery := #'handlesButtonMultiPress:inView:'. |
1553 delegateQuery := #'handlesButtonMultiPress:inView:'. |
1551 ] ifFalse:[ (type == #mouseWheelMotion:x:y:amount:deltaTime:) ifTrue:[ |
1554 ] ifFalse:[ (type == #mouseWheelMotion:x:y:amount:deltaTime:) ifTrue:[ |
1552 isMouseWheelEvent := true. |
1555 isMouseWheelEvent := true. |
1553 deviceMessage := type. |
1556 deviceMessage := type. |
1554 delegateMessage := #mouseWheelMotion:x:y:amount:deltaTime:view:. |
1557 delegateMessage := #mouseWheelMotion:x:y:amount:deltaTime:view:. |
1555 delegateQuery := #handlesMouseWheelMotion:inView:. |
1558 delegateQuery := #handlesMouseWheelMotion:inView:. |
1556 ] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[ |
1559 ] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[ |
1557 isPointerEvent := true. |
1560 isPointerEvent := true. |
1558 deviceMessage := #'devicePointerEnter:x:y:'. |
1561 deviceMessage := #'devicePointerEnter:x:y:'. |
1559 delegateMessage := #'pointerEnter:x:y:view:'. |
1562 delegateMessage := #'pointerEnter:x:y:view:'. |
1560 delegateQuery := #'handlesPointerEnter:inView:'. |
1563 delegateQuery := #'handlesPointerEnter:inView:'. |
1561 ] ifFalse:[ (type == #'pointerLeave:') ifTrue:[ |
1564 ] ifFalse:[ (type == #'pointerLeave:') ifTrue:[ |
1562 isPointerEvent := true. |
1565 isPointerEvent := true. |
1563 deviceMessage := type. |
1566 deviceMessage := type. |
1564 delegateMessage := #'pointerLeave:view:'. |
1567 delegateMessage := #'pointerLeave:view:'. |
1565 delegateQuery := #'handlesPointerLeave:inView:'. |
1568 delegateQuery := #'handlesPointerLeave:inView:'. |
1566 ] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[ |
1569 ] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[ |
1567 deviceMessage := #'deviceExposeX:y:width:height:'. |
1570 isExposeEvent := true. |
|
1571 deviceMessage := #'deviceExposeX:y:width:height:'. |
1568 ] ifFalse:[ (type == #'graphicsExposeX:y:width:height:final:') ifTrue:[ |
1572 ] ifFalse:[ (type == #'graphicsExposeX:y:width:height:final:') ifTrue:[ |
1569 deviceMessage := #'deviceGraphicsExposeX:y:width:height:final:'. |
1573 isExposeEvent := true. |
|
1574 deviceMessage := #'deviceGraphicsExposeX:y:width:height:final:'. |
1570 ]]]]]]]]]]]]. |
1575 ]]]]]]]]]]]]. |
1571 |
1576 |
1572 " |
1577 " |
1573 if there is a focusView, and its a keyboard event, pass it |
1578 if there is a focusView, and its a keyboard event, pass it |
1574 to that view (or its controller, or its delegate). |
1579 to that view (or its controller, or its delegate). |
1575 In this case, a coordinate which is outside of |
1580 In this case, a coordinate which is outside of |
1576 the focusView (0 @ 0) is passed as x/y coordinates. |
1581 the focusView (0 @ 0) is passed as x/y coordinates. |
1577 " |
1582 " |
1578 ((isKeyEvent "or:[isMouseWheelEvent]") |
1583 ((isKeyEvent "or:[isMouseWheelEvent]") |
1579 and:[focusView notNil and:[self ~~ focusView]]) ifTrue:[ |
1584 and:[focusView notNil and:[self ~~ focusView]]) ifTrue:[ |
1580 delegatedEvent := ev shallowCopy. |
1585 delegatedEvent := ev shallowCopy. |
1581 delegatedEvent delegatedFrom:ev. |
1586 delegatedEvent delegatedFrom:ev. |
1582 delegatedEvent arguments:(ev arguments shallowCopy). |
1587 delegatedEvent arguments:(ev arguments shallowCopy). |
1583 delegatedEvent x:-1; y:-1. |
1588 delegatedEvent x:-1; y:-1. |
1584 |
1589 |
1585 focusView |
1590 focusView |
1586 dispatchEvent:delegatedEvent |
1591 dispatchEvent:delegatedEvent |
1587 withFocusOn:nil |
1592 withFocusOn:nil |
1588 delegate:doDelegate. |
1593 delegate:doDelegate. |
1589 ^ self |
1594 ^ self |
1590 ]. |
1595 ]. |
1591 |
1596 |
1592 doDelegate ifTrue:[ |
1597 doDelegate ifTrue:[ |
1593 " |
1598 " |
1594 handle delegated messages |
1599 handle delegated messages |
1595 " |
1600 " |
1596 (isKeyEvent |
1601 (isKeyEvent |
1597 or:[isButtonEvent |
1602 or:[isButtonEvent |
1598 or:[isMouseWheelEvent |
1603 or:[isMouseWheelEvent |
1599 or:[isPointerEvent]]]) ifTrue:[ |
1604 or:[isPointerEvent]]]) ifTrue:[ |
1600 delegate := self delegate. |
1605 delegate := self delegate. |
1601 |
1606 |
1602 " |
1607 " |
1603 what a kludge - sending to delegate requires |
1608 what a kludge - sending to delegate requires |
1604 another selector and an additional argument ... |
1609 another selector and an additional argument ... |
1605 " |
1610 " |
1606 (delegate notNil) ifTrue:[ |
1611 (delegate notNil) ifTrue:[ |
1607 " |
1612 " |
1608 is the delegate interested in that event ? |
1613 is the delegate interested in that event ? |
1609 (if it does not respond to the handlesXXX message, assume: NO) |
1614 (if it does not respond to the handlesXXX message, assume: NO) |
1610 " |
1615 " |
1611 (delegate askFor:delegateQuery with:(argArray at:1) with:self) ifTrue:[ |
1616 (delegate askFor:delegateQuery with:(argArray at:1) with:self) ifTrue:[ |
1612 " |
1617 " |
1613 mhmh ... have to convert to logical coordinates |
1618 mhmh ... have to convert to logical coordinates |
1614 " |
1619 " |
1615 transformation notNil ifTrue:[ |
1620 transformation notNil ifTrue:[ |
1616 argArray size > 2 ifTrue:[ |
1621 argArray size > 2 ifTrue:[ |
1617 argArray at:2 put:(transformation applyInverseToX:(argArray at:2)). |
1622 argArray at:2 put:(transformation applyInverseToX:(argArray at:2)). |
1618 argArray at:3 put:(transformation applyInverseToY:(argArray at:3)). |
1623 argArray at:3 put:(transformation applyInverseToY:(argArray at:3)). |
1619 ]. |
1624 ]. |
1620 ]. |
1625 ]. |
1621 argArray isNil ifTrue:[ |
1626 argArray isNil ifTrue:[ |
1622 delegate perform:delegateMessage with:self |
1627 delegate perform:delegateMessage with:self |
1623 ] ifFalse:[ |
1628 ] ifFalse:[ |
1624 delegate perform:delegateMessage withArguments:(argArray copyWith:self) |
1629 delegate perform:delegateMessage withArguments:(argArray copyWith:self) |
1625 ]. |
1630 ]. |
1626 ^ self |
1631 ^ self |
1627 ] |
1632 ] |
1628 ]. |
1633 ]. |
1629 ]. |
1634 ]. |
1630 ]. |
1635 ]. |
1631 |
1636 |
1632 " |
1637 " |
1633 if I am not shown, ignore input events |
1638 if I am not shown, ignore input events |
1634 " |
1639 " |
1635 (isKeyEvent |
1640 (isKeyEvent |
1636 or:[isButtonEvent |
1641 or:[isButtonEvent |
1637 or:[isMouseWheelEvent |
1642 or:[isMouseWheelEvent |
1638 or:[isPointerEvent]]]) ifTrue:[ |
1643 or:[isPointerEvent]]]) ifTrue:[ |
1639 realized ifFalse:[ |
1644 realized ifFalse:[ |
1640 ^ self |
1645 ^ self |
1641 ] |
1646 ] |
1642 ]. |
1647 ]. |
1643 |
1648 |
1644 " |
1649 " |
1645 if there is a controller, that one gets all user events |
1650 if there is a controller, that one gets all user events |
1646 " |
1651 " |
1647 eventReceiver := self. |
1652 eventReceiver := self. |
1648 (controller := self controller) notNil ifTrue:[ |
1653 (controller := self controller) notNil ifTrue:[ |
1649 (isKeyEvent |
1654 (isKeyEvent |
1650 or:[isButtonEvent |
1655 or:[isButtonEvent |
1651 or:[isMouseWheelEvent |
1656 or:[isMouseWheelEvent |
1652 or:[isPointerEvent |
1657 or:[isPointerEvent |
1653 or:[(type == #focusIn) |
1658 or:[(type == #focusIn) |
1654 or:[(type == #focusOut)]]]]]) ifTrue:[ |
1659 or:[(type == #focusOut)]]]]]) ifTrue:[ |
1655 eventReceiver := controller. |
1660 eventReceiver := controller. |
1656 ] |
1661 ] |
1657 ]. |
1662 ]. |
1658 |
1663 |
1659 " |
1664 " |
1660 finally, another one: |
1665 finally, another one: |
1661 if I have a transformation, edit the selector from #foo to #deviceFoo... |
1666 if I have a transformation, edit the selector from #foo to #deviceFoo... |