1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
34 namespace System.Windows.Forms {
35 public class ContainerControl : ScrollableControl, IContainerControl {
36 private Control active_control;
37 private Control focused_control;
38 private Control unvalidated_control;
40 private SizeF auto_scale_dimensions;
41 private AutoScaleMode auto_scale_mode;
44 #region Public Constructors
45 public ContainerControl() {
46 active_control = null;
47 focused_control = null;
48 unvalidated_control = null;
49 ControlRemoved += new ControlEventHandler(OnControlRemoved);
51 auto_scale_dimensions = SizeF.Empty;
52 auto_scale_mode = AutoScaleMode.None;
55 #endregion // Public Constructors
57 #region Public Instance Properties
59 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
60 public Control ActiveControl {
62 return active_control;
66 if ((active_control==value) || (value==null)) {
70 active_control = value;
72 if (!Contains(value) && this != value) {
73 throw new ArgumentException("Not a child control");
79 // Scroll control into view
81 // Let the control know it's selected
87 public SizeF AutoScaleDimensions {
89 return auto_scale_dimensions;
93 auto_scale_dimensions = value;
97 public SizeF AutoScaleFactor {
99 if (auto_scale_dimensions.IsEmpty) {
100 return new SizeF(1f, 1f);
102 return new SizeF(CurrentAutoScaleDimensions.Width / auto_scale_dimensions.Width,
103 CurrentAutoScaleDimensions.Height / auto_scale_dimensions.Height);
108 [MonoTODO("Call scaling method")]
109 public virtual AutoScaleMode AutoScaleMode {
111 return auto_scale_mode;
114 if (auto_scale_mode != value) {
115 auto_scale_mode = value;
124 public override BindingContext BindingContext {
126 if (base.BindingContext == null) {
127 base.BindingContext = new BindingContext();
129 return base.BindingContext;
133 base.BindingContext = value;
138 [MonoTODO("Revisit when System.Drawing.GDI.WindowsGraphics.GetTextMetrics is done or come up with other cross-plat avg. font width calc method")]
139 public SizeF CurrentAutoScaleDimensions {
141 switch(auto_scale_mode) {
142 case AutoScaleMode.Dpi: {
147 bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
148 g = Graphics.FromImage(bmp);
149 size = new SizeF(g.DpiX, g.DpiY);
155 case AutoScaleMode.Font: {
156 // http://msdn2.microsoft.com/en-us/library/system.windows.forms.containercontrol.currentautoscaledimensions(VS.80).aspx
157 // Implement System.Drawing.GDI.WindowsGraphics.GetTextMetrics first...
162 return auto_scale_dimensions;
168 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
169 public Form ParentForm {
173 parent = this.parent;
175 while (parent != null) {
176 if (parent is Form) {
179 parent = parent.parent;
185 #endregion // Public Instance Properties
187 #region Protected Instance Methods
188 protected override CreateParams CreateParams {
190 return base.CreateParams;
193 #endregion // Public Instance Methods
195 #region Public Instance Methods
197 static bool ValidateWarned;
198 public bool Validate() {
199 //throw new NotImplementedException();
200 if (!ValidateWarned) {
201 Console.WriteLine("ContainerControl.Validate is not yet implemented");
202 ValidateWarned = true;
207 bool IContainerControl.ActivateControl(Control control) {
208 return Select(control);
210 #endregion // Public Instance Methods
212 #region Protected Instance Methods
213 [EditorBrowsable (EditorBrowsableState.Advanced)]
214 protected override void AdjustFormScrollbars(bool displayScrollbars) {
215 base.AdjustFormScrollbars(displayScrollbars);
218 protected override void Dispose(bool disposing) {
219 base.Dispose(disposing);
222 // LAMESPEC This used to be documented, but it's not in code
223 // and no longer listed in MSDN2
224 // [EditorBrowsable (EditorBrowsableState.Advanced)]
225 // protected override void OnControlRemoved(ControlEventArgs e) {
226 private void OnControlRemoved(object sender, ControlEventArgs e) {
227 if (e.Control == this.unvalidated_control) {
228 this.unvalidated_control = null;
231 if (e.Control == this.active_control) {
232 this.unvalidated_control = null;
235 // base.OnControlRemoved(e);
238 protected override void OnCreateControl() {
239 base.OnCreateControl();
240 // MS seems to call this here, it gets the whole databinding process started
241 OnBindingContextChanged (EventArgs.Empty);
244 [EditorBrowsable (EditorBrowsableState.Advanced)]
245 protected override bool ProcessDialogChar(char charCode) {
247 if (ProcessMnemonic(charCode)) {
251 return base.ProcessDialogChar(charCode);
254 protected override bool ProcessDialogKey(Keys keyData) {
258 key = keyData & Keys.KeyCode;
263 if (ProcessTabKey((Control.ModifierKeys & Keys.Shift) == 0)) {
283 if (SelectNextControl(active_control, forward, false, false, true)) {
291 return base.ProcessDialogKey(keyData);
294 protected override bool ProcessMnemonic(char charCode) {
302 c = GetNextControl(c, true);
304 // This is stupid. I want to be able to call c.ProcessMnemonic directly
305 if (c.ProcessControlMnemonic(charCode)) {
315 } while (c != active_control);
320 protected virtual bool ProcessTabKey(bool forward) {
321 return SelectNextControl(active_control, forward, true, true, true);
324 protected override void Select(bool directed, bool forward) {
325 base.Select(directed, forward);
328 protected virtual void UpdateDefaultButton() {
332 [EditorBrowsable (EditorBrowsableState.Advanced)]
333 protected override void WndProc(ref Message m) {
336 #endregion // Protected Instance Methods
338 internal virtual void CheckAcceptButton()
340 // do nothing here, only called if it is a Form