ContentEditControl.xaml.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  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.HasFlag(ModifierKeys.Control) && Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
  229. {
  230. if(e.Key == Key.S)
  231. {
  232. textArea.AddStrikethrough();
  233. UpdateEditArea(oldRect, textArea);
  234. e.Handled = true;
  235. }
  236. }
  237. if (Keyboard.Modifiers == ModifierKeys.Control)
  238. {
  239. if (e.Key == Key.Left)
  240. {
  241. textArea.GetPreWordCharPlace();
  242. UpdateEditArea(oldRect, textArea);
  243. e.Handled = true;
  244. }
  245. if (e.Key == Key.Right)
  246. {
  247. textArea.GetNextWordCharPlace();
  248. UpdateEditArea(oldRect, textArea);
  249. e.Handled = true;
  250. }
  251. if (e.Key == Key.Up)
  252. {
  253. textArea.GetSectionBeginCharPlace();
  254. UpdateEditArea(oldRect, textArea);
  255. e.Handled = true;
  256. }
  257. if (e.Key == Key.Down)
  258. {
  259. textArea.GetSectionEndCharPlace();
  260. UpdateEditArea(oldRect, textArea);
  261. e.Handled = true;
  262. }
  263. if (e.Key == Key.U)
  264. {
  265. textArea.AddUnderline();
  266. UpdateEditArea(oldRect, textArea);
  267. e.Handled = true;
  268. }
  269. }
  270. if (Keyboard.Modifiers == ModifierKeys.Shift)
  271. {
  272. if (isUpdateStartPoint)
  273. {
  274. startPoint = GetPoint(textArea);
  275. isUpdateStartPoint = false;
  276. }
  277. if (e.Key == Key.Left)
  278. {
  279. textArea.GetPrevCharPlace();
  280. endPoint = GetPoint(textArea);
  281. textArea.GetSelectChars(startPoint, endPoint);
  282. UpdateEditArea(oldRect, textArea);
  283. e.Handled = true;
  284. }
  285. if (e.Key == Key.Right)
  286. {
  287. textArea.GetNextCharPlace();
  288. endPoint = GetPoint(textArea);
  289. textArea.GetSelectChars(startPoint, endPoint);
  290. UpdateEditArea(oldRect, textArea);
  291. e.Handled = true;
  292. }
  293. if (e.Key == Key.Up)
  294. {
  295. textArea.GetUpCharPlace();
  296. endPoint = GetPoint(textArea);
  297. textArea.GetSelectChars(startPoint, endPoint);
  298. UpdateEditArea(oldRect, textArea);
  299. e.Handled = true;
  300. }
  301. if (e.Key == Key.Down)
  302. {
  303. textArea.GetDownCharPlace();
  304. endPoint = GetPoint(textArea);
  305. textArea.GetSelectChars(startPoint, endPoint);
  306. UpdateEditArea(oldRect, textArea);
  307. e.Handled = true;
  308. }
  309. }
  310. if (Keyboard.Modifiers == ModifierKeys.Alt)
  311. {
  312. if (e.SystemKey == Key.Up)
  313. {
  314. textArea.GetLineBeginCharPlace();
  315. UpdateEditArea(oldRect, textArea);
  316. e.Handled = true;
  317. }
  318. if (e.SystemKey == Key.Down)
  319. {
  320. textArea.GetLineEndCharPlace();
  321. UpdateEditArea(oldRect, textArea);
  322. e.Handled = true;
  323. }
  324. }
  325. if (Keyboard.Modifiers == ModifierKeys.None)
  326. {
  327. CRect textFrame = textArea.GetFrame();
  328. if (e.Key == Key.Left)
  329. {
  330. textFrame.left -= 5;
  331. textArea.SetFrame(textFrame);
  332. e.Handled = true;
  333. }
  334. if (e.Key == Key.Right)
  335. {
  336. textFrame.left += 5;
  337. textArea.SetFrame(textFrame);
  338. e.Handled = true;
  339. }
  340. if (e.Key == Key.Up)
  341. {
  342. textFrame.top -= 5;
  343. textArea.SetFrame(textFrame);
  344. e.Handled = true;
  345. }
  346. if (e.Key == Key.Down)
  347. {
  348. textFrame.top += 5;
  349. textArea.SetFrame(textFrame);
  350. e.Handled = true;
  351. }
  352. }
  353. if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift))
  354. {
  355. if (isUpdateStartPoint)
  356. {
  357. startPoint = GetPoint(textArea);
  358. isUpdateStartPoint = false;
  359. }
  360. if (e.Key == Key.Left)
  361. {
  362. textArea.GetPreWordCharPlace();
  363. endPoint = GetPoint(textArea);
  364. textArea.GetSelectChars(startPoint, endPoint);
  365. UpdateEditArea(oldRect, textArea);
  366. e.Handled = true;
  367. }
  368. if (e.Key == Key.Right)
  369. {
  370. textArea.GetNextWordCharPlace();
  371. endPoint = GetPoint(textArea);
  372. textArea.GetSelectChars(startPoint, endPoint);
  373. UpdateEditArea(oldRect, textArea);
  374. e.Handled = true;
  375. }
  376. if (e.Key == Key.Up)
  377. {
  378. textArea.GetSectionBeginCharPlace();
  379. endPoint = GetPoint(textArea);
  380. textArea.GetSelectChars(startPoint, endPoint);
  381. UpdateEditArea(oldRect, textArea);
  382. e.Handled = true;
  383. }
  384. if (e.Key == Key.Down)
  385. {
  386. textArea.GetSectionEndCharPlace();
  387. endPoint = GetPoint(textArea);
  388. textArea.GetSelectChars(startPoint, endPoint);
  389. UpdateEditArea(oldRect, textArea);
  390. e.Handled = true;
  391. }
  392. }
  393. }
  394. #endregion
  395. #region Panel
  396. public void ExpandLeftPanel(bool isExpand)
  397. {
  398. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  399. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  400. if (isExpand)
  401. {
  402. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  403. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  404. }
  405. else
  406. {
  407. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  408. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  409. }
  410. }
  411. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  412. {
  413. PropertyContainer.Width = 260;
  414. PropertyContainer.Child = propertytPanel;
  415. PropertyContainer.Visibility = visible;
  416. }
  417. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  418. {
  419. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  420. {
  421. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  422. }
  423. else if (e.PropertyName == nameof(PanelState.RightPanel))
  424. {
  425. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  426. {
  427. ExpandRightPropertyPanel(pdfContentEditControl, Visibility.Visible);
  428. }
  429. else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  430. {
  431. ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
  432. }
  433. else
  434. {
  435. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  436. }
  437. }
  438. }
  439. #endregion
  440. #region UI
  441. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  442. {
  443. ToggleButton senderBtn = sender as ToggleButton;
  444. if (senderBtn != null && PdfViewControl != null)
  445. {
  446. ClearPDFEditState(senderBtn);
  447. if (senderBtn.IsChecked == true)
  448. {
  449. TextEditParam textEditParam = new TextEditParam();
  450. textEditParam.EditType = CPDFEditType.EditText;
  451. textEditParam.IsBold = false;
  452. textEditParam.IsItalic = false;
  453. textEditParam.FontSize = 14;
  454. textEditParam.FontName = "Arial";
  455. textEditParam.FontColor = new byte[] { 0, 0, 0 };
  456. textEditParam.EditIndex = -1;
  457. textEditParam.TextAlign = TextAlignType.AlignLeft;
  458. textEditParam.Transparency = 255;
  459. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { textEditParam });
  460. DefaultSettingParam defaultSettingParam = PdfViewControl.PDFViewTool.GetDefaultSettingParam();
  461. defaultSettingParam.SetPDFEditParamm(textEditParam);
  462. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  463. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.EditText);
  464. PdfViewControl.PDFViewTool.SetCurrentEditType(CPDFEditType.EditText);
  465. }
  466. }
  467. }
  468. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  469. {
  470. ToggleButton senderBtn = sender as ToggleButton;
  471. if (senderBtn != null && PdfViewControl != null)
  472. {
  473. ClearPDFEditState(senderBtn);
  474. panelState.RightPanel = PanelState.RightPanelState.None;
  475. senderBtn.IsChecked = false;
  476. OpenFileDialog openFileDialog = new OpenFileDialog();
  477. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  478. if (openFileDialog.ShowDialog() == true)
  479. {
  480. try
  481. {
  482. bool SetImage = PdfViewControl.PDFViewTool.GetCPDFViewer().SetStampMouseImage(openFileDialog.FileName);
  483. PdfViewControl.PDFToolManager.SetCreateImagePath(openFileDialog.FileName);
  484. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsVisibleCustomMouse(SetImage);
  485. PdfViewControl.PDFViewTool.GetCPDFViewer().SetIsShowStampMouse(SetImage);
  486. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.EditImage);
  487. }
  488. catch
  489. {
  490. }
  491. }
  492. }
  493. }
  494. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  495. {
  496. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  497. {
  498. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Undo();
  499. PdfViewControl.PDFViewTool.GetCPDFViewer().UpdateRenderFrame();
  500. }
  501. }
  502. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  503. {
  504. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null)
  505. {
  506. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Redo();
  507. PdfViewControl.PDFViewTool.GetCPDFViewer().UpdateRenderFrame();
  508. }
  509. }
  510. #endregion
  511. #region
  512. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  513. {
  514. PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
  515. PdfViewControl.MouseRightButtonDownHandler += PdfViewControl_MouseRightButtonDownHandler;
  516. }
  517. private void UserControl_UnLoaded(object sender, RoutedEventArgs e)
  518. {
  519. PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
  520. }
  521. private void PDFEditEmptyPanel()
  522. {
  523. PropertyContainer.Child = pdfContentEditControl;
  524. if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
  525. {
  526. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.EditText)
  527. {
  528. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { pdfTextCreateParam });
  529. }
  530. else if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.None)
  531. {
  532. pdfContentEditControl.ClearContentControl();
  533. }
  534. }
  535. else
  536. {
  537. pdfContentEditControl.ClearContentControl();
  538. }
  539. }
  540. private CPoint GetPoint(CPDFEditTextArea textArea)
  541. {
  542. CPoint caretPoint = new CPoint();
  543. CPoint caretPointHigh = new CPoint();
  544. textArea.GetTextCursorPoints(ref caretPoint, ref caretPointHigh);
  545. var lineHeight = caretPoint.y - caretPointHigh.y;
  546. CRect caretRect = new CRect(caretPoint.x, caretPoint.y, caretPointHigh.x, caretPointHigh.y);
  547. caretPoint = new CPoint(caretRect.left, caretRect.top);
  548. return new CPoint(caretRect.left, (caretRect.top + caretRect.bottom) / 2);
  549. }
  550. /// <summary>
  551. /// Update the edit area appearance after the edit area is changed
  552. /// </summary>
  553. private void UpdateEditArea(Rect oldRect, CPDFEditArea editArea)
  554. {
  555. PdfViewControl.PDFViewTool.UpdateRender(oldRect, editArea);
  556. }
  557. private void PdfViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
  558. {
  559. ContextMenu ContextMenu = PdfViewControl.GetRightMenu();
  560. if (ContextMenu == null)
  561. {
  562. ContextMenu = new ContextMenu();
  563. }
  564. switch (e.hitTestType)
  565. {
  566. case MouseHitTestType.TextEdit:
  567. CreateTextEditMenu(sender, ref ContextMenu);
  568. break;
  569. case MouseHitTestType.ImageEdit:
  570. CreateImageEditMenu(sender, ref ContextMenu);
  571. break;
  572. case MouseHitTestType.PathEdit:
  573. CreatePathEditMenu(sender, ref ContextMenu);
  574. break;
  575. case MouseHitTestType.Unknown:
  576. List<int> pageInts = new List<int>();
  577. List<CPDFEditArea> editAreas = PdfViewControl.PDFToolManager.GetSelectedEditAreaListObject(ref pageInts);
  578. if (editAreas.Count > 0)
  579. {
  580. CreateMultiTextEditMenu(sender, ref ContextMenu);
  581. }
  582. else
  583. {
  584. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  585. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteWithoutStyle, CommandTarget = (UIElement)sender });
  586. }
  587. break;
  588. default:
  589. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  590. ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteWithoutStyle, CommandTarget = (UIElement)sender });
  591. break;
  592. }
  593. PdfViewControl.SetRightMenu(ContextMenu);
  594. }
  595. #endregion
  596. #region Property changed
  597. protected void OnPropertyChanged([CallerMemberName] string name = null)
  598. {
  599. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  600. }
  601. public void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  602. {
  603. OnPropertyChanged(e.PropertyName);
  604. if (e.PropertyName == "CanUndo" || e.PropertyName == "CanRedo")
  605. {
  606. OnCanSaveChanged?.Invoke(this, CanSave);
  607. }
  608. }
  609. #endregion
  610. #region Context menu
  611. private void AppendOpacityMenu(MenuItem parentMenu, CPDFEditArea editArea, CPDFEditType editType)
  612. {
  613. if (editArea == null)
  614. return;
  615. List<int> opacityList = new List<int>()
  616. {
  617. 25,50,75,100
  618. };
  619. Rect oldRect = DataConversionForWPF.CRectConversionForRect(editArea.GetFrame());
  620. foreach (int opacity in opacityList)
  621. {
  622. MenuItem opacityMenu = new MenuItem();
  623. opacityMenu.Header = string.Format("{0}%", opacity);
  624. opacityMenu.Click += (o, p) =>
  625. {
  626. if (editArea != null && editType == CPDFEditType.EditImage)
  627. {
  628. CPDFEditImageArea editImageArea = editArea as CPDFEditImageArea;
  629. editImageArea?.SetImageTransparency((byte)Math.Ceiling(opacity * 255 / 100D));
  630. pdfContentEditControl.RefreshThumb();
  631. UpdateEditArea(oldRect, editImageArea);
  632. }
  633. else if (editArea != null && editType == CPDFEditType.EditText)
  634. {
  635. CPDFEditTextArea editTextArea = editArea as CPDFEditTextArea;
  636. editTextArea?.SetCharsFontTransparency((byte)Math.Ceiling(opacity * 255 / 100D));
  637. UpdateEditArea(oldRect, editTextArea);
  638. }
  639. else if (editArea != null && editType == CPDFEditType.EditPath)
  640. {
  641. CPDFEditPathArea editPathArea = editArea as CPDFEditPathArea;
  642. editPathArea?.SetTransparency((byte)Math.Ceiling(opacity * 255 / 100D));
  643. UpdateEditArea(oldRect, editPathArea);
  644. }
  645. };
  646. parentMenu.Items.Add(opacityMenu);
  647. }
  648. }
  649. private void PDFToolManager_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
  650. {
  651. if (e.IsCreate)
  652. {
  653. PdfViewControl.SetIsShowStampMouse(false);
  654. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.EditImage)
  655. {
  656. PdfViewControl.PDFToolManager.SetCreateContentEditType(CPDFEditType.None);
  657. }
  658. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() == CPDFEditType.EditText)
  659. {
  660. textAreaCreating = true;
  661. }
  662. }
  663. int pageIndex = -1;
  664. CPDFEditArea editArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref pageIndex);
  665. List<int> pageInts = new List<int>();
  666. List<CPDFEditArea> editAreas = PdfViewControl.PDFToolManager.GetSelectedEditAreaListObject(ref pageInts);
  667. if (editArea != null)
  668. {
  669. if (editArea.Type == CPDFEditType.EditText)
  670. {
  671. PDFEditParam editParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editArea, pageIndex);
  672. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { (TextEditParam)editParam }, true);
  673. PropertyContainer.Child = pdfContentEditControl;
  674. }
  675. }
  676. else if (editAreas != null && editAreas.Count != 0)
  677. {
  678. List<CPDFEditTextArea> editTextAreas = editAreas.OfType<CPDFEditTextArea>().ToList();
  679. List<CPDFEditImageArea> editImageAreas = editAreas.OfType<CPDFEditImageArea>().ToList();
  680. List<CPDFEditPathArea> editPathAreas = editAreas.OfType<CPDFEditPathArea>().ToList();
  681. editTextAreas.ForEach(textArea => textArea.SelectAllChars());
  682. if (editAreas.Count == editTextAreas.Count)
  683. {
  684. List<TextEditParam> editParams = editTextAreas.
  685. Select(area => ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), area, pageInts.FirstOrDefault())).
  686. Cast<TextEditParam>().ToList();
  687. pdfContentEditControl.SetPDFTextEditData(editParams, true);
  688. PropertyContainer.Child = pdfContentEditControl;
  689. }
  690. else if (editAreas.Count == editImageAreas.Count)
  691. {
  692. List<ImageEditParam> editParams = editImageAreas.
  693. Select(area => ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), area, pageInts.FirstOrDefault())).
  694. Cast<ImageEditParam>().ToList();
  695. pdfContentEditControl.SetPDFImageEditData(editParams);
  696. PropertyContainer.Child = pdfContentEditControl;
  697. }
  698. else if (editAreas.Count == editPathAreas.Count)
  699. {
  700. List<PathEditParam> editParams = editPathAreas.
  701. Select(area => ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), area, pageInts.FirstOrDefault())).
  702. Cast<PathEditParam>().ToList();
  703. pdfContentEditControl.SetPDFPathEditData(editParams);
  704. PropertyContainer.Child = pdfContentEditControl;
  705. }
  706. else
  707. {
  708. pdfContentEditControl.ClearContentControl();
  709. }
  710. }
  711. else
  712. {
  713. return;
  714. }
  715. }
  716. private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  717. {
  718. isUpdateStartPoint = true;
  719. if (PdfViewControl.PDFToolManager.GetToolType() != ToolType.ContentEdit)
  720. {
  721. PropertyContainer.Child = pdfContentEditControl;
  722. return;
  723. }
  724. int pageIndex = -1;
  725. CPDFEditArea editAreaArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref pageIndex);
  726. if (editAreaArea == null)
  727. {
  728. if (PdfViewControl.PDFToolManager.GetCreateContentEditType() != CPDFEditType.EditText)
  729. {
  730. pdfContentEditControl.ClearContentControl();
  731. }
  732. return;
  733. }
  734. else
  735. {
  736. if (editAreaArea.Type == CPDFEditType.EditText)
  737. {
  738. PDFEditParam pDFEditParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editAreaArea, pageIndex);
  739. pdfContentEditControl.SetPDFTextEditData(new List<TextEditParam> { (TextEditParam)pDFEditParam }, true);
  740. PropertyContainer.Child = pdfContentEditControl;
  741. }
  742. else if (editAreaArea.Type == CPDFEditType.EditImage)
  743. {
  744. UIElement pageView = sender as UIElement;
  745. if (pageView != null)
  746. {
  747. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  748. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  749. }
  750. PDFEditParam pDFEditParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editAreaArea, pageIndex);
  751. pdfContentEditControl.SetPDFImageEditData(new List<ImageEditParam> { (ImageEditParam)pDFEditParam });
  752. PropertyContainer.Child = pdfContentEditControl;
  753. }
  754. else if (editAreaArea.Type == CPDFEditType.EditPath)
  755. {
  756. UIElement pageView = sender as UIElement;
  757. if (pageView != null)
  758. {
  759. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  760. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  761. }
  762. PDFEditParam pDFEditParam = ParamConverter.CPDFDataConverterToPDFEitParam(PdfViewControl.PDFToolManager.GetDocument(), editAreaArea, pageIndex);
  763. pdfContentEditControl.SetPDFPathEditData(new List<PathEditParam> { (PathEditParam)pDFEditParam });
  764. PropertyContainer.Child = pdfContentEditControl;
  765. }
  766. }
  767. }
  768. private void PdfViewControl_SplitPDFViewToolCreated(object sender, EventArgs e)
  769. {
  770. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  771. PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  772. }
  773. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  774. {
  775. UIElement pageView = sender as UIElement;
  776. if (pageView != null)
  777. {
  778. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  779. }
  780. if (imageAreaParam != null)
  781. {
  782. pdfContentEditControl.SetPDFImageEditData(new List<ImageEditParam> { (ImageEditParam)imageAreaParam });
  783. }
  784. }
  785. public void ClearViewerControl()
  786. {
  787. PDFGrid.Child = null;
  788. BotaContainer.Child = null;
  789. PropertyContainer.Child = null;
  790. displaySettingsControl = null;
  791. }
  792. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  793. {
  794. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null && CanUndo)
  795. {
  796. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Undo();
  797. }
  798. }
  799. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  800. {
  801. if (PdfViewControl != null && PdfViewControl.PDFViewTool != null && CanRedo)
  802. {
  803. PdfViewControl.PDFViewTool.GetCPDFViewer()?.UndoManager?.Redo();
  804. }
  805. }
  806. private void CreateTextEditMenu(object sender, ref ContextMenu menu)
  807. {
  808. int index = -1;
  809. CPDFEditTextArea textArea =
  810. PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref index) as CPDFEditTextArea;
  811. if (textArea != null)
  812. {
  813. if (PdfViewControl.PDFToolManager.GetDocument().GetPermissionsInfo().AllowsCopying)
  814. {
  815. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  816. }
  817. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  818. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  819. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  820. }
  821. else
  822. {
  823. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  824. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_MatchPaste"), Command = CustomCommands.PasteWithoutStyle, CommandTarget = (UIElement)sender });
  825. }
  826. }
  827. private void CreateImageEditMenu(object sender, ref ContextMenu menu)
  828. {
  829. int index = -1;
  830. CPDFEditImageArea imageArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref index) as CPDFEditImageArea;
  831. if (imageArea == null)
  832. return;
  833. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  834. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  835. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  836. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  837. MenuItem rotateLeftMenu = new MenuItem();
  838. rotateLeftMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateLeft");
  839. rotateLeftMenu.Click += (o, p) =>
  840. {
  841. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  842. imageArea.Rotate(90);
  843. pdfContentEditControl.RefreshThumb();
  844. UpdateEditArea(oldRect,imageArea);
  845. };
  846. menu.Items.Add(rotateLeftMenu);
  847. MenuItem rotateRightMenu = new MenuItem();
  848. rotateRightMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateRight");
  849. rotateRightMenu.Click += (o, p) =>
  850. {
  851. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  852. imageArea.Rotate(-90);
  853. pdfContentEditControl.RefreshThumb();
  854. UpdateEditArea(oldRect, imageArea);
  855. };
  856. menu.Items.Add(rotateRightMenu);
  857. MenuItem replaceMenu = new MenuItem();
  858. replaceMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Replace");
  859. replaceMenu.Click += (o, p) =>
  860. {
  861. OpenFileDialog openFileDialog = new OpenFileDialog();
  862. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  863. if (openFileDialog.ShowDialog() == true)
  864. {
  865. int imageWidth = 0;
  866. int imageHeight = 0;
  867. byte[] imageData = null;
  868. BitmapFrame frame = null;
  869. BitmapDecoder decoder = BitmapDecoder.Create(new Uri(openFileDialog.FileName), BitmapCreateOptions.None, BitmapCacheOption.Default);
  870. if (decoder.Frames.Count > 0)
  871. {
  872. frame = decoder.Frames[0];
  873. }
  874. if (frame != null)
  875. {
  876. imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  877. if (frame.Format != PixelFormats.Bgra32)
  878. {
  879. FormatConvertedBitmap covert = new FormatConvertedBitmap(frame, PixelFormats.Bgra32, frame.Palette, 0);
  880. covert.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  881. }
  882. else
  883. {
  884. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  885. }
  886. imageWidth = frame.PixelWidth;
  887. imageHeight = frame.PixelHeight;
  888. }
  889. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  890. imageArea.ReplaceImageArea(imageArea.GetFrame(), imageData, imageWidth, imageHeight);
  891. pdfContentEditControl.RefreshThumb();
  892. UpdateEditArea(oldRect, imageArea);
  893. }
  894. };
  895. menu.Items.Add(replaceMenu);
  896. MenuItem exportMenu = new MenuItem();
  897. exportMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Export");
  898. exportMenu.Click += (o, p) =>
  899. {
  900. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  901. {
  902. try
  903. {
  904. FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
  905. if (folderBrowserDialog.ShowDialog() == DialogResult.OK && imageArea != null)
  906. {
  907. string path = Path.GetTempPath();
  908. string uuid = Guid.NewGuid().ToString("N");
  909. string imagePath = Path.Combine(path, uuid + ".tmp");
  910. imageArea.ExtractImage(imagePath);
  911. Bitmap bitmapImage = new Bitmap(imagePath);
  912. string fileName = Path.Combine(folderBrowserDialog.SelectedPath, uuid + ".jpg");
  913. bitmapImage.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  914. Process.Start("explorer", "/select,\"" + fileName + "\"");
  915. }
  916. }
  917. catch (Exception ex)
  918. {
  919. }
  920. }
  921. };
  922. menu.Items.Add(exportMenu);
  923. MenuItem opacityMenu = new MenuItem();
  924. opacityMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Opacity");
  925. menu.Items.Add(opacityMenu);
  926. AppendOpacityMenu(opacityMenu, imageArea, CPDFEditType.EditImage);
  927. MenuItem horizonMirror = new MenuItem();
  928. horizonMirror.Header = LanguageHelper.CommonManager.GetString("Menu_HFlip");
  929. horizonMirror.Click += (o, p) =>
  930. {
  931. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  932. imageArea.HorizontalMirror();
  933. pdfContentEditControl.RefreshThumb();
  934. UpdateEditArea(oldRect, imageArea);
  935. };
  936. menu.Items.Add(horizonMirror);
  937. MenuItem verticalMirror = new MenuItem();
  938. verticalMirror.Header = LanguageHelper.CommonManager.GetString("Menu_VFlip");
  939. verticalMirror.Click += (o, p) =>
  940. {
  941. if (imageArea != null)
  942. {
  943. Rect oldRect = DataConversionForWPF.CRectConversionForRect(imageArea.GetFrame());
  944. imageArea.VerticalMirror();
  945. pdfContentEditControl.RefreshThumb();
  946. UpdateEditArea(oldRect, imageArea);
  947. }
  948. };
  949. menu.Items.Add(verticalMirror);
  950. MenuItem cropMenu = new MenuItem();
  951. cropMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Crop");
  952. cropMenu.Click += (o, p) =>
  953. {
  954. if (imageArea != null)
  955. {
  956. PdfViewControl.PDFViewTool.SetCropMode(!PdfViewControl.PDFViewTool.GetIsCropMode());
  957. }
  958. };
  959. menu.Items.Add(cropMenu);
  960. }
  961. private void CreatePathEditMenu(object sender, ref ContextMenu menu)
  962. {
  963. int index = -1;
  964. CPDFEditPathArea pathArea = PdfViewControl.PDFToolManager.GetSelectedEditAreaObject(ref index) as CPDFEditPathArea;
  965. if (pathArea == null)
  966. return;
  967. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  968. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  969. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  970. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  971. MenuItem rotateLeftMenu = new MenuItem();
  972. rotateLeftMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateLeft");
  973. rotateLeftMenu.Click += (o, p) =>
  974. {
  975. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathArea.GetFrame());
  976. pathArea.Rotate(90);
  977. UpdateEditArea(oldRect, pathArea);
  978. };
  979. menu.Items.Add(rotateLeftMenu);
  980. MenuItem rotateRightMenu = new MenuItem();
  981. rotateRightMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RotateRight");
  982. rotateRightMenu.Click += (o, p) =>
  983. {
  984. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathArea.GetFrame());
  985. pathArea.Rotate(-90);
  986. UpdateEditArea(oldRect, pathArea);
  987. };
  988. menu.Items.Add(rotateRightMenu);
  989. MenuItem opacityMenu = new MenuItem();
  990. opacityMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Opacity");
  991. menu.Items.Add(opacityMenu);
  992. AppendOpacityMenu(opacityMenu, pathArea, CPDFEditType.EditPath);
  993. MenuItem horizonMirror = new MenuItem();
  994. horizonMirror.Header = LanguageHelper.CommonManager.GetString("Menu_HFlip");
  995. horizonMirror.Click += (o, p) =>
  996. {
  997. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathArea.GetFrame());
  998. pathArea.HorizontalMirror();
  999. UpdateEditArea(oldRect, pathArea);
  1000. };
  1001. menu.Items.Add(horizonMirror);
  1002. MenuItem verticalMirror = new MenuItem();
  1003. verticalMirror.Header = LanguageHelper.CommonManager.GetString("Menu_VFlip");
  1004. verticalMirror.Click += (o, p) =>
  1005. {
  1006. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathArea.GetFrame());
  1007. pathArea.VerticalMirror();
  1008. UpdateEditArea(oldRect, pathArea);
  1009. };
  1010. menu.Items.Add(verticalMirror);
  1011. MenuItem cropMenu = new MenuItem();
  1012. cropMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Crop");
  1013. cropMenu.Click += (o, p) =>
  1014. {
  1015. if (pathArea != null)
  1016. {
  1017. PdfViewControl.PDFViewTool.SetCropMode(!PdfViewControl.PDFViewTool.GetIsCropMode());
  1018. }
  1019. };
  1020. menu.Items.Add(cropMenu);
  1021. }
  1022. private void CreateMultiTextEditMenu(object sender, ref ContextMenu menu)
  1023. {
  1024. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  1025. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  1026. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  1027. menu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  1028. }
  1029. }
  1030. }
  1031. #endregion