2002-08-23 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System / System.ComponentModel / Component.cs
1 //
2 // System.ComponentModel.Component.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System;
11
12 namespace System.ComponentModel {
13
14         // <summary>
15         //   Component class.
16         // </summary>
17         //
18         // <remarks>
19         //   Longer description
20         // </remarks>
21         public class Component : MarshalByRefObject, IComponent, IDisposable {
22
23                 EventHandlerList event_handlers;
24                 ISite            mySite;
25
26                 // <summary>
27                 //   Component Constructor
28                 // </summary>
29                 public Component ()
30                 {
31                         event_handlers = null;
32                 }
33
34                 // <summary>
35                 //   Get IContainer of this Component
36                 // </summary>
37                 public IContainer Container {
38                         get {
39                                 return mySite.Container;
40                         }
41                 }
42
43                 protected bool DesignMode {
44                         get {
45                                 return mySite.DesignMode;
46                         }
47                 }
48
49                 protected EventHandlerList Events {
50                         get {
51                                 // Note: space vs. time tradeoff
52                                 // We create the object here if it's never be accessed before.  This potentially 
53                                 // saves space. However, we must check each time the propery is accessed to
54                                 // determine whether we need to create the object, which increases overhead.
55                                 // We could put the creation in the contructor, but that would waste space
56                                 // if it were never used.  However, accessing this property would be faster.
57                                 if (null == event_handlers)\r
58                                 {
59                                         event_handlers = new EventHandlerList();
60                                 }
61                                 return event_handlers;
62                         }
63                 }
64
65                 public virtual ISite Site {
66                         get {
67                                 return mySite;
68                         }
69
70                         set {
71                                 mySite = value;
72                         }
73                 }
74
75                 [MonoTODO]
76                 ~Component()
77                 {
78                         // FIXME: Not sure this is correct.
79                         Dispose(true);
80                 }
81
82                 // <summary>
83                 //   Dispose resources used by this component
84                 // </summary>
85                 [MonoTODO]
86                 public void Dispose ()
87                 {
88                         // FIXME: Not sure this is correct.
89                         Dispose(false);
90                         if (Disposed != null)
91                                 Disposed(this, EventArgs.Empty);
92                 }
93
94                 // <summary>
95                 //   Controls disposal of resources used by this.
96                 // </summary>
97                 //
98                 // <param name="release_all"> Controls which resources are released</param>
99                 //
100                 // <remarks>
101                 //   if release_all is set to true, both managed and unmanaged
102                 //   resources should be released.  If release_all is set to false,
103                 //   only unmanaged resources should be disposed
104                 // </remarks>
105                 protected virtual void Dispose (bool release_all)
106                 {
107                 }
108
109                 // <summary>
110                 //   Implements the IServiceProvider interface
111                 // </summary>
112                 [MonoTODO]
113                 protected virtual object GetService (Type service)
114                 {
115                         // FIXME: Not sure what this should do.
116                         return null;
117                 }
118
119                 public override string ToString ()
120                 {
121                         if (mySite == null)
122                                 return GetType ().ToString ();
123                         return String.Format ("{0} [{1}]", mySite.Name, GetType ().ToString ());
124                 }
125                 // <summary>
126                 //   FIXME: Figure out this one.
127                 // </summary>
128                 [MonoTODO ("Figure this out")]
129                 public event EventHandler Disposed;
130         }
131         
132 }