root/dwt/widgets/Event.d

Revision 246:fd9c62a2998e, 6.5 kB (checked in by Frank Benoit <benoit@tionex.de>, 5 months ago)

Updater SWT 3.4M7 to 3.4

Line 
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 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.widgets.Event;
14
15 import dwt.graphics.GC;
16 import dwt.graphics.Rectangle;
17
18 import dwt.widgets.Widget;
19 import dwt.widgets.Display;
20
21 import tango.text.convert.Format;
22 import dwt.dwthelper.utils;
23
24
25 /**
26  * Instances of this class provide a description of a particular
27  * event which occurred within DWT. The DWT <em>untyped listener</em>
28  * API uses these instances for all event dispatching.
29  * <p>
30  * Note: For a given event, only the fields which are appropriate
31  * will be filled in. The contents of the fields which are not used
32  * by the event are unspecified.
33  * </p>
34  *
35  * @see Listener
36  * @see dwt.events.TypedEvent
37  * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Listeners</a>
38  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
39  */
40
41 public class Event {
42
43     /**
44      * the display where the event occurred
45      *
46      * @since 2.0
47      */
48     public Display display;
49
50     /**
51      * the widget that issued the event
52      */
53     public Widget widget;
54
55     /**
56      * the type of event, as defined by the event type constants
57      * in class <code>DWT</code>
58      *
59      * @see dwt.DWT
60      */
61     public int type;
62
63     /**
64      * the event specific detail field, as defined by the detail constants
65      * in class <code>DWT</code>
66      *
67      * @see dwt.DWT
68      */
69     public int detail;
70
71     /**
72      * the item that the event occurred in (can be null)
73      */
74     public Widget item;
75
76     /**
77      * the index of the item where the event occurred
78      *
79      * @since 3.2
80      */
81     public int index;
82
83     /**
84      * the graphics context to use when painting
85      * that is configured to use the colors, font and
86      * damaged region of the control.  It is valid
87      * only during the paint and must not be disposed
88      */
89     public GC gc;
90
91     /**
92      * depending on the event type, the x offset of the bounding
93      * rectangle of the region that requires painting or the
94      * widget-relative, x coordinate of the pointer at the
95      * time the mouse button was pressed or released
96      */
97     public int x;
98
99     /**
100      * depending on the event type, the y offset of the bounding
101      * rectangle of the  region that requires painting or the
102      * widget-relative, y coordinate of the pointer at the
103      * time the mouse button was pressed or released
104      */
105     public int y;
106
107     /**
108      * the width of the bounding rectangle of the
109      * region that requires painting
110      */
111     public int width;
112
113     /**
114      * the height of the bounding rectangle of the
115      * region that requires painting
116      */
117     public int height;
118
119     /**
120      * depending on the event type, the number of following
121      * paint events which are pending which may always be zero
122      * on some platforms or the number of lines or pages to
123      * scroll using the mouse wheel
124      */
125     public int count;
126
127     /**
128      * the time that the event occurred.
129      *
130      * NOTE: This field is an unsigned integer and should
131      * be AND'ed with 0xFFFFFFFFL so that it can be treated
132      * as a signed long.
133      */
134     public int time;
135
136     /**
137      * the button that was pressed or released; 1 for the
138      * first button, 2 for the second button, and 3 for the
139      * third button, etc.
140      */
141     public int button;
142
143     /**
144      * depending on the event, the character represented by the key
145      * that was typed.  This is the final character that results
146      * after all modifiers have been applied.  For example, when the
147      * user types Ctrl+A, the character value is 0x01 (ASCII SOH).
148      * It is important that applications do not attempt to modify the
149      * character value based on a stateMask (such as DWT.CTRL) or the
150      * resulting character will not be correct.
151      */
152     public wchar character = '\0';
153
154     /**
155      * depending on the event, the key code of the key that was typed,
156      * as defined by the key code constants in class <code>DWT</code>.
157      * When the character field of the event is ambiguous, this field
158      * contains the unaffected value of the original character.  For
159      * example, typing Ctrl+M or Enter both result in the character '\r'
160      * but the keyCode field will also contain '\r' when Enter was typed
161      * and 'm' when Ctrl+M was typed.
162      *
163      * @see dwt.DWT
164      */
165     public int keyCode;
166
167     /**
168      * depending on the event, the state of the keyboard modifier
169      * keys and mouse masks at the time the event was generated.
170      *
171      * @see dwt.DWT
172      */
173     public int stateMask;
174
175     /**
176      * depending on the event, the range of text being modified.
177      * Setting these fields only has effect during ImeComposition
178      * events.
179      */
180     public int start, end;
181
182     /**
183      * depending on the event, the new text that will be inserted.
184      * Setting this field will change the text that is about to
185      * be inserted or deleted.
186      */
187     public String text;
188
189     /**
190      * depending on the event, a flag indicating whether the operation
191      * should be allowed.  Setting this field to false will cancel the
192      * operation.
193      */
194     public bool doit = true;
195
196     /**
197      * a field for application use
198      */
199     public Object data;
200
201 /**
202  * Gets the bounds.
203  *
204  * @return a rectangle that is the bounds.
205  */
206 public Rectangle getBounds () {
207     return new Rectangle (x, y, width, height);
208 }
209
210 /**
211  * Sets the bounds.
212  *
213  * @param rect the new rectangle
214  */
215 public void setBounds (Rectangle rect) {
216     this.x = rect.x;
217     this.y = rect.y;
218     this.width = rect.width;
219     this.height = rect.height;
220 }
221
222 /**
223  * Returns a string containing a concise, human-readable
224  * description of the receiver.
225  *
226  * @return a string representation of the event
227  */
228 override public String toString () {
229     return Format( "Event {{type={} {} time={} data={} x={} y={} width={} height={} detail={}}",
230         type, widget, time, data, x, y, width, height, detail );  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
231 }
232 }
Note: See TracBrowser for help on using the browser.