Changeset 311:02332a154347 for dwt/events/SelectionListener.d
- Timestamp:
- 09/16/08 09:19:38 (4 months ago)
- Files:
-
- dwt/events/SelectionListener.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/events/SelectionListener.d
r253 r311 16 16 public import dwt.internal.DWTEventListener; 17 17 public import dwt.events.SelectionEvent; 18 19 import tango.core.Traits; 20 import tango.core.Tuple; 18 21 19 22 /** … … 35 38 public interface SelectionListener : DWTEventListener { 36 39 40 public enum { 41 SELECTION, 42 DEFAULTSELECTION 43 } 37 44 /** 38 45 * Sent when selection occurs in the control. … … 66 73 67 74 75 /// DWT extension 76 private class _DgSelectionListenerT(Dg,T...) : SelectionListener { 68 77 69 /// Helper class for the dgListener template function 70 private class _DgSelectionListenerWidgetSelectedT(Dg,T...) : SelectionListener { 71 72 alias ParameterTupleOf!(DgSel) DgArgs; 78 alias ParameterTupleOf!(Dg) DgArgs; 73 79 static assert( is(DgArgs == Tuple!(SelectionEvent,T)), 74 "Delegate args not correct " );80 "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" ); 75 81 76 82 Dg dg; 77 83 T t; 84 int type; 78 85 79 private this( Dg dg, T t ){ 86 private this( int type, Dg dg, T t ){ 87 this.type = type; 80 88 this.dg = dg; 81 89 static if( T.length > 0 ){ … … 85 93 86 94 public void widgetSelected(SelectionEvent e){ 87 dg(e,t); 95 if( type is SelectionListener.SELECTION ){ 96 dg(e,t); 97 } 88 98 } 89 99 public void widgetDefaultSelected(SelectionEvent e){ 100 if( type is SelectionListener.DEFAULTSELECTION ){ 101 dg(e,t); 102 } 90 103 } 91 104 } 92 105 93 private class _DgSelectionListenerWidgetDefaultSelectedT(Dg,T...) : SelectionListener { 94 95 alias ParameterTupleOf!(DgSel) DgArgs; 96 static assert( is(DgArgs == Tuple!(SelectionEvent,T)), 97 "Delegate args not correct" ); 98 99 Dg dg; 100 T t; 101 102 private this( Dg dg, T t ){ 103 this.dg = dg; 104 static if( T.length > 0 ){ 105 this.t = t; 106 } 107 } 108 109 public void widgetSelected(SelectionEvent e){ 110 } 111 public void widgetDefaultSelected(SelectionEvent e){ 112 dg(e,t); 113 } 106 SelectionListener dgSelectionListener( Dg, T... )( int type, Dg dg, T args ){ 107 return new _DgSelectionListenerT!( Dg, T )( type, dg, args ); 114 108 } 115 109 116 110 SelectionListener dgSelectionListenerWidgetSelected( Dg, T... )( Dg dg, T args ){ 117 return new _DgSelectionListenerWidgetSelectedT!( Dg, T )(dg, args );111 return dgSelectionListener( SelectionListener.SELECTION, dg, args ); 118 112 } 119 113 SelectionListener dgSelectionListenerWidgetDefaultSelected( Dg, T... )( Dg dg, T args ){ 120 return new _DgSelectionListenerWidgetDefaultSelectedT!( Dg, T )(dg, args );114 return dgSelectionListener( SelectionListener.DEFAULTSELECTION, dg, args ); 121 115 } 122 116 123 124
