~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to samples/ComponentInspector/ComponentInspector.Core/Src/ObjectBrowser/GuiDesigner/DesignerSite.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// <file>
 
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>
 
6
// </file>
 
7
 
 
8
using System;
 
9
using System.Collections;
 
10
using System.ComponentModel;
 
11
using System.ComponentModel.Design;
 
12
using System.Windows.Forms;
 
13
using System.Windows.Forms.Design;
 
14
 
 
15
using NoGoop.ObjBrowser.TreeNodes;
 
16
 
 
17
namespace NoGoop.ObjBrowser.GuiDesigner
 
18
{
 
19
        public class DesignerSite : ISite, IDictionaryService, ITypeDescriptorFilterService, 
 
20
                IInheritanceService, IComponentChangeService
 
21
        {
 
22
                DesignerHost                    _host;
 
23
 
 
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;
 
31
 
 
32
                protected IWindowTarget         _origWindowTarget;
 
33
                protected IWindowTarget         _designWindowTarget;
 
34
 
 
35
                protected static int            _serialNumber;
 
36
 
 
37
                protected static string         _ehServiceTypeName = 
 
38
                        "System.Windows.Forms.Design.IEventHandlerService";
 
39
 
 
40
                public IContainer Container {
 
41
                        get {
 
42
                                return _container;
 
43
                        }
 
44
                }
 
45
 
 
46
                public IComponent Component {
 
47
                        get {
 
48
                                return _component;
 
49
                        }
 
50
                }
 
51
 
 
52
                public bool DesignMode {
 
53
                        get {
 
54
                                return _host.DesignMode;
 
55
                        }
 
56
                }
 
57
 
 
58
                public IWindowTarget DesignWindowTarget {
 
59
                        get {
 
60
                                        return _designWindowTarget;
 
61
                        }
 
62
                        set {
 
63
                                _designWindowTarget = value;
 
64
                        }
 
65
                }
 
66
 
 
67
                public IWindowTarget OrigWindowTarget {
 
68
                        get {
 
69
                                return _origWindowTarget;
 
70
                        }
 
71
                }
 
72
 
 
73
                public string Name {
 
74
                        get {
 
75
                                return _name;
 
76
                        }
 
77
                        set {
 
78
                                _name = value;
 
79
                        }
 
80
                }
 
81
 
 
82
                public IDesigner Designer {
 
83
                        get {
 
84
                                return _designer;
 
85
                        }
 
86
                        set {
 
87
                                _designer = value;
 
88
                        }
 
89
                }
 
90
 
 
91
                internal ObjectTreeNode TargetNode {
 
92
                        get {
 
93
                                return _targetNode;
 
94
                        }
 
95
                        set {
 
96
                                _targetNode = value;
 
97
                        }
 
98
                }
 
99
 
 
100
                public DesignerSite(DesignerHost host, IComponent comp, IContainer con, string name)
 
101
                {
 
102
                        _host = host;
 
103
                        _component = comp;
 
104
                        _container = con;
 
105
                        _name = name;
 
106
                        _serviceContainer = new ServiceContainer();
 
107
                        _dictHash = new Hashtable();
 
108
                        if (comp is Control)
 
109
                                _origWindowTarget = ((Control)comp).WindowTarget;
 
110
 
 
111
                        if (ComponentAdded != null)
 
112
                                ComponentAdded(this, new ComponentEventArgs(comp));
 
113
                        if (ComponentAdding != null)
 
114
                                ComponentAdding(this, new ComponentEventArgs(comp));
 
115
                }
 
116
 
 
117
                // Try to get a site-specific service, and if that does not
 
118
                // work, ask the host
 
119
                public Object GetService(Type type)
 
120
                {
 
121
                        Object service = GetServiceFromSite(type);
 
122
                        if (service == null)
 
123
                                service = _host.GetService(type);
 
124
                        if (service != null && service is IComponent)
 
125
                                ((IComponent)service).Site = this;
 
126
                        return service;
 
127
                }
 
128
 
 
129
                // Get the service from the site
 
130
                internal Object GetServiceFromSite(Type type)
 
131
                {
 
132
                        Object service = _serviceContainer.GetService(type);
 
133
                        if (service != null)
 
134
                                return service;
 
135
 
 
136
                        // These are the site local services
 
137
                        if (type.Equals(typeof(IInheritanceService))) {
 
138
                                AddService(typeof(IInheritanceService), new InheritanceService());
 
139
                                return GetService(type);
 
140
                        }
 
141
                        if (type.Equals(typeof(AmbientProperties))) {
 
142
                                AddService(typeof(AmbientProperties), new AmbientProperties());
 
143
                                return GetService(type);
 
144
                        }
 
145
                        if (type.Equals(typeof(IDictionaryService))) {
 
146
                                AddService(typeof(IDictionaryService), this);
 
147
                                return GetService(type);
 
148
                        }
 
149
                        if (type.Equals(typeof(IComponentChangeService))) {
 
150
                                AddService(typeof(IComponentChangeService),this);
 
151
                                return GetService(type);
 
152
                        }
 
153
                        if (type.Equals(typeof(ITypeDescriptorFilterService))) {
 
154
                                AddService(typeof(ITypeDescriptorFilterService), this);
 
155
                                return GetService(type);
 
156
                        }
 
157
                        if (type.Equals(typeof(IInheritanceService))) {
 
158
                                AddService(typeof(IInheritanceService),this);
 
159
                                return GetService(type);
 
160
                        }
 
161
                        if (type.FullName.Equals(_ehServiceTypeName)) {
 
162
                                Object ehService = new EventHandlerService((Control)_component);
 
163
                                AddService(type, ehService);
 
164
                                return GetService(type);
 
165
                        }
 
166
                        return service;
 
167
                }
 
168
 
 
169
                protected void AddService(Type type, Object service)
 
170
                {
 
171
                        _serviceContainer.AddService(type, service);
 
172
                }
 
173
 
 
174
                public void SetValue(Object key, Object value)
 
175
                {
 
176
                        Object foundVal = _dictHash[key];
 
177
                        if (foundVal == null)
 
178
                                _dictHash.Add(key, value);
 
179
                        else
 
180
                                _dictHash[key] = value;
 
181
                }
 
182
 
 
183
                public Object GetValue(Object key)
 
184
                {
 
185
                        return _dictHash[key];
 
186
                }
 
187
 
 
188
                public Object GetKey(Object value)
 
189
                {
 
190
                         foreach (Object key in _dictHash.Keys) {
 
191
                                if (_dictHash[key].Equals(value))
 
192
                                        return key;
 
193
                         }
 
194
                         return null;
 
195
                }
 
196
 
 
197
 
 
198
                public void OnComponentChanged(Object comp, MemberDescriptor member, Object oldValue, Object newValue)
 
199
                {
 
200
                        if (ComponentChanged != null) {
 
201
                                ComponentChanged(this, new ComponentChangedEventArgs(comp, member, oldValue, newValue));
 
202
                        }
 
203
                }
 
204
 
 
205
                public void OnComponentChanging(Object comp, MemberDescriptor member)
 
206
                {
 
207
                        if (ComponentChanging != null) {
 
208
                                ComponentChanging(this, new ComponentChangingEventArgs(comp, member));
 
209
                        }
 
210
                }
 
211
 
 
212
                public void OnComponentRemoving(Object comp)
 
213
                {
 
214
                        if (ComponentRemoving != null) {
 
215
                                ComponentRemoving(this, new ComponentEventArgs((IComponent)comp));
 
216
                        }
 
217
                }
 
218
 
 
219
                public void OnComponentRemoved(Object comp)
 
220
                {
 
221
                        if (ComponentRemoved != null) {
 
222
                                ComponentRemoved(this, new ComponentEventArgs((IComponent)comp));
 
223
                        }
 
224
                }
 
225
 
 
226
                protected void OnComponentRename(Object comp, string oldName, string newName)
 
227
                {
 
228
                        if (ComponentRename != null) {
 
229
                                ComponentRename(this, new ComponentRenameEventArgs(comp, oldName, newName));
 
230
                        }
 
231
                }
 
232
 
 
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;
 
240
 
 
241
                public bool FilterAttributes(IComponent comp, IDictionary attr)
 
242
                {
 
243
                        return true;
 
244
                }
 
245
 
 
246
                public bool FilterEvents(IComponent comp, IDictionary attr)
 
247
                {
 
248
                        return true;
 
249
                }
 
250
 
 
251
                public bool FilterProperties(IComponent comp, IDictionary attr)
 
252
                {
 
253
                        return true;
 
254
                }
 
255
 
 
256
                public void AddInheritedComponents(IComponent comp, IContainer con)
 
257
                {
 
258
                }
 
259
 
 
260
                public InheritanceAttribute GetInheritanceAttribute(IComponent comp)
 
261
                {
 
262
                        return InheritanceAttribute.NotInherited;
 
263
                }
 
264
        }
 
265
}