Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/events/SelectionListener.d @ 49:7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 27 Mar 2009 12:59:54 +0100 |
parents | ddbfe84d86df |
children | 536e43f63c81 |
rev | line source |
---|---|
25 | 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 org.eclipse.swt.events.SelectionListener; | |
14 | |
15 import java.lang.all; | |
16 | |
17 | |
18 public import org.eclipse.swt.internal.SWTEventListener; | |
19 public import org.eclipse.swt.events.SelectionEvent; | |
20 | |
48 | 21 version(Tango){ |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
22 import tango.core.Traits; |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
23 import tango.core.Tuple; |
48 | 24 } else { // Phobos |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
25 import std.traits; |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
26 import std.typetuple; |
48 | 27 } |
25 | 28 |
29 /** | |
30 * Classes which implement this interface provide methods | |
31 * that deal with the events that are generated when selection | |
32 * occurs in a control. | |
33 * <p> | |
34 * After creating an instance of a class that : | |
35 * this interface it can be added to a control using the | |
36 * <code>addSelectionListener</code> method and removed using | |
37 * the <code>removeSelectionListener</code> method. When | |
38 * selection occurs in a control the appropriate method | |
39 * will be invoked. | |
40 * </p> | |
41 * | |
42 * @see SelectionAdapter | |
43 * @see SelectionEvent | |
44 */ | |
45 public interface SelectionListener : SWTEventListener { | |
46 | |
47 public enum { | |
48 SELECTION, | |
49 DEFAULTSELECTION | |
50 } | |
51 /** | |
52 * Sent when selection occurs in the control. | |
53 * <p> | |
54 * For example, selection occurs in a List when the user selects | |
55 * an item or items with the keyboard or mouse. On some platforms, | |
56 * the event occurs when a mouse button or key is pressed. On others, | |
57 * it happens when the mouse or key is released. The exact key or | |
58 * mouse gesture that causes this event is platform specific. | |
59 * </p> | |
60 * | |
61 * @param e an event containing information about the selection | |
62 */ | |
63 public void widgetSelected(SelectionEvent e); | |
64 | |
65 /** | |
66 * Sent when default selection occurs in the control. | |
67 * <p> | |
68 * For example, on some platforms default selection occurs in a List | |
69 * when the user double-clicks an item or types return in a Text. | |
70 * On some platforms, the event occurs when a mouse button or key is | |
71 * pressed. On others, it happens when the mouse or key is released. | |
72 * The exact key or mouse gesture that causes this event is platform | |
73 * specific. | |
74 * </p> | |
75 * | |
76 * @param e an event containing information about the default selection | |
77 */ | |
78 public void widgetDefaultSelected(SelectionEvent e); | |
79 } | |
80 | |
81 | |
82 /// SWT extension | |
83 private class _DgSelectionListenerT(Dg,T...) : SelectionListener { | |
84 | |
49
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
85 version(Tango){ |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
86 alias ParameterTupleOf!(Dg) DgArgs; |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
87 static assert( is(DgArgs == Tuple!(SelectionEvent,T)), |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
88 "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" ); |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
89 } else { // Phobos |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
90 alias ParameterTypeTuple!(Dg) DgArgs; |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
91 static assert( is(DgArgs == TypeTuple!(SelectionEvent,T)), |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
92 "Delegate args not correct: "~DgArgs.stringof~" vs. (Event,"~T.stringof~")" ); |
7a2dd761a8b2
more work until dmd 2.026 linux segfaults.
Frank Benoit <benoit@tionex.de>
parents:
48
diff
changeset
|
93 } |
25 | 94 |
95 Dg dg; | |
96 T t; | |
97 int type; | |
98 | |
99 private this( int type, Dg dg, T t ){ | |
100 this.type = type; | |
101 this.dg = dg; | |
102 static if( T.length > 0 ){ | |
103 this.t = t; | |
104 } | |
105 } | |
106 | |
107 public void widgetSelected(SelectionEvent e){ | |
108 if( type is SelectionListener.SELECTION ){ | |
109 dg(e,t); | |
110 } | |
111 } | |
112 public void widgetDefaultSelected(SelectionEvent e){ | |
113 if( type is SelectionListener.DEFAULTSELECTION ){ | |
114 dg(e,t); | |
115 } | |
116 } | |
117 } | |
118 | |
119 SelectionListener dgSelectionListener( Dg, T... )( int type, Dg dg, T args ){ | |
120 return new _DgSelectionListenerT!( Dg, T )( type, dg, args ); | |
121 } | |
122 | |
123 SelectionListener dgSelectionListenerWidgetSelected( Dg, T... )( Dg dg, T args ){ | |
124 return dgSelectionListener( SelectionListener.SELECTION, dg, args ); | |
125 } | |
126 SelectionListener dgSelectionListenerWidgetDefaultSelected( Dg, T... )( Dg dg, T args ){ | |
127 return dgSelectionListener( SelectionListener.DEFAULTSELECTION, dg, args ); | |
128 } | |
129 |