2 // System.Drawing.Design.ToolboxItem.cs
5 // Alejandro Sánchez Acosta
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Alejandro Sánchez Acosta
9 // (C) 2003 Andreas Nahr
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Collections;
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
39 using System.Reflection;
40 using System.Runtime.Serialization;
42 namespace System.Drawing.Design
45 public class ToolboxItem : ISerializable
48 private AssemblyName assembly;
49 private Bitmap bitmap;
50 private ICollection filter = new ToolboxItemFilterAttribute[0];
51 private string displayname = string.Empty;
52 private bool locked = false;
53 private string name = string.Empty;
55 public ToolboxItem() {
58 public ToolboxItem (Type toolType) {
59 Initialize (toolType);
62 public AssemblyName AssemblyName {
73 public Bitmap Bitmap {
84 public string DisplayName {
95 public ICollection Filter {
106 protected bool Locked {
112 public string TypeName {
123 protected void CheckUnlocked ()
125 throw new InvalidOperationException ("The ToolboxItem is locked");
128 public IComponent[] CreateComponents ()
130 return CreateComponents (null);
133 public IComponent[] CreateComponents (IDesignerHost host)
135 OnComponentsCreating (new ToolboxComponentsCreatingEventArgs (host));
136 IComponent[] Comp = CreateComponentsCore (host);
137 OnComponentsCreated ( new ToolboxComponentsCreatedEventArgs (Comp));
142 protected virtual IComponent[] CreateComponentsCore (IDesignerHost host)
144 throw new NotImplementedException ();
147 protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
149 assembly = (AssemblyName)info.GetValue ("AssemblyName", typeof (AssemblyName));
150 bitmap = (Bitmap)info.GetValue ("Bitmap", typeof (Bitmap));
151 filter = (ICollection)info.GetValue ("Filter", typeof (ICollection));
152 displayname = info.GetString ("DisplayName");
153 locked = info.GetBoolean ("Locked");
154 name = info.GetString ("TypeName");
157 public override bool Equals (object obj)
159 // FIXME: too harsh??
160 if (!(obj is ToolboxItem))
164 return ((ToolboxItem) obj).AssemblyName.Equals (assembly) &&
165 ((ToolboxItem) obj).Locked.Equals (locked) &&
166 ((ToolboxItem) obj).TypeName.Equals (name) &&
167 ((ToolboxItem) obj).DisplayName.Equals (displayname) &&
168 ((ToolboxItem) obj).Bitmap.Equals (bitmap);
171 public override int GetHashCode ()
173 // FIXME: other algorithm?
174 return string.Concat (name, displayname).GetHashCode ();
178 protected virtual Type GetType (IDesignerHost host, AssemblyName assemblyName, string typeName, bool reference)
180 throw new NotImplementedException ();
184 public virtual void Initialize (Type type)
186 // assembly = // FIXME we need to get the AssemblyName data from somewhere or create a new one
187 displayname = type.Name;
188 name = type.FullName;
189 // seems to be a right place to create the bitmap
190 bitmap = new Bitmap (16, 16); // FIXME set some default bitmap !?
192 filter = type.GetCustomAttributes (typeof (ToolboxItemFilterAttribute), true);
194 throw new NotImplementedException ();
197 void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
199 Serialize (info, context);
207 protected virtual void OnComponentsCreated (ToolboxComponentsCreatedEventArgs args)
209 if (ComponentsCreated != null)
210 this.ComponentsCreated (this, args);
213 protected virtual void OnComponentsCreating (ToolboxComponentsCreatingEventArgs args)
215 if (ComponentsCreated != null)
216 this.ComponentsCreating (this, args);
219 protected virtual void Serialize (SerializationInfo info, StreamingContext context)
221 info.AddValue ("AssemblyName", assembly);
222 info.AddValue ("Bitmap", bitmap);
223 info.AddValue ("Filter", filter);
224 info.AddValue ("DisplayName", displayname);
225 info.AddValue ("Locked", locked);
226 info.AddValue ("TypeName", name);
229 public override string ToString()
234 public event ToolboxComponentsCreatedEventHandler ComponentsCreated;
236 public event ToolboxComponentsCreatingEventHandler ComponentsCreating;