MainPage.xaml.cs 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.PDFPage.Edit;
  4. using Compdfkit_Tools.Data;
  5. using Compdfkit_Tools.Edit;
  6. using Compdfkit_Tools.Helper;
  7. using Compdfkit_Tools.PDFControl;
  8. using ComPDFKitViewer;
  9. using ComPDFKitViewer.AnnotEvent;
  10. using ComPDFKitViewer.PdfViewer;
  11. using Microsoft.Win32;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.ComponentModel;
  15. using System.Diagnostics;
  16. using System.Drawing;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Runtime.CompilerServices;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Controls.Primitives;
  23. using System.Windows.Input;
  24. using System.Windows.Media;
  25. using System.Windows.Media.Imaging;
  26. using Path = System.IO.Path;
  27. using Point = System.Windows.Point;
  28. namespace PDFViewer
  29. {
  30. public partial class MainPage : UserControl, INotifyPropertyChanged
  31. {
  32. #region Property
  33. private bool isFirstLoad = true;
  34. private string currentMode = "Viewer";
  35. private PDFViewControl passwordViewer;
  36. private PDFViewControl pdfViewControl = new PDFViewControl();
  37. private CPDFAnnotationControl pdfAnnotationControl = null;
  38. private UIElement pdfEditControl = null;
  39. private CPDFPageEditControl pageEditControl = null;
  40. private FromPropertyControl pdfFormControl = new FromPropertyControl();
  41. private PDFImageEditControl imageEditControl = null;
  42. private CPDFDisplaySettingsControl displayPanel = null;
  43. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  44. public bool CanSave
  45. {
  46. get
  47. {
  48. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  49. {
  50. return pdfViewControl.PDFView.UndoManager.CanSave;
  51. }
  52. return false;
  53. }
  54. }
  55. public bool CanUndo
  56. {
  57. get
  58. {
  59. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  60. {
  61. return pdfViewControl.PDFView.UndoManager.CanUndo;
  62. }
  63. return false;
  64. }
  65. }
  66. public bool CanRedo
  67. {
  68. get
  69. {
  70. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  71. {
  72. return pdfViewControl.PDFView.UndoManager.CanRedo;
  73. }
  74. return false;
  75. }
  76. }
  77. private PDFEditEvent lastPDFEditEvent = null;
  78. public event Func<string[], bool> CheckExistBeforeOpenFileEvent;
  79. public event PropertyChangedEventHandler PropertyChanged;
  80. public event EventHandler FileChangeEvent;
  81. private PDFEditEvent pdfTextCreateParam;
  82. private PDFTextEditControl textEditControl = new PDFTextEditControl();
  83. private KeyEventHandler KeyDownHandler;
  84. #endregion
  85. public MainPage()
  86. {
  87. InitializeComponent();
  88. DataContext = this;
  89. if (pdfFormControl != null)
  90. {
  91. pdfFormControl = new FromPropertyControl();
  92. }
  93. }
  94. #region Initial Load Unload
  95. public void InitialPDFViewControl(PDFViewControl newPDFViewer)
  96. {
  97. pdfAnnotationControl.SetPDFViewer(newPDFViewer.PDFView);
  98. FormBarControl.InitWithPDFViewer(newPDFViewer.PDFView, pdfFormControl);
  99. pdfFormControl.SetPDFViewer(newPDFViewer.PDFView);
  100. pdfAnnotationControl.AnnotationCancel();
  101. AnnotationBarControl.ClearAllToolState();
  102. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  103. newPDFViewer.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
  104. newPDFViewer.CustomSignHandle = true;
  105. }
  106. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  107. {
  108. pdfAnnotationControl = new CPDFAnnotationControl();
  109. BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
  110. LoadDocument();
  111. }
  112. public void SetPDFViewer(PDFViewControl newPdfViewer)
  113. {
  114. if (newPdfViewer != null)
  115. {
  116. pdfViewControl = newPdfViewer;
  117. }
  118. }
  119. private void CPDFTitleBarControl_Loaded(object sender, RoutedEventArgs e)
  120. {
  121. CPDFTitleBarControl.OpenFileEvent -= CPDFTitleBarControl_OpenFileEvent;
  122. CPDFTitleBarControl.OpenFileEvent += CPDFTitleBarControl_OpenFileEvent;
  123. CPDFTitleBarControl.SaveAsFileEvent -= CPDFTitleBarControl_SaveAsFileEvent;
  124. CPDFTitleBarControl.SaveAsFileEvent += CPDFTitleBarControl_SaveAsFileEvent;
  125. CPDFTitleBarControl.SaveFileEvent -= CPDFTitleBarControl_SaveFileEvent;
  126. CPDFTitleBarControl.SaveFileEvent += CPDFTitleBarControl_SaveFileEvent; ;
  127. }
  128. private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
  129. {
  130. AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
  131. AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
  132. }
  133. private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
  134. {
  135. CPDFAnnotationType[] annotationProperties = { CPDFAnnotationType.Highlight, CPDFAnnotationType.Underline, CPDFAnnotationType.Strikeout, CPDFAnnotationType.Squiggly, CPDFAnnotationType.Freehand, CPDFAnnotationType.FreeText, CPDFAnnotationType.Note, CPDFAnnotationType.Circle, CPDFAnnotationType.Square, CPDFAnnotationType.Arrow, CPDFAnnotationType.Line, CPDFAnnotationType.Image, CPDFAnnotationType.Stamp, CPDFAnnotationType.Signature, CPDFAnnotationType.Link, CPDFAnnotationType.Audio };
  136. AnnotationBarControl.InitAnnotationBar(annotationProperties);
  137. AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
  138. AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
  139. }
  140. #endregion
  141. #region UI
  142. /// <summary>
  143. /// InfoChanged
  144. /// When the PDF zoom ratio changes, the value of the zoom control also changes.
  145. /// </summary>
  146. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  147. {
  148. if (e.Key == "Zoom")
  149. {
  150. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  151. }
  152. }
  153. private void EditLink_Click(object sender, RoutedEventArgs e)
  154. {
  155. RightPanelButton.IsChecked = true;
  156. PropertyContainer.Visibility = Visibility.Visible;
  157. }
  158. private double CheckZoomLevel(double zoom, bool IsGrowth)
  159. {
  160. double standardZoom = 100;
  161. if (zoom <= 0.01)
  162. {
  163. return 0.01;
  164. }
  165. if (zoom >= 10)
  166. {
  167. return 10;
  168. }
  169. zoom *= 100;
  170. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  171. {
  172. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  173. {
  174. standardZoom = zoomLevelList[i + 1];
  175. break;
  176. }
  177. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  178. {
  179. standardZoom = zoomLevelList[i];
  180. break;
  181. }
  182. }
  183. return standardZoom / 100;
  184. }
  185. private void PDFView_AnnotEditHandler(object sender, List<ComPDFKitViewer.AnnotEvent.AnnotEditEvent> e)
  186. {
  187. BotaSideTool.LoadAnnotationList();
  188. }
  189. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  190. {
  191. OnPropertyChanged(e.PropertyName);
  192. }
  193. private void PasswordUI_Closed(object sender, EventArgs e)
  194. {
  195. PopupBorder.Visibility = Visibility.Collapsed;
  196. PasswordUI.Visibility = Visibility.Collapsed;
  197. }
  198. private void PasswordUI_Canceled(object sender, EventArgs e)
  199. {
  200. PopupBorder.Visibility = Visibility.Collapsed;
  201. PasswordUI.Visibility = Visibility.Collapsed;
  202. }
  203. private void PasswordUI_Confirmed(object sender, string e)
  204. {
  205. if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
  206. {
  207. passwordViewer.PDFView.Document.UnlockWithPassword(e);
  208. if (passwordViewer.PDFView.Document.IsLocked == false)
  209. {
  210. PasswordUI.SetShowError("", Visibility.Collapsed);
  211. PasswordUI.ClearPassword();
  212. PasswordUI.Visibility = Visibility.Collapsed;
  213. PopupBorder.Visibility = Visibility.Collapsed;
  214. pdfViewControl = passwordViewer;
  215. LoadDocument();
  216. FileChangeEvent?.Invoke(null, EventArgs.Empty);
  217. }
  218. else
  219. {
  220. PasswordUI.SetShowError("error", Visibility.Visible);
  221. }
  222. }
  223. }
  224. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  225. {
  226. SaveFile();
  227. }
  228. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  229. {
  230. UIElement pageView = sender as UIElement;
  231. if (pageView != null)
  232. {
  233. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  234. }
  235. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  236. {
  237. if (imageEditControl == null)
  238. {
  239. imageEditControl = new PDFImageEditControl();
  240. }
  241. imageEditControl.InitWithPDFViewer(pdfViewControl.PDFView);
  242. imageEditControl.SetPDFImageEditData(lastPDFEditEvent);
  243. pdfEditControl = imageEditControl as UIElement;
  244. PropertyContainer.Child = pdfEditControl;
  245. }
  246. }
  247. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  248. {
  249. PasswordUI.Visibility = Visibility.Collapsed;
  250. FileInfoUI.Visibility = Visibility.Visible;
  251. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  252. PopupBorder.Visibility = Visibility.Visible;
  253. }
  254. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  255. {
  256. PopupBorder.Visibility = Visibility.Collapsed;
  257. }
  258. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  259. {
  260. ToggleButton senderBtn = sender as ToggleButton;
  261. if (senderBtn != null && pdfViewControl != null)
  262. {
  263. ClearPDFEditState(senderBtn);
  264. if (senderBtn.IsChecked == true)
  265. {
  266. PDFEditEvent createParam = new PDFEditEvent();
  267. createParam.EditType = CPDFEditType.EditText;
  268. createParam.IsBold = false;
  269. createParam.IsItalic = false;
  270. createParam.FontSize = 14;
  271. createParam.FontName = "Helvetica";
  272. createParam.FontColor = Colors.Black;
  273. createParam.TextAlign = TextAlignType.AlignLeft;
  274. createParam.Transparency = 255;
  275. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  276. {
  277. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  278. if (pdfDoc.PageCount > 0)
  279. {
  280. CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
  281. CPDFEditPage editPage = pdfPage.GetEditPage();
  282. editPage.BeginEdit(CPDFEditType.EditText);
  283. createParam.SystemFontNameList.AddRange(editPage.GetFontList());
  284. editPage.EndEdit();
  285. }
  286. }
  287. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  288. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
  289. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
  290. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  291. pdfViewControl.PDFView?.ReloadDocument();
  292. pdfViewControl.PDFView?.SetPDFEditParam(createParam);
  293. if (textEditControl == null)
  294. {
  295. textEditControl = new PDFTextEditControl();
  296. }
  297. textEditControl.SetPDFTextEditData(createParam);
  298. ExpandRightPropertyPanel(textEditControl, Visibility.Visible);
  299. if ((bool)ViewSettingBtn.IsChecked)
  300. {
  301. ViewSettingBtn.IsChecked = false;
  302. }
  303. RightPanelButton.IsChecked = true;
  304. pdfTextCreateParam = createParam;
  305. }
  306. else
  307. {
  308. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  309. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  310. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  311. pdfViewControl.PDFView?.ReloadDocument();
  312. LeftToolPanelButton.IsChecked = false;
  313. if ((bool)ViewSettingBtn.IsChecked)
  314. {
  315. return;
  316. }
  317. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  318. }
  319. }
  320. }
  321. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  322. {
  323. ToggleButton senderBtn = sender as ToggleButton;
  324. if (senderBtn != null && pdfViewControl != null)
  325. {
  326. senderBtn.IsChecked = false;
  327. OpenFileDialog openFileDialog = new OpenFileDialog();
  328. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  329. if (openFileDialog.ShowDialog() == true)
  330. {
  331. ClearPDFEditState(senderBtn);
  332. pdfViewControl.PDFView?.ClearSelectPDFEdit();
  333. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  334. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  335. pdfViewControl.PDFView?.ReloadDocument();
  336. RightPanelButton.IsChecked = false;
  337. if (PropertyContainer.Child != null && !(bool)ViewSettingBtn.IsChecked)
  338. {
  339. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  340. }
  341. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
  342. pdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
  343. }
  344. }
  345. }
  346. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  347. {
  348. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  349. {
  350. pdfViewControl.PDFView.UndoManager?.Undo();
  351. }
  352. }
  353. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  354. {
  355. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  356. {
  357. pdfViewControl.PDFView.UndoManager?.Redo();
  358. }
  359. }
  360. private void ClearPDFEditState(ToggleButton ignoreBtn = null)
  361. {
  362. List<ToggleButton> clearBtnList = new List<ToggleButton>()
  363. {
  364. PDFTextEditButton,
  365. PDFImageEditButton
  366. };
  367. foreach (ToggleButton item in clearBtnList)
  368. {
  369. if (ignoreBtn == item)
  370. {
  371. continue;
  372. }
  373. item.IsChecked = false;
  374. }
  375. }
  376. private void PdfAnnotationControl_ClearAnnotationBar(object sender, EventArgs e)
  377. {
  378. AnnotationBarControl.ClearAllToolState();
  379. }
  380. private void AnnotationBarControl_AnnotationCancel(object sender, EventArgs e)
  381. {
  382. pdfAnnotationControl.AnnotationCancel();
  383. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  384. RightPanelButton.IsChecked = false;
  385. ViewSettingBtn.IsChecked = false;
  386. }
  387. #endregion
  388. #region ContextMenu
  389. /// <summary>
  390. /// Annotation Context menu
  391. /// </summary>
  392. private void PDFView_AnnotCommandHandler(object sender, ComPDFKitViewer.AnnotEvent.AnnotCommandArgs e)
  393. {
  394. switch (e.CommandType)
  395. {
  396. case CommandType.Context:
  397. e.Handle = true;
  398. if (e.CommandTarget == TargetType.Annot)
  399. {
  400. e.Handle = true;
  401. e.PopupMenu = new ContextMenu();
  402. if (e.PressOnLink && AnnotationBarControl.CurrentMode == "Link")
  403. {
  404. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  405. MenuItem propertyMenu = new MenuItem();
  406. propertyMenu = new MenuItem();
  407. propertyMenu.Header = "Edit";
  408. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(propertyMenu, "Click", EditLink_Click);
  409. propertyMenu.CommandParameter = e;
  410. e.PopupMenu.Items.Add(propertyMenu);
  411. }
  412. else if (e.PressOnAnnot)
  413. {
  414. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  415. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  416. e.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  417. }
  418. else if (e.PressOnMedia || e.PressOnSound)
  419. {
  420. e.Handle = true;
  421. e.PopupMenu.Items.Add(new MenuItem() { Header = "Play", Command = MediaCommands.Play, CommandTarget = (UIElement)sender, CommandParameter = e });
  422. e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  423. }
  424. else if (e.PressOnSelectedText)
  425. {
  426. e.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  427. }
  428. else
  429. {
  430. e.Handle = true;
  431. e.PopupMenu = new ContextMenu();
  432. if (currentMode == "Annotations")
  433. {
  434. e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  435. e.PopupMenu.Items.Add(new Separator());
  436. }
  437. MenuItem fitWidthMenu = new MenuItem();
  438. fitWidthMenu.Header = "Automatically Resize";
  439. fitWidthMenu.Click += (o, p) =>
  440. {
  441. if (pdfViewControl != null)
  442. {
  443. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  444. }
  445. };
  446. e.PopupMenu.Items.Add(fitWidthMenu);
  447. MenuItem fitSizeMenu = new MenuItem();
  448. fitSizeMenu.Header = "Actual Size";
  449. fitSizeMenu.Click += (o, p) =>
  450. {
  451. if (pdfViewControl != null)
  452. {
  453. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  454. }
  455. };
  456. e.PopupMenu.Items.Add(fitSizeMenu);
  457. MenuItem zoomInMenu = new MenuItem();
  458. zoomInMenu.Header = "Zoom In";
  459. zoomInMenu.Click += (o, p) =>
  460. {
  461. if (pdfViewControl != null)
  462. {
  463. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  464. pdfViewControl.PDFView?.Zoom(newZoom);
  465. }
  466. };
  467. e.PopupMenu.Items.Add(zoomInMenu);
  468. MenuItem zoomOutMenu = new MenuItem();
  469. zoomOutMenu.Header = "Zoom Out";
  470. zoomOutMenu.Click += (o, p) =>
  471. {
  472. if (pdfViewControl != null)
  473. {
  474. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  475. pdfViewControl.PDFView?.Zoom(newZoom);
  476. }
  477. };
  478. e.PopupMenu.Items.Add(zoomOutMenu);
  479. e.PopupMenu.Items.Add(new Separator());
  480. MenuItem singleView = new MenuItem();
  481. singleView.Header = "Single Page";
  482. singleView.Click += (o, p) =>
  483. {
  484. if (pdfViewControl != null)
  485. {
  486. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  487. }
  488. };
  489. e.PopupMenu.Items.Add(singleView);
  490. MenuItem singleContinuousView = new MenuItem();
  491. singleContinuousView.Header = "Single Page Continuous";
  492. singleContinuousView.Click += (o, p) =>
  493. {
  494. if (pdfViewControl != null)
  495. {
  496. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  497. }
  498. };
  499. e.PopupMenu.Items.Add(singleContinuousView);
  500. MenuItem doubleView = new MenuItem();
  501. doubleView.Header = "Two Pages";
  502. doubleView.Click += (o, p) =>
  503. {
  504. if (pdfViewControl != null)
  505. {
  506. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  507. }
  508. };
  509. e.PopupMenu.Items.Add(doubleView);
  510. MenuItem doubleContinuousView = new MenuItem();
  511. doubleContinuousView.Header = "Two Pages Continuous";
  512. doubleContinuousView.Click += (o, p) =>
  513. {
  514. if (pdfViewControl != null)
  515. {
  516. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  517. }
  518. };
  519. e.PopupMenu.Items.Add(doubleContinuousView);
  520. }
  521. }
  522. else if (e.CommandTarget == TargetType.ImageSelection)
  523. {
  524. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.GetSelectImageCount() > 0)
  525. {
  526. e.Handle = true;
  527. e.PopupMenu = new ContextMenu();
  528. MenuItem imageCopyMenu = new MenuItem();
  529. imageCopyMenu = new MenuItem();
  530. imageCopyMenu.Header = "Copy Images";
  531. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  532. imageCopyMenu.CommandParameter = e;
  533. e.PopupMenu.Items.Add(imageCopyMenu);
  534. MenuItem imageExtraMenu = new MenuItem();
  535. imageExtraMenu = new MenuItem();
  536. imageExtraMenu.Header = "Extract Images";
  537. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  538. imageExtraMenu.CommandParameter = e;
  539. e.PopupMenu.Items.Add(imageExtraMenu);
  540. }
  541. }
  542. break;
  543. case CommandType.Copy:
  544. e.DoCommand();
  545. break;
  546. case CommandType.Cut:
  547. case CommandType.Paste:
  548. case CommandType.Delete:
  549. e.DoCommand();
  550. break;
  551. default:
  552. break;
  553. }
  554. }
  555. /// <summary>
  556. /// TextEdit context menu.
  557. /// </summary>
  558. private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
  559. {
  560. editCommand.PopupMenu = new ContextMenu();
  561. if (lastPDFEditEvent != null)
  562. {
  563. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  564. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  565. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  566. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  567. }
  568. else
  569. {
  570. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  571. if (editCommand.TextAreaCopied)
  572. {
  573. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  574. }
  575. }
  576. }
  577. /// <summary>
  578. /// ImageEdit right-click menu.
  579. /// </summary>
  580. private void PDFEditImageContextMenu(object sender, PDFEditCommand editCommand)
  581. {
  582. editCommand.PopupMenu = new ContextMenu();
  583. if (lastPDFEditEvent != null)
  584. {
  585. MenuItem rotateLeftMenu = new MenuItem();
  586. rotateLeftMenu.Header = "Left Rotate";
  587. rotateLeftMenu.Click += (o, p) =>
  588. {
  589. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  590. {
  591. lastPDFEditEvent.Rotate = -90;
  592. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  593. imageEditControl?.SetImageThumb();
  594. }
  595. };
  596. editCommand.PopupMenu.Items.Add(rotateLeftMenu);
  597. MenuItem rotateRightMenu = new MenuItem();
  598. rotateRightMenu.Header = "Right Rotate";
  599. rotateRightMenu.Click += (o, p) =>
  600. {
  601. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  602. {
  603. lastPDFEditEvent.Rotate = 90;
  604. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  605. imageEditControl?.SetImageThumb();
  606. }
  607. };
  608. editCommand.PopupMenu.Items.Add(rotateRightMenu);
  609. MenuItem replaceMenu = new MenuItem();
  610. replaceMenu.Header = "Replace";
  611. replaceMenu.Click += (o, p) =>
  612. {
  613. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  614. {
  615. OpenFileDialog openFileDialog = new OpenFileDialog();
  616. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  617. if (openFileDialog.ShowDialog() == true)
  618. {
  619. lastPDFEditEvent.ReplaceImagePath = openFileDialog.FileName;
  620. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  621. pdfViewControl.PDFView?.ClearSelectPDFEdit();
  622. imageEditControl?.SetImageThumb();
  623. }
  624. }
  625. };
  626. editCommand.PopupMenu.Items.Add(replaceMenu);
  627. MenuItem exportMenu = new MenuItem();
  628. exportMenu.Header = "Export";
  629. exportMenu.Click += (o, p) =>
  630. {
  631. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  632. {
  633. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView.GetSelectedImages();
  634. if (imageDict != null && imageDict.Count > 0)
  635. {
  636. System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
  637. if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  638. {
  639. string choosePath = folderBrowser.SelectedPath;
  640. string openPath = choosePath;
  641. foreach (int pageIndex in imageDict.Keys)
  642. {
  643. List<Bitmap> imageList = imageDict[pageIndex];
  644. foreach (Bitmap image in imageList)
  645. {
  646. string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  647. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  648. openPath = savePath;
  649. }
  650. }
  651. Process.Start("explorer", "/select,\"" + openPath + "\"");
  652. }
  653. }
  654. }
  655. };
  656. editCommand.PopupMenu.Items.Add(exportMenu);
  657. MenuItem opacityMenu = new MenuItem();
  658. opacityMenu.Header = "Opacity";
  659. editCommand.PopupMenu.Items.Add(opacityMenu);
  660. AppendOpacityMenu(opacityMenu);
  661. MenuItem horizonMirror = new MenuItem();
  662. horizonMirror.Header = "HMirror";
  663. horizonMirror.Click += (o, p) =>
  664. {
  665. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  666. {
  667. lastPDFEditEvent.HorizontalMirror = true;
  668. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  669. }
  670. };
  671. editCommand.PopupMenu.Items.Add(horizonMirror);
  672. MenuItem verticalMirror = new MenuItem();
  673. verticalMirror.Header = "VMirror";
  674. verticalMirror.Click += (o, p) =>
  675. {
  676. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  677. {
  678. lastPDFEditEvent.VerticalMirror = true;
  679. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  680. }
  681. };
  682. editCommand.PopupMenu.Items.Add(verticalMirror);
  683. MenuItem cropMenu = new MenuItem();
  684. cropMenu.Header = "Crop";
  685. cropMenu.Click += (o, p) =>
  686. {
  687. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  688. {
  689. lastPDFEditEvent.ClipImage = true;
  690. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  691. }
  692. };
  693. editCommand.PopupMenu.Items.Add(cropMenu);
  694. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  695. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  696. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  697. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  698. }
  699. else
  700. {
  701. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  702. }
  703. }
  704. /// <summary>
  705. /// ImageEdit transparency submenu.
  706. /// </summary>
  707. private void AppendOpacityMenu(MenuItem parentMenu)
  708. {
  709. List<int> opacityList = new List<int>()
  710. {
  711. 25,50,75,100
  712. };
  713. foreach (int opacity in opacityList)
  714. {
  715. MenuItem opacityMenu = new MenuItem();
  716. opacityMenu.Header = string.Format("{0}%", opacity);
  717. opacityMenu.Click += (o, p) =>
  718. {
  719. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  720. {
  721. lastPDFEditEvent.Transparency = (int)Math.Ceiling(opacity * 255 / 100D);
  722. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  723. }
  724. };
  725. parentMenu.Items.Add(opacityMenu);
  726. }
  727. }
  728. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  729. {
  730. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  731. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  732. {
  733. string choosePath = folderDialog.SelectedPath;
  734. string openPath = choosePath;
  735. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  736. if (imageDict != null && imageDict.Count > 0)
  737. {
  738. foreach (int pageIndex in imageDict.Keys)
  739. {
  740. List<Bitmap> imageList = imageDict[pageIndex];
  741. foreach (Bitmap image in imageList)
  742. {
  743. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  744. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  745. openPath = savePath;
  746. }
  747. }
  748. }
  749. Process.Start("explorer", "/select,\"" + openPath + "\"");
  750. }
  751. }
  752. private void CopyImage_Click(object sender, RoutedEventArgs e)
  753. {
  754. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  755. if (imageDict != null && imageDict.Count > 0)
  756. {
  757. foreach (int pageIndex in imageDict.Keys)
  758. {
  759. List<Bitmap> imageList = imageDict[pageIndex];
  760. foreach (Bitmap image in imageList)
  761. {
  762. MemoryStream ms = new MemoryStream();
  763. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  764. BitmapImage imageData = new BitmapImage();
  765. imageData.BeginInit();
  766. imageData.StreamSource = ms;
  767. imageData.CacheOption = BitmapCacheOption.OnLoad;
  768. imageData.EndInit();
  769. imageData.Freeze();
  770. Clipboard.SetImage(imageData);
  771. break;
  772. }
  773. }
  774. }
  775. }
  776. #endregion
  777. #region Property changed
  778. protected void OnPropertyChanged([CallerMemberName] string name = null)
  779. {
  780. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  781. }
  782. #endregion
  783. #region Open and save file
  784. public void InitWithFilePath(string filePath)
  785. {
  786. pdfViewControl = new PDFViewControl();
  787. pdfViewControl.PDFView.InitDocument(filePath);
  788. }
  789. private void LoadDocument()
  790. {
  791. //Load the Document
  792. pdfViewControl.PDFView?.Load();
  793. //Highlight the link annotation
  794. pdfViewControl.PDFView?.SetShowLink(true);
  795. //Add PDFViewControl to PDFGrid
  796. PDFGrid.Child = pdfViewControl;
  797. // Register the InfoChanged event handler,
  798. // which is used to notify the CPDFScalingControl of real-time changes in the displayed number when the page size changes.
  799. pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
  800. pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
  801. //
  802. pdfViewControl.PDFView.PDFEditCommandHandler -= PDFView_PDFEditCommandHandler;
  803. pdfViewControl.PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
  804. //
  805. pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  806. pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  807. //Can undo, can redo
  808. pdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  809. pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  810. pdfViewControl.PDFView.SetFormFieldHighlight(true);
  811. PasswordUI.Closed -= PasswordUI_Closed;
  812. PasswordUI.Canceled -= PasswordUI_Canceled;
  813. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  814. PasswordUI.Confirmed += PasswordUI_Confirmed;
  815. PasswordUI.Canceled += PasswordUI_Canceled;
  816. PasswordUI.Closed += PasswordUI_Closed;
  817. pdfViewControl.PDFView.ChangeFitMode(FitMode.FitWidth);
  818. CPDFSaclingControl.InitWithPDFViewer(pdfViewControl.PDFView);
  819. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
  820. InitialPDFViewControl(pdfViewControl);
  821. pdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  822. FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
  823. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  824. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  825. ViewSettingBtn.IsChecked = false;
  826. PropertyContainer.Child = null;
  827. PropertyContainer.Visibility = Visibility.Collapsed;
  828. ModeComboBox.SelectedIndex = 0;
  829. if (KeyDownHandler != null)
  830. {
  831. pdfViewControl.PDFView.RemoveHandler(KeyDownEvent, KeyDownHandler);
  832. }
  833. KeyDownHandler = new KeyEventHandler(PDFView_KeyDown);
  834. pdfViewControl.PDFView.AddHandler(KeyDownEvent, KeyDownHandler, false, true);
  835. }
  836. /// <summary>
  837. /// Save the file to another PDF file.
  838. /// </summary>
  839. public void SaveAsFile()
  840. {
  841. {
  842. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  843. {
  844. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  845. SaveFileDialog saveDialog = new SaveFileDialog();
  846. saveDialog.Filter = "(*.pdf)|*.pdf";
  847. saveDialog.DefaultExt = ".pdf";
  848. saveDialog.OverwritePrompt = true;
  849. if (saveDialog.ShowDialog() == true)
  850. {
  851. pdfDoc.WriteToFilePath(saveDialog.FileName);
  852. }
  853. }
  854. }
  855. }
  856. /// <summary>
  857. /// Save the file in the current path.
  858. /// </summary>
  859. public void SaveFile()
  860. {
  861. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  862. {
  863. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  864. if (pdfDoc.WriteToLoadedPath())
  865. {
  866. pdfViewControl.PDFView.UndoManager.CanSave = false;
  867. return;
  868. }
  869. SaveFileDialog saveDialog = new SaveFileDialog();
  870. saveDialog.Filter = "(*.pdf)|*.pdf";
  871. saveDialog.DefaultExt = ".pdf";
  872. saveDialog.OverwritePrompt = true;
  873. if (saveDialog.ShowDialog() == true)
  874. {
  875. pdfDoc.WriteToFilePath(saveDialog.FileName);
  876. }
  877. }
  878. }
  879. public void OpenFile()
  880. {
  881. string filePath = CommonHelper.GetFilePathOrEmpty();
  882. string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
  883. if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
  884. {
  885. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  886. {
  887. if (oldFilePath.ToLower() == filePath.ToLower())
  888. {
  889. return;
  890. }
  891. }
  892. if ((bool)CheckExistBeforeOpenFileEvent?.Invoke(new string[] { filePath, oldFilePath }))
  893. {
  894. return;
  895. }
  896. passwordViewer = new PDFViewControl();
  897. passwordViewer.PDFView.InitDocument(filePath);
  898. if (passwordViewer.PDFView.Document == null)
  899. {
  900. MessageBox.Show("Open File Failed");
  901. return;
  902. }
  903. if (passwordViewer.PDFView.Document.IsLocked)
  904. {
  905. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
  906. PasswordUI.ClearPassword();
  907. PopupBorder.Visibility = Visibility.Visible;
  908. PasswordUI.Visibility = Visibility.Visible;
  909. }
  910. else
  911. {
  912. pdfViewControl = passwordViewer;
  913. LoadDocument();
  914. FileChangeEvent?.Invoke(null, EventArgs.Empty);
  915. }
  916. }
  917. }
  918. private void OpenFile_Click(object sender, RoutedEventArgs e)
  919. {
  920. OpenFile();
  921. }
  922. #endregion
  923. #region ToolPanel expand and collapse
  924. private void ExpandLeftPanel(bool isExpand)
  925. {
  926. BotaSideTool.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  927. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  928. if (isExpand)
  929. {
  930. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  931. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  932. }
  933. else
  934. {
  935. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  936. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  937. }
  938. }
  939. private void ControlLeftPanel()
  940. {
  941. if (LeftToolPanelButton != null)
  942. {
  943. bool isExpand = LeftToolPanelButton.IsChecked == true;
  944. ExpandLeftPanel(isExpand);
  945. }
  946. }
  947. private void ControlRightPanel()
  948. {
  949. if (RightPanelButton != null)
  950. {
  951. if (RightPanelButton.IsChecked == true)
  952. {
  953. if (currentMode == "Annotation")
  954. {
  955. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  956. }
  957. else if (currentMode == "Edit")
  958. {
  959. ExpandRightPropertyPanel(pdfEditControl, Visibility.Visible);
  960. }
  961. else if (currentMode == "Forms")
  962. {
  963. ExpandRightPropertyPanel(pdfFormControl, Visibility.Visible);
  964. }
  965. else
  966. {
  967. bool expandEmpty = true;
  968. if (currentMode == "Content Editor")
  969. {
  970. if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
  971. {
  972. if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  973. {
  974. if (textEditControl == null)
  975. {
  976. textEditControl = new PDFTextEditControl();
  977. }
  978. textEditControl.SetPDFTextEditData(pdfTextCreateParam);
  979. ExpandRightPropertyPanel(textEditControl, Visibility.Visible);
  980. expandEmpty = false;
  981. }
  982. }
  983. }
  984. if (expandEmpty)
  985. {
  986. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  987. }
  988. }
  989. if ((bool)ViewSettingBtn.IsChecked)
  990. {
  991. ViewSettingBtn.IsChecked = false;
  992. }
  993. }
  994. else
  995. {
  996. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  997. }
  998. }
  999. }
  1000. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  1001. {
  1002. ControlLeftPanel();
  1003. }
  1004. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  1005. {
  1006. ExpandLeftPanel(true);
  1007. LeftToolPanelButton.IsChecked = true;
  1008. BotaSideTool.SelectBotaTool(BOTATools.Search);
  1009. }
  1010. private void ShowViewSettings()
  1011. {
  1012. if (ViewSettingBtn != null)
  1013. {
  1014. if (ViewSettingBtn.IsChecked == true)
  1015. {
  1016. displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
  1017. PropertyContainer.Child = displayPanel;
  1018. PropertyContainer.Visibility = Visibility.Visible;
  1019. if ((bool)RightPanelButton.IsChecked)
  1020. {
  1021. RightPanelButton.IsChecked = false;
  1022. }
  1023. }
  1024. else
  1025. {
  1026. PropertyContainer.Child = null;
  1027. PropertyContainer.Visibility = Visibility.Collapsed;
  1028. }
  1029. }
  1030. }
  1031. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  1032. {
  1033. ShowViewSettings();
  1034. }
  1035. public void ExpandRightPropertyPanel(UIElement properytPanel, Visibility visible)
  1036. {
  1037. PropertyContainer.Width = 260;
  1038. PropertyContainer.Child = properytPanel;
  1039. PropertyContainer.Visibility = visible;
  1040. if (visible == Visibility.Hidden || visible == Visibility.Collapsed)
  1041. {
  1042. RightPanelButton.IsChecked = false;
  1043. }
  1044. }
  1045. private void RightPanelButton_Click(object sender, RoutedEventArgs e)
  1046. {
  1047. ControlRightPanel();
  1048. }
  1049. #endregion
  1050. #region Event handle
  1051. private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
  1052. {
  1053. pdfAnnotationControl.LoadAnnotationPanel(e);
  1054. if (e != CPDFAnnotationType.Audio && e != CPDFAnnotationType.Image)
  1055. {
  1056. ExpandRightPropertyPanel(pdfAnnotationControl, Visibility.Visible);
  1057. RightPanelButton.IsChecked = true;
  1058. }
  1059. }
  1060. private void PDFView_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  1061. {
  1062. if ((bool)ViewSettingBtn.IsChecked)
  1063. {
  1064. ViewSettingBtn.IsChecked= false;
  1065. RightPanelButton.IsChecked= true;
  1066. }
  1067. PropertyContainer.Child = pdfAnnotationControl;
  1068. pdfAnnotationControl.SetAnnotEventData(e);
  1069. }
  1070. private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
  1071. {
  1072. if (e is WidgetSignArgs)
  1073. {
  1074. RightPanelButton.IsChecked = true;
  1075. ExpandRightPropertyPanel(pdfFormControl, Visibility.Visible);
  1076. pdfFormControl.SetPropertyForType(e, null);
  1077. }
  1078. else
  1079. {
  1080. RightPanelButton.IsChecked = false;
  1081. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1082. }
  1083. }
  1084. private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
  1085. {
  1086. if (e == null)
  1087. {
  1088. return;
  1089. }
  1090. if (e.EditType == CPDFEditType.EditText)
  1091. {
  1092. e.Handle = true;
  1093. PDFEditTextContextMenu(sender, e);
  1094. }
  1095. if (e.EditType == CPDFEditType.EditImage)
  1096. {
  1097. e.Handle = true;
  1098. PDFEditImageContextMenu(sender, e);
  1099. }
  1100. }
  1101. /// <summary>
  1102. /// Text and Image Selected Event
  1103. /// </summary>
  1104. private void PDFView_PDFEditActiveHandler(object sender, ComPDFKitViewer.PDFEditEvent e)
  1105. {
  1106. lastPDFEditEvent = e;
  1107. if ((bool)ViewSettingBtn.IsChecked)
  1108. {
  1109. ViewSettingBtn.IsChecked = false;
  1110. RightPanelButton.IsChecked = true;
  1111. }
  1112. if (e == null)
  1113. {
  1114. pdfEditControl = null;
  1115. PropertyContainer.Child = pdfEditControl;
  1116. if (pdfTextCreateParam != null && pdfViewControl != null && pdfViewControl.PDFView != null)
  1117. {
  1118. if (pdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  1119. {
  1120. if (textEditControl == null)
  1121. {
  1122. textEditControl = new PDFTextEditControl();
  1123. }
  1124. textEditControl.SetPDFTextEditData(pdfTextCreateParam);
  1125. PropertyContainer.Child = textEditControl;
  1126. }
  1127. }
  1128. return;
  1129. }
  1130. if (Mouse.RightButton == MouseButtonState.Pressed)
  1131. {
  1132. return;
  1133. }
  1134. if (e.EditType == CPDFEditType.EditText)
  1135. {
  1136. if (textEditControl == null)
  1137. {
  1138. textEditControl = new PDFTextEditControl();
  1139. }
  1140. textEditControl.SetPDFTextEditData(e);
  1141. pdfEditControl = textEditControl as UIElement;
  1142. PropertyContainer.Child = pdfEditControl;
  1143. return;
  1144. }
  1145. if (e.EditType == CPDFEditType.EditImage && pdfViewControl != null)
  1146. {
  1147. RightPanelButton.IsChecked = true;
  1148. UIElement pageView = sender as UIElement;
  1149. if (pageView != null)
  1150. {
  1151. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp; ;
  1152. }
  1153. return;
  1154. }
  1155. }
  1156. private void PDFView_FormEditHandler(object sender, List<AnnotEditEvent> e)
  1157. {
  1158. if (e != null && e.Count > 0)
  1159. {
  1160. AnnotEditEvent editEvent = e[e.Count - 1];
  1161. if (editEvent.EditAction == ActionType.Add)
  1162. {
  1163. pdfViewControl.PDFView.SelectAnnotation(editEvent.PageIndex, editEvent.AnnotIndex);
  1164. }
  1165. }
  1166. }
  1167. private void PDFView_FormActiveHandler(object sender, AnnotAttribEvent e)
  1168. {
  1169. if (e == null || e.IsAnnotCreateReset)
  1170. {
  1171. pdfFormControl.SetPropertyForType(null, null);
  1172. }
  1173. else
  1174. {
  1175. switch (e.GetAnnotTypes())
  1176. {
  1177. case AnnotArgsType.WidgetViewForm:
  1178. WidgetArgs formArgs = e.GetAnnotHandlerEventArgs(AnnotArgsType.WidgetViewForm).First() as WidgetArgs;
  1179. switch (formArgs.WidgeType)
  1180. {
  1181. case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  1182. case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_COMBOBOX:
  1183. case ComPDFKit.PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_LISTBOX:
  1184. ExpandRightPropertyPanel(pdfFormControl, Visibility.Visible);
  1185. if ((bool)ViewSettingBtn.IsChecked)
  1186. {
  1187. ViewSettingBtn.IsChecked = false;
  1188. }
  1189. RightPanelButton.IsChecked = true;
  1190. break;
  1191. default:
  1192. break;
  1193. }
  1194. pdfFormControl.SetPropertyForType(formArgs, e);
  1195. break;
  1196. }
  1197. }
  1198. }
  1199. private void PageEditControl_ExitPageEdit(object sender, EventArgs e)
  1200. {
  1201. ModeComboBox.SelectedIndex = 0;
  1202. }
  1203. private void PageEditControl_PageMoved(object sender, RoutedEventArgs e)
  1204. {
  1205. if (pdfViewControl == null || pdfViewControl.PDFView == null)
  1206. {
  1207. return;
  1208. }
  1209. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  1210. }
  1211. private void CPDFPageEditBarControl_PageEditEvent(object sender, string e)
  1212. {
  1213. pageEditControl.PageEdit(e);
  1214. }
  1215. private void CPDFTitleBarControl_SaveFileEvent(object sender, EventArgs e)
  1216. {
  1217. SaveFile();
  1218. }
  1219. private void CPDFTitleBarControl_SaveAsFileEvent(object sender, EventArgs e)
  1220. {
  1221. SaveAsFile();
  1222. }
  1223. private void CPDFTitleBarControl_OpenFileEvent(object sender, EventArgs e)
  1224. {
  1225. OpenFile();
  1226. }
  1227. public void PDFView_KeyDown(object sender, KeyEventArgs e)
  1228. {
  1229. if (pdfViewControl.PDFView.MouseMode != MouseModes.PDFEdit)
  1230. {
  1231. return;
  1232. }
  1233. if (Keyboard.Modifiers == ModifierKeys.Control)
  1234. {
  1235. if (e.Key == Key.Left)
  1236. {
  1237. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, false);
  1238. e.Handled = true;
  1239. }
  1240. if (e.Key == Key.Right)
  1241. {
  1242. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, false);
  1243. e.Handled = true;
  1244. }
  1245. if (e.Key == Key.Up)
  1246. {
  1247. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, false);
  1248. e.Handled = true;
  1249. }
  1250. if (e.Key == Key.Down)
  1251. {
  1252. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, false);
  1253. e.Handled = true;
  1254. }
  1255. }
  1256. if (Keyboard.Modifiers == ModifierKeys.Shift)
  1257. {
  1258. if (e.Key == Key.Left)
  1259. {
  1260. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreCharPlace, false);
  1261. e.Handled = true;
  1262. }
  1263. if (e.Key == Key.Right)
  1264. {
  1265. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextCharPlace, false);
  1266. e.Handled = true;
  1267. }
  1268. if (e.Key == Key.Up)
  1269. {
  1270. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeUpCharPlace, false);
  1271. e.Handled = true;
  1272. }
  1273. if (e.Key == Key.Down)
  1274. {
  1275. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeDownCharPlace, false);
  1276. e.Handled = true;
  1277. }
  1278. }
  1279. if (Keyboard.Modifiers == ModifierKeys.Alt)
  1280. {
  1281. if (e.SystemKey == Key.Up)
  1282. {
  1283. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLocationLineBegin, false);
  1284. e.Handled = true;
  1285. }
  1286. if (e.SystemKey == Key.Down)
  1287. {
  1288. pdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeLineEnd, false);
  1289. e.Handled = true;
  1290. }
  1291. }
  1292. if (Keyboard.Modifiers == ModifierKeys.None)
  1293. {
  1294. if (e.Key == Key.Left)
  1295. {
  1296. pdfViewControl.PDFView.MoveEditArea(new Point(-5, 0));
  1297. e.Handled = true;
  1298. }
  1299. if (e.Key == Key.Right)
  1300. {
  1301. pdfViewControl.PDFView.MoveEditArea(new Point(5, 0));
  1302. e.Handled = true;
  1303. }
  1304. if (e.Key == Key.Up)
  1305. {
  1306. pdfViewControl.PDFView.MoveEditArea(new Point(0, -5));
  1307. e.Handled = true;
  1308. }
  1309. if (e.Key == Key.Down)
  1310. {
  1311. pdfViewControl.PDFView.MoveEditArea(new Point(0, 5));
  1312. e.Handled = true;
  1313. }
  1314. }
  1315. }
  1316. #endregion
  1317. #region Change mode
  1318. /// <summary>
  1319. /// Actions performed when switching modes:
  1320. /// Separated into actions performed upon entering and exiting the mode.
  1321. /// </summary>
  1322. private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  1323. {
  1324. pdfTextCreateParam = null;
  1325. if (isFirstLoad)
  1326. {
  1327. isFirstLoad = false;
  1328. return;
  1329. }
  1330. var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
  1331. //Behavior when exit mode
  1332. switch (currentMode)
  1333. {
  1334. case "Viewer":
  1335. break;
  1336. /*
  1337. * Behavior when exit Edit mode
  1338. * Clear and collapse the ToolBar
  1339. * Clear And collapse the property panel.
  1340. * Change the mousemode to PanTool
  1341. * Unsubscribe the event handles
  1342. * Clear the undo history
  1343. */
  1344. case "Annotations":
  1345. AnnotationBarControl.Visibility = Visibility.Collapsed;
  1346. AnnotationBarControl.ClearAllToolState();
  1347. pdfAnnotationControl.ClearPanel();
  1348. if (!(bool)ViewSettingBtn.IsChecked)
  1349. {
  1350. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1351. }
  1352. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1353. pdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
  1354. pdfAnnotationControl.ClearAnnotationBar -= PdfAnnotationControl_ClearAnnotationBar;
  1355. pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
  1356. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1357. break;
  1358. /*
  1359. * Behavior when exit edit mode:
  1360. * Collapsed the ToolBar
  1361. * Highlight the link annotation
  1362. * Set the mode to not allow edit
  1363. * Set the mouse mode to PanTool
  1364. * Reload Document
  1365. * Unsubscribe click event.
  1366. * Clear And collapse the property panel.
  1367. * Clear and collapse the ToolBar
  1368. * Clear undo history
  1369. * CPDFDisplaySettingsControl
  1370. * Enable the configuration of the split view.
  1371. */
  1372. case "Content Editor":
  1373. PDFEditTool.Visibility = Visibility.Collapsed;
  1374. pdfViewControl.PDFView?.SetShowLink(true);
  1375. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.None);
  1376. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1377. pdfViewControl.PDFView?.ReloadDocument();
  1378. pdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
  1379. if (!(bool)ViewSettingBtn.IsChecked)
  1380. {
  1381. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1382. }
  1383. ClearPDFEditState();
  1384. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1385. if (displayPanel != null)
  1386. {
  1387. displayPanel.SetVisibilityWhenContentEdit(Visibility.Visible);
  1388. }
  1389. break;
  1390. /*
  1391. * Behavior when exit form mode:
  1392. * Clear and collapsed the ToolBar
  1393. * Clear And Collapse the property panel.
  1394. * Unsubscribe event.
  1395. * Clear undo history
  1396. */
  1397. case "Forms":
  1398. if (!(bool)ViewSettingBtn.IsChecked)
  1399. {
  1400. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1401. }
  1402. FormBarControl.ClearAllToolState();
  1403. FormBarControl.Visibility = Visibility.Collapsed;
  1404. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  1405. pdfViewControl.PDFView.AnnotActiveHandler -= PDFView_FormActiveHandler;
  1406. pdfViewControl.PDFView.AnnotEditHandler -= PDFView_FormEditHandler;
  1407. pdfViewControl.PDFView?.UndoManager.ClearHistory();
  1408. break;
  1409. /*
  1410. * Unsubscribe event.
  1411. * Show Undo Redo Button
  1412. * Collapse PageEditBarControl
  1413. * Replace PDFGrid.Child to pdfViewControl.
  1414. * Reload Document
  1415. * Enable Button
  1416. */
  1417. case "Docs Editor":
  1418. pageEditControl.ExitPageEdit -= PageEditControl_ExitPageEdit;
  1419. pageEditControl.PageMoved -= PageEditControl_PageMoved;
  1420. PageEditBarControl.PageEditEvent -= CPDFPageEditBarControl_PageEditEvent;
  1421. UndoRedoStackPanel.Visibility = Visibility.Visible;
  1422. PageEditBarControl.Visibility = Visibility.Collapsed;
  1423. PDFGrid.Child = pdfViewControl;
  1424. FloatPageTool.Visibility = Visibility.Visible;
  1425. pdfViewControl.PDFView.ReloadDocument();
  1426. LeftToolPanelButton.IsEnabled = true;
  1427. SearchButton.IsEnabled = true;
  1428. RightPanelButton.IsEnabled = true;
  1429. ViewSettingBtn.IsEnabled = true;
  1430. break;
  1431. default:
  1432. break;
  1433. }
  1434. /*
  1435. * Behavior when switching to Viewer mode:
  1436. * Hide the ToolBar
  1437. * Set mousemode to Viewer
  1438. */
  1439. if ((string)item.Content == "Viewer")
  1440. {
  1441. ToolBarContainer.Visibility = Visibility.Collapsed;
  1442. pdfViewControl.PDFView.SetMouseMode(MouseModes.Viewer);
  1443. }
  1444. /*
  1445. * Behavior when switching to Annotation mode:
  1446. * Show the ToolBar
  1447. * Show the AnnotationBar
  1448. */
  1449. else if ((string)item.Content == "Annotations")
  1450. {
  1451. ToolBarContainer.Visibility = Visibility.Visible;
  1452. AnnotationBarControl.Visibility = Visibility.Visible;
  1453. pdfViewControl.PDFView.SetMouseMode(MouseModes.PanTool);
  1454. pdfAnnotationControl.ClearAnnotationBar += PdfAnnotationControl_ClearAnnotationBar;
  1455. pdfViewControl.PDFView.AnnotEditHandler += PDFView_AnnotEditHandler;
  1456. pdfViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
  1457. }
  1458. /*
  1459. * Behavior when switching to Edit mode:
  1460. * Show the ToolBar
  1461. * Show the EditBar
  1462. * Set the mode to allow editing of both text and images
  1463. * Set the mouse mode to PDFEdit
  1464. * Reload Document
  1465. * Set the splite mode to None and unable the split setting
  1466. */
  1467. else if ((string)item.Content == "Content Editor")
  1468. {
  1469. ToolBarContainer.Visibility = Visibility.Visible;
  1470. PDFEditTool.Visibility = Visibility.Visible;
  1471. PageEditBarControl.Visibility = Visibility.Collapsed;
  1472. pdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
  1473. pdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  1474. pdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  1475. pdfViewControl.PDFView?.ReloadDocument();
  1476. pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
  1477. pdfViewControl.PDFView.SetSplitMode(SplitMode.None);
  1478. if (displayPanel != null)
  1479. {
  1480. displayPanel.SetVisibilityWhenContentEdit(Visibility.Collapsed);
  1481. }
  1482. }
  1483. /*
  1484. * Behavior when switching to Form mode:
  1485. *
  1486. */
  1487. else if ((string)item.Content == "Forms")
  1488. {
  1489. ToolBarContainer.Visibility = Visibility.Visible;
  1490. FormBarControl.Visibility = Visibility.Visible;
  1491. pdfViewControl.PDFView?.SetShowLink(true);
  1492. pdfViewControl.PDFView?.SetMouseMode(MouseModes.FormEditTool);
  1493. pdfViewControl.PDFView?.ReloadDocument();
  1494. pdfViewControl.PDFView.AnnotActiveHandler += PDFView_FormActiveHandler;
  1495. pdfViewControl.PDFView.AnnotEditHandler += PDFView_FormEditHandler;
  1496. }
  1497. /*
  1498. *
  1499. */
  1500. else if ((string)item.Content == "Docs Editor")
  1501. {
  1502. ToolBarContainer.Visibility = Visibility.Visible;
  1503. if (pageEditControl == null)
  1504. {
  1505. pageEditControl = new CPDFPageEditControl();
  1506. }
  1507. pageEditControl.ExitPageEdit += PageEditControl_ExitPageEdit; ;
  1508. pageEditControl.PageMoved += PageEditControl_PageMoved; ;
  1509. PageEditBarControl.PageEditEvent += CPDFPageEditBarControl_PageEditEvent;
  1510. pageEditControl.LoadThumbnails(pdfViewControl.PDFView);
  1511. PDFGrid.Child = pageEditControl;
  1512. UndoRedoStackPanel.Visibility = Visibility.Collapsed;
  1513. PageEditBarControl.Visibility = Visibility.Visible;
  1514. LeftToolPanelButton.IsChecked = false;
  1515. LeftToolPanelButton.IsEnabled = false;
  1516. SearchButton.IsEnabled = false;
  1517. RightPanelButton.IsChecked = false;
  1518. RightPanelButton.IsEnabled = false;
  1519. ViewSettingBtn.IsChecked = false;
  1520. ViewSettingBtn.IsEnabled = false;
  1521. ExpandLeftPanel(false);
  1522. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  1523. FloatPageTool.Visibility = Visibility.Collapsed;
  1524. }
  1525. currentMode = (string)item.Content;
  1526. }
  1527. #endregion
  1528. #region Shortcut
  1529. private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
  1530. {
  1531. OpenFile();
  1532. }
  1533. private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
  1534. {
  1535. if (CanSave)
  1536. {
  1537. SaveFile();
  1538. }
  1539. }
  1540. private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
  1541. {
  1542. SaveAsFile();
  1543. }
  1544. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  1545. {
  1546. if (pdfViewControl != null && pdfViewControl.PDFView != null && CanUndo)
  1547. {
  1548. pdfViewControl.PDFView.UndoManager?.Undo();
  1549. }
  1550. }
  1551. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  1552. {
  1553. if (pdfViewControl != null && pdfViewControl.PDFView != null && CanRedo)
  1554. {
  1555. pdfViewControl.PDFView.UndoManager?.Redo();
  1556. }
  1557. }
  1558. private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
  1559. {
  1560. LeftToolPanelButton.IsChecked = !LeftToolPanelButton.IsChecked;
  1561. ControlLeftPanel();
  1562. }
  1563. private void CommandBinding_Executed_ControlRightPanel(object sender, ExecutedRoutedEventArgs e)
  1564. {
  1565. RightPanelButton.IsChecked = !RightPanelButton.IsChecked;
  1566. ControlRightPanel();
  1567. }
  1568. private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
  1569. {
  1570. ExpandLeftPanel(true);
  1571. LeftToolPanelButton.IsChecked = true;
  1572. BotaSideTool.SelectBotaTool(BOTATools.Bookmark);
  1573. }
  1574. private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
  1575. {
  1576. ExpandLeftPanel(true);
  1577. LeftToolPanelButton.IsChecked = true;
  1578. BotaSideTool.SelectBotaTool(BOTATools.Outline);
  1579. }
  1580. private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
  1581. {
  1582. ExpandLeftPanel(true);
  1583. LeftToolPanelButton.IsChecked = true;
  1584. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  1585. }
  1586. private void CommandBinding_Executed_Annotation(object sender, ExecutedRoutedEventArgs e)
  1587. {
  1588. ExpandLeftPanel(true);
  1589. LeftToolPanelButton.IsChecked = true;
  1590. BotaSideTool.SelectBotaTool(BOTATools.Annotation);
  1591. }
  1592. private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
  1593. {
  1594. ExpandLeftPanel(true);
  1595. LeftToolPanelButton.IsChecked = true;
  1596. BotaSideTool.SelectBotaTool(BOTATools.Search);
  1597. }
  1598. private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
  1599. {
  1600. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  1601. pdfViewControl.PDFView?.Zoom(newZoom);
  1602. }
  1603. private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
  1604. {
  1605. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  1606. pdfViewControl.PDFView?.Zoom(newZoom);
  1607. }
  1608. private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
  1609. {
  1610. ViewSettingBtn.IsChecked = !ViewSettingBtn.IsChecked;
  1611. ShowViewSettings();
  1612. }
  1613. private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
  1614. {
  1615. if (PopupBorder.Visibility != Visibility.Visible)
  1616. {
  1617. PasswordUI.Visibility = Visibility.Collapsed;
  1618. FileInfoUI.Visibility = Visibility.Visible;
  1619. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  1620. PopupBorder.Visibility = Visibility.Visible;
  1621. }
  1622. else
  1623. {
  1624. FileInfoUI.Visibility = Visibility.Collapsed;
  1625. PopupBorder.Visibility = Visibility.Collapsed;
  1626. }
  1627. }
  1628. #endregion
  1629. }
  1630. }