1
2
3
4
5
6 using System;
7
8 namespace System.Windows
9 {
10 public ControlCreateParams& GroupBoxControlCreateParams(ControlCreateParams& controlCreateParams, ButtonStyle buttonStyle)
11 {
12 controlCreateParams.SetWindowClassName("BUTTON");
13 controlCreateParams.SetWindowStyle(cast<WindowStyle>(DefaultChildWindowStyle() | buttonStyle));
14 controlCreateParams.SetBackgroundColor(DefaultControlBackgroundColor());
15 return controlCreateParams;
16 }
17
18 public ControlCreateParams& GroupBoxControlCreateParams(ControlCreateParams& controlCreateParams)
19 {
20 return GroupBoxControlCreateParams(controlCreateParams, ButtonStyle.BS_GROUPBOX);
21 }
22
23 public class GroupBoxCreateParams
24 {
25 public nothrow GroupBoxCreateParams(ControlCreateParams& controlCreateParams_) : controlCreateParams(controlCreateParams_)
26 {
27 }
28 public nothrow GroupBoxCreateParams& Defaults()
29 {
30 return *this;
31 }
32 public ControlCreateParams& controlCreateParams;
33 }
34
35 public class GroupBox : ButtonBase
36 {
37 public GroupBox(const Color& backgroundColor, const string& text, const Point& location, const Size& size, Dock dock, Anchors anchors) :
38 base("BUTTON", DefaultWindowClassStyle(), cast<WindowStyle>(DefaultChildWindowStyle() | ButtonStyle.BS_GROUPBOX), DefaultExtendedWindowStyle(),
39 backgroundColor, text, location, size, dock, anchors), children(this), checkedRadioButton(null)
40 {
41 }
42 public GroupBox(const string& text, const Point& location, const Size& size, Dock dock, Anchors anchors) :
43 this(DefaultControlBackgroundColor(), text, location, size, dock, anchors)
44 {
45 }
46 public GroupBox(GroupBoxCreateParams& createParams) : base(createParams.controlCreateParams), children(this), checkedRadioButton(null)
47 {
48 }
49 public void AddChild(Control* child)
50 {
51 children.AddChild(child);
52 ControlEventArgs args(child);
53 OnControlAdded(args);
54 }
55 public UniquePtr<Control> RemoveChild(Control* child)
56 {
57 UniquePtr<Component> childComponent = children.RemoveChild(child);
58 ControlEventArgs args(child);
59 OnControlRemoved(args);
60 return UniquePtr<Control>(childComponent.Release() as Control*);
61 }
62 public void InsertChildBefore(Control* child, Control* before)
63 {
64 children.InsertBefore(child, before);
65 ControlEventArgs args(child);
66 OnControlAdded(args);
67 }
68 public void InsertChildAfter(Control* child, Control* after)
69 {
70 children.InsertAfter(child, after);
71 ControlEventArgs args(child);
72 OnControlAdded(args);
73 }
74 public nothrow const Container& Children() const
75 {
76 return children;
77 }
78 public inline nothrow RadioButton* CheckedRadioButton() const
79 {
80 return checkedRadioButton;
81 }
82 public void SetCheckedRadioButton(RadioButton* radioButton)
83 {
84 if (radioButton != checkedRadioButton)
85 {
86 if (checkedRadioButton != null)
87 {
88 checkedRadioButton->SetChecked(false);
89 }
90 checkedRadioButton = radioButton;
91 if (checkedRadioButton != null)
92 {
93 checkedRadioButton->SetChecked(true);
94 }
95 }
96 }
97 internal inline nothrow void ResetCheckedRadioButton()
98 {
99 checkedRadioButton = null;
100 }
101 protected override void OnCreated()
102 {
103 base->OnCreated();
104 Graphics graphics = Graphics.FromWindowHandle(Handle());
105 const FontHandle& fontHandle = GetFontHandle(graphics);
106 if (!fontHandle.IsNull())
107 {
108 SendSetFontMessage(fontHandle);
109 }
110 SubClassCommandWndProc();
111 }
112 protected override void OnControlAdded(ControlEventArgs& args)
113 {
114 base->OnControlAdded(args);
115 if (args.control is RadioButton*)
116 {
117 if (checkedRadioButton == null)
118 {
119 SetCheckedRadioButton(cast<RadioButton*>(args.control));
120 }
121 }
122 }
123 protected override void OnControlRemoved(ControlEventArgs& args)
124 {
125 base->OnControlRemoved(args);
126 if (args.control is RadioButton*)
127 {
128 if (checkedRadioButton == cast<RadioButton*>(args.control))
129 {
130 ResetCheckedRadioButton();
131 }
132 }
133 }
134 protected override void OnChildGotFocus(ControlEventArgs& args)
135 {
136 base->OnChildGotFocus(args);
137 Control* parentControl = ParentControl();
138 if (parentControl != null)
139 {
140 parentControl->OnChildGotFocus(args);
141 }
142 }
143 protected override void OnChildLostFocus(ControlEventArgs& args)
144 {
145 base->OnChildLostFocus(args);
146 Control* parentControl = ParentControl();
147 if (parentControl != null)
148 {
149 parentControl->OnChildLostFocus(args);
150 }
151 }
152 internal override nothrow Control* GetFirstEnabledTabStopControl() const
153 {
154 Component* child = children.FirstChild();
155 while (child != null)
156 {
157 if (child is Control*)
158 {
159 Control* control = cast<Control*>(child);
160 Control* tabStopChild = control->GetFirstEnabledTabStopControl();
161 if (tabStopChild != null)
162 {
163 return tabStopChild;
164 }
165 }
166 child = child->NextSibling();
167 }
168 return null;
169 }
170 internal override nothrow Control* GetLastEnabledTabStopControl() const
171 {
172 Component* child = children.LastChild();
173 while (child != null)
174 {
175 if (child is Control*)
176 {
177 Control* control = cast<Control*>(child);
178 Control* tabStopChild = control->GetLastEnabledTabStopControl();
179 if (tabStopChild != null)
180 {
181 return tabStopChild;
182 }
183 }
184 child = child->PrevSibling();
185 }
186 return null;
187 }
188 private Container children;
189 private RadioButton* checkedRadioButton;
190 }
191 }