3368
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2014 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libview2' }"
|
|
13 |
|
|
14 |
EventListener subclass:#PluggableEventListener
|
|
15 |
instanceVariableNames:'keyPressAction keyReleaseAction'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Interface-Support-UI'
|
|
19 |
!
|
|
20 |
|
|
21 |
!PluggableEventListener class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2014 by Claus Gittinger
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
a preliminary version of a pluggable event listener.
|
|
40 |
can be configured via handler blocks.
|
|
41 |
|
|
42 |
[see also:]
|
|
43 |
WindowSensor WindowEvent WindowGroup
|
|
44 |
|
|
45 |
[author:]
|
|
46 |
Claus Gittinger
|
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
example
|
|
51 |
"
|
|
52 |
eat a particular key from another view.
|
|
53 |
|
|
54 |
|v e|
|
|
55 |
|
|
56 |
v := StandardSystemView extent:300@200.
|
|
57 |
v add:(e := EditTextView origin:0.0@0.0 corner:1.0@1.0).
|
|
58 |
v label:'key a is ignored'.
|
|
59 |
v openAndWait.
|
|
60 |
|
|
61 |
e sensor addEventListener:(
|
|
62 |
PluggableEventListener new
|
|
63 |
keyPressAction:[:event |
|
|
64 |
event key == $a ifTrue:[
|
|
65 |
Transcript showCR:'a key eaten'.
|
|
66 |
true.
|
|
67 |
] ifFalse:[
|
|
68 |
Transcript showCR:'other key ok'.
|
|
69 |
false
|
|
70 |
]
|
|
71 |
]).
|
|
72 |
"
|
|
73 |
! !
|
|
74 |
|
|
75 |
!PluggableEventListener methodsFor:'accessing'!
|
|
76 |
|
|
77 |
keyPressAction:aBlock
|
|
78 |
"install a block as handler for keyPress events.
|
|
79 |
the block will get the windowEvent as argument,
|
|
80 |
and is supposed to return true if it handled the event,
|
|
81 |
false if not (so the event is processed as usual)."
|
|
82 |
|
|
83 |
keyPressAction := aBlock.
|
|
84 |
!
|
|
85 |
|
|
86 |
keyReleaseAction:aBlock
|
|
87 |
"install a block as handler for keyRelease events.
|
|
88 |
the block will get the windowEvent as argument,
|
|
89 |
and is supposed to return true if it handled the event,
|
|
90 |
false if not (so the event is processed as usual)."
|
|
91 |
|
|
92 |
keyReleaseAction := aBlock.
|
|
93 |
! !
|
|
94 |
|
|
95 |
!PluggableEventListener methodsFor:'event processing'!
|
|
96 |
|
|
97 |
processEvent:anEvent
|
|
98 |
"process an event; if true is returned, the event is considered to be
|
|
99 |
'eaten' by the listener, and not passed to the view.
|
|
100 |
If false is returned, the event is processed as usual.
|
|
101 |
Here, the event is dispatched into one of the button*/key* etc. methods"
|
|
102 |
|
|
103 |
|handler|
|
|
104 |
|
|
105 |
anEvent isKeyPressEvent ifTrue:[
|
|
106 |
handler := keyPressAction
|
|
107 |
] ifFalse:[
|
|
108 |
anEvent isKeyReleaseEvent ifTrue:[
|
|
109 |
handler := keyReleaseAction
|
|
110 |
]
|
|
111 |
].
|
|
112 |
|
|
113 |
handler notNil ifTrue:[
|
|
114 |
^ handler value:anEvent
|
|
115 |
].
|
|
116 |
|
|
117 |
^ false
|
|
118 |
! !
|
|
119 |
|
|
120 |
!PluggableEventListener class methodsFor:'documentation'!
|
|
121 |
|
|
122 |
version
|
|
123 |
^ '$Header: /cvs/stx/stx/libview2/PluggableEventListener.st,v 1.1 2014-09-19 17:45:07 cg Exp $'
|
|
124 |
!
|
|
125 |
|
|
126 |
version_CVS
|
|
127 |
^ '$Header: /cvs/stx/stx/libview2/PluggableEventListener.st,v 1.1 2014-09-19 17:45:07 cg Exp $'
|
|
128 |
! !
|
|
129 |
|