2
// <copyright see="prj:///doc/copyright.txt"/>
3
// <license see="prj:///doc/license.txt"/>
4
// <owner name="Oakland Software Incorporated" email="general@oaklandsoftware.com"/>
5
// <version>$Revision$</version>
9
using System.Collections;
10
using System.ComponentModel;
11
using System.ComponentModel.Design;
12
using System.Windows.Forms;
13
using System.Windows.Forms.Design;
15
using NoGoop.ObjBrowser.TreeNodes;
17
namespace NoGoop.ObjBrowser.GuiDesigner
19
public class DesignerSite : ISite, IDictionaryService, ITypeDescriptorFilterService,
20
IInheritanceService, IComponentChangeService
24
protected IContainer _container;
25
protected IComponent _component;
26
protected String _name;
27
protected ServiceContainer _serviceContainer;
28
protected Hashtable _dictHash;
29
protected IDesigner _designer;
30
internal ObjectTreeNode _targetNode;
32
protected IWindowTarget _origWindowTarget;
33
protected IWindowTarget _designWindowTarget;
35
protected static int _serialNumber;
37
protected static string _ehServiceTypeName =
38
"System.Windows.Forms.Design.IEventHandlerService";
40
public IContainer Container {
46
public IComponent Component {
52
public bool DesignMode {
54
return _host.DesignMode;
58
public IWindowTarget DesignWindowTarget {
60
return _designWindowTarget;
63
_designWindowTarget = value;
67
public IWindowTarget OrigWindowTarget {
69
return _origWindowTarget;
82
public IDesigner Designer {
91
internal ObjectTreeNode TargetNode {
100
public DesignerSite(DesignerHost host, IComponent comp, IContainer con, string name)
106
_serviceContainer = new ServiceContainer();
107
_dictHash = new Hashtable();
109
_origWindowTarget = ((Control)comp).WindowTarget;
111
if (ComponentAdded != null)
112
ComponentAdded(this, new ComponentEventArgs(comp));
113
if (ComponentAdding != null)
114
ComponentAdding(this, new ComponentEventArgs(comp));
117
// Try to get a site-specific service, and if that does not
118
// work, ask the host
119
public Object GetService(Type type)
121
Object service = GetServiceFromSite(type);
123
service = _host.GetService(type);
124
if (service != null && service is IComponent)
125
((IComponent)service).Site = this;
129
// Get the service from the site
130
internal Object GetServiceFromSite(Type type)
132
Object service = _serviceContainer.GetService(type);
136
// These are the site local services
137
if (type.Equals(typeof(IInheritanceService))) {
138
AddService(typeof(IInheritanceService), new InheritanceService());
139
return GetService(type);
141
if (type.Equals(typeof(AmbientProperties))) {
142
AddService(typeof(AmbientProperties), new AmbientProperties());
143
return GetService(type);
145
if (type.Equals(typeof(IDictionaryService))) {
146
AddService(typeof(IDictionaryService), this);
147
return GetService(type);
149
if (type.Equals(typeof(IComponentChangeService))) {
150
AddService(typeof(IComponentChangeService),this);
151
return GetService(type);
153
if (type.Equals(typeof(ITypeDescriptorFilterService))) {
154
AddService(typeof(ITypeDescriptorFilterService), this);
155
return GetService(type);
157
if (type.Equals(typeof(IInheritanceService))) {
158
AddService(typeof(IInheritanceService),this);
159
return GetService(type);
161
if (type.FullName.Equals(_ehServiceTypeName)) {
162
Object ehService = new EventHandlerService((Control)_component);
163
AddService(type, ehService);
164
return GetService(type);
169
protected void AddService(Type type, Object service)
171
_serviceContainer.AddService(type, service);
174
public void SetValue(Object key, Object value)
176
Object foundVal = _dictHash[key];
177
if (foundVal == null)
178
_dictHash.Add(key, value);
180
_dictHash[key] = value;
183
public Object GetValue(Object key)
185
return _dictHash[key];
188
public Object GetKey(Object value)
190
foreach (Object key in _dictHash.Keys) {
191
if (_dictHash[key].Equals(value))
198
public void OnComponentChanged(Object comp, MemberDescriptor member, Object oldValue, Object newValue)
200
if (ComponentChanged != null) {
201
ComponentChanged(this, new ComponentChangedEventArgs(comp, member, oldValue, newValue));
205
public void OnComponentChanging(Object comp, MemberDescriptor member)
207
if (ComponentChanging != null) {
208
ComponentChanging(this, new ComponentChangingEventArgs(comp, member));
212
public void OnComponentRemoving(Object comp)
214
if (ComponentRemoving != null) {
215
ComponentRemoving(this, new ComponentEventArgs((IComponent)comp));
219
public void OnComponentRemoved(Object comp)
221
if (ComponentRemoved != null) {
222
ComponentRemoved(this, new ComponentEventArgs((IComponent)comp));
226
protected void OnComponentRename(Object comp, string oldName, string newName)
228
if (ComponentRename != null) {
229
ComponentRename(this, new ComponentRenameEventArgs(comp, oldName, newName));
233
public event ComponentEventHandler ComponentAdded;
234
public event ComponentEventHandler ComponentAdding;
235
public event ComponentChangedEventHandler ComponentChanged;
236
public event ComponentChangingEventHandler ComponentChanging;
237
public event ComponentEventHandler ComponentRemoved;
238
public event ComponentEventHandler ComponentRemoving;
239
public event ComponentRenameEventHandler ComponentRename;
241
public bool FilterAttributes(IComponent comp, IDictionary attr)
246
public bool FilterEvents(IComponent comp, IDictionary attr)
251
public bool FilterProperties(IComponent comp, IDictionary attr)
256
public void AddInheritedComponents(IComponent comp, IContainer con)
260
public InheritanceAttribute GetInheritanceAttribute(IComponent comp)
262
return InheritanceAttribute.NotInherited;