ContentEditControl.xaml.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKit.PDFPage;
  4. using ComPDFKit.PDFPage.Edit;
  5. using ComPDFKit.Tool;
  6. using ComPDFKit.Tool.SettingParam;
  7. using Compdfkit_Tools.Edit;
  8. using Compdfkit_Tools.Helper;
  9. using ComPDFKitViewer;
  10. using Microsoft.Win32;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Diagnostics;
  15. using System.Drawing;
  16. using System.IO;
  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 System.Windows.Media;
  23. using static ComPDFKit.Tool.CPDFToolManager;
  24. using System.Windows.Media.Imaging;
  25. using ComPDFKit.Tool.Help;
  26. using ComPDFKit.Tool.UndoManger;
  27. namespace Compdfkit_Tools.PDFControl
  28. {
  29. public partial class ContentEditControl : UserControl, INotifyPropertyChanged
  30. {
  31. #region Property
  32. public PDFViewControl PdfViewControl;
  33. public PDFContentEditControl pdfContentEditControl = new PDFContentEditControl();
  34. private CPDFDisplaySettingsControl displaySettingsControl = null;
  35. private TextEditParam pdfTextCreateParam;
  36. private PDFEditParam lastPDFEditEvent = null;
  37. private List<TextEditParam> lastPDFEditMultiEvents = null;
  38. private PanelState panelState = PanelState.GetInstance();
  39. private KeyEventHandler KeyDownHandler;
  40. public event PropertyChangedEventHandler PropertyChanged;
  41. public ICommand CloseTabCommand;
  42. public ICommand ExpandPropertyPanelCommand;
  43. public bool CanUndo
  44. {
  45. get
  46. {
  47. try
  48. {
  49. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  50. {
  51. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  52. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  53. return pdfViewer.UndoManager.CanUndo;
  54. }
  55. }
  56. catch (Exception ex)
  57. {
  58. }
  59. return false;
  60. }
  61. }
  62. public bool CanRedo
  63. {
  64. get
  65. {
  66. try
  67. {
  68. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  69. {
  70. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  71. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  72. return pdfViewer.UndoManager.CanRedo;
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. }
  78. return false;
  79. }
  80. }
  81. private bool CanSave
  82. {
  83. get
  84. {
  85. try
  86. {
  87. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  88. {
  89. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  90. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  91. return (pdfViewer.UndoManager.CanUndo | pdfViewer.UndoManager.CanRedo);
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. }
  97. return false;
  98. }
  99. }
  100. public event EventHandler<bool> OnCanSaveChanged;
  101. public event EventHandler OnAnnotEditHandler;
  102. #endregion
  103. public ContentEditControl()
  104. {
  105. InitializeComponent();
  106. panelState.PropertyChanged -= PanelState_PropertyChanged;
  107. panelState.PropertyChanged += PanelState_PropertyChanged;
  108. }
  109. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  110. {
  111. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  112. {
  113. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  114. }
  115. else if (e.PropertyName == nameof(PanelState.RightPanel))
  116. {
  117. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  118. {
  119. ExpandRightPropertyPanel(pdfContentEditControl, Visibility.Visible);
  120. }
  121. else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  122. {
  123. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  124. }
  125. else
  126. {
  127. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  128. }
  129. }
  130. }
  131. public void ClearPDFEditState(ToggleButton ignoreBtn = null)
  132. {
  133. List<ToggleButton> clearBtnList = new List<ToggleButton>()
  134. {
  135. PDFTextEditButton,
  136. PDFImageEditButton
  137. };
  138. foreach (ToggleButton item in clearBtnList)
  139. {
  140. if (ignoreBtn == item)
  141. {
  142. continue;
  143. }
  144. item.IsChecked = false;
  145. }
  146. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.None);
  147. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(false);
  148. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(false);
  149. }
  150. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  151. {
  152. ToggleButton senderBtn = sender as ToggleButton;
  153. if (senderBtn != null && PdfViewControl != null)
  154. {
  155. ClearPDFEditState(senderBtn);
  156. if (senderBtn.IsChecked == true)
  157. {
  158. TextEditParam textEditParam = new TextEditParam();
  159. textEditParam.EditType = CPDFEditType.EditText;
  160. textEditParam.IsBold = false;
  161. textEditParam.IsItalic = false;
  162. textEditParam.FontSize = 14;
  163. textEditParam.FontName = "Helvetica";
  164. textEditParam.FontColor = new byte[] { 0, 0, 0 };
  165. textEditParam.EditIndex = -1;
  166. textEditParam.TextAlign = TextAlignType.AlignLeft;
  167. textEditParam.Transparency = 255;
  168. pdfContentEditControl.SetPDFTextEditData(textEditParam);
  169. DefaultSettingParam defaultSettingParam = PdfViewControl.PDFViewTool.GetDefaultSettingParam();
  170. defaultSettingParam.SetPDFEditParamm(textEditParam);
  171. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  172. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.EditText);
  173. }
  174. else
  175. {
  176. }
  177. // PDFEditEvent createParam = new PDFEditEvent();
  178. // createParam.EditType = CPDFEditType.EditText;
  179. // createParam.IsBold = false;
  180. // createParam.IsItalic = false;
  181. // createParam.FontSize = 14;
  182. // createParam.FontName = "Helvetica";
  183. // createParam.FontColor = Colors.Black;
  184. // createParam.TextAlign = TextAlignType.AlignLeft;
  185. // createParam.Transparency = 255;
  186. // if (PdfViewControl.PDFView != null && PdfViewControl.PDFView.Document != null)
  187. // {
  188. // CPDFDocument pdfDoc = PdfViewControl.PDFView.Document;
  189. // PdfViewControl.PDFView.ToolManager.EnableClickCreate = true;
  190. // PdfViewControl.PDFView.ToolManager.ClickCreateWidth = 100;
  191. // if (pdfDoc.PageCount > 0)
  192. // {
  193. // CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
  194. // CPDFEditPage editPage = pdfPage.GetEditPage();
  195. // editPage.BeginEdit(CPDFEditType.EditText);
  196. // createParam.SystemFontNameList.AddRange(editPage.GetFontList());
  197. // editPage.EndEdit();
  198. // }
  199. // }
  200. // PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
  201. // PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
  202. // PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  203. // PdfViewControl.PDFView?.ReloadDocument();
  204. // PdfViewControl.PDFView?.SetPDFEditParam(createParam);
  205. // pdfContentEditControl.SetPDFTextEditData(createParam);
  206. // panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  207. // pdfTextCreateParam = createParam;
  208. //}
  209. //else
  210. //{
  211. // PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  212. // PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  213. // PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  214. // PdfViewControl.PDFView?.ReloadDocument();
  215. // pdfContentEditControl.ClearContentControl();
  216. // panelState.RightPanel = PanelState.RightPanelState.None;
  217. //}
  218. }
  219. }
  220. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  221. {
  222. ToggleButton senderBtn = sender as ToggleButton;
  223. if (senderBtn != null && PdfViewControl != null)
  224. {
  225. panelState.RightPanel = PanelState.RightPanelState.None;
  226. senderBtn.IsChecked = false;
  227. OpenFileDialog openFileDialog = new OpenFileDialog();
  228. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  229. if (openFileDialog.ShowDialog() == true)
  230. {
  231. ClearPDFEditState(senderBtn);
  232. try
  233. {
  234. bool SetImage = PdfViewControl.PDFViewTool.GetCPDFViewer().SetStampMouseImage(openFileDialog.FileName);
  235. PdfViewControl.PDFToolManager.SetCreateImagePath(openFileDialog.FileName);
  236. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(SetImage);
  237. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(SetImage);
  238. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.EditImage);
  239. }
  240. catch
  241. {
  242. }
  243. //if (openFileDialog.ShowDialog() == true)
  244. //{
  245. // ClearPDFEditState(senderBtn);
  246. // PdfViewControl.PDFView?.ClearSelectPDFEdit();
  247. // PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  248. // PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  249. // PdfViewControl.PDFView?.ReloadDocument();
  250. // PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
  251. // PdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
  252. //}
  253. }
  254. }
  255. }
  256. public void ExpandLeftPanel(bool isExpand)
  257. {
  258. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  259. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  260. if (isExpand)
  261. {
  262. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  263. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  264. }
  265. else
  266. {
  267. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  268. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  269. }
  270. }
  271. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  272. {
  273. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  274. {
  275. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Undo();
  276. //PdfViewControl.PDFToolManager.ClearSelect();
  277. PdfViewControl.PDFViewTool.GetCPDFViewer().UpDateRenderFrame();
  278. }
  279. }
  280. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  281. {
  282. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  283. {
  284. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Redo();
  285. //PdfViewControl.PDFToolManager.ClearSelect();
  286. PdfViewControl.PDFViewTool.GetCPDFViewer().UpDateRenderFrame();
  287. }
  288. }
  289. public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
  290. {
  291. this.PropertyContainer.Child = displaySettingsControl;
  292. this.PropertyContainer.Visibility = visibility;
  293. }
  294. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  295. {
  296. this.BotaContainer.Child = botaControl;
  297. }
  298. public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
  299. {
  300. this.displaySettingsControl = displaySettingsControl;
  301. }
  302. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  303. {
  304. }
  305. private void UserControl_UnLoaded(object sender, RoutedEventArgs e)
  306. {
  307. }
  308. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  309. {
  310. PropertyContainer.Width = 260;
  311. PropertyContainer.Child = propertytPanel;
  312. PropertyContainer.Visibility = visible;
  313. }
  314. public void InitWithPDFViewer(PDFViewControl view)
  315. {
  316. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  317. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  318. PdfViewControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
  319. PdfViewControl.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
  320. PdfViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
  321. PdfViewControl.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
  322. PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
  323. PdfViewControl.MouseRightButtonDownHandler += PdfViewControl_MouseRightButtonDownHandler;
  324. PdfViewControl = view;
  325. PDFGrid.Child = PdfViewControl;
  326. FloatPageTool.InitWithPDFViewer(view);
  327. pdfContentEditControl.InitWithPDFViewer(view);
  328. DataContext = this;
  329. //if(pdfViewer!=null)
  330. //{
  331. // pdfViewer.EnableMultiSelectEdit = true;
  332. // pdfViewer.PDFEditMultiActiveHandler -= PDFEditMultiActiveHandler;
  333. // pdfViewer.PDFEditMultiActiveHandler += PDFEditMultiActiveHandler;
  334. // if (KeyDownHandler != null)
  335. // {
  336. // pdfViewer.RemoveHandler(KeyDownEvent, KeyDownHandler);
  337. // }
  338. // KeyDownHandler = new KeyEventHandler(PDFView_KeyDown);
  339. // pdfViewer.AddHandler(KeyDownEvent, KeyDownHandler, false, true);
  340. //}
  341. }
  342. private void PDFEditEmptyPanel()
  343. {
  344. PropertyContainer.Child = pdfContentEditControl;
  345. if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
  346. {
  347. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.EditText)
  348. {
  349. pdfContentEditControl.SetPDFTextEditData(pdfTextCreateParam);
  350. }
  351. else if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.None)
  352. {
  353. pdfContentEditControl.ClearContentControl();
  354. }
  355. }
  356. else
  357. {
  358. pdfContentEditControl.ClearContentControl();
  359. }
  360. }
  361. //private void PDFEditMultiActiveHandler(object sender, List<PDFEditEvent> e)
  362. //{
  363. // lastPDFEditEvent = null;
  364. // lastPDFEditMultiEvents = e;
  365. // if(e==null)
  366. // {
  367. // PDFEditEmptyPanel();
  368. // return;
  369. // }
  370. // if(e.Count>1)
  371. // {
  372. // List<CPDFEditType> editList= e.AsEnumerable().Select(x=>x.EditType).Distinct().ToList();
  373. // if(editList.Count>1)
  374. // {
  375. // PDFEditEmptyPanel();
  376. // return;
  377. // }
  378. // if (editList[0]==CPDFEditType.EditText)
  379. // {
  380. // pdfContentEditControl.SetPDFTextMultiEditData(e);
  381. // return;
  382. // }
  383. // if (editList[0]==CPDFEditType.EditImage)
  384. // {
  385. // UIElement pageView = sender as UIElement;
  386. // if (pageView != null)
  387. // {
  388. // pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  389. // }
  390. // pdfContentEditControl.SetPDFImageMultiEditData(e);
  391. // }
  392. // }
  393. //}
  394. //public void PDFView_KeyDown(object sender, KeyEventArgs e)
  395. //{
  396. // if (PdfViewControl.PDFView.MouseMode != MouseModes.PDFEdit)
  397. // {
  398. // return;
  399. // }
  400. // if (Keyboard.Modifiers == ModifierKeys.Control)
  401. // {
  402. // if (e.Key == Key.Left)
  403. // {
  404. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, false);
  405. // e.Handled = true;
  406. // }
  407. // if (e.Key == Key.Right)
  408. // {
  409. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, false);
  410. // e.Handled = true;
  411. // }
  412. // if (e.Key == Key.Up)
  413. // {
  414. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, false);
  415. // e.Handled = true;
  416. // }
  417. // if (e.Key == Key.Down)
  418. // {
  419. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, false);
  420. // e.Handled = true;
  421. // }
  422. // }
  423. // if (Keyboard.Modifiers == ModifierKeys.Shift)
  424. // {
  425. // if (e.Key == Key.Left)
  426. // {
  427. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreCharPlace, true);
  428. // e.Handled = true;
  429. // }
  430. // if (e.Key == Key.Right)
  431. // {
  432. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextCharPlace, true);
  433. // e.Handled = true;
  434. // }
  435. // if (e.Key == Key.Up)
  436. // {
  437. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeUpCharPlace, true);
  438. // e.Handled = true;
  439. // }
  440. // if (e.Key == Key.Down)
  441. // {
  442. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeDownCharPlace, true);
  443. // e.Handled = true;
  444. // }
  445. // }
  446. // if (Keyboard.Modifiers == ModifierKeys.Alt)
  447. // {
  448. // if (e.SystemKey == Key.Up)
  449. // {
  450. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLocationLineBegin, false);
  451. // e.Handled = true;
  452. // }
  453. // if (e.SystemKey == Key.Down)
  454. // {
  455. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeLineEnd, false);
  456. // e.Handled = true;
  457. // }
  458. // }
  459. // if (Keyboard.Modifiers == ModifierKeys.None)
  460. // {
  461. // if (e.Key == Key.Left)
  462. // {
  463. // PdfViewControl.PDFView.MoveEditArea(new Point(-5, 0));
  464. // e.Handled = true;
  465. // }
  466. // if (e.Key == Key.Right)
  467. // {
  468. // PdfViewControl.PDFView.MoveEditArea(new Point(5, 0));
  469. // e.Handled = true;
  470. // }
  471. // if (e.Key == Key.Up)
  472. // {
  473. // PdfViewControl.PDFView.MoveEditArea(new Point(0, -5));
  474. // e.Handled = true;
  475. // }
  476. // if (e.Key == Key.Down)
  477. // {
  478. // PdfViewControl.PDFView.MoveEditArea(new Point(0, 5));
  479. // e.Handled = true;
  480. // }
  481. // }
  482. // if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift))
  483. // {
  484. // if (e.Key == Key.Left)
  485. // {
  486. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypePreWord, true);
  487. // e.Handled = true;
  488. // }
  489. // if (e.Key == Key.Right)
  490. // {
  491. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeNextWord, true);
  492. // e.Handled = true;
  493. // }
  494. // if (e.Key == Key.Up)
  495. // {
  496. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionBegin, true);
  497. // e.Handled = true;
  498. // }
  499. // if (e.Key == Key.Down)
  500. // {
  501. // PdfViewControl.PDFView.JumpEditingLoction(CEditingLocation.CEditingLoadTypeSectionEnd, true);
  502. // e.Handled = true;
  503. // }
  504. // }
  505. //}
  506. private void PdfViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
  507. {
  508. ContextMenu ContextMenu = PdfViewControl.GetRightMenu();
  509. if (ContextMenu == null)
  510. {
  511. ContextMenu = new ContextMenu();
  512. }
  513. switch (e.hitTestType)
  514. {
  515. case MouseHitTestType.kTextEdit:
  516. case MouseHitTestType.kImageEdit:
  517. CreateEditMenu(sender, ref ContextMenu);
  518. break;
  519. default:
  520. ContextMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  521. break;
  522. }
  523. PdfViewControl.SetRightMenu(ContextMenu);
  524. }
  525. private void CreateEditMenu(object sender, ref ContextMenu menu)
  526. {
  527. menu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  528. menu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  529. menu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  530. menu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  531. }
  532. private void PDFToolManager_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
  533. {
  534. if (e.IsCreate)
  535. {
  536. PdfViewControl.SetIsShowStampMouse(false);
  537. }
  538. }
  539. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  540. {
  541. if (PdfViewControl.PDFToolManager.GetToolType() != ToolType.ContentEdit)
  542. {
  543. PropertyContainer.Child = pdfContentEditControl;
  544. //if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
  545. //{
  546. // if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  547. // {
  548. // pdfContentEditControl.SetPDFTextEditData(pdfTextCreateParam);
  549. // }
  550. // else if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.None)
  551. // {
  552. // pdfContentEditControl.ClearContentControl();
  553. // }
  554. //}
  555. //else
  556. //{
  557. // pdfContentEditControl.ClearContentControl();
  558. //}
  559. return;
  560. }
  561. int PageIndex = -1;
  562. CPDFEditArea editAreaArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref PageIndex);
  563. if (editAreaArea == null)
  564. {
  565. return;
  566. }
  567. else
  568. {
  569. if (editAreaArea.Type == CPDFEditType.EditText)
  570. {
  571. PDFEditParam pDFEditParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editAreaArea, PageIndex);
  572. pdfContentEditControl.SetPDFTextEditData((TextEditParam)pDFEditParam, true);
  573. PropertyContainer.Child = pdfContentEditControl;
  574. return;
  575. }
  576. else if (editAreaArea.Type == CPDFEditType.EditImage && PdfViewControl != null)
  577. {
  578. UIElement pageView = sender as UIElement;
  579. if (pageView != null)
  580. {
  581. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  582. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  583. }
  584. PDFEditParam pDFEditParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editAreaArea, PageIndex);
  585. pdfContentEditControl.SetPDFImageEditData((ImageEditParam)pDFEditParam);
  586. PropertyContainer.Child = pdfContentEditControl;
  587. return;
  588. }
  589. }
  590. }
  591. private void PdfViewControl_SplitPDFViewToolCreated(object sender, EventArgs e)
  592. {
  593. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  594. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  595. }
  596. /// <summary>
  597. /// Text and Image Selected Event
  598. /// </summary>
  599. private void PDFView_PDFEditActiveHandler(object sender, PDFEditParam e)
  600. {
  601. lastPDFEditEvent = e;
  602. if (e == null)
  603. {
  604. PropertyContainer.Child = pdfContentEditControl;
  605. //if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
  606. //{
  607. // if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  608. // {
  609. // pdfContentEditControl.SetPDFTextEditData(pdfTextCreateParam);
  610. // }
  611. // else if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.None)
  612. // {
  613. // pdfContentEditControl.ClearContentControl();
  614. // }
  615. //}
  616. //else
  617. //{
  618. // pdfContentEditControl.ClearContentControl();
  619. //}
  620. return;
  621. }
  622. if (e.EditType == CPDFEditType.EditText)
  623. {
  624. pdfContentEditControl.SetPDFTextEditData((TextEditParam)e, true);
  625. return;
  626. }
  627. if (e.EditType == CPDFEditType.EditImage && PdfViewControl != null)
  628. {
  629. UIElement pageView = sender as UIElement;
  630. if (pageView != null)
  631. {
  632. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  633. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  634. }
  635. pdfContentEditControl.SetPDFImageEditData((ImageEditParam)e);
  636. return;
  637. }
  638. }
  639. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  640. {
  641. UIElement pageView = sender as UIElement;
  642. if (pageView != null)
  643. {
  644. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  645. }
  646. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  647. {
  648. pdfContentEditControl.SetPDFImageEditData((ImageEditParam)lastPDFEditEvent);
  649. }
  650. }
  651. public void ClearViewerControl()
  652. {
  653. PDFGrid.Child = null;
  654. BotaContainer.Child = null;
  655. PropertyContainer.Child = null;
  656. displaySettingsControl = null;
  657. }
  658. #region Property changed
  659. protected void OnPropertyChanged([CallerMemberName] string name = null)
  660. {
  661. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  662. }
  663. public void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  664. {
  665. OnPropertyChanged(e.PropertyName);
  666. if (e.PropertyName == "CanSave")
  667. {
  668. OnCanSaveChanged?.Invoke(this, CanSave);
  669. }
  670. }
  671. #endregion
  672. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  673. {
  674. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null && CanUndo)
  675. {
  676. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Undo();
  677. }
  678. }
  679. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  680. {
  681. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null && CanRedo)
  682. {
  683. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Redo();
  684. }
  685. }
  686. }
  687. }