MainPage.xaml.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFAnnotation.Form;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.Tool;
  5. using ComPDFKit.Tool.Help;
  6. using ComPDFKit.Controls.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
  7. using ComPDFKit.Controls.Helper;
  8. using ComPDFKit.Controls.Measure;
  9. using ComPDFKit.Controls.PDFControl;
  10. using ComPDFKit.Controls.PDFView;
  11. using ComPDFKitViewer;
  12. using ComPDFKitViewer.Widget;
  13. using Microsoft.Win32;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.ComponentModel;
  17. using System.Runtime.CompilerServices;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Controls.Primitives;
  21. using System.Windows.Input;
  22. using ComPDFKit.Controls.PDFControlUI;
  23. using ComPDFKit.Controls.Snapshot;
  24. using System.Windows.Media;
  25. namespace PDFViewer
  26. {
  27. public partial class MainPage : UserControl, INotifyPropertyChanged
  28. {
  29. #region Properties
  30. private string currentMode = "Viewer";
  31. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  32. private PDFViewControl viewControl;
  33. private PDFViewControl passwordViewer;
  34. private RegularViewerControl regularViewerControl = new RegularViewerControl();
  35. private AnnotationControl annotationControl = new AnnotationControl();
  36. private FormControl formControl = new FormControl();
  37. private ContentEditControl contentEditControl = new ContentEditControl();
  38. private PageEditControl pageEditControl = new PageEditControl();
  39. private MeasureControl measureControl = new MeasureControl();
  40. private DigitalSignatureControl digitalSignatureControl = new DigitalSignatureControl();
  41. private SignatureStatusBarControl signatureStatusBarControl = new SignatureStatusBarControl();
  42. private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl();
  43. private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
  44. private PanelState panelState = PanelState.GetInstance();
  45. public event EventHandler FileChangeEvent;
  46. public event Func<string[], bool> CheckExistBeforeOpenFileEvent;
  47. public event EventHandler<string> AfterSaveAsFileEvent;
  48. public event PropertyChangedEventHandler PropertyChanged;
  49. private bool _canSave = false;
  50. /// <summary>
  51. /// Whether the save operation can be performed.
  52. /// </summary>
  53. public bool CanSave
  54. {
  55. get => _canSave;
  56. set
  57. {
  58. _canSave = value;
  59. OnPropertyChanged();
  60. }
  61. }
  62. public PDFViewControl GetPDFViewControl()
  63. {
  64. return viewControl;
  65. }
  66. /// <summary>
  67. /// Whether the left panel is expanded.
  68. /// </summary>
  69. public bool LeftToolPanelButtonIsChecked
  70. {
  71. get => panelState.IsLeftPanelExpand;
  72. set
  73. {
  74. panelState.IsLeftPanelExpand = value;
  75. OnPropertyChanged();
  76. }
  77. }
  78. /// <summary>
  79. /// Whether the right panel is expanded.
  80. /// </summary>
  81. public bool RightToolPanelButtonIsChecked
  82. {
  83. get => panelState.RightPanel == PanelState.RightPanelState.PropertyPanel;
  84. set
  85. {
  86. panelState.RightPanel = (value) ? PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
  87. OnPropertyChanged();
  88. }
  89. }
  90. /// <summary>
  91. /// Whether the view setting panel is expanded.
  92. /// </summary>
  93. public bool ViewSettingBtnIsChecked
  94. {
  95. get
  96. {
  97. return (panelState.RightPanel == PanelState.RightPanelState.ViewSettings);
  98. }
  99. set
  100. {
  101. panelState.RightPanel = (value) ? PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
  102. OnPropertyChanged();
  103. }
  104. }
  105. private Visibility _notDocsEditorVisible = Visibility.Visible;
  106. /// <summary>
  107. /// Whether the Document Editor panel is visible.
  108. /// </summary>
  109. public Visibility NotDocsEditorVisible
  110. {
  111. get => _notDocsEditorVisible;
  112. set
  113. {
  114. _notDocsEditorVisible = value;
  115. OnPropertyChanged();
  116. }
  117. }
  118. public MainPage()
  119. {
  120. InitializeComponent();
  121. this.DataContext = this;
  122. }
  123. #endregion
  124. #region Load document
  125. /// <summary>
  126. /// Initialize the PDFViewer and load the PDF file.
  127. /// </summary>
  128. /// <param name="filePath"></param>
  129. public void InitWithFilePath(string filePath)
  130. {
  131. viewControl = new PDFViewControl();
  132. viewControl.InitDocument(filePath);
  133. }
  134. public void InitWithDocument(CPDFDocument document)
  135. {
  136. viewControl = new PDFViewControl();
  137. viewControl.GetCPDFViewer().InitDoc(document);
  138. }
  139. /// <summary>
  140. /// Init controls and set events.
  141. /// </summary>
  142. private void LoadDocument()
  143. {
  144. if (viewControl != null && viewControl.PDFViewTool != null)
  145. {
  146. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  147. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  148. if (pdfDoc == null)
  149. {
  150. return;
  151. }
  152. SizeChanged -= MainPage_SizeChanged;
  153. SizeChanged += MainPage_SizeChanged;
  154. PasswordUI.Closed -= PasswordUI_Closed;
  155. PasswordUI.Canceled -= PasswordUI_Canceled;
  156. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  157. PasswordUI.Closed += PasswordUI_Closed;
  158. PasswordUI.Canceled += PasswordUI_Canceled;
  159. PasswordUI.Confirmed += PasswordUI_Confirmed;
  160. CPDFSaclingControl.InitWithPDFViewer(viewControl);
  161. ModeComboBox.SelectedIndex = 0;
  162. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfviewer.GetZoom() * 100)));
  163. botaBarControl.AddBOTAContent(new[] { BOTATools.Thumbnail, BOTATools.Outline, BOTATools.Bookmark, BOTATools.Annotation, BOTATools.Search });
  164. botaBarControl.ViewCertificateEvent -= digitalSignatureControl.ViewCertificateEvent;
  165. botaBarControl.ViewCertificateEvent += digitalSignatureControl.ViewCertificateEvent;
  166. botaBarControl.ViewSignatureEvent -= digitalSignatureControl.ViewSignatureEvent;
  167. botaBarControl.ViewSignatureEvent += digitalSignatureControl.ViewSignatureEvent;
  168. botaBarControl.DeleteSignatureEvent -= BotaBarControl_DeleteSignatureEvent;
  169. botaBarControl.DeleteSignatureEvent += BotaBarControl_DeleteSignatureEvent;
  170. botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
  171. ViewSettingBtn.IsChecked = false;
  172. botaBarControl.InitWithPDFViewer(viewControl);
  173. botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
  174. displaySettingsControl.InitWithPDFViewer(viewControl);
  175. LoadCustomControl();
  176. panelState.PropertyChanged -= PanelState_PropertyChanged;
  177. panelState.PropertyChanged += PanelState_PropertyChanged;
  178. displaySettingsControl.SplitModeChanged -= DisplaySettingsControl_SplitModeChanged;
  179. displaySettingsControl.SplitModeChanged += DisplaySettingsControl_SplitModeChanged;
  180. viewControl.PDFToolManager.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
  181. viewControl.PDFToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
  182. pdfviewer.SetLinkHighlight(Properties.Settings.Default.IsHighlightLinkArea);
  183. pdfviewer.SetFormFieldHighlight(Properties.Settings.Default.IsHighlightFormArea);
  184. pdfviewer.GetDocument().FontSubset = Properties.Settings.Default.FontSubsetting;
  185. pdfviewer.ScrollStride = Properties.Settings.Default.Divisor;
  186. }
  187. }
  188. private void BotaBarControl_DeleteSignatureEvent(object sender, EventArgs e)
  189. {
  190. viewControl.PDFViewTool.IsDocumentModified = true;
  191. DigitalSignatureControl_OnSignatureStatusChanged(sender, e);
  192. }
  193. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  194. {
  195. if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  196. {
  197. BaseWidget baseWidget = viewControl.GetCacheHitTestWidget();
  198. if (baseWidget != null)
  199. {
  200. AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
  201. viewControl.PDFViewTool.GetCPDFViewer().GetDocument(),
  202. baseWidget.GetAnnotData().PageIndex,
  203. baseWidget.GetAnnotData().Annot);
  204. if ((annotParam as WidgetParm).WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
  205. {
  206. var sigWidget = baseWidget.GetAnnotData().Annot as CPDFSignatureWidget;
  207. if(sigWidget == null)
  208. {
  209. return;
  210. }
  211. var sig = sigWidget.GetSignature(viewControl.GetCPDFViewer().GetDocument());
  212. if (sigWidget.IsSigned() && sig != null && sig.SignerList.Count > 0)
  213. {
  214. return;
  215. }
  216. if (currentMode == "Annotation")
  217. {
  218. CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
  219. signatureProperty.SetFormProperty(annotParam, viewControl, baseWidget.GetAnnotData().Annot);
  220. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  221. annotationControl.SetPropertyContainer(signatureProperty);
  222. }
  223. else if (currentMode == "Viewer")
  224. {
  225. CPDFSignatureUI signatureProperty = new CPDFSignatureUI();
  226. signatureProperty.SetFormProperty(annotParam, viewControl, baseWidget.GetAnnotData().Annot);
  227. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  228. regularViewerControl.SetPropertyContainer(signatureProperty);
  229. }
  230. }
  231. }
  232. }
  233. }
  234. private void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
  235. {
  236. viewControl.WindowSizeChange();
  237. }
  238. private void DisplaySettingsControl_SplitModeChanged(object sender, ComPDFKit.Controls.PDFControlUI.CPDFViewModeUI.SplitMode e)
  239. {
  240. viewControl.SetSplitViewMode(e);
  241. }
  242. /// <summary>
  243. /// When the RightPanel state is changed, decide whether to display the ViewSettingPanel or RightToolPanel.
  244. /// </summary>
  245. /// <param name="sender"></param>
  246. /// <param name="e"></param>
  247. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  248. {
  249. if (e.PropertyName == "RightPanel")
  250. {
  251. OnPropertyChanged(nameof(RightToolPanelButtonIsChecked));
  252. OnPropertyChanged(nameof(ViewSettingBtnIsChecked));
  253. }
  254. }
  255. public void SetFeatureMode(string featureName)
  256. {
  257. if (!string.IsNullOrEmpty(featureName))
  258. {
  259. switch (featureName)
  260. {
  261. case "Viewer":
  262. ModeComboBox.SelectedIndex = 0;
  263. break;
  264. case "Annotations":
  265. ModeComboBox.SelectedIndex = 1;
  266. break;
  267. case "Forms":
  268. ModeComboBox.SelectedIndex = 2;
  269. break;
  270. case "Signatures":
  271. ModeComboBox.SelectedIndex = 5;
  272. break;
  273. case "Document Editor":
  274. ModeComboBox.SelectedIndex = 4;
  275. break;
  276. case "Content Editor":
  277. ModeComboBox.SelectedIndex = 3;
  278. break;
  279. case "Measurement":
  280. ModeComboBox.SelectedIndex = 6;
  281. break;
  282. default:
  283. break;
  284. }
  285. }
  286. }
  287. internal void SetPDFViewer(PDFViewControl newPdfViewer)
  288. {
  289. if (newPdfViewer != null)
  290. {
  291. viewControl = newPdfViewer;
  292. }
  293. }
  294. #endregion
  295. #region Password
  296. /// <summary>
  297. /// Event handler for confirming the password. Open the PDF file if the password is correct.
  298. /// </summary>
  299. /// <param name="sender"></param>
  300. /// <param name="e"></param>
  301. private void PasswordUI_Confirmed(object sender, string e)
  302. {
  303. if (passwordViewer != null && passwordViewer.PDFViewTool != null)
  304. {
  305. CPDFViewer pdfviewer = passwordViewer.PDFViewTool.GetCPDFViewer();
  306. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  307. if (pdfDoc == null)
  308. {
  309. return;
  310. }
  311. pdfDoc.UnlockWithPassword(e);
  312. if (pdfDoc.IsLocked == false)
  313. {
  314. PasswordUI.SetShowError("", Visibility.Collapsed);
  315. PasswordUI.ClearPassword();
  316. PasswordUI.Visibility = Visibility.Collapsed;
  317. PopupBorder.Visibility = Visibility.Collapsed;
  318. viewControl = passwordViewer;
  319. LoadDocument();
  320. viewControl.PDFViewTool.GetCPDFViewer().UpdateVirtualNodes();
  321. FileChangeEvent?.Invoke(null, EventArgs.Empty);
  322. }
  323. else
  324. {
  325. PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
  326. }
  327. }
  328. }
  329. /// <summary>
  330. /// Event handler for canceling password input.
  331. /// </summary>
  332. /// <param name="sender"></param>
  333. /// <param name="e"></param>
  334. private void PasswordUI_Canceled(object sender, EventArgs e)
  335. {
  336. PopupBorder.Visibility = Visibility.Collapsed;
  337. PasswordUI.Visibility = Visibility.Collapsed;
  338. }
  339. /// <summary>
  340. /// Event handler for closing the password input dialog.
  341. /// </summary>
  342. /// <param name="sender"></param>
  343. /// <param name="e"></param>
  344. private void PasswordUI_Closed(object sender, EventArgs e)
  345. {
  346. PopupBorder.Visibility = Visibility.Collapsed;
  347. PasswordUI.Visibility = Visibility.Collapsed;
  348. }
  349. #endregion
  350. #region Load custom control
  351. /// <summary>
  352. /// Load the custom controls for the PDF viewer.
  353. /// </summary>
  354. private void LoadCustomControl()
  355. {
  356. regularViewerControl.PdfViewControl = viewControl;
  357. regularViewerControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  358. regularViewerControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  359. regularViewerControl.InitWithPDFViewer(viewControl);
  360. //regularViewerControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  361. regularViewerControl.SetBOTAContainer(null);
  362. regularViewerControl.SetBOTAContainer(botaBarControl);
  363. regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
  364. PDFGrid.Child = regularViewerControl;
  365. SignatureHelper.InitEffectiveSignatureList(viewControl.GetCPDFViewer().GetDocument());
  366. SignatureHelper.VerifySignatureList(viewControl.GetCPDFViewer().GetDocument());
  367. signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
  368. viewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  369. viewControl.PDFViewTool.DocumentModifiedChanged -= PDFViewTool_DocumentModifiedChanged;
  370. viewControl.PDFViewTool.DocumentModifiedChanged += PDFViewTool_DocumentModifiedChanged;
  371. }
  372. /// <summary>
  373. /// Event handler for the Loaded event of the MainPage.
  374. /// </summary>
  375. /// <param name="sender"></param>
  376. /// <param name="e"></param>
  377. private void MainPage_Loaded(object sender, RoutedEventArgs e)
  378. {
  379. LoadDocument();
  380. }
  381. #endregion
  382. #region Event handle
  383. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  384. {
  385. if (e.Key == "Zoom")
  386. {
  387. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  388. }
  389. }
  390. /// <summary>
  391. /// Command for opening a PDF file saved with a signature.
  392. /// </summary>
  393. /// <param name="sender"></param>
  394. /// <param name="e"></param>
  395. private void DigitalSignatureControl_AfterFillSignature(object sender, string e)
  396. {
  397. OpenFile(e);
  398. }
  399. /// <summary>
  400. /// Event handler for deleting a signature from the BOTA. Set the CanSave property to true and update the signature status.
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void BotaControlOnDeleteSignatureEvent(object sender, EventArgs e)
  405. {
  406. DigitalSignatureControl_OnSignatureStatusChanged(sender, e);
  407. }
  408. /// <summary>
  409. /// Event handler for updating a signature. Update the signature status.
  410. /// </summary>
  411. /// <param name="sender"></param>
  412. /// <param name="e"></param>
  413. private void DigitalSignatureControl_OnSignatureStatusChanged(object sender, EventArgs e)
  414. {
  415. SignatureHelper.InitEffectiveSignatureList(viewControl.GetCPDFViewer().GetDocument());
  416. SignatureHelper.VerifySignatureList(viewControl.GetCPDFViewer().GetDocument());
  417. signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
  418. botaBarControl.LoadSignatureList();
  419. }
  420. /// <summary>
  421. /// Event handler for updating the CanSave property.
  422. /// </summary>
  423. /// <param name="sender"></param>
  424. /// <param name="e"></param>
  425. private void DigitalSignatureControl_OnCanSaveChanged(object sender, bool e)
  426. {
  427. this.CanSave = e;
  428. }
  429. #endregion
  430. #region Private Command Event
  431. /// <summary>
  432. /// Close all the expanded panels.
  433. /// </summary>
  434. private void ClearPanelState()
  435. {
  436. LeftToolPanelButtonIsChecked = false;
  437. ViewSettingBtnIsChecked = false;
  438. RightToolPanelButtonIsChecked = false;
  439. }
  440. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  441. {
  442. panelState.IsLeftPanelExpand = (sender as ToggleButton).IsChecked == true;
  443. }
  444. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  445. {
  446. var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
  447. if ((string)item.Tag == currentMode)
  448. {
  449. return;
  450. }
  451. if((string)item.Tag == "Viewer" || (string)item.Tag == "Annotation")
  452. {
  453. SnapshotButton.Visibility = Visibility.Visible;
  454. }
  455. else
  456. {
  457. SnapshotButton.Visibility = Visibility.Collapsed;
  458. }
  459. ClearPanelState();
  460. if (ViewSettingBtn != null)
  461. ViewSettingBtn.IsChecked = false;
  462. if (RightPanelButton != null)
  463. RightPanelButton.IsChecked = false;
  464. if (viewControl != null && viewControl.GetCPDFViewer() != null)
  465. {
  466. // pdfViewer.PDFView.ToolManager.EnableClickCreate = false;
  467. }
  468. if (currentMode == "Viewer")
  469. {
  470. regularViewerControl.ClearViewerControl();
  471. }
  472. else if (currentMode == "Annotation")
  473. {
  474. annotationControl.UnloadEvent();
  475. annotationControl.ClearViewerControl();
  476. annotationControl.PDFAnnotationControl.AnnotationCancel();
  477. viewControl.SetIsShowStampMouse(false);
  478. }
  479. else if (currentMode == "Form")
  480. {
  481. formControl.UnloadEvent();
  482. formControl.ClearViewerControl();
  483. viewControl.SetIsShowStampMouse(false);
  484. viewControl.GetCPDFViewer().SetFormFieldHighlight(Properties.Settings.Default.IsHighlightFormArea);
  485. }
  486. else if (currentMode == "Content Editor")
  487. {
  488. botaBarControl.ReplaceFunctionEnabled = false;
  489. displaySettingsControl.SetVisibilityWhenContentEdit(Visibility.Visible);
  490. contentEditControl.ClearViewerControl();
  491. contentEditControl.ClearPDFEditState();
  492. }
  493. else if (currentMode == "Document Editor")
  494. {
  495. pageEditControl.ExitPageEdit -= PageEditControl_ExitPageEdit;
  496. NotDocsEditorVisible = Visibility.Visible;
  497. botaBarControl.LoadThumbnail();
  498. }
  499. else if (currentMode == "Digital Signature")
  500. {
  501. RightPanelButton.Visibility = Visibility.Visible;
  502. digitalSignatureControl.ClearViewerControl();
  503. botaBarControl.RemoveBOTAContent(BOTATools.Signature);
  504. digitalSignatureControl.UnloadEvent();
  505. }
  506. else if (currentMode == "Measurement")
  507. {
  508. RightPanelButton.Visibility = Visibility.Visible;
  509. GetPDFViewControl().PDFViewTool.GetDefaultSettingParam().IsOpenMeasure = false;
  510. measureControl.ClearAllToolState();
  511. measureControl.ClearViewerControl();
  512. measureControl.UnloadEvent();
  513. }
  514. if (item.Tag as string == "Viewer")
  515. {
  516. regularViewerControl.PdfViewControl = viewControl;
  517. regularViewerControl.InitWithPDFViewer(viewControl);
  518. if (regularViewerControl.PdfViewControl != null)
  519. {
  520. PDFGrid.Child = regularViewerControl;
  521. viewControl.SetToolType(ToolType.Viewer);
  522. regularViewerControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  523. regularViewerControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  524. regularViewerControl.SetBOTAContainer(botaBarControl);
  525. regularViewerControl.SetDisplaySettingsControl(displaySettingsControl);
  526. }
  527. }
  528. else if (item.Tag as string == "Annotation")
  529. {
  530. annotationControl.SetToolBarContainerVisibility(Visibility.Visible);
  531. PDFGrid.Child = annotationControl;
  532. viewControl.SetToolType(ToolType.Pan);
  533. annotationControl.PDFViewControl = viewControl;
  534. annotationControl.InitWithPDFViewer(viewControl);
  535. if (annotationControl.PDFViewControl != null)
  536. {
  537. annotationControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  538. annotationControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  539. annotationControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
  540. annotationControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
  541. annotationControl.InitialPDFViewControl(annotationControl.PDFViewControl);
  542. annotationControl.SetBOTAContainer(botaBarControl);
  543. annotationControl.SetDisplaySettingsControl(displaySettingsControl);
  544. }
  545. }
  546. else if (item.Tag as string == "Form")
  547. {
  548. formControl.SetToolBarContainerVisibility(Visibility.Visible);
  549. formControl.PdfViewControl = viewControl;
  550. formControl.InitWithPDFViewer(viewControl);
  551. if (formControl.PdfViewControl != null)
  552. {
  553. PDFGrid.Child = formControl;
  554. viewControl.SetToolType(ToolType.WidgetEdit);
  555. formControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  556. formControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  557. formControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
  558. formControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
  559. formControl.SetBOTAContainer(botaBarControl);
  560. formControl.InitialPDFViewControl(formControl.PdfViewControl);
  561. formControl.SetDisplaySettingsControl(displaySettingsControl);
  562. viewControl.GetCPDFViewer().SetFormFieldHighlight(true);
  563. }
  564. }
  565. else if (item.Tag as string == "Content Editor")
  566. {
  567. contentEditControl.PdfViewControl = viewControl;
  568. contentEditControl.InitWithPDFViewer(viewControl);
  569. displaySettingsControl.SetVisibilityWhenContentEdit(Visibility.Collapsed);
  570. if (contentEditControl.pdfContentEditControl != null && contentEditControl.PdfViewControl != null)
  571. {
  572. PDFGrid.Child = contentEditControl;
  573. viewControl.SetToolType(ToolType.ContentEdit);
  574. contentEditControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  575. contentEditControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  576. contentEditControl.SetBOTAContainer(botaBarControl);
  577. contentEditControl.SetDisplaySettingsControl(displaySettingsControl);
  578. contentEditControl.PdfViewControl.SetSplitViewMode(CPDFViewModeUI.SplitMode.None);
  579. }
  580. }
  581. else if (item.Tag as string == "Document Editor")
  582. {
  583. pageEditControl.PDFViewControl = viewControl;
  584. pageEditControl.ExitPageEdit += PageEditControl_ExitPageEdit;
  585. pageEditControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
  586. pageEditControl.OnCanSaveChanged += ControlOnCanSaveChanged;
  587. PDFGrid.Child = pageEditControl;
  588. NotDocsEditorVisible = Visibility.Collapsed;
  589. }
  590. else if (item.Tag as string == "Digital Signature")
  591. {
  592. if (digitalSignatureControl.PDFViewControl != null)
  593. {
  594. RightPanelButton.Visibility = Visibility.Collapsed;
  595. PDFGrid.Child = digitalSignatureControl;
  596. viewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  597. digitalSignatureControl.PDFViewControl = viewControl;
  598. botaBarControl.AddBOTAContent(BOTATools.Signature);
  599. digitalSignatureControl.InitWithPDFViewer(viewControl);
  600. digitalSignatureControl.SetBOTAContainer(botaBarControl);
  601. digitalSignatureControl.SetDisplaySettingsControl(displaySettingsControl);
  602. digitalSignatureControl.SetSignatureStatusBarControl(signatureStatusBarControl);
  603. signatureStatusBarControl.OnViewSignatureButtonClicked -= ViewAllSignatures;
  604. signatureStatusBarControl.OnViewSignatureButtonClicked += ViewAllSignatures;
  605. digitalSignatureControl.OnCanSaveChanged -= DigitalSignatureControl_OnCanSaveChanged;
  606. digitalSignatureControl.OnCanSaveChanged += DigitalSignatureControl_OnCanSaveChanged;
  607. digitalSignatureControl.SignatureStatusChanged -= DigitalSignatureControl_OnSignatureStatusChanged;
  608. digitalSignatureControl.SignatureStatusChanged += DigitalSignatureControl_OnSignatureStatusChanged;
  609. digitalSignatureControl.AfterFillSignature -= DigitalSignatureControl_AfterFillSignature;
  610. digitalSignatureControl.AfterFillSignature += DigitalSignatureControl_AfterFillSignature;
  611. }
  612. }
  613. else if (item.Tag as string == "Measurement")
  614. {
  615. if (contentEditControl.pdfContentEditControl != null && viewControl != null)
  616. {
  617. RightPanelButton.Visibility = Visibility.Visible;
  618. PDFGrid.Child = measureControl;
  619. viewControl.PDFToolManager.SetToolType(ToolType.Pan);
  620. viewControl.SetToolType(ToolType.Pan);
  621. measureControl.InitWithPDFViewer(viewControl);
  622. measureControl.SetBOTAContainer(botaBarControl);
  623. measureControl.ClearAllToolState();
  624. measureControl.SetSettingsControl(displaySettingsControl);
  625. GetPDFViewControl().PDFViewTool.GetDefaultSettingParam().IsOpenMeasure = true;
  626. measureControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
  627. measureControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
  628. }
  629. }
  630. currentMode = item.Tag as string;
  631. RightToolPanelButtonIsChecked = false;
  632. SnapshotButton.IsChecked = false;
  633. viewControl.FocusPDFViewTool.RemovePageSelectdUserControl();
  634. }
  635. /// <summary>
  636. /// Event handler for ViewSignatureBtn click event. Expand the bota control and select the Signature tool.
  637. /// </summary>
  638. /// <param name="sender"></param>
  639. /// <param name="e"></param>
  640. private void ViewAllSignatures(object sender, EventArgs e)
  641. {
  642. LeftToolPanelButton.IsChecked = true;
  643. botaBarControl.SelectBotaTool(BOTATools.Signature);
  644. }
  645. private void PageEditControl_ExitPageEdit(object sender, EventArgs e)
  646. {
  647. ModeComboBox.SelectedIndex = 0;
  648. }
  649. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  650. {
  651. PasswordUI.Visibility = Visibility.Collapsed;
  652. FileInfoUI.Visibility = Visibility.Visible;
  653. FileInfoControl.InitWithPDFViewer(viewControl);
  654. PopupBorder.Visibility = Visibility.Visible;
  655. }
  656. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  657. {
  658. panelState.RightPanel =
  659. ((sender as ToggleButton).IsChecked == true) ?
  660. PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
  661. }
  662. private void RightPanelButton_Click(object sender, RoutedEventArgs e)
  663. {
  664. panelState.RightPanel =
  665. ((sender as ToggleButton).IsChecked == true) ?
  666. PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
  667. }
  668. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  669. {
  670. LeftToolPanelButton.IsChecked = true;
  671. botaBarControl.SelectBotaTool(BOTATools.Search);
  672. }
  673. private void CPDFTitleBarControl_Loaded(object sender, RoutedEventArgs e)
  674. {
  675. CPDFTitleBarControl.OpenFileEvent -= CPDFTitleBarControl_OpenFileEvent;
  676. CPDFTitleBarControl.OpenFileEvent += CPDFTitleBarControl_OpenFileEvent;
  677. CPDFTitleBarControl.SaveAsFileEvent -= CPDFTitleBarControl_SaveAsFileEvent;
  678. CPDFTitleBarControl.SaveAsFileEvent += CPDFTitleBarControl_SaveAsFileEvent;
  679. CPDFTitleBarControl.SaveFileEvent -= CPDFTitleBarControl_SaveFileEvent;
  680. CPDFTitleBarControl.SaveFileEvent += CPDFTitleBarControl_SaveFileEvent;
  681. CPDFTitleBarControl.FlattenEvent -= CPDFTitleBarControl_FlattenEvent;
  682. CPDFTitleBarControl.FlattenEvent += CPDFTitleBarControl_FlattenEvent;
  683. CPDFTitleBarControl.PrintEvent -= CPDFTitleBarControl_PrintEvent;
  684. CPDFTitleBarControl.PrintEvent += CPDFTitleBarControl_PrintEvent;
  685. }
  686. private void CPDFTitleBarControl_PrintEvent(object sender, EventArgs e)
  687. {
  688. PrinterDialog printerDialog = new PrinterDialog();
  689. printerDialog.Document = viewControl.GetCPDFViewer().GetDocument();
  690. printerDialog.ShowDialog();
  691. }
  692. private void CPDFTitleBarControl_FlattenEvent(object sender, EventArgs e)
  693. {
  694. if (viewControl != null && viewControl.GetCPDFViewer() != null && viewControl.GetCPDFViewer().GetDocument() != null)
  695. {
  696. string savePath = ComPDFKit.Controls.Helper.CommonHelper.GetGeneratePathOrEmpty("PDF files (*.pdf)|*.pdf", viewControl.GetCPDFViewer().GetDocument().FileName + "_Flattened.pdf");
  697. if (!string.IsNullOrEmpty(savePath))
  698. {
  699. if (CanSave)
  700. {
  701. SaveFile();
  702. viewControl.PDFViewTool.IsDocumentModified = false;
  703. }
  704. CPDFDocument document = CPDFDocument.InitWithFilePath(viewControl.GetCPDFViewer().GetDocument().FilePath);
  705. if (document?.WriteFlattenToFilePath(savePath) == true)
  706. {
  707. System.Diagnostics.Process.Start("Explorer.exe", "/select," + savePath);
  708. }
  709. document?.Release();
  710. }
  711. }
  712. }
  713. private void CPDFTitleBarControl_SaveFileEvent(object sender, EventArgs e)
  714. {
  715. SaveFile();
  716. }
  717. private void CPDFTitleBarControl_SaveAsFileEvent(object sender, EventArgs e)
  718. {
  719. SaveAsFile();
  720. }
  721. private void CPDFTitleBarControl_OpenFileEvent(object sender, EventArgs e)
  722. {
  723. OpenFile();
  724. }
  725. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  726. {
  727. PopupBorder.Visibility = Visibility.Collapsed;
  728. }
  729. /// <summary>
  730. /// Refresh the annotation list when a annotation is edited.
  731. /// </summary>
  732. /// <param name="sender"></param>
  733. /// <param name="e"></param>
  734. private void PdfFormControlRefreshAnnotList(object sender, EventArgs e)
  735. {
  736. botaBarControl.LoadAnnotationList();
  737. }
  738. /// <summary>
  739. /// When a CanSave property of a control is changed, the CanSave property of current page is changed.
  740. /// </summary>
  741. /// <param name="sender"></param>
  742. /// <param name="e"></param>
  743. private void ControlOnCanSaveChanged(object sender, bool e)
  744. {
  745. this.CanSave = e;
  746. }
  747. private void PDFViewTool_DocumentModifiedChanged(object sender, EventArgs e)
  748. {
  749. CanSave = viewControl.PDFViewTool.IsDocumentModified;
  750. }
  751. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  752. {
  753. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  754. }
  755. private void SnapShotButton_Click(object sender, RoutedEventArgs e)
  756. {
  757. if((sender as ToggleButton).IsChecked == true)
  758. {
  759. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  760. SnapshotMenu snapMenu = new SnapshotMenu();
  761. snapshotArgs.ControlPointColor = Colors.White;
  762. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  763. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  764. snapshotArgs.ToolPanel = snapMenu;
  765. snapshotArgs.Viewer = viewControl;
  766. snapMenu.SnapToolArgs = snapshotArgs;
  767. snapMenu.PdfViewer = viewControl;
  768. snapMenu.SnapToolEvent += SnapMenu_SnapToolEvent;
  769. viewControl.PDFToolManager.SetToolType(ToolType.SelectedPage);
  770. viewControl.FocusPDFViewTool.SetPageSelectdUserControl(snapshotArgs.ToolPanel);
  771. }
  772. else
  773. {
  774. if ((ModeComboBox.SelectedItem as ComboBoxItem).Tag.ToString() == "Viewer")
  775. {
  776. viewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  777. }
  778. else if ((ModeComboBox.SelectedItem as ComboBoxItem).Tag.ToString() == "Annotation")
  779. {
  780. viewControl.PDFToolManager.SetToolType(ToolType.Pan);
  781. }
  782. viewControl.FocusPDFViewTool.RemovePageSelectdUserControl();
  783. }
  784. }
  785. private void SnapMenu_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  786. {
  787. switch (e.Key)
  788. {
  789. case "CloseSnap":
  790. {
  791. if ((ModeComboBox.SelectedItem as ComboBoxItem).Tag.ToString() == "Viewer")
  792. {
  793. viewControl.PDFToolManager.SetToolType(ToolType.Viewer);
  794. }
  795. else if ((ModeComboBox.SelectedItem as ComboBoxItem).Tag.ToString() == "Annotation")
  796. {
  797. viewControl.PDFToolManager.SetToolType(ToolType.Pan);
  798. }
  799. SnapshotButton.IsChecked = false;
  800. viewControl.FocusPDFViewTool.RemovePageSelectdUserControl();
  801. }
  802. break;
  803. case "Save":
  804. CanSave = true;
  805. break;
  806. default:
  807. break;
  808. }
  809. }
  810. #endregion
  811. #region Open and Save file
  812. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  813. {
  814. SaveFile();
  815. CanSave = false;
  816. }
  817. private void OpenFile(string filePath = "")
  818. {
  819. if (viewControl != null && viewControl.PDFViewTool != null)
  820. {
  821. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  822. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  823. if (pdfDoc == null)
  824. {
  825. return;
  826. }
  827. if (string.IsNullOrEmpty(filePath))
  828. {
  829. filePath = ComPDFKit.Controls.Helper.CommonHelper.GetExistedPathOrEmpty();
  830. }
  831. string oldFilePath = pdfDoc.FilePath;
  832. if (!string.IsNullOrEmpty(filePath) && regularViewerControl.PdfViewControl != null)
  833. {
  834. if (oldFilePath.ToLower() == filePath.ToLower())
  835. {
  836. return;
  837. }
  838. if ((bool)CheckExistBeforeOpenFileEvent?.Invoke(new string[] { filePath, oldFilePath }))
  839. {
  840. return;
  841. }
  842. if (CanSave)
  843. {
  844. string fileName = pdfDoc.FileName;
  845. var message = fileName + " " + LanguageHelper.CommonManager.GetString("Warn_NotSave");
  846. var result = MessageBox.Show(message, LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
  847. if (result == MessageBoxResult.Yes)
  848. {
  849. SaveFile();
  850. }
  851. else if (result == MessageBoxResult.Cancel)
  852. {
  853. return;
  854. }
  855. }
  856. passwordViewer = new PDFViewControl();
  857. passwordViewer.InitDocument(filePath);
  858. CPDFViewer tempViewer = passwordViewer.PDFViewTool?.GetCPDFViewer();
  859. CPDFDocument tempDoc = tempViewer?.GetDocument();
  860. if (tempDoc == null)
  861. {
  862. MessageBox.Show("Open File Failed");
  863. return;
  864. }
  865. if (passwordViewer.GetCPDFViewer().GetDocument().IsLocked)
  866. {
  867. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " " + LanguageHelper.CommonManager.GetString("Tip_Encrypted"));
  868. PasswordUI.ClearPassword();
  869. PopupBorder.Visibility = Visibility.Visible;
  870. PasswordUI.Visibility = Visibility.Visible;
  871. }
  872. else
  873. {
  874. pdfDoc.Release();
  875. viewControl = passwordViewer;
  876. LoadDocument();
  877. FileChangeEvent?.Invoke(null, EventArgs.Empty);
  878. }
  879. }
  880. }
  881. }
  882. private void OpenFile_Click(object sender, RoutedEventArgs e)
  883. {
  884. OpenFile();
  885. }
  886. /// <summary>
  887. /// Save the file to another PDF file.
  888. /// </summary>
  889. public void SaveAsFile()
  890. {
  891. if (viewControl != null && viewControl.PDFViewTool != null)
  892. {
  893. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  894. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  895. if (pdfDoc == null)
  896. {
  897. return;
  898. }
  899. SaveFileDialog saveDialog = new SaveFileDialog();
  900. saveDialog.Filter = "(*.pdf)|*.pdf";
  901. saveDialog.DefaultExt = ".pdf";
  902. saveDialog.OverwritePrompt = true;
  903. if (saveDialog.ShowDialog() == true)
  904. {
  905. pdfDoc.WriteToFilePath(saveDialog.FileName);
  906. }
  907. }
  908. }
  909. /// <summary>
  910. /// Save the file in the current path.
  911. /// </summary>
  912. public void SaveFile()
  913. {
  914. if (viewControl != null && viewControl.PDFViewTool != null)
  915. {
  916. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  917. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  918. if (pdfDoc == null)
  919. {
  920. return;
  921. }
  922. try
  923. {
  924. if (!string.IsNullOrEmpty(pdfDoc.FilePath))
  925. {
  926. if (pdfDoc.WriteToLoadedPath())
  927. {
  928. return;
  929. }
  930. }
  931. SaveFileDialog saveDialog = new SaveFileDialog
  932. {
  933. Filter = "(*.pdf)|*.pdf",
  934. DefaultExt = ".pdf",
  935. OverwritePrompt = true
  936. };
  937. if (saveDialog.ShowDialog() == true)
  938. {
  939. if (pdfDoc.WriteToFilePath(saveDialog.FileName))
  940. {
  941. AfterSaveAsFileEvent?.Invoke(this, saveDialog.FileName);
  942. }
  943. }
  944. }
  945. catch (Exception ex)
  946. {
  947. return;
  948. }
  949. }
  950. }
  951. public void CloseFile()
  952. {
  953. if (viewControl != null && viewControl.PDFViewTool != null)
  954. {
  955. CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
  956. CPDFDocument pdfDoc = pdfviewer?.GetDocument();
  957. if(pdfDoc !=null)
  958. {
  959. pdfDoc.Release();
  960. }
  961. }
  962. }
  963. #endregion
  964. #region Command Binding
  965. private double CheckZoomLevel(double zoom, bool IsGrowth)
  966. {
  967. double standardZoom = 100;
  968. if (zoom <= 0.01)
  969. {
  970. return 0.01;
  971. }
  972. if (zoom >= 10)
  973. {
  974. return 10;
  975. }
  976. zoom *= 100;
  977. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  978. {
  979. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  980. {
  981. standardZoom = zoomLevelList[i + 1];
  982. break;
  983. }
  984. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  985. {
  986. standardZoom = zoomLevelList[i];
  987. break;
  988. }
  989. }
  990. return standardZoom / 100;
  991. }
  992. private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
  993. {
  994. OpenFile();
  995. }
  996. private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
  997. {
  998. if (CanSave)
  999. {
  1000. SaveFile();
  1001. }
  1002. }
  1003. private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
  1004. {
  1005. SaveAsFile();
  1006. }
  1007. private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
  1008. {
  1009. panelState.IsLeftPanelExpand = !panelState.IsLeftPanelExpand;
  1010. }
  1011. private void CommandBinding_Executed_ControlRightPanel(object sender, ExecutedRoutedEventArgs e)
  1012. {
  1013. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  1014. {
  1015. panelState.RightPanel = PanelState.RightPanelState.None;
  1016. }
  1017. else
  1018. {
  1019. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  1020. }
  1021. }
  1022. private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
  1023. {
  1024. LeftToolPanelButton.IsChecked = true;
  1025. botaBarControl.SelectBotaTool(BOTATools.Bookmark);
  1026. }
  1027. private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
  1028. {
  1029. LeftToolPanelButton.IsChecked = true;
  1030. botaBarControl.SelectBotaTool(BOTATools.Outline);
  1031. }
  1032. private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
  1033. {
  1034. LeftToolPanelButton.IsChecked = true;
  1035. botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
  1036. }
  1037. private void CommandBinding_Executed_Annotation(object sender, ExecutedRoutedEventArgs e)
  1038. {
  1039. LeftToolPanelButton.IsChecked = true;
  1040. botaBarControl.SelectBotaTool(BOTATools.Annotation);
  1041. }
  1042. private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
  1043. {
  1044. LeftToolPanelButton.IsChecked = true;
  1045. botaBarControl.SelectBotaTool(BOTATools.Search);
  1046. }
  1047. private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
  1048. {
  1049. if (viewControl != null && viewControl.PDFViewTool != null)
  1050. {
  1051. CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
  1052. if (pdfViewer != null)
  1053. {
  1054. double newZoom = CheckZoomLevel(pdfViewer.GetZoom() + 0.01, true);
  1055. pdfViewer.SetZoom(newZoom);
  1056. }
  1057. }
  1058. }
  1059. private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
  1060. {
  1061. if (viewControl != null && viewControl.PDFViewTool != null)
  1062. {
  1063. CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
  1064. if (pdfViewer != null)
  1065. {
  1066. double newZoom = CheckZoomLevel(pdfViewer.GetZoom() - 0.01, false);
  1067. pdfViewer.SetZoom(newZoom);
  1068. }
  1069. }
  1070. }
  1071. private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
  1072. {
  1073. panelState.RightPanel = PanelState.RightPanelState.ViewSettings;
  1074. }
  1075. private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
  1076. {
  1077. if (PopupBorder.Visibility != Visibility.Visible)
  1078. {
  1079. PasswordUI.Visibility = Visibility.Collapsed;
  1080. FileInfoControl.Visibility = Visibility.Visible;
  1081. FileInfoControl.InitWithPDFViewer(viewControl);
  1082. FileInfoControl.CloseInfoEvent -= CPDFInfoControl_CloseInfoEvent;
  1083. FileInfoControl.CloseInfoEvent += CPDFInfoControl_CloseInfoEvent;
  1084. PopupBorder.Visibility = Visibility.Visible;
  1085. }
  1086. else
  1087. {
  1088. FileInfoControl.Visibility = Visibility.Collapsed;
  1089. PopupBorder.Visibility = Visibility.Collapsed;
  1090. this.Focus();
  1091. }
  1092. }
  1093. private void CPDFInfoControl_CloseInfoEvent(object sender, EventArgs e)
  1094. {
  1095. PopupBorder.Visibility = Visibility.Collapsed;
  1096. }
  1097. #endregion
  1098. }
  1099. }