DocumentWorkspaceWindow.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Annotation.Measure;
  3. using PaintDotNet.SystemLayer;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Drawing;
  9. using System.Drawing.Imaging;
  10. using System.Reflection;
  11. using System.Threading;
  12. using System.Windows.Forms;
  13. namespace PaintDotNet
  14. {
  15. /// <summary>
  16. /// 抽出来在各种弹窗里面使用
  17. /// </summary>
  18. internal class DocumentWorkspaceWindow : DocumentView
  19. {
  20. private ZoomBasis zoomBasis;
  21. private ZoomBasis savedZb;
  22. private ScaleFactor savedSf;
  23. public TreeView oldDrawTreeView;
  24. protected override void OnSizeChanged(EventArgs e)
  25. {
  26. PerformLayout();
  27. base.OnSizeChanged(e);
  28. }
  29. protected override void OnLayout(LayoutEventArgs e)
  30. {
  31. if (this.zoomBasis == ZoomBasis.FitToWindow)
  32. {
  33. ZoomToWindow();
  34. // This bizarre ordering of setting PanelAutoScroll prevents some very weird layout/scroll-without-scrollbars stuff.
  35. PanelAutoScroll = true;
  36. PanelAutoScroll = false;
  37. }
  38. base.OnLayout(e);
  39. }
  40. protected override void OnResize(EventArgs e)
  41. {
  42. if (this.zoomBasis == ZoomBasis.FitToWindow)
  43. {
  44. PerformLayout();
  45. }
  46. base.OnResize(e);
  47. }
  48. public DocumentWorkspaceWindow(AppWorkspace appWorkspace)
  49. {
  50. this.AppWorkspaceTop = appWorkspace;
  51. this.InitToolsAndManager();
  52. this.RulersEnabled = false;
  53. this.rightDown = false;
  54. InitializeComponent();
  55. this.zoomBasis = ZoomBasis.FitToWindow;
  56. InitializeBottomEvent();
  57. this.MouseEvent_Del(null, null);
  58. }
  59. public DocumentWorkspaceWindow()
  60. {
  61. this.RulersEnabled = false;
  62. this.rightDown = false;
  63. InitializeComponent();
  64. this.zoomBasis = ZoomBasis.FitToWindow;
  65. InitializeBottomEvent();
  66. this.MouseEvent_Del(null, null);
  67. }
  68. protected override void OnUnitsChanged()
  69. {
  70. base.OnUnitsChanged();
  71. }
  72. private void InitializeComponent()
  73. {
  74. }
  75. protected override void Dispose(bool disposing)
  76. {
  77. base.Dispose(disposing);
  78. }
  79. public override void ZoomIn()
  80. {
  81. this.ZoomBasis = ZoomBasis.ScaleFactor;
  82. base.ZoomIn();
  83. }
  84. public override void ZoomIn(double factor)
  85. {
  86. this.ZoomBasis = ZoomBasis.ScaleFactor;
  87. base.ZoomIn(factor);
  88. }
  89. public override void ZoomOut()
  90. {
  91. this.ZoomBasis = ZoomBasis.ScaleFactor;
  92. base.ZoomOut();
  93. }
  94. public override void ZoomOut(double factor)
  95. {
  96. this.ZoomBasis = ZoomBasis.ScaleFactor;
  97. base.ZoomOut(factor);
  98. }
  99. public event EventHandler ZoomBasisChanging;
  100. protected virtual void OnZoomBasisChanging()
  101. {
  102. if (ZoomBasisChanging != null)
  103. {
  104. ZoomBasisChanging(this, EventArgs.Empty);
  105. }
  106. }
  107. public event EventHandler ZoomBasisChanged;
  108. protected virtual void OnZoomBasisChanged()
  109. {
  110. if (ZoomBasisChanged != null)
  111. {
  112. ZoomBasisChanged(this, EventArgs.Empty);
  113. }
  114. }
  115. public ZoomBasis ZoomBasis
  116. {
  117. get
  118. {
  119. return this.zoomBasis;
  120. }
  121. set
  122. {
  123. if (this.zoomBasis != value)
  124. {
  125. OnZoomBasisChanging();
  126. this.zoomBasis = value;
  127. switch (this.zoomBasis)
  128. {
  129. case ZoomBasis.FitToWindow:
  130. ZoomToWindow();
  131. // Enable PanelAutoScroll only long enough to recenter the view
  132. PanelAutoScroll = true;
  133. PanelAutoScroll = false;
  134. // this would be unset by the scalefactor changes in ZoomToWindow
  135. this.zoomBasis = ZoomBasis.FitToWindow;
  136. break;
  137. case ZoomBasis.ScaleFactor:
  138. PanelAutoScroll = true;
  139. break;
  140. default:
  141. throw new InvalidEnumArgumentException();
  142. }
  143. OnZoomBasisChanged();
  144. }
  145. }
  146. }
  147. protected override void HandleMouseWheel(Control sender, MouseEventArgs e)
  148. {
  149. if (Control.ModifierKeys == Keys.Control && !disableWheel)
  150. {
  151. double mouseDelta = (double)e.Delta / 120.0f;
  152. Rectangle visibleDocBoundsStart = this.VisibleDocumentBounds;
  153. System.Drawing.Point mouseDocPt = this.MouseToDocument(sender, new System.Drawing.Point(e.X, e.Y));
  154. RectangleF visibleDocDocRect1 = this.VisibleDocumentRectangleF;
  155. PointF mouseNPt = new PointF(
  156. (mouseDocPt.X - visibleDocDocRect1.X) / visibleDocDocRect1.Width,
  157. (mouseDocPt.Y - visibleDocDocRect1.Y) / visibleDocDocRect1.Height);
  158. Rectangle rc = this.PanelClientRectangle;
  159. int width = this.SurfaceScrollableWidth;
  160. int height = this.SurfaceScrollableHeight;
  161. //获取鼠标在图像中的坐标定位
  162. double originX = 0.5;
  163. double originY = 0.5;
  164. double ptxInDoc = mouseDocPt.X * this.ScaleRatio;
  165. double ptyInDoc = mouseDocPt.Y * this.ScaleRatio;
  166. if (rc.Width < width)
  167. {
  168. originX = (ptxInDoc + this.PanelScrollPosition.X - 0.0) / width;
  169. }
  170. if (rc.Height < height)
  171. {
  172. originY = (ptyInDoc + this.PanelScrollPosition.Y - 0.0) / height;
  173. }
  174. const double factor = 1.12;
  175. double mouseFactor = Math.Pow(factor, Math.Abs(mouseDelta));
  176. if (e.Delta > 0)
  177. {
  178. this.ZoomIn(mouseFactor);
  179. }
  180. else if (e.Delta < 0)
  181. {
  182. this.ZoomOut(mouseFactor);
  183. }
  184. RectangleF visibleDocDocRect2 = this.VisibleDocumentRectangleF;
  185. PointF scrollPt2 = new PointF(
  186. mouseDocPt.X - visibleDocDocRect2.Width * mouseNPt.X,
  187. mouseDocPt.Y - visibleDocDocRect2.Height * mouseNPt.Y);
  188. this.DocumentScrollPositionF = scrollPt2;
  189. int width2 = this.SurfaceScrollableWidth;
  190. int height2 = this.SurfaceScrollableHeight;
  191. if ((rc.Width < width2 || rc.Height < height2) && (rc.Width < width || rc.Height < height))
  192. {
  193. //根据鼠标在图像中的坐标重新定位放大后的图像
  194. this.PanelScrollPosition = new System.Drawing.Point(
  195. (int)(width2 * originX - ptxInDoc + 0),
  196. (int)(height2 * originY - ptyInDoc + 0));
  197. }
  198. else if (rc.Width < width2 || rc.Height < height2)
  199. {
  200. this.PanelScrollPosition = new System.Drawing.Point((int)(width2 - rc.Width) / 2 + 0, (int)(height2 - rc.Height) / 2 + 0);
  201. }
  202. else
  203. {
  204. this.PanelScrollPosition = new System.Drawing.Point((int)(width2 - rc.Width) / 2 + 0, (int)(height2 - rc.Height) / 2 + 0);
  205. }
  206. Rectangle visibleDocBoundsEnd = this.VisibleDocumentBounds;
  207. if (visibleDocBoundsEnd != visibleDocBoundsStart)
  208. {
  209. // Make sure the screen updates, otherwise it can get a little funky looking
  210. this.Update();
  211. }
  212. /*double mouseDelta = (double)e.Delta / 120.0f;
  213. Rectangle visibleDocBoundsStart = this.VisibleDocumentBounds;
  214. Point mouseDocPt = this.MouseToDocument(sender, new Point(e.X, e.Y));
  215. RectangleF visibleDocDocRect1 = this.VisibleDocumentRectangleF;
  216. PointF mouseNPt = new PointF(
  217. (mouseDocPt.X - visibleDocDocRect1.X) / visibleDocDocRect1.Width,
  218. (mouseDocPt.Y - visibleDocDocRect1.Y) / visibleDocDocRect1.Height);
  219. const double factor = 1.12;
  220. double mouseFactor = Math.Pow(factor, Math.Abs(mouseDelta));
  221. if (e.Delta > 0)
  222. {
  223. this.ZoomIn(mouseFactor);
  224. }
  225. else if (e.Delta < 0)
  226. {
  227. this.ZoomOut(mouseFactor);
  228. }
  229. RectangleF visibleDocDocRect2 = this.VisibleDocumentRectangleF;
  230. PointF scrollPt2 = new PointF(
  231. mouseDocPt.X - visibleDocDocRect2.Width * mouseNPt.X,
  232. mouseDocPt.Y - visibleDocDocRect2.Height * mouseNPt.Y);
  233. this.DocumentScrollPositionF = scrollPt2;
  234. Rectangle visibleDocBoundsEnd = this.VisibleDocumentBounds;
  235. if (visibleDocBoundsEnd != visibleDocBoundsStart)
  236. {
  237. // Make sure the screen updates, otherwise it can get a little funky looking
  238. this.Update();
  239. }*/
  240. }
  241. base.HandleMouseWheel(sender, e);
  242. }
  243. protected override void OnLoad(EventArgs e)
  244. {
  245. base.OnLoad(e);
  246. }
  247. public event EventHandler ActiveLayerChanged;
  248. protected void OnLayerChanged()
  249. {
  250. this.Focus();
  251. if (ActiveLayerChanged != null)
  252. {
  253. ActiveLayerChanged(this, EventArgs.Empty);
  254. }
  255. }
  256. /// <summary>
  257. /// 初始化底部按钮的各种事件
  258. /// </summary>
  259. private void InitializeBottomEvent()
  260. {
  261. /*//缩小按钮
  262. this.PanelBottom.zoomOutButton.Click += new EventHandler(ZoomOutButton_Click);
  263. //放大按钮
  264. this.PanelBottom.zoomInButton.Click += new EventHandler(zoomInButton_Click);*/
  265. }
  266. private void ZoomOutButton_Click(object sender, EventArgs e)
  267. {
  268. this.ZoomOut();
  269. }
  270. private void zoomInButton_Click(object sender, EventArgs e)
  271. {
  272. this.ZoomIn();
  273. }
  274. public event EventHandler ToolChanging;
  275. protected void OnToolChanging()
  276. {
  277. if (ToolChanging != null)
  278. {
  279. ToolChanging(this, EventArgs.Empty);
  280. }
  281. }
  282. public event EventHandler ToolChanged;
  283. protected void OnToolChanged()
  284. {
  285. if (ToolChanged != null)
  286. {
  287. ToolChanged(this, EventArgs.Empty);
  288. }
  289. }
  290. /// <summary>
  291. /// Updates any pertinent EXIF tags, such as "Creation Software", to be
  292. /// relevant or up-to-date.
  293. /// </summary>
  294. /// <param name="document"></param>
  295. private void UpdateExifTags(Document document)
  296. {
  297. PropertyItem pi = Exif.CreateAscii(ExifTagID.Software, PdnInfo.GetProductName(false));
  298. document.Metadata.ReplaceExifValues(ExifTagID.Software, new PropertyItem[1] { pi });
  299. }
  300. protected override void OnDocumentChanging(Document newDocument)
  301. {
  302. base.OnDocumentChanging(newDocument);
  303. this.savedZb = this.ZoomBasis;
  304. this.savedSf = ScaleFactor;
  305. if (newDocument != null)
  306. {
  307. UpdateExifTags(newDocument);
  308. }
  309. }
  310. protected override void OnDocumentChanged()
  311. {
  312. bool oldDirty = this.Document.Dirty;
  313. this.Document.Invalidate();
  314. this.Document.Dirty = oldDirty;
  315. this.ZoomBasis = this.savedZb;
  316. if (this.savedZb == ZoomBasis.ScaleFactor)
  317. {
  318. ScaleFactor = this.savedSf;
  319. }
  320. AutoScrollPosition = new Point(0, 0);
  321. base.OnDocumentChanged();
  322. }
  323. private sealed class OurProgressEvents : IFileTransferProgressEvents
  324. {
  325. private TransferProgressDialog progressDialog;
  326. private ICancelable cancelSink;
  327. private int itemCount = 0;
  328. private int itemOrdinal = 0;
  329. private string itemName = string.Empty;
  330. private long totalWork;
  331. private long totalProgress;
  332. private const int maxPBValue = 200; // granularity of progress bar. 100 means 1%, 200 means 0.5%, etc.
  333. private bool cancelRequested = false;
  334. private ManualResetEvent operationEnded = new ManualResetEvent(false);
  335. public OurProgressEvents()
  336. {
  337. }
  338. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "cancelSink")]
  339. public void BeginOperation(IWin32Window owner, EventHandler callWhenUIShown, ICancelable cancelSink)
  340. {
  341. if (this.progressDialog != null)
  342. {
  343. throw new InvalidOperationException("Operation already in progress");
  344. }
  345. this.progressDialog = new TransferProgressDialog();
  346. this.progressDialog.Text = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.TransferProgress.Title");
  347. this.progressDialog.Icon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.MenuFileOpenIcon.png").Reference);
  348. this.progressDialog.Title = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.ItemText.Initializing");
  349. this.progressDialog.ProgressBar.Style = ProgressBarStyle.Marquee;
  350. this.progressDialog.ProgressBar.Maximum = maxPBValue;
  351. this.progressDialog.CancelClicked +=
  352. delegate (object sender, EventArgs e)
  353. {
  354. this.cancelRequested = true;
  355. this.cancelSink.RequestCancel();
  356. UpdateUI();
  357. };
  358. EventHandler progressDialog_Shown =
  359. delegate (object sender, EventArgs e)
  360. {
  361. callWhenUIShown(this, EventArgs.Empty);
  362. };
  363. this.cancelSink = cancelSink;
  364. this.itemOrdinal = 0;
  365. this.cancelRequested = false;
  366. this.itemName = string.Empty;
  367. this.itemCount = 0;
  368. this.itemOrdinal = 0;
  369. this.totalProgress = 0;
  370. this.totalWork = 0;
  371. this.progressDialog.Shown += progressDialog_Shown;
  372. this.progressDialog.ShowDialog(owner);
  373. this.progressDialog.Shown -= progressDialog_Shown;
  374. this.progressDialog.Dispose();
  375. this.progressDialog = null;
  376. this.cancelSink = null;
  377. }
  378. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "itemCount")]
  379. public void SetItemCount(int itemCount)
  380. {
  381. if (this.progressDialog.InvokeRequired)
  382. {
  383. this.progressDialog.BeginInvoke(new Procedure<int>(SetItemCount), new object[] { itemCount });
  384. }
  385. else
  386. {
  387. this.itemCount = itemCount;
  388. UpdateUI();
  389. }
  390. }
  391. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "itemOrdinal")]
  392. public void SetItemOrdinal(int itemOrdinal)
  393. {
  394. if (this.progressDialog.InvokeRequired)
  395. {
  396. this.progressDialog.BeginInvoke(new Procedure<int>(SetItemOrdinal), new object[] { itemOrdinal });
  397. }
  398. else
  399. {
  400. this.itemOrdinal = itemOrdinal;
  401. this.totalWork = 0;
  402. this.totalProgress = 0;
  403. UpdateUI();
  404. }
  405. }
  406. public void SetItemInfo(string itemInfo)
  407. {
  408. if (this.progressDialog.InvokeRequired)
  409. {
  410. this.progressDialog.BeginInvoke(new Procedure<string>(SetItemInfo), new object[] { itemInfo });
  411. }
  412. else
  413. {
  414. this.itemName = itemInfo;
  415. UpdateUI();
  416. }
  417. }
  418. public void BeginItem()
  419. {
  420. if (this.progressDialog.InvokeRequired)
  421. {
  422. this.progressDialog.BeginInvoke(new Procedure(BeginItem), null);
  423. }
  424. else
  425. {
  426. this.progressDialog.ProgressBar.Style = ProgressBarStyle.Continuous;
  427. }
  428. }
  429. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "totalWork")]
  430. public void SetItemWorkTotal(long totalWork)
  431. {
  432. if (this.progressDialog.InvokeRequired)
  433. {
  434. this.progressDialog.BeginInvoke(new Procedure<long>(SetItemWorkTotal), new object[] { totalWork });
  435. }
  436. else
  437. {
  438. this.totalWork = totalWork;
  439. UpdateUI();
  440. }
  441. }
  442. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "totalProgress")]
  443. public void SetItemWorkProgress(long totalProgress)
  444. {
  445. if (this.progressDialog.InvokeRequired)
  446. {
  447. this.progressDialog.BeginInvoke(new Procedure<long>(SetItemWorkProgress), new object[] { totalProgress });
  448. }
  449. else
  450. {
  451. this.totalProgress = totalProgress;
  452. UpdateUI();
  453. }
  454. }
  455. public void EndItem(WorkItemResult result)
  456. {
  457. if (this.progressDialog.InvokeRequired)
  458. {
  459. this.progressDialog.BeginInvoke(new Procedure<WorkItemResult>(EndItem), new object[] { result });
  460. }
  461. else
  462. {
  463. }
  464. }
  465. public void EndOperation(OperationResult result)
  466. {
  467. if (this.progressDialog.InvokeRequired)
  468. {
  469. this.progressDialog.BeginInvoke(new Procedure<OperationResult>(EndOperation), new object[] { result });
  470. }
  471. else
  472. {
  473. this.progressDialog.Close();
  474. }
  475. }
  476. public WorkItemFailureAction ReportItemFailure(Exception ex)
  477. {
  478. if (this.progressDialog.InvokeRequired)
  479. {
  480. object result = this.progressDialog.Invoke(
  481. new Function<WorkItemFailureAction, Exception>(ReportItemFailure),
  482. new object[] { ex });
  483. return (WorkItemFailureAction)result;
  484. }
  485. else
  486. {
  487. WorkItemFailureAction result;
  488. result = ShowFileTransferFailedDialog(ex);
  489. return result;
  490. }
  491. }
  492. private WorkItemFailureAction ShowFileTransferFailedDialog(Exception ex)
  493. {
  494. WorkItemFailureAction result;
  495. Icon formIcon = this.progressDialog.Icon;
  496. string formTitle = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.ItemFailureDialog.Title");
  497. Image taskImage = PdnResources.GetImageResource("Icons.WarningIcon.png").Reference;
  498. string introTextFormat = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.ItemFailureDialog.IntroText.Format");
  499. string introText = string.Format(introTextFormat, ex.Message);
  500. TaskButton retryTB = new TaskButton(
  501. PdnResources.GetImageResource("Icons.MenuImageRotate90CWIcon.png").Reference,
  502. PdnResources.GetString("DocumentWorkspace.ShowFileDialog.RetryTB.ActionText"),
  503. PdnResources.GetString("DocumentWorkspace.ShowFileDialog.RetryTB.ExplanationText"));
  504. TaskButton skipTB = new TaskButton(
  505. PdnResources.GetImageResource("Icons.HistoryFastForwardIcon.png").Reference,
  506. PdnResources.GetString("DocumentWorkspace.ShowFileDialog.SkipTB.ActionText"),
  507. PdnResources.GetString("DocumentWorkspace.ShowFileDialog.SkipTB.ExplanationText"));
  508. TaskButton cancelTB = new TaskButton(
  509. PdnResources.GetImageResource("Icons.CancelIcon.png").Reference,
  510. PdnResources.GetString("DocumentWorkspace.ShowFileDialog.CancelTB.ActionText"),
  511. PdnResources.GetString("DocumentWorkspace.ShowFileDialog.CancelTB.ExplanationText"));
  512. List<TaskButton> taskButtons = new List<TaskButton>();
  513. taskButtons.Add(retryTB);
  514. // Only have the Skip button if there is more than 1 item being transferred.
  515. // If only 1 item is begin transferred, Skip and Cancel are essentially synonymous.
  516. if (this.itemCount > 1)
  517. {
  518. taskButtons.Add(skipTB);
  519. }
  520. taskButtons.Add(cancelTB);
  521. int width96 = (TaskDialog.DefaultPixelWidth96Dpi * 4) / 3; // 33% wider
  522. TaskButton clickedTB = TaskDialog.Show(
  523. this.progressDialog,
  524. formIcon,
  525. formTitle,
  526. taskImage,
  527. true,
  528. introText,
  529. taskButtons.ToArray(),
  530. retryTB,
  531. cancelTB,
  532. width96,
  533. false,
  534. 0,
  535. out bool unuse);
  536. if (clickedTB == retryTB)
  537. {
  538. result = WorkItemFailureAction.RetryItem;
  539. }
  540. else if (clickedTB == skipTB)
  541. {
  542. result = WorkItemFailureAction.SkipItem;
  543. }
  544. else
  545. {
  546. result = WorkItemFailureAction.CancelOperation;
  547. }
  548. return result;
  549. }
  550. private void UpdateUI()
  551. {
  552. int itemCount2 = Math.Max(1, this.itemCount);
  553. double startValue = (double)this.itemOrdinal / (double)itemCount2;
  554. double endValue = (double)(this.itemOrdinal + 1) / (double)itemCount2;
  555. long totalWork2 = Math.Max(1, this.totalWork);
  556. double lerp = (double)this.totalProgress / (double)totalWork2;
  557. double newValue = Utility.Lerp(startValue, endValue, lerp);
  558. int newValueInt = (int)Math.Ceiling(maxPBValue * newValue);
  559. if (this.cancelRequested)
  560. {
  561. this.progressDialog.CancelEnabled = false;
  562. this.progressDialog.Title = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.ItemText.Canceling");
  563. this.progressDialog.ProcessMsg = string.Empty;
  564. this.progressDialog.ProgressBar.Style = ProgressBarStyle.Marquee;
  565. }
  566. else
  567. {
  568. this.progressDialog.CancelEnabled = true;
  569. this.progressDialog.Title = this.itemName;
  570. string progressFormat = PdnResources.GetString("DocumentWorkspace.ShowFileDialog.ProgressText.Format");
  571. string progressText = string.Format(progressFormat, this.itemOrdinal + 1, this.itemCount);
  572. this.progressDialog.ProcessMsg = progressText;
  573. this.progressDialog.ProgressBar.Style = ProgressBarStyle.Continuous;
  574. this.progressDialog.ProgressBar.Value = newValueInt;
  575. }
  576. }
  577. }
  578. /// <summary>
  579. /// 更新测量单位,刷新UI
  580. /// </summary>
  581. /// <param name="measurementUnit"></param>
  582. public void UpdateMeasureUnit(MeasurementUnit measurementUnit)
  583. {
  584. //循环所有测量,更新单位
  585. if (this.GraphicsList != null
  586. && this.GraphicsList.Count > 0)
  587. {
  588. int count = this.GraphicsList.Count;
  589. for (int i = 0; i < count; i++)
  590. {
  591. if (this.GraphicsList[i].objectType == DrawClass.Measure)
  592. {
  593. ((MeasureDrawObject)(this.GraphicsList[i])).MeasurementUnit = measurementUnit;
  594. }
  595. }
  596. }
  597. this.Refresh();
  598. }
  599. /// <summary>
  600. /// 分栏显示禁止滚动改变图片大小
  601. /// </summary>
  602. bool disableWheel = false;
  603. public void removeEvent()
  604. {
  605. disableWheel = true;
  606. }
  607. }
  608. }