Move Mono.CompilerServices.SymbolWriter to build after 2.1 raw mscorlib
[mono.git] / mcs / class / System.Design / System.ComponentModel.Design / DesignModeNestedContainer.cs
1 //
2 // System.ComponentModel.Design.DesignModeSite
3 //
4 // Authors:      
5 //        Ivan N. Zlatev (contact i-nZ.net)
6 //
7 // (C) 2007 Ivan N. Zlatev
8
9 //
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 #if NET_2_0
30
31 using System;
32 using System.Collections;
33 using System.ComponentModel;
34 using System.ComponentModel.Design.Serialization;
35
36 namespace System.ComponentModel.Design
37 {
38
39         internal class DesignModeNestedContainer : NestedContainer
40         {
41
42                 // DesignModeNestedContainer is a NestedContainer where:
43                 //  * Site's Name property is a qualified name that includes the owning component's name 
44                 // followed by a period (.) and the child component's name.
45                 //  * GetService is routed through the owner
46
47                 private class Site : DesignModeSite, INestedSite
48                 {
49
50                         public Site (IComponent component, string name, IContainer container, IServiceProvider serviceProvider) :
51                                 base (component,  name,  container,  serviceProvider)
52                         {
53                         }
54
55                         // [owner].[container].[site]
56                         //
57                         public string FullName {
58                                 get {
59                                         if (this.Name == null)
60                                                 return null;
61
62                                         string ownerName = ((DesignModeNestedContainer)this.Container).OwnerName;
63                                         if (ownerName == null)
64                                                 return this.Name;
65
66                                         return ownerName + "." + this.Name;
67                                 }
68                         }
69                 }
70
71                 private string _containerName;
72
73                 public DesignModeNestedContainer (IComponent owner, string containerName) : base (owner)
74                 {
75                         _containerName = containerName;
76                 }
77
78                 public override void Add (IComponent component, string name)
79                 {
80                         if (this.Owner.Site != null) {
81                            DesignerHost host = this.Owner.Site.GetService (typeof (IDesignerHost)) as DesignerHost;
82                            if (host != null) {
83                                    host.AddPreProcess (component, name);
84                                    base.Add (component, name);
85                                    host.AddPostProcess (component, name);
86                            }
87                         }
88                 }
89
90                 public override void Remove (IComponent component)
91                 {
92                         if (this.Owner.Site != null) {
93                            DesignerHost host = this.Owner.Site.GetService (typeof (IDesignerHost)) as DesignerHost;
94                            if (host != null) {
95                                    host.RemovePreProcess (component);
96                                    base.Remove (component);
97                                    host.RemovePostProcess (component);
98                            }
99                         }
100                 }
101
102                 // [owner].[container]
103                 //
104                 protected override string OwnerName {
105                         get {
106                                 if (_containerName != null)
107                                         return base.OwnerName + "." + _containerName;
108                                 else
109                                         return base.OwnerName;
110                         }
111                 }
112
113                 protected override ISite CreateSite (IComponent component, string name)
114                 {
115                         if (component == null)
116                                 throw new ArgumentNullException("component");
117
118                         if (Owner.Site == null)
119                                 throw new InvalidOperationException ("Owner not sited.");
120
121                         return new DesignModeNestedContainer.Site (component, name, this, (IServiceProvider)Owner.Site);
122                 }
123                 
124                 protected override object GetService (Type service)
125                 {
126                         if (service == typeof (INestedContainer))
127                                 return this;
128
129                         object serviceInstance = null;
130
131                         if (this.Owner.Site != null)
132                                 serviceInstance = this.Owner.Site.GetService (service);
133
134                         if (serviceInstance == null)
135                                 return base.GetService (service);
136
137                         return null;
138                 }
139         }
140 }
141 #endif