Mercurial > projects > dynamin
annotate dynamin/gui/events.d @ 55:c138461bf845
Add focusing and other changes that are related
like descendantAdded/Removed events, Window.activated event, and updating List.
Window.state was also added, even though focusing does not depend on it.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 08 Aug 2009 15:42:27 -0500 |
parents | 2a194d52fdb5 |
children | 8dac206ea523 |
rev | line source |
---|---|
0 | 1 // Written in the D programming language |
2 // www.digitalmars.com/d/ | |
3 | |
4 /* | |
5 * The contents of this file are subject to the Mozilla Public License Version | |
6 * 1.1 (the "License"); you may not use this file except in compliance with | |
7 * the License. You may obtain a copy of the License at | |
8 * http://www.mozilla.org/MPL/ | |
9 * | |
10 * Software distributed under the License is distributed on an "AS IS" basis, | |
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 * for the specific language governing rights and limitations under the | |
13 * License. | |
14 * | |
15 * The Original Code is the Dynamin library. | |
16 * | |
17 * The Initial Developer of the Original Code is Jordan Miner. | |
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009 | |
19 * the Initial Developer. All Rights Reserved. | |
20 * | |
21 * Contributor(s): | |
22 * Jordan Miner <jminer7@gmail.com> | |
23 * | |
24 */ | |
25 | |
26 module dynamin.gui.events; | |
27 | |
28 import dynamin.all_core; | |
29 import dynamin.all_painting; | |
30 import dynamin.all_gui; | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
31 import dynamin.gui.control; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
32 import dynamin.gui.container; |
0 | 33 |
34 /// | |
35 enum MouseButton { | |
36 None, /// | |
37 Left, /// | |
38 Right, /// | |
39 Middle, /// | |
40 XButton1, /// | |
41 XButton2 /// | |
42 } | |
43 | |
44 /// | |
45 class PaintingEventArgs : EventArgs { | |
46 Graphics g; | |
47 //NativeGraphics ng; | |
48 public: | |
49 /// | |
50 this(Graphics g) { | |
51 this.g = g; | |
52 } | |
53 /// | |
54 Graphics graphics() { return g; } | |
55 } | |
56 | |
57 /// | |
58 class MouseEventArgs : StopEventArgs { | |
59 Point _location; | |
60 MouseButton _button; | |
61 public: | |
62 /// | |
63 this(real x, real y, MouseButton b) { | |
64 _location = Point(x, y); | |
65 _button = b; | |
66 } | |
67 /// | |
68 Point location() { return _location; } | |
69 /// | |
70 void location(Point pt) { _location = pt; } | |
71 /// | |
72 real x() { return _location.x; } | |
73 /// | |
74 real y() { return _location.y; } | |
75 /// | |
76 MouseButton button() { return _button; } | |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
77 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
78 return format("MouseEventArgs [x={}, y={}, button={}]", |
27
dfaa3da21b27
Fix stupid mistake with last commit.
Jordan Miner <jminer7@gmail.com>
parents:
26
diff
changeset
|
79 x, y, _button); |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
80 } |
0 | 81 } |
82 /// | |
83 class MouseTurnedEventArgs : StopEventArgs { | |
84 double _scrollAmount; | |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
85 bool _scrollScreen; |
0 | 86 public: |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
87 this(double scrollAmount, bool scrollScreen) { |
0 | 88 _scrollAmount = scrollAmount; |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
89 _scrollScreen = scrollScreen; |
0 | 90 } |
91 /** | |
92 * The amount that a control should scroll in response to this event. | |
93 * In a text control, this is the number of lines to scroll. | |
94 * This will be negative if the control should scroll upward and positive | |
95 * if the control should scroll downward. If the amount to be scrolled | |
96 * is more than what is visible on screen, only what is on screen | |
97 * should be scrolled. | |
98 * | |
99 * All users of this class should check scrollScreen to see whether to | |
100 * scroll one screen or to scroll the amount by this. | |
101 */ | |
102 double scrollAmount() { return _scrollAmount; } | |
103 /** | |
104 * On some systems, such as Windows, there is the option of setting | |
105 * the mouse wheel to scroll a screen at a time, the same as the page up | |
106 * and page down keys do. If this option is turned on, scrollScreen will | |
107 * return true and scrollAmount will return ±3. If the option is turned off, | |
108 * scrollScreen will return false. | |
109 */ | |
110 bool scrollScreen() { | |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
111 return _scrollScreen; |
0 | 112 } |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
113 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
114 return format("MouseTurnedEventArgs [scrollAmount={}, scrollScreen={}]", |
31
2a194d52fdb5
Implement MouseTurnedEventArgs.scrollScreen.
Jordan Miner <jminer7@gmail.com>
parents:
30
diff
changeset
|
115 _scrollAmount, _scrollScreen); |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
116 } |
0 | 117 } |
118 /// | |
119 class KeyEventArgs : StopEventArgs { | |
120 Key _key; | |
121 bool _repeat; | |
122 public: | |
123 this(Key key, bool repeat) { | |
124 _key = key; | |
125 _repeat = repeat; | |
126 } | |
127 /** | |
128 * Returns: the key that was typed. | |
129 */ | |
130 Key key() { return _key; } | |
131 /** | |
132 * Gets whether this key event was generated by the user holding | |
133 * down the key. | |
134 * Returns: true if the key was already down before this event, false | |
135 * if the key was just pressed | |
136 */ | |
137 bool repeat() { return _repeat; } | |
26
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
138 string toString() { |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
139 return format("KeyEventArgs [key={}, repeat={}]", _key, _repeat); |
87265a206638
Add toString() on some events.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
140 } |
0 | 141 } |
142 /// | |
143 class KeyTypedEventArgs : StopEventArgs { | |
144 dchar _ch; | |
145 bool _repeat; | |
146 public: | |
147 this(dchar c, bool repeat) { | |
148 _ch = c; | |
149 _repeat = repeat; | |
150 } | |
151 /** | |
152 * Gets whether this key event was generated from the user holding | |
153 * down the key. | |
154 * Returns: true if the key was already down before this event, false | |
155 * if the key was just pressed | |
156 */ | |
157 bool repeat() { return _repeat; } | |
158 /** | |
159 * Gets the character that was typed by the user. Many keys on the | |
160 * keyboard will not generate a KeyTyped event, as they do not represent | |
161 * characters. Shift, Insert, Home, F7, and Caps Lock are just some of | |
162 * the keys that do not represent characters. | |
163 */ | |
164 dchar character() { return _ch; } | |
165 } | |
166 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
167 /// |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
168 class HierarchyEventArgs : EventArgs { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
169 int _levels = 0; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
170 Control _control; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
171 public: |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
172 this(Control c) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
173 _control = c; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
174 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
175 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
176 * An immediate child would be a level of 0. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
177 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
178 int levels() { return _levels; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
179 /// ditto |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
180 void levels(int l) { _levels = l; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
181 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
182 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
183 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
184 Control descendant() { return _control; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
185 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
186 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
187 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
188 Container ancestor() { return cast(Container)_control; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
189 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
31
diff
changeset
|
190 |