annotate dynamin/gui/control.d @ 64:aa7eafe2865d

Add setTabOrder()
author Jordan Miner <jminer7@gmail.com>
date Sat, 08 Aug 2009 22:32:14 -0500
parents cf7c5f968306
children 419e38206522
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
1 // Written in the D programming language
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
2 // www.digitalmars.com/d/
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
3
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
4 /*
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
5 * The contents of this file are subject to the Mozilla Public License Version
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
6 * 1.1 (the "License"); you may not use this file except in compliance with
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
7 * the License. You may obtain a copy of the License at
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
8 * http://www.mozilla.org/MPL/
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
9 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
10 * Software distributed under the License is distributed on an "AS IS" basis,
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
12 * for the specific language governing rights and limitations under the
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
13 * License.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
14 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
15 * The Original Code is the Dynamin library.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
16 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
17 * The Initial Developer of the Original Code is Jordan Miner.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
19 * the Initial Developer. All Rights Reserved.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
20 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
21 * Contributor(s):
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
22 * Jordan Miner <jminer7@gmail.com>
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
23 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
24 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
25
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
26 module dynamin.gui.control;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
27
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
28 import dynamin.all_core;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
29 import dynamin.all_painting;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
30 import dynamin.gui.container;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
31 import dynamin.gui.events;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
32 import dynamin.gui.window;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
33 import dynamin.gui.cursor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
34 import tango.io.Stdout;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
35
55
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
36 //{{{ hotControl
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
37 Control hotControl;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
38 // the hot control is the one the mouse is over
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
39 package void setHotControl(Control c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
40 if(c !is hotControl) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
41 if(hotControl)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
42 hotControl.mouseLeft(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
43 hotControl = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
44 if(c)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
45 c.mouseEntered(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
46 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
47 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
48 package Control getHotControl() { return hotControl; }
55
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
49 //}}}
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
50
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
51 //{{{ captorControl
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
52 Control captorControl;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
53 package void setCaptorControl(Control c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
54 captorControl = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
55 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
56 package Control getCaptorControl() { return captorControl; }
55
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
57 //}}}
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
58
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
59 //{{{ focusedControl
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
60 Control focusedControl;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
61 package void setFocusedControl(Control c) {
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
62 if(focusedControl is c)
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
63 return;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
64 scope e = new EventArgs;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
65 if(focusedControl)
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
66 focusedControl.focusLost(e);
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
67 focusedControl = c;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
68 if(focusedControl)
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
69 focusedControl.focusGained(e);
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
70 }
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
71 package Control getFocusedControl() { return focusedControl; }
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
72 //}}}
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
73
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
74 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
75 * The painting event is an exception to the rule that added handlers are called
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
76 * before whenPainting. The painting event is far more useful since
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
77 * added handles are called after the control's whenPainting has finished.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
78 * Otherwise, anything handlers painted would likely be painted over when the
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
79 * control painted.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
80 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
81 class Control {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
82 protected:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
83 bool _visible;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
84 bool _focusable;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
85 bool _focused;
49
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
86 int _tabIndex;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
87 package Point _location;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
88 package Size _size;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
89 string _text;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
90 Color _backColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
91 Color _foreColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
92 Font _font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
93 Cursor _cursor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
94 Container _parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
95 bool _elasticX, _elasticY;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
96 public:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
97 protected void dispatchMouseEntered(EventArgs e) {
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
98 setCurrentCursor(_cursor);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
99 mouseEntered.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
100 mouseEntered.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
101 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
102 protected void dispatchMouseDown(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
103 setCaptorControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
104 mouseDown.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
105 mouseDown.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
106 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
107 protected void dispatchMouseUp(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
108 setCaptorControl(null);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
109 mouseUp.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
110 mouseUp.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
111 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
112 protected void dispatchMouseMoved(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
113 setHotControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
114 mouseMoved.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
115 mouseMoved.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
116 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
117 protected void dispatchMouseDragged(MouseEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
118 setHotControl(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
119 mouseDragged.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
120 mouseDragged.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
121 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
122 protected void dispatchMouseTurned(MouseTurnedEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
123 mouseTurned.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
124 mouseTurned.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
125 if(!e.stopped && _parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
126 _parent.mouseTurned(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
127 }
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
128 protected void dispatchKeyDown(KeyEventArgs e) {
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
129 keyDown.callHandlers(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
130 keyDown.callMainHandler(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
131 if(!e.stopped && _parent)
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
132 _parent.keyDown(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
133 }
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
134 protected void dispatchKeyUp(KeyEventArgs e) {
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
135 keyUp.callHandlers(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
136 keyUp.callMainHandler(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
137 if(!e.stopped && _parent)
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
138 _parent.keyUp(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
139 }
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
140 protected void dispatchKeyTyped(KeyTypedEventArgs e) {
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
141 keyTyped.callHandlers(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
142 keyTyped.callMainHandler(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
143 if(!e.stopped && _parent)
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
144 _parent.keyTyped(e);
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
145 }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
146 protected void dispatchPainting(PaintingEventArgs e) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
147 e.graphics.save();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
148 painting.callMainHandler(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
149 e.graphics.restore();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
150 e.graphics.save();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
151 // TODO: every call to a handler should be wrapped in a save/restore
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
152 painting.callHandlers(e);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
153 e.graphics.restore();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
154 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
155
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
156 /// Override this method in a subclass to handle the moved event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
157 protected void whenMoved(EventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
158 /// This event occurs after the control has been moved.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
159 Event!(whenMoved) moved;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
160
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
161 /// Override this method in a subclass to handle the resized event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
162 protected void whenResized(EventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
163 /// This event occurs after the control has been resized.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
164 Event!(whenResized) resized;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
165
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
166 /// Override this method in a subclass to handle the mouseEntered event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
167 protected void whenMouseEntered(EventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
168 /// This event occurs after the mouse has entered the control.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
169 Event!(whenMouseEntered) mouseEntered;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
170
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
171 /// Override this method in a subclass to handle the mouseLeft event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
172 protected void whenMouseLeft(EventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
173 /// This event occurs after the mouse has left the control.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
174 Event!(whenMouseLeft) mouseLeft;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
175
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
176 /// Override this method in a subclass to handle the mouseDown event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
177 protected void whenMouseDown(MouseEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
178 /// This event occurs after a mouse button is pressed.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
179 Event!(whenMouseDown) mouseDown;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
180
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
181 /// Override this method in a subclass to handle the mouseUp event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
182 protected void whenMouseUp(MouseEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
183 /// This event occurs after a mouse button is released.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
184 Event!(whenMouseUp) mouseUp;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
185
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
186 /// Override this method in a subclass to handle the mouseMoved event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
187 protected void whenMouseMoved(MouseEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
188 /// This event occurs after the mouse has been moved.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
189 Event!(whenMouseMoved) mouseMoved;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
190
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
191 /// Override this method in a subclass to handle the mouseMoved event.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
192 protected void whenMouseDragged(MouseEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
193 /// This event occurs after the mouse has been moved.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
194 Event!(whenMouseDragged) mouseDragged;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
195
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
196 /// Override this method in a subclass to handle the mouseTurned event.
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
197 /// If this event is not stopped, it will be sent to the control's parent.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
198 protected void whenMouseTurned(MouseTurnedEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
199 /// This event occurs after the mouse wheel has been turned.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
200 Event!(whenMouseTurned) mouseTurned;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
201
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
202 /// Override this method in a subclass to handle the keyDown event.
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
203 /// If this event is not stopped, it will be sent to the control's parent.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
204 protected void whenKeyDown(KeyEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
205 /// This event occurs after a key is pressed.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
206 Event!(whenKeyDown) keyDown;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
207
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
208 /// Override this method in a subclass to handle the keyTyped event.
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
209 /// If this event is not stopped, it will be sent to the control's parent.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
210 protected void whenKeyTyped(KeyTypedEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
211 /// This event occurs after a character key is pressed.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
212 Event!(whenKeyTyped) keyTyped;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
213
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
214 /// Override this method in a subclass to handle the keyUp event.
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
215 /// If this event is not stopped, it will be sent to the control's parent.
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
216 protected void whenKeyUp(KeyEventArgs e) { }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
217 /// This event occurs after a key is released.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
218 Event!(whenKeyUp) keyUp;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
219
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
220 /// Override this method in a subclass to handle the painting event.
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
221 protected void whenPainting(PaintingEventArgs e) {
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
222 e.graphics.source = backColor;
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
223 e.graphics.paint();
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
224 }
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
225 /// This event occurs when the control needs to be painted.
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
226 Event!(whenPainting) painting;
8
b621b528823d whenXX methods have to come before the event if switched to template mixins.
Jordan Miner <jminer7@gmail.com>
parents: 5
diff changeset
227
55
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
228 /// Override this method in a subclass to handle the focusGained event.
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
229 protected void whenFocusGained(EventArgs e) {
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
230 repaint();
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
231 }
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
232 /// This event occurs after this control is focused.
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
233 Event!(whenFocusGained) focusGained;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
234
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
235 /// Override this method in a subclass to handle the focusLost event.
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
236 protected void whenFocusLost(EventArgs e) {
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
237 repaint();
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
238 }
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
239 /// This event occurs after this control loses focus.
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
240 Event!(whenFocusLost) focusLost;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
241
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
242 this() {
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
243 moved.mainHandler = &whenMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
244 resized.mainHandler = &whenResized;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
245 mouseEntered.mainHandler = &whenMouseEntered;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
246 mouseEntered.dispatcher = &dispatchMouseEntered;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
247 mouseLeft.mainHandler = &whenMouseLeft;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
248 mouseDown.mainHandler = &whenMouseDown;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
249 mouseDown.dispatcher = &dispatchMouseDown;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
250 mouseUp.mainHandler = &whenMouseUp;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
251 mouseUp.dispatcher = &dispatchMouseUp;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
252 mouseMoved.mainHandler = &whenMouseMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
253 mouseMoved.dispatcher = &dispatchMouseMoved;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
254 mouseDragged.mainHandler = &whenMouseDragged;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
255 mouseDragged.dispatcher = &dispatchMouseDragged;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
256 mouseTurned.mainHandler = &whenMouseTurned;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
257 mouseTurned.dispatcher = &dispatchMouseTurned;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
258 keyDown.mainHandler = &whenKeyDown;
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
259 keyDown.dispatcher = &dispatchKeyDown;
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
260 keyTyped.mainHandler = &whenKeyTyped;
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
261 keyTyped.dispatcher = &dispatchKeyTyped;
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
262 keyUp.mainHandler = &whenKeyUp;
47
41b76c218851 Change keyUp, keyDown, and keyTyped to bubble to a control's parent if not stopped.
Jordan Miner <jminer7@gmail.com>
parents: 23
diff changeset
263 keyUp.dispatcher = &dispatchKeyUp;
10
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
264 painting.mainHandler = &whenPainting;
ccc108b25a0a Convert to using a struct for events. Fix some comments too.
Jordan Miner <jminer7@gmail.com>
parents: 8
diff changeset
265 painting.dispatcher = &dispatchPainting;
55
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
266 focusGained.mainHandler = &whenFocusGained;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
267 focusLost.mainHandler = &whenFocusLost;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
268
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
269 _location = Point(0, 0);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
270 _size = Size(100, 100);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
271 _text = "";
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
272 _focusable = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
273 _focused = false;
49
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
274 _tabIndex = 0;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
275 _visible = true;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
276 _cursor = Cursor.Arrow;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
277 _elasticX = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
278 _elasticY = false;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
279
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
280 // TODO: remove these when themes mature
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
281 _foreColor = Color.Black;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
282 _font = new Font("Tahoma", 11);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
283 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
284
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
285 protected Graphics quickCreateGraphics() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
286 if(_parent is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
287 return null;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
288 auto g = _parent.quickCreateGraphics();
60
cf7c5f968306 Fix crash in withGraphics() if there wasn't a Window ancestor with a handle.
Jordan Miner <jminer7@gmail.com>
parents: 59
diff changeset
289 if(g)
cf7c5f968306 Fix crash in withGraphics() if there wasn't a Window ancestor with a handle.
Jordan Miner <jminer7@gmail.com>
parents: 59
diff changeset
290 g.translate(location);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
291 return g;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
292 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
293
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
294 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
295 * Sets the specified Graphics' font and source to this control's font
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
296 * and foreground color. Also, clips to this control's rectangle.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
297 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
298 void setupGraphics(Graphics g) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
299 g.rectangle(0, 0, width, height);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
300 g.clip();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
301 g.font = font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
302 g.source = foreColor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
303 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
304
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
305 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
306 * Creates a Graphics, calls the specified delegate with it, and deletes
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
307 * it to release resources.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
308 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
309 void withGraphics(void delegate(Graphics g) dg) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
310 auto g = quickCreateGraphics();
60
cf7c5f968306 Fix crash in withGraphics() if there wasn't a Window ancestor with a handle.
Jordan Miner <jminer7@gmail.com>
parents: 59
diff changeset
311 if(!g)
cf7c5f968306 Fix crash in withGraphics() if there wasn't a Window ancestor with a handle.
Jordan Miner <jminer7@gmail.com>
parents: 59
diff changeset
312 return;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
313 setupGraphics(g);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
314 dg(g);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
315 delete g;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
316 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
317
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
318 /**
55
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
319 * Returns whether or not this control can receive focus.
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
320 */
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
321 bool focusable() {
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
322 return _focusable;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
323 }
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
324 void focusable(bool f) {
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
325 _focusable = f;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
326 // TODO:
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
327 }
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
328
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
329 /**
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
330 * Returns whether this control currently has focus. A control with focus
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
331 * receives keyboard events.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
332 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
333 bool focused() {
55
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
334 return getFocusedControl() is this;
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
335 }
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
336
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
337 /**
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
338 * Returns true if this control should visually show when it has focus
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
339 * and returns false if not. Focus is usually hidden until the
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
340 * user uses the keyboard to navigate.
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
341 *
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
342 * A text box is one control that shows when it is
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
343 * focused (by its caret), regardless of this value. (Because showing
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
344 * focus isn't the sole purpose of a caret.)
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
345 */
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
346 bool showFocus() {
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
347 auto top = getTopLevel();
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
348 return top && (cast(Window)top).showFocus;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
349 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
350
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
351 /**
49
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
352 * Gets or sets this control's tab index. The tab index of controls
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
353 * decides in what order they are focused when the tab key is pressed.
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
354 * If multiple controls in a window have the same tab index, focus is
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
355 * changed based on the order they were added to the window.
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
356 * The default is 0.
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
357 */
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
358 int tabIndex() {
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
359 return _tabIndex;
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
360 }
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
361 /// ditto
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
362 void tabIndex(int i) {
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
363 _tabIndex = i;
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
364 }
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
365
62742ce025ec Add Control.tabIndex
Jordan Miner <jminer7@gmail.com>
parents: 47
diff changeset
366 /**
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
367 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
368 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
369 void focus() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
370 if(!_focusable)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
371 return;
56
c2566ab82535 Edit comments and fix a typo.
Jordan Miner <jminer7@gmail.com>
parents: 55
diff changeset
372
50
a18c2fd9fe36 Fix a crash if Control.focus was called on a Control not in a Window.
Jordan Miner <jminer7@gmail.com>
parents: 49
diff changeset
373 auto top = getTopLevel();
a18c2fd9fe36 Fix a crash if Control.focus was called on a Control not in a Window.
Jordan Miner <jminer7@gmail.com>
parents: 49
diff changeset
374 if(!top)
a18c2fd9fe36 Fix a crash if Control.focus was called on a Control not in a Window.
Jordan Miner <jminer7@gmail.com>
parents: 49
diff changeset
375 return;
55
c138461bf845 Add focusing and other changes that are related
Jordan Miner <jminer7@gmail.com>
parents: 53
diff changeset
376 if(auto win = cast(Window)top)
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
377 win.focusedControl = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
378 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
379
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
380 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
381 * Returns whether this control is on the screen. A control is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
382 * on screen if one of its ancestors is a top level window. Whether or
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
383 * not the control is visible has no bearing on this value. If a control
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
384 * has no parent, then it is clearly not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
385 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
386 bool onScreen() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
387 return _parent && _parent.onScreen;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
388 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
389
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
390 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
391 * Gets the location of this control in screen coordinates. An exception is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
392 * thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
393 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
394 Point screenLocation() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
395 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
396 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
397 return _parent.screenLocation + location;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
398 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
399
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
400 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
401 * Converts the specified point in content coordinates into screen
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
402 * coordinates. An exception is thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
403 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
404 Point contentToScreen(Point pt) { // TODO: content?? even on Window??
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
405 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
406 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
407 return _parent.contentToScreen(pt + location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
408 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
409
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
410 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
411 * Converts the specified point in screen coordinates into content
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
412 * coordinates. An exception is thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
413 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
414 Point screenToContent(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
415 if(!_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
416 throw new Exception("control is not on screen");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
417 return _parent.screenToContent(pt) - location; // TODO: borders
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
418 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
419
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
420 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
421 * Converts the specified point in this control's content coordinates
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
422 * into the specified control's content coordinates. An exception is
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
423 * thrown if this control is not on the screen.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
424 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
425 Point contentToContent(Point pt, Control c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
426 return c.screenToContent(contentToScreen(pt));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
427 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
428
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
429 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
430 * Returns whether the specified point is inside this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
431 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
432 bool contains(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
433 return pt.x >= 0 && pt.y >= 0 && pt.x < width && pt.y < height;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
434 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
435 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
436 bool contains(real x, real y) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
437 return contains(Point(x, y));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
438 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
439
51
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
440 /**
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
441 * Returns true if this control is a top-level control and false otherwise.
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
442 * Top-level controls do not have parents. Non-top-level controls can only
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
443 * be shown on the screen by adding them as children to a top-level control.
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
444 * Currently, the only top-level control is Window.
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
445 */
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
446 bool topLevel() { return false; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
447 // TODO: return NativeControl/Window?
51
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
448 /**
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
449 * Loops over this control's ancestors, and if a top-level control is found,
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
450 * it is returned. If this control does not have a top-level ancestor,
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
451 * null is returned.
d5823ccfddc6 Add a couple doc comments.
Jordan Miner <jminer7@gmail.com>
parents: 50
diff changeset
452 */
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
453 Control getTopLevel() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
454 Control c = this;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
455 while(c.parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
456 c = c.parent;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
457 return c.topLevel ? c : null;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
458 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
459
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
460 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
461 * Gets this control's parent.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
462 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
463 Container parent() { return _parent; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
464 package void parent(Container c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
465 _parent = c;
53
6e33b00595e9 Fix capitalization in a couple comments.
Jordan Miner <jminer7@gmail.com>
parents: 51
diff changeset
466 //parentChanged(new EventArgs); // TODO: add event
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
467 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
468
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
469 /**
59
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
470 * Calls the specified delegate with each of this control's ancestors,
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
471 * starting with its parent and moving up. Returns the first ancestor
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
472 * that the delgate returns true for. If none are found, returns null.
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
473 */
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
474 Container findAncestor(bool delegate(Container) dg) {
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
475 Container anc = parent;
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
476 while(anc) {
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
477 if(dg(anc))
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
478 return anc;
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
479 anc = anc.parent;
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
480 }
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
481 return null;
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
482 }
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
483
d3ba5d4a3a27 Add Control.findAncestor
Jordan Miner <jminer7@gmail.com>
parents: 56
diff changeset
484 /**
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
485 * Gets or sets whether is control is visible. The default is true, except
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
486 * on top-level windows.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
487 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
488 //void visible(bool b) { visible = b; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
489 bool visible() { return _visible; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
490
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
491 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
492 * Gets or sets the location of this control in its parent's content
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
493 * coordinates.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
494 * Examples:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
495 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
496 * control.location = [5, 35];
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
497 * control.location = Point(50, 50);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
498 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
499 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
500 Point location() { return _location; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
501 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
502 void location(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
503 if((cast(Window)_parent) !is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
504 throw new Exception("cannot set location of a window's content");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
505 pt.x = round(pt.x);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
506 pt.y = round(pt.y);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
507 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
508 _location = pt;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
509 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
510 moved(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
511 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
512 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
513 void location(real[] pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
514 assert(pt.length == 2, "pt must be just an x and y");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
515 location = Point(pt[0], pt[1]);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
516 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
517
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
518 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
519 * Gets or sets the size of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
520 * Examples:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
521 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
522 * control.size = [75, 23];
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
523 * control.size = Size(80, 20);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
524 * -----
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
525 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
526 Size size() { return _size; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
527 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
528 void size(Size newSize) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
529 if(newSize.width < 0)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
530 newSize.width = 0;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
531 if(newSize.height < 0)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
532 newSize.height = 0;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
533 newSize.width = round(newSize.width);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
534 newSize.height = round(newSize.height);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
535 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
536 _size = newSize;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
537 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
538 resized(new EventArgs);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
539 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
540 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
541 void size(real[] newSize) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
542 assert(newSize.length == 2, "size must be just a width and height");
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
543 size = Size(newSize[0], newSize[1]);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
544 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
545
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
546 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
547 * Gets the size at which this control looks the best. It is intended that
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
548 * the control not be made smaller than this size, and only be made larger
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
549 * if it is elastic, or if it needs to be aligned with other controls.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
550 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
551 * This property should be overridden in subclasses to return a best size.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
552 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
553 Size bestSize() { return Size(100, 100); }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
554
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
555 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
556 * Gets the distance from the top of this control to the baseline of
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
557 * the first line of this control's text. If this control does not have
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
558 * text, 0 may be returned.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
559 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
560 int baseline() { return 0; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
561
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
562 /// Same as location.x
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
563 real x() { return location.x; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
564 /// Same as location.y
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
565 real y() { return location.y; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
566 /// Same as size.width
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
567 real width() { return size.width; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
568 /// Same as size.height
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
569 real height() { return size.height; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
570
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
571 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
572 * Gets or sets whether this control is elastic horizontally or vertically.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
573 * If a control is elastic, then it is intended to be made larger than its
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
574 * best size.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
575 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
576 bool elasticX() { return _elasticX; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
577 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
578 void elasticX(bool b) { _elasticX = b; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
579 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
580 bool elasticY() { return _elasticY; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
581 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
582 void elasticY(bool b) { _elasticY = b; }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
583
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
584 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
585 * Gets or sets the text that this control shows.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
586 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
587 string text() { return _text.dup; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
588 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
589 void text(string str) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
590 _text = str.dup;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
591 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
592 //TextChanged(EventArgs e) // TODO: add event
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
593 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
594
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
595 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
596 * Gets or sets the background color of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
597 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
598 Color backColor() { return _backColor; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
599 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
600 void backColor(Color c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
601 _backColor = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
602 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
603 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
604
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
605 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
606 * Gets or sets the foreground color of this control.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
607 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
608 Color foreColor() { return _foreColor; }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
609 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
610 void foreColor(Color c) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
611 _foreColor = c;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
612 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
613 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
614
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
615 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
616 * Gets or sets the font of this control uses to display text. A value of
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
617 * null means that the font is unset. When the font is null, the
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
618 * current theme's font is used. The default is null.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
619 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
620 Font font() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
621 // TODO: if font is null (unset), return from theme
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
622 //if(font is null)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
623 // return Theme.Current.Control_Font(this);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
624 //else
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
625 return _font;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
626 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
627 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
628 void font(Font f) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
629 _font = f;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
630 repaint();
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
631 }
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
632
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
633 void setCurrentCursor(Cursor cur) {
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
634 if(parent)
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
635 parent.setCurrentCursor(cur);
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
636 }
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
637 /**
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
638 * Gets or sets the mouse cursor that will be shown when the mouse
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
639 * is over this control.
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
640 */
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
641 Cursor cursor() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
642 return _cursor;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
643 }
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
644 /// ditto
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
645 void cursor(Cursor cur) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
646 if(_cursor is cur)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
647 return;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
648 _cursor = cur;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
649 if(getHotControl() is this)
23
d55b5b998412 Implement built-in mouse cursors with X.
Jordan Miner <jminer7@gmail.com>
parents: 15
diff changeset
650 setCurrentCursor(_cursor);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
651 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
652
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
653 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
654 * Causes the part of the control inside the specified
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
655 * rectangle to be repainted. The rectangle is in content coordinates.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
656 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
657 * The control will not be repainted before this method returns; rather,
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
658 * the area is just marked as needing to be repainted. The next time there
15
96b29f2efa4d Fix typo in doc comment.
Jordan Miner <jminer7@gmail.com>
parents: 10
diff changeset
659 * are no other system events to be processed, a painting event will
96b29f2efa4d Fix typo in doc comment.
Jordan Miner <jminer7@gmail.com>
parents: 10
diff changeset
660 * be called.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
661 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
662 void repaint(Rect rect) {
5
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
663 // TODO: make sure that parts clipped off by the parent are
4029d5af7542 Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
664 // not invalidated
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
665 if(_parent)
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
666 _parent.repaint(rect + location);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
667 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
668 /// ditto
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
669 void repaint(real x, real y, real width, real height) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
670 repaint(Rect(x, y, width, height));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
671 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
672 /**
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
673 * Causes the entire control to be repainted.
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
674 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
675 void repaint() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
676 repaint(Rect(0, 0, width, height));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
677 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
678 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
679
64
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
680 /**
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
681 * Sets the tabIndex of each control to be subsequent numbers. The first control
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
682 * will have an index of startIndex.
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
683 */
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
684 void setTabOrder(Control[] controls...) {
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
685 setTabOrder(0, controls);
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
686 }
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
687 /// ditto
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
688 void setTabOrder(int startIndex, Control[] controls...) {
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
689 foreach(c; controls)
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
690 c.tabIndex = startIndex++;
60
cf7c5f968306 Fix crash in withGraphics() if there wasn't a Window ancestor with a handle.
Jordan Miner <jminer7@gmail.com>
parents: 59
diff changeset
691 }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
692
64
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
693 unittest {
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
694 auto c1 = new Control;
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
695 auto c2 = new Control;
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
696 auto c3 = new Control;
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
697
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
698 // test setTabOrder()
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
699 setTabOrder(c1, c2, c3);
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
700 assert(c1.tabIndex == 0);
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
701 assert(c2.tabIndex == 1);
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
702 assert(c3.tabIndex == 2);
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
703
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
704 c1.withGraphics((Graphics g) { g.source = Color.Blue; });
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
705 }
aa7eafe2865d Add setTabOrder()
Jordan Miner <jminer7@gmail.com>
parents: 60
diff changeset
706