1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681 |
- using FastReport.Cloud.StorageClient;
- using FastReport.Cloud.StorageClient.Dropbox;
- using FastReport.Cloud.StorageClient.FastCloud;
- using FastReport.Cloud.StorageClient.Ftp;
- using FastReport.Cloud.StorageClient.S3;
- using FastReport.Controls;
- using FastReport.Design;
- using FastReport.Export;
- using FastReport.Messaging;
- using FastReport.Utils;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Design;
- using System.IO;
- using System.Windows.Forms;
- #if !AVALONIA
- using FastReport.Cloud.StorageClient.Box;
- using FastReport.Cloud.StorageClient.GoogleDrive;
- using FastReport.Cloud.StorageClient.SkyDrive;
- using Box = FastReport.Cloud.StorageClient.Box;
- using GoogleDrive = FastReport.Cloud.StorageClient.GoogleDrive;
- using SkyDrive = FastReport.Cloud.StorageClient.SkyDrive;
- #endif
- #if !DEBUG
- using FastReport.Forms;
- #endif
- namespace FastReport.Preview
- {
- /// <summary>
- /// Represents a Windows Forms control used to preview a report.
- /// </summary>
- /// <remarks>
- /// To use this control, place it on a form and link it to a report using the report's
- /// <see cref="FastReport.Report.Preview"/> property. To show a report, call
- /// the <b>Report.Show</b> method:
- /// <code>
- /// report1.Preview = previewControl1;
- /// report1.Show();
- /// </code>
- /// <para>Use this control's methods such as <see cref="Print"/>, <see cref="Save()"/> etc. to
- /// handle the preview. Call <see cref="Clear"/> method to clear the preview.</para>
- /// <para>You can specify whether the standard toolbar is visible in the <see cref="ToolbarVisible"/>
- /// property. The <see cref="StatusbarVisible"/> property allows you to hide/show the statusbar.
- /// </para>
- /// </remarks>
- [ToolboxItem(true), ToolboxBitmap(typeof(Report), "Resources.PreviewControl.bmp")]
- public partial class PreviewControl : UserControl
- {
- #region Fields
- private Report report;
- private List<PreviewTab> documents;
- private bool toolbarVisible;
- private bool statusbarVisible;
- private Color pageBorderColor;
- private Color activePageBorderColor;
- private PreviewButtons buttons;
- private PreviewExports exports;
- private PreviewClouds clouds;
- private float defaultZoom;
- private bool locked;
- private PreviewTab currentPreview;
- private bool fastScrolling;
- private Timer uploadTimer;
- private UIStyle uiStyle;
- private bool useBackColor;
- private FRTabControl tabControl;
- private Point pageOffset;
- private string saveInitialDirectory;
- private ToolStripZoomControl zoomControl;
- private bool updatingZoom;
- #endregion
- #region Properties
- /// <summary>
- /// Occurs when current page number is changed.
- /// </summary>
- public event EventHandler PageChanged;
- /// <summary>
- /// Occurs when UIStyle property is changed.
- /// </summary>
- public event EventHandler UIStyleChanged;
- /// <summary>
- /// Gets a reference to the report.
- /// </summary>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public Report Report
- {
- get { return report; }
- }
- /// <summary>
- /// Obsolete. Gets or sets the color of page border.
- /// </summary>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Never)]
- public Color PageBorderColor
- {
- get { return pageBorderColor; }
- set { pageBorderColor = value; }
- }
- /// <summary>
- /// Gets or sets the color of active page border.
- /// </summary>
- [DefaultValue(typeof(Color), "255, 199, 60")]
- public Color ActivePageBorderColor
- {
- get { return activePageBorderColor; }
- set { activePageBorderColor = value; }
- }
- /// <summary>
- /// Gets or sets the first page offset from the top left corner of the control.
- /// </summary>
- public Point PageOffset
- {
- get { return pageOffset; }
- set { pageOffset = value; }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the toolbar is visible.
- /// </summary>
- [DefaultValue(true)]
- public bool ToolbarVisible
- {
- get { return toolbarVisible; }
- set
- {
- toolbarVisible = value;
- toolStrip.Visible = value;
- }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the statusbar is visible.
- /// </summary>
- [DefaultValue(true)]
- public bool StatusbarVisible
- {
- get { return statusbarVisible; }
- set
- {
- statusbarVisible = value;
- statusStrip.Visible = value;
- }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the outline control is visible.
- /// </summary>
- [DefaultValue(false)]
- public bool OutlineVisible
- {
- get { return outlineControl.Visible; }
- set
- {
- splitContainer1.Panel1Collapsed = !value;
- outlineControl.Visible = value;
- btnOutline.Checked = value;
- }
- }
- /// <summary>
- /// Specifies the set of buttons available in the toolbar.
- /// </summary>
- [DefaultValue(PreviewButtons.All)]
- public PreviewButtons Buttons
- {
- get { return buttons; }
- set
- {
- buttons = value;
- UpdateButtons();
- }
- }
- /// <summary>
- /// Specifies the set of exports that will be available in the preview's "save" menu.
- /// </summary>
- [DefaultValue(PreviewExports.All)]
- public PreviewExports Exports
- {
- get { return exports; }
- set
- {
- exports = value;
- UpdateButtons();
- }
- }
- /// <summary>
- /// Specifies the set of exports in clouds that will be available in the preview's "save" menu.
- /// </summary>
- [DefaultValue(PreviewClouds.All)]
- public PreviewClouds Clouds
- {
- get { return clouds; }
- set
- {
- clouds = value;
- UpdateButtons();
- }
- }
- /// <summary>
- /// Gets or sets a value indicating whether the fast scrolling method should be used.
- /// </summary>
- /// <remarks>
- /// If you enable this property, the gradient background will be disabled.
- /// </remarks>
- [DefaultValue(false)]
- public bool FastScrolling
- {
- get { return fastScrolling; }
- set { fastScrolling = value; }
- }
- /// <summary>
- /// Gets or sets the visual style.
- /// </summary>
- public UIStyle UIStyle
- {
- get { return uiStyle; }
- set
- {
- uiStyle = value;
- UpdateUIStyle();
- UIStyleChanged?.Invoke(this, EventArgs.Empty);
- }
- }
- /// <summary>
- /// Gets or sets a value indicating that the BackColor property must be used to draw the background area.
- /// </summary>
- /// <remarks>
- /// By default, the background area is drawn using the color defined in the current <b>UIStyle</b>.
- /// </remarks>
- [DefaultValue(false)]
- public bool UseBackColor
- {
- get { return useBackColor; }
- set
- {
- useBackColor = value;
- UpdateUIStyle();
- }
- }
- /// <summary>
- /// Gets the preview window's toolbar.
- /// </summary>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public ToolStrip ToolBar
- {
- get { return toolStrip; }
- }
- /// <summary>
- /// Gets the preview window's statusbar.
- /// </summary>
- [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public StatusStrip StatusBar
- {
- get { return statusStrip; }
- }
- /// <summary>
- /// Gets or sets the initial directory that is displayed by a save file dialog.
- /// </summary>
- public string SaveInitialDirectory
- {
- get { return saveInitialDirectory; }
- set { saveInitialDirectory = value; }
- }
- internal float DefaultZoom
- {
- get { return defaultZoom; }
- }
- internal PreviewTab CurrentPreview
- {
- get { return currentPreview; }
- }
- private bool IsPreviewEmpty
- {
- get { return CurrentPreview == null || CurrentPreview.Disabled; }
- }
- #endregion
- #region Private Methods
- private void CreateOpenList()
- {
- var openLocal = new ToolStripMenuItem(Res.Get("Preview,OpenLocal"));
- openLocal.Image = this.GetImage(1);
- openLocal.Font = DrawUtils.DefaultFont;
- openLocal.Click += btnOpenLocal_Click;
- var openViaCloud = new ToolStripMenuItem(Res.Get("Preview,OpenViaCloud"));
- openViaCloud.Image = this.GetImage(261);
- openViaCloud.Font = DrawUtils.DefaultFont;
- openViaCloud.Click += btnOpenViaCloud_Click;
-
- btnOpen.DropDownItems.Clear();
- btnOpen.DropDownItems.AddRange(new ToolStripItem[] { openLocal, openViaCloud });
- }
- private void CreateSaveList()
- {
- var saveLocal = new ToolStripMenuItem(Res.Get("Preview,SaveLocal"));
- saveLocal.Font = DrawUtils.DefaultFont;
- saveLocal.Click += btnSaveLocal_Click;
- var saveToCloud = new ToolStripMenuItem(Res.Get("Preview,SaveToCloud"));
- saveToCloud.Image = this.GetImage(262);
- saveToCloud.Font = DrawUtils.DefaultFont;
- saveToCloud.Click += btnSaveToCloud_Click;
- var savePrepared = new ToolStripMenuItem(Res.Get("Preview,SaveNative"));
- savePrepared.Font = DrawUtils.DefaultFont;
- savePrepared.DropDownItems.AddRange(new ToolStripItem[] { saveLocal, saveToCloud });
- btnSave.DropDownItems.Clear();
- btnSave.DropDownItems.Add(savePrepared);
- CreateExportList(btnSave, Export_Click);
- CreateCloudList(btnSave, SaveToCloud_Click);
- //CreateMessengersList(btnSave, SendViaMessenger_Click);
- }
- private void CreateItems(ExportsOptions.ExportsTreeNode root, ToolStripDropDownItem button, EventHandler handler)
- {
- foreach (var node in root.Nodes)
- {
- if (node.IsCategory)
- {
- var categoryItem = createButtonItem(node);
- CreateItems(node, categoryItem, handler);
- if (categoryItem.DropDownItems.Count > 0)
- button.DropDownItems.Add(categoryItem);
- }
- else if (node.ExportType != null)
- {
- bool enabled = node.Enabled;
- if (node.IsExport)
- {
- if (Enum.TryParse<PreviewExports>(node.Tag.Object.Name, out var res))
- enabled = (Exports & res) != 0;
- }
- else if (node.IsCloud)
- {
- if (Enum.TryParse<PreviewClouds>(node.Name, out var res))
- enabled = (Clouds & res) != 0;
- }
- /*else if (node.IsMessenger)
- {
- if (Enum.TryParse<PreviewMessengers>(node.Name, out var res))
- enabled = (Messengers & res) != 0;
- }*/
- if (enabled)
- {
- var item = createButtonItem(node);
- item.Click += handler;
- button.DropDownItems.Add(item);
- }
- }
- }
- }
- private ToolStripMenuItem createButtonItem(ExportsOptions.ExportsTreeNode node)
- {
- var item = new ToolStripMenuItem(node.ToString() + (node.IsCategory ? "" : "..."));
- item.Tag = node.Tag;
- item.Name = node.Name;
- item.Image = node.Image ?? this.GetImage(node.ImageIndex);
- item.Font = DrawUtils.DefaultFont;
- return item;
- }
- private void CreateExportList(ToolStripDropDownItem button, EventHandler handler)
- {
- var options = ExportsOptions.GetInstance();
- CreateItems(options.ExportsMenu, button, handler);
- }
- private void CreateCloudList(ToolStripDropDownItem button, EventHandler handler)
- {
- var options = ExportsOptions.GetInstance();
- var categoryItem = createButtonItem(options.CloudMenu);
- CreateItems(options.CloudMenu, categoryItem, handler);
- if (categoryItem.DropDownItems.Count > 0)
- {
- button.DropDownItems.Add(new ToolStripSeparator());
- button.DropDownItems.Add(categoryItem);
- }
- }
- private void CreateMessengersList(ToolStripDropDownItem button, EventHandler handler)
- {
- var options = ExportsOptions.GetInstance();
- var categoryItem = createButtonItem(options.MessengerMenu);
- CreateItems(options.MessengerMenu, categoryItem, handler);
- if (categoryItem.DropDownItems.Count > 0)
- {
- button.DropDownItems.Add(new ToolStripSeparator());
- button.DropDownItems.Add(categoryItem);
- }
- }
- private void UpdateButtons()
- {
- btnPrint.Available = (Buttons & PreviewButtons.Print) != 0;
- btnOpen.Available = (Buttons & PreviewButtons.Open) != 0;
- btnSave.Available = (Buttons & PreviewButtons.Save) != 0;
- btnDesign.Available = (Buttons & PreviewButtons.Design) != 0;
- btnEmail.Available = (Buttons & PreviewButtons.Email) != 0 && !Config.EmailSettings.UseMAPI;
- btnFind.Available = (Buttons & PreviewButtons.Find) != 0;
- btnOutline.Available = (Buttons & PreviewButtons.Outline) != 0;
- btnPageSetup.Available = (Buttons & PreviewButtons.PageSetup) != 0;
- btnEdit.Available = (Buttons & PreviewButtons.Edit) != 0;
- btnWatermark.Available = (Buttons & PreviewButtons.Watermark) != 0;
- btnFirst.Available = (Buttons & PreviewButtons.Navigator) != 0;
- btnPrior.Available = (Buttons & PreviewButtons.Navigator) != 0;
- tbPageNo.Available = (Buttons & PreviewButtons.Navigator) != 0;
- lblTotalPages.Available = (Buttons & PreviewButtons.Navigator) != 0;
- btnNext.Available = (Buttons & PreviewButtons.Navigator) != 0;
- btnLast.Available = (Buttons & PreviewButtons.Navigator) != 0;
- btnClose.Available = (Buttons & PreviewButtons.Close) != 0;
- }
- private List<PreparedPages> GetPageOfTabs()
- {
- List<PreparedPages> list = new List<PreparedPages>();
- foreach (var tab in tabControl.Tabs)
- {
- if (tab is PreviewTab)
- list.Add((tab as PreviewTab).PreparedPages);
- }
- return list;
- }
- private void Export_Click(object sender, EventArgs e)
- {
- if (IsPreviewEmpty)
- return;
- ObjectInfo info = (sender as ToolStripMenuItem).Tag as ObjectInfo;
- if (info == null)
- Save();
- else
- {
- ExportBase export = Activator.CreateInstance(info.Object) as ExportBase;
- export.CurPage = CurrentPreview.PageNo;
- export.AllowSaveSettings = true;
- export.ShowProgress = true;
- try
- {
- export.Export(Report, GetPageOfTabs());
- }
- #if !DEBUG
- catch (Exception ex)
- {
- using (ExceptionForm form = new ExceptionForm(ex))
- {
- form.ShowDialog();
- }
- }
- #endif
- finally
- {
- }
- }
- }
- private async void Design()
- {
- if (Report == null)
- return;
- using (Report designedReport = new Report())
- {
- designedReport.FileName = Report.FileName;
- if (!String.IsNullOrEmpty(Report.FileName))
- designedReport.Load(designedReport.FileName);
- else
- using (MemoryStream repStream = new MemoryStream())
- {
- Report.Save(repStream);
- repStream.Position = 0;
- designedReport.Load(repStream);
- }
- Report.Dictionary.ReRegisterData(designedReport.Dictionary);
- #if AVALONIA
- if (await designedReport.DesignAsync())
- #else
- if (designedReport.Design())
- #endif
- {
- Report.PreparedPages.Clear();
- Report.PreparedPages.ClearPageCache();
- try
- {
- Report.LoadFromString(designedReport.SaveToString());
- }
- catch (Exception ex)
- {
- FRMessageBox.Error(ex.Message);
- }
- if (CurrentPreview != null)
- {
- Report.Preview = CurrentPreview.Preview;
- Report.Show();
- }
- }
- }
- }
- private void SaveToCloud_Click(object sender, EventArgs e)
- {
- if (IsPreviewEmpty)
- {
- return;
- }
- ObjectInfo info = (sender as ToolStripMenuItem).Tag as ObjectInfo;
- if (info != null)
- {
- CloudStorageClient client = Activator.CreateInstance(info.Object) as CloudStorageClient;
- if (client is FtpStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("FtpServer").FindItem("StorageSettings");
- string server = xi.GetProp("FtpServer");
- string username = xi.GetProp("FtpUsername");
- FtpStorageClientForm form = new FtpStorageClientForm(server, username, "", Report);
- form.ShowDialog();
- }
- else if (client is DropboxStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("DropboxCloud").FindItem("StorageSettings");
- string accessToken = xi.GetProp("AccessToken");
- if (String.IsNullOrEmpty(accessToken))
- {
- ApplicationInfoForm appInfoDialog = new ApplicationInfoForm();
- appInfoDialog.ShowDialog();
- accessToken = appInfoDialog.AccessToken;
- }
- DropboxStorageClientForm form = new DropboxStorageClientForm(accessToken, Report);
- form.ShowDialog();
- }
- else if (client is FastCloudStorageClient)
- {
- FastCloudStorageClientSimpleForm form = new FastCloudStorageClientSimpleForm(Report);
- form.ShowDialog();
- }
- #if !AVALONIA
- else if (client is BoxStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("BoxCloud").FindItem("StorageSettings");
- string id = xi.GetProp("ClientId");
- string secret = xi.GetProp("ClientSecret");
- DialogResult clientInfoDialogDialogResult = DialogResult.OK;
- if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(secret))
- {
- Box.ClientInfoForm clientInfoDialog = new Box.ClientInfoForm();
- clientInfoDialog.ShowDialog();
- id = clientInfoDialog.Id;
- secret = clientInfoDialog.Secret;
- clientInfoDialogDialogResult = clientInfoDialog.DialogResult;
- }
- if (clientInfoDialogDialogResult == DialogResult.OK)
- {
- BoxStorageClientForm form = new BoxStorageClientForm(new SkyDrive.ClientInfo("", id, secret), Report);
- form.ShowDialog();
- }
- }
- else if (client is GoogleDriveStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("GoogleDriveCloud").FindItem("StorageSettings");
- string id = xi.GetProp("ClientId");
- string secret = xi.GetProp("ClientSecret");
- if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(secret))
- {
- GoogleDrive.ClientInfoForm clientInfoDialog = new GoogleDrive.ClientInfoForm();
- clientInfoDialog.ShowDialog();
- id = clientInfoDialog.Id;
- secret = clientInfoDialog.Secret;
- }
- GoogleDriveStorageClientForm form = new GoogleDriveStorageClientForm(new SkyDrive.ClientInfo("", id, secret), Report);
- form.ShowDialog();
- }
- else if (client is SkyDriveStorageClient)
- {
- XmlItem xi = Config.Root.FindItem("SkyDriveCloud").FindItem("StorageSettings");
- string id = xi.GetProp("ClientId");
- string secret = xi.GetProp("ClientSecret");
- if (String.IsNullOrEmpty(id) || String.IsNullOrEmpty(secret))
- {
- SkyDrive.ClientInfoForm appInfoDialog = new SkyDrive.ClientInfoForm();
- appInfoDialog.ShowDialog();
- id = appInfoDialog.Id;
- secret = appInfoDialog.Secret;
- }
- SkyDriveStorageClientForm form = new SkyDriveStorageClientForm(new SkyDrive.ClientInfo("", id, secret), Report);
- form.ShowDialog();
- }
- #endif
- else if (client is S3StorageClient)
- {
- XmlItem xi = Config.Root.FindItem("S3").FindItem("StorageSettings");
- string accessKeyId = xi.GetProp("AccessKeyId");
- string secretAccessKey = xi.GetProp("SecretAccessKey");
- string region = xi.GetProp("Region");
- string host = xi.GetProp("Host");
- Cloud.StorageClient.S3.ClientInfoForm appInfoDialog = new Cloud.StorageClient.S3.ClientInfoForm();
- appInfoDialog.AccessKeyId = accessKeyId;
- appInfoDialog.SecretAccessKey = secretAccessKey;
- appInfoDialog.Region = region;
- appInfoDialog.Host = host;
- if (appInfoDialog.ShowDialog() == DialogResult.OK)
- {
- accessKeyId = appInfoDialog.AccessKeyId;
- secretAccessKey = appInfoDialog.SecretAccessKey;
- region = appInfoDialog.Region;
- host = appInfoDialog.Host;
- }
- else
- return;
- S3ClientForm form = new S3ClientForm(accessKeyId, secretAccessKey, region, host, Report);
- form.Client.AfterUpload += PreviewControl_AfterUpload;
- form.Client.BeforeUpload += Client_BeforeUpload;
- form.ShowDialog();
- }
- }
- }
- private void Client_BeforeUpload(object sender, EventArgs e)
- {
- ShowPerformance(Res.Get("Preview,Uploading"));
- uploadTimer.Start();
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (lblPerformance.Text.Contains("..."))
- lblPerformance.Text = lblPerformance.Text.Replace("...", "");
- else
- lblPerformance.Text += ".";
- }
- private void PreviewControl_AfterUpload(object sender, EventArgs e)
- {
- ShowPerformance(Res.Get("Preview,UploadDone"));
- }
- private void tabControl1_TabClosed(object sender, EventArgs e)
- {
- DeleteTab(sender as PreviewTab);
- }
- private void tabControl1_TabChanged(object sender, EventArgs e)
- {
- if (locked)
- return;
- currentPreview = tabControl.SelectedTab as PreviewTab;
- if (currentPreview != null && !currentPreview.Fake)
- {
- UpdateOutline();
- UpdateZoom(currentPreview.Zoom);
- UpdatePageNumbers(currentPreview.PageNo, currentPreview.PageCount);
- }
- }
- private void tabControl_Resize(object sender, EventArgs e)
- {
- UpdateDocumentLayout();
- }
- private bool CanDisposeTabReport(PreviewTab tab)
- {
- if (tab == null || tab.Report == null)
- return false;
- // if the preview is owned by Report, do not dispose
- if (report == tab.Report)
- return false;
- // check if the same Report is used in other tabs
- foreach (PreviewTab t in documents)
- {
- if (t != tab && t.Report == tab.Report)
- {
- return false;
- }
- }
- return true;
- }
- private void Localize()
- {
- MyRes res = new MyRes("Preview");
- btnPrint.Text = res.Get("PrintText");
- btnPrint.ToolTipText = res.Get("Print");
- btnOpen.ToolTipText = res.Get("Open");
- btnOpen.Text = res.Get("OpenText");
- btnDesign.Text = res.Get("DesignText");
- btnDesign.ToolTipText = res.Get("Design");
- btnSave.ToolTipText = res.Get("Save");
- btnSave.Text = res.Get("SaveText");
- btnEmail.ToolTipText = res.Get("Email");
- btnFind.ToolTipText = res.Get("Find");
- btnOutline.ToolTipText = res.Get("Outline");
- btnPageSetup.ToolTipText = res.Get("PageSetup");
- btnEdit.ToolTipText = res.Get("Edit");
- btnWatermark.ToolTipText = res.Get("Watermark");
- btnFirst.ToolTipText = res.Get("First");
- btnPrior.ToolTipText = res.Get("Prior");
- btnNext.ToolTipText = res.Get("Next");
- lblTotalPages.Text = String.Format(Res.Get("Misc,ofM"), 1);
- btnLast.ToolTipText = res.Get("Last");
- btnClose.Text = Res.Get("Buttons,Close");
- }
- private void Init()
- {
- outlineControl.SetPreview(this);
- uploadTimer = new Timer();
- uploadTimer.Interval = 1500;
- uploadTimer.Tick += Timer_Tick;
- pageBorderColor = Color.FromArgb(80, 80, 80);
- activePageBorderColor = Color.FromArgb(255, 199, 60);
- pageOffset = new Point(10, 10);
- defaultZoom = 1;
- buttons = PreviewButtons.All;
- exports = Config.PreviewSettings.Exports;
- clouds = Config.PreviewSettings.Clouds;
- RestoreState();
- UpdateButtons();
- zoomControl.ZoomValue = Zoom;
- }
- public void RestoreState()
- {
- var storage = new ControlStorageService(this, "Preview");
- defaultZoom = storage.GetFloat("Zoom", 1);
- splitContainer1.SplitterDistance = storage.GetDip("OutlineWidth", 250, 50, 800);
- }
- public void SaveState()
- {
- Clear();
- outlineControl.Hide();
- var storage = new ControlStorageService(this, "Preview");
- storage.SetFloat("Zoom", Zoom);
- storage.SetDip("OutlineWidth", splitContainer1.SplitterDistance);
- }
- private void UpdateDocumentLayout()
- {
- foreach (PreviewTab tab in documents)
- {
- tab.UpdatePages();
- }
- }
- private void UpdateUIStyle()
- {
- toolStrip.Renderer = statusStrip.Renderer = UIStyleUtils.GetToolStripRenderer(UIStyle);
- zoomControl.UIStyle = UIStyle;
- var table = UIStyleUtils.GetColorTable(UIStyle);
- if (!UseBackColor)
- BackColor = table.Workspace.WorkspaceBackColor;
- tabControl.Style = table.Workspace;
- foreach (PreviewTab tab in documents)
- {
- tab.Style = UIStyle;
- }
- }
- private void UpdateOutline()
- {
- outlineControl.PreparedPages = currentPreview.PreparedPages;
- OutlineVisible = !currentPreview.PreparedPages.Outline.IsEmpty;
- }
- private void AddFakeTab()
- {
- PreviewTab tab = new PreviewTab(this, null, "", null);
- tab.Fake = true;
- documents.Add(tab);
- tab.AddToTabControl(tabControl);
- }
- private void UpdateTabsVisible()
- {
- tabControl.ShowTabs = documents.Count > 1 && !documents[0].Fake;
- }
- private PreviewTab FindTab(string text)
- {
- foreach (PreviewTab tab in documents)
- {
- if (tab.Text == text)
- return tab;
- }
- return null;
- }
- private PreviewTab FindTabByHyperlinkValue(string value)
- {
- foreach (PreviewTab tab in documents)
- {
- if (tab.HyperlinkValue == value)
- return tab;
- }
- return null;
- }
- #endregion
- #region Public Methods
- internal void SetReport(Report report)
- {
- this.report = report;
- }
- internal void UpdatePageNumbers(int pageNo, int totalPages)
- {
- lblStatus.Text = String.Format(Res.Get("Misc,PageNofM"), pageNo, totalPages);
- tbPageNo.Text = pageNo.ToString();
- lblTotalPages.Text = String.Format(Res.Get("Misc,ofM"), totalPages);
- if (PageChanged != null)
- PageChanged(this, EventArgs.Empty);
- }
- internal void UpdateZoom(float zoom)
- {
- updatingZoom = true;
- zoomControl.ZoomValue = zoom;
- updatingZoom = false;
- }
- internal void UpdateUrl(string url)
- {
- lblUrl.Text = url;
- }
- internal void ShowPerformance(string text)
- {
- uploadTimer.Stop();
- lblPerformance.Text = text;
- }
- internal void DoClick()
- {
- OnClick(EventArgs.Empty);
- }
- // Clears all tabs except the first one. This method is used in the report.Prepare.
- // It is needed to avoid flickering when using stand-alone PreviewControl.
- // When report is prepared and ShowPrepared method is called, the "fake" tab will
- // be replaced with the new tab.
- internal void ClearTabsExceptFirst()
- {
- while (documents.Count > 1)
- {
- DeleteTab(documents[documents.Count - 1]);
- }
- if (documents.Count == 1)
- documents[0].Fake = true;
- }
- internal PreviewTab AddPreviewTab(Report report, string text, Hyperlink hyperlink, bool setActive)
- {
- PreviewTab tab = new PreviewTab(this, report, text, hyperlink);
- documents.Add(tab);
- if (documents.Count == 2 && documents[0].Fake)
- DeleteTab(documents[0]);
- var rescale = tabControl.Dpi() / (float)tab.Dpi();
- tab.AddToTabControl(tabControl);
- tab.Scale(new SizeF(rescale, rescale));
- tab.UnlockLayout();
- UpdateTabsVisible();
- tab.UpdatePages();
- if (setActive)
- tabControl.SelectedTab = tab;
- else
- tabControl.Refresh();
- return tab;
- }
- /// <summary>
- /// Adds a new report tab to the preview control.
- /// </summary>
- /// <param name="report">The <b>Report</b> object that contains the prepared report.</param>
- /// <param name="text">The title for the new tab.</param>
- /// <remarks>
- /// Prepare the report using its <b>Prepare</b> method before you pass it to the <b>report</b> parameter.
- /// </remarks>
- public void AddTab(Report report, string text)
- {
- if (this.report == null)
- SetReport(report);
- AddPreviewTab(report, text, null, true);
- }
- /// <summary>
- /// Switches to the tab with specified text.
- /// </summary>
- /// <param name="text">Text of the tab.</param>
- /// <returns><b>true</b> if the tab with specified text exists, or <b>false</b> if there is no such tab.</returns>
- public bool SwitchToTab(string text)
- {
- PreviewTab tab = FindTab(text);
- if (tab != null)
- {
- tabControl.SelectedTab = tab;
- return true;
- }
- return false;
- }
- internal bool SwitchToTab(Hyperlink hyperlink)
- {
- PreviewTab tab = FindTabByHyperlinkValue(hyperlink.Value);
- if (tab != null)
- {
- tabControl.SelectedTab = tab;
- return true;
- }
- return false;
- }
- /// <summary>
- /// Deletes the report tab with specified text.
- /// </summary>
- /// <param name="text">The text of the tab.</param>
- public void DeleteTab(string text)
- {
- PreviewTab tab = FindTab(text);
- if (tab != null)
- DeleteTab(tab);
- }
- /// <summary>
- /// Checks if the tab with specified text exists.
- /// </summary>
- /// <param name="text">The text of the tab.</param>
- /// <returns><b>true</b> if the tab exists.</returns>
- public bool TabExists(string text)
- {
- return FindTab(text) != null;
- }
- internal void DeleteTab(PreviewTab tab)
- {
- if (CanDisposeTabReport(tab))
- tab.Report.Dispose();
- documents.Remove(tab);
- tabControl.Tabs.Remove(tab);
- tab.Dispose();
- uploadTimer.Dispose();
- UpdateTabsVisible();
- }
- /// <summary>
- /// Displays the text in the status bar.
- /// </summary>
- /// <param name="text">Text to display.</param>
- public void ShowStatus(string text)
- {
- int tick = Environment.TickCount;
- if (tick - lastTick < 50 && !string.IsNullOrEmpty(text))
- return;
- lastTick = tick;
- lblStatus.Text = text;
- statusStrip.Refresh();
- Application.DoEvents();
- }
- internal void Lock()
- {
- locked = true;
- }
- internal void Unlock()
- {
- locked = false;
- }
- /// <summary>
- /// Sets the focus to the preview control.
- /// </summary>
- public new void Focus()
- {
- if (currentPreview != null)
- currentPreview.Focus();
- }
- /// <summary>
- /// Updates the control appearance and layout on dpi change.
- /// </summary>
- public void UpdateDpiDependencies()
- {
- Font = this.LogicalToDevice(DrawUtils.DefaultFont);
- tabControl.Font = Font;
- toolStrip.Font = Font;
- statusStrip.Font = Font;
- tbPageNo.Font = Font;
- outlineControl.Font = Font;
- outlineControl.UpdateDpiDependencies();
- toolStrip.Height = this.LogicalToDevice(26);
- statusStrip.Height = this.LogicalToDevice(26);
- statusStrip.Padding = new Padding(6, 0, 0, 0);
- tabControl.UpdateDpiDependencies();
- btnPrint.Image = this.GetImage(195);
- btnOpen.Image = this.GetImage(1);
- btnSave.Image = this.GetImage(2);
- btnDesign.Image = this.GetImage(68);
- btnEmail.Image = this.GetImage(200);
- btnFind.Image = this.GetImage(181);
- btnOutline.Image = this.GetImage(196);
- btnPageSetup.Image = this.GetImage(13);
- btnEdit.Image = this.GetImage(198);
- btnWatermark.Image = this.GetImage(194);
- btnFirst.Image = this.GetImage(185);
- btnPrior.Image = this.GetImage(186);
- btnNext.Image = this.GetImage(187);
- btnLast.Image = this.GetImage(188);
- tbPageNo.Size = this.LogicalToDevice(new Size(40, 21));
- lblStatus.Size = this.LogicalToDevice(new Size(280, 21));
- zoomControl.Size = this.LogicalToDevice(new Size(280, 26));
- CreateOpenList();
- CreateSaveList();
- UpdateDocumentLayout();
- }
- #endregion
- #region Async Prepare
- /// <summary>
- /// Gets the value indicating that async report is running.
- /// </summary>
- /// <remarks>
- /// This value can be used to abort the report when you close the form that contains the report preview control.
- /// </remarks>
- public bool IsAsyncReportRunning { get; private set; }
- // we have to call this separately before AsyncReportStart to set this flag (case: clicking reports in the reports list too fast leads to NRE)
- internal void SetAsyncReportRunning() => IsAsyncReportRunning = true;
- internal void AsyncReportStart()
- {
- Report.PreparedPages.PageAdded += AsyncReportPageAdded;
- // update buttons
- btnClose.Text = Res.Get("Buttons,Cancel");
- EnableButtons(false);
- lblStatus.Text = "";
- uploadTimer.Stop();
- lblPerformance.Text = "";
- tbPageNo.Text = "0";
- }
- private int lastTick;
- private void AsyncReportPageAdded(object sender, EventArgs e)
- {
- int tick = Environment.TickCount;
- if (tick - lastTick < 50 && Report.PreparedPages.Count > 100)
- return;
- Application.DoEvents();
- if (Report.Engine.FinalPass)
- {
- OutlineVisible = !Report.PreparedPages.Outline.IsEmpty;
- CurrentPreview.UpdatePages();
- }
- lastTick = Environment.TickCount;
- }
- internal void AsyncReportFinish()
- {
- IsAsyncReportRunning = false;
- Report.PreparedPages.PageAdded -= AsyncReportPageAdded;
- Report.PreparedPages.ClearPageCache();
- UpdateOutline();
- CurrentPreview.UpdatePages();
- // update buttons
- btnClose.Text = Res.Get("Buttons,Close");
- EnableButtons(true);
- }
- private void EnableButtons(bool enable)
- {
- foreach (ToolStripItem button in ToolBar.Items)
- {
- if (button == btnFirst)
- break;
- button.Enabled = enable;
- }
- }
- #endregion
- #region Event handlers
- private void btnDesign_Click(object sender, EventArgs e)
- {
- Design();
- }
- private void btnPrint_Click(object sender, EventArgs e)
- {
- Print();
- }
- private void btnOpenLocal_Click(object sender, EventArgs e)
- {
- Load();
- }
- private void btnOpenViaCloud_Click(object sender, EventArgs e)
- {
- var stream = CloudCommands.LoadPreviewFile();
- if (stream != null)
- Load(stream);
- }
- private void btnSaveLocal_Click(object sender, EventArgs e)
- {
- Save();
- }
- private void btnSaveToCloud_Click(object sender, EventArgs e)
- {
- CloudCommands.SavePreviewFile(currentPreview.Report);
- }
- private void btnEmail_Click(object sender, EventArgs e)
- {
- SendEmail();
- }
- private void btnFind_Click(object sender, EventArgs e)
- {
- Find();
- }
- private void btnZoom100_Click(object sender, EventArgs e)
- {
- Zoom = 1;
- }
- private void btnZoomWholePage_Click(object sender, EventArgs e)
- {
- ZoomWholePage();
- }
- private void btnZoomPageWidth_Click(object sender, EventArgs e)
- {
- ZoomPageWidth();
- }
- private void slider_ValueChanged(object sender, EventArgs e)
- {
- if (updatingZoom || CurrentPreview == null)
- return;
- Zoom = zoomControl.ZoomValue;
- CurrentPreview.Focus();
- }
- private void btnEdit_Click(object sender, EventArgs e)
- {
- EditPage();
- }
- private void btnFirst_Click(object sender, EventArgs e)
- {
- First();
- }
- private void btnPrior_Click(object sender, EventArgs e)
- {
- Prior();
- }
- private void btnNext_Click(object sender, EventArgs e)
- {
- Next();
- }
- private void btnLast_Click(object sender, EventArgs e)
- {
- Last();
- }
- private void cbxPageNo_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- try
- {
- PageNo = int.Parse(tbPageNo.Text);
- }
- catch
- {
- PageNo = PageCount;
- }
- CurrentPreview.Focus();
- }
- }
- private void tbPageNo_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar != '\b' && (e.KeyChar < '0' || e.KeyChar > '9'))
- e.Handled = true;
- }
- private void btnWatermark_Click(object sender, EventArgs e)
- {
- EditWatermark();
- }
- private void btnOutline_Click(object sender, EventArgs e)
- {
- OutlineVisible = btnOutline.Checked;
- }
- private void btnPageSetup_Click(object sender, EventArgs e)
- {
- PageSetup();
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- if (IsAsyncReportRunning)
- {
- Report.Abort();
- return;
- }
- #if WPF
- System.Windows.Window.GetWindow(control)?.Close();
- #elif AVALONIA
- (Avalonia.Controls.TopLevel.GetTopLevel(control) as Avalonia.Controls.Window)?.Close();
- #else
- if (FindForm() != null)
- FindForm().Close();
- #endif
- }
- #endregion
- #region Preview commands
- /// <summary>
- /// Prints the current report.
- /// </summary>
- /// <returns><b>true</b> if report was printed; <b>false</b> if user cancels the "Print" dialog.</returns>
- public bool Print()
- {
- if (CurrentPreview == null)
- return false;
- return CurrentPreview.Print();
- }
- /// <summary>
- /// Saves the current report to a .fpx file using the "Save FIle" dialog.
- /// </summary>
- public void Save()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Save();
- }
- /// <summary>
- /// Saves the current report to a specified .fpx file.
- /// </summary>
- public void Save(string fileName)
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Save(fileName);
- }
- /// <summary>
- /// Saves the current report to a stream.
- /// </summary>
- public void Save(Stream stream)
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Save(stream);
- }
- private bool PreLoad()
- {
- if (CurrentPreview == null)
- return false;
- if (documents.Count == 1 && documents[0].Fake)
- {
- Report report = new Report();
- report.SetPreparedPages(new PreparedPages(report));
- AddTab(report, "");
- }
- return true;
- }
- private void PostLoad()
- {
- UpdateOutline();
- }
- /// <summary>
- /// Loads the report from a .fpx file using the "Open File" dialog.
- /// </summary>
- public new void Load()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Load();
- UpdateOutline();
- }
- /// <summary>
- /// Loads the report from a specified .fpx file.
- /// </summary>
- public new void Load(string fileName)
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Load(fileName);
- UpdateOutline();
- }
- /// <summary>
- /// Load the report from a stream.
- /// </summary>
- /// <param name="stream">The stream to load from.</param>
- public new void Load(Stream stream)
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Load(stream);
- UpdateOutline();
- }
- /// <summary>
- /// Sends an email.
- /// </summary>
- public void SendEmail()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.SendEmail();
- }
- /// <summary>
- /// Finds the text in the current report using the "Find Text" dialog.
- /// </summary>
- public void Find()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Find();
- }
- /// <summary>
- /// Finds the specified text in the current report.
- /// </summary>
- /// <param name="text">Text to find.</param>
- /// <param name="matchCase">A value indicating whether the search is case-sensitive.</param>
- /// <param name="wholeWord">A value indicating whether the search matches whole words only.</param>
- /// <returns><b>true</b> if text found.</returns>
- public bool Find(string text, bool matchCase, bool wholeWord)
- {
- if (CurrentPreview == null)
- return false;
- return CurrentPreview.Find(text, matchCase, wholeWord);
- }
- /// <summary>
- /// Finds the next occurence of text specified in the <b>Find</b> method.
- /// </summary>
- /// <returns><b>true</b> if text found.</returns>
- public bool FindNext()
- {
- if (CurrentPreview == null)
- return false;
- return CurrentPreview.FindNext();
- }
- /// <summary>
- /// Navigates to the first page.
- /// </summary>
- public void First()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.First();
- }
- /// <summary>
- /// Navigates to the previuos page.
- /// </summary>
- public void Prior()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Prior();
- }
- /// <summary>
- /// Navigates to the next page.
- /// </summary>
- public void Next()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Next();
- }
- /// <summary>
- /// Navigates to the last page.
- /// </summary>
- public void Last()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.Last();
- }
- /// <summary>
- /// Gets or sets the current page number.
- /// </summary>
- /// <remarks>
- /// This value is 1-based.
- /// </remarks>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public int PageNo
- {
- get
- {
- if (CurrentPreview == null)
- return 1;
- return CurrentPreview.PageNo;
- }
- set
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.PageNo = value;
- }
- }
- /// <summary>
- /// Gets the pages count in the current report.
- /// </summary>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public int PageCount
- {
- get
- {
- if (CurrentPreview == null)
- return 0;
- return CurrentPreview.PageCount;
- }
- }
- /// <summary>
- /// Gets or sets the zoom factor.
- /// </summary>
- /// <remarks>
- /// <b>1</b> corresponds to 100% zoom.
- /// </remarks>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public float Zoom
- {
- get
- {
- if (CurrentPreview == null)
- return 1;
- return CurrentPreview.Zoom;
- }
- set
- {
- if (CurrentPreview != null)
- {
- CurrentPreview.Zoom = value;
- updatingZoom = true;
- zoomControl.ZoomValue = value;
- updatingZoom = false;
- }
- }
- }
- /// <summary>
- /// Zooms in.
- /// </summary>
- public void ZoomIn()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.ZoomIn();
- }
- /// <summary>
- /// Zooms out.
- /// </summary>
- public void ZoomOut()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.ZoomOut();
- }
- /// <summary>
- /// Zooms to fit the page width.
- /// </summary>
- public void ZoomPageWidth()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.ZoomPageWidth();
- }
- /// <summary>
- /// Zooms to fit the whole page.
- /// </summary>
- public void ZoomWholePage()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.ZoomWholePage();
- }
- /// <summary>
- /// Edits the current page in the designer.
- /// </summary>
- public void EditPage()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.EditPage();
- }
- /// <summary>
- /// Edits the watermark.
- /// </summary>
- public void EditWatermark()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.EditWatermark();
- }
- /// <summary>
- /// Edits the page settings.
- /// </summary>
- public void PageSetup()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.PageSetup();
- }
- /// <summary>
- /// Navigates to the specified position inside a specified page.
- /// </summary>
- /// <param name="pageNo">The page number (1-based).</param>
- /// <param name="point">The position inside a page, in pixels.</param>
- public void PositionTo(int pageNo, PointF point)
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.PositionTo(pageNo, point);
- }
- /// <summary>
- /// Clears the preview.
- /// </summary>
- public void Clear()
- {
- while (documents.Count > 0)
- {
- DeleteTab(documents[0]);
- }
- lblStatus.Text = "";
- tbPageNo.Text = "";
- }
- /// <summary>
- /// Refresh the report.
- /// </summary>
- public void RefreshReport()
- {
- if (CurrentPreview == null)
- return;
- CurrentPreview.RefreshReport();
- }
- #endregion
- /// <summary>
- /// Initializes a new instance of the <see cref="PreviewControl"/> class.
- /// </summary>
- public PreviewControl()
- {
- // we need this to ensure that static constructor of the Report was called.
- Report report = new Report();
- report.Dispose();
- documents = new List<PreviewTab>();
- InitializeComponent();
- tabControl = new FRTabControl();
- tabControl.Parent = splitContainer1.Panel2;
- tabControl.ShowCaption = false;
- tabControl.TabOrientation = TabOrientation.Top;
- tabControl.Dock = DockStyle.Fill;
- tabControl.Name = "tabControl";
- tabControl.Resize += tabControl_Resize;
- tabControl.SelectedTabChanged += tabControl1_TabChanged;
- tabControl.TabClosed += tabControl1_TabClosed;
- zoomControl = new ToolStripZoomControl();
- zoomControl.ZoomPageWidthClick += btnZoomPageWidth_Click;
- zoomControl.ZoomWholePageClick += btnZoomWholePage_Click;
- zoomControl.Zoom100Click += btnZoom100_Click;
- zoomControl.ValueChanged += slider_ValueChanged;
- statusStrip.Items.Add(zoomControl);
- #if (WPF || AVALONIA)
- toolStrip.BorderThickness = new Padding(0);
- var shadow = toolStrip.SetShadow(DockStyle.Bottom);
- UIStyleChanged += (s, e) => shadow.Color = UIStyleUtils.GetColorTable(UIStyle).ToolStripBorder;
- #endif
- toolbarVisible = true;
- statusbarVisible = true;
- OutlineVisible = false;
- UIStyle = Config.UIStyle;
- Localize();
- Init();
- AddFakeTab();
- UpdateDpiDependencies();
- }
- }
- }
|