ContentEditControl.xaml.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. using ComPDFKit.PDFPage;
  2. using ComPDFKit.PDFPage.Edit;
  3. using ComPDFKit.Tool;
  4. using ComPDFKit.Tool.SettingParam;
  5. using ComPDFKit.Controls.Edit;
  6. using ComPDFKit.Controls.Helper;
  7. using ComPDFKitViewer;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Diagnostics;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Runtime.CompilerServices;
  15. using System.Windows;
  16. using System.Windows.Controls.Primitives;
  17. using System.Windows.Forms;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Imaging;
  21. using ComPDFKit.Import;
  22. using ComPDFKit.Tool.Help;
  23. using ComPDFKit.Viewer.Helper;
  24. using ContextMenu = System.Windows.Controls.ContextMenu;
  25. using KeyEventArgs = System.Windows.Input.KeyEventArgs;
  26. using KeyEventHandler = System.Windows.Input.KeyEventHandler;
  27. using MenuItem = System.Windows.Controls.MenuItem;
  28. using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
  29. using UserControl = System.Windows.Controls.UserControl;
  30. using System.Linq;
  31. namespace ComPDFKit.Controls.PDFControl
  32. {
  33. public partial class ContentEditControl : UserControl, INotifyPropertyChanged
  34. {
  35. #region Property
  36. private bool isUpdateStartPoint = true;
  37. public ICommand CloseTabCommand;
  38. public ICommand ExpandPropertyPanelCommand;
  39. private CPoint startPoint;
  40. private CPoint endPoint;
  41. public PDFViewControl PdfViewControl;
  42. public PDFContentEditControl pdfContentEditControl = new PDFContentEditControl();
  43. private CPDFDisplaySettingsControl displaySettingsControl = null;
  44. private TextEditParam pdfTextCreateParam;
  45. private PDFEditParam imageAreaParam = null;
  46. private List<TextEditParam> lastPDFEditMultiEvents = null;
  47. private PanelState panelState = PanelState.GetInstance();
  48. private KeyEventHandler KeyDownHandler;
  49. private bool textAreaCreating = false;
  50. public event PropertyChangedEventHandler PropertyChanged;
  51. public bool CanUndo
  52. {
  53. get
  54. {
  55. try
  56. {
  57. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  58. {
  59. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  60. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  61. return pdfViewer.UndoManager.CanUndo;
  62. }
  63. }
  64. catch (Exception ex)
  65. {
  66. return false;
  67. }
  68. return false;
  69. }
  70. }
  71. public bool CanRedo
  72. {
  73. get
  74. {
  75. try
  76. {
  77. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  78. {
  79. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  80. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  81. return pdfViewer.UndoManager.CanRedo;
  82. }
  83. }
  84. catch (Exception ex)
  85. {
  86. return false;
  87. }
  88. return false;
  89. }
  90. }
  91. private bool CanSave
  92. {
  93. get
  94. {
  95. try
  96. {
  97. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  98. {
  99. CPDFViewerTool viewerTool = PdfViewControl.PDFViewTool;
  100. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  101. return (pdfViewer.UndoManager.CanUndo | pdfViewer.UndoManager.CanRedo);
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. return false;
  107. }
  108. return false;
  109. }
  110. }
  111. public event EventHandler<bool> OnCanSaveChanged;
  112. public event EventHandler OnAnnotEditHandler;
  113. #endregion
  114. public ContentEditControl()
  115. {
  116. InitializeComponent();
  117. panelState.PropertyChanged -= PanelState_PropertyChanged;
  118. panelState.PropertyChanged += PanelState_PropertyChanged;
  119. }
  120. #region public method
  121. public void ClearPDFEditState(ToggleButton ignoreBtn = null)
  122. {
  123. List<ToggleButton> clearBtnList = new List<ToggleButton>()
  124. {
  125. PDFTextEditButton,
  126. PDFImageEditButton
  127. };
  128. foreach (ToggleButton item in clearBtnList)
  129. {
  130. if (ignoreBtn == item)
  131. {
  132. continue;
  133. }
  134. item.IsChecked = false;
  135. }
  136. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.None);
  137. PdfViewControl.PDFViewTool.SetCurrentEditType(CPDFEditType.EditText | CPDFEditType.EditImage | CPDFEditType.EditPath);
  138. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(false);
  139. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(false);
  140. PdfViewControl.PDFViewTool.SelectedEditAreaForIndex(-1, -1);
  141. }
  142. public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
  143. {
  144. this.PropertyContainer.Child = displaySettingsControl;
  145. this.PropertyContainer.Visibility = visibility;
  146. }
  147. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  148. {
  149. this.BotaContainer.Child = botaControl;
  150. botaControl.ReplaceFunctionEnabled = true;
  151. }
  152. public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
  153. {
  154. this.displaySettingsControl = displaySettingsControl;
  155. }
  156. public void InitWithPDFViewer(PDFViewControl view)
  157. {
  158. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  159. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  160. PdfViewControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
  161. PdfViewControl.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
  162. PdfViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
  163. PdfViewControl.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
  164. PdfViewControl.DrawChanged -= PdfViewControl_DrawChanged;
  165. PdfViewControl.DrawChanged += PdfViewControl_DrawChanged;
  166. PdfViewControl = view;
  167. PDFGrid.Child = PdfViewControl;
  168. FloatPageTool.InitWithPDFViewer(view);
  169. pdfContentEditControl.InitWithPDFViewer(view);
  170. DataContext = this;
  171. if (PdfViewControl != null)
  172. {
  173. PdfViewControl.PDFViewTool.IsManipulationEnabled = true;
  174. if (KeyDownHandler != null)
  175. {
  176. PdfViewControl.PDFViewTool.RemoveHandler(KeyDownEvent, KeyDownHandler);
  177. }
  178. KeyDownHandler = new KeyEventHandler(PDFView_KeyDown);
  179. PdfViewControl.PDFViewTool.AddHandler(KeyDownEvent, KeyDownHandler, false);
  180. }
  181. }
  182. private void PdfViewControl_DrawChanged(object sender, EventArgs e)
  183. {
  184. if (textAreaCreating && PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.EditText)
  185. {
  186. textAreaCreating = false;
  187. int pageIndex = -1;
  188. CPDFEditArea editAreaArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref pageIndex);
  189. if (editAreaArea == null)
  190. {
  191. return;
  192. }
  193. else
  194. {
  195. if (editAreaArea.Type == CPDFEditType.EditText)
  196. {
  197. PDFEditParam pDFEditParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editAreaArea, pageIndex);
  198. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { (TextEditParam)pDFEditParam }, true);
  199. PropertyContainer.Child = pdfContentEditControl;
  200. }
  201. }
  202. }
  203. }
  204. /// <summary>
  205. /// Short cut key for PDFView
  206. /// </summary>
  207. public void PDFView_KeyDown(object sender, KeyEventArgs e)
  208. {
  209. if (PdfViewControl.PDFViewTool.GetToolType() != ToolType.ContentEdit)
  210. {
  211. return;
  212. }
  213. if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
  214. {
  215. PdfViewControl.PDFViewTool.SetMultiSelectKey(e.Key);
  216. }
  217. else if (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl)
  218. {
  219. PdfViewControl.PDFViewTool.SetMultiSelectKey(e.Key);
  220. }
  221. int pageIndex = -1;
  222. CPDFEditTextArea textArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref pageIndex) as CPDFEditTextArea;
  223. if (textArea == null)
  224. {
  225. return;
  226. }
  227. Rect oldRect = DataConversionForWPF.CRectConversionForRect(textArea.GetFrame());
  228. if (Keyboard.Modifiers == ModifierKeys.Control)
  229. {
  230. if (e.Key == Key.Left)
  231. {
  232. textArea.GetPreWordCharPlace();
  233. UpdateEditArea(oldRect, textArea);
  234. e.Handled = true;
  235. }
  236. if (e.Key == Key.Right)
  237. {
  238. textArea.GetNextWordCharPlace();
  239. UpdateEditArea(oldRect, textArea);
  240. e.Handled = true;
  241. }
  242. if (e.Key == Key.Up)
  243. {
  244. textArea.GetSectionBeginCharPlace();
  245. UpdateEditArea(oldRect, textArea);
  246. e.Handled = true;
  247. }
  248. if (e.Key == Key.Down)
  249. {
  250. textArea.GetSectionEndCharPlace();
  251. UpdateEditArea(oldRect, textArea);
  252. e.Handled = true;
  253. }
  254. }
  255. if (Keyboard.Modifiers == ModifierKeys.Shift)
  256. {
  257. if (isUpdateStartPoint)
  258. {
  259. startPoint = GetPoint(textArea);
  260. isUpdateStartPoint = false;
  261. }
  262. if (e.Key == Key.Left)
  263. {
  264. textArea.GetPrevCharPlace();
  265. endPoint = GetPoint(textArea);
  266. textArea.GetSelectChars(startPoint, endPoint);
  267. UpdateEditArea(oldRect, textArea);
  268. e.Handled = true;
  269. }
  270. if (e.Key == Key.Right)
  271. {
  272. textArea.GetNextCharPlace();
  273. endPoint = GetPoint(textArea);
  274. textArea.GetSelectChars(startPoint, endPoint);
  275. UpdateEditArea(oldRect, textArea);
  276. e.Handled = true;
  277. }
  278. if (e.Key == Key.Up)
  279. {
  280. textArea.GetUpCharPlace();
  281. endPoint = GetPoint(textArea);
  282. textArea.GetSelectChars(startPoint, endPoint);
  283. UpdateEditArea(oldRect, textArea);
  284. e.Handled = true;
  285. }
  286. if (e.Key == Key.Down)
  287. {
  288. textArea.GetDownCharPlace();
  289. endPoint = GetPoint(textArea);
  290. textArea.GetSelectChars(startPoint, endPoint);
  291. UpdateEditArea(oldRect, textArea);
  292. e.Handled = true;
  293. }
  294. }
  295. if (Keyboard.Modifiers == ModifierKeys.Alt)
  296. {
  297. if (e.SystemKey == Key.Up)
  298. {
  299. textArea.GetLineBeginCharPlace();
  300. UpdateEditArea(oldRect, textArea);
  301. e.Handled = true;
  302. }
  303. if (e.SystemKey == Key.Down)
  304. {
  305. textArea.GetLineEndCharPlace();
  306. UpdateEditArea(oldRect, textArea);
  307. e.Handled = true;
  308. }
  309. }
  310. if (Keyboard.Modifiers == ModifierKeys.None)
  311. {
  312. CRect textFrame = textArea.GetFrame();
  313. if (e.Key == Key.Left)
  314. {
  315. textFrame.left -= 5;
  316. textArea.SetFrame(textFrame);
  317. e.Handled = true;
  318. }
  319. if (e.Key == Key.Right)
  320. {
  321. textFrame.left += 5;
  322. textArea.SetFrame(textFrame);
  323. e.Handled = true;
  324. }
  325. if (e.Key == Key.Up)
  326. {
  327. textFrame.top -= 5;
  328. textArea.SetFrame(textFrame);
  329. e.Handled = true;
  330. }
  331. if (e.Key == Key.Down)
  332. {
  333. textFrame.top += 5;
  334. textArea.SetFrame(textFrame);
  335. e.Handled = true;
  336. }
  337. }
  338. if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift))
  339. {
  340. if (isUpdateStartPoint)
  341. {
  342. startPoint = GetPoint(textArea);
  343. isUpdateStartPoint = false;
  344. }
  345. if (e.Key == Key.Left)
  346. {
  347. textArea.GetPreWordCharPlace();
  348. endPoint = GetPoint(textArea);
  349. textArea.GetSelectChars(startPoint, endPoint);
  350. UpdateEditArea(oldRect, textArea);
  351. e.Handled = true;
  352. }
  353. if (e.Key == Key.Right)
  354. {
  355. textArea.GetNextWordCharPlace();
  356. endPoint = GetPoint(textArea);
  357. textArea.GetSelectChars(startPoint, endPoint);
  358. UpdateEditArea(oldRect, textArea);
  359. e.Handled = true;
  360. }
  361. if (e.Key == Key.Up)
  362. {
  363. textArea.GetSectionBeginCharPlace();
  364. endPoint = GetPoint(textArea);
  365. textArea.GetSelectChars(startPoint, endPoint);
  366. UpdateEditArea(oldRect, textArea);
  367. e.Handled = true;
  368. }
  369. if (e.Key == Key.Down)
  370. {
  371. textArea.GetSectionEndCharPlace();
  372. endPoint = GetPoint(textArea);
  373. textArea.GetSelectChars(startPoint, endPoint);
  374. UpdateEditArea(oldRect, textArea);
  375. e.Handled = true;
  376. }
  377. }
  378. }
  379. #endregion
  380. #region Panel
  381. public void ExpandLeftPanel(bool isExpand)
  382. {
  383. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  384. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  385. if (isExpand)
  386. {
  387. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  388. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  389. }
  390. else
  391. {
  392. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  393. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  394. }
  395. }
  396. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  397. {
  398. PropertyContainer.Width = 260;
  399. PropertyContainer.Child = propertytPanel;
  400. PropertyContainer.Visibility = visible;
  401. }
  402. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  403. {
  404. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  405. {
  406. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  407. }
  408. else if (e.PropertyName == nameof(PanelState.RightPanel))
  409. {
  410. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  411. {
  412. ExpandRightPropertyPanel(pdfContentEditControl, Visibility.Visible);
  413. }
  414. else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  415. {
  416. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  417. }
  418. else
  419. {
  420. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  421. }
  422. }
  423. }
  424. #endregion
  425. #region UI
  426. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  427. {
  428. ToggleButton senderBtn = sender as ToggleButton;
  429. if (senderBtn != null && PdfViewControl != null)
  430. {
  431. ClearPDFEditState(senderBtn);
  432. if (senderBtn.IsChecked == true)
  433. {
  434. TextEditParam textEditParam = new TextEditParam();
  435. textEditParam.EditType = CPDFEditType.EditText;
  436. textEditParam.IsBold = false;
  437. textEditParam.IsItalic = false;
  438. textEditParam.FontSize = 14;
  439. textEditParam.FontName = "Arial";
  440. textEditParam.FontColor = new byte[] { 0, 0, 0 };
  441. textEditParam.EditIndex = -1;
  442. textEditParam.TextAlign = TextAlignType.AlignLeft;
  443. textEditParam.Transparency = 255;
  444. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { textEditParam });
  445. DefaultSettingParam defaultSettingParam = PdfViewControl.PDFViewTool.GetDefaultSettingParam();
  446. defaultSettingParam.SetPDFEditParamm(textEditParam);
  447. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  448. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.EditText);
  449. PdfViewControl.PDFViewTool.SetCurrentEditType(CPDFEditType.EditText);
  450. }
  451. }
  452. }
  453. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  454. {
  455. ToggleButton senderBtn = sender as ToggleButton;
  456. if (senderBtn != null && PdfViewControl != null)
  457. {
  458. ClearPDFEditState(senderBtn);
  459. panelState.RightPanel = PanelState.RightPanelState.None;
  460. senderBtn.IsChecked = false;
  461. OpenFileDialog openFileDialog = new OpenFileDialog();
  462. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  463. if (openFileDialog.ShowDialog() == true)
  464. {
  465. try
  466. {
  467. bool SetImage = PdfViewControl.PDFViewTool.GetCPDFViewer().SetStampMouseImage(openFileDialog.FileName);
  468. PdfViewControl.PDFToolManager.SetCreateImagePath(openFileDialog.FileName);
  469. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(SetImage);
  470. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(SetImage);
  471. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.EditImage);
  472. }
  473. catch
  474. {
  475. }
  476. }
  477. }
  478. }
  479. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  480. {
  481. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  482. {
  483. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Undo();
  484. PdfViewControl.PDFViewTool.GetCPDFViewer().UpdateRenderFrame();
  485. }
  486. }
  487. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  488. {
  489. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  490. {
  491. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Redo();
  492. PdfViewControl.PDFViewTool.GetCPDFViewer().UpdateRenderFrame();
  493. }
  494. }
  495. #endregion
  496. #region
  497. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  498. {
  499. PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
  500. PdfViewControl.MouseRightButtonDownHandler += PdfViewControl_MouseRightButtonDownHandler;
  501. }
  502. private void UserControl_UnLoaded(object sender, RoutedEventArgs e)
  503. {
  504. PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
  505. }
  506. private void PDFEditEmptyPanel()
  507. {
  508. PropertyContainer.Child = pdfContentEditControl;
  509. if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
  510. {
  511. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.EditText)
  512. {
  513. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { pdfTextCreateParam });
  514. }
  515. else if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.None)
  516. {
  517. pdfContentEditControl.ClearContentControl();
  518. }
  519. }
  520. else
  521. {
  522. pdfContentEditControl.ClearContentControl();
  523. }
  524. }
  525. private CPoint GetPoint(CPDFEditTextArea textArea)
  526. {
  527. CPoint caretPoint = new CPoint();
  528. CPoint caretPointHigh = new CPoint();
  529. textArea.GetTextCursorPoints(ref caretPoint, ref caretPointHigh);
  530. var lineHeight = caretPoint.y - caretPointHigh.y;
  531. CRect caretRect = new CRect(caretPoint.x, caretPoint.y, caretPointHigh.x, caretPointHigh.y);
  532. caretPoint = new CPoint(caretRect.left, caretRect.top);
  533. return new CPoint(caretRect.left, (caretRect.top + caretRect.bottom) / 2);
  534. }
  535. /// <summary>
  536. /// Update the edit area appearance after the edit area is changed
  537. /// </summary>
  538. private void UpdateEditArea(Rect oldRect, CPDFEditArea editArea)
  539. {
  540. PdfViewControl.PDFViewTool.UpdateRender(oldRect, editArea);
  541. }
  542. private void PdfViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
  543. {
  544. ContextMenu ContextMenu = PdfViewControl.GetRightMenu();
  545. if (ContextMenu == null)
  546. {
  547. ContextMenu = new ContextMenu();
  548. }
  549. switch (e.hitTestType)
  550. {
  551. case MouseHitTestType.TextEdit:
  552. CreateTextEditMenu(sender, ref ContextMenu);
  553. break;
  554. case MouseHitTestType.ImageEdit:
  555. CreateImageEditMenu(sender, ref ContextMenu);
  556. break;
  557. case MouseHitTestType.PathEdit:
  558. CreatePathEditMenu(sender, ref ContextMenu);
  559. break;
  560. case MouseHitTestType.Unknown:
  561. List<int> pageInts = new List<int>();
  562. List<CPDFEditArea> editAreas = PdfViewControl.PDFToolManager.GetSelectedEditAreaListObject(ref pageInts);
  563. if (editAreas.Count > 0)
  564. {
  565. CreateMultiTextEditMenu(sender, ref ContextMenu);
  566. }
  567. else
  568. {
  569. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  570. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteWithoutStyle, CommandTarget = (UIElement)sender });
  571. }
  572. break;
  573. default:
  574. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  575. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteWithoutStyle, CommandTarget = (UIElement)sender });
  576. break;
  577. }
  578. PdfViewControl.SetRightMenu(ContextMenu);
  579. }
  580. #endregion
  581. #region Property changed
  582. protected void OnPropertyChanged([CallerMemberName] string name = null)
  583. {
  584. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  585. }
  586. public void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  587. {
  588. OnPropertyChanged(e.PropertyName);
  589. if (e.PropertyName == "CanUndo" || e.PropertyName == "CanRedo")
  590. {
  591. OnCanSaveChanged?.Invoke(this, CanSave);
  592. }
  593. }
  594. #endregion
  595. #region Context menu
  596. private void AppendOpacityMenu(MenuItem parentMenu, CPDFEditArea editArea, CPDFEditType editType)
  597. {
  598. if (editArea == null)
  599. return;
  600. List<int> opacityList = new List<int>()
  601. {
  602. 25,50,75,100
  603. };
  604. Rect oldRect = DataConversionForWPF.CRectConversionForRect(editArea.GetFrame());
  605. foreach (int opacity in opacityList)
  606. {
  607. MenuItem opacityMenu = new MenuItem();
  608. opacityMenu.Header = string.Format("{0}%", opacity);
  609. opacityMenu.Click += (o, p) =>
  610. {
  611. if (editArea != null && editType == CPDFEditType.EditImage)
  612. {
  613. CPDFEditImageArea editImageArea = editArea as CPDFEditImageArea;
  614. editImageArea?.SetImageTransparency((byte)Math.Ceiling(opacity * 255 / 100D));
  615. pdfContentEditControl.RefreshThumb();
  616. UpdateEditArea(oldRect, editImageArea);
  617. }
  618. else if (editArea != null && editType == CPDFEditType.EditText)
  619. {
  620. CPDFEditTextArea editTextArea = editArea as CPDFEditTextArea;
  621. editTextArea?.SetCharsFontTransparency((byte)Math.Ceiling(opacity * 255 / 100D));
  622. UpdateEditArea(oldRect, editTextArea);
  623. }
  624. else if (editArea != null && editType == CPDFEditType.EditPath)
  625. {
  626. CPDFEditPathArea editPathArea = editArea as CPDFEditPathArea;
  627. editPathArea?.SetTransparency((byte)Math.Ceiling(opacity * 255 / 100D));
  628. UpdateEditArea(oldRect, editPathArea);
  629. }
  630. };
  631. parentMenu.Items.Add(opacityMenu);
  632. }
  633. }
  634. private void PDFToolManager_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
  635. {
  636. if (e.IsCreate)
  637. {
  638. PdfViewControl.SetIsShowStampMouse(false);
  639. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.EditImage)
  640. {
  641. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.None);
  642. }
  643. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.EditText)
  644. {
  645. textAreaCreating = true;
  646. }
  647. }
  648. int pageIndex = -1;
  649. CPDFEditArea editArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref pageIndex);
  650. List<int> pageInts = new List<int>();
  651. List<CPDFEditArea> editAreas = PdfViewControl.PDFToolManager.GetSelectedEditAreaListObject(ref pageInts);
  652. if (editArea != null)
  653. {
  654. if (editArea.Type == CPDFEditType.EditText)
  655. {
  656. PDFEditParam editParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editArea, pageIndex);
  657. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { (TextEditParam)editParam }, true);
  658. PropertyContainer.Child = pdfContentEditControl;
  659. }
  660. }
  661. else if (editAreas != null && editAreas.Count != 0)
  662. {
  663. List<CPDFEditTextArea> editTextAreas = editAreas.OfType<CPDFEditTextArea>().ToList();
  664. List<CPDFEditImageArea> editImageAreas = editAreas.OfType<CPDFEditImageArea>().ToList();
  665. List<CPDFEditPathArea> editPathAreas = editAreas.OfType<CPDFEditPathArea>().ToList();
  666. editTextAreas.ForEach(textArea => textArea.SelectAllChars());
  667. if (editAreas.Count == editTextAreas.Count)
  668. {
  669. List<TextEditParam> editParams = editTextAreas.
  670. Select(area => ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), area, pageInts.FirstOrDefault())).
  671. Cast<TextEditParam>().ToList();
  672. pdfContentEditControl.SetPDFTextEditData(editParams, true);
  673. PropertyContainer.Child = pdfContentEditControl;
  674. }
  675. else if (editTextAreas.Count == 0 && editPathAreas.Count == 0)
  676. {
  677. List<ImageEditParam> editParams = editAreas.
  678. Select(area => ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), area, pageInts.FirstOrDefault())).
  679. Cast<ImageEditParam>().ToList();
  680. pdfContentEditControl.SetPDFImageEditData(editParams);
  681. PropertyContainer.Child = pdfContentEditControl;
  682. }
  683. else
  684. {
  685. pdfContentEditControl.ClearContentControl();
  686. }
  687. }
  688. else
  689. {
  690. return;
  691. }
  692. }
  693. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  694. {
  695. isUpdateStartPoint = true;
  696. if (PdfViewControl.PDFToolManager.GetToolType() != ToolType.ContentEdit)
  697. {
  698. PropertyContainer.Child = pdfContentEditControl;
  699. return;
  700. }
  701. int pageIndex = -1;
  702. CPDFEditArea editAreaArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref pageIndex);
  703. if (editAreaArea == null)
  704. {
  705. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() != CPDFEditType.EditText)
  706. {
  707. pdfContentEditControl.ClearContentControl();
  708. }
  709. return;
  710. }
  711. else
  712. {
  713. if (editAreaArea.Type == CPDFEditType.EditText)
  714. {
  715. PDFEditParam pDFEditParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editAreaArea, pageIndex);
  716. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { (TextEditParam)pDFEditParam }, true);
  717. PropertyContainer.Child = pdfContentEditControl;
  718. }
  719. else if (editAreaArea.Type == CPDFEditType.EditImage && PdfViewControl != null)
  720. {
  721. UIElement pageView = sender as UIElement;
  722. if (pageView != null)
  723. {
  724. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  725. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  726. }
  727. PDFEditParam pDFEditParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editAreaArea, pageIndex);
  728. pdfContentEditControl.SetPDFImageEditData(new List<ImageEditParam> { (ImageEditParam)pDFEditParam });
  729. PropertyContainer.Child = pdfContentEditControl;
  730. }
  731. }
  732. }
  733. private void PdfViewControl_SplitPDFViewToolCreated(object sender, EventArgs e)
  734. {
  735. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  736. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  737. }
  738. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  739. {
  740. UIElement pageView = sender as UIElement;
  741. if (pageView != null)
  742. {
  743. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  744. }
  745. if (imageAreaParam != null)
  746. {
  747. pdfContentEditControl.SetPDFImageEditData(new List<ImageEditParam> { (ImageEditParam)imageAreaParam });
  748. }
  749. }
  750. public void ClearViewerControl()
  751. {
  752. PDFGrid.Child = null;
  753. BotaContainer.Child = null;
  754. PropertyContainer.Child = null;
  755. displaySettingsControl = null;
  756. }
  757. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  758. {
  759. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null && CanUndo)
  760. {
  761. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Undo();
  762. }
  763. }
  764. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  765. {
  766. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null && CanRedo)
  767. {
  768. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Redo();
  769. }
  770. }
  771. private void CreateTextEditMenu(object sender, ref ContextMenu menu)
  772. {
  773. int index = -1;
  774. CPDFEditTextArea textArea =
  775. PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref index) as CPDFEditTextArea;
  776. if (textArea != null)
  777. {
  778. if (PdfViewControl.PDFToolManager.GetDocument().GetPermissionsInfo().AllowsCopying)
  779. {
  780. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  781. }
  782. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  783. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  784. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  785. }
  786. else
  787. {
  788. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  789. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteWithoutStyle, CommandTarget = (UIElement)sender });
  790. }
  791. }
  792. private void CreateImageEditMenu(object sender, ref ContextMenu menu)
  793. {
  794. int index = -1;
  795. CPDFEditImageArea imageArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref index) as CPDFEditImageArea;
  796. if (imageArea == null)
  797. return;
  798. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  799. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  800. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  801. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  802. MenuItem rotateLeftMenu = new MenuItem();
  803. rotateLeftMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateLeft");
  804. rotateLeftMenu.Click += (o, p) =>
  805. {
  806. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  807. imageArea.Rotate(-90);
  808. pdfContentEditControl.RefreshThumb();
  809. UpdateEditArea(oldRect,imageArea);
  810. };
  811. menu.Items.Add(rotateLeftMenu);
  812. MenuItem rotateRightMenu = new MenuItem();
  813. rotateRightMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateRight");
  814. rotateRightMenu.Click += (o, p) =>
  815. {
  816. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  817. imageArea.Rotate(90);
  818. pdfContentEditControl.RefreshThumb();
  819. UpdateEditArea(oldRect, imageArea);
  820. };
  821. menu.Items.Add(rotateRightMenu);
  822. MenuItem replaceMenu = new MenuItem();
  823. replaceMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Replace");
  824. replaceMenu.Click += (o, p) =>
  825. {
  826. OpenFileDialog openFileDialog = new OpenFileDialog();
  827. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  828. if (openFileDialog.ShowDialog() == true)
  829. {
  830. int imageWidth = 0;
  831. int imageHeight = 0;
  832. byte[] imageData = null;
  833. BitmapFrame frame = null;
  834. BitmapDecoder decoder = BitmapDecoder.Create(new Uri(openFileDialog.FileName), BitmapCreateOptions.None, BitmapCacheOption.Default);
  835. if (decoder.Frames.Count > 0)
  836. {
  837. frame = decoder.Frames[0];
  838. }
  839. if (frame != null)
  840. {
  841. imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  842. if (frame.Format != PixelFormats.Bgra32)
  843. {
  844. FormatConvertedBitmap covert = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, frame.Palette, 0);
  845. covert.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  846. }
  847. else
  848. {
  849. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  850. }
  851. imageWidth = frame.PixelWidth;
  852. imageHeight = frame.PixelHeight;
  853. }
  854. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  855. imageArea.ReplaceImageArea(imageArea.GetFrame(), imageData, imageWidth, imageHeight);
  856. pdfContentEditControl.RefreshThumb();
  857. UpdateEditArea(oldRect, imageArea);
  858. }
  859. };
  860. menu.Items.Add(replaceMenu);
  861. MenuItem exportMenu = new MenuItem();
  862. exportMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Export");
  863. exportMenu.Click += (o, p) =>
  864. {
  865. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  866. {
  867. try
  868. {
  869. FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
  870. if (folderBrowserDialog.ShowDialog() == DialogResult.OK && imageArea != null)
  871. {
  872. string path = Path.GetTempPath();
  873. string uuid = Guid.NewGuid().ToString("N");
  874. string imagePath = Path.Combine(path, uuid + ".tmp");
  875. imageArea.ExtractImage(imagePath);
  876. Bitmap bitmapImage = new Bitmap(imagePath);
  877. string fileName = Path.Combine(folderBrowserDialog.SelectedPath, uuid + ".jpg");
  878. bitmapImage.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  879. Process.Start("explorer", "/select,\"" + fileName + "\"");
  880. }
  881. }
  882. catch (Exception ex)
  883. {
  884. }
  885. }
  886. };
  887. menu.Items.Add(exportMenu);
  888. MenuItem opacityMenu = new MenuItem();
  889. opacityMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Opacity");
  890. menu.Items.Add(opacityMenu);
  891. AppendOpacityMenu(opacityMenu, imageArea, CPDFEditType.EditImage);
  892. MenuItem horizonMirror = new MenuItem();
  893. horizonMirror.Header = LanguageHelper.CommonManager.GetString("Menu_HFlip");
  894. horizonMirror.Click += (o, p) =>
  895. {
  896. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  897. imageArea.HorizontalMirror();
  898. pdfContentEditControl.RefreshThumb();
  899. UpdateEditArea(oldRect, imageArea);
  900. };
  901. menu.Items.Add(horizonMirror);
  902. MenuItem verticalMirror = new MenuItem();
  903. verticalMirror.Header = LanguageHelper.CommonManager.GetString("Menu_VFlip");
  904. verticalMirror.Click += (o, p) =>
  905. {
  906. if (imageArea != null)
  907. {
  908. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  909. imageArea.VerticalMirror();
  910. pdfContentEditControl.RefreshThumb();
  911. UpdateEditArea(oldRect, imageArea);
  912. }
  913. };
  914. menu.Items.Add(verticalMirror);
  915. MenuItem cropMenu = new MenuItem();
  916. cropMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Crop");
  917. cropMenu.Click += (o, p) =>
  918. {
  919. if (imageArea != null)
  920. {
  921. PdfViewControl.PDFViewTool.SetCropMode(!PdfViewControl.PDFViewTool.GetIsCropMode());
  922. }
  923. };
  924. menu.Items.Add(cropMenu);
  925. }
  926. private void CreatePathEditMenu(object sender, ref ContextMenu menu)
  927. {
  928. int index = -1;
  929. CPDFEditPathArea pathArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref index) as CPDFEditPathArea;
  930. if (pathArea == null)
  931. return;
  932. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  933. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  934. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  935. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  936. MenuItem rotateLeftMenu = new MenuItem();
  937. rotateLeftMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateLeft");
  938. rotateLeftMenu.Click += (o, p) =>
  939. {
  940. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathArea.GetFrame());
  941. pathArea.Rotate(-90);
  942. UpdateEditArea(oldRect, pathArea);
  943. };
  944. menu.Items.Add(rotateLeftMenu);
  945. MenuItem rotateRightMenu = new MenuItem();
  946. rotateRightMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateRight");
  947. rotateRightMenu.Click += (o, p) =>
  948. {
  949. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathArea.GetFrame());
  950. pathArea.Rotate(90);
  951. UpdateEditArea(oldRect, pathArea);
  952. };
  953. menu.Items.Add(rotateRightMenu);
  954. MenuItem opacityMenu = new MenuItem();
  955. opacityMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Opacity");
  956. menu.Items.Add(opacityMenu);
  957. AppendOpacityMenu(opacityMenu, pathArea, CPDFEditType.EditPath);
  958. MenuItem horizonMirror = new MenuItem();
  959. horizonMirror.Header = LanguageHelper.CommonManager.GetString("Menu_HFlip");
  960. horizonMirror.Click += (o, p) =>
  961. {
  962. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathArea.GetFrame());
  963. pathArea.HorizontalMirror();
  964. UpdateEditArea(oldRect, pathArea);
  965. };
  966. menu.Items.Add(horizonMirror);
  967. MenuItem verticalMirror = new MenuItem();
  968. verticalMirror.Header = LanguageHelper.CommonManager.GetString("Menu_VFlip");
  969. verticalMirror.Click += (o, p) =>
  970. {
  971. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathArea.GetFrame());
  972. pathArea.VerticalMirror();
  973. UpdateEditArea(oldRect, pathArea);
  974. };
  975. menu.Items.Add(verticalMirror);
  976. MenuItem cropMenu = new MenuItem();
  977. cropMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Crop");
  978. cropMenu.Click += (o, p) =>
  979. {
  980. if (pathArea != null)
  981. {
  982. PdfViewControl.PDFViewTool.SetCropMode(!PdfViewControl.PDFViewTool.GetIsCropMode());
  983. }
  984. };
  985. menu.Items.Add(cropMenu);
  986. }
  987. private void CreateMultiTextEditMenu(object sender, ref ContextMenu menu)
  988. {
  989. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  990. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  991. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  992. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  993. }
  994. }
  995. }
  996. #endregion