Mercurial > projects > dynamin
annotate dynamin/gui/window.d @ 66:4c095424a9ab
Remove outdated comment
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Mon, 10 Aug 2009 01:44:29 -0500 |
parents | 84beb40c1665 |
children | 419e38206522 |
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; | |
176 BorderSize _borderSize; | |
177 Window _owner; | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
178 package bool _active; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
179 package WindowState _state; |
0 | 180 WindowBorderStyle _borderStyle; |
181 bool _resizable = true; | |
44
ad551ec36b75
Revert Window.content to being a Panel.
Jordan Miner <jminer7@gmail.com>
parents:
35
diff
changeset
|
182 Panel _content; |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
183 bool _showFocus; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
184 // _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
|
185 // 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
|
186 // window is active |
0 | 187 Control _focusedControl; |
188 package Control focusedControl() { return _focusedControl; } | |
189 package void focusedControl(Control c) { | |
190 _focusedControl = c; | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
191 if(active) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
192 setFocusedControl(_focusedControl); |
0 | 193 } |
194 override void dispatchPainting(PaintingEventArgs e) { | |
195 Theme.current.Window_paint(this, e.graphics); | |
196 super.dispatchPainting(e); | |
197 } | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
198 override void whenDescendantAdded(HierarchyEventArgs e) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
199 super.whenDescendantAdded(e); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
200 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
|
201 // && e.descendant.enabled) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
202 focusedControl = e.descendant; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
203 } |
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 //{{{ focusing |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
207 public override bool showFocus() { return _showFocus; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
208 override void whenKeyDown(KeyEventArgs e) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
209 if(e.key == Key.Tab) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
210 getNextFocusable().focus(); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
211 _showFocus = true; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
212 } |
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 // will not return null |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
216 Control getNextFocusable() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
217 Control foc = focusedControl; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
218 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
219 Control[32] buffer; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
220 auto des = getFocusableDescendants(buffer); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
221 if(des.length == 0) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
222 return this; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
223 else if(des.length == 1) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
224 return des[0]; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
225 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
226 int focI = locate(des, foc); |
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 // 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
|
229 foreach(c; des[focI+1..$]) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
230 if(c.tabIndex == foc.tabIndex) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
231 return c; |
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 // 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
|
234 // from the beginning of the array |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
235 Control smallest; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
236 Control nextLargest; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
237 foreach(c; des) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
238 if(c.tabIndex > foc.tabIndex) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
239 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
|
240 nextLargest = c; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
241 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
|
242 smallest = c; |
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 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
245 if(nextLargest) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
246 return nextLargest; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
247 else |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
248 return smallest; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
249 } |
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 // will not return null |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
252 Control getPreviousFocusable() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
253 return null; |
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 public: |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
258 /// 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
|
259 protected void whenActivated(EventArgs e) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
260 setFocusedControl(_focusedControl is null ? content : _focusedControl); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
261 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
262 /// 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
|
263 Event!(whenActivated) activated; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
264 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
265 /// 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
|
266 protected void whenDeactivated(EventArgs e) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
267 setFocusedControl(null); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
268 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
269 /// 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
|
270 Event!(whenDeactivated) deactivated; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
271 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
272 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
273 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
274 */ |
0 | 275 this() { |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
276 activated.mainHandler = &whenActivated; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
277 deactivated.mainHandler = &whenDeactivated; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
278 |
0 | 279 content = new Panel; |
280 | |
281 _visible = false; | |
282 _minSize = Size(0, 0); | |
283 _maxSize = Size(0, 0); | |
284 _borderStyle = WindowBorderStyle.Normal; | |
285 recreateHandle(); | |
286 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
287 /// ditto |
0 | 288 this(string text) { |
289 this(); | |
290 this.text = text; | |
291 } | |
292 | |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
293 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
294 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
295 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
296 Panel content() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
297 return _content; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
298 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
299 /// ditto |
44
ad551ec36b75
Revert Window.content to being a Panel.
Jordan Miner <jminer7@gmail.com>
parents:
35
diff
changeset
|
300 void content(Panel panel) { |
0 | 301 if(panel is null) |
302 throw new IllegalArgumentException("content must not be null"); | |
303 // TODO: remove handlers | |
304 super.remove(panel); | |
305 super.add(_content = panel); | |
306 _content.resized += &whenContentResized; | |
307 _content.minSizeChanged += &whenContentMinSizeChanged; | |
308 _content.maxSizeChanged += &whenContentMaxSizeChanged; | |
309 | |
310 auto best = _content.bestSize; | |
311 _content.minSize = best; | |
312 _content.maxSize = Size(_content.elasticX ? 0 : best.width, | |
313 _content.elasticY ? 0 : best.height); | |
314 resizable = _content.maxSize != best; // avoid calling elasticX/Y again | |
315 _content.size = best; | |
316 | |
317 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
318 |
0 | 319 bool ignoreResize; |
320 void whenContentResized(EventArgs e) { | |
321 if(ignoreResize) | |
322 return; | |
323 ignoreResize = true; | |
324 size = _content.size + _borderSize; | |
325 ignoreResize = false; | |
326 } | |
327 void whenContentMinSizeChanged(EventArgs e) { | |
328 if(!handleCreated) | |
329 return; | |
330 backend_contentMinSizeChanged; | |
331 } | |
332 void whenContentMaxSizeChanged(EventArgs e) { | |
333 if(!handleCreated) | |
334 return; | |
335 backend_contentMaxSizeChanged; | |
336 } | |
337 override void whenResized(EventArgs e) { | |
338 if(ignoreResize) | |
339 return; | |
340 _content._location = Point(_borderSize.left, _borderSize.top); | |
341 ignoreResize = true; | |
342 _content.size = _size-_borderSize; | |
343 ignoreResize = false; | |
344 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
345 |
0 | 346 /** |
347 * If the handle has not yet been created, calling this will cause it to be. | |
348 * Under the Windows backend, returns a HWND. | |
349 * Under the X backend, returns a Window. | |
350 * Returns: the backend specific native handle. | |
351 */ | |
352 typeof(_handle) handle() { | |
353 if(!handleCreated) | |
354 recreateHandle(); | |
355 assert(Thread.getThis() is Application.eventThread || | |
356 Application.eventThread is null, | |
12
7a7e5f9bd1ae
Implement invoke() and invokeNow() on Windows.
Jordan Miner <jminer7@gmail.com>
parents:
5
diff
changeset
|
357 "Controls must be accessed and changed only on the event thread. Use invokeNow() from other threads."); |
0 | 358 return _handle; |
359 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
360 |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
361 /// |
0 | 362 bool handleCreated() { return backend_handleCreated; } |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
363 |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
364 /// |
0 | 365 void recreateHandle() { |
366 backend_recreateHandle(); | |
367 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
368 |
0 | 369 override protected Graphics quickCreateGraphics() { |
370 if(!handleCreated) | |
371 return null; | |
372 return backend_quickCreateGraphics(); | |
373 } | |
374 override bool onScreen() { | |
375 return true; | |
376 } | |
377 override Point screenLocation() { | |
378 return location; | |
379 } | |
380 override Point contentToScreen(Point pt) { | |
381 return pt + location; | |
382 } | |
383 override Point screenToContent(Point pt) { | |
384 return pt - location; | |
385 } | |
386 override bool topLevel() { return true; } | |
387 override Container parent() { return null; } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
388 |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
389 // 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
|
390 // 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
|
391 // but don't if it does not |
0 | 392 void owner(Window w) { |
393 _owner = w; | |
394 if(!handleCreated) | |
395 return; | |
396 recreateHandle(); | |
397 } | |
398 Window owner() { return _owner; } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
399 |
0 | 400 alias Control.visible visible; |
401 void visible(bool b) { | |
402 _visible = b; | |
403 backend_visible = b; | |
404 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
405 |
0 | 406 /** |
55
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
407 * |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
408 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
409 bool active() { return _active; } |
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 */ |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
413 void activate() { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
414 if(!handleCreated) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
415 return; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
416 backend_activate(); |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
417 } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
418 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
419 /** |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
420 * 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
|
421 * maximized. |
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 WindowState state() { return _state; } |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
424 /// ditto |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
425 void state(WindowState s) { |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
426 _state = s; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
427 if(!handleCreated) |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
428 return; |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
429 backend_state = s; |
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 |
c138461bf845
Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents:
54
diff
changeset
|
432 /** |
0 | 433 * Gets or sets what border this window will have around its contents. |
434 * The default is WindowBorderStyle.Normal. | |
435 */ | |
436 WindowBorderStyle borderStyle() { return _borderStyle; } | |
437 /// ditto | |
438 void borderStyle(WindowBorderStyle border) { | |
439 if(border > WindowBorderStyle.Tool) | |
440 throw new IllegalArgumentException("Window.borderStyle(): invalid border style"); | |
441 _borderStyle = border; | |
442 backend_borderStyle = border; | |
443 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
444 |
23
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
445 override void setCurrentCursor(Cursor cur) { |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
446 if(!handleCreated) |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
447 return; |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
448 backend_setCurrentCursor(cur); |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
449 } |
d55b5b998412
Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents:
12
diff
changeset
|
450 |
0 | 451 alias Control.repaint repaint; |
452 void repaint(Rect rect) { | |
453 if(!handleCreated) | |
454 return; | |
455 backend_repaint(rect); | |
456 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
457 |
0 | 458 /** |
459 * An array of rectangles in screen coordinates that the window will be | |
460 * snapped to. | |
461 */ | |
462 Rect[] snapRects = null; | |
463 /** | |
63 | 464 * Convenience method that sets snapRects to an array |
0 | 465 * with just the specified Rect. |
466 */ | |
467 void snapRect(Rect rect) { | |
468 snapRects = [rect]; | |
469 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
470 |
0 | 471 /** |
63 | 472 * The snapDistance specifies how close a window has to be to a |
0 | 473 * snap rectangle for the window to snap to it. The default is 10 pixels. |
474 */ | |
475 uint snapDistance = 10; | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
476 |
0 | 477 /** |
478 * Gets or sets whether this window can be resized by the user. | |
479 * The default is true. | |
480 */ | |
481 bool resizable() { return _resizable; } | |
482 /// ditto | |
66 | 483 void resizable(bool b) { |
0 | 484 _resizable = b; |
485 if(!handleCreated) | |
486 return; | |
487 backend_resizable = b; | |
488 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
489 |
0 | 490 // TODO: 1.0 MinSize -> contentMinSize MaxSize -> contentMaxSize |
491 alias Control.location location; | |
492 void location(Point pt) { | |
493 super.location(pt); | |
494 if(!handleCreated) | |
495 return; | |
496 backend_location = pt; | |
497 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
498 |
0 | 499 alias Control.size size; |
500 void size(Size size) { | |
501 super.size(size); | |
502 _content.size = size - _borderSize; | |
503 if(!handleCreated) | |
504 return; | |
505 backend_size = size; | |
506 } | |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
507 |
0 | 508 alias Control.text text; |
509 void text(string str) { | |
510 super.text(str); | |
511 if(!handleCreated) | |
512 return; | |
513 backend_text = str; | |
514 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
1
diff
changeset
|
515 |
0 | 516 /** |
54
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
517 * 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
|
518 */ |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
519 BorderSize borderSize() { |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
520 return _borderSize; |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
521 } |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
522 |
3738a2d0bac3
Fix comments and add blank lines.
Jordan Miner <jminer7@gmail.com>
parents:
44
diff
changeset
|
523 /** |
63 | 524 * Moves this window to the specified position relative to the specified |
525 * control. If no control is specified, the window is positioned relative | |
526 * to the screen. | |
0 | 527 */ |
528 void position(Position pos, Control c = null) { | |
529 Rect rect; | |
530 if(c && c.onScreen) { | |
531 rect = c.screenLocation + c.size; | |
532 } else { | |
533 rect = desktopRect; | |
534 } | |
535 Point newLoc = Point(); | |
536 switch(pos) { | |
537 case Position.TopLeft: | |
538 case Position.Left: | |
539 case Position.BottomLeft: | |
540 newLoc.x = rect.x; | |
541 break; | |
542 case Position.Top: | |
543 case Position.Center: | |
544 case Position.Bottom: | |
545 newLoc.x = rect.x + (rect.width - width)/2; | |
546 break; | |
547 case Position.TopRight: | |
548 case Position.Right: | |
549 case Position.BottomRight: | |
550 newLoc.x = rect.x + rect.width - width; | |
551 break; | |
552 } | |
553 switch(pos) { | |
554 case Position.TopLeft: | |
555 case Position.Top: | |
556 case Position.TopRight: | |
557 newLoc.y = rect.y; | |
558 break; | |
559 case Position.Left: | |
560 case Position.Center: | |
561 case Position.Right: | |
562 newLoc.y = rect.y + (rect.height - height)/2; | |
563 break; | |
564 case Position.BottomLeft: | |
565 case Position.Bottom: | |
566 case Position.BottomRight: | |
567 newLoc.y = rect.y + rect.height - height; | |
568 break; | |
569 } | |
570 location = newLoc; | |
571 } | |
572 } | |
573 |