Mercurial > projects > dwt-linux
comparison dwt/events/SelectionListener.d @ 315:21959e16bc1e
Improved Listeners access functions.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 16 Sep 2008 15:28:21 +0200 |
parents | 5899e0b43e5d |
children |
comparison
equal
deleted
inserted
replaced
314:0f7ac29ac726 | 315:21959e16bc1e |
---|---|
13 module dwt.events.SelectionListener; | 13 module dwt.events.SelectionListener; |
14 | 14 |
15 | 15 |
16 public import dwt.internal.DWTEventListener; | 16 public import dwt.internal.DWTEventListener; |
17 public import dwt.events.SelectionEvent; | 17 public import dwt.events.SelectionEvent; |
18 | |
19 import tango.core.Traits; | |
20 import tango.core.Tuple; | |
18 | 21 |
19 /** | 22 /** |
20 * Classes which implement this interface provide methods | 23 * Classes which implement this interface provide methods |
21 * that deal with the events that are generated when selection | 24 * that deal with the events that are generated when selection |
22 * occurs in a control. | 25 * occurs in a control. |
32 * @see SelectionAdapter | 35 * @see SelectionAdapter |
33 * @see SelectionEvent | 36 * @see SelectionEvent |
34 */ | 37 */ |
35 public interface SelectionListener : DWTEventListener { | 38 public interface SelectionListener : DWTEventListener { |
36 | 39 |
40 public enum { | |
41 SELECTION, | |
42 DEFAULTSELECTION | |
43 } | |
37 /** | 44 /** |
38 * Sent when selection occurs in the control. | 45 * Sent when selection occurs in the control. |
39 * <p> | 46 * <p> |
40 * For example, selection occurs in a List when the user selects | 47 * For example, selection occurs in a List when the user selects |
41 * an item or items with the keyboard or mouse. On some platforms, | 48 * an item or items with the keyboard or mouse. On some platforms, |
61 * | 68 * |
62 * @param e an event containing information about the default selection | 69 * @param e an event containing information about the default selection |
63 */ | 70 */ |
64 public void widgetDefaultSelected(SelectionEvent e); | 71 public void widgetDefaultSelected(SelectionEvent e); |
65 } | 72 } |
73 | |
74 | |
75 /// DWT extension | |
76 private class _DgSelectionListenerT(Dg,T...) : SelectionListener { | |
77 | |
78 alias ParameterTupleOf!(Dg) DgArgs; | |
79 static assert( is(DgArgs == Tuple!(SelectionEvent,T)), | |
80 "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" ); | |
81 | |
82 Dg dg; | |
83 T t; | |
84 int type; | |
85 | |
86 private this( int type, Dg dg, T t ){ | |
87 this.type = type; | |
88 this.dg = dg; | |
89 static if( T.length > 0 ){ | |
90 this.t = t; | |
91 } | |
92 } | |
93 | |
94 public void widgetSelected(SelectionEvent e){ | |
95 if( type is SelectionListener.SELECTION ){ | |
96 dg(e,t); | |
97 } | |
98 } | |
99 public void widgetDefaultSelected(SelectionEvent e){ | |
100 if( type is SelectionListener.DEFAULTSELECTION ){ | |
101 dg(e,t); | |
102 } | |
103 } | |
104 } | |
105 | |
106 SelectionListener dgSelectionListener( Dg, T... )( int type, Dg dg, T args ){ | |
107 return new _DgSelectionListenerT!( Dg, T )( type, dg, args ); | |
108 } | |
109 | |
110 SelectionListener dgSelectionListenerWidgetSelected( Dg, T... )( Dg dg, T args ){ | |
111 return dgSelectionListener( SelectionListener.SELECTION, dg, args ); | |
112 } | |
113 SelectionListener dgSelectionListenerWidgetDefaultSelected( Dg, T... )( Dg dg, T args ){ | |
114 return dgSelectionListener( SelectionListener.DEFAULTSELECTION, dg, args ); | |
115 } | |
116 |