-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
MorphicEventHandler.class.st
267 lines (220 loc) · 7.77 KB
/
MorphicEventHandler.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
"
I'm the class in charge of handling the subscriptions to events such as clicks or key presses.
I'm a provisory solution while my clients are fixed and I can be replaced by announcements
"
Class {
#name : #MorphicEventHandler,
#superclass : #Object,
#instVars : [
'subscriptions'
],
#category : #'Morphic-Base-Events'
}
{ #category : #events }
MorphicEventHandler >> addSubscription: aSubscription toEvent: eventName [
(subscriptions includesKey: eventName)
ifFalse: [ subscriptions at: eventName put: Set new. ].
(subscriptions at: eventName)
add: aSubscription.
]
{ #category : #access }
MorphicEventHandler >> allRecipients [
^subscriptions collect: [ :each | each recipients ]
]
{ #category : #events }
MorphicEventHandler >> click: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #click from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> doubleClick: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #doubleClick from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> doubleClickTimeout: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #doubleClickTimeout from: sourceMorph
]
{ #category : #testing }
MorphicEventHandler >> existsSubscriptionsFor: anEvent [
^(subscriptions includesKey: anEvent) and: [ (subscriptions at: anEvent) notEmpty ]
]
{ #category : #testing }
MorphicEventHandler >> handlesClickOrDrag: evt [
^(self existsSubscriptionsFor: #click)
or: [ (self existsSubscriptionsFor: #doubleClick)
or: [(self existsSubscriptionsFor: #startDrag)]].
]
{ #category : #testing }
MorphicEventHandler >> handlesGestureStart: evt [
^self existsSubscriptionsFor: #gestureStart
]
{ #category : #testing }
MorphicEventHandler >> handlesKeyDown: evt [
^self existsSubscriptionsFor: #keyDown
]
{ #category : #testing }
MorphicEventHandler >> handlesKeyStroke: evt [
^self existsSubscriptionsFor: #keyStroke
]
{ #category : #testing }
MorphicEventHandler >> handlesKeyUp: evt [
^self existsSubscriptionsFor: #keyUp
]
{ #category : #testing }
MorphicEventHandler >> handlesKeyboard: evt [
^(self handlesKeyDown: evt)
or: [ (self handlesKeyUp: evt)
or: [ self handlesKeyStroke: evt ]].
]
{ #category : #testing }
MorphicEventHandler >> handlesMouseDown: evt [
^(self existsSubscriptionsFor: #mouseDown)
or: [ (self existsSubscriptionsFor: #mouseStillDown)
or: [ (self existsSubscriptionsFor: #mouseUp)
or: [ (self handlesClickOrDrag: evt)
or: [ self handlesGestureStart: evt]]]].
]
{ #category : #testing }
MorphicEventHandler >> handlesMouseMove: evt [
^self existsSubscriptionsFor: #mouseMove
]
{ #category : #testing }
MorphicEventHandler >> handlesMouseOver: evt [
(self existsSubscriptionsFor: #mouseEnter) ifTrue: [ ^true ].
(self existsSubscriptionsFor: #mouseLeave) ifTrue: [ ^true ].
(self existsSubscriptionsFor: #mouseOver) ifTrue: [ ^true ].
^false.
]
{ #category : #testing }
MorphicEventHandler >> handlesMouseOverDragging: evt [
^(self existsSubscriptionsFor: #mouseEnterDragging )
or: [ self existsSubscriptionsFor: #mouseLeaveDragging ]
]
{ #category : #testing }
MorphicEventHandler >> handlesMouseStillDown: evt [
^self existsSubscriptionsFor: #mouseStillDown.
]
{ #category : #initialization }
MorphicEventHandler >> initialize [
subscriptions := Dictionary new.
]
{ #category : #events }
MorphicEventHandler >> keyDown: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #keyDown from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> keyStroke: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #keyStroke from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> keyUp: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #keyUp from: sourceMorph
]
{ #category : #access }
MorphicEventHandler >> methodRefList [
"Return a MethodReference for each message I can send."
| list |
list := OrderedCollection new.
subscriptions do: [
:subscriptionSet |
subscriptionSet do: [ :s |
s ifNotNil: [list
add: (RGMethodDefinition
realClass: (s recipient class whichClassIncludesSelector: s selector)
selector: s selector)]
]
].
^ list
]
{ #category : #events }
MorphicEventHandler >> mouseDown: event fromMorph: sourceMorph [
"Take double-clicks into account."
((self handlesClickOrDrag: event) and:[event redButtonPressed]) ifTrue:[
event hand waitForClicksOrDrag: sourceMorph event: event.
].
^self notifyMorphsOfEvent: event ofType: #mouseDown from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> mouseEnter: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #mouseEnter from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> mouseEnterDragging: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #mouseEnterDragging from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> mouseLeave: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #mouseLeave from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> mouseLeaveDragging: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #mouseLeaveDragging from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> mouseMove: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #mouseMove from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> mouseOver: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #mouseOver from: sourceMorph
]
{ #category : #testing }
MorphicEventHandler >> mouseSelectorsInclude: selector [
| mouseEventTypes allSubscriptions |
mouseEventTypes := #(
mouseDown
mouseMove
mouseStillDown
mouseUp
mouseEnter
mouseLeave
mouseEnterDragging
mouseLeaveDragging
doubleClick).
allSubscriptions := subscriptions values flatCollect: [ :e | e ].
^ allSubscriptions anySatisfy: [ :e | (mouseEventTypes includes: e event) and: [ e selector = selector ] ].
]
{ #category : #events }
MorphicEventHandler >> mouseStillDown: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #mouseStillDown from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> mouseUp: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #mouseUp from: sourceMorph
]
{ #category : #events }
MorphicEventHandler >> notifyMorphsOfEvent: anEvent ofType: eventType from: sourceMorph [
| result |
result := false.
((subscriptions includesKey: eventType) not or: [ (subscriptions at: eventType) isEmpty ])
ifTrue: [ ^false ].
(subscriptions at: eventType) do: [ :s | result := result | ((s notify: anEvent from: sourceMorph) == true) ].
^result
]
{ #category : #initialization }
MorphicEventHandler >> on: eventName send: selector to: recipient [
self
addSubscription: (MorphEventSubscription on: eventName send: selector to: recipient)
toEvent: eventName.
]
{ #category : #initialization }
MorphicEventHandler >> on: eventName send: selector to: recipient withValue: value [
selector numArgs = 3 ifFalse:
[self error: 'Warning: value parameters are passed as first of 3 arguments'].
self
addSubscription: (MorphEventSubscription on: eventName send: selector to: recipient withValue: value)
toEvent: eventName.
]
{ #category : #events }
MorphicEventHandler >> startDrag: event fromMorph: sourceMorph [
^self notifyMorphsOfEvent: event ofType: #startDrag from: sourceMorph
]
{ #category : #copying }
MorphicEventHandler >> veryDeepFixupWith: deepCopier [
| old |
"ALL inst vars were weakly copied. If they were in the tree being copied, fix them up, otherwise point to the originals!!"
super veryDeepFixupWith: deepCopier.
1 to: self class instSize do: [:ii |
old := self instVarAt: ii.
self instVarAt: ii put: (deepCopier references at: old ifAbsent: [old])
].
]