root/dwt/events/SelectionListener.d

Revision 311:02332a154347, 3.7 kB (checked in by Frank Benoit <benoit@tionex.de>, 3 months ago)

Improved Listeners access functions.

Line 
1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module dwt.events.SelectionListener;
14
15
16 public import dwt.internal.DWTEventListener;
17 public import dwt.events.SelectionEvent;
18
19 import tango.core.Traits;
20 import tango.core.Tuple;
21
22 /**
23  * Classes which implement this interface provide methods
24  * that deal with the events that are generated when selection
25  * occurs in a control.
26  * <p>
27  * After creating an instance of a class that :
28  * this interface it can be added to a control using the
29  * <code>addSelectionListener</code> method and removed using
30  * the <code>removeSelectionListener</code> method. When
31  * selection occurs in a control the appropriate method
32  * will be invoked.
33  * </p>
34  *
35  * @see SelectionAdapter
36  * @see SelectionEvent
37  */
38 public interface SelectionListener : DWTEventListener {
39
40     public enum {
41         SELECTION,
42         DEFAULTSELECTION
43     }
44 /**
45  * Sent when selection occurs in the control.
46  * <p>
47  * For example, selection occurs in a List when the user selects
48  * an item or items with the keyboard or mouse.  On some platforms,
49  * the event occurs when a mouse button or key is pressed.  On others,
50  * it happens when the mouse or key is released.  The exact key or
51  * mouse gesture that causes this event is platform specific.
52  * </p>
53  *
54  * @param e an event containing information about the selection
55  */
56 public void widgetSelected(SelectionEvent e);
57
58 /**
59  * Sent when default selection occurs in the control.
60  * <p>
61  * For example, on some platforms default selection occurs in a List
62  * when the user double-clicks an item or types return in a Text.
63  * On some platforms, the event occurs when a mouse button or key is
64  * pressed.  On others, it happens when the mouse or key is released.
65  * The exact key or mouse gesture that causes this event is platform
66  * specific.
67  * </p>
68  *
69  * @param e an event containing information about the default selection
70  */
71 public void widgetDefaultSelected(SelectionEvent e);
72 }
73
74
75 /// DWT extension
76 private class _DgSelectionListenerT(Dg,T...) : SelectionListener {
77
78     alias ParameterTupleOf!(Dg) DgArgs;
79     static assert( is(DgArgs == Tuple!(SelectionEvent,T)),
80                 "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" );
81
82     Dg dg;
83     T  t;
84     int type;
85
86     private this( int type, Dg dg, T t ){
87         this.type = type;
88         this.dg = dg;
89         static if( T.length > 0 ){
90             this.t = t;
91         }
92     }
93
94     public void widgetSelected(SelectionEvent e){
95         if( type is SelectionListener.SELECTION ){
96             dg(e,t);
97         }
98     }
99     public void widgetDefaultSelected(SelectionEvent e){
100         if( type is SelectionListener.DEFAULTSELECTION ){
101             dg(e,t);
102         }
103     }
104 }
105
106 SelectionListener dgSelectionListener( Dg, T... )( int type, Dg dg, T args ){
107     return new _DgSelectionListenerT!( Dg, T )( type, dg, args );
108 }
109
110 SelectionListener dgSelectionListenerWidgetSelected( Dg, T... )( Dg dg, T args ){
111     return dgSelectionListener( SelectionListener.SELECTION, dg, args );
112 }
113 SelectionListener dgSelectionListenerWidgetDefaultSelected( Dg, T... )( Dg dg, T args ){
114     return dgSelectionListener( SelectionListener.DEFAULTSELECTION, dg, args );
115 }
Note: See TracBrowser for help on using the browser.