comparison dwt/events/KeyEvent.d @ 0:380af2bdd8e5

Upload of whole dwt tree
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sat, 09 Aug 2008 17:00:02 +0200
parents
children 649b8e223d5a
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 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 *******************************************************************************/
11 module dwt.events.KeyEvent;
12
13 import dwt.dwthelper.utils;
14
15
16 import dwt.widgets.Event;
17
18 /**
19 * Instances of this class are sent as a result of
20 * keys being pressed and released on the keyboard.
21 * <p>
22 * When a key listener is added to a control, the control
23 * will take part in widget traversal. By default, all
24 * traversal keys (such as the tab key and so on) are
25 * delivered to the control. In order for a control to take
26 * part in traversal, it should listen for traversal events.
27 * Otherwise, the user can traverse into a control but not
28 * out. Note that native controls such as table and tree
29 * implement key traversal in the operating system. It is
30 * not necessary to add traversal listeners for these controls,
31 * unless you want to override the default traversal.
32 * </p>
33 * @see KeyListener
34 * @see TraverseListener
35 */
36
37 public class KeyEvent extends TypedEvent {
38
39 /**
40 * the character represented by the key that was typed.
41 * This is the final character that results after all modifiers have been
42 * applied. For example, when the user types Ctrl+A, the character value
43 * is 0x01. It is important that applications do not attempt to modify the
44 * character value based on a stateMask (such as DWT.CTRL) or the resulting
45 * character will not be correct.
46 */
47 public char character;
48
49 /**
50 * the key code of the key that was typed,
51 * as defined by the key code constants in class <code>DWT</code>.
52 * When the character field of the event is ambiguous, this field
53 * contains the unicode value of the original character. For example,
54 * typing Ctrl+M or Return both result in the character '\r' but the
55 * keyCode field will also contain '\r' when Return was typed.
56 *
57 * @see dwt.DWT
58 */
59 public int keyCode;
60
61 /**
62 * the state of the keyboard modifier keys at the time
63 * the event was generated, as defined by the key code
64 * constants in class <code>DWT</code>.
65 *
66 * @see dwt.DWT
67 */
68 public int stateMask;
69
70 /**
71 * A flag indicating whether the operation should be allowed.
72 * Setting this field to <code>false</code> will cancel the operation.
73 */
74 public bool doit;
75
76 static final long serialVersionUID = 3256442491011412789L;
77
78 /**
79 * Constructs a new instance of this class based on the
80 * information in the given untyped event.
81 *
82 * @param e the untyped event containing the information
83 */
84 public KeyEvent(Event e) {
85 super(e);
86 this.character = e.character;
87 this.keyCode = e.keyCode;
88 this.stateMask = e.stateMask;
89 this.doit = e.doit;
90 }
91
92 /**
93 * Returns a string containing a concise, human-readable
94 * description of the receiver.
95 *
96 * @return a string representation of the event
97 */
98 public String toString() {
99 String string = super.toString ();
100 return string.substring (0, string.length() - 1) // remove trailing '}'
101 + " character='" + ((character is 0) ? "\\0" : "" + character) + "'"
102 + " keyCode=" + keyCode
103 + " stateMask=" + stateMask
104 + " doit=" + doit
105 + "}";
106 }
107 }