* ImageList.cs: When the image stream is set pull all the images
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ContainerControl.cs
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:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
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.
19 //
20 // Copyright (c) 2004 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24 //
25 //
26
27
28 // NOT COMPLETE
29
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
32
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;
38
39                 #region Public Constructors
40                 public ContainerControl() {
41                         active_control = null;
42                         focused_control = null;
43                         unvalidated_control = null;
44                 }
45                 #endregion      // Public Constructors
46
47                 #region Public Instance Properties
48                 [Browsable (false)]
49                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
50                 public Control ActiveControl {
51                         get {
52                                 return active_control;
53                         }
54
55                         set {
56                                 if ((active_control==value) || (value==null)) {
57                                         return;
58                                 }
59
60                                 active_control = value;
61
62                                 if (!Contains(value) && this != value) {
63                                         throw new ArgumentException("Not a child control");
64                                 }
65
66                                 // Scroll control into view
67
68                                 // Let the control know it's selected
69                                 Select(value);
70                         }
71                 }
72
73                 [Browsable (false)]
74                 public override BindingContext BindingContext {
75                         get {
76                                 if (base.BindingContext == null) {
77                                         base.BindingContext = new BindingContext();
78                                 }
79                                 return base.BindingContext;
80                         }
81
82                         set {
83                                 base.BindingContext = value;
84                         }
85                 }
86
87                 [Browsable (false)]
88                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
89                 public Form ParentForm {
90                         get {
91                                 Control parent;
92
93                                 parent = this.parent;
94
95                                 while (parent != null) {
96                                         if (parent is Form) {
97                                                 return (Form)parent;
98                                         }
99                                         parent = parent.parent;
100                                 }
101
102                                 return null;
103                         }
104                 }
105                 #endregion      // Public Instance Properties
106
107                 #region Protected Instance Methods
108                 protected override CreateParams CreateParams {
109                         get {
110                                 return base.CreateParams;
111                         }
112                 }
113                 #endregion      // Public Instance Methods
114
115                 #region Public Instance Methods
116                 [MonoTODO]
117                 public bool Validate() {
118                         throw new NotImplementedException();
119                 }
120
121                 bool IContainerControl.ActivateControl(Control control) {
122                         return Select(control);
123                 }
124                 #endregion      // Public Instance Methods
125
126                 #region Protected Instance Methods
127                 [EditorBrowsable (EditorBrowsableState.Advanced)]
128                 protected override void AdjustFormScrollbars(bool displayScrollbars) {
129                         // Internal MS
130                 }
131
132                 protected override void Dispose(bool disposing) {
133                         base.Dispose(disposing);
134                 }
135
136                 [EditorBrowsable (EditorBrowsableState.Advanced)]
137                 protected override void OnControlRemoved(ControlEventArgs e) {
138                         if (e.Control == this.unvalidated_control) {
139                                 this.unvalidated_control = null;
140                         }
141
142                         if (e.Control == this.active_control) {
143                                 this.unvalidated_control = null;
144                         }
145
146                         base.OnControlRemoved(e);
147                 }
148
149                 protected override void OnCreateControl() {
150                         base.OnCreateControl();
151                         // MS seems to call this here, it gets the whole databinding process started
152                         OnBindingContextChanged (EventArgs.Empty);
153                 }
154
155                 [EditorBrowsable (EditorBrowsableState.Advanced)]
156                 protected override bool ProcessDialogChar(char charCode) {
157                         if (GetTopLevel()) {
158                                 if (ProcessMnemonic(charCode)) {
159                                         return true;
160                                 }
161                         }
162                         return base.ProcessDialogChar(charCode);
163                 }
164
165                 protected override bool ProcessDialogKey(Keys keyData) {
166                         Keys    key;
167                         bool    forward;
168
169                         key = keyData & Keys.KeyCode;
170                         forward = true;
171
172                         switch (key) {
173                                 case Keys.Tab: {
174                                         if (ProcessTabKey((Control.ModifierKeys & Keys.Shift) == 0)) {
175                                                 return true;
176                                         }
177                                         break;
178                                 }
179
180                                 case Keys.Left: {
181                                         forward = false;
182                                         goto case Keys.Down;
183                                 }
184
185                                 case Keys.Up: {
186                                         forward = false;
187                                         goto case Keys.Down;
188                                 }
189
190                                 case Keys.Right: {
191                                         goto case Keys.Down;
192                                 }
193                                 case Keys.Down: {
194                                         if (SelectNextControl(active_control, forward, false, false, true)) {
195                                                 return true;
196                                         }
197                                         break;
198                                 } 
199
200
201                         }
202                         return base.ProcessDialogKey(keyData);
203                 }
204
205                 protected override bool ProcessMnemonic(char charCode) {
206                         bool    wrapped;
207                         Control c;
208
209                         wrapped = false;
210                         c = active_control;
211
212                         do {
213                                 c = GetNextControl(c, true);
214                                 if (c != null) {
215                                         // This is stupid. I want to be able to call c.ProcessMnemonic directly
216                                         if (c.ProcessControlMnemonic(charCode)) {
217                                                 return(true);
218                                         }
219                                         continue;
220                                 } else {
221                                         if (wrapped) {
222                                                 break;
223                                         }
224                                         wrapped = true;
225                                 }
226                         } while (c != active_control);
227                         
228                         return false;
229                 }
230
231                 protected virtual bool ProcessTabKey(bool forward) {
232                         return SelectNextControl(active_control, forward, true, true, true);
233                 }
234
235                 protected override void Select(bool directed, bool forward) {
236                         base.Select(directed, forward);
237                 }
238
239                 protected virtual void UpdateDefaultButton() {
240                         // MS Internal
241                 }
242
243                 [EditorBrowsable (EditorBrowsableState.Advanced)]
244                 protected override void WndProc(ref Message m) {
245                         base.WndProc(ref m);
246                 }
247                 #endregion      // Protected Instance Methods
248         }
249 }