root/dwt/events/KeyEvent.d

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