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;
33 namespace System.Windows.Forms {
34 public class ContainerControl : ScrollableControl, IContainerControl {
35 private Control active_control;
36 private Control focused_control;
37 private Control unvalidated_control;
39 #region Public Constructors
40 public ContainerControl() {
41 active_control = null;
42 focused_control = null;
43 unvalidated_control = null;
44 ControlRemoved += new ControlEventHandler(OnControlRemoved);
46 #endregion // Public Constructors
48 #region Public Instance Properties
50 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
51 public Control ActiveControl {
53 return active_control;
57 if ((active_control==value) || (value==null)) {
61 active_control = value;
63 if (!Contains(value) && this != value) {
64 throw new ArgumentException("Not a child control");
67 // Scroll control into view
69 // Let the control know it's selected
75 public override BindingContext BindingContext {
77 if (base.BindingContext == null) {
78 base.BindingContext = new BindingContext();
80 return base.BindingContext;
84 base.BindingContext = value;
89 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
90 public Form ParentForm {
96 while (parent != null) {
100 parent = parent.parent;
106 #endregion // Public Instance Properties
108 #region Protected Instance Methods
109 protected override CreateParams CreateParams {
111 return base.CreateParams;
114 #endregion // Public Instance Methods
116 #region Public Instance Methods
118 static bool ValidateWarned;
119 public bool Validate() {
120 //throw new NotImplementedException();
121 if (!ValidateWarned) {
122 Console.WriteLine("ContainerControl.Validate is not yet implemented");
123 ValidateWarned = true;
128 bool IContainerControl.ActivateControl(Control control) {
129 return Select(control);
131 #endregion // Public Instance Methods
133 #region Protected Instance Methods
134 [EditorBrowsable (EditorBrowsableState.Advanced)]
135 protected override void AdjustFormScrollbars(bool displayScrollbars) {
136 base.AdjustFormScrollbars(displayScrollbars);
139 protected override void Dispose(bool disposing) {
140 base.Dispose(disposing);
143 // LAMESPEC This used to be documented, but it's not in code
144 // and no longer listed in MSDN2
145 // [EditorBrowsable (EditorBrowsableState.Advanced)]
146 // protected override void OnControlRemoved(ControlEventArgs e) {
147 private void OnControlRemoved(object sender, ControlEventArgs e) {
148 if (e.Control == this.unvalidated_control) {
149 this.unvalidated_control = null;
152 if (e.Control == this.active_control) {
153 this.unvalidated_control = null;
156 // base.OnControlRemoved(e);
159 protected override void OnCreateControl() {
160 base.OnCreateControl();
161 // MS seems to call this here, it gets the whole databinding process started
162 OnBindingContextChanged (EventArgs.Empty);
165 [EditorBrowsable (EditorBrowsableState.Advanced)]
166 protected override bool ProcessDialogChar(char charCode) {
168 if (ProcessMnemonic(charCode)) {
172 return base.ProcessDialogChar(charCode);
175 protected override bool ProcessDialogKey(Keys keyData) {
179 key = keyData & Keys.KeyCode;
184 if (ProcessTabKey((Control.ModifierKeys & Keys.Shift) == 0)) {
204 if (SelectNextControl(active_control, forward, false, false, true)) {
212 return base.ProcessDialogKey(keyData);
215 protected override bool ProcessMnemonic(char charCode) {
223 c = GetNextControl(c, true);
225 // This is stupid. I want to be able to call c.ProcessMnemonic directly
226 if (c.ProcessControlMnemonic(charCode)) {
236 } while (c != active_control);
241 protected virtual bool ProcessTabKey(bool forward) {
242 return SelectNextControl(active_control, forward, true, true, true);
245 protected override void Select(bool directed, bool forward) {
246 base.Select(directed, forward);
249 protected virtual void UpdateDefaultButton() {
253 [EditorBrowsable (EditorBrowsableState.Advanced)]
254 protected override void WndProc(ref Message m) {
257 #endregion // Protected Instance Methods