0
|
1 // Written in the D programming language
|
|
2 // www.digitalmars.com/d/
|
|
3
|
|
4 /*
|
|
5 * The contents of this file are subject to the Mozilla Public License Version
|
|
6 * 1.1 (the "License"); you may not use this file except in compliance with
|
|
7 * the License. You may obtain a copy of the License at
|
|
8 * http://www.mozilla.org/MPL/
|
|
9 *
|
|
10 * Software distributed under the License is distributed on an "AS IS" basis,
|
|
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
12 * for the specific language governing rights and limitations under the
|
|
13 * License.
|
|
14 *
|
|
15 * The Original Code is the Dynamin library.
|
|
16 *
|
|
17 * The Initial Developer of the Original Code is Jordan Miner.
|
|
18 * Portions created by the Initial Developer are Copyright (C) 2007-2009
|
|
19 * the Initial Developer. All Rights Reserved.
|
|
20 *
|
|
21 * Contributor(s):
|
|
22 * Jordan Miner <jminer7@gmail.com>
|
|
23 *
|
|
24 */
|
|
25
|
|
26 module dynamin.gui.check_box;
|
|
27
|
|
28 import dynamin.all_core;
|
|
29 import dynamin.all_gui;
|
|
30 import dynamin.all_painting;
|
|
31 import tango.io.Stdout;
|
|
32
|
|
33 enum CheckState {
|
|
34 ///
|
|
35 Unchecked,
|
|
36 ///
|
|
37 Checked,
|
|
38 ///
|
|
39 Both
|
|
40 }
|
|
41
|
|
42 /**
|
|
43 * A control that can be checked or unchecked independent of other controls.
|
|
44 *
|
|
45 * The appearance of a check box with Windows Classic:
|
|
46 *
|
|
47 * $(IMAGE ../web/example_check_box.png)
|
|
48 */
|
|
49 class CheckBox : Button {
|
|
50 protected:
|
|
51 CheckState _checkState = CheckState.Unchecked;
|
|
52 override void whenClicked(EventArgs e) {
|
|
53 checked = !checked;
|
|
54 focus();
|
|
55 }
|
|
56 override void whenPainting(PaintingEventArgs e) {
|
|
57 Theme.current.CheckBox_paint(this, e.graphics);
|
|
58 }
|
|
59
|
|
60 public:
|
|
61 /// This event occurs after .
|
|
62 Event!() checkedChanged;
|
|
63 /// Override this method in a subclass to handle the SelectedChanged event.
|
|
64 protected void whenCheckedChanged(EventArgs e) { }
|
|
65 this() {
|
|
66 checkedChanged = new Event!()(&whenCheckedChanged);
|
|
67 _focusable = true;
|
|
68 }
|
|
69 this(string text) {
|
|
70 this();
|
|
71 this.text = text;
|
|
72 }
|
|
73 bool checked() {
|
|
74 return _checkState == CheckState.Checked;
|
|
75 }
|
|
76 void checked(bool b) {
|
|
77 _checkState = b ? CheckState.Checked : CheckState.Unchecked;
|
|
78 repaint();
|
|
79 checkedChanged(new EventArgs);
|
|
80 }
|
|
81 override Size bestSize() {
|
|
82 return Size(70, 15);
|
|
83 }
|
|
84 override void paintFore(Graphics g) {
|
|
85 g.drawText(text, 0, (height-g.getTextExtents(text).height)/2);
|
|
86 }
|
|
87 }
|
|
88
|