CPDFViewerTool.xaml.cs 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKit.PDFDocument.Action;
  4. using ComPDFKit.PDFPage;
  5. using ComPDFKit.Tool.DrawTool;
  6. using ComPDFKit.Tool.FillTool;
  7. using ComPDFKit.Tool.Help;
  8. using ComPDFKit.Tool.SettingParam;
  9. using ComPDFKit.Viewer.Helper;
  10. using ComPDFKit.Viewer.Layer;
  11. using ComPDFKitViewer;
  12. using ComPDFKitViewer.Annot;
  13. using ComPDFKitViewer.BaseObject;
  14. using ComPDFKitViewer.Helper;
  15. using ComPDFKitViewer.Layer;
  16. using ComPDFKitViewer.Widget;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Diagnostics;
  20. using System.Windows;
  21. using System.Windows.Controls;
  22. using System.Windows.Controls.Primitives;
  23. using System.Windows.Input;
  24. using System.Windows.Media;
  25. using UndoAction = ComPDFKitViewer.Helper.UndoAction;
  26. namespace ComPDFKit.Tool
  27. {
  28. public struct MouseEventObject
  29. {
  30. public MouseEventArgs mouseButtonEventArgs;
  31. public MouseHitTestType hitTestType;
  32. public C_ANNOTATION_TYPE annotType;
  33. /// <summary>
  34. /// Identifies whether the object is created
  35. /// </summary>
  36. public bool IsCreate;
  37. public bool IsDrawing;
  38. public bool IsMersured;
  39. public object Data;
  40. }
  41. public enum MouseHitTestType
  42. {
  43. Unknown,
  44. Text,
  45. Annot,
  46. SelectRect,
  47. Widget,
  48. TextEdit,
  49. ImageEdit,
  50. PathEdit,
  51. ImageSelect,
  52. MultiTextEdit,
  53. SelectedPageRect,
  54. MultiSelector
  55. }
  56. public enum ToolType
  57. {
  58. None = -1,
  59. Viewer,
  60. Pan,
  61. CreateAnnot,
  62. WidgetEdit,
  63. ContentEdit,
  64. Customize,
  65. SelectedPage,
  66. /// <summary>
  67. /// Scroller Tool
  68. /// </summary>
  69. ViewerScroller
  70. }
  71. public partial class CPDFViewerTool : UserControl
  72. {
  73. public bool IsDocumentModified
  74. {
  75. get => isDocumentModified;
  76. set
  77. {
  78. isDocumentModified = value;
  79. DocumentModifiedChanged?.Invoke(this, EventArgs.Empty);
  80. }
  81. }
  82. public CPDFViewerTool()
  83. {
  84. InitializeComponent();
  85. BindCommand();
  86. Application.Current.Exit += Current_Exit;
  87. InsertSelectImageView();
  88. InsertAnnotView();
  89. InsertAnnotEditView();
  90. InsertWidgetView();
  91. InsertSelectedRectView();
  92. InsertMultiSelectedRectView();
  93. InsertCustomizeToolView();
  94. InsertSelectTextView();
  95. //Frame Select
  96. InsertFrameSelectToolView();
  97. InsertTextEditView();
  98. InsertPageSelectedRectView();
  99. AnnotSelectInsert();
  100. FillManager = new FillManager(this);
  101. }
  102. internal void InvokeMouseLeftDown(MouseEventObject e)
  103. {
  104. MouseLeftButtonDownHandler?.Invoke(this, e);
  105. }
  106. private void Current_Exit(object sender, ExitEventArgs e)
  107. {
  108. GetCPDFViewer().Dispose();
  109. }
  110. protected override Visual GetVisualChild(int index)
  111. {
  112. return base.GetVisualChild(index);
  113. }
  114. protected override int VisualChildrenCount => base.VisualChildrenCount;
  115. public event EventHandler<MouseEventObject> MouseLeftButtonDownHandler;
  116. public event EventHandler<MouseEventObject> MouseLeftButtonUpHandler;
  117. public event EventHandler<MouseEventObject> MouseMoveHandler;
  118. public event EventHandler<MouseEventObject> MouseRightButtonDownHandler;
  119. public event EventHandler<ScrollChangedEventArgs> ScrollChangedHandler;
  120. public event EventHandler DrawChanged;
  121. public event EventHandler DocumentModifiedChanged;
  122. private ToolType currentModel = ToolType.Viewer;
  123. DefaultSettingParam defaultSettingParam = new DefaultSettingParam();
  124. DefaultDrawParam defaultDrawParam = new DefaultDrawParam();
  125. MeasureSetting measureSetting = new MeasureSetting();
  126. Point Point = new Point();
  127. Point CachePoint = new Point();
  128. private bool isMultiSelected;
  129. private bool isDocumentModified = false;
  130. public FillManager FillManager { get; private set; }
  131. public bool CanAddTextEdit = true;
  132. protected bool isContinueCreateTextEdit = false;
  133. public bool GetIsMultiSelected()
  134. {
  135. return isMultiSelected;
  136. }
  137. /// <summary>
  138. /// Set whether continuous text editing is required
  139. /// </summary>
  140. /// <param name="isContinueCreateTextEdit"></param>
  141. public void SetContinueCreateTextEdit(bool isContinueCreateTextEdit)
  142. {
  143. this.isContinueCreateTextEdit = isContinueCreateTextEdit;
  144. CanAddTextEdit = true;
  145. }
  146. /// <summary>
  147. /// Does it support multiple selection
  148. /// </summary>
  149. /// <param name="isMulti">true Can MultiSelected</param>
  150. public void SetIsMultiSelected(bool isMulti)
  151. {
  152. isMultiSelected = isMulti;
  153. }
  154. public DefaultSettingParam GetDefaultSettingParam()
  155. {
  156. return defaultSettingParam;
  157. }
  158. public DefaultDrawParam GetDefaultDrawParam()
  159. {
  160. return defaultDrawParam;
  161. }
  162. /// <summary>
  163. /// Set default painting parameters
  164. /// </summary>
  165. /// <param name="defaultDrawParam"></param>
  166. public void SetDefaultDrawParam(DefaultDrawParam defaultDrawParam = null)
  167. {
  168. if (defaultDrawParam == null)
  169. {
  170. this.defaultDrawParam = new DefaultDrawParam();
  171. }
  172. else
  173. {
  174. this.defaultDrawParam = defaultDrawParam;
  175. }
  176. }
  177. public MeasureSetting GetMeasureSetting()
  178. {
  179. return measureSetting;
  180. }
  181. public bool IsSelectRectMousePoint()
  182. {
  183. if (DrawSelectRectDownEvent() && cacheHitTestAnnot != null)
  184. {
  185. return true;
  186. }
  187. return false;
  188. }
  189. private void LinkAnnotAction(BaseAnnot annot)
  190. {
  191. AnnotData data = annot.GetAnnotData();
  192. CPDFLinkAnnotation linkAnnot = data.Annot as CPDFLinkAnnotation;
  193. CPDFAction action = linkAnnot.GetLinkAction();
  194. if (action != null)
  195. {
  196. ActionProcess(action);
  197. }
  198. else
  199. {
  200. CPDFDestination dest = linkAnnot.GetDestination(PDFViewer.GetDocument());
  201. if (dest != null)
  202. {
  203. CPDFGoToAction gotoAction = new CPDFGoToAction();
  204. gotoAction.SetDestination(PDFViewer.GetDocument(), dest);
  205. ActionProcess(gotoAction);
  206. }
  207. }
  208. }
  209. public void ActionProcess(CPDFAction action)
  210. {
  211. if (action == null)
  212. {
  213. return;
  214. }
  215. switch (action.ActionType)
  216. {
  217. case C_ACTION_TYPE.ACTION_TYPE_NAMED:
  218. {
  219. CPDFNamedAction namedAction = action as CPDFNamedAction;
  220. string namedStr = namedAction.GetName();
  221. switch (namedStr)
  222. {
  223. case "FirstPage":
  224. {
  225. PDFViewer?.GoToPage(0, new Point(0, 0));
  226. break;
  227. }
  228. case "LastPage":
  229. {
  230. PDFViewer?.GoToPage(PDFViewer.GetDocument().PageCount - 1, new Point(0, 0));
  231. break;
  232. }
  233. case "NextPage":
  234. if (PDFViewer != null)
  235. {
  236. int nextIndex = PDFViewer.CurrentRenderFrame.PageIndex + 1;
  237. if (nextIndex < PDFViewer.GetDocument().PageCount)
  238. {
  239. PDFViewer.GoToPage(nextIndex, new Point(0, 0));
  240. }
  241. }
  242. break;
  243. case "PrevPage":
  244. if (PDFViewer != null)
  245. {
  246. int prevIndex = PDFViewer.CurrentRenderFrame.PageIndex - 1;
  247. if (prevIndex >= 0)
  248. {
  249. PDFViewer.GoToPage(prevIndex, new Point(0, 0));
  250. }
  251. }
  252. break;
  253. default:
  254. break;
  255. }
  256. break;
  257. }
  258. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  259. if (PDFViewer != null)
  260. {
  261. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  262. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.GetDocument());
  263. if (dest != null)
  264. {
  265. Size pageSize = DataConversionForWPF.CSizeConversionForSize(PDFViewer.GetDocument().GetPageSize(dest.PageIndex));
  266. PDFViewer.GoToPage(dest.PageIndex, new Point(dest.Position_X, pageSize.Height - dest.Position_Y));
  267. }
  268. }
  269. break;
  270. case C_ACTION_TYPE.ACTION_TYPE_GOTOR:
  271. if (PDFViewer != null)
  272. {
  273. CPDFGoToRAction gotorAction = action as CPDFGoToRAction;
  274. CPDFDestination dest = gotorAction.GetDestination(PDFViewer.GetDocument());
  275. if (dest != null)
  276. {
  277. Size pageSize = DataConversionForWPF.CSizeConversionForSize(PDFViewer.GetDocument().GetPageSize(dest.PageIndex));
  278. PDFViewer.GoToPage(dest.PageIndex, new Point(dest.Position_X, pageSize.Height - dest.Position_Y));
  279. }
  280. }
  281. break;
  282. case C_ACTION_TYPE.ACTION_TYPE_URI:
  283. {
  284. CPDFUriAction uriAction = action as CPDFUriAction;
  285. string uri = uriAction.GetUri();
  286. try
  287. {
  288. if (!string.IsNullOrEmpty(uri))
  289. {
  290. Process.Start(uri);
  291. }
  292. }
  293. catch (Exception ex)
  294. {
  295. }
  296. }
  297. break;
  298. default:
  299. break;
  300. }
  301. }
  302. protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
  303. {
  304. if (isContinueCreateTextEdit)
  305. {
  306. if (lastSelectedRect != null)
  307. {
  308. CanAddTextEdit = false;
  309. }
  310. else
  311. {
  312. CanAddTextEdit = true;
  313. }
  314. }
  315. if (PDFViewer == null || PDFViewer.CurrentRenderFrame == null || PDFViewer.IsRendering)
  316. {
  317. return;
  318. }
  319. if (!HitTestBorder())
  320. {
  321. RemovePopTextUI();
  322. }
  323. Focus();
  324. if (FillManager?.MouseDownHandle(e) == true)
  325. {
  326. return;
  327. }
  328. Mouse.Capture(this, CaptureMode.SubTree);
  329. MouseEventObject mouseEventObject = new MouseEventObject
  330. {
  331. mouseButtonEventArgs = e,
  332. hitTestType = MouseHitTestType.Unknown,
  333. annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE,
  334. IsCreate = false
  335. };
  336. if (currentModel == ToolType.ViewerScroller)
  337. {
  338. // Scroller Tool Only Scrolle
  339. MouseLeftButtonDownHandler?.Invoke(this, mouseEventObject);
  340. return;
  341. }
  342. AnnotData beforeSelectAnnotData = GetSelectAnnotData();
  343. if (isDrawSelectRect)
  344. {
  345. if (e.ClickCount == 2)
  346. {
  347. // Refresh the currently selected annotation object to ensure it is the latest
  348. AnnotHitTest();
  349. if (cacheHitTestAnnot is FreeTextAnnot)
  350. {
  351. BuildPopTextUI(cacheHitTestAnnot);
  352. isDrawSelectRect = false;
  353. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  354. mouseEventObject.IsMersured = cacheHitTestAnnot.GetAnnotData().Annot.IsMeasured();
  355. MouseLeftButtonDownHandler?.Invoke(this, mouseEventObject);
  356. return;
  357. }
  358. if (cacheHitTestAnnot is StickyNoteAnnot)
  359. {
  360. (cacheHitTestAnnot as StickyNoteAnnot).PopStickyNote();
  361. }
  362. }
  363. // Click inside the selected rectangle area
  364. if (DrawSelectRectDownEvent() && cacheHitTestAnnot != null)
  365. {
  366. AnnotWidgetHitTest();
  367. mouseEventObject.hitTestType = MouseHitTestType.SelectRect;
  368. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  369. mouseEventObject.IsMersured = cacheHitTestAnnot.GetAnnotData().Annot.IsMeasured();
  370. MouseLeftButtonDownHandler?.Invoke(this, mouseEventObject);
  371. return;
  372. }
  373. else
  374. {
  375. CleanSelectedRect();
  376. }
  377. }
  378. if (IsDrawEditAnnot)
  379. {
  380. // Click inside the selected rectangle area
  381. if (DrawEditAnnotDownEvent() && cacheHitTestAnnot != null)
  382. {
  383. AnnotWidgetHitTest();
  384. mouseEventObject.hitTestType = MouseHitTestType.SelectRect;
  385. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  386. mouseEventObject.IsMersured = cacheHitTestAnnot.GetAnnotData().Annot.IsMeasured();
  387. MouseLeftButtonDownHandler?.Invoke(this, mouseEventObject);
  388. return;
  389. }
  390. }
  391. Point = e.GetPosition(this);
  392. // Annotation selection effect
  393. if ((currentModel == ToolType.Pan
  394. || currentModel == ToolType.CreateAnnot)
  395. && AnnotHitTest()
  396. && IsCanSave()
  397. && !PDFViewer.GetIsShowStampMouse()
  398. )
  399. {
  400. //if (!IsCacheRedaction)
  401. {
  402. if (cacheHitTestAnnot?.CurrentType == C_ANNOTATION_TYPE.C_ANNOTATION_LINK && currentModel != ToolType.CreateAnnot)
  403. {
  404. LinkAnnotAction(cacheHitTestAnnot);
  405. }
  406. else
  407. {
  408. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  409. {
  410. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  411. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  412. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  413. };
  414. if (cacheHitTestAnnot != null && list.Contains(cacheHitTestAnnot.CurrentType))
  415. {
  416. mouseEventObject.IsMersured = cacheHitTestAnnot.GetAnnotData().Annot.IsMeasured();
  417. SetEditAnnotObject();
  418. }
  419. else
  420. {
  421. if (AllowMultiSelect &&
  422. (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
  423. {
  424. if (!AnnotSelectAreaHitTest())
  425. {
  426. if (AnnotMoveHitTest())
  427. {
  428. BaseAnnot hitAnnot = PDFViewer?.AnnotHitTest() as BaseAnnot;
  429. if (beforeSelectAnnotData != null)
  430. {
  431. AnnotSelectAddItem(beforeSelectAnnotData);
  432. }
  433. if (AnnotSelectGetCount() == 0 && hitAnnot != null)
  434. {
  435. AnnotSelectAddItem(hitAnnot.GetAnnotData());
  436. }
  437. mouseEventObject.hitTestType = MouseHitTestType.Annot;
  438. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  439. }
  440. else
  441. {
  442. AnnotSelectAreaHit();
  443. }
  444. }
  445. AnnotSelectMoveHit();
  446. }
  447. else
  448. {
  449. if (GetAnnotSelectsRect() != null)
  450. {
  451. AnnotSelectMoveHit();
  452. }
  453. else
  454. {
  455. SelectedAnnot();
  456. }
  457. }
  458. }
  459. isDrawSelectRect = true;
  460. }
  461. }
  462. mouseEventObject.hitTestType = MouseHitTestType.Annot;
  463. if (cacheHitTestAnnot != null)
  464. {
  465. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  466. }
  467. else
  468. {
  469. mouseEventObject.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE;
  470. }
  471. }
  472. else if ((currentModel == ToolType.Pan
  473. || currentModel == ToolType.CreateAnnot) && AnnotSelectAreaHitTest())
  474. {
  475. if (GetAnnotSelectsRect() != null)
  476. {
  477. AnnotSelectMoveHit();
  478. return;
  479. }
  480. }
  481. // Form selected effect
  482. else if ((currentModel == ToolType.Pan || currentModel == ToolType.Viewer) && AnnotWidgetHitTest())
  483. {
  484. mouseEventObject.hitTestType = MouseHitTestType.Widget;
  485. mouseEventObject.annotType = cacheMoveWidget.GetAnnotData().AnnotType;
  486. FormClickProcess();
  487. }
  488. else if ((currentModel == ToolType.Pan || currentModel == ToolType.Viewer))
  489. {
  490. if (AnnotHitTest() && cacheHitTestAnnot.CurrentType == C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
  491. {
  492. LinkAnnotAction(cacheHitTestAnnot);
  493. }
  494. if (!IsText() && DrawDownSelectImage(true))
  495. {
  496. mouseEventObject.hitTestType = MouseHitTestType.ImageSelect;
  497. }
  498. else
  499. {
  500. if (!AnnotSelectAreaHitTest())
  501. {
  502. AnnotSelectAreaHit();
  503. }
  504. ReDrawSelectImage();
  505. }
  506. }
  507. // Form creation mode
  508. else if (currentModel == ToolType.WidgetEdit)
  509. {
  510. if (!AnnotSelectAreaHitTest())
  511. {
  512. if (AnnotWidgetHitTest())
  513. {
  514. BaseWidget hitWidget = PDFViewer?.AnnotHitTest() as BaseWidget;
  515. cacheHitTestAnnot = null;
  516. if (AnnotSelectGetCount() == 0 && hitWidget != null)
  517. {
  518. AnnotSelectAddItem(hitWidget.GetAnnotData());
  519. cacheHitTestAnnot = hitWidget;
  520. SelectedAnnot();
  521. }
  522. mouseEventObject.hitTestType = MouseHitTestType.Annot;
  523. mouseEventObject.annotType = cacheMoveWidget.GetAnnotData().AnnotType;
  524. }
  525. else
  526. {
  527. AnnotSelectAreaHit();
  528. }
  529. }
  530. else
  531. {
  532. AnnotSelectMoveHit();
  533. return;
  534. }
  535. }
  536. // Content editing mode
  537. else if (currentModel == ToolType.ContentEdit)
  538. {
  539. OpenSelectedMulti(isMultiSelected);
  540. if (!PDFViewer.GetIsShowStampMouse())
  541. {
  542. DrawTextEditDownEvent(true);
  543. }
  544. if (lastSelectedRect != null)
  545. {
  546. //Multi selection processing optimization, other click effects
  547. DrawEndFrameSelect();
  548. if (!Keyboard.IsKeyDown(multiKey) || !isMultiSelected)
  549. {
  550. CleanSelectedMultiRect();
  551. OpenSelectedMulti(false);
  552. if (PDFViewer.CurrentRenderFrame != null)
  553. {
  554. currentZoom = PDFViewer.CurrentRenderFrame.ZoomFactor;
  555. if (PDFViewer.CurrentRenderFrame.IsCacheEditPage == true && currentModel == ToolType.ContentEdit)
  556. {
  557. SetEditTextRect(PDFViewer.CurrentRenderFrame);
  558. if (selectedEditPageIndex != -1 && selectedEditAreaIndex != -1)
  559. {
  560. DrawSelectedEditAreaForIndex();
  561. }
  562. }
  563. }
  564. ReDrawSelectedMultiRect();
  565. }
  566. if (lastSelectedRect == null)
  567. {
  568. return;
  569. }
  570. SelectedMultiRect(lastSelectedRect.GetRect(), lastSelectedRect.GetMaxRect(), SelectedType.PDFEdit);
  571. HideDrawSelectedMultiRect();
  572. lastSelectedRect.DataChanged -= SelectedRect_DataChanged;
  573. lastSelectedRect.DataChanged += SelectedRect_DataChanged;
  574. }
  575. else
  576. {
  577. if (Keyboard.IsKeyDown(multiKey) && isMultiSelected)
  578. {
  579. DelMultiSelectRect();
  580. }
  581. if (HitTestMultiSelectedRect())
  582. {
  583. mouseEventObject.hitTestType = MouseHitTestType.MultiTextEdit;
  584. }
  585. else
  586. {
  587. //Clear the currently selected object
  588. startSelectedRect = null;
  589. startSelectedIndex = -1;
  590. startSelectedPageIndex = -1;
  591. startSelectedEditAreaObject = null;
  592. CleanSelectedMultiRect();
  593. OpenSelectedMulti(false);
  594. if (PDFViewer.CurrentRenderFrame != null)
  595. {
  596. currentZoom = PDFViewer.CurrentRenderFrame.ZoomFactor;
  597. if (PDFViewer.CurrentRenderFrame.IsCacheEditPage == true && currentModel == ToolType.ContentEdit)
  598. {
  599. SetEditTextRect(PDFViewer.CurrentRenderFrame);
  600. if (selectedEditPageIndex != -1 && selectedEditAreaIndex != -1)
  601. {
  602. DrawSelectedEditAreaForIndex();
  603. }
  604. }
  605. }
  606. ReDrawSelectedMultiRect();
  607. }
  608. }
  609. }
  610. else if (currentModel == ToolType.SelectedPage)
  611. {
  612. if (HitTestPageSelectedRect())
  613. {
  614. }
  615. else
  616. {
  617. CleanPageSelectedRect();
  618. CreatePageSelectdRect();
  619. }
  620. mouseEventObject.hitTestType = MouseHitTestType.SelectedPageRect;
  621. }
  622. MouseLeftButtonDownHandler?.Invoke(this, mouseEventObject);
  623. }
  624. protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
  625. {
  626. if (PDFViewer == null || PDFViewer.CurrentRenderFrame == null || PDFViewer.IsRendering)
  627. {
  628. return;
  629. }
  630. if (FillManager?.MouseUpHandle(e) == true)
  631. {
  632. return;
  633. }
  634. if (currentModel == ToolType.Pan || currentModel == ToolType.CreateAnnot)
  635. {
  636. bool areaSelectAdd = AnnotSelectAreaSelect(false, true);
  637. if (AnnotMoveHitTest())
  638. {
  639. BaseAnnot checkItem = PDFViewer?.AnnotHitTest();
  640. AnnotSelectAddItem(checkItem?.GetAnnotData(), !AnnotSelectAreaHitTest());
  641. }
  642. if (AnnotSelectGetCount() > 0)
  643. {
  644. CleanSelectedRect();
  645. }
  646. if (IsMoved == false && AnnotSelectAreaHitTest() == false && AnnotMoveHitTest() == false)
  647. {
  648. AnnotSelectClean();
  649. }
  650. if (AnnotSelectGetCount() == 1)
  651. {
  652. cacheHitTestAnnot = AnnotSelectGetAnnot();
  653. if (cacheHitTestAnnot != null)
  654. {
  655. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
  656. SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
  657. if (selectedRect != null)
  658. {
  659. if (IsMoved && areaSelectAdd == false)
  660. {
  661. selectedRect.UpdateAnnotData(cacheHitTestAnnot.GetAnnotData());
  662. }
  663. else
  664. {
  665. selectedRect.SetAnnotData(cacheHitTestAnnot.GetAnnotData(), PDFViewer);
  666. }
  667. selectedRect.Draw();
  668. }
  669. isDrawSelectRect = true;
  670. }
  671. }
  672. }
  673. if (currentModel == ToolType.WidgetEdit)
  674. {
  675. bool areaSelectAdd = AnnotSelectAreaSelect(true);
  676. if (AnnotMoveHitTest())
  677. {
  678. BaseWidget checkItem = PDFViewer?.AnnotHitTest() as BaseWidget;
  679. AnnotSelectAddItem(checkItem?.GetAnnotData(), !AnnotSelectAreaHitTest());
  680. }
  681. if (AnnotSelectGetCount() > 1)
  682. {
  683. CleanSelectedRect();
  684. }
  685. if (IsMoved == false && AnnotSelectAreaHitTest() == false && AnnotWidgetHitTest() == false)
  686. {
  687. AnnotSelectClean();
  688. }
  689. if (AnnotSelectGetCount() == 1)
  690. {
  691. cacheHitTestAnnot = AnnotSelectGetAnnot();
  692. if (cacheHitTestAnnot != null)
  693. {
  694. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
  695. SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
  696. if (selectedRect != null)
  697. {
  698. if (IsMoved && areaSelectAdd == false)
  699. {
  700. selectedRect.UpdateAnnotData(cacheHitTestAnnot.GetAnnotData());
  701. }
  702. else
  703. {
  704. selectedRect.SetAnnotData(cacheHitTestAnnot.GetAnnotData(), PDFViewer);
  705. }
  706. selectedRect.Draw();
  707. }
  708. isDrawSelectRect = true;
  709. }
  710. }
  711. }
  712. MouseEventObject mouseEventObject = new MouseEventObject
  713. {
  714. mouseButtonEventArgs = e,
  715. hitTestType = MouseHitTestType.Unknown,
  716. annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE,
  717. IsCreate = false
  718. };
  719. if (isDrawSelectRect || IsDrawEditAnnot)
  720. {
  721. mouseEventObject.hitTestType = MouseHitTestType.SelectRect;
  722. if (cacheHitTestAnnot != null)
  723. {
  724. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  725. }
  726. else
  727. {
  728. mouseEventObject.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE;
  729. }
  730. }
  731. MouseLeftButtonUpHandler?.Invoke(this, mouseEventObject);
  732. ReleaseMouseCapture();
  733. if (currentModel == ToolType.WidgetEdit || currentModel == ToolType.Pan || currentModel == ToolType.CreateAnnot)
  734. {
  735. AnnotSelectUpdate();
  736. AnnotSelectDraw();
  737. AnnotSelectSave();
  738. AreaMoveData = new AnnotSelectAreaData();
  739. }
  740. IsMoved = false;
  741. }
  742. protected override async void OnMouseMove(MouseEventArgs e)
  743. {
  744. IsMoved = e.LeftButton == MouseButtonState.Pressed;
  745. if (PDFViewer == null || PDFViewer.CurrentRenderFrame == null || PDFViewer.IsRendering)
  746. {
  747. return;
  748. }
  749. Cursor oldCursor = this.Cursor;
  750. Cursor newCursor = this.Cursor;
  751. MouseEventObject mouseEventObject = new MouseEventObject
  752. {
  753. mouseButtonEventArgs = e,
  754. hitTestType = MouseHitTestType.Unknown,
  755. annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE,
  756. IsCreate = false
  757. };
  758. if (currentModel == ToolType.ViewerScroller)
  759. {
  760. // Scroller Tool Only Scrolle
  761. MouseLeftButtonDownHandler?.Invoke(this, mouseEventObject);
  762. return;
  763. }
  764. if (Mouse.LeftButton != MouseButtonState.Pressed)
  765. {
  766. List<ToolType> allowModeList = new List<ToolType>()
  767. {
  768. ToolType.Pan,
  769. ToolType.Viewer
  770. };
  771. if (allowModeList.Contains(currentModel))
  772. {
  773. newCursor = Cursors.Arrow;
  774. if (caheMoveAnnot is BaseWidget)
  775. {
  776. BaseWidget widget = (BaseWidget)caheMoveAnnot;
  777. if (widget.GetFormType() == PDFAnnotation.Form.C_WIDGET_TYPE.WIDGET_PUSHBUTTON && PDFViewer != null)
  778. {
  779. newCursor = Cursors.Hand;
  780. }
  781. }
  782. if (caheMoveAnnot is LinkAnnot)
  783. {
  784. newCursor = Cursors.Hand;
  785. }
  786. }
  787. }
  788. if (!isDrawSelectRect && !IsDrawEditAnnot)
  789. {
  790. if (AnnotMoveHitTest())
  791. {
  792. if (isCacheRedaction)
  793. {
  794. (caheMoveAnnot as RedactionAnnot).SetIsMouseHover(true);
  795. (caheMoveAnnot as RedactionAnnot).Draw();
  796. }
  797. mouseEventObject.annotType = caheMoveAnnot.GetAnnotData().AnnotType;
  798. mouseEventObject.IsMersured = caheMoveAnnot.GetAnnotData().Annot.IsMeasured();
  799. }
  800. else
  801. {
  802. if (isCacheRedaction)
  803. {
  804. isCacheRedaction = false;
  805. (caheMoveAnnot as RedactionAnnot).SetIsMouseHover(false);
  806. (caheMoveAnnot as RedactionAnnot).Draw();
  807. }
  808. caheMoveAnnot = null;
  809. if ((currentModel == ToolType.Pan || currentModel == ToolType.Viewer))
  810. {
  811. if (GetTextSelectInfo() == null)
  812. {
  813. DrawMoveSelectImage();
  814. }
  815. }
  816. }
  817. }
  818. else
  819. {
  820. if (AnnotMoveHitTest())
  821. {
  822. if (DrawSelectRectDownEvent() == false && Mouse.LeftButton != MouseButtonState.Pressed)
  823. {
  824. mouseEventObject.annotType = caheMoveAnnot.GetAnnotData().AnnotType;
  825. }
  826. if (isCacheRedaction)
  827. {
  828. (caheMoveAnnot as RedactionAnnot)?.SetIsMouseHover(true);
  829. (caheMoveAnnot as RedactionAnnot)?.Draw();
  830. }
  831. }
  832. else
  833. {
  834. if (isCacheRedaction)
  835. {
  836. (caheMoveAnnot as RedactionAnnot)?.SetIsMouseHover(false);
  837. (caheMoveAnnot as RedactionAnnot)?.Draw();
  838. }
  839. }
  840. if (mouseEventObject.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_NONE)
  841. {
  842. mouseEventObject.hitTestType = MouseHitTestType.SelectRect;
  843. if (cacheHitTestAnnot != null)
  844. {
  845. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  846. mouseEventObject.IsMersured = cacheHitTestAnnot.GetAnnotData().Annot.IsMeasured();
  847. }
  848. else
  849. {
  850. mouseEventObject.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE;
  851. }
  852. }
  853. }
  854. if (currentModel == ToolType.WidgetEdit)
  855. {
  856. AnnotSelectAreaDraw();
  857. if (!AnnotSelectMoveDraw())
  858. {
  859. AnnotSelectAreaHover();
  860. }
  861. }
  862. if ((currentModel == ToolType.Pan || currentModel == ToolType.CreateAnnot) && !IsText() && IsSelectText())
  863. {
  864. AnnotSelectAreaDraw();
  865. if (!AnnotSelectMoveDraw())
  866. {
  867. AnnotSelectAreaHover();
  868. }
  869. }
  870. MouseMoveHandler?.Invoke(this, mouseEventObject);
  871. PDFViewer.SetCustomMousePoint(Mouse.GetPosition(this).Y, Mouse.GetPosition(this).X);
  872. if (oldCursor != newCursor)
  873. {
  874. this.Cursor = newCursor;
  875. }
  876. }
  877. protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
  878. {
  879. BaseLayer baseLayer = PDFViewer.GetViewForTag(CreateAnnotTag);
  880. bool isCreating = (baseLayer as CreateAnnotTool).IsCreating();
  881. if (PDFViewer.IsRendering || isCreating)
  882. {
  883. ContextMenu = null;
  884. return;
  885. }
  886. MouseEventObject mouseEventObject = new MouseEventObject
  887. {
  888. mouseButtonEventArgs = e,
  889. hitTestType = MouseHitTestType.Unknown,
  890. annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE,
  891. IsCreate = false
  892. };
  893. if (currentModel == ToolType.Pan || currentModel == ToolType.Viewer)
  894. {
  895. if (GetMousePointToTextSelectInfo())
  896. {
  897. mouseEventObject.hitTestType = MouseHitTestType.Text;
  898. }
  899. }
  900. if (isDrawSelectRect && !AnnotSelectAreaHitTest())
  901. {
  902. // Click inside the selected rectangle area
  903. if (DrawSelectRectDownEvent() && cacheHitTestAnnot != null)
  904. {
  905. mouseEventObject.hitTestType = MouseHitTestType.SelectRect;
  906. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  907. MouseRightButtonDownHandler?.Invoke(this, mouseEventObject);
  908. return;
  909. }
  910. }
  911. if (IsDrawEditAnnot)
  912. {
  913. // Click inside the selected rectangle area
  914. if (DrawEditAnnotDownEvent() && cacheHitTestAnnot != null)
  915. {
  916. mouseEventObject.hitTestType = MouseHitTestType.SelectRect;
  917. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  918. MouseRightButtonDownHandler?.Invoke(this, mouseEventObject);
  919. return;
  920. }
  921. }
  922. Point = e.GetPosition(this);
  923. // Annotation selection effect
  924. if ((currentModel == ToolType.Pan || currentModel == ToolType.CreateAnnot))
  925. {
  926. if (AnnotHitTest() && !AnnotSelectAreaHitTest())
  927. {
  928. if (!isCacheRedaction)
  929. {
  930. if (cacheHitTestAnnot?.CurrentType == C_ANNOTATION_TYPE.C_ANNOTATION_LINK && currentModel != ToolType.CreateAnnot)
  931. {
  932. LinkAnnotAction(cacheHitTestAnnot);
  933. }
  934. else
  935. {
  936. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  937. {
  938. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  939. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  940. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  941. };
  942. if (cacheHitTestAnnot != null && list.Contains(cacheHitTestAnnot.CurrentType))
  943. {
  944. SetEditAnnotObject();
  945. DrawEditAnnotLayer();
  946. }
  947. else
  948. {
  949. SelectedAnnot();
  950. DrawSelectedLayer();
  951. }
  952. isDrawSelectRect = true;
  953. }
  954. }
  955. mouseEventObject.hitTestType = MouseHitTestType.Annot;
  956. if (cacheHitTestAnnot != null)
  957. {
  958. mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
  959. }
  960. else
  961. {
  962. mouseEventObject.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE;
  963. }
  964. }
  965. else
  966. {
  967. CleanSelectedRect();
  968. CleanEditAnnot();
  969. }
  970. }
  971. // Form selection effect
  972. if ((currentModel == ToolType.Pan || currentModel == ToolType.Viewer) && AnnotWidgetHitTest())
  973. {
  974. mouseEventObject.hitTestType = MouseHitTestType.Widget;
  975. mouseEventObject.annotType = cacheMoveWidget.GetAnnotData().AnnotType;
  976. FormClickProcess();
  977. }
  978. // Form creation mode
  979. if (currentModel == ToolType.WidgetEdit)
  980. {
  981. if (!AnnotSelectAreaHitTest())
  982. {
  983. if (AnnotWidgetHitTest())
  984. {
  985. cacheHitTestAnnot = PDFViewer?.AnnotHitTest() as BaseWidget;
  986. SelectedAnnot();
  987. DrawSelectedLayer();
  988. mouseEventObject.hitTestType = MouseHitTestType.Annot;
  989. mouseEventObject.annotType = cacheMoveWidget.GetAnnotData().AnnotType;
  990. AnnotSelectClean();
  991. AnnotSelectAddItem(cacheHitTestAnnot?.GetAnnotData());
  992. }
  993. else
  994. {
  995. CleanSelectedRect();
  996. }
  997. }
  998. else
  999. {
  1000. mouseEventObject.hitTestType = MouseHitTestType.MultiSelector;
  1001. }
  1002. }
  1003. // Content editing mode
  1004. if (currentModel == ToolType.ContentEdit)
  1005. {
  1006. if (e.ClickCount == 1)
  1007. {
  1008. DrawTextEditDownEvent(false);
  1009. if (GetLastSelectedRect() != null)
  1010. {
  1011. EditAreaObject editAreaObject = GetEditAreaObjectForRect(lastSelectedRect);
  1012. switch (editAreaObject.cPDFEditArea.Type)
  1013. {
  1014. case CPDFEditType.EditText:
  1015. mouseEventObject.hitTestType = MouseHitTestType.TextEdit;
  1016. break;
  1017. case CPDFEditType.EditImage:
  1018. mouseEventObject.hitTestType = MouseHitTestType.ImageEdit;
  1019. break;
  1020. case CPDFEditType.EditPath:
  1021. mouseEventObject.hitTestType = MouseHitTestType.PathEdit;
  1022. break;
  1023. default:
  1024. break;
  1025. }
  1026. }
  1027. }
  1028. }
  1029. else
  1030. {
  1031. if ((currentModel == ToolType.Viewer || currentModel == ToolType.Pan) && mouseEventObject.hitTestType == MouseHitTestType.Unknown && DrawDownSelectImage(false))
  1032. {
  1033. mouseEventObject.hitTestType = MouseHitTestType.ImageSelect;
  1034. }
  1035. }
  1036. if (currentModel == ToolType.SelectedPage)
  1037. {
  1038. if (HitTestPageSelectedRect())
  1039. {
  1040. mouseEventObject.hitTestType = MouseHitTestType.SelectedPageRect;
  1041. }
  1042. }
  1043. if (AnnotSelectAreaHitTest())
  1044. {
  1045. mouseEventObject.hitTestType = MouseHitTestType.MultiSelector;
  1046. }
  1047. MouseRightButtonDownHandler?.Invoke(this, mouseEventObject);
  1048. }
  1049. public bool GetIsCropMode()
  1050. {
  1051. if (lastSelectedRect != null)
  1052. {
  1053. return lastSelectedRect.GetCurrentDrawPointType() == DrawPointType.Crop;
  1054. }
  1055. return false;
  1056. }
  1057. public void SetCropMode(bool crop)
  1058. {
  1059. if (lastSelectedRect != null)
  1060. {
  1061. List<PointControlType> ignoreList = new List<PointControlType>();
  1062. if (crop)
  1063. {
  1064. lastSelectedRect.SetCurrentDrawPointType(DrawPointType.Crop);
  1065. ignoreList.Add(PointControlType.Body);
  1066. // Initialize ClipRect
  1067. ClipThickness = new Thickness(0, 0, 0, 0);
  1068. if (editArea.TryGetValue(lastSelectedRect, out EditAreaObject editAreaObject))
  1069. {
  1070. cropIndex = editAreaObject.EditAreaIndex;
  1071. }
  1072. lastSelectedRect.DataChanged -= LastSelectedRect_DataChanged;
  1073. }
  1074. else
  1075. {
  1076. lastSelectedRect.SetCurrentDrawPointType(DrawPointType.Square);
  1077. cropIndex = -1;
  1078. lastSelectedRect.DataChanged += LastSelectedRect_DataChanged;
  1079. }
  1080. lastSelectedRect.SetIgnorePoints(ignoreList);
  1081. lastSelectedRect.Draw();
  1082. }
  1083. }
  1084. internal void SetToolType(ToolType model)
  1085. {
  1086. currentModel = model;
  1087. CPDFViewer pdfViewer = GetCPDFViewer();
  1088. if (pdfViewer != null)
  1089. {
  1090. if (currentModel == ToolType.WidgetEdit)
  1091. {
  1092. pdfViewer.IsHideFormShow = true;
  1093. }
  1094. else
  1095. {
  1096. pdfViewer.IsHideFormShow = false;
  1097. }
  1098. }
  1099. }
  1100. public ToolType GetToolType()
  1101. {
  1102. return currentModel;
  1103. }
  1104. public void SavePoint()
  1105. {
  1106. CachePoint = Point;
  1107. }
  1108. public void CleanPoint()
  1109. {
  1110. CachePoint = new Point();
  1111. }
  1112. private void CPDFViewerTool_Loaded(object sender, RoutedEventArgs e)
  1113. {
  1114. PDFViewer.DrawChanged += PDFViewer_DrawChanged;
  1115. PDFViewer.UndoManager.HistoryChanged += UndoManager_HistoryChanged;
  1116. PDFViewer.MouseEnter += PDFViewer_MouseEnter;
  1117. PDFViewer.MouseLeave += PDFViewer_MouseLeave;
  1118. }
  1119. private void PDFViewer_MouseLeave(object sender, MouseEventArgs e)
  1120. {
  1121. PDFViewer.IsVisibilityMouse(false);
  1122. }
  1123. private void PDFViewer_MouseEnter(object sender, MouseEventArgs e)
  1124. {
  1125. PDFViewer.IsVisibilityMouse(true);
  1126. }
  1127. private void UndoManager_HistoryChanged(object sender, KeyValuePair<UndoAction, IHistory> data)
  1128. {
  1129. IsDocumentModified = true;
  1130. }
  1131. private void CPDFViewerTool_Unloaded(object sender, RoutedEventArgs e)
  1132. {
  1133. PDFViewer.DrawChanged -= PDFViewer_DrawChanged;
  1134. }
  1135. private void PDFViewer_DrawChanged(object sender, EventArgs e)
  1136. {
  1137. SizeChangeds();
  1138. AnnotSelectUpdate();
  1139. AnnotSelectDraw();
  1140. DrawChanged?.Invoke(this, e);
  1141. }
  1142. public void SizeChangeds()
  1143. {
  1144. if (IsLoaded)
  1145. {
  1146. if (cacheHitTestAnnot != null)
  1147. {
  1148. BaseLayer baseLayer1 = PDFViewer.GetViewForTag(PDFViewer.GetAnnotViewTag());
  1149. bool Update = (baseLayer1 as AnnotLayer).GetUpdate(ref cacheHitTestAnnot);
  1150. if (Update)
  1151. {
  1152. if (IsDrawEditAnnot)
  1153. {
  1154. SetEditAnnotObject();
  1155. DrawEditAnnotLayer();
  1156. }
  1157. if (isDrawSelectRect)
  1158. {
  1159. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  1160. {
  1161. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  1162. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  1163. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  1164. };
  1165. if (cacheHitTestAnnot != null && list.Contains(cacheHitTestAnnot.CurrentType))
  1166. {
  1167. SetEditAnnotObject();
  1168. DrawEditAnnotLayer();
  1169. }
  1170. else
  1171. {
  1172. SelectedAnnot();
  1173. }
  1174. DrawSelectedLayer();
  1175. }
  1176. }
  1177. else
  1178. {
  1179. SelectedAnnot(null);
  1180. CleanEditAnnot(true);
  1181. }
  1182. }
  1183. else if (selectedPageIndex != -1 && selectedAnnotIndex != -1)
  1184. {
  1185. BaseLayer baseLayer1 = PDFViewer.GetViewForTag(PDFViewer.GetAnnotViewTag());
  1186. cacheHitTestAnnot = (baseLayer1 as AnnotLayer).GetSelectedAnnot(ref selectedPageIndex, ref selectedAnnotIndex);
  1187. if (cacheHitTestAnnot != null)
  1188. {
  1189. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  1190. {
  1191. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  1192. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  1193. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  1194. };
  1195. if (cacheHitTestAnnot != null && list.Contains(cacheHitTestAnnot.CurrentType))
  1196. {
  1197. SetEditAnnotObject();
  1198. DrawEditAnnotLayer();
  1199. }
  1200. else
  1201. {
  1202. SelectedAnnot();
  1203. }
  1204. DrawSelectedLayer();
  1205. isDrawSelectRect = true;
  1206. }
  1207. }
  1208. if (PDFViewer.CurrentRenderFrame != null)
  1209. {
  1210. currentZoom = PDFViewer.CurrentRenderFrame.ZoomFactor;
  1211. if (PDFViewer.CurrentRenderFrame.IsCacheEditPage == true && currentModel == ToolType.ContentEdit)
  1212. {
  1213. SetEditTextRect(PDFViewer.CurrentRenderFrame);
  1214. if (selectedEditPageIndex != -1 && selectedEditAreaIndex != -1)
  1215. {
  1216. DrawSelectedEditAreaForIndex();
  1217. }
  1218. }
  1219. }
  1220. ReDrawSelectedMultiRect();
  1221. ReDrawWidget();
  1222. ReDrawSelectText();
  1223. ReDrawSelectImage();
  1224. UpdateFormHitPop();
  1225. UpdateTextPop();
  1226. }
  1227. }
  1228. private void ScrollViewer_MouseUp(object sender, MouseButtonEventArgs e)
  1229. {
  1230. }
  1231. private void ScrollViewer_MouseDown(object sender, MouseButtonEventArgs e)
  1232. {
  1233. }
  1234. private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
  1235. {
  1236. ScrollChangedHandler?.Invoke(this, e);
  1237. }
  1238. public void SetPageImageScale(float imageScale)
  1239. {
  1240. if (imageScale <= 0)
  1241. {
  1242. imageScale = 1;
  1243. }
  1244. CPDFViewer.PageImageScale = imageScale;
  1245. }
  1246. public float GetPageImageScale()
  1247. {
  1248. return CPDFViewer.PageImageScale;
  1249. }
  1250. }
  1251. }