diff dwt/custom/CTabFolder2Listener.d @ 315:21959e16bc1e

Improved Listeners access functions.
author Frank Benoit <benoit@tionex.de>
date Tue, 16 Sep 2008 15:28:21 +0200
parents 0f12f6bb9739
children
line wrap: on
line diff
--- a/dwt/custom/CTabFolder2Listener.d	Mon Sep 08 01:35:33 2008 +0200
+++ b/dwt/custom/CTabFolder2Listener.d	Tue Sep 16 15:28:21 2008 +0200
@@ -15,6 +15,9 @@
 import dwt.internal.DWTEventListener;
 import dwt.custom.CTabFolderEvent;
 
+import tango.core.Traits;
+import tango.core.Tuple;
+
 /**
  * Classes which implement this interface provide methods
  * that deal with the events that are generated by the CTabFolder
@@ -34,6 +37,13 @@
  * @since 3.0
  */
 public interface CTabFolder2Listener : DWTEventListener {
+    public enum {
+        MINIMIZE,
+        MAXIMIZE,
+        SHOWLIST,
+        RESTORE,
+        CLOSE
+    }
 
 /**
  * Sent when the user clicks on the close button of an item in the CTabFolder.
@@ -113,3 +123,73 @@
  */
 public void showList(CTabFolderEvent event);
 }
+
+
+
+/// Helper class for the dgListener template function
+private class _DgCTabFolder2ListenerT(Dg,T...) : CTabFolder2Listener {
+
+    alias ParameterTupleOf!(Dg) DgArgs;
+    static assert( is(DgArgs == Tuple!(CTabFolderEvent,T)),
+                "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" );
+
+    Dg dg;
+    T  t;
+    int type;
+
+    private this( int type, Dg dg, T t ){
+        this.type = type;
+        this.dg = dg;
+        static if( T.length > 0 ){
+            this.t = t;
+        }
+    }
+
+    void itemClosed( CTabFolderEvent e ){
+        dg(e,t);
+    }
+    public void close(CTabFolderEvent e){
+        if( type is CTabFolder2Listener.CLOSE ){
+            dg(e,t);
+        }
+    }
+    public void minimize(CTabFolderEvent e){
+        if( type is CTabFolder2Listener.MINIMIZE ){
+            dg(e,t);
+        }
+    }
+    public void maximize(CTabFolderEvent e){
+        if( type is CTabFolder2Listener.MAXIMIZE ){
+            dg(e,t);
+        }
+    }
+    public void restore(CTabFolderEvent e){
+        if( type is CTabFolder2Listener.RESTORE ){
+            dg(e,t);
+        }
+    }
+    public void showList(CTabFolderEvent e){
+        if( type is CTabFolder2Listener.SHOWLIST ){
+            dg(e,t);
+        }
+    }
+}
+
+/++
+ + dgListener creates a class implementing the Listener interface and delegating the call to
+ + handleEvent to the users delegate. This template function will store also additional parameters.
+ +
+ + Examle of usage:
+ + ---
+ + void handleTextEvent ( Event e, int inset ) {
+ +     // ...
+ + }
+ + text.addListener (DWT.FocusOut, dgListener( &handleTextEvent, inset ));
+ + ---
+ +/
+CTabFolder2Listener dgCTabFolder2Listener( Dg, T... )( int type, Dg dg, T args ){
+    return new _DgCTabFolder2ListenerT!( Dg, T )( type, dg, args );
+}
+
+
+