2 // System.ComponentModel.Design.DesignModeSite
5 // Ivan N. Zlatev (contact i-nZ.net)
7 // (C) 2007 Ivan N. Zlatev
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
33 using System.ComponentModel;
34 using System.ComponentModel.Design.Serialization;
36 namespace System.ComponentModel.Design
39 internal class DesignModeNestedContainer : NestedContainer
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
47 private class Site : DesignModeSite, INestedSite
50 public Site (IComponent component, string name, IContainer container, IServiceProvider serviceProvider) :
51 base (component, name, container, serviceProvider)
55 // [owner].[container].[site]
57 public string FullName {
59 if (this.Name == null)
62 string ownerName = ((DesignModeNestedContainer)this.Container).OwnerName;
63 if (ownerName == null)
66 return ownerName + "." + this.Name;
71 private string _containerName;
73 public DesignModeNestedContainer (IComponent owner, string containerName) : base (owner)
75 _containerName = containerName;
78 public override void Add (IComponent component, string name)
80 if (this.Owner.Site != null) {
81 DesignerHost host = this.Owner.Site.GetService (typeof (IDesignerHost)) as DesignerHost;
83 host.AddPreProcess (component, name);
84 base.Add (component, name);
85 host.AddPostProcess (component, name);
90 public override void Remove (IComponent component)
92 if (this.Owner.Site != null) {
93 DesignerHost host = this.Owner.Site.GetService (typeof (IDesignerHost)) as DesignerHost;
95 host.RemovePreProcess (component);
96 base.Remove (component);
97 host.RemovePostProcess (component);
102 // [owner].[container]
104 protected override string OwnerName {
106 if (_containerName != null)
107 return base.OwnerName + "." + _containerName;
109 return base.OwnerName;
113 protected override ISite CreateSite (IComponent component, string name)
115 if (component == null)
116 throw new ArgumentNullException("component");
118 if (Owner.Site == null)
119 throw new InvalidOperationException ("Owner not sited.");
121 return new DesignModeNestedContainer.Site (component, name, this, (IServiceProvider)Owner.Site);
124 protected override object GetService (Type service)
126 if (service == typeof (INestedContainer))
129 object serviceInstance = null;
131 if (this.Owner.Site != null)
132 serviceInstance = this.Owner.Site.GetService (service);
134 if (serviceInstance == null)
135 return base.GetService (service);