2001-08-21 Nick Drochak <ndrochak@gol.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                 }
32
33                 // <summary>
34                 //   Get IContainer of this Component
35                 // </summary>
36                 public IContainer Container {
37                         get {
38                                 return mySite.Container;
39                         }
40                 }
41
42                 protected bool DesignMode {
43                         get {
44                                 return mySite.DesignMode;
45                         }
46                 }
47
48                 protected EventHandlerList Events {
49                         get {
50                                 // Note: space vs. time tradeoff
51                                 // We create the object here if it's never be accessed before.  This potentially 
52                                 // saves space. However, we must check each time the propery is accessed to
53                                 // determine whether we need to create the object, which increases overhead.
54                                 // We could put the creation in the contructor, but that would waste space
55                                 // if it were never used.  However, accessing this property would be faster.
56                                 if (null == event_handlers)\r
57                                 {
58                                         event_handlers = new EventHandlerList();
59                                 }
60                                 return event_handlers;
61                         }
62                 }
63
64                 public virtual ISite Site {
65                         get {
66                                 return mySite;
67                         }
68
69                         set {
70                                 mySite = value;
71                         }
72                 }
73
74                 ~Component() \r
75                 {
76                         // FIXME: Not sure this is correct.
77                         Dispose(true);
78                         Disposed(this, EventArgs.Empty);
79                 }
80
81                 // <summary>
82                 //   Dispose resources used by this component
83                 // </summary>
84                 public virtual void Dispose ()
85                 {
86                         // FIXME: Not sure this is correct.
87                         Dispose(false);
88                         Disposed(this, EventArgs.Empty);
89                 }
90
91                 // <summary>
92                 //   Controls disposal of resources used by this.
93                 // </summary>
94                 //
95                 // <param name="release_all"> Controls which resources are released</param>
96                 //
97                 // <remarks>
98                 //   if release_all is set to true, both managed and unmanaged
99                 //   resources should be released.  If release_all is set to false,
100                 //   only unmanaged resources should be disposed
101                 // </remarks>
102                 protected virtual void Dispose (bool release_all)
103                 {
104                 }
105
106                 // <summary>
107                 //   Implements the IServiceProvider interface
108                 // </summary>
109                 protected virtual object GetService (Type service)
110                 {
111                         // FIXME: Not sure what this should do.
112                         return null;
113                 }
114
115                 // <summary>
116                 //   FIXME: Figure out this one.
117                 // </summary>
118                 public event EventHandler Disposed;
119         }
120         
121 }