2002-08-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System / System.ComponentModel / Container.cs
1 //
2 // System.ComponentModel.Container.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 namespace System.ComponentModel {
11
12         // <summary>
13         //   Container class: encapsulates components.  
14         // </summary>
15         //
16         // <remarks>
17         //   
18         // </remarks>
19         public class Container : IContainer, IDisposable {
20                 ComponentCollection cc;
21
22                 // <summary>
23                 //   Auxiliary class to support the default behaviour of CreateSite
24                 // </summary>
25                 //
26                 // <remarks>
27                 //   This is an internal class that is used to provide a
28                 //   default implementation of an ISite class.  Container
29                 //   is just a default implementation of IContainer, and
30                 //   provides this as a way of getting started
31                 // </remarks>
32                 
33                 class DefaultSite : ISite {
34                         IComponent component;
35                         IContainer container;
36                         string     name;
37                         
38                         public DefaultSite (string name, IComponent component, IContainer container)
39                         {
40                                 this.component = component;
41                                 this.container = container;
42                                 this.name = name;
43                         }
44
45                         public IComponent Component {
46                                 get {
47                                         return component;
48                                 }
49                         }
50
51                         public IContainer Container {
52                                 get {
53                                         return container;
54                                 }
55                         }
56
57                         [MonoTODO]
58                         public bool DesignMode {
59                                 get {
60                                         // FIXME: should we provide a way to set
61                                         // this value?
62                                         return false;
63                                 }
64                         }
65
66                         public string Name {
67                                 get {
68                                         return name;
69                                 }
70
71                                 set {
72                                         name = value;
73                                 }
74                         }
75
76                         [MonoTODO]
77                         public virtual object GetService (Type t)
78                         {
79                                 // FIXME: do not know what this is supposed to do.
80                                 return null;
81                         }
82                 }
83                 
84                 // <summary>
85                 //   Container constructor
86                 // </summary>
87                 public Container ()
88                 {
89                 }
90
91                 public virtual ComponentCollection Components {
92                         get {
93                                 return cc;
94                         }
95                 }
96
97                 // <summary>
98                 //   Adds an IComponent to the Container
99                 // </summary>
100                 [MonoTODO]
101                 public virtual void Add (IComponent component)
102                 {
103                         // FIXME: Add this component to the ComponentCollection.cc
104                 }
105
106                 // <summary>
107                 //   Adds an IComponent to the Container.  With a name binding.
108                 // </summary>
109                 [MonoTODO]
110                 public virtual void Add (IComponent component, string name)
111                 {
112                         // FIXME: Add this component to the ComponentCollection.cc
113                 }
114
115                 // <summary>
116                 //   Returns an ISite for a component.
117                 // <summary>
118                 protected virtual ISite CreateSite (IComponent component, string name)
119                 {
120                         return new DefaultSite (name, component, this);
121                 }
122
123                 public void Dispose ()
124                 {
125                         Dispose (true);
126                         GC.SuppressFinalize (this);
127                 }
128
129                 bool disposed = false;
130                 
131                 protected virtual void Dispose (bool release_all)
132                 {
133                         if (disposed)
134                                 return;
135                         disposed = true;
136
137                         if (release_all){
138                                 //??
139                         }
140
141                         cc = null;
142                 }
143
144                 ~Container ()
145                 {
146                         Dispose (false);
147                 }
148
149                 [MonoTODO]
150                 protected virtual object GetService (Type service)
151                 {
152                         // FIXME: Not clear what GetService does.
153                         
154                         return null;
155                 }
156
157                 [MonoTODO]
158                 public virtual void Remove (IComponent component)
159                 {
160                         // FIXME: Add this component to the ComponentCollection.cc
161                 }
162         }
163         
164 }