Mercurial > projects > dwt-mac
comparison dwt/widgets/EventTable.d @ 15:2952d5604c0a
Ported some widgets, added some stuff to the runtime bindings
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Fri, 29 Aug 2008 21:46:05 +0200 |
parents | 380af2bdd8e5 |
children | 5b53d338c709 |
comparison
equal
deleted
inserted
replaced
14:762fbe6f17d3 | 15:2952d5604c0a |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.widgets.EventTable; | 14 module dwt.widgets.EventTable; |
12 | 15 |
13 import dwt.dwthelper.utils; | |
14 | 16 |
15 import dwt.DWT; | 17 import dwt.DWT; |
16 import dwt.internal.DWTEventListener; | 18 import dwt.internal.DWTEventListener; |
19 | |
20 import dwt.dwthelper.System; | |
21 import dwt.dwthelper.utils; | |
22 | |
23 import dwt.widgets.Event; | |
24 import dwt.widgets.Listener; | |
25 import dwt.widgets.TypedListener; | |
17 | 26 |
18 /** | 27 /** |
19 * Instances of this class implement a simple | 28 * Instances of this class implement a simple |
20 * look up mechanism that maps an event type | 29 * look up mechanism that maps an event type |
21 * to a listener. Multiple listeners for the | 30 * to a listener. Multiple listeners for the |
24 | 33 |
25 class EventTable { | 34 class EventTable { |
26 int [] types; | 35 int [] types; |
27 Listener [] listeners; | 36 Listener [] listeners; |
28 int level; | 37 int level; |
29 static final int GROW_SIZE = 4; | 38 static const int GROW_SIZE = 4; |
30 | 39 |
31 public Listener [] getListeners (int eventType) { | 40 public Listener [] getListeners (int eventType) { |
32 if (types is null) return new Listener [0]; | 41 if (types is null) return new Listener [0]; |
33 int count = 0; | 42 int count = 0; |
34 for (int i=0; i<types.length; i++) { | 43 for (int i=0; i<types.length; i++) { |
57 if (index is length) { | 66 if (index is length) { |
58 int [] newTypes = new int [length + GROW_SIZE]; | 67 int [] newTypes = new int [length + GROW_SIZE]; |
59 System.arraycopy (types, 0, newTypes, 0, length); | 68 System.arraycopy (types, 0, newTypes, 0, length); |
60 types = newTypes; | 69 types = newTypes; |
61 Listener [] newListeners = new Listener [length + GROW_SIZE]; | 70 Listener [] newListeners = new Listener [length + GROW_SIZE]; |
62 System.arraycopy (listeners, 0, newListeners, 0, length); | 71 SimpleType!(Listener).arraycopy (listeners, 0, newListeners, 0, length); |
63 listeners = newListeners; | 72 listeners = newListeners; |
64 } | 73 } |
65 types [index] = eventType; | 74 types [index] = eventType; |
66 listeners [index] = listener; | 75 listeners [index] = listener; |
67 } | 76 } |
116 | 125 |
117 void remove (int index) { | 126 void remove (int index) { |
118 if (level is 0) { | 127 if (level is 0) { |
119 int end = types.length - 1; | 128 int end = types.length - 1; |
120 System.arraycopy (types, index + 1, types, index, end - index); | 129 System.arraycopy (types, index + 1, types, index, end - index); |
121 System.arraycopy (listeners, index + 1, listeners, index, end - index); | 130 SimpleType!(Listener).arraycopy (listeners, index + 1, listeners, index, end - index); |
122 index = end; | 131 index = end; |
123 } else { | 132 } else { |
124 if (level > 0) level = -level; | 133 if (level > 0) level = -level; |
125 } | 134 } |
126 types [index] = 0; | 135 types [index] = 0; |
139 | 148 |
140 public void unhook (int eventType, DWTEventListener listener) { | 149 public void unhook (int eventType, DWTEventListener listener) { |
141 if (types is null) return; | 150 if (types is null) return; |
142 for (int i=0; i<types.length; i++) { | 151 for (int i=0; i<types.length; i++) { |
143 if (types [i] is eventType) { | 152 if (types [i] is eventType) { |
144 if (listeners [i] instanceof TypedListener) { | 153 if (cast(TypedListener) listeners [i]) { |
145 TypedListener typedListener = (TypedListener) listeners [i]; | 154 TypedListener typedListener = cast(TypedListener) listeners [i]; |
146 if (typedListener.getEventListener () is listener) { | 155 if (typedListener.getEventListener () is listener) { |
147 remove (i); | 156 remove (i); |
148 return; | 157 return; |
149 } | 158 } |
150 } | 159 } |