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