Changeset 243:84629474b5ec

Show
Ignore:
Timestamp:
05/17/08 17:22:11 (3 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Add dgListener template function for the Listener class

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/widgets/Listener.d

    r72 r243  
    1414 
    1515import dwt.widgets.Event; 
     16 
     17import tango.core.Traits; 
     18import tango.core.Tuple; 
    1619 
    1720/** 
     
    5457void handleEvent (Event event); 
    5558} 
     59 
     60/// Helper class for the dgListener template function 
     61private class _DgListenerT(Dg,T...) : Listener { 
     62 
     63    alias ParameterTupleOf!(Dg) DgArgs; 
     64    static assert( is(DgArgs == Tuple!(Event,T)), 
     65                "Delegate args not correct" ); 
     66 
     67    Dg dg; 
     68    T  t; 
     69 
     70    private this( Dg dg, T t ){ 
     71        this.dg = dg; 
     72        static if( T.length > 0 ){ 
     73            this.t = t; 
     74        } 
     75    } 
     76 
     77    void handleEvent( Event e ){ 
     78        dg(e,t); 
     79    } 
     80} 
     81 
     82/++ 
     83 + dgListener creates a class implementing the Listener interface and delegating the call to 
     84 + handleEvent to the users delegate. This template function will store also additional parameters. 
     85 + 
     86 + Examle of usage: 
     87 + --- 
     88 + void handleTextEvent (Event e, int inset ) { 
     89 +     // ... 
     90 + } 
     91 + text.addListener (DWT.FocusOut, dgListener( &handleTextEvent, inset )); 
     92 + --- 
     93 +/ 
     94Listener dgListener( Dg, T... )( Dg dg, T args ){ 
     95    return new _DgListenerT!( Dg, T )( dg, args ); 
     96} 
     97 
     98 
     99 
     100 
     101 
     102 
     103