RegisteredObjects.DesignExt.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using FastReport.Cloud.StorageClient;
  5. using FastReport.Messaging;
  6. using FastReport.Wizards;
  7. namespace FastReport.Utils
  8. {
  9. partial class ObjectInfo
  10. {
  11. #region Private Fields
  12. private int imageIndex;
  13. private int buttonIndex;
  14. private int flags;
  15. private bool multiInsert;
  16. #endregion Private Fields
  17. #region Public Properties
  18. /// <summary>
  19. /// Image index.
  20. /// </summary>
  21. public int ImageIndex
  22. {
  23. get { return imageIndex; }
  24. set { imageIndex = value; }
  25. }
  26. /// <summary>
  27. /// Button index.
  28. /// </summary>
  29. public int ButtonIndex
  30. {
  31. get { return buttonIndex; }
  32. set { buttonIndex = value; }
  33. }
  34. /// <summary>
  35. /// Flags that will be used to create an object instance in the designer.
  36. /// </summary>
  37. public int Flags
  38. {
  39. get { return flags; }
  40. set { flags = value; }
  41. }
  42. /// <summary>
  43. /// Indicates whether this object can be inserted several times simultaneously.
  44. /// </summary>
  45. /// <remarks>
  46. /// This is applied to Line object only.
  47. /// </remarks>
  48. public bool MultiInsert
  49. {
  50. get { return multiInsert; }
  51. set { multiInsert = value; }
  52. }
  53. #endregion Public Properties
  54. #region Private Methods
  55. private void UpdateDesign(Bitmap image, int imageIndex, int buttonIndex = -1)
  56. {
  57. ButtonIndex = buttonIndex;
  58. ImageIndex = imageIndex;
  59. if (image != null)
  60. ImageIndex = Res.AddImage(image);
  61. }
  62. private void UpdateDesign(int flags, bool multiInsert, Bitmap image, int imageIndex, int buttonIndex = -1)
  63. {
  64. UpdateDesign(image, imageIndex, buttonIndex);
  65. Flags = flags;
  66. MultiInsert = multiInsert;
  67. }
  68. #endregion Private Methods
  69. }
  70. enum ItemWizardEnum : int
  71. {
  72. /// <summary>
  73. ///
  74. /// </summary>
  75. Report = 0,
  76. /// <summary>
  77. ///
  78. /// </summary>
  79. ReportItem = 1,
  80. /// <summary>
  81. ///
  82. /// </summary>
  83. Game = 2
  84. }
  85. partial class RegisteredObjects
  86. {
  87. #region Public Methods
  88. /// <summary>
  89. /// Registers a new cloud storage client.
  90. /// </summary>
  91. /// <param name="obj">Type of cloud storage client.</param>
  92. /// <param name="text">Text for cloud storage client's menu item.</param>
  93. /// <remarks>
  94. /// The <b>obj</b> must be of <see cref="CloudStorageClient"/> type.
  95. /// </remarks>
  96. /// <example>
  97. /// <code>
  98. /// // register own cloud storage client
  99. /// RegisteredObjects.AddCloud(typeof(MyCloud), "My Cloud");
  100. /// </code>
  101. /// </example>
  102. public static void AddCloud(Type obj, string text)
  103. {
  104. if (!obj.IsSubclassOf(typeof(Cloud.StorageClient.CloudStorageClient)))
  105. {
  106. throw new Exception("The 'obj' parameter must be of CloudStorageClient type.");
  107. }
  108. InternalAdd(obj, "", null, -1, text);
  109. }
  110. /// <summary>
  111. /// Registers a new messenger.
  112. /// </summary>
  113. /// <param name="obj">Type of messenger.</param>
  114. /// <param name="text">Text messenger's menu item.</param>
  115. /// <remarks>
  116. /// The <b>obj</b> must be of <see cref="MessengerBase"/> type.
  117. /// </remarks>
  118. /// <example>
  119. /// <code>
  120. /// // register own messenger
  121. /// RegisteredObjects.AddMessenger(typeof(MyMessenger), "My Messenger");
  122. /// </code>
  123. /// </example>
  124. public static void AddMessenger(Type obj, string text)
  125. {
  126. if (!obj.IsSubclassOf(typeof(Messaging.MessengerBase)))
  127. {
  128. throw new Exception("The 'obj' parameter must be of MessengerBase type.");
  129. }
  130. InternalAddMessenger(obj, text);
  131. }
  132. internal static ObjectInfo InternalAddMessenger(Type obj, string text)
  133. {
  134. return InternalAdd(obj, "", null, -1, text);
  135. }
  136. /// <summary>
  137. /// Registers a new wizard.
  138. /// </summary>
  139. /// <param name="obj">Type of wizard.</param>
  140. /// <param name="image">Image for wizard item.</param>
  141. /// <param name="text">Text for wizard item.</param>
  142. /// <param name="isReportItemWizard"><b>true</b> if this wizard creates some items in existing report.</param>
  143. /// <remarks>
  144. /// The <b>obj</b> must be of <see cref="WizardBase"/> type.
  145. /// </remarks>
  146. /// <example>This example shows how to register own wizard that is used to create some items in the
  147. /// current report. If you want to register a wizard that will be used to create a new report,
  148. /// set the <b>isReportItemWizard</b> to <b>false</b>.
  149. /// <code>
  150. /// // register own wizard
  151. /// RegisteredObjects.AddWizard(typeof(MyWizard), myWizBmp, "My Wizard", true);
  152. /// </code>
  153. /// </example>
  154. public static void AddWizard(Type obj, Bitmap image, string text, bool isReportItemWizard)
  155. {
  156. if (!obj.IsSubclassOf(typeof(WizardBase)))
  157. throw new Exception("The 'obj' parameter must be of WizardBase type.");
  158. InternalAdd(obj, "", image, -1, text, isReportItemWizard ? 1 : 0, false);
  159. }
  160. #endregion Public Methods
  161. #region Internal Methods
  162. internal static ObjectInfo AddCloud(Type obj, string text, int imageIndex)
  163. {
  164. if (!obj.IsSubclassOf(typeof(Cloud.StorageClient.CloudStorageClient)))
  165. {
  166. throw new Exception("The 'obj' parameter must be of CloudStorageClient type.");
  167. }
  168. return InternalAdd(obj, "", null, imageIndex, text);
  169. }
  170. internal static void AddMessenger(Type obj, string text, int imageIndex)
  171. {
  172. if (!obj.IsSubclassOf(typeof(Messaging.MessengerBase)))
  173. {
  174. throw new Exception("The 'obj' parameter must be of MessengerBase type.");
  175. }
  176. InternalAdd(obj, "", null, imageIndex, text);
  177. }
  178. internal static void AddWizard(Type obj, int imageIndex, string text, ItemWizardEnum itemWizardEnum)
  179. {
  180. InternalAdd(obj, "", null, imageIndex, text, (int)itemWizardEnum, false);
  181. }
  182. internal static FunctionInfo FindFunctionsRoot()
  183. {
  184. List<FunctionInfo> list = new List<FunctionInfo>();
  185. Functions.EnumItems(list);
  186. foreach (FunctionInfo item in list)
  187. {
  188. if (item.Name == "Functions")
  189. return item;
  190. }
  191. return null;
  192. }
  193. #endregion Internal Methods
  194. }
  195. }