Mercurial > projects > dynamin
annotate dynamin/gui/window.d @ 69:b5460ba7c93e
Add test that Window.handle isn't created prematurely
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Mon, 10 Aug 2009 03:22:42 -0500 |
parents | 6580fabb7dce |
children | 68be24186634 |
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.window; | |
27 | |
28 import dynamin.c.cairo; | |
29 import dynamin.all_core; | |
30 import dynamin.all_painting; | |
31 import dynamin.all_gui; | |
32 import dynamin.gui.control; | |
23
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
33 import dynamin.gui.cursor; |
1
3ab1e9bfb88c
Fix a rename of gui.backend -> gui_backend I missed.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
34 import dynamin.gui_backend; |
0 | 35 import dynamin.gui.container; |
36 import dynamin.gui.events; | |
37 import tango.io.Stdout; | |
38 import tango.core.Exception; | |
39 import tango.core.Thread; | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
40 import tango.text.Util; |
0 | 41 |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
42 /// |
0 | 43 static class Application { |
44 static: | |
45 mixin ApplicationBackend; | |
46 package Thread eventThread; | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
47 /// Starts event processing. Must be called from main(). |
0 | 48 void run(Window w = null) { |
49 Window.hasProcessedEvents = true; | |
50 | |
51 auto thread = Thread.getThis(); | |
52 assert(eventThread is null || eventThread is thread, | |
53 "Application.run called from two different threads"); | |
54 eventThread = thread; | |
55 | |
56 backend_run(w); | |
57 } | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
58 /** |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
59 * Calls the specified delegate on the event thread and returns without |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
60 * waiting for the delegate to finish. Since the delegate is not called |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
61 * immediately, it must not live on the stack. Instead, it could be a |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
62 * method of a class. In D2, delegates generally are on the heap. |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
63 */ |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
64 void invoke(void delegate() dg) { |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
65 backend_invoke(dg); |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
66 } |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
67 /** |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
68 * Calls the specified delegate on the event thread and blocks until |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
69 * the delegate finishes. |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
70 */ |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
71 void invokeNow(void delegate() dg) { |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
72 backend_invokeNow(dg); |
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
73 } |
0 | 74 } |
75 | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
76 /// |
0 | 77 enum DialogResult { |
78 /// | |
79 OK, | |
80 /// | |
81 Yes, | |
82 /// | |
83 No, | |
84 /// | |
85 Cancel, | |
86 /// | |
87 Custom | |
88 } | |
89 | |
90 /// | |
91 enum Position { | |
92 /// Specifies being at the top-left corner. | |
93 TopLeft, | |
94 /// Specifies being centered between the top-left corner and the top-right corner. | |
95 Top, | |
96 /// Specifies being at the top-right corner. | |
97 TopRight, | |
98 /// Specifies being centered between the top-left corner and the bottom-left corner. | |
99 Left, | |
100 /// Specifies being centered between all corners. | |
101 Center, | |
102 /// Specifies being centered between the top-right corner and the bottom-right corner. | |
103 Right, | |
104 /// Specifies being at the bottom-left corner. | |
105 BottomLeft, | |
106 /// Specifies being centered between the bottom-left corner and the bottom-right corner. | |
107 Bottom, | |
108 /// Specifies being at the bottom-right corner. | |
109 BottomRight | |
110 } | |
111 | |
112 /** | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
113 * The different states a window may be in. It may not be in more than one of |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
114 * these states at a time. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
115 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
116 enum WindowState { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
117 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
118 * Specifies that the window is neither minimized or maximized. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
119 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
120 Normal, |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
121 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
122 * Specifies that the window is only visible as an icon and/or text on |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
123 * the taskbar or dock. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
124 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
125 Minimized, |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
126 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
127 * Specifies that the window covers the screen in at least one direction. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
128 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
129 Maximized |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
130 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
131 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
132 /** |
0 | 133 * The different types of borders that a window may have. |
134 * These do not affect whether the window is resizable-- | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
135 * use Window.resizable for that. |
0 | 136 */ |
137 enum WindowBorderStyle { | |
138 /** Specifies that the window has no border around the content area. */ | |
139 None, | |
140 /** | |
141 * Specifies that the window has a normal border with a title bar, icon, | |
142 * and minimize button. | |
143 */ | |
144 Normal, | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
145 /** |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
146 * Specifies that the window has a normal border without a minimize button. |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
147 */ |
0 | 148 Dialog, |
149 /** Specifies that the window has the border of a floating tool box. */ | |
150 Tool | |
151 } | |
152 | |
153 alias List!(Control) ControlList; | |
154 //Frames and Dialogs are identical except that Dialogs do not have minimize and | |
155 //maximize buttons, are not shown on the taskbar, and can be modal. | |
156 /** | |
157 * A window is a top level control that has no parent. Its location is relative | |
158 * to the top-left corner of the screen. | |
159 * A window can have no border, the border of a normal window, or the border | |
160 * of a tool window. | |
161 * | |
162 * The appearance of a window with Windows Classic: | |
163 * | |
164 * $(IMAGE ../web/example_window.png) | |
165 */ | |
166 class Window : Container { | |
167 private static hasProcessedEvents = false; | |
168 ~this() { // this should be a static ~this, but I get a circular dep error | |
169 if(!hasProcessedEvents) { | |
170 Stdout("Warning: a window was created, but Application.run"); | |
171 Stdout(" was not called to process events").newline; | |
172 } | |
173 } | |
174 protected: | |
175 mixin WindowBackend; | |
67
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
176 bool _visible; |
0 | 177 BorderSize _borderSize; |
178 Window _owner; | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
179 package bool _active; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
180 package WindowState _state; |
0 | 181 WindowBorderStyle _borderStyle; |
182 bool _resizable = true; | |
44
ad551ec36b75
Revert Window.content to being a Panel.
Jordan Miner <jminer7@gmail.com>
parents:
35
diff
changeset
|
183 Panel _content; |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
184 bool _showFocus; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
185 // _focusedControl might not be focused at the current time (that is |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
186 // getFocusedControl()), but will at least be focused when this |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
187 // window is active |
0 | 188 Control _focusedControl; |
189 package Control focusedControl() { return _focusedControl; } | |
190 package void focusedControl(Control c) { | |
191 _focusedControl = c; | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
192 if(active) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
193 setFocusedControl(_focusedControl); |
0 | 194 } |
195 override void dispatchPainting(PaintingEventArgs e) { | |
196 Theme.current.Window_paint(this, e.graphics); | |
197 super.dispatchPainting(e); | |
198 } | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
199 override void whenDescendantAdded(HierarchyEventArgs e) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
200 super.whenDescendantAdded(e); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
201 if(focusedControl is null && e.descendant.focusable) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
202 // && e.descendant.enabled) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
203 focusedControl = e.descendant; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
204 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
205 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
206 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
207 //{{{ focusing |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
208 public override bool showFocus() { return _showFocus; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
209 override void whenKeyDown(KeyEventArgs e) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
210 if(e.key == Key.Tab) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
211 getNextFocusable().focus(); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
212 _showFocus = true; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
213 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
214 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
215 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
216 // will not return null |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
217 Control getNextFocusable() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
218 Control foc = focusedControl; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
219 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
220 Control[32] buffer; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
221 auto des = getFocusableDescendants(buffer); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
222 if(des.length == 0) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
223 return this; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
224 else if(des.length == 1) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
225 return des[0]; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
226 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
227 int focI = locate(des, foc); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
228 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
229 // look _after_ this control for one with the same tab index |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
230 foreach(c; des[focI+1..$]) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
231 if(c.tabIndex == foc.tabIndex) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
232 return c; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
233 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
234 // if none are found, look for the next largest tab index |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
235 // from the beginning of the array |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
236 Control smallest; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
237 Control nextLargest; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
238 foreach(c; des) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
239 if(c.tabIndex > foc.tabIndex) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
240 if(nextLargest is null || c.tabIndex < nextLargest.tabIndex) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
241 nextLargest = c; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
242 if(smallest is null || c.tabIndex < smallest.tabIndex) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
243 smallest = c; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
244 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
245 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
246 if(nextLargest) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
247 return nextLargest; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
248 else |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
249 return smallest; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
250 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
251 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
252 // will not return null |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
253 Control getPreviousFocusable() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
254 return null; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
255 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
256 //}}} |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
257 |
0 | 258 public: |
67
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
259 /// Override this method in a subclass to handle the visibleChanged event. |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
260 protected void whenVisibleChanged(EventArgs e) { } |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
261 /// This event occurs after this control is shown or hidden. |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
262 Event!(whenVisibleChanged) visibleChanged; |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
263 |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
264 /// Override this method in a subclass to handle the activated event. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
265 protected void whenActivated(EventArgs e) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
266 setFocusedControl(_focusedControl is null ? content : _focusedControl); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
267 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
268 /// This event occurs after this window is activated. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
269 Event!(whenActivated) activated; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
270 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
271 /// Override this method in a subclass to handle the deactivated event. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
272 protected void whenDeactivated(EventArgs e) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
273 setFocusedControl(null); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
274 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
275 /// This event occurs after this window is deactivated. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
276 Event!(whenDeactivated) deactivated; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
277 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
278 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
279 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
280 */ |
0 | 281 this() { |
67
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
282 visibleChanged.mainHandler = &whenVisibleChanged; |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
283 activated.mainHandler = &whenActivated; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
284 deactivated.mainHandler = &whenDeactivated; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
285 |
0 | 286 content = new Panel; |
287 | |
288 _visible = false; | |
289 _minSize = Size(0, 0); | |
290 _maxSize = Size(0, 0); | |
291 _borderStyle = WindowBorderStyle.Normal; | |
292 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
293 /// ditto |
0 | 294 this(string text) { |
295 this(); | |
296 this.text = text; | |
297 } | |
298 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
299 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
300 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
301 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
302 Panel content() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
303 return _content; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
304 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
305 /// ditto |
44
ad551ec36b75
Revert Window.content to being a Panel.
Jordan Miner <jminer7@gmail.com>
parents:
35
diff
changeset
|
306 void content(Panel panel) { |
0 | 307 if(panel is null) |
308 throw new IllegalArgumentException("content must not be null"); | |
309 // TODO: remove handlers | |
310 super.remove(panel); | |
311 super.add(_content = panel); | |
312 _content.resized += &whenContentResized; | |
313 _content.minSizeChanged += &whenContentMinSizeChanged; | |
314 _content.maxSizeChanged += &whenContentMaxSizeChanged; | |
315 | |
316 auto best = _content.bestSize; | |
317 _content.minSize = best; | |
318 _content.maxSize = Size(_content.elasticX ? 0 : best.width, | |
319 _content.elasticY ? 0 : best.height); | |
320 resizable = _content.maxSize != best; // avoid calling elasticX/Y again | |
321 _content.size = best; | |
322 | |
323 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
324 |
0 | 325 bool ignoreResize; |
326 void whenContentResized(EventArgs e) { | |
327 if(ignoreResize) | |
328 return; | |
329 ignoreResize = true; | |
330 size = _content.size + _borderSize; | |
331 ignoreResize = false; | |
332 } | |
333 void whenContentMinSizeChanged(EventArgs e) { | |
334 if(!handleCreated) | |
335 return; | |
336 backend_contentMinSizeChanged; | |
337 } | |
338 void whenContentMaxSizeChanged(EventArgs e) { | |
339 if(!handleCreated) | |
340 return; | |
341 backend_contentMaxSizeChanged; | |
342 } | |
343 override void whenResized(EventArgs e) { | |
344 if(ignoreResize) | |
345 return; | |
346 _content._location = Point(_borderSize.left, _borderSize.top); | |
347 ignoreResize = true; | |
348 _content.size = _size-_borderSize; | |
349 ignoreResize = false; | |
350 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
351 |
0 | 352 /** |
353 * If the handle has not yet been created, calling this will cause it to be. | |
354 * Under the Windows backend, returns a HWND. | |
355 * Under the X backend, returns a Window. | |
356 * Returns: the backend specific native handle. | |
357 */ | |
358 typeof(_handle) handle() { | |
359 if(!handleCreated) | |
360 recreateHandle(); | |
361 assert(Thread.getThis() is Application.eventThread || | |
362 Application.eventThread is null, | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
363 "Controls must be accessed and changed only on the event thread. Use invokeNow() from other threads."); |
0 | 364 return _handle; |
365 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
366 |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
367 /// |
0 | 368 bool handleCreated() { return backend_handleCreated; } |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
369 |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
370 /// |
0 | 371 void recreateHandle() { |
372 backend_recreateHandle(); | |
373 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
374 |
0 | 375 override protected Graphics quickCreateGraphics() { |
376 if(!handleCreated) | |
377 return null; | |
378 return backend_quickCreateGraphics(); | |
379 } | |
380 override bool onScreen() { | |
381 return true; | |
382 } | |
383 override Point screenLocation() { | |
384 return location; | |
385 } | |
386 override Point contentToScreen(Point pt) { | |
387 return pt + location; | |
388 } | |
389 override Point screenToContent(Point pt) { | |
390 return pt - location; | |
391 } | |
392 override bool topLevel() { return true; } | |
393 override Container parent() { return null; } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
394 |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
395 // TODO: because you should always be able to click a window from |
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
396 // the taskbar, then show it on taskbar if window has an owner, |
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
397 // but don't if it does not |
0 | 398 void owner(Window w) { |
68
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
67
diff
changeset
|
399 if(_owner == w) |
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
67
diff
changeset
|
400 return; |
0 | 401 _owner = w; |
402 if(!handleCreated) | |
403 return; | |
404 recreateHandle(); | |
405 } | |
406 Window owner() { return _owner; } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
407 |
67
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
408 /** |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
409 * Gets or sets whether this window is visible. The default is false. |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
410 */ |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
411 bool visible() { return _visible; } |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
412 /// ditto |
0 | 413 void visible(bool b) { |
68
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
67
diff
changeset
|
414 if(_visible == b) |
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
67
diff
changeset
|
415 return; |
0 | 416 _visible = b; |
417 backend_visible = b; | |
67
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
418 |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
419 scope e = new EventArgs; |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
420 visibleChanged(e); |
0 | 421 } |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
422 |
0 | 423 /** |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
424 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
425 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
426 bool active() { return _active; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
427 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
428 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
429 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
430 void activate() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
431 if(!handleCreated) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
432 return; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
433 backend_activate(); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
434 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
435 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
436 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
437 * Gets or sets whether the window's state is normal, minimized, or |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
438 * maximized. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
439 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
440 WindowState state() { return _state; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
441 /// ditto |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
442 void state(WindowState s) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
443 _state = s; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
444 if(!handleCreated) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
445 return; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
446 backend_state = s; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
447 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
448 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
449 /** |
0 | 450 * Gets or sets what border this window will have around its contents. |
451 * The default is WindowBorderStyle.Normal. | |
452 */ | |
453 WindowBorderStyle borderStyle() { return _borderStyle; } | |
454 /// ditto | |
455 void borderStyle(WindowBorderStyle border) { | |
68
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
67
diff
changeset
|
456 if(_borderStyle == border) |
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
67
diff
changeset
|
457 return; |
0 | 458 if(border > WindowBorderStyle.Tool) |
459 throw new IllegalArgumentException("Window.borderStyle(): invalid border style"); | |
460 _borderStyle = border; | |
461 backend_borderStyle = border; | |
462 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
463 |
23
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
464 override void setCurrentCursor(Cursor cur) { |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
465 if(!handleCreated) |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
466 return; |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
467 backend_setCurrentCursor(cur); |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
468 } |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
469 |
0 | 470 alias Control.repaint repaint; |
471 void repaint(Rect rect) { | |
472 if(!handleCreated) | |
473 return; | |
474 backend_repaint(rect); | |
475 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
476 |
0 | 477 /** |
478 * An array of rectangles in screen coordinates that the window will be | |
479 * snapped to. | |
480 */ | |
481 Rect[] snapRects = null; | |
482 /** | |
63 | 483 * Convenience method that sets snapRects to an array |
0 | 484 * with just the specified Rect. |
485 */ | |
486 void snapRect(Rect rect) { | |
487 snapRects = [rect]; | |
488 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
489 |
0 | 490 /** |
63 | 491 * The snapDistance specifies how close a window has to be to a |
0 | 492 * snap rectangle for the window to snap to it. The default is 10 pixels. |
493 */ | |
494 uint snapDistance = 10; | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
495 |
0 | 496 /** |
497 * Gets or sets whether this window can be resized by the user. | |
498 * The default is true. | |
499 */ | |
500 bool resizable() { return _resizable; } | |
501 /// ditto | |
66 | 502 void resizable(bool b) { |
68
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
67
diff
changeset
|
503 if(_resizable == b) |
6580fabb7dce
Setting a property to the value it already is shouldn't do anything
Jordan Miner <jminer7@gmail.com>
parents:
67
diff
changeset
|
504 return; |
0 | 505 _resizable = b; |
506 if(!handleCreated) | |
507 return; | |
508 backend_resizable = b; | |
509 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
510 |
0 | 511 // TODO: 1.0 MinSize -> contentMinSize MaxSize -> contentMaxSize |
512 alias Control.location location; | |
513 void location(Point pt) { | |
514 super.location(pt); | |
515 if(!handleCreated) | |
516 return; | |
517 backend_location = pt; | |
518 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
519 |
0 | 520 alias Control.size size; |
521 void size(Size size) { | |
522 super.size(size); | |
523 _content.size = size - _borderSize; | |
524 if(!handleCreated) | |
525 return; | |
526 backend_size = size; | |
527 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
528 |
0 | 529 alias Control.text text; |
530 void text(string str) { | |
531 super.text(str); | |
532 if(!handleCreated) | |
533 return; | |
534 backend_text = str; | |
535 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
536 |
0 | 537 /** |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
538 * Gets the size of the border/frame around this window. |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
539 */ |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
540 BorderSize borderSize() { |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
541 return _borderSize; |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
542 } |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
543 |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
544 /** |
63 | 545 * Moves this window to the specified position relative to the specified |
546 * control. If no control is specified, the window is positioned relative | |
547 * to the screen. | |
0 | 548 */ |
549 void position(Position pos, Control c = null) { | |
550 Rect rect; | |
551 if(c && c.onScreen) { | |
552 rect = c.screenLocation + c.size; | |
553 } else { | |
554 rect = desktopRect; | |
555 } | |
556 Point newLoc = Point(); | |
557 switch(pos) { | |
558 case Position.TopLeft: | |
559 case Position.Left: | |
560 case Position.BottomLeft: | |
561 newLoc.x = rect.x; | |
562 break; | |
563 case Position.Top: | |
564 case Position.Center: | |
565 case Position.Bottom: | |
566 newLoc.x = rect.x + (rect.width - width)/2; | |
567 break; | |
568 case Position.TopRight: | |
569 case Position.Right: | |
570 case Position.BottomRight: | |
571 newLoc.x = rect.x + rect.width - width; | |
572 break; | |
573 } | |
574 switch(pos) { | |
575 case Position.TopLeft: | |
576 case Position.Top: | |
577 case Position.TopRight: | |
578 newLoc.y = rect.y; | |
579 break; | |
580 case Position.Left: | |
581 case Position.Center: | |
582 case Position.Right: | |
583 newLoc.y = rect.y + (rect.height - height)/2; | |
584 break; | |
585 case Position.BottomLeft: | |
586 case Position.Bottom: | |
587 case Position.BottomRight: | |
588 newLoc.y = rect.y + rect.height - height; | |
589 break; | |
590 } | |
591 location = newLoc; | |
592 } | |
593 } | |
594 | |
69
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
595 unittest { |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
596 auto w = new Window; |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
597 assert(!w.handleCreated); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
598 w.content = new Panel; |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
599 assert(!w.handleCreated); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
600 w.location = Point(5, 5); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
601 assert(!w.handleCreated); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
602 w.size = Size(100, 100); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
603 assert(!w.handleCreated); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
604 w.position = Position.Right; |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
605 assert(!w.handleCreated); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
606 w.text = "Test Text"; |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
607 assert(!w.handleCreated); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
608 w.borderStyle = WindowBorderStyle.Tool; |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
609 assert(!w.handleCreated); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
610 w.state = WindowState.Maximized; |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
611 assert(!w.handleCreated); |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
612 } |
b5460ba7c93e
Add test that Window.handle isn't created prematurely
Jordan Miner <jminer7@gmail.com>
parents:
68
diff
changeset
|
613 |