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/custom/CTabFolder2Listener.d

    r155 r311  
    1515import dwt.internal.DWTEventListener; 
    1616import dwt.custom.CTabFolderEvent; 
     17 
     18import tango.core.Traits; 
     19import tango.core.Tuple; 
    1720 
    1821/** 
     
    3538 */ 
    3639public interface CTabFolder2Listener : DWTEventListener { 
     40    public enum { 
     41        MINIMIZE, 
     42        MAXIMIZE, 
     43        SHOWLIST, 
     44        RESTORE, 
     45        CLOSE 
     46    } 
    3747 
    3848/** 
     
    114124public void showList(CTabFolderEvent event); 
    115125} 
     126 
     127 
     128 
     129/// Helper class for the dgListener template function 
     130private 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 +/ 
     190CTabFolder2Listener dgCTabFolder2Listener( Dg, T... )( int type, Dg dg, T args ){ 
     191    return new _DgCTabFolder2ListenerT!( Dg, T )( type, dg, args ); 
     192} 
     193 
     194 
     195