# HG changeset patch # User Frank Benoit # Date 1221571701 -7200 # Node ID 21959e16bc1e3a170130c6453ab56caf8df5a5ac # Parent 0f7ac29ac72685f7ef20f2bc7cd33cf8bfdf75c8 Improved Listeners access functions. diff -r 0f7ac29ac726 -r 21959e16bc1e dwt/custom/CTabFolder2Listener.d --- 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 ); +} + + + diff -r 0f7ac29ac726 -r 21959e16bc1e dwt/custom/CTabFolderListener.d --- a/dwt/custom/CTabFolderListener.d Mon Sep 08 01:35:33 2008 +0200 +++ b/dwt/custom/CTabFolderListener.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 a method * that deals with events generated in the CTabFolder. @@ -42,3 +45,46 @@ */ public void itemClosed(CTabFolderEvent event); } + + + +/// Helper class for the dgListener template function +private class _DgCTabFolderListenerT(Dg,T...) : CTabFolderListener { + + alias ParameterTupleOf!(Dg) DgArgs; + static assert( is(DgArgs == Tuple!(CTabFolderEvent,T)), + "Delegate args not correct" ); + + Dg dg; + T t; + + private this( Dg dg, T t ){ + this.dg = dg; + static if( T.length > 0 ){ + this.t = t; + } + } + + void itemClosed( CTabFolderEvent e ){ + 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 )); + + --- + +/ +CTabFolderListener dgCTabFolderListener( Dg, T... )( Dg dg, T args ){ + return new _DgCTabFolderListenerT!( Dg, T )( dg, args ); +} + + + diff -r 0f7ac29ac726 -r 21959e16bc1e dwt/dwthelper/Runnable.d --- a/dwt/dwthelper/Runnable.d Mon Sep 08 01:35:33 2008 +0200 +++ b/dwt/dwthelper/Runnable.d Tue Sep 16 15:28:21 2008 +0200 @@ -17,7 +17,7 @@ alias ParameterTupleOf!(Dg) DgArgs; static assert( is(DgArgs == Tuple!(T)), - "Delegate args not correct" ); + "Delegate args not correct: "~DgArgs.stringof~" vs "~T.stringof ); Dg dg; T t; @@ -36,4 +36,4 @@ _DgRunnableT!(Dg,T) dgRunnable(Dg,T...)( Dg dg, T args ){ return new _DgRunnableT!(Dg,T)(dg,args); -} \ No newline at end of file +} diff -r 0f7ac29ac726 -r 21959e16bc1e dwt/events/SelectionListener.d --- a/dwt/events/SelectionListener.d Mon Sep 08 01:35:33 2008 +0200 +++ b/dwt/events/SelectionListener.d Tue Sep 16 15:28:21 2008 +0200 @@ -16,6 +16,9 @@ public import dwt.internal.DWTEventListener; public import dwt.events.SelectionEvent; +import tango.core.Traits; +import tango.core.Tuple; + /** * Classes which implement this interface provide methods * that deal with the events that are generated when selection @@ -34,6 +37,10 @@ */ public interface SelectionListener : DWTEventListener { + public enum { + SELECTION, + DEFAULTSELECTION + } /** * Sent when selection occurs in the control. *

@@ -63,3 +70,47 @@ */ public void widgetDefaultSelected(SelectionEvent e); } + + +/// DWT extension +private class _DgSelectionListenerT(Dg,T...) : SelectionListener { + + alias ParameterTupleOf!(Dg) DgArgs; + static assert( is(DgArgs == Tuple!(SelectionEvent,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; + } + } + + public void widgetSelected(SelectionEvent e){ + if( type is SelectionListener.SELECTION ){ + dg(e,t); + } + } + public void widgetDefaultSelected(SelectionEvent e){ + if( type is SelectionListener.DEFAULTSELECTION ){ + dg(e,t); + } + } +} + +SelectionListener dgSelectionListener( Dg, T... )( int type, Dg dg, T args ){ + return new _DgSelectionListenerT!( Dg, T )( type, dg, args ); +} + +SelectionListener dgSelectionListenerWidgetSelected( Dg, T... )( Dg dg, T args ){ + return dgSelectionListener( SelectionListener.SELECTION, dg, args ); +} +SelectionListener dgSelectionListenerWidgetDefaultSelected( Dg, T... )( Dg dg, T args ){ + return dgSelectionListener( SelectionListener.DEFAULTSELECTION, dg, args ); +} + diff -r 0f7ac29ac726 -r 21959e16bc1e dwt/widgets/Listener.d --- a/dwt/widgets/Listener.d Mon Sep 08 01:35:33 2008 +0200 +++ b/dwt/widgets/Listener.d Tue Sep 16 15:28:21 2008 +0200 @@ -57,12 +57,13 @@ void handleEvent (Event event); } + /// Helper class for the dgListener template function private class _DgListenerT(Dg,T...) : Listener { alias ParameterTupleOf!(Dg) DgArgs; static assert( is(DgArgs == Tuple!(Event,T)), - "Delegate args not correct" ); + "Delegate args not correct: delegate args: ("~DgArgs.stringof~") vs. passed args: ("~Tuple!(Event,T).stringof~")" ); Dg dg; T t; @@ -97,7 +98,3 @@ - - - -