comparison dwt/custom/CTabFolder2Listener.d @ 315:21959e16bc1e

Improved Listeners access functions.
author Frank Benoit <benoit@tionex.de>
date Tue, 16 Sep 2008 15:28:21 +0200
parents 0f12f6bb9739
children
comparison
equal deleted inserted replaced
314:0f7ac29ac726 315:21959e16bc1e
12 *******************************************************************************/ 12 *******************************************************************************/
13 module dwt.custom.CTabFolder2Listener; 13 module dwt.custom.CTabFolder2Listener;
14 14
15 import dwt.internal.DWTEventListener; 15 import dwt.internal.DWTEventListener;
16 import dwt.custom.CTabFolderEvent; 16 import dwt.custom.CTabFolderEvent;
17
18 import tango.core.Traits;
19 import tango.core.Tuple;
17 20
18 /** 21 /**
19 * Classes which implement this interface provide methods 22 * Classes which implement this interface provide methods
20 * that deal with the events that are generated by the CTabFolder 23 * that deal with the events that are generated by the CTabFolder
21 * control. 24 * control.
32 * @see CTabFolderEvent 35 * @see CTabFolderEvent
33 * 36 *
34 * @since 3.0 37 * @since 3.0
35 */ 38 */
36 public interface CTabFolder2Listener : DWTEventListener { 39 public interface CTabFolder2Listener : DWTEventListener {
40 public enum {
41 MINIMIZE,
42 MAXIMIZE,
43 SHOWLIST,
44 RESTORE,
45 CLOSE
46 }
37 47
38 /** 48 /**
39 * Sent when the user clicks on the close button of an item in the CTabFolder. 49 * Sent when the user clicks on the close button of an item in the CTabFolder.
40 * The item being closed is specified in the event.item field. 50 * The item being closed is specified in the event.item field.
41 * Setting the event.doit field to false will stop the CTabItem from closing. 51 * Setting the event.doit field to false will stop the CTabItem from closing.
111 * 121 *
112 * @see CTabFolder#setSelection(CTabItem) 122 * @see CTabFolder#setSelection(CTabItem)
113 */ 123 */
114 public void showList(CTabFolderEvent event); 124 public void showList(CTabFolderEvent event);
115 } 125 }
126
127
128
129 /// Helper class for the dgListener template function
130 private class _DgCTabFolder2ListenerT(Dg,T...) : CTabFolder2Listener {
131
132 alias ParameterTupleOf!(Dg) DgArgs;
133 static assert( is(DgArgs == Tuple!(CTabFolderEvent,T)),
134 "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" );
135
136 Dg dg;
137 T t;
138 int type;
139
140 private this( int type, Dg dg, T t ){
141 this.type = type;
142 this.dg = dg;
143 static if( T.length > 0 ){
144 this.t = t;
145 }
146 }
147
148 void itemClosed( CTabFolderEvent e ){
149 dg(e,t);
150 }
151 public void close(CTabFolderEvent e){
152 if( type is CTabFolder2Listener.CLOSE ){
153 dg(e,t);
154 }
155 }
156 public void minimize(CTabFolderEvent e){
157 if( type is CTabFolder2Listener.MINIMIZE ){
158 dg(e,t);
159 }
160 }
161 public void maximize(CTabFolderEvent e){
162 if( type is CTabFolder2Listener.MAXIMIZE ){
163 dg(e,t);
164 }
165 }
166 public void restore(CTabFolderEvent e){
167 if( type is CTabFolder2Listener.RESTORE ){
168 dg(e,t);
169 }
170 }
171 public void showList(CTabFolderEvent e){
172 if( type is CTabFolder2Listener.SHOWLIST ){
173 dg(e,t);
174 }
175 }
176 }
177
178 /++
179 + dgListener creates a class implementing the Listener interface and delegating the call to
180 + handleEvent to the users delegate. This template function will store also additional parameters.
181 +
182 + Examle of usage:
183 + ---
184 + void handleTextEvent ( Event e, int inset ) {
185 + // ...
186 + }
187 + text.addListener (DWT.FocusOut, dgListener( &handleTextEvent, inset ));
188 + ---
189 +/
190 CTabFolder2Listener dgCTabFolder2Listener( Dg, T... )( int type, Dg dg, T args ){
191 return new _DgCTabFolder2ListenerT!( Dg, T )( type, dg, args );
192 }
193
194
195