Show
Ignore:
Timestamp:
09/16/08 09:19:38 (4 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Improved Listeners access functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/events/SelectionListener.d

    r253 r311  
    1616public import dwt.internal.DWTEventListener; 
    1717public import dwt.events.SelectionEvent; 
     18 
     19import tango.core.Traits; 
     20import tango.core.Tuple; 
    1821 
    1922/** 
     
    3538public interface SelectionListener : DWTEventListener { 
    3639 
     40    public enum { 
     41        SELECTION, 
     42        DEFAULTSELECTION 
     43    } 
    3744/** 
    3845 * Sent when selection occurs in the control. 
     
    6673 
    6774 
     75/// DWT extension 
     76private class _DgSelectionListenerT(Dg,T...) : SelectionListener { 
    6877 
    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; 
    7379    static assert( is(DgArgs == Tuple!(SelectionEvent,T)), 
    74                 "Delegate args not correct" ); 
     80                "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" ); 
    7581 
    7682    Dg dg; 
    7783    T  t; 
     84    int type; 
    7885 
    79     private this( Dg dg, T t ){ 
     86    private this( int type, Dg dg, T t ){ 
     87        this.type = type; 
    8088        this.dg = dg; 
    8189        static if( T.length > 0 ){ 
     
    8593 
    8694    public void widgetSelected(SelectionEvent e){ 
    87         dg(e,t); 
     95        if( type is SelectionListener.SELECTION ){ 
     96            dg(e,t); 
     97        } 
    8898    } 
    8999    public void widgetDefaultSelected(SelectionEvent e){ 
     100        if( type is SelectionListener.DEFAULTSELECTION ){ 
     101            dg(e,t); 
     102        } 
    90103    } 
    91104} 
    92105 
    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     } 
     106SelectionListener dgSelectionListener( Dg, T... )( int type, Dg dg, T args ){ 
     107    return new _DgSelectionListenerT!( Dg, T )( type, dg, args ); 
    114108} 
    115109 
    116110SelectionListener dgSelectionListenerWidgetSelected( Dg, T... )( Dg dg, T args ){ 
    117     return new _DgSelectionListenerWidgetSelectedT!( Dg, T )( dg, args ); 
     111    return dgSelectionListener( SelectionListener.SELECTION, dg, args ); 
    118112} 
    119113SelectionListener dgSelectionListenerWidgetDefaultSelected( Dg, T... )( Dg dg, T args ){ 
    120     return new _DgSelectionListenerWidgetDefaultSelectedT!( Dg, T )( dg, args ); 
     114    return dgSelectionListener( SelectionListener.DEFAULTSELECTION, dg, args ); 
    121115} 
    122116 
    123  
    124