Mercurial > projects > dynamin
annotate dynamin/gui/window.d @ 68:6580fabb7dce
Setting a property to the value it already is shouldn't do anything
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Mon, 10 Aug 2009 02:48:15 -0500 |
parents | 419e38206522 |
children | b5460ba7c93e |
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 recreateHandle(); | |
293 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
294 /// ditto |
0 | 295 this(string text) { |
296 this(); | |
297 this.text = text; | |
298 } | |
299 | |
55
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 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
303 Panel content() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
304 return _content; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
305 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
306 /// ditto |
44
ad551ec36b75
Revert Window.content to being a Panel.
Jordan Miner <jminer7@gmail.com>
parents:
35
diff
changeset
|
307 void content(Panel panel) { |
0 | 308 if(panel is null) |
309 throw new IllegalArgumentException("content must not be null"); | |
310 // TODO: remove handlers | |
311 super.remove(panel); | |
312 super.add(_content = panel); | |
313 _content.resized += &whenContentResized; | |
314 _content.minSizeChanged += &whenContentMinSizeChanged; | |
315 _content.maxSizeChanged += &whenContentMaxSizeChanged; | |
316 | |
317 auto best = _content.bestSize; | |
318 _content.minSize = best; | |
319 _content.maxSize = Size(_content.elasticX ? 0 : best.width, | |
320 _content.elasticY ? 0 : best.height); | |
321 resizable = _content.maxSize != best; // avoid calling elasticX/Y again | |
322 _content.size = best; | |
323 | |
324 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
325 |
0 | 326 bool ignoreResize; |
327 void whenContentResized(EventArgs e) { | |
328 if(ignoreResize) | |
329 return; | |
330 ignoreResize = true; | |
331 size = _content.size + _borderSize; | |
332 ignoreResize = false; | |
333 } | |
334 void whenContentMinSizeChanged(EventArgs e) { | |
335 if(!handleCreated) | |
336 return; | |
337 backend_contentMinSizeChanged; | |
338 } | |
339 void whenContentMaxSizeChanged(EventArgs e) { | |
340 if(!handleCreated) | |
341 return; | |
342 backend_contentMaxSizeChanged; | |
343 } | |
344 override void whenResized(EventArgs e) { | |
345 if(ignoreResize) | |
346 return; | |
347 _content._location = Point(_borderSize.left, _borderSize.top); | |
348 ignoreResize = true; | |
349 _content.size = _size-_borderSize; | |
350 ignoreResize = false; | |
351 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
352 |
0 | 353 /** |
354 * If the handle has not yet been created, calling this will cause it to be. | |
355 * Under the Windows backend, returns a HWND. | |
356 * Under the X backend, returns a Window. | |
357 * Returns: the backend specific native handle. | |
358 */ | |
359 typeof(_handle) handle() { | |
360 if(!handleCreated) | |
361 recreateHandle(); | |
362 assert(Thread.getThis() is Application.eventThread || | |
363 Application.eventThread is null, | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
364 "Controls must be accessed and changed only on the event thread. Use invokeNow() from other threads."); |
0 | 365 return _handle; |
366 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
367 |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
368 /// |
0 | 369 bool handleCreated() { return backend_handleCreated; } |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
370 |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
371 /// |
0 | 372 void recreateHandle() { |
373 backend_recreateHandle(); | |
374 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
375 |
0 | 376 override protected Graphics quickCreateGraphics() { |
377 if(!handleCreated) | |
378 return null; | |
379 return backend_quickCreateGraphics(); | |
380 } | |
381 override bool onScreen() { | |
382 return true; | |
383 } | |
384 override Point screenLocation() { | |
385 return location; | |
386 } | |
387 override Point contentToScreen(Point pt) { | |
388 return pt + location; | |
389 } | |
390 override Point screenToContent(Point pt) { | |
391 return pt - location; | |
392 } | |
393 override bool topLevel() { return true; } | |
394 override Container parent() { return null; } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
395 |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
396 // 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
|
397 // 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
|
398 // but don't if it does not |
0 | 399 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
|
400 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
|
401 return; |
0 | 402 _owner = w; |
403 if(!handleCreated) | |
404 return; | |
405 recreateHandle(); | |
406 } | |
407 Window owner() { return _owner; } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
408 |
67
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
409 /** |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
410 * 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
|
411 */ |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
412 bool visible() { return _visible; } |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
413 /// ditto |
0 | 414 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
|
415 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
|
416 return; |
0 | 417 _visible = b; |
418 backend_visible = b; | |
67
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
419 |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
420 scope e = new EventArgs; |
419e38206522
Move visible from Control to Window
Jordan Miner <jminer7@gmail.com>
parents:
66
diff
changeset
|
421 visibleChanged(e); |
0 | 422 } |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
423 |
0 | 424 /** |
55
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 bool active() { return _active; } |
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 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
431 void activate() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
432 if(!handleCreated) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
433 return; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
434 backend_activate(); |
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 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
438 * 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
|
439 * maximized. |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
440 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
441 WindowState state() { return _state; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
442 /// ditto |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
443 void state(WindowState s) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
444 _state = s; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
445 if(!handleCreated) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
446 return; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
447 backend_state = s; |
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 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
450 /** |
0 | 451 * Gets or sets what border this window will have around its contents. |
452 * The default is WindowBorderStyle.Normal. | |
453 */ | |
454 WindowBorderStyle borderStyle() { return _borderStyle; } | |
455 /// ditto | |
456 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
|
457 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
|
458 return; |
0 | 459 if(border > WindowBorderStyle.Tool) |
460 throw new IllegalArgumentException("Window.borderStyle(): invalid border style"); | |
461 _borderStyle = border; | |
462 backend_borderStyle = border; | |
463 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
464 |
23
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
465 override void setCurrentCursor(Cursor cur) { |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
466 if(!handleCreated) |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
467 return; |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
468 backend_setCurrentCursor(cur); |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
469 } |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
470 |
0 | 471 alias Control.repaint repaint; |
472 void repaint(Rect rect) { | |
473 if(!handleCreated) | |
474 return; | |
475 backend_repaint(rect); | |
476 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
477 |
0 | 478 /** |
479 * An array of rectangles in screen coordinates that the window will be | |
480 * snapped to. | |
481 */ | |
482 Rect[] snapRects = null; | |
483 /** | |
63 | 484 * Convenience method that sets snapRects to an array |
0 | 485 * with just the specified Rect. |
486 */ | |
487 void snapRect(Rect rect) { | |
488 snapRects = [rect]; | |
489 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
490 |
0 | 491 /** |
63 | 492 * The snapDistance specifies how close a window has to be to a |
0 | 493 * snap rectangle for the window to snap to it. The default is 10 pixels. |
494 */ | |
495 uint snapDistance = 10; | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
496 |
0 | 497 /** |
498 * Gets or sets whether this window can be resized by the user. | |
499 * The default is true. | |
500 */ | |
501 bool resizable() { return _resizable; } | |
502 /// ditto | |
66 | 503 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
|
504 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
|
505 return; |
0 | 506 _resizable = b; |
507 if(!handleCreated) | |
508 return; | |
509 backend_resizable = b; | |
510 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
511 |
0 | 512 // TODO: 1.0 MinSize -> contentMinSize MaxSize -> contentMaxSize |
513 alias Control.location location; | |
514 void location(Point pt) { | |
515 super.location(pt); | |
516 if(!handleCreated) | |
517 return; | |
518 backend_location = pt; | |
519 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
520 |
0 | 521 alias Control.size size; |
522 void size(Size size) { | |
523 super.size(size); | |
524 _content.size = size - _borderSize; | |
525 if(!handleCreated) | |
526 return; | |
527 backend_size = size; | |
528 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
529 |
0 | 530 alias Control.text text; |
531 void text(string str) { | |
532 super.text(str); | |
533 if(!handleCreated) | |
534 return; | |
535 backend_text = str; | |
536 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
537 |
0 | 538 /** |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
539 * 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
|
540 */ |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
541 BorderSize borderSize() { |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
542 return _borderSize; |
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 |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
545 /** |
63 | 546 * Moves this window to the specified position relative to the specified |
547 * control. If no control is specified, the window is positioned relative | |
548 * to the screen. | |
0 | 549 */ |
550 void position(Position pos, Control c = null) { | |
551 Rect rect; | |
552 if(c && c.onScreen) { | |
553 rect = c.screenLocation + c.size; | |
554 } else { | |
555 rect = desktopRect; | |
556 } | |
557 Point newLoc = Point(); | |
558 switch(pos) { | |
559 case Position.TopLeft: | |
560 case Position.Left: | |
561 case Position.BottomLeft: | |
562 newLoc.x = rect.x; | |
563 break; | |
564 case Position.Top: | |
565 case Position.Center: | |
566 case Position.Bottom: | |
567 newLoc.x = rect.x + (rect.width - width)/2; | |
568 break; | |
569 case Position.TopRight: | |
570 case Position.Right: | |
571 case Position.BottomRight: | |
572 newLoc.x = rect.x + rect.width - width; | |
573 break; | |
574 } | |
575 switch(pos) { | |
576 case Position.TopLeft: | |
577 case Position.Top: | |
578 case Position.TopRight: | |
579 newLoc.y = rect.y; | |
580 break; | |
581 case Position.Left: | |
582 case Position.Center: | |
583 case Position.Right: | |
584 newLoc.y = rect.y + (rect.height - height)/2; | |
585 break; | |
586 case Position.BottomLeft: | |
587 case Position.Bottom: | |
588 case Position.BottomRight: | |
589 newLoc.y = rect.y + rect.height - height; | |
590 break; | |
591 } | |
592 location = newLoc; | |
593 } | |
594 } | |
595 |