PreviewControl.Mono.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. using FastReport.Cloud.StorageClient;
  2. using FastReport.Cloud.StorageClient.Dropbox;
  3. using FastReport.Cloud.StorageClient.FastCloud;
  4. using FastReport.Cloud.StorageClient.Ftp;
  5. using FastReport.Cloud.StorageClient.S3;
  6. using FastReport.Controls;
  7. using FastReport.Design;
  8. using FastReport.Export;
  9. using FastReport.Messaging;
  10. using FastReport.Utils;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Drawing;
  15. using System.Drawing.Design;
  16. using System.IO;
  17. using System.Windows.Forms;
  18. #if !AVALONIA
  19. using FastReport.Cloud.StorageClient.Box;
  20. using FastReport.Cloud.StorageClient.GoogleDrive;
  21. using FastReport.Cloud.StorageClient.SkyDrive;
  22. using Box = FastReport.Cloud.StorageClient.Box;
  23. using GoogleDrive = FastReport.Cloud.StorageClient.GoogleDrive;
  24. using SkyDrive = FastReport.Cloud.StorageClient.SkyDrive;
  25. #endif
  26. #if !DEBUG
  27. using FastReport.Forms;
  28. #endif
  29. namespace FastReport.Preview
  30. {
  31. /// <summary>
  32. /// Represents a Windows Forms control used to preview a report.
  33. /// </summary>
  34. /// <remarks>
  35. /// To use this control, place it on a form and link it to a report using the report's
  36. /// <see cref="FastReport.Report.Preview"/> property. To show a report, call
  37. /// the <b>Report.Show</b> method:
  38. /// <code>
  39. /// report1.Preview = previewControl1;
  40. /// report1.Show();
  41. /// </code>
  42. /// <para>Use this control's methods such as <see cref="Print"/>, <see cref="Save()"/> etc. to
  43. /// handle the preview. Call <see cref="Clear"/> method to clear the preview.</para>
  44. /// <para>You can specify whether the standard toolbar is visible in the <see cref="ToolbarVisible"/>
  45. /// property. The <see cref="StatusbarVisible"/> property allows you to hide/show the statusbar.
  46. /// </para>
  47. /// </remarks>
  48. [ToolboxItem(true), ToolboxBitmap(typeof(Report), "Resources.PreviewControl.bmp")]
  49. public partial class PreviewControl : UserControl
  50. {
  51. #region Fields
  52. private Report report;
  53. private List<PreviewTab> documents;
  54. private bool toolbarVisible;
  55. private bool statusbarVisible;
  56. private Color pageBorderColor;
  57. private Color activePageBorderColor;
  58. private PreviewButtons buttons;
  59. private PreviewExports exports;
  60. private PreviewClouds clouds;
  61. private float defaultZoom;
  62. private bool locked;
  63. private PreviewTab currentPreview;
  64. private bool fastScrolling;
  65. private Timer uploadTimer;
  66. private UIStyle uiStyle;
  67. private bool useBackColor;
  68. private FRTabControl tabControl;
  69. private Point pageOffset;
  70. private string saveInitialDirectory;
  71. private ToolStripZoomControl zoomControl;
  72. private bool updatingZoom;
  73. #endregion
  74. #region Properties
  75. /// <summary>
  76. /// Occurs when current page number is changed.
  77. /// </summary>
  78. public event EventHandler PageChanged;
  79. /// <summary>
  80. /// Occurs when UIStyle property is changed.
  81. /// </summary>
  82. public event EventHandler UIStyleChanged;
  83. /// <summary>
  84. /// Gets a reference to the report.
  85. /// </summary>
  86. [Browsable(false)]
  87. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  88. public Report Report
  89. {
  90. get { return report; }
  91. }
  92. /// <summary>
  93. /// Obsolete. Gets or sets the color of page border.
  94. /// </summary>
  95. [Browsable(false)]
  96. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  97. [EditorBrowsable(EditorBrowsableState.Never)]
  98. public Color PageBorderColor
  99. {
  100. get { return pageBorderColor; }
  101. set { pageBorderColor = value; }
  102. }
  103. /// <summary>
  104. /// Gets or sets the color of active page border.
  105. /// </summary>
  106. [DefaultValue(typeof(Color), "255, 199, 60")]
  107. public Color ActivePageBorderColor
  108. {
  109. get { return activePageBorderColor; }
  110. set { activePageBorderColor = value; }
  111. }
  112. /// <summary>
  113. /// Gets or sets the first page offset from the top left corner of the control.
  114. /// </summary>
  115. public Point PageOffset
  116. {
  117. get { return pageOffset; }
  118. set { pageOffset = value; }
  119. }
  120. /// <summary>
  121. /// Gets or sets a value indicating whether the toolbar is visible.
  122. /// </summary>
  123. [DefaultValue(true)]
  124. public bool ToolbarVisible
  125. {
  126. get { return toolbarVisible; }
  127. set
  128. {
  129. toolbarVisible = value;
  130. toolStrip.Visible = value;
  131. }
  132. }
  133. /// <summary>
  134. /// Gets or sets a value indicating whether the statusbar is visible.
  135. /// </summary>
  136. [DefaultValue(true)]
  137. public bool StatusbarVisible
  138. {
  139. get { return statusbarVisible; }
  140. set
  141. {
  142. statusbarVisible = value;
  143. statusStrip.Visible = value;
  144. }
  145. }
  146. /// <summary>
  147. /// Gets or sets a value indicating whether the outline control is visible.
  148. /// </summary>
  149. [DefaultValue(false)]
  150. public bool OutlineVisible
  151. {
  152. get { return outlineControl.Visible; }
  153. set
  154. {
  155. splitContainer1.Panel1Collapsed = !value;
  156. outlineControl.Visible = value;
  157. btnOutline.Checked = value;
  158. }
  159. }
  160. /// <summary>
  161. /// Specifies the set of buttons available in the toolbar.
  162. /// </summary>
  163. [DefaultValue(PreviewButtons.All)]
  164. public PreviewButtons Buttons
  165. {
  166. get { return buttons; }
  167. set
  168. {
  169. buttons = value;
  170. UpdateButtons();
  171. }
  172. }
  173. /// <summary>
  174. /// Specifies the set of exports that will be available in the preview's "save" menu.
  175. /// </summary>
  176. [DefaultValue(PreviewExports.All)]
  177. public PreviewExports Exports
  178. {
  179. get { return exports; }
  180. set
  181. {
  182. exports = value;
  183. UpdateButtons();
  184. }
  185. }
  186. /// <summary>
  187. /// Specifies the set of exports in clouds that will be available in the preview's "save" menu.
  188. /// </summary>
  189. [DefaultValue(PreviewClouds.All)]
  190. public PreviewClouds Clouds
  191. {
  192. get { return clouds; }
  193. set
  194. {
  195. clouds = value;
  196. UpdateButtons();
  197. }
  198. }
  199. /// <summary>
  200. /// Gets or sets a value indicating whether the fast scrolling method should be used.
  201. /// </summary>
  202. /// <remarks>
  203. /// If you enable this property, the gradient background will be disabled.
  204. /// </remarks>
  205. [DefaultValue(false)]
  206. public bool FastScrolling
  207. {
  208. get { return fastScrolling; }
  209. set { fastScrolling = value; }
  210. }
  211. /// <summary>
  212. /// Gets or sets the visual style.
  213. /// </summary>
  214. public UIStyle UIStyle
  215. {
  216. get { return uiStyle; }
  217. set
  218. {
  219. uiStyle = value;
  220. UpdateUIStyle();
  221. UIStyleChanged?.Invoke(this, EventArgs.Empty);
  222. }
  223. }
  224. /// <summary>
  225. /// Gets or sets a value indicating that the BackColor property must be used to draw the background area.
  226. /// </summary>
  227. /// <remarks>
  228. /// By default, the background area is drawn using the color defined in the current <b>UIStyle</b>.
  229. /// </remarks>
  230. [DefaultValue(false)]
  231. public bool UseBackColor
  232. {
  233. get { return useBackColor; }
  234. set
  235. {
  236. useBackColor = value;
  237. UpdateUIStyle();
  238. }
  239. }
  240. /// <summary>
  241. /// Gets the preview window's toolbar.
  242. /// </summary>
  243. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  244. public ToolStrip ToolBar
  245. {
  246. get { return toolStrip; }
  247. }
  248. /// <summary>
  249. /// Gets the preview window's statusbar.
  250. /// </summary>
  251. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  252. public StatusStrip StatusBar
  253. {
  254. get { return statusStrip; }
  255. }
  256. /// <summary>
  257. /// Gets or sets the initial directory that is displayed by a save file dialog.
  258. /// </summary>
  259. public string SaveInitialDirectory
  260. {
  261. get { return saveInitialDirectory; }
  262. set { saveInitialDirectory = value; }
  263. }
  264. internal float DefaultZoom
  265. {
  266. get { return defaultZoom; }
  267. }
  268. internal PreviewTab CurrentPreview
  269. {
  270. get { return currentPreview; }
  271. }
  272. private bool IsPreviewEmpty
  273. {
  274. get { return CurrentPreview == null || CurrentPreview.Disabled; }
  275. }
  276. #endregion
  277. #region Private Methods
  278. private void CreateOpenList()
  279. {
  280. var openLocal = new ToolStripMenuItem(Res.Get("Preview,OpenLocal"));
  281. openLocal.Image = this.GetImage(1);
  282. openLocal.Font = DrawUtils.DefaultFont;
  283. openLocal.Click += btnOpenLocal_Click;
  284. var openViaCloud = new ToolStripMenuItem(Res.Get("Preview,OpenViaCloud"));
  285. openViaCloud.Image = this.GetImage(261);
  286. openViaCloud.Font = DrawUtils.DefaultFont;
  287. openViaCloud.Click += btnOpenViaCloud_Click;
  288. btnOpen.DropDownItems.Clear();
  289. btnOpen.DropDownItems.AddRange(new ToolStripItem[] { openLocal, openViaCloud });
  290. }
  291. private void CreateSaveList()
  292. {
  293. var saveLocal = new ToolStripMenuItem(Res.Get("Preview,SaveLocal"));
  294. saveLocal.Font = DrawUtils.DefaultFont;
  295. saveLocal.Click += btnSaveLocal_Click;
  296. var saveToCloud = new ToolStripMenuItem(Res.Get("Preview,SaveToCloud"));
  297. saveToCloud.Image = this.GetImage(262);
  298. saveToCloud.Font = DrawUtils.DefaultFont;
  299. saveToCloud.Click += btnSaveToCloud_Click;
  300. var savePrepared = new ToolStripMenuItem(Res.Get("Preview,SaveNative"));
  301. savePrepared.Font = DrawUtils.DefaultFont;
  302. savePrepared.DropDownItems.AddRange(new ToolStripItem[] { saveLocal, saveToCloud });
  303. btnSave.DropDownItems.Clear();
  304. btnSave.DropDownItems.Add(savePrepared);
  305. CreateExportList(btnSave, Export_Click);
  306. CreateCloudList(btnSave, SaveToCloud_Click);
  307. //CreateMessengersList(btnSave, SendViaMessenger_Click);
  308. }
  309. private void CreateItems(ExportsOptions.ExportsTreeNode root, ToolStripDropDownItem button, EventHandler handler)
  310. {
  311. foreach (var node in root.Nodes)
  312. {
  313. if (node.IsCategory)
  314. {
  315. var categoryItem = createButtonItem(node);
  316. CreateItems(node, categoryItem, handler);
  317. if (categoryItem.DropDownItems.Count > 0)
  318. button.DropDownItems.Add(categoryItem);
  319. }
  320. else if (node.ExportType != null)
  321. {
  322. bool enabled = node.Enabled;
  323. if (node.IsExport)
  324. {
  325. if (Enum.TryParse<PreviewExports>(node.Tag.Object.Name, out var res))
  326. enabled = (Exports & res) != 0;
  327. }
  328. else if (node.IsCloud)
  329. {
  330. if (Enum.TryParse<PreviewClouds>(node.Name, out var res))
  331. enabled = (Clouds & res) != 0;
  332. }
  333. /*else if (node.IsMessenger)
  334. {
  335. if (Enum.TryParse<PreviewMessengers>(node.Name, out var res))
  336. enabled = (Messengers & res) != 0;
  337. }*/
  338. if (enabled)
  339. {
  340. var item = createButtonItem(node);
  341. item.Click += handler;
  342. button.DropDownItems.Add(item);
  343. }
  344. }
  345. }
  346. }
  347. private ToolStripMenuItem createButtonItem(ExportsOptions.ExportsTreeNode node)
  348. {
  349. var item = new ToolStripMenuItem(node.ToString() + (node.IsCategory ? "" : "..."));
  350. item.Tag = node.Tag;
  351. item.Name = node.Name;
  352. item.Image = node.Image ?? this.GetImage(node.ImageIndex);
  353. item.Font = DrawUtils.DefaultFont;
  354. return item;
  355. }
  356. private void CreateExportList(ToolStripDropDownItem button, EventHandler handler)
  357. {
  358. var options = ExportsOptions.GetInstance();
  359. CreateItems(options.ExportsMenu, button, handler);
  360. }
  361. private void CreateCloudList(ToolStripDropDownItem button, EventHandler handler)
  362. {
  363. var options = ExportsOptions.GetInstance();
  364. var categoryItem = createButtonItem(options.CloudMenu);
  365. CreateItems(options.CloudMenu, categoryItem, handler);
  366. if (categoryItem.DropDownItems.Count > 0)
  367. {
  368. button.DropDownItems.Add(new ToolStripSeparator());
  369. button.DropDownItems.Add(categoryItem);
  370. }
  371. }
  372. private void CreateMessengersList(ToolStripDropDownItem button, EventHandler handler)
  373. {
  374. var options = ExportsOptions.GetInstance();
  375. var categoryItem = createButtonItem(options.MessengerMenu);
  376. CreateItems(options.MessengerMenu, categoryItem, handler);
  377. if (categoryItem.DropDownItems.Count > 0)
  378. {
  379. button.DropDownItems.Add(new ToolStripSeparator());
  380. button.DropDownItems.Add(categoryItem);
  381. }
  382. }
  383. private void UpdateButtons()
  384. {
  385. btnPrint.Available = (Buttons & PreviewButtons.Print) != 0;
  386. btnOpen.Available = (Buttons & PreviewButtons.Open) != 0;
  387. btnSave.Available = (Buttons & PreviewButtons.Save) != 0;
  388. btnDesign.Available = (Buttons & PreviewButtons.Design) != 0;
  389. btnEmail.Available = (Buttons & PreviewButtons.Email) != 0 && !Config.EmailSettings.UseMAPI;
  390. btnFind.Available = (Buttons & PreviewButtons.Find) != 0;
  391. btnOutline.Available = (Buttons & PreviewButtons.Outline) != 0;
  392. btnPageSetup.Available = (Buttons & PreviewButtons.PageSetup) != 0;
  393. btnEdit.Available = (Buttons & PreviewButtons.Edit) != 0;
  394. btnWatermark.Available = (Buttons & PreviewButtons.Watermark) != 0;
  395. btnFirst.Available = (Buttons & PreviewButtons.Navigator) != 0;
  396. btnPrior.Available = (Buttons & PreviewButtons.Navigator) != 0;
  397. tbPageNo.Available = (Buttons & PreviewButtons.Navigator) != 0;
  398. lblTotalPages.Available = (Buttons & PreviewButtons.Navigator) != 0;
  399. btnNext.Available = (Buttons & PreviewButtons.Navigator) != 0;
  400. btnLast.Available = (Buttons & PreviewButtons.Navigator) != 0;
  401. btnClose.Available = (Buttons & PreviewButtons.Close) != 0;
  402. }
  403. private List<PreparedPages> GetPageOfTabs()
  404. {
  405. List<PreparedPages> list = new List<PreparedPages>();
  406. foreach (var tab in tabControl.Tabs)
  407. {
  408. if (tab is PreviewTab)
  409. list.Add((tab as PreviewTab).PreparedPages);
  410. }
  411. return list;
  412. }
  413. private void Export_Click(object sender, EventArgs e)
  414. {
  415. if (IsPreviewEmpty)
  416. return;
  417. ObjectInfo info = (sender as ToolStripMenuItem).Tag as ObjectInfo;
  418. if (info == null)
  419. Save();
  420. else
  421. {
  422. ExportBase export = Activator.CreateInstance(info.Object) as ExportBase;
  423. export.CurPage = CurrentPreview.PageNo;
  424. export.AllowSaveSettings = true;
  425. export.ShowProgress = true;
  426. try
  427. {
  428. export.Export(Report, GetPageOfTabs());
  429. }
  430. #if !DEBUG
  431. catch (Exception ex)
  432. {
  433. using (ExceptionForm form = new ExceptionForm(ex))
  434. {
  435. form.ShowDialog();
  436. }
  437. }
  438. #endif
  439. finally
  440. {
  441. }
  442. }
  443. }
  444. private async void Design()
  445. {
  446. if (Report == null)
  447. return;
  448. using (Report designedReport = new Report())
  449. {
  450. designedReport.FileName = Report.FileName;
  451. if (!String.IsNullOrEmpty(Report.FileName))
  452. designedReport.Load(designedReport.FileName);
  453. else
  454. using (MemoryStream repStream = new MemoryStream())
  455. {
  456. Report.Save(repStream);
  457. repStream.Position = 0;
  458. designedReport.Load(repStream);
  459. }
  460. Report.Dictionary.ReRegisterData(designedReport.Dictionary);
  461. #if AVALONIA
  462. if (await designedReport.DesignAsync())
  463. #else
  464. if (designedReport.Design())
  465. #endif
  466. {
  467. Report.PreparedPages.Clear();
  468. Report.PreparedPages.ClearPageCache();
  469. try
  470. {
  471. Report.LoadFromString(designedReport.SaveToString());
  472. }
  473. catch (Exception ex)
  474. {
  475. FRMessageBox.Error(ex.Message);
  476. }
  477. if (CurrentPreview != null)
  478. {
  479. Report.Preview = CurrentPreview.Preview;
  480. Report.Show();
  481. }
  482. }
  483. }
  484. }
  485. private void SaveToCloud_Click(object sender, EventArgs e)
  486. {
  487. if (IsPreviewEmpty)
  488. {
  489. return;
  490. }
  491. ObjectInfo info = (sender as ToolStripMenuItem).Tag as ObjectInfo;
  492. if (info != null)
  493. {
  494. CloudStorageClient client = Activator.CreateInstance(info.Object) as CloudStorageClient;
  495. if (client is FtpStorageClient)
  496. {
  497. XmlItem xi = Config.Root.FindItem("FtpServer").FindItem("StorageSettings");
  498. string server = xi.GetProp("FtpServer");
  499. string username = xi.GetProp("FtpUsername");
  500. FtpStorageClientForm form = new FtpStorageClientForm(server, username, "", Report);
  501. form.ShowDialog();
  502. }
  503. else if (client is DropboxStorageClient)
  504. {
  505. XmlItem xi = Config.Root.FindItem("DropboxCloud").FindItem("StorageSettings");
  506. string accessToken = xi.GetProp("AccessToken");
  507. if (String.IsNullOrEmpty(accessToken))
  508. {
  509. ApplicationInfoForm appInfoDialog = new ApplicationInfoForm();
  510. appInfoDialog.ShowDialog();
  511. accessToken = appInfoDialog.AccessToken;
  512. }
  513. DropboxStorageClientForm form = new DropboxStorageClientForm(accessToken, Report);
  514. form.ShowDialog();
  515. }
  516. else if (client is FastCloudStorageClient)
  517. {
  518. FastCloudStorageClientSimpleForm form = new FastCloudStorageClientSimpleForm(Report);
  519. form.ShowDialog();
  520. }
  521. #if !AVALONIA
  522. else if (client is BoxStorageClient)
  523. {
  524. XmlItem xi = Config.Root.FindItem("BoxCloud").FindItem("StorageSettings");
  525. string id = xi.GetProp("ClientId");
  526. string secret = xi.GetProp("ClientSecret");
  527. DialogResult clientInfoDialogDialogResult = DialogResult.OK;
  528. if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(secret))
  529. {
  530. Box.ClientInfoForm clientInfoDialog = new Box.ClientInfoForm();
  531. clientInfoDialog.ShowDialog();
  532. id = clientInfoDialog.Id;
  533. secret = clientInfoDialog.Secret;
  534. clientInfoDialogDialogResult = clientInfoDialog.DialogResult;
  535. }
  536. if (clientInfoDialogDialogResult == DialogResult.OK)
  537. {
  538. BoxStorageClientForm form = new BoxStorageClientForm(new SkyDrive.ClientInfo("", id, secret), Report);
  539. form.ShowDialog();
  540. }
  541. }
  542. else if (client is GoogleDriveStorageClient)
  543. {
  544. XmlItem xi = Config.Root.FindItem("GoogleDriveCloud").FindItem("StorageSettings");
  545. string id = xi.GetProp("ClientId");
  546. string secret = xi.GetProp("ClientSecret");
  547. if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(secret))
  548. {
  549. GoogleDrive.ClientInfoForm clientInfoDialog = new GoogleDrive.ClientInfoForm();
  550. clientInfoDialog.ShowDialog();
  551. id = clientInfoDialog.Id;
  552. secret = clientInfoDialog.Secret;
  553. }
  554. GoogleDriveStorageClientForm form = new GoogleDriveStorageClientForm(new SkyDrive.ClientInfo("", id, secret), Report);
  555. form.ShowDialog();
  556. }
  557. else if (client is SkyDriveStorageClient)
  558. {
  559. XmlItem xi = Config.Root.FindItem("SkyDriveCloud").FindItem("StorageSettings");
  560. string id = xi.GetProp("ClientId");
  561. string secret = xi.GetProp("ClientSecret");
  562. if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(secret))
  563. {
  564. SkyDrive.ClientInfoForm appInfoDialog = new SkyDrive.ClientInfoForm();
  565. appInfoDialog.ShowDialog();
  566. id = appInfoDialog.Id;
  567. secret = appInfoDialog.Secret;
  568. }
  569. SkyDriveStorageClientForm form = new SkyDriveStorageClientForm(new SkyDrive.ClientInfo("", id, secret), Report);
  570. form.ShowDialog();
  571. }
  572. #endif
  573. else if (client is S3StorageClient)
  574. {
  575. XmlItem xi = Config.Root.FindItem("S3").FindItem("StorageSettings");
  576. string accessKeyId = xi.GetProp("AccessKeyId");
  577. string secretAccessKey = xi.GetProp("SecretAccessKey");
  578. string region = xi.GetProp("Region");
  579. string host = xi.GetProp("Host");
  580. Cloud.StorageClient.S3.ClientInfoForm appInfoDialog = new Cloud.StorageClient.S3.ClientInfoForm();
  581. appInfoDialog.AccessKeyId = accessKeyId;
  582. appInfoDialog.SecretAccessKey = secretAccessKey;
  583. appInfoDialog.Region = region;
  584. appInfoDialog.Host = host;
  585. if (appInfoDialog.ShowDialog() == DialogResult.OK)
  586. {
  587. accessKeyId = appInfoDialog.AccessKeyId;
  588. secretAccessKey = appInfoDialog.SecretAccessKey;
  589. region = appInfoDialog.Region;
  590. host = appInfoDialog.Host;
  591. }
  592. else
  593. return;
  594. S3ClientForm form = new S3ClientForm(accessKeyId, secretAccessKey, region, host, Report);
  595. form.Client.AfterUpload += PreviewControl_AfterUpload;
  596. form.Client.BeforeUpload += Client_BeforeUpload;
  597. form.ShowDialog();
  598. }
  599. }
  600. }
  601. private void Client_BeforeUpload(object sender, EventArgs e)
  602. {
  603. ShowPerformance(Res.Get("Preview,Uploading"));
  604. uploadTimer.Start();
  605. }
  606. private void Timer_Tick(object sender, EventArgs e)
  607. {
  608. if (lblPerformance.Text.Contains("..."))
  609. lblPerformance.Text = lblPerformance.Text.Replace("...", "");
  610. else
  611. lblPerformance.Text += ".";
  612. }
  613. private void PreviewControl_AfterUpload(object sender, EventArgs e)
  614. {
  615. ShowPerformance(Res.Get("Preview,UploadDone"));
  616. }
  617. private void tabControl1_TabClosed(object sender, EventArgs e)
  618. {
  619. DeleteTab(sender as PreviewTab);
  620. }
  621. private void tabControl1_TabChanged(object sender, EventArgs e)
  622. {
  623. if (locked)
  624. return;
  625. currentPreview = tabControl.SelectedTab as PreviewTab;
  626. if (currentPreview != null && !currentPreview.Fake)
  627. {
  628. UpdateOutline();
  629. UpdateZoom(currentPreview.Zoom);
  630. UpdatePageNumbers(currentPreview.PageNo, currentPreview.PageCount);
  631. }
  632. }
  633. private void tabControl_Resize(object sender, EventArgs e)
  634. {
  635. UpdateDocumentLayout();
  636. }
  637. private bool CanDisposeTabReport(PreviewTab tab)
  638. {
  639. if (tab == null || tab.Report == null)
  640. return false;
  641. // if the preview is owned by Report, do not dispose
  642. if (report == tab.Report)
  643. return false;
  644. // check if the same Report is used in other tabs
  645. foreach (PreviewTab t in documents)
  646. {
  647. if (t != tab && t.Report == tab.Report)
  648. {
  649. return false;
  650. }
  651. }
  652. return true;
  653. }
  654. private void Localize()
  655. {
  656. MyRes res = new MyRes("Preview");
  657. btnPrint.Text = res.Get("PrintText");
  658. btnPrint.ToolTipText = res.Get("Print");
  659. btnOpen.ToolTipText = res.Get("Open");
  660. btnOpen.Text = res.Get("OpenText");
  661. btnDesign.Text = res.Get("DesignText");
  662. btnDesign.ToolTipText = res.Get("Design");
  663. btnSave.ToolTipText = res.Get("Save");
  664. btnSave.Text = res.Get("SaveText");
  665. btnEmail.ToolTipText = res.Get("Email");
  666. btnFind.ToolTipText = res.Get("Find");
  667. btnOutline.ToolTipText = res.Get("Outline");
  668. btnPageSetup.ToolTipText = res.Get("PageSetup");
  669. btnEdit.ToolTipText = res.Get("Edit");
  670. btnWatermark.ToolTipText = res.Get("Watermark");
  671. btnFirst.ToolTipText = res.Get("First");
  672. btnPrior.ToolTipText = res.Get("Prior");
  673. btnNext.ToolTipText = res.Get("Next");
  674. lblTotalPages.Text = String.Format(Res.Get("Misc,ofM"), 1);
  675. btnLast.ToolTipText = res.Get("Last");
  676. btnClose.Text = Res.Get("Buttons,Close");
  677. }
  678. private void Init()
  679. {
  680. outlineControl.SetPreview(this);
  681. uploadTimer = new Timer();
  682. uploadTimer.Interval = 1500;
  683. uploadTimer.Tick += Timer_Tick;
  684. pageBorderColor = Color.FromArgb(80, 80, 80);
  685. activePageBorderColor = Color.FromArgb(255, 199, 60);
  686. pageOffset = new Point(10, 10);
  687. defaultZoom = 1;
  688. buttons = PreviewButtons.All;
  689. exports = Config.PreviewSettings.Exports;
  690. clouds = Config.PreviewSettings.Clouds;
  691. RestoreState();
  692. UpdateButtons();
  693. zoomControl.ZoomValue = Zoom;
  694. }
  695. public void RestoreState()
  696. {
  697. var storage = new ControlStorageService(this, "Preview");
  698. defaultZoom = storage.GetFloat("Zoom", 1);
  699. splitContainer1.SplitterDistance = storage.GetDip("OutlineWidth", 250, 50, 800);
  700. }
  701. public void SaveState()
  702. {
  703. Clear();
  704. outlineControl.Hide();
  705. var storage = new ControlStorageService(this, "Preview");
  706. storage.SetFloat("Zoom", Zoom);
  707. storage.SetDip("OutlineWidth", splitContainer1.SplitterDistance);
  708. }
  709. private void UpdateDocumentLayout()
  710. {
  711. foreach (PreviewTab tab in documents)
  712. {
  713. tab.UpdatePages();
  714. }
  715. }
  716. private void UpdateUIStyle()
  717. {
  718. toolStrip.Renderer = statusStrip.Renderer = UIStyleUtils.GetToolStripRenderer(UIStyle);
  719. zoomControl.UIStyle = UIStyle;
  720. var table = UIStyleUtils.GetColorTable(UIStyle);
  721. if (!UseBackColor)
  722. BackColor = table.Workspace.WorkspaceBackColor;
  723. tabControl.Style = table.Workspace;
  724. foreach (PreviewTab tab in documents)
  725. {
  726. tab.Style = UIStyle;
  727. }
  728. }
  729. private void UpdateOutline()
  730. {
  731. outlineControl.PreparedPages = currentPreview.PreparedPages;
  732. OutlineVisible = !currentPreview.PreparedPages.Outline.IsEmpty;
  733. }
  734. private void AddFakeTab()
  735. {
  736. PreviewTab tab = new PreviewTab(this, null, "", null);
  737. tab.Fake = true;
  738. documents.Add(tab);
  739. tab.AddToTabControl(tabControl);
  740. }
  741. private void UpdateTabsVisible()
  742. {
  743. tabControl.ShowTabs = documents.Count > 1 && !documents[0].Fake;
  744. }
  745. private PreviewTab FindTab(string text)
  746. {
  747. foreach (PreviewTab tab in documents)
  748. {
  749. if (tab.Text == text)
  750. return tab;
  751. }
  752. return null;
  753. }
  754. private PreviewTab FindTabByHyperlinkValue(string value)
  755. {
  756. foreach (PreviewTab tab in documents)
  757. {
  758. if (tab.HyperlinkValue == value)
  759. return tab;
  760. }
  761. return null;
  762. }
  763. #endregion
  764. #region Public Methods
  765. internal void SetReport(Report report)
  766. {
  767. this.report = report;
  768. }
  769. internal void UpdatePageNumbers(int pageNo, int totalPages)
  770. {
  771. lblStatus.Text = String.Format(Res.Get("Misc,PageNofM"), pageNo, totalPages);
  772. tbPageNo.Text = pageNo.ToString();
  773. lblTotalPages.Text = String.Format(Res.Get("Misc,ofM"), totalPages);
  774. if (PageChanged != null)
  775. PageChanged(this, EventArgs.Empty);
  776. }
  777. internal void UpdateZoom(float zoom)
  778. {
  779. updatingZoom = true;
  780. zoomControl.ZoomValue = zoom;
  781. updatingZoom = false;
  782. }
  783. internal void UpdateUrl(string url)
  784. {
  785. lblUrl.Text = url;
  786. }
  787. internal void ShowPerformance(string text)
  788. {
  789. uploadTimer.Stop();
  790. lblPerformance.Text = text;
  791. }
  792. internal void DoClick()
  793. {
  794. OnClick(EventArgs.Empty);
  795. }
  796. // Clears all tabs except the first one. This method is used in the report.Prepare.
  797. // It is needed to avoid flickering when using stand-alone PreviewControl.
  798. // When report is prepared and ShowPrepared method is called, the "fake" tab will
  799. // be replaced with the new tab.
  800. internal void ClearTabsExceptFirst()
  801. {
  802. while (documents.Count > 1)
  803. {
  804. DeleteTab(documents[documents.Count - 1]);
  805. }
  806. if (documents.Count == 1)
  807. documents[0].Fake = true;
  808. }
  809. internal PreviewTab AddPreviewTab(Report report, string text, Hyperlink hyperlink, bool setActive)
  810. {
  811. PreviewTab tab = new PreviewTab(this, report, text, hyperlink);
  812. documents.Add(tab);
  813. if (documents.Count == 2 && documents[0].Fake)
  814. DeleteTab(documents[0]);
  815. var rescale = tabControl.Dpi() / (float)tab.Dpi();
  816. tab.AddToTabControl(tabControl);
  817. tab.Scale(new SizeF(rescale, rescale));
  818. tab.UnlockLayout();
  819. UpdateTabsVisible();
  820. tab.UpdatePages();
  821. if (setActive)
  822. tabControl.SelectedTab = tab;
  823. else
  824. tabControl.Refresh();
  825. return tab;
  826. }
  827. /// <summary>
  828. /// Adds a new report tab to the preview control.
  829. /// </summary>
  830. /// <param name="report">The <b>Report</b> object that contains the prepared report.</param>
  831. /// <param name="text">The title for the new tab.</param>
  832. /// <remarks>
  833. /// Prepare the report using its <b>Prepare</b> method before you pass it to the <b>report</b> parameter.
  834. /// </remarks>
  835. public void AddTab(Report report, string text)
  836. {
  837. if (this.report == null)
  838. SetReport(report);
  839. AddPreviewTab(report, text, null, true);
  840. }
  841. /// <summary>
  842. /// Switches to the tab with specified text.
  843. /// </summary>
  844. /// <param name="text">Text of the tab.</param>
  845. /// <returns><b>true</b> if the tab with specified text exists, or <b>false</b> if there is no such tab.</returns>
  846. public bool SwitchToTab(string text)
  847. {
  848. PreviewTab tab = FindTab(text);
  849. if (tab != null)
  850. {
  851. tabControl.SelectedTab = tab;
  852. return true;
  853. }
  854. return false;
  855. }
  856. internal bool SwitchToTab(Hyperlink hyperlink)
  857. {
  858. PreviewTab tab = FindTabByHyperlinkValue(hyperlink.Value);
  859. if (tab != null)
  860. {
  861. tabControl.SelectedTab = tab;
  862. return true;
  863. }
  864. return false;
  865. }
  866. /// <summary>
  867. /// Deletes the report tab with specified text.
  868. /// </summary>
  869. /// <param name="text">The text of the tab.</param>
  870. public void DeleteTab(string text)
  871. {
  872. PreviewTab tab = FindTab(text);
  873. if (tab != null)
  874. DeleteTab(tab);
  875. }
  876. /// <summary>
  877. /// Checks if the tab with specified text exists.
  878. /// </summary>
  879. /// <param name="text">The text of the tab.</param>
  880. /// <returns><b>true</b> if the tab exists.</returns>
  881. public bool TabExists(string text)
  882. {
  883. return FindTab(text) != null;
  884. }
  885. internal void DeleteTab(PreviewTab tab)
  886. {
  887. if (CanDisposeTabReport(tab))
  888. tab.Report.Dispose();
  889. documents.Remove(tab);
  890. tabControl.Tabs.Remove(tab);
  891. tab.Dispose();
  892. uploadTimer.Dispose();
  893. UpdateTabsVisible();
  894. }
  895. /// <summary>
  896. /// Displays the text in the status bar.
  897. /// </summary>
  898. /// <param name="text">Text to display.</param>
  899. public void ShowStatus(string text)
  900. {
  901. int tick = Environment.TickCount;
  902. if (tick - lastTick < 50 && !string.IsNullOrEmpty(text))
  903. return;
  904. lastTick = tick;
  905. lblStatus.Text = text;
  906. statusStrip.Refresh();
  907. Application.DoEvents();
  908. }
  909. internal void Lock()
  910. {
  911. locked = true;
  912. }
  913. internal void Unlock()
  914. {
  915. locked = false;
  916. }
  917. /// <summary>
  918. /// Sets the focus to the preview control.
  919. /// </summary>
  920. public new void Focus()
  921. {
  922. if (currentPreview != null)
  923. currentPreview.Focus();
  924. }
  925. /// <summary>
  926. /// Updates the control appearance and layout on dpi change.
  927. /// </summary>
  928. public void UpdateDpiDependencies()
  929. {
  930. Font = this.LogicalToDevice(DrawUtils.DefaultFont);
  931. tabControl.Font = Font;
  932. toolStrip.Font = Font;
  933. statusStrip.Font = Font;
  934. tbPageNo.Font = Font;
  935. outlineControl.Font = Font;
  936. outlineControl.UpdateDpiDependencies();
  937. toolStrip.Height = this.LogicalToDevice(26);
  938. statusStrip.Height = this.LogicalToDevice(26);
  939. statusStrip.Padding = new Padding(6, 0, 0, 0);
  940. tabControl.UpdateDpiDependencies();
  941. btnPrint.Image = this.GetImage(195);
  942. btnOpen.Image = this.GetImage(1);
  943. btnSave.Image = this.GetImage(2);
  944. btnDesign.Image = this.GetImage(68);
  945. btnEmail.Image = this.GetImage(200);
  946. btnFind.Image = this.GetImage(181);
  947. btnOutline.Image = this.GetImage(196);
  948. btnPageSetup.Image = this.GetImage(13);
  949. btnEdit.Image = this.GetImage(198);
  950. btnWatermark.Image = this.GetImage(194);
  951. btnFirst.Image = this.GetImage(185);
  952. btnPrior.Image = this.GetImage(186);
  953. btnNext.Image = this.GetImage(187);
  954. btnLast.Image = this.GetImage(188);
  955. tbPageNo.Size = this.LogicalToDevice(new Size(40, 21));
  956. lblStatus.Size = this.LogicalToDevice(new Size(280, 21));
  957. zoomControl.Size = this.LogicalToDevice(new Size(280, 26));
  958. CreateOpenList();
  959. CreateSaveList();
  960. UpdateDocumentLayout();
  961. }
  962. #endregion
  963. #region Async Prepare
  964. /// <summary>
  965. /// Gets the value indicating that async report is running.
  966. /// </summary>
  967. /// <remarks>
  968. /// This value can be used to abort the report when you close the form that contains the report preview control.
  969. /// </remarks>
  970. public bool IsAsyncReportRunning { get; private set; }
  971. // we have to call this separately before AsyncReportStart to set this flag (case: clicking reports in the reports list too fast leads to NRE)
  972. internal void SetAsyncReportRunning() => IsAsyncReportRunning = true;
  973. internal void AsyncReportStart()
  974. {
  975. Report.PreparedPages.PageAdded += AsyncReportPageAdded;
  976. // update buttons
  977. btnClose.Text = Res.Get("Buttons,Cancel");
  978. EnableButtons(false);
  979. lblStatus.Text = "";
  980. uploadTimer.Stop();
  981. lblPerformance.Text = "";
  982. tbPageNo.Text = "0";
  983. }
  984. private int lastTick;
  985. private void AsyncReportPageAdded(object sender, EventArgs e)
  986. {
  987. int tick = Environment.TickCount;
  988. if (tick - lastTick < 50 && Report.PreparedPages.Count > 100)
  989. return;
  990. Application.DoEvents();
  991. if (Report.Engine.FinalPass)
  992. {
  993. OutlineVisible = !Report.PreparedPages.Outline.IsEmpty;
  994. CurrentPreview.UpdatePages();
  995. }
  996. lastTick = Environment.TickCount;
  997. }
  998. internal void AsyncReportFinish()
  999. {
  1000. IsAsyncReportRunning = false;
  1001. Report.PreparedPages.PageAdded -= AsyncReportPageAdded;
  1002. Report.PreparedPages.ClearPageCache();
  1003. UpdateOutline();
  1004. CurrentPreview.UpdatePages();
  1005. // update buttons
  1006. btnClose.Text = Res.Get("Buttons,Close");
  1007. EnableButtons(true);
  1008. }
  1009. private void EnableButtons(bool enable)
  1010. {
  1011. foreach (ToolStripItem button in ToolBar.Items)
  1012. {
  1013. if (button == btnFirst)
  1014. break;
  1015. button.Enabled = enable;
  1016. }
  1017. }
  1018. #endregion
  1019. #region Event handlers
  1020. private void btnDesign_Click(object sender, EventArgs e)
  1021. {
  1022. Design();
  1023. }
  1024. private void btnPrint_Click(object sender, EventArgs e)
  1025. {
  1026. Print();
  1027. }
  1028. private void btnOpenLocal_Click(object sender, EventArgs e)
  1029. {
  1030. Load();
  1031. }
  1032. private void btnOpenViaCloud_Click(object sender, EventArgs e)
  1033. {
  1034. var stream = CloudCommands.LoadPreviewFile();
  1035. if (stream != null)
  1036. Load(stream);
  1037. }
  1038. private void btnSaveLocal_Click(object sender, EventArgs e)
  1039. {
  1040. Save();
  1041. }
  1042. private void btnSaveToCloud_Click(object sender, EventArgs e)
  1043. {
  1044. CloudCommands.SavePreviewFile(currentPreview.Report);
  1045. }
  1046. private void btnEmail_Click(object sender, EventArgs e)
  1047. {
  1048. SendEmail();
  1049. }
  1050. private void btnFind_Click(object sender, EventArgs e)
  1051. {
  1052. Find();
  1053. }
  1054. private void btnZoom100_Click(object sender, EventArgs e)
  1055. {
  1056. Zoom = 1;
  1057. }
  1058. private void btnZoomWholePage_Click(object sender, EventArgs e)
  1059. {
  1060. ZoomWholePage();
  1061. }
  1062. private void btnZoomPageWidth_Click(object sender, EventArgs e)
  1063. {
  1064. ZoomPageWidth();
  1065. }
  1066. private void slider_ValueChanged(object sender, EventArgs e)
  1067. {
  1068. if (updatingZoom || CurrentPreview == null)
  1069. return;
  1070. Zoom = zoomControl.ZoomValue;
  1071. CurrentPreview.Focus();
  1072. }
  1073. private void btnEdit_Click(object sender, EventArgs e)
  1074. {
  1075. EditPage();
  1076. }
  1077. private void btnFirst_Click(object sender, EventArgs e)
  1078. {
  1079. First();
  1080. }
  1081. private void btnPrior_Click(object sender, EventArgs e)
  1082. {
  1083. Prior();
  1084. }
  1085. private void btnNext_Click(object sender, EventArgs e)
  1086. {
  1087. Next();
  1088. }
  1089. private void btnLast_Click(object sender, EventArgs e)
  1090. {
  1091. Last();
  1092. }
  1093. private void cbxPageNo_KeyDown(object sender, KeyEventArgs e)
  1094. {
  1095. if (e.KeyCode == Keys.Enter)
  1096. {
  1097. try
  1098. {
  1099. PageNo = int.Parse(tbPageNo.Text);
  1100. }
  1101. catch
  1102. {
  1103. PageNo = PageCount;
  1104. }
  1105. CurrentPreview.Focus();
  1106. }
  1107. }
  1108. private void tbPageNo_KeyPress(object sender, KeyPressEventArgs e)
  1109. {
  1110. if (e.KeyChar != '\b' && (e.KeyChar < '0' || e.KeyChar > '9'))
  1111. e.Handled = true;
  1112. }
  1113. private void btnWatermark_Click(object sender, EventArgs e)
  1114. {
  1115. EditWatermark();
  1116. }
  1117. private void btnOutline_Click(object sender, EventArgs e)
  1118. {
  1119. OutlineVisible = btnOutline.Checked;
  1120. }
  1121. private void btnPageSetup_Click(object sender, EventArgs e)
  1122. {
  1123. PageSetup();
  1124. }
  1125. private void btnClose_Click(object sender, EventArgs e)
  1126. {
  1127. if (IsAsyncReportRunning)
  1128. {
  1129. Report.Abort();
  1130. return;
  1131. }
  1132. #if WPF
  1133. System.Windows.Window.GetWindow(control)?.Close();
  1134. #elif AVALONIA
  1135. (Avalonia.Controls.TopLevel.GetTopLevel(control) as Avalonia.Controls.Window)?.Close();
  1136. #else
  1137. if (FindForm() != null)
  1138. FindForm().Close();
  1139. #endif
  1140. }
  1141. #endregion
  1142. #region Preview commands
  1143. /// <summary>
  1144. /// Prints the current report.
  1145. /// </summary>
  1146. /// <returns><b>true</b> if report was printed; <b>false</b> if user cancels the "Print" dialog.</returns>
  1147. public bool Print()
  1148. {
  1149. if (CurrentPreview == null)
  1150. return false;
  1151. return CurrentPreview.Print();
  1152. }
  1153. /// <summary>
  1154. /// Saves the current report to a .fpx file using the "Save FIle" dialog.
  1155. /// </summary>
  1156. public void Save()
  1157. {
  1158. if (CurrentPreview == null)
  1159. return;
  1160. CurrentPreview.Save();
  1161. }
  1162. /// <summary>
  1163. /// Saves the current report to a specified .fpx file.
  1164. /// </summary>
  1165. public void Save(string fileName)
  1166. {
  1167. if (CurrentPreview == null)
  1168. return;
  1169. CurrentPreview.Save(fileName);
  1170. }
  1171. /// <summary>
  1172. /// Saves the current report to a stream.
  1173. /// </summary>
  1174. public void Save(Stream stream)
  1175. {
  1176. if (CurrentPreview == null)
  1177. return;
  1178. CurrentPreview.Save(stream);
  1179. }
  1180. private bool PreLoad()
  1181. {
  1182. if (CurrentPreview == null)
  1183. return false;
  1184. if (documents.Count == 1 && documents[0].Fake)
  1185. {
  1186. Report report = new Report();
  1187. report.SetPreparedPages(new PreparedPages(report));
  1188. AddTab(report, "");
  1189. }
  1190. return true;
  1191. }
  1192. private void PostLoad()
  1193. {
  1194. UpdateOutline();
  1195. }
  1196. /// <summary>
  1197. /// Loads the report from a .fpx file using the "Open File" dialog.
  1198. /// </summary>
  1199. public new void Load()
  1200. {
  1201. if (CurrentPreview == null)
  1202. return;
  1203. CurrentPreview.Load();
  1204. UpdateOutline();
  1205. }
  1206. /// <summary>
  1207. /// Loads the report from a specified .fpx file.
  1208. /// </summary>
  1209. public new void Load(string fileName)
  1210. {
  1211. if (CurrentPreview == null)
  1212. return;
  1213. CurrentPreview.Load(fileName);
  1214. UpdateOutline();
  1215. }
  1216. /// <summary>
  1217. /// Load the report from a stream.
  1218. /// </summary>
  1219. /// <param name="stream">The stream to load from.</param>
  1220. public new void Load(Stream stream)
  1221. {
  1222. if (CurrentPreview == null)
  1223. return;
  1224. CurrentPreview.Load(stream);
  1225. UpdateOutline();
  1226. }
  1227. /// <summary>
  1228. /// Sends an email.
  1229. /// </summary>
  1230. public void SendEmail()
  1231. {
  1232. if (CurrentPreview == null)
  1233. return;
  1234. CurrentPreview.SendEmail();
  1235. }
  1236. /// <summary>
  1237. /// Finds the text in the current report using the "Find Text" dialog.
  1238. /// </summary>
  1239. public void Find()
  1240. {
  1241. if (CurrentPreview == null)
  1242. return;
  1243. CurrentPreview.Find();
  1244. }
  1245. /// <summary>
  1246. /// Finds the specified text in the current report.
  1247. /// </summary>
  1248. /// <param name="text">Text to find.</param>
  1249. /// <param name="matchCase">A value indicating whether the search is case-sensitive.</param>
  1250. /// <param name="wholeWord">A value indicating whether the search matches whole words only.</param>
  1251. /// <returns><b>true</b> if text found.</returns>
  1252. public bool Find(string text, bool matchCase, bool wholeWord)
  1253. {
  1254. if (CurrentPreview == null)
  1255. return false;
  1256. return CurrentPreview.Find(text, matchCase, wholeWord);
  1257. }
  1258. /// <summary>
  1259. /// Finds the next occurence of text specified in the <b>Find</b> method.
  1260. /// </summary>
  1261. /// <returns><b>true</b> if text found.</returns>
  1262. public bool FindNext()
  1263. {
  1264. if (CurrentPreview == null)
  1265. return false;
  1266. return CurrentPreview.FindNext();
  1267. }
  1268. /// <summary>
  1269. /// Navigates to the first page.
  1270. /// </summary>
  1271. public void First()
  1272. {
  1273. if (CurrentPreview == null)
  1274. return;
  1275. CurrentPreview.First();
  1276. }
  1277. /// <summary>
  1278. /// Navigates to the previuos page.
  1279. /// </summary>
  1280. public void Prior()
  1281. {
  1282. if (CurrentPreview == null)
  1283. return;
  1284. CurrentPreview.Prior();
  1285. }
  1286. /// <summary>
  1287. /// Navigates to the next page.
  1288. /// </summary>
  1289. public void Next()
  1290. {
  1291. if (CurrentPreview == null)
  1292. return;
  1293. CurrentPreview.Next();
  1294. }
  1295. /// <summary>
  1296. /// Navigates to the last page.
  1297. /// </summary>
  1298. public void Last()
  1299. {
  1300. if (CurrentPreview == null)
  1301. return;
  1302. CurrentPreview.Last();
  1303. }
  1304. /// <summary>
  1305. /// Gets or sets the current page number.
  1306. /// </summary>
  1307. /// <remarks>
  1308. /// This value is 1-based.
  1309. /// </remarks>
  1310. [Browsable(false)]
  1311. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1312. public int PageNo
  1313. {
  1314. get
  1315. {
  1316. if (CurrentPreview == null)
  1317. return 1;
  1318. return CurrentPreview.PageNo;
  1319. }
  1320. set
  1321. {
  1322. if (CurrentPreview == null)
  1323. return;
  1324. CurrentPreview.PageNo = value;
  1325. }
  1326. }
  1327. /// <summary>
  1328. /// Gets the pages count in the current report.
  1329. /// </summary>
  1330. [Browsable(false)]
  1331. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1332. public int PageCount
  1333. {
  1334. get
  1335. {
  1336. if (CurrentPreview == null)
  1337. return 0;
  1338. return CurrentPreview.PageCount;
  1339. }
  1340. }
  1341. /// <summary>
  1342. /// Gets or sets the zoom factor.
  1343. /// </summary>
  1344. /// <remarks>
  1345. /// <b>1</b> corresponds to 100% zoom.
  1346. /// </remarks>
  1347. [Browsable(false)]
  1348. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1349. public float Zoom
  1350. {
  1351. get
  1352. {
  1353. if (CurrentPreview == null)
  1354. return 1;
  1355. return CurrentPreview.Zoom;
  1356. }
  1357. set
  1358. {
  1359. if (CurrentPreview != null)
  1360. {
  1361. CurrentPreview.Zoom = value;
  1362. updatingZoom = true;
  1363. zoomControl.ZoomValue = value;
  1364. updatingZoom = false;
  1365. }
  1366. }
  1367. }
  1368. /// <summary>
  1369. /// Zooms in.
  1370. /// </summary>
  1371. public void ZoomIn()
  1372. {
  1373. if (CurrentPreview == null)
  1374. return;
  1375. CurrentPreview.ZoomIn();
  1376. }
  1377. /// <summary>
  1378. /// Zooms out.
  1379. /// </summary>
  1380. public void ZoomOut()
  1381. {
  1382. if (CurrentPreview == null)
  1383. return;
  1384. CurrentPreview.ZoomOut();
  1385. }
  1386. /// <summary>
  1387. /// Zooms to fit the page width.
  1388. /// </summary>
  1389. public void ZoomPageWidth()
  1390. {
  1391. if (CurrentPreview == null)
  1392. return;
  1393. CurrentPreview.ZoomPageWidth();
  1394. }
  1395. /// <summary>
  1396. /// Zooms to fit the whole page.
  1397. /// </summary>
  1398. public void ZoomWholePage()
  1399. {
  1400. if (CurrentPreview == null)
  1401. return;
  1402. CurrentPreview.ZoomWholePage();
  1403. }
  1404. /// <summary>
  1405. /// Edits the current page in the designer.
  1406. /// </summary>
  1407. public void EditPage()
  1408. {
  1409. if (CurrentPreview == null)
  1410. return;
  1411. CurrentPreview.EditPage();
  1412. }
  1413. /// <summary>
  1414. /// Edits the watermark.
  1415. /// </summary>
  1416. public void EditWatermark()
  1417. {
  1418. if (CurrentPreview == null)
  1419. return;
  1420. CurrentPreview.EditWatermark();
  1421. }
  1422. /// <summary>
  1423. /// Edits the page settings.
  1424. /// </summary>
  1425. public void PageSetup()
  1426. {
  1427. if (CurrentPreview == null)
  1428. return;
  1429. CurrentPreview.PageSetup();
  1430. }
  1431. /// <summary>
  1432. /// Navigates to the specified position inside a specified page.
  1433. /// </summary>
  1434. /// <param name="pageNo">The page number (1-based).</param>
  1435. /// <param name="point">The position inside a page, in pixels.</param>
  1436. public void PositionTo(int pageNo, PointF point)
  1437. {
  1438. if (CurrentPreview == null)
  1439. return;
  1440. CurrentPreview.PositionTo(pageNo, point);
  1441. }
  1442. /// <summary>
  1443. /// Clears the preview.
  1444. /// </summary>
  1445. public void Clear()
  1446. {
  1447. while (documents.Count > 0)
  1448. {
  1449. DeleteTab(documents[0]);
  1450. }
  1451. lblStatus.Text = "";
  1452. tbPageNo.Text = "";
  1453. }
  1454. /// <summary>
  1455. /// Refresh the report.
  1456. /// </summary>
  1457. public void RefreshReport()
  1458. {
  1459. if (CurrentPreview == null)
  1460. return;
  1461. CurrentPreview.RefreshReport();
  1462. }
  1463. #endregion
  1464. /// <summary>
  1465. /// Initializes a new instance of the <see cref="PreviewControl"/> class.
  1466. /// </summary>
  1467. public PreviewControl()
  1468. {
  1469. // we need this to ensure that static constructor of the Report was called.
  1470. Report report = new Report();
  1471. report.Dispose();
  1472. documents = new List<PreviewTab>();
  1473. InitializeComponent();
  1474. tabControl = new FRTabControl();
  1475. tabControl.Parent = splitContainer1.Panel2;
  1476. tabControl.ShowCaption = false;
  1477. tabControl.TabOrientation = TabOrientation.Top;
  1478. tabControl.Dock = DockStyle.Fill;
  1479. tabControl.Name = "tabControl";
  1480. tabControl.Resize += tabControl_Resize;
  1481. tabControl.SelectedTabChanged += tabControl1_TabChanged;
  1482. tabControl.TabClosed += tabControl1_TabClosed;
  1483. zoomControl = new ToolStripZoomControl();
  1484. zoomControl.ZoomPageWidthClick += btnZoomPageWidth_Click;
  1485. zoomControl.ZoomWholePageClick += btnZoomWholePage_Click;
  1486. zoomControl.Zoom100Click += btnZoom100_Click;
  1487. zoomControl.ValueChanged += slider_ValueChanged;
  1488. statusStrip.Items.Add(zoomControl);
  1489. #if (WPF || AVALONIA)
  1490. toolStrip.BorderThickness = new Padding(0);
  1491. var shadow = toolStrip.SetShadow(DockStyle.Bottom);
  1492. UIStyleChanged += (s, e) => shadow.Color = UIStyleUtils.GetColorTable(UIStyle).ToolStripBorder;
  1493. #endif
  1494. toolbarVisible = true;
  1495. statusbarVisible = true;
  1496. OutlineVisible = false;
  1497. UIStyle = Config.UIStyle;
  1498. Localize();
  1499. Init();
  1500. AddFakeTab();
  1501. UpdateDpiDependencies();
  1502. }
  1503. }
  1504. }