1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.widgets;
17 import org.eclipse.swt.graphics.*;
18 import org.eclipse.swt.internal.*;
21 * Instances of this class provide a description of a particular
22 * event which occurred within SWT. The SWT <em>untyped listener</em>
23 * API uses these instances for all event dispatching.
25 * Note: For a given event, only the fields which are appropriate
26 * will be filled in. The contents of the fields which are not used
27 * by the event are unspecified.
31 * @see org.eclipse.swt.events.TypedEvent
32 * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Listeners</a>
33 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
39 * the display where the event occurred
43 public Display display;
46 * the widget that issued the event
51 * the type of event, as defined by the event type constants
52 * in class <code>SWT</code>
54 * @see org.eclipse.swt.SWT
59 * the event specific detail field, as defined by the detail constants
60 * in class <code>SWT</code>
62 * @see org.eclipse.swt.SWT
67 * the item that the event occurred in (can be null)
72 * the index of the item where the event occurred
79 * the graphics context to use when painting
80 * that is configured to use the colors, font and
81 * damaged region of the control. It is valid
82 * only during the paint and must not be disposed
87 * depending on the event type, the x offset of the bounding
88 * rectangle of the region that requires painting or the
89 * widget-relative, x coordinate of the pointer at the
90 * time the mouse button was pressed or released
95 * depending on the event type, the y offset of the bounding
96 * rectangle of the region that requires painting or the
97 * widget-relative, y coordinate of the pointer at the
98 * time the mouse button was pressed or released
103 * the width of the bounding rectangle of the
104 * region that requires painting
109 * the height of the bounding rectangle of the
110 * region that requires painting
115 * depending on the event type, the number of following
116 * paint events that are pending which may always be zero
117 * on some platforms, or the number of lines or pages to
118 * scroll using the mouse wheel, or the number of times the
119 * mouse has been clicked
124 * the time that the event occurred.
126 * NOTE: This field is an unsigned integer and should
127 * be AND'ed with 0xFFFFFFFFL so that it can be treated
133 * the button that was pressed or released; 1 for the
134 * first button, 2 for the second button, and 3 for the
140 * depending on the event, the character represented by the key
141 * that was typed. This is the final character that results
142 * after all modifiers have been applied. For example, when the
143 * user types Ctrl+A, the character value is 0x01 (ASCII SOH).
144 * It is important that applications do not attempt to modify the
145 * character value based on a stateMask (such as SWT.CTRL) or the
146 * resulting character will not be correct.
148 public char character;
151 * depending on the event, the key code of the key that was typed,
152 * as defined by the key code constants in class <code>SWT</code>.
153 * When the character field of the event is ambiguous, this field
154 * contains the unaffected value of the original character. For
155 * example, typing Ctrl+M or Enter both result in the character '\r'
156 * but the keyCode field will also contain '\r' when Enter was typed
157 * and 'm' when Ctrl+M was typed.
159 * @see org.eclipse.swt.SWT
164 * depending on the event, the location of key specified by the
165 * keyCode or character. The possible values for this field are
166 * <code>SWT.LEFT</code>, <code>SWT.RIGHT</code>, <code>SWT.KEYPAD</code>,
167 * or <code>SWT.NONE</code> representing the main keyboard area.
169 * The location field can be used to differentiate key events that have
170 * the same key code and character but are generated by different keys
171 * in the keyboard. For example, a key down event with the key code equals
172 * to SWT.SHIFT can be generated by the left and the right shift keys in the
173 * keyboard. The location field can only be used to determine the location
174 * of the key code or character in the current event. It does not
175 * include information about the location of modifiers in state
179 * @see org.eclipse.swt.SWT#LEFT
180 * @see org.eclipse.swt.SWT#RIGHT
181 * @see org.eclipse.swt.SWT#KEYPAD
185 public int keyLocation;
188 * depending on the event, the state of the keyboard modifier
189 * keys and mouse masks at the time the event was generated.
191 * @see org.eclipse.swt.SWT#MODIFIER_MASK
192 * @see org.eclipse.swt.SWT#BUTTON_MASK
194 public int stateMask;
197 * depending on the event, the range of text being modified.
198 * Setting these fields only has effect during ImeComposition
201 public int start, end;
204 * depending on the event, the new text that will be inserted.
205 * Setting this field will change the text that is about to
206 * be inserted or deleted.
211 * Bidi segment offsets
214 public int[] segments;
217 * Characters to be applied on the segment boundaries
220 public char[] segmentsChars;
223 * depending on the event, a flag indicating whether the operation
224 * should be allowed. Setting this field to false will cancel the
227 public boolean doit = true;
230 * a field for application use
235 * An array of the touch states for the current touch event.
239 public Touch[] touches;
242 * If nonzero, a positive value indicates a swipe to the right,
243 * and a negative value indicates a swipe to the left.
247 public int xDirection;
250 * If nonzero, a positive value indicates a swipe in the up direction,
251 * and a negative value indicates a swipe in the down direction.
255 public int yDirection;
258 * The change in magnification. This value should be added to the current
259 * scaling of an item to get the new scale factor.
263 public double magnification;
266 * The number of degrees rotated on the track pad.
270 public double rotation;
275 * @return a rectangle that is the bounds.
277 public Rectangle getBounds () {
278 return new Rectangle (x, y, width, height);
280 Rectangle getBoundsInPixels () {
281 return DPIUtil.autoScaleUp(getBounds());
284 Point getLocation () {
285 return new Point (x, y);
288 Point getLocationInPixels () {
289 return DPIUtil.autoScaleUp(new Point(x, y));
295 * @param rect the new rectangle
297 public void setBounds (Rectangle rect) {
300 this.width = rect.width;
301 this.height = rect.height;
304 void setBoundsInPixels (Rectangle rect) {
305 setBounds(DPIUtil.autoScaleDown(rect));
308 void setLocationInPixels (int x, int y) {
309 this.x = DPIUtil.autoScaleDown(x);
310 this.y = DPIUtil.autoScaleDown(y);
314 * Returns a string containing a concise, human-readable
315 * description of the receiver.
317 * @return a string representation of the event
320 public String toString () {
321 return "Event {type=" + type + " " + widget + " time=" + time + " data=" + data + " x=" + x + " y=" + y + " width=" + width + " height=" + height + " detail=" + detail + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$