AnnotToolContentViewModel.Command.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. //PDFViewer.SetToolParam(annot);
  132. }
  133. else
  134. {
  135. switch (annot.EventType)
  136. {
  137. case AnnotArgsType.AnnotLink:
  138. //viewContentViewModel.IsCreateLink = false;
  139. GetLink(e.AnnotItemsList, e);
  140. PDFViewer.SetToolParam(annot);
  141. break;
  142. }
  143. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  144. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  145. annot.EventType != AnnotArgsType.AnnotUnderline &&
  146. annot.EventType != AnnotArgsType.AnnotHighlight &&
  147. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  148. annot.EventType != AnnotArgsType.AnnotLink &&
  149. annot.EventType != AnnotArgsType.AnnotFreehand &&
  150. annot.EventType != AnnotArgsType.AnnotSticky
  151. )
  152. {
  153. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  154. {
  155. foreach (var item in ToolExpandDict)
  156. {
  157. if (item.Value == e.AnnotItemsList[0].EventType)
  158. {
  159. annot = null;//新建注释时,回到默认值
  160. FindAnnotTypeKey(item.Key, ref annot);
  161. break;
  162. }
  163. }
  164. }
  165. }
  166. //else
  167. PDFViewer.SetToolParam(annot);
  168. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  169. if (isRightMenuAddAnnot)
  170. {
  171. ShowPropertyPanel(false);
  172. }
  173. else
  174. {
  175. ShowPropertyPanel();
  176. }
  177. }
  178. }
  179. else
  180. {
  181. bool isDifferentAnnotTyle = false;
  182. var lastAnnot = annot;
  183. foreach (var item in e.AnnotItemsList)
  184. {
  185. if (lastAnnot.EventType != item.EventType)
  186. {
  187. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  188. {
  189. lastAnnot = item;
  190. continue;
  191. }
  192. lastAnnot = item;
  193. isDifferentAnnotTyle = true;
  194. break;
  195. }
  196. }
  197. if (isDifferentAnnotTyle)
  198. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  199. else
  200. GetSelectedAnnots(e);
  201. }
  202. }
  203. }
  204. else
  205. {
  206. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  207. }
  208. }
  209. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  210. {
  211. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  212. annot.EventType == AnnotArgsType.AnnotSquare ||
  213. annot.EventType == AnnotArgsType.AnnotLine
  214. )
  215. {
  216. return true;
  217. }
  218. else
  219. {
  220. return false;
  221. }
  222. }
  223. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  224. {
  225. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  226. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  227. annot.EventType == AnnotArgsType.AnnotHighlight ||
  228. annot.EventType == AnnotArgsType.AnnotStrikeout
  229. )
  230. {
  231. return true;
  232. }
  233. else
  234. {
  235. return false;
  236. }
  237. }
  238. private void GetSelectedAnnots(AnnotAttribEvent e)
  239. {
  240. var annot = e.AnnotItemsList[0];
  241. switch (annot.EventType)
  242. {
  243. case AnnotArgsType.AnnotHighlight:
  244. GetHighLight(e.AnnotItemsList);
  245. break;
  246. case AnnotArgsType.AnnotUnderline:
  247. GetUnderLine(e.AnnotItemsList);
  248. break;
  249. case AnnotArgsType.AnnotStrikeout:
  250. GetStrikeout(e.AnnotItemsList);
  251. break;
  252. case AnnotArgsType.AnnotSquiggly:
  253. GetSquiggly(e.AnnotItemsList);
  254. break;
  255. case AnnotArgsType.AnnotFreehand:
  256. GetFreehand(e.AnnotItemsList);
  257. break;
  258. case AnnotArgsType.AnnotFreeText:
  259. GetFreetext(e.AnnotItemsList);
  260. break;
  261. case AnnotArgsType.AnnotSquare:
  262. GetRect(e.AnnotItemsList);
  263. break;
  264. case AnnotArgsType.AnnotCircle:
  265. GetCircle(e.AnnotItemsList);
  266. break;
  267. case AnnotArgsType.AnnotLine:
  268. bool isLine = true;
  269. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  270. {
  271. 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)
  272. {
  273. isLine = false;
  274. }
  275. }
  276. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  277. {
  278. 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)
  279. {
  280. isLine = false;
  281. }
  282. }
  283. if (isLine)
  284. GetArrowLine("Line", e.AnnotItemsList);
  285. else
  286. GetArrowLine("Arrow", e.AnnotItemsList);
  287. break;
  288. case AnnotArgsType.AnnotLink:
  289. //viewContentViewModel.IsCreateLink = false;
  290. GetLink(e.AnnotItemsList, e);
  291. break;
  292. case AnnotArgsType.AnnotSticky:
  293. GetStickyNote(e.AnnotItemsList);
  294. break;
  295. }
  296. }
  297. //在注释工具的状态下,右键菜单
  298. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  299. {
  300. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  301. return;
  302. switch (e.CommandType)
  303. {
  304. case CommandType.Context:
  305. if (e.AnnotEventArgsList.Count > 0)
  306. {
  307. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  308. {
  309. //绑定标记密文处右键菜单
  310. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  311. }
  312. else
  313. {
  314. if(e.AnnotEventArgsList.Count == 1)
  315. {
  316. var selectedAnnot = e.AnnotEventArgsList[0];
  317. switch(selectedAnnot.EventType)
  318. {
  319. case AnnotArgsType.AnnotHighlight:
  320. case AnnotArgsType.AnnotUnderline:
  321. case AnnotArgsType.AnnotStrikeout:
  322. case AnnotArgsType.AnnotSquiggly:
  323. e.PopupMenu = SelectHightAnnotMenu(sender);
  324. break;
  325. case AnnotArgsType.AnnotFreehand:
  326. e.PopupMenu = SelectFreeHandAnnotMenu(sender);
  327. break;
  328. case AnnotArgsType.AnnotFreeText:
  329. e.PopupMenu = SelectFreeTextAnnotMenu(sender);
  330. break;
  331. case AnnotArgsType.AnnotSticky:
  332. e.PopupMenu = SelectStrickNoteAnnotMenu(sender);
  333. break;
  334. case AnnotArgsType.AnnotSquare:
  335. case AnnotArgsType.AnnotLine:
  336. case AnnotArgsType.AnnotCircle:
  337. e.PopupMenu = SelectShapeAnnotMenu(sender);
  338. break;
  339. case AnnotArgsType.AnnotLink:
  340. e.PopupMenu = SelectHightAnnotMenu(sender);
  341. break;
  342. case AnnotArgsType.AnnotStamp:
  343. e.PopupMenu = SelectHightAnnotMenu(sender);
  344. break;
  345. }
  346. }
  347. else
  348. {
  349. bool isHigh = true;//是否为高亮
  350. foreach(var item in e.AnnotEventArgsList)
  351. {
  352. if(isHightAnnot(item) == false)
  353. {
  354. isHigh = false;
  355. break;
  356. }
  357. }
  358. e.PopupMenu = SelectMultiAnnotMenu(sender, isHigh);
  359. }
  360. }
  361. if (e.PopupMenu != null)
  362. {
  363. e.Handle = true;
  364. }
  365. }
  366. else
  367. {
  368. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  369. {
  370. e.PopupMenu = NoneSelectAnnotContextMenu(sender, e);
  371. if (e.PopupMenu != null)
  372. {
  373. e.Handle = true;
  374. }
  375. }
  376. else
  377. {
  378. e.PopupMenu = ViewerContextMenu();
  379. if (e.PopupMenu != null)
  380. {
  381. e.Handle = true;
  382. }
  383. }
  384. }
  385. break;
  386. }
  387. }
  388. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  389. {
  390. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  391. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  392. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  393. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  394. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  395. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  396. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  397. {
  398. e.PopupMenu = popMenu;
  399. e.Handle = true;
  400. if (popMenu != null && popMenu.Items.Count == 5)
  401. {
  402. //复制
  403. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  404. menuItem.CommandTarget = PDFViewer;
  405. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  406. //导出
  407. menuItem = popMenu.Items[1] as MenuItem;
  408. menuItem.CommandTarget = PDFViewer;
  409. if (menuItem.Items.Count == 3)
  410. {
  411. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  412. menuItem1.CommandTarget = PDFViewer;
  413. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  414. menuItem1 = menuItem.Items[1] as MenuItem;
  415. menuItem1.CommandTarget = PDFViewer;
  416. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  417. menuItem1 = menuItem.Items[2] as MenuItem;
  418. menuItem1.CommandTarget = PDFViewer;
  419. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  420. }
  421. //裁剪
  422. menuItem = popMenu.Items[2] as MenuItem;
  423. menuItem.CommandTarget = PDFViewer;
  424. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  425. //缩放至所选区域
  426. menuItem = popMenu.Items[3] as MenuItem;
  427. menuItem.CommandTarget = PDFViewer;
  428. menuItem.Visibility = Visibility.Collapsed;
  429. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  430. //打印
  431. menuItem = popMenu.Items[4] as MenuItem;
  432. menuItem.CommandTarget = PDFViewer;
  433. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  434. }
  435. }
  436. }
  437. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  438. {
  439. switch (e.Key)
  440. {
  441. case "CloseSnap":
  442. {
  443. #region to do
  444. //var item = PDFViewerTab.SelectedItem as TabItem;
  445. //if (item == null)
  446. //{
  447. // ClearSelectedToolPanel();
  448. // return;
  449. //}
  450. //Grid grid = item.Content as Grid;
  451. //if (grid == null || grid.Children.Count == 0)
  452. //{
  453. // ClearSelectedToolPanel();
  454. // return;
  455. //}
  456. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  457. //if (pdfViewer == null)
  458. //{
  459. // ClearSelectedToolPanel();
  460. // return;
  461. //}
  462. #endregion to do
  463. switch (PDFViewer.MouseMode)
  464. {
  465. case MouseModes.SelectTextTool:
  466. break;
  467. default:
  468. BtnSelecttoolIsChecked = false;
  469. BtnHandIsChecked = true;
  470. PDFViewer.EnableZoom(true);
  471. PDFViewer.EnableScroll(true);
  472. break;
  473. }
  474. }
  475. break;
  476. default:
  477. break;
  478. }
  479. }
  480. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  481. {
  482. if (e != null && e.Count > 0)
  483. {
  484. for (int i = 0; i < e.Count; i++)
  485. {
  486. AnnotEditEvent editEvent = e[i];
  487. switch (editEvent.EditAction)
  488. {
  489. case ActionType.Add:
  490. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  491. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  492. {
  493. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  494. if (viewModel != null)
  495. {
  496. int pageindex = editEvent.PageIndex;
  497. int annotindex = editEvent.AnnotIndex;
  498. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  499. }
  500. }
  501. break;
  502. case ActionType.Del:
  503. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  504. if (isTabItemAnnotation)
  505. {
  506. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  507. if (viewModel != null)
  508. {
  509. int pageindex = editEvent.PageIndex;
  510. int annotindex = editEvent.AnnotIndex;
  511. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  512. }
  513. }
  514. break;
  515. case ActionType.Modify:
  516. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  517. if (bOTAContent.TabItemAnnotation.IsSelected)
  518. {
  519. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  520. if (viewModel != null)
  521. {
  522. int pageindex = editEvent.PageIndex;
  523. int annotindex = editEvent.AnnotIndex;
  524. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  525. }
  526. }
  527. break;
  528. case ActionType.TextEdit:
  529. break;
  530. default:
  531. break;
  532. }
  533. }
  534. }
  535. }
  536. private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e)
  537. {
  538. }
  539. #endregion PDFViewer事件
  540. #region BindingEvent事件
  541. private void AnnotProperty_DefaultStored(object sender, object e)
  542. {
  543. }
  544. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  545. {
  546. if (e != null)
  547. {
  548. AnnotHandlerEventArgs annotArgs = null;
  549. foreach (AnnotArgsType argsType in e.Keys)
  550. {
  551. switch (argsType)
  552. {
  553. case AnnotArgsType.AnnotSquare:
  554. annotArgs = GetRect();
  555. break;
  556. case AnnotArgsType.AnnotCircle:
  557. annotArgs = GetCircle();
  558. break;
  559. case AnnotArgsType.AnnotLine:
  560. var LineTag = e[argsType] as string;
  561. annotArgs = GetArrowLine(LineTag);
  562. break;
  563. }
  564. if (annotArgs != null)
  565. {
  566. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  567. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  568. PDFViewer.SetToolParam(annotArgs);
  569. }
  570. ShowPropertyPanel();
  571. }
  572. }
  573. }
  574. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  575. {
  576. if (e != null)
  577. {
  578. foreach (AnnotArgsType argsType in e.Keys)
  579. {
  580. switch (argsType)
  581. {
  582. case AnnotArgsType.AnnotHighlight:
  583. if (e[argsType] is Color)
  584. {
  585. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  586. }
  587. if (e[argsType] is double)
  588. {
  589. HighLightOpacity = (double)e[argsType];
  590. }
  591. break;
  592. case AnnotArgsType.AnnotUnderline:
  593. if (e[argsType] is Color)
  594. {
  595. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  596. }
  597. if (e[argsType] is double)
  598. {
  599. underLineOpacity = (double)e[argsType];
  600. }
  601. break;
  602. case AnnotArgsType.AnnotSquiggly:
  603. if (e[argsType] is Color)
  604. {
  605. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  606. }
  607. if (e[argsType] is double)
  608. {
  609. SquigglyOpacity = (double)e[argsType];
  610. }
  611. break;
  612. case AnnotArgsType.AnnotStrikeout:
  613. if (e[argsType] is Color)
  614. {
  615. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  616. }
  617. if (e[argsType] is double)
  618. {
  619. StrikeoutOpacity = (double)e[argsType];
  620. }
  621. break;
  622. case AnnotArgsType.AnnotFreehand:
  623. if (e[argsType] is Color)
  624. {
  625. // FreehandPath.Fill = new SolidColorBrush((Color)e[argsType]);
  626. }
  627. if (e[argsType] is double)
  628. {
  629. // FreehandPath.Opacity = (double)e[argsType];
  630. }
  631. break;
  632. case AnnotArgsType.AnnotErase:
  633. if (e[argsType] is ToggleButton)
  634. {
  635. ToggleButton clickBtn = e[argsType] as ToggleButton;
  636. if (clickBtn.IsChecked == true)
  637. {
  638. if (clickBtn.Tag.ToString() == "PenBtn")
  639. {
  640. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  641. btn.Tag = "Freehand"; btn.IsChecked = true;
  642. BtnMyTools_Click(btn);
  643. break;
  644. }
  645. EraseArgs eraseArgs = new EraseArgs();
  646. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  647. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  648. eraseArgs.Thickness = 10;
  649. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  650. if (annotProperty != null)
  651. {
  652. eraseArgs.Thickness = annotProperty.Thickness;
  653. }
  654. PDFViewer.ClearSelectAnnots(false);
  655. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  656. PDFViewer.SetToolParam(eraseArgs);
  657. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  658. annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor;
  659. annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor;
  660. annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness;
  661. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  662. if (eraseArgs != null)
  663. eraseArgsList.Add(eraseArgs);
  664. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList, annotAttribsList);
  665. }
  666. }
  667. break;
  668. }
  669. }
  670. }
  671. }
  672. #endregion BindingEvent事件
  673. }
  674. }