ToolboxItem.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // System.Drawing.Design.ToolboxItem.cs
  3. //
  4. // Authors:
  5. // Alejandro Sánchez Acosta
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) Alejandro Sánchez Acosta
  9. // (C) 2003 Andreas Nahr
  10. //
  11. using System.Collections;
  12. using System.ComponentModel;
  13. using System.ComponentModel.Design;
  14. using System.Drawing;
  15. using System.Reflection;
  16. using System.Runtime.Serialization;
  17. namespace System.Drawing.Design
  18. {
  19. [Serializable]
  20. public class ToolboxItem : ISerializable
  21. {
  22. private AssemblyName assembly;
  23. private Bitmap bitmap;
  24. private ICollection filter = new ToolboxItemFilterAttribute[0];
  25. private string displayname = "";
  26. private bool locked = false;
  27. private string name = "";
  28. public ToolboxItem() {
  29. }
  30. public ToolboxItem (Type toolType) {
  31. Initialize (toolType);
  32. }
  33. public AssemblyName AssemblyName {
  34. get {
  35. return assembly;
  36. }
  37. set {
  38. CheckUnlocked ();
  39. assembly = value;
  40. }
  41. }
  42. public Bitmap Bitmap {
  43. get {
  44. return bitmap;
  45. }
  46. set {
  47. CheckUnlocked ();
  48. bitmap = value;
  49. }
  50. }
  51. public string DisplayName {
  52. get {
  53. return displayname;
  54. }
  55. set {
  56. CheckUnlocked ();
  57. displayname = value;
  58. }
  59. }
  60. public ICollection Filter {
  61. get {
  62. return filter;
  63. }
  64. set {
  65. CheckUnlocked ();
  66. filter = value;
  67. }
  68. }
  69. protected bool Locked {
  70. get {
  71. return locked;
  72. }
  73. }
  74. public string TypeName {
  75. get {
  76. return name;
  77. }
  78. set {
  79. CheckUnlocked ();
  80. name = value;
  81. }
  82. }
  83. protected void CheckUnlocked ()
  84. {
  85. throw new InvalidOperationException ("The ToolboxItem is locked");
  86. }
  87. public IComponent[] CreateComponents ()
  88. {
  89. return CreateComponents (null);
  90. }
  91. public IComponent[] CreateComponents (IDesignerHost host)
  92. {
  93. OnComponentsCreating (new ToolboxComponentsCreatingEventArgs (host));
  94. IComponent[] Comp = CreateComponentsCore (host);
  95. OnComponentsCreated ( new ToolboxComponentsCreatedEventArgs (Comp));
  96. return Comp;
  97. }
  98. [MonoTODO]
  99. protected virtual IComponent[] CreateComponentsCore (IDesignerHost host)
  100. {
  101. throw new NotImplementedException ();
  102. }
  103. [MonoTODO]
  104. protected virtual void Deserialize (SerializationInfo info, StreamingContext context)
  105. {
  106. throw new NotImplementedException ();
  107. }
  108. public override bool Equals (object obj)
  109. {
  110. // FIXME: too harsh??
  111. if (!(obj is ToolboxItem))
  112. return false;
  113. if (obj == this)
  114. return true;
  115. return ((ToolboxItem) obj).AssemblyName.Equals (assembly) &&
  116. ((ToolboxItem) obj).Locked.Equals (locked) &&
  117. ((ToolboxItem) obj).TypeName.Equals (name) &&
  118. ((ToolboxItem) obj).DisplayName.Equals (displayname) &&
  119. ((ToolboxItem) obj).Bitmap.Equals (bitmap);
  120. }
  121. public override int GetHashCode ()
  122. {
  123. // FIXME: other algorithm?
  124. return string.Concat (name, displayname).GetHashCode ();
  125. }
  126. [MonoTODO]
  127. protected virtual Type GetType (IDesignerHost host, AssemblyName assemblyName, string typeName, bool reference)
  128. {
  129. throw new NotImplementedException ();
  130. }
  131. [MonoTODO]
  132. public virtual void Initialize (Type type)
  133. {
  134. // assembly = // FIXME we need to get the AssemblyName data from somewhere or create a new one
  135. displayname = type.Name;
  136. name = type.FullName;
  137. // seems to be a right place to create the bitmap
  138. bitmap = new Bitmap (16, 16); // FIXME set some default bitmap !?
  139. filter = type.GetCustomAttributes (typeof (ToolboxItemFilterAttribute), true);
  140. throw new NotImplementedException ();
  141. }
  142. [MonoTODO]
  143. void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
  144. {
  145. throw new NotImplementedException ();
  146. }
  147. public void Lock ()
  148. {
  149. locked = true;
  150. }
  151. protected virtual void OnComponentsCreated (ToolboxComponentsCreatedEventArgs args)
  152. {
  153. this.ComponentsCreated (this, args);
  154. }
  155. protected virtual void OnComponentsCreating (ToolboxComponentsCreatingEventArgs args)
  156. {
  157. this.ComponentsCreating (this, args);
  158. }
  159. [MonoTODO]
  160. protected virtual void Serialize (SerializationInfo info, StreamingContext context)
  161. {
  162. throw new NotImplementedException ();
  163. }
  164. public override string ToString()
  165. {
  166. return displayname;
  167. }
  168. public event ToolboxComponentsCreatedEventHandler ComponentsCreated;
  169. public event ToolboxComponentsCreatingEventHandler ComponentsCreating;
  170. }
  171. }