PreviewSettings.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. using System;
  2. using System.Drawing;
  3. using System.ComponentModel;
  4. using FastReport.Utils;
  5. using FastReport.Preview;
  6. using System.Drawing.Design;
  7. namespace FastReport
  8. {
  9. /// <summary>
  10. /// Specifies the set of buttons available in the preview.
  11. /// </summary>
  12. [Flags]
  13. [EditorAttribute("FastReport.TypeEditors.FlagsEditor, FastReport", typeof(UITypeEditor))]
  14. public enum PreviewButtons
  15. {
  16. /// <summary>
  17. /// No buttons visible.
  18. /// </summary>
  19. None = 0,
  20. /// <summary>
  21. /// The "Print" button is visible.
  22. /// </summary>
  23. Print = 1,
  24. /// <summary>
  25. /// The "Open" button is visible.
  26. /// </summary>
  27. Open = 2,
  28. /// <summary>
  29. /// The "Save" button is visible.
  30. /// </summary>
  31. Save = 4,
  32. /// <summary>
  33. /// The "Email" button is visible.
  34. /// </summary>
  35. Email = 8,
  36. /// <summary>
  37. /// The "Find" button is visible.
  38. /// </summary>
  39. Find = 16,
  40. /// <summary>
  41. /// The zoom buttons are visible.
  42. /// </summary>
  43. Zoom = 32,
  44. /// <summary>
  45. /// The "Outline" button is visible.
  46. /// </summary>
  47. Outline = 64,
  48. /// <summary>
  49. /// The "Page setup" button is visible.
  50. /// </summary>
  51. PageSetup = 128,
  52. /// <summary>
  53. /// The "Edit" button is visible.
  54. /// </summary>
  55. Edit = 256,
  56. /// <summary>
  57. /// The "Watermark" button is visible.
  58. /// </summary>
  59. Watermark = 512,
  60. /// <summary>
  61. /// The page navigator buttons are visible.
  62. /// </summary>
  63. Navigator = 1024,
  64. /// <summary>
  65. /// The "Close" button is visible.
  66. /// </summary>
  67. Close = 2048,
  68. /// <summary>
  69. /// The "Design" button is visible.
  70. /// </summary>
  71. Design = 4096,
  72. /// <summary>
  73. /// The "Copy Page" button is visible.
  74. /// </summary>
  75. CopyPage = 8192,
  76. /// <summary>
  77. /// The "Delete Page" button is visible.
  78. /// </summary>
  79. DeletePage = 16384,
  80. /// <summary>
  81. /// The "About" button is visible.
  82. /// </summary>
  83. About = 32768,
  84. /// <summary>
  85. /// All buttons are visible.
  86. /// </summary>
  87. // if you add something to this enum, don't forget to correct "All" member
  88. All = Print | Open | Save | Email | Find | Zoom | Outline | PageSetup | Edit |
  89. Watermark | Navigator | Close | CopyPage | DeletePage | About
  90. }
  91. /// <summary>
  92. /// Specifies the set of export buttons available in the preview.
  93. /// </summary>
  94. [Flags]
  95. [EditorAttribute("FastReport.TypeEditors.FlagsEditor, FastReport", typeof(UITypeEditor))]
  96. public enum PreviewExports
  97. {
  98. /// <summary>
  99. /// No exports visible.
  100. /// </summary>
  101. None = 0,
  102. /// <summary>
  103. /// The "Prepared" button is visible.
  104. /// </summary>
  105. Prepared = 1,
  106. /// <summary>
  107. /// The "PDFExport" button is visible.
  108. /// </summary>
  109. PDFExport = 2,
  110. /// <summary>
  111. /// The "RTFExport" button is visible.
  112. /// </summary>
  113. RTFExport = 4,
  114. /// <summary>
  115. /// The "HTMLExport" button is visible.
  116. /// </summary>
  117. HTMLExport = 8,
  118. /// <summary>
  119. /// The "MHTExport" button is visible.
  120. /// </summary>
  121. MHTExport = 16,
  122. /// <summary>
  123. /// The "XMLExport" export button is visible.
  124. /// </summary>
  125. XMLExport = 32,
  126. /// <summary>
  127. /// The "Excel2007Export" button is visible.
  128. /// </summary>
  129. Excel2007Export = 64,
  130. /// <summary>
  131. /// The "Excel2003Document" button is visible.
  132. /// </summary>
  133. Excel2003Document = 128,
  134. /// <summary>
  135. /// The "Word2007Export" button is visible.
  136. /// </summary>
  137. Word2007Export = 256,
  138. /// <summary>
  139. /// The "PowerPoint2007Export" button is visible.
  140. /// </summary>
  141. PowerPoint2007Export = 512,
  142. /// <summary>
  143. /// The "ODSExport" button is visible.
  144. /// </summary>
  145. ODSExport = 1024,
  146. /// <summary>
  147. /// The "ODTExport" button is visible.
  148. /// </summary>
  149. ODTExport = 2048,
  150. /// <summary>
  151. /// The "XPSExport" export button is visible.
  152. /// </summary>
  153. XPSExport = 4096,
  154. /// <summary>
  155. /// The "CSVExport" button is visible.
  156. /// </summary>
  157. CSVExport = 8192,
  158. /// <summary>
  159. /// The "DBFExport" button is visible.
  160. /// </summary>
  161. DBFExport = 16384,
  162. /// <summary>
  163. /// The "TextExport" button is visible.
  164. /// </summary>
  165. TextExport = 32768,
  166. /// <summary>
  167. /// The "ZplExport" button is visible.
  168. /// </summary>
  169. ZplExport = 65536,
  170. /// <summary>
  171. /// The "ImageExport" button is visible.
  172. /// </summary>
  173. ImageExport = 131072,
  174. /// <summary>
  175. /// The "XAMLExport" button is visible.
  176. /// </summary>
  177. XAMLExport = 262144,
  178. /// <summary>
  179. /// The "SVGExport" button is visible.
  180. /// </summary>
  181. SVGExport = 524288,
  182. /// <summary>
  183. /// The "PPMLExport" button is visible.
  184. /// </summary>
  185. PPMLExport = 1048576,
  186. /// <summary>
  187. /// The "PSExport" button is visible.
  188. /// </summary>
  189. PSExport = 2097152,
  190. /// <summary>
  191. /// The "JsonExport" button is visible.
  192. /// </summary>
  193. JsonExport = 4194304,
  194. /// <summary>
  195. /// The "LaTeXExport" button is visible.
  196. /// </summary>
  197. LaTeXExport = 8388608,
  198. /// <summary>
  199. /// The "HpglExport" button is visible.
  200. /// </summary>
  201. HpglExport = 16777216,
  202. /// <summary>
  203. /// The "DxfExport" button is visible.
  204. /// </summary>
  205. DxfExport = 33554432,
  206. /// <summary>
  207. /// The All export buttons is visible.
  208. /// </summary>
  209. All = Prepared | PDFExport | RTFExport | HTMLExport | MHTExport | XMLExport | Excel2007Export | Excel2003Document |
  210. Word2007Export | PowerPoint2007Export | ODSExport | ODTExport | XPSExport | CSVExport | DBFExport | TextExport |
  211. ZplExport | ImageExport | XAMLExport | SVGExport | PPMLExport | PSExport | JsonExport | LaTeXExport | DxfExport
  212. }
  213. /// <summary>
  214. /// Specifies the set of cloud exports available in the preview.
  215. /// </summary>
  216. [Flags]
  217. [EditorAttribute("FastReport.TypeEditors.FlagsEditor, FastReport", typeof(UITypeEditor))]
  218. public enum PreviewClouds
  219. {
  220. /// <summary>
  221. /// No items visible.
  222. /// </summary>
  223. None = 0,
  224. /// <summary>
  225. /// The "Box" button is visible.
  226. /// </summary>
  227. Box = 1,
  228. /// <summary>
  229. /// The "Dropbox" button is visible.
  230. /// </summary>
  231. Dropbox = 2,
  232. /// <summary>
  233. /// The "Ftp" button is visible.
  234. /// </summary>
  235. Ftp = 4,
  236. /// <summary>
  237. /// The "GoogleDrive" button is visible.
  238. /// </summary>
  239. GoogleDrive = 8,
  240. /// <summary>
  241. /// The "SkyDrive" button is visible.
  242. /// </summary>
  243. SkyDrive = 16,
  244. /// <summary>
  245. /// The "S3" button is visible.
  246. /// </summary>
  247. S3 = 32,
  248. /// <summary>
  249. /// The All export in clouds buttons is visible.
  250. /// </summary>
  251. All = Box | Dropbox | Ftp | GoogleDrive | SkyDrive | S3
  252. }
  253. /// <summary>
  254. /// Specifies the set of export by messenger buttons available in the preview.
  255. /// </summary>
  256. [Flags]
  257. [EditorAttribute("FastReport.TypeEditors.FlagsEditor, FastReport", typeof(UITypeEditor))]
  258. public enum PreviewMessengers
  259. {
  260. /// <summary>
  261. /// No exports by messengers visible.
  262. /// </summary>
  263. None = 0,
  264. /// <summary>
  265. /// The "Xmpp" button is visible.
  266. /// </summary>
  267. Xmpp = 1,
  268. /// <summary>
  269. /// The All export by messengers buttons is visible.
  270. /// </summary>
  271. All = Xmpp
  272. }
  273. /// <summary>
  274. /// Contains some settings of the preview window.
  275. /// </summary>
  276. [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
  277. public class PreviewSettings
  278. {
  279. #region Fields
  280. private PreviewButtons buttons;
  281. private int pagesInCache;
  282. private bool showInTaskbar;
  283. private bool topMost;
  284. private Icon icon;
  285. private string text;
  286. private bool fastScrolling;
  287. private bool allowPrintToFile;
  288. private string saveInitialDirectory;
  289. #endregion
  290. #region Properties
  291. /// <summary>
  292. /// Occurs when the standard preview window opened.
  293. /// </summary>
  294. /// <remarks>
  295. /// You may use this event to change the standard preview window, for example, add an own button to it.
  296. /// The <b>sender</b> parameter in this event is the <b>PreviewControl</b>.
  297. /// </remarks>
  298. public event EventHandler PreviewOpened;
  299. /// <summary>
  300. /// Gets or sets a set of buttons that will be visible in the preview's toolbar.
  301. /// </summary>
  302. /// <example>
  303. /// Here is an example how you can disable the "Print" and "EMail" buttons:
  304. /// <code>
  305. /// Config.PreviewSettings.Buttons = PreviewButtons.Open |
  306. /// PreviewButtons.Save |
  307. /// PreviewButtons.Find |
  308. /// PreviewButtons.Zoom |
  309. /// PreviewButtons.Outline |
  310. /// PreviewButtons.PageSetup |
  311. /// PreviewButtons.Edit |
  312. /// PreviewButtons.Watermark |
  313. /// PreviewButtons.Navigator |
  314. /// PreviewButtons.Close;
  315. /// </code>
  316. /// </example>
  317. [DefaultValue(PreviewButtons.All)]
  318. public PreviewButtons Buttons
  319. {
  320. get { return buttons; }
  321. set { buttons = value; }
  322. }
  323. #if !COMMUNITY
  324. /// <summary>
  325. /// Specifies the set of exports that will be available in the preview's "save" menu.
  326. /// </summary>
  327. [DefaultValue(PreviewExports.All)]
  328. public PreviewExports Exports
  329. {
  330. get => ExportsOptions.GetInstance().Exports;
  331. set => ExportsOptions.GetInstance().Exports = value;
  332. }
  333. /// <summary>
  334. /// Specifies the set of exports in clouds that will be available in the preview's "save" menu.
  335. /// </summary>
  336. [DefaultValue(PreviewClouds.All)]
  337. public PreviewClouds Clouds
  338. {
  339. get => ExportsOptions.GetInstance().Clouds;
  340. set => ExportsOptions.GetInstance().Clouds = value;
  341. }
  342. /// <summary>
  343. /// Specifies the set of exports by messengers that will be available in the preview's "save" menu.
  344. /// </summary>
  345. //[DefaultValue(PreviewMessengers.All)]
  346. [DefaultValue(PreviewMessengers.None)]
  347. [Browsable(false)]
  348. public PreviewMessengers Messengers
  349. {
  350. get => ExportsOptions.GetInstance().Messengers;
  351. set => ExportsOptions.GetInstance().Messengers = value;
  352. }
  353. #endif
  354. /// <summary>
  355. /// Gets or sets the number of prepared pages that can be stored in the memory cache during preview.
  356. /// </summary>
  357. /// <remarks>
  358. /// Decrease this value if your prepared report contains a lot of pictures. This will
  359. /// save the RAM memory.
  360. /// </remarks>
  361. [DefaultValue(50)]
  362. public int PagesInCache
  363. {
  364. get { return pagesInCache; }
  365. set { pagesInCache = value; }
  366. }
  367. /// <summary>
  368. /// Gets or sets a value indicating whether the preview window is displayed in the Windows taskbar.
  369. /// </summary>
  370. [DefaultValue(false)]
  371. public bool ShowInTaskbar
  372. {
  373. get { return showInTaskbar; }
  374. set { showInTaskbar = value; }
  375. }
  376. /// <summary>
  377. /// Gets or sets a value indicating whether the preview window should be displayed as a topmost form.
  378. /// </summary>
  379. [DefaultValue(false)]
  380. public bool TopMost
  381. {
  382. get { return topMost; }
  383. set { topMost = value; }
  384. }
  385. /// <summary>
  386. /// Gets or sets the icon for the preview window.
  387. /// </summary>
  388. public Icon Icon
  389. {
  390. get
  391. {
  392. if (icon == null)
  393. icon = ResourceLoader.GetIcon("icon16.ico");
  394. return icon;
  395. }
  396. set { icon = value; }
  397. }
  398. /// <summary>
  399. /// Gets or sets the text for the preview window.
  400. /// </summary>
  401. /// <remarks>
  402. /// If no text is set, the default text "Preview" will be used.
  403. /// </remarks>
  404. public string Text
  405. {
  406. get { return text; }
  407. set { text = value; }
  408. }
  409. /// <summary>
  410. /// Gets or sets a value indicating whether the fast scrolling method should be used.
  411. /// </summary>
  412. /// <remarks>
  413. /// If you enable this property, the gradient background will be disabled.
  414. /// </remarks>
  415. [DefaultValue(false)]
  416. public bool FastScrolling
  417. {
  418. get { return fastScrolling; }
  419. set { fastScrolling = value; }
  420. }
  421. /// <summary>
  422. /// Enables or disables the "Print to file" feature in the print dialog.
  423. /// </summary>
  424. [DefaultValue(true)]
  425. public bool AllowPrintToFile
  426. {
  427. get { return allowPrintToFile; }
  428. set { allowPrintToFile = value; }
  429. }
  430. /// <summary>
  431. /// Gets or sets the initial directory that is displayed by a save file dialog.
  432. /// </summary>
  433. public string SaveInitialDirectory
  434. {
  435. get { return saveInitialDirectory; }
  436. set { saveInitialDirectory = value; }
  437. }
  438. #endregion
  439. internal void OnPreviewOpened(PreviewControl sender)
  440. {
  441. if (PreviewOpened != null)
  442. PreviewOpened(sender, EventArgs.Empty);
  443. }
  444. /// <summary>
  445. /// Initializes a new instance of the <b>PreviewSettings</b> class with default settings.
  446. /// </summary>
  447. public PreviewSettings()
  448. {
  449. buttons = PreviewButtons.All;
  450. pagesInCache = 50;
  451. text = "";
  452. allowPrintToFile = true;
  453. }
  454. }
  455. }