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