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