ContentEditControl.xaml.cs 55 KB

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