AnnotToolContentViewModel.Command.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument.Action;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKitViewer;
  5. using ComPDFKitViewer.AnnotEvent;
  6. using ComPDFKitViewer.PdfViewer;
  7. using PDF_Office.CustomControl;
  8. using PDF_Office.EventAggregators;
  9. using PDF_Office.Helper;
  10. using PDF_Office.Properties;
  11. using PDF_Office.ViewModels.BOTA;
  12. using PDF_Office.Views.BOTA;
  13. using PDFSettings;
  14. using Prism.Mvvm;
  15. using Prism.Regions;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows;
  22. using System.Windows.Controls;
  23. using System.Windows.Controls.Primitives;
  24. using System.Windows.Media;
  25. using System.Diagnostics;
  26. namespace PDF_Office.ViewModels.Tools
  27. {
  28. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  29. {
  30. #region 事件绑定和解绑
  31. private void BindingEvent()
  32. {
  33. //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
  34. //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
  35. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  36. propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  37. propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
  38. propertyPanel.DefaultStored += AnnotProperty_DefaultStored;
  39. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  40. propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
  41. }
  42. private void UnBindingEvent()
  43. {
  44. propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  45. propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
  46. propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  47. }
  48. private void BindingPDFViewerHandler()
  49. {
  50. //来自PDFViewer的响应事件
  51. if (PDFViewer != null)
  52. {
  53. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  54. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  55. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  56. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  57. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  58. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  59. PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
  60. PDFViewer.WidgetClickHander += PDFViewer_WidgetClickHander;
  61. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  62. PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
  63. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  64. PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
  65. }
  66. }
  67. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  68. {
  69. if (action == null)
  70. {
  71. return;
  72. }
  73. switch (action.ActionType)
  74. {
  75. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  76. if (PDFViewer != null)
  77. {
  78. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  79. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  80. if (dest != null)
  81. {
  82. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
  83. }
  84. }
  85. break;
  86. case C_ACTION_TYPE.ACTION_TYPE_URI:
  87. {
  88. CPDFUriAction uriAction = action as CPDFUriAction;
  89. string uri = uriAction.GetUri();
  90. try
  91. {
  92. if (!string.IsNullOrEmpty(uri))
  93. {
  94. Process.Start(uri);
  95. }
  96. }
  97. catch (Exception ex)
  98. {
  99. }
  100. }
  101. break;
  102. }
  103. }
  104. private void UnBindingPDFViewerHandler()
  105. {
  106. if (PDFViewer != null)
  107. {
  108. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  109. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  110. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  111. PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
  112. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  113. }
  114. }
  115. #endregion 事件绑定和解绑
  116. #region PDFViewer事件
  117. //选中和非选中注释
  118. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  119. {
  120. if (e != null)
  121. {
  122. var annot = e.AnnotItemsList[0];
  123. if (annot != null)
  124. {
  125. if (e.AnnotItemsList.Count == 1)
  126. {
  127. //IsAnnotCreateReset:是否为创建注释的状态
  128. if (e.IsAnnotCreateReset == false)
  129. {
  130. GetSelectedAnnots(e);
  131. }
  132. else
  133. {
  134. switch (annot.EventType)
  135. {
  136. case AnnotArgsType.AnnotLink:
  137. //viewContentViewModel.IsCreateLink = false;
  138. GetLink(e.AnnotItemsList, e);
  139. PDFViewer.SetToolParam(annot);
  140. break;
  141. }
  142. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  143. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  144. annot.EventType != AnnotArgsType.AnnotUnderline &&
  145. annot.EventType != AnnotArgsType.AnnotHighlight &&
  146. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  147. annot.EventType != AnnotArgsType.AnnotLink &&
  148. annot.EventType != AnnotArgsType.AnnotFreehand &&
  149. annot.EventType != AnnotArgsType.AnnotSticky
  150. )
  151. {
  152. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  153. {
  154. foreach (var item in ToolExpandDict)
  155. {
  156. if (item.Value == e.AnnotItemsList[0].EventType)
  157. {
  158. annot = null;//新建注释时,回到默认值
  159. FindAnnotTypeKey(item.Key, ref annot);
  160. break;
  161. }
  162. }
  163. }
  164. }
  165. //else
  166. PDFViewer.SetToolParam(annot);
  167. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  168. if (isRightMenuAddAnnot)
  169. {
  170. ShowPropertyPanel(false);
  171. }
  172. else
  173. {
  174. ShowPropertyPanel();
  175. }
  176. }
  177. }
  178. else
  179. {
  180. bool isDifferentAnnotTyle = false;
  181. var lastAnnot = annot;
  182. foreach (var item in e.AnnotItemsList)
  183. {
  184. if (lastAnnot.EventType != item.EventType)
  185. {
  186. if ((isShapAnnot(annot) == true && isShapAnnot(item) == true) || (isHightAnnot(annot) == true && isHightAnnot(item) == true))
  187. {
  188. lastAnnot = item;
  189. continue;
  190. }
  191. lastAnnot = item;
  192. isDifferentAnnotTyle = true;
  193. break;
  194. }
  195. }
  196. if (isDifferentAnnotTyle)
  197. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  198. else
  199. GetSelectedAnnots(e);
  200. }
  201. }
  202. //注释列表同步选中
  203. var list = e.GetPageAnnotsIndex();
  204. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  205. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  206. {
  207. if (list.Keys.Count == 0)
  208. {
  209. return;
  210. }
  211. var pageindex = new List<int>(list.Keys);
  212. List<int> annotes = new List<int>();
  213. list.TryGetValue(pageindex[0], out annotes);
  214. int annoteindex = annotes[0];
  215. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  216. if (viewModel != null)
  217. {
  218. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  219. }
  220. }
  221. }
  222. else
  223. {
  224. if (BtnLinkIsChecked == false)
  225. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  226. }
  227. }
  228. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  229. {
  230. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  231. annot.EventType == AnnotArgsType.AnnotSquare ||
  232. annot.EventType == AnnotArgsType.AnnotLine
  233. )
  234. {
  235. return true;
  236. }
  237. else
  238. {
  239. return false;
  240. }
  241. }
  242. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  243. {
  244. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  245. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  246. annot.EventType == AnnotArgsType.AnnotHighlight ||
  247. annot.EventType == AnnotArgsType.AnnotStrikeout
  248. )
  249. {
  250. return true;
  251. }
  252. else
  253. {
  254. return false;
  255. }
  256. }
  257. private void GetSelectedAnnots(AnnotAttribEvent e)
  258. {
  259. var annot = e.AnnotItemsList[0];
  260. switch (annot.EventType)
  261. {
  262. case AnnotArgsType.AnnotHighlight:
  263. GetHighLight(e.AnnotItemsList);
  264. break;
  265. case AnnotArgsType.AnnotUnderline:
  266. GetUnderLine(e.AnnotItemsList);
  267. break;
  268. case AnnotArgsType.AnnotStrikeout:
  269. GetStrikeout(e.AnnotItemsList);
  270. break;
  271. case AnnotArgsType.AnnotSquiggly:
  272. GetSquiggly(e.AnnotItemsList);
  273. break;
  274. case AnnotArgsType.AnnotFreehand:
  275. GetFreehand(e.AnnotItemsList);
  276. break;
  277. case AnnotArgsType.AnnotFreeText:
  278. GetFreetext(e.AnnotItemsList);
  279. break;
  280. case AnnotArgsType.AnnotSquare:
  281. GetRect(e.AnnotItemsList);
  282. break;
  283. case AnnotArgsType.AnnotCircle:
  284. GetCircle(e.AnnotItemsList);
  285. break;
  286. case AnnotArgsType.AnnotLine:
  287. bool isLine = true;
  288. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  289. {
  290. if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_NONE)
  291. {
  292. isLine = false;
  293. }
  294. }
  295. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  296. {
  297. if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_NONE)
  298. {
  299. isLine = false;
  300. }
  301. }
  302. if (isLine)
  303. GetArrowLine("Line", e.AnnotItemsList);
  304. else
  305. GetArrowLine("Arrow", e.AnnotItemsList);
  306. break;
  307. case AnnotArgsType.AnnotLink:
  308. //viewContentViewModel.IsCreateLink = false;
  309. GetLink(e.AnnotItemsList, e);
  310. break;
  311. case AnnotArgsType.AnnotSticky:
  312. GetStickyNote(e.AnnotItemsList);
  313. break;
  314. }
  315. }
  316. //在注释工具的状态下,右键菜单
  317. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  318. {
  319. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  320. return;
  321. switch (e.CommandType)
  322. {
  323. case CommandType.Context:
  324. if (e.AnnotEventArgsList.Count > 0)
  325. {
  326. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  327. {
  328. //绑定标记密文处右键菜单
  329. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  330. }
  331. else
  332. {
  333. if (e.AnnotEventArgsList.Count == 1)
  334. {
  335. var selectedAnnot = e.AnnotEventArgsList[0];
  336. switch (selectedAnnot.EventType)
  337. {
  338. case AnnotArgsType.AnnotHighlight:
  339. case AnnotArgsType.AnnotUnderline:
  340. case AnnotArgsType.AnnotStrikeout:
  341. case AnnotArgsType.AnnotSquiggly:
  342. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  343. break;
  344. case AnnotArgsType.AnnotFreehand:
  345. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  346. break;
  347. case AnnotArgsType.AnnotFreeText:
  348. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  349. break;
  350. case AnnotArgsType.AnnotSticky:
  351. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  352. break;
  353. case AnnotArgsType.AnnotSquare:
  354. case AnnotArgsType.AnnotCircle:
  355. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  356. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  357. break;
  358. case AnnotArgsType.AnnotLine:
  359. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  360. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  361. break;
  362. case AnnotArgsType.AnnotLink:
  363. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  364. break;
  365. case AnnotArgsType.AnnotStamp:
  366. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  367. break;
  368. }
  369. }
  370. else
  371. {
  372. bool isHigh = true;//是否为高亮
  373. foreach (var item in e.AnnotEventArgsList)
  374. {
  375. if (isHightAnnot(item) == false)
  376. {
  377. isHigh = false;
  378. break;
  379. }
  380. }
  381. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  382. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  383. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList,sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  384. }
  385. }
  386. if (e.PopupMenu != null)
  387. {
  388. e.Handle = true;
  389. }
  390. }
  391. else
  392. {
  393. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  394. {
  395. e.PopupMenu = NoneSelectAnnotContextMenu(sender, e);
  396. if (e.PopupMenu != null)
  397. {
  398. e.Handle = true;
  399. }
  400. }
  401. else
  402. {
  403. e.PopupMenu = ViewerContextMenu();
  404. if (e.PopupMenu != null)
  405. {
  406. e.Handle = true;
  407. }
  408. }
  409. }
  410. break;
  411. }
  412. }
  413. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  414. {
  415. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  416. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  417. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  418. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  419. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  420. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  421. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  422. {
  423. e.PopupMenu = popMenu;
  424. e.Handle = true;
  425. if (popMenu != null && popMenu.Items.Count == 5)
  426. {
  427. //复制
  428. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  429. menuItem.CommandTarget = PDFViewer;
  430. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  431. //导出
  432. menuItem = popMenu.Items[1] as MenuItem;
  433. menuItem.CommandTarget = PDFViewer;
  434. if (menuItem.Items.Count == 3)
  435. {
  436. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  437. menuItem1.CommandTarget = PDFViewer;
  438. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  439. menuItem1 = menuItem.Items[1] as MenuItem;
  440. menuItem1.CommandTarget = PDFViewer;
  441. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  442. menuItem1 = menuItem.Items[2] as MenuItem;
  443. menuItem1.CommandTarget = PDFViewer;
  444. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  445. }
  446. //裁剪
  447. menuItem = popMenu.Items[2] as MenuItem;
  448. menuItem.CommandTarget = PDFViewer;
  449. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  450. //缩放至所选区域
  451. menuItem = popMenu.Items[3] as MenuItem;
  452. menuItem.CommandTarget = PDFViewer;
  453. menuItem.Visibility = Visibility.Collapsed;
  454. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  455. //打印
  456. menuItem = popMenu.Items[4] as MenuItem;
  457. menuItem.CommandTarget = PDFViewer;
  458. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  459. }
  460. }
  461. }
  462. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  463. {
  464. switch (e.Key)
  465. {
  466. case "CloseSnap":
  467. {
  468. #region to do
  469. //var item = PDFViewerTab.SelectedItem as TabItem;
  470. //if (item == null)
  471. //{
  472. // ClearSelectedToolPanel();
  473. // return;
  474. //}
  475. //Grid grid = item.Content as Grid;
  476. //if (grid == null || grid.Children.Count == 0)
  477. //{
  478. // ClearSelectedToolPanel();
  479. // return;
  480. //}
  481. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  482. //if (pdfViewer == null)
  483. //{
  484. // ClearSelectedToolPanel();
  485. // return;
  486. //}
  487. #endregion to do
  488. switch (PDFViewer.MouseMode)
  489. {
  490. case MouseModes.SelectTextTool:
  491. break;
  492. default:
  493. BtnSelecttoolIsChecked = false;
  494. BtnHandIsChecked = true;
  495. PDFViewer.EnableZoom(true);
  496. PDFViewer.EnableScroll(true);
  497. break;
  498. }
  499. }
  500. break;
  501. default:
  502. break;
  503. }
  504. }
  505. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  506. {
  507. if (e != null && e.Count > 0)
  508. {
  509. for (int i = 0; i < e.Count; i++)
  510. {
  511. AnnotEditEvent editEvent = e[i];
  512. switch (editEvent.EditAction)
  513. {
  514. case ActionType.Add:
  515. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  516. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  517. {
  518. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  519. if (viewModel != null)
  520. {
  521. int pageindex = editEvent.PageIndex;
  522. int annotindex = editEvent.AnnotIndex;
  523. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  524. }
  525. }
  526. break;
  527. case ActionType.Del:
  528. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  529. if (isTabItemAnnotation)
  530. {
  531. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  532. if (viewModel != null)
  533. {
  534. int pageindex = editEvent.PageIndex;
  535. int annotindex = editEvent.AnnotIndex;
  536. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  537. }
  538. }
  539. break;
  540. case ActionType.Modify:
  541. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  542. if (bOTAContent.TabItemAnnotation.IsSelected)
  543. {
  544. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  545. if (viewModel != null)
  546. {
  547. int pageindex = editEvent.PageIndex;
  548. int annotindex = editEvent.AnnotIndex;
  549. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  550. }
  551. }
  552. break;
  553. case ActionType.TextEdit:
  554. break;
  555. default:
  556. break;
  557. }
  558. }
  559. }
  560. }
  561. private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e)
  562. {
  563. }
  564. #endregion PDFViewer事件
  565. #region BindingEvent事件
  566. private void AnnotProperty_DefaultStored(object sender, object e)
  567. {
  568. }
  569. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  570. {
  571. if (e != null)
  572. {
  573. AnnotHandlerEventArgs annotArgs = null;
  574. foreach (AnnotArgsType argsType in e.Keys)
  575. {
  576. switch (argsType)
  577. {
  578. case AnnotArgsType.AnnotSquare:
  579. annotArgs = GetRect();
  580. break;
  581. case AnnotArgsType.AnnotCircle:
  582. annotArgs = GetCircle();
  583. break;
  584. case AnnotArgsType.AnnotLine:
  585. var LineTag = e[argsType] as string;
  586. annotArgs = GetArrowLine(LineTag);
  587. break;
  588. }
  589. if (annotArgs != null)
  590. {
  591. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  592. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  593. PDFViewer.SetToolParam(annotArgs);
  594. }
  595. ShowPropertyPanel();
  596. }
  597. }
  598. }
  599. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  600. {
  601. if (e != null)
  602. {
  603. foreach (AnnotArgsType argsType in e.Keys)
  604. {
  605. switch (argsType)
  606. {
  607. case AnnotArgsType.AnnotHighlight:
  608. if (e[argsType] is Color)
  609. {
  610. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  611. }
  612. if (e[argsType] is double)
  613. {
  614. HighLightOpacity = (double)e[argsType];
  615. }
  616. break;
  617. case AnnotArgsType.AnnotUnderline:
  618. if (e[argsType] is Color)
  619. {
  620. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  621. }
  622. if (e[argsType] is double)
  623. {
  624. underLineOpacity = (double)e[argsType];
  625. }
  626. break;
  627. case AnnotArgsType.AnnotSquiggly:
  628. if (e[argsType] is Color)
  629. {
  630. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  631. }
  632. if (e[argsType] is double)
  633. {
  634. SquigglyOpacity = (double)e[argsType];
  635. }
  636. break;
  637. case AnnotArgsType.AnnotStrikeout:
  638. if (e[argsType] is Color)
  639. {
  640. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  641. }
  642. if (e[argsType] is double)
  643. {
  644. StrikeoutOpacity = (double)e[argsType];
  645. }
  646. break;
  647. case AnnotArgsType.AnnotFreehand:
  648. if (e[argsType] is Color)
  649. {
  650. // FreehandPath.Fill = new SolidColorBrush((Color)e[argsType]);
  651. }
  652. if (e[argsType] is double)
  653. {
  654. // FreehandPath.Opacity = (double)e[argsType];
  655. }
  656. break;
  657. case AnnotArgsType.AnnotErase:
  658. if (e[argsType] is ToggleButton)
  659. {
  660. ToggleButton clickBtn = e[argsType] as ToggleButton;
  661. if (clickBtn.IsChecked == true)
  662. {
  663. if (clickBtn.Tag.ToString() == "PenBtn")
  664. {
  665. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  666. btn.Tag = "Freehand"; btn.IsChecked = true;
  667. BtnMyTools_Click(btn);
  668. break;
  669. }
  670. EraseArgs eraseArgs = new EraseArgs();
  671. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  672. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  673. eraseArgs.Thickness = 10;
  674. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  675. if (annotProperty != null)
  676. {
  677. eraseArgs.Thickness = annotProperty.Thickness;
  678. }
  679. PDFViewer.ClearSelectAnnots(false);
  680. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  681. PDFViewer.SetToolParam(eraseArgs);
  682. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  683. annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor;
  684. annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor;
  685. annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness;
  686. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  687. if (eraseArgs != null)
  688. eraseArgsList.Add(eraseArgs);
  689. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList, annotAttribsList);
  690. }
  691. }
  692. break;
  693. }
  694. }
  695. }
  696. }
  697. #endregion BindingEvent事件
  698. }
  699. }