(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System / System.ComponentModel / Container.cs
blob757052f00291a5c7a58cc36f96ca20563da84e74
1 //
2 // System.ComponentModel.Container.cs
3 //
4 // Author:
5 // Miguel de Icaza (miguel@ximian.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Ximian, Inc. http://www.ximian.com
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
35 namespace System.ComponentModel {
37 // <summary>
38 // Container class: encapsulates components.
39 // </summary>
41 // <remarks>
42 //
43 // </remarks>
44 public class Container : IContainer, IDisposable {
46 private ArrayList c = new ArrayList ();
47 //ComponentCollection cc;
49 // <summary>
50 // Auxiliary class to support the default behaviour of CreateSite
51 // </summary>
53 // <remarks>
54 // This is an internal class that is used to provide a
55 // default implementation of an ISite class. Container
56 // is just a default implementation of IContainer, and
57 // provides this as a way of getting started
58 // </remarks>
60 class DefaultSite : ISite {
61 private IComponent component;
62 private Container container;
63 private string name;
65 public DefaultSite (string name, IComponent component, Container container)
67 this.component = component;
68 this.container = container;
69 this.name = name;
72 public IComponent Component {
73 get {
74 return component;
78 public IContainer Container {
79 get {
80 return container;
84 [MonoTODO]
85 public bool DesignMode {
86 get {
87 // FIXME: should we provide a way to set
88 // this value?
89 return false;
93 public string Name {
94 get {
95 return name;
98 set {
99 name = value;
103 public virtual object GetService (Type t)
105 if (typeof(ISite) != t) {
106 return null;
108 return container.GetService (t);
112 // <summary>
113 // Container constructor
114 // </summary>
115 public Container ()
119 public virtual ComponentCollection Components {
120 get {
121 Array a = c.ToArray(typeof (IComponent));
122 return new ComponentCollection((IComponent[]) a);
126 public virtual void Add (IComponent component)
128 Add (component, null);
131 public virtual void Add (IComponent component, string name)
133 component.Site = CreateSite (component, name);
134 c.Add (component);
137 protected virtual ISite CreateSite (IComponent component, string name)
139 if (name != null) {
140 foreach (IComponent Comp in c) {
141 if (Comp.Site != null && Comp.Site.Name == name)
142 throw new ArgumentException ("duplicate component name", "name");
146 return new DefaultSite (name, component, this);
149 public void Dispose ()
151 Dispose (true);
152 GC.SuppressFinalize (this);
155 bool disposed = false;
157 protected virtual void Dispose (bool release_all)
159 if (disposed)
160 return;
161 disposed = true;
163 if (release_all){
164 foreach (IComponent component in c)
165 component.Dispose ();
168 c = null;
171 ~Container ()
173 Dispose (false);
176 protected virtual object GetService (Type service)
178 if (typeof(IContainer) != service) {
179 return null;
181 return this;
184 public virtual void Remove (IComponent component)
186 c.Remove (component);