AnnotToolContentViewModel.Layout.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKitViewer;
  3. using ComPDFKitViewer.AnnotEvent;
  4. using ComPDFKitViewer.PdfViewer;
  5. using PDF_Master.CustomControl;
  6. using PDF_Master.CustomControl.CompositeControl;
  7. using PDF_Master.Helper;
  8. using PDF_Master.Model.PropertyPanel.AnnotPanel;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Input;
  21. using System.Windows.Media;
  22. using System.Windows.Media.Imaging;
  23. using System.Windows.Shapes;
  24. using static Dropbox.Api.TeamLog.AdminAlertSeverityEnum;
  25. using MenuItem = System.Windows.Controls.MenuItem;
  26. namespace PDF_Master.ViewModels.Tools
  27. {
  28. //文件说明:与布局相关的代码逻辑:菜单、属性面板
  29. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  30. {
  31. #region 属性面板
  32. /// <summary>
  33. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  34. /// </summary>
  35. /// <param name="viewContent">对应的注释面板</param>
  36. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  37. /// <param name="annot">注释</param>
  38. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  39. private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, AnnotAttribEvent annotAttribEvent = null)
  40. {
  41. if (annots != null)
  42. {
  43. PropertyPanel.annotlists = annots;
  44. PropertyPanel.annot = annots[0];
  45. }
  46. else
  47. {
  48. PropertyPanel.annotlists = null;
  49. PropertyPanel.annot = null;
  50. }
  51. PropertyPanel.AnnotEvents = null;
  52. PropertyPanel.AnnotEvent = null;
  53. if (annots != null)
  54. {
  55. if (annots.Count > 1)
  56. {
  57. if (PropertyPanel.AnnotEvents == null)
  58. {
  59. PropertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
  60. }
  61. PropertyPanel.AnnotEvents.Clear();
  62. foreach (var itemAnnot in annots)
  63. {
  64. var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, itemAnnot.GetAnnotAttrib());
  65. //eventitem.ClearChangeAttribute();
  66. PropertyPanel.AnnotEvents.Add(eventitem);
  67. }
  68. }
  69. PropertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annots[0].GetAnnotAttrib());
  70. //propertyPanel.AnnotEvent.ClearChangeAttribute();
  71. if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
  72. {
  73. PropertyPanel.AnnotEvent = annotAttribEvent;
  74. }
  75. }
  76. PropertyPanel.SetIsTextFill(false);
  77. if (string.IsNullOrEmpty(viewContent) == false)
  78. {
  79. viewContentViewModel.SelectedPrpoertyPanel(viewContent, PropertyPanel);
  80. }
  81. }
  82. /// <summary>
  83. /// 展开显示属性面板
  84. /// </summary>
  85. private void ShowPropertyPanel(bool show = true)
  86. {
  87. viewContentViewModel.IsPropertyOpen = show;
  88. }
  89. #endregion 属性面板
  90. #region 阅读页 - 右键菜单
  91. #region 右击菜单文案
  92. /// <summary>
  93. /// 右键菜单文案
  94. /// </summary>
  95. ///
  96. public string T_RightMenuSelectionCopy = App.MainPageLoader.GetString("ViewRightMenuSelection_Copy");
  97. public string T_RightMenuSelectionPaste = App.MainPageLoader.GetString("ViewRightMenuSelection_Paste");
  98. public string T_RightMenuSelectionHighlight = App.MainPageLoader.GetString("ViewRightMenuSelection_Highlight");
  99. public string T_RightMenuSelectionUnderline = App.MainPageLoader.GetString("ViewRightMenuSelection_Underline");
  100. public string T_RightMenuSelectionStrikethrough = App.MainPageLoader.GetString("ViewRightMenuSelection_Strikethrough");
  101. public string T_RightMenuSelectionText = App.MainPageLoader.GetString("ViewRightMenuSelection_Text");
  102. public string T_RightMenuSelectionNote = App.MainPageLoader.GetString("ViewRightMenuSelection_Note");
  103. public string T_RightMenuSelectionRectangle = App.MainPageLoader.GetString("ViewRightMenuSelection_Rectangle");
  104. public string T_RightMenuSelectionOval = App.MainPageLoader.GetString("ViewRightMenuSelection_Oval");
  105. public string T_RightMenuSelectionStraightLine = App.MainPageLoader.GetString("ViewRightMenuSelection_StraightLine");
  106. public string T_RightMenuSelectionAddLink = App.MainPageLoader.GetString("ViewRightMenuSelection_AddLink");
  107. public string T_RightMenuSelectionAddOutline = App.MainPageLoader.GetString("ViewRightMenuSelection_AddOutline");
  108. public string T_RightMenuSelectionExtractImage = App.MainPageLoader.GetString("ViewRightMenuSelection_ExtractImage");
  109. #endregion 右击菜单文案
  110. private ContextMenu ViewerContextMenu(object sender)
  111. {
  112. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  113. //contextMenu.Loaded += ContextMenu_Loaded;
  114. ViewerContextMenu_Loaded(contextMenu, sender);
  115. return contextMenu;
  116. }
  117. private void ViewerContextMenu_Loaded(object sender, object e)
  118. {
  119. ContextMenu contextMenu = sender as ContextMenu;
  120. contextMenu.DataContext = viewContentViewModel;
  121. if (contextMenu.Items.Count > 0)
  122. {
  123. int index = PDFViewer.CurrentIndex;
  124. //检测是否已存在相同数据
  125. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  126. if (list != null)
  127. {
  128. isAddBookMark = false;
  129. }
  130. else
  131. {
  132. isAddBookMark = true;
  133. }
  134. foreach (var item in contextMenu.Items)
  135. {
  136. if (item is MenuItem menuItem1)
  137. {
  138. switch (menuItem1.Tag.ToString())
  139. {
  140. case "Paste":
  141. //粘贴
  142. //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  143. //{
  144. // menuItem1.IsEnabled = false;
  145. // menuItem1.Opacity = 0.5;
  146. //}
  147. //else
  148. //{
  149. // menuItem1.IsEnabled = true;
  150. // menuItem1.Opacity = 1;
  151. //}
  152. menuItem1.CommandTarget = (UIElement)e;
  153. menuItem1.Command = ApplicationCommands.Paste;
  154. break;
  155. case "AddAnnotation":
  156. if (menuItem1.Items.Count > 0)
  157. {
  158. SetAddAnnotation(menuItem1.Items);
  159. }
  160. break;
  161. case "HiddenAnnot":
  162. menuItem1.Click -= HiddenAnnot_Click;
  163. menuItem1.Click += HiddenAnnot_Click;
  164. SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", BtnShowAnnotIsChecked);
  165. break;
  166. case "DisplayAnnot":
  167. menuItem1.Click -= DisplayAnnot_Click;
  168. menuItem1.Click += DisplayAnnot_Click;
  169. SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", BtnShowAnnotIsChecked);
  170. break;
  171. case "AddBookMark":
  172. menuItem1.Command = AddBookMarkCommand;
  173. SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark);
  174. break;
  175. case "DelBookMark":
  176. menuItem1.Click -= DelBookMark_Click;
  177. menuItem1.Click += DelBookMark_Click;
  178. SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark);
  179. break;
  180. case "ToolMode":
  181. if (menuItem1.Items.Count > 0)
  182. {
  183. SetToolMode(menuItem1.Items);
  184. }
  185. break;
  186. case "ReadModel":
  187. SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", viewContentViewModel.mainViewModel.IsBookMode);
  188. menuItem1.Click -= ReadModel_Click;
  189. menuItem1.Click += ReadModel_Click;
  190. break;
  191. case "UnReadModel":
  192. SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", viewContentViewModel.mainViewModel.IsBookMode);
  193. menuItem1.Click -= UnReadModel_Click;
  194. menuItem1.Click += UnReadModel_Click;
  195. break;
  196. case "ViewZoom":
  197. if (menuItem1.Items.Count > 0)
  198. {
  199. ViewZoom(menuItem1.Items);
  200. }
  201. break;
  202. case "PageDisplay":
  203. if (menuItem1.Items.Count > 0)
  204. {
  205. PageDisplay(menuItem1.Items);
  206. }
  207. break;
  208. case "Select":
  209. menuItem1.Click -= Select_Click;
  210. menuItem1.Click += Select_Click;
  211. break;
  212. case "Print":
  213. menuItem1.Command = viewContentViewModel.PrintCommand;
  214. break;
  215. case "HighlightLinks":
  216. if (OpenFileInfo != null)
  217. {
  218. menuItem1.IsChecked = OpenFileInfo.ShowHighLightLink;
  219. }
  220. menuItem1.Click -= HighlightLinks_Click;
  221. menuItem1.Click += HighlightLinks_Click;
  222. break;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. private void HighlightLinks_Click(object sender, RoutedEventArgs e)
  229. {
  230. if (sender is MenuItem menuItem)
  231. {
  232. //if (OpenFileInfo != null)
  233. //{
  234. // menuItem.IsChecked = OpenFileInfo.ShowHighLightLink;
  235. //}
  236. if (menuItem.IsChecked)
  237. {
  238. PDFViewer.SetShowLink(true);
  239. }
  240. else
  241. {
  242. PDFViewer.SetShowLink(false);
  243. }
  244. if (OpenFileInfo != null)
  245. {
  246. OpenFileInfo.ShowHighLightLink = menuItem.IsChecked;
  247. }
  248. //if (menuItem.IsChecked == true)
  249. //{
  250. // menuItem.IsChecked = false;
  251. //}
  252. }
  253. }
  254. private void SetMenuItemVisibility(MenuItem menuItem1, string right, string deny, bool flag)
  255. {
  256. if (menuItem1.Tag.ToString() == right && flag)
  257. {
  258. menuItem1.Visibility = Visibility.Collapsed;
  259. }
  260. if (menuItem1.Tag.ToString() == right && flag == false)
  261. {
  262. menuItem1.Visibility = Visibility.Visible;
  263. }
  264. if (menuItem1.Tag.ToString() == deny && flag == false)
  265. {
  266. menuItem1.Visibility = Visibility.Collapsed;
  267. }
  268. if (menuItem1.Tag.ToString() == deny && flag)
  269. {
  270. menuItem1.Visibility = Visibility.Visible;
  271. }
  272. }
  273. private void CopyMenu_Click(object sender, RoutedEventArgs e)
  274. {
  275. try
  276. {
  277. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  278. if (imageDict != null && imageDict.Count > 0)
  279. {
  280. foreach (int pageIndex in imageDict.Keys)
  281. {
  282. List<System.Drawing.Bitmap> imageList = imageDict[pageIndex];
  283. foreach (System.Drawing.Bitmap image in imageList)
  284. {
  285. MemoryStream ms = new MemoryStream();
  286. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  287. BitmapImage imageData = new BitmapImage();
  288. imageData.BeginInit();
  289. imageData.StreamSource = ms;
  290. imageData.CacheOption = BitmapCacheOption.OnLoad;
  291. imageData.EndInit();
  292. imageData.Freeze();
  293. Clipboard.SetImage(imageData);
  294. break;
  295. }
  296. }
  297. }
  298. }
  299. catch (Exception ex)
  300. {
  301. }
  302. }
  303. /// <summary>
  304. /// 选择文本或者图像的右键菜单
  305. /// </summary>
  306. /// <param name="sender"></param>
  307. /// <param name="annotCommand"></param>
  308. /// <returns></returns>
  309. private ContextMenu SelectedTextOrImageContextMenu(object sender, AnnotCommandArgs annotCommand)
  310. {
  311. ContextMenu popMenu = new ContextMenu();
  312. popMenu.FontSize = 14;
  313. MenuItem menuItem = new MenuItem();
  314. menuItem = new MenuItem();
  315. menuItem.CommandTarget = (UIElement)sender;
  316. menuItem.Header = T_RightMenuSelectionCopy;
  317. if (annotCommand.CommandTarget == TargetType.ImageSelection && PDFViewer.GetSelectImageCount() > 0)
  318. {
  319. menuItem.IsEnabled = true;
  320. menuItem.Click -= CopyMenu_Click;
  321. menuItem.Click += CopyMenu_Click;
  322. }
  323. else
  324. {
  325. menuItem.Command = ApplicationCommands.Copy;
  326. }
  327. popMenu.Items.Add(menuItem);
  328. menuItem = new MenuItem();
  329. menuItem.CommandTarget = (UIElement)sender;
  330. menuItem.Command = ApplicationCommands.Paste;
  331. menuItem.Header = T_RightMenuSelectionPaste;
  332. popMenu.Items.Add(menuItem);
  333. Separator separator = null;
  334. if (annotCommand.CommandTarget == TargetType.ImageSelection)
  335. {
  336. separator = SetSeparator();
  337. popMenu.Items.Add(separator);
  338. SetSelectTextOrImageMenuItem(T_RightMenuSelectionExtractImage, "ExportPicture", annotCommand, out menuItem);
  339. if (PDFViewer.GetSelectImageCount() > 0)
  340. {
  341. menuItem.IsEnabled = true;
  342. }
  343. popMenu.Items.Add(menuItem);
  344. }
  345. else if (annotCommand.CommandTarget == TargetType.Annot)
  346. {
  347. separator = SetSeparator();
  348. popMenu.Items.Add(separator);
  349. SetSelectTextOrImageMenuItem(T_RightMenuSelectionHighlight, "HighLight", annotCommand, out menuItem);
  350. popMenu.Items.Add(menuItem);
  351. SetSelectTextOrImageMenuItem(T_RightMenuSelectionUnderline, "UnderLine", annotCommand, out menuItem);
  352. popMenu.Items.Add(menuItem);
  353. SetSelectTextOrImageMenuItem(T_RightMenuSelectionStrikethrough, "Strikeout", annotCommand, out menuItem);
  354. popMenu.Items.Add(menuItem);
  355. separator = SetSeparator();
  356. //popMenu.Items.Add(separator);
  357. SetSelectTextOrImageMenuItem(T_RightMenuSelectionText, "Freetext", annotCommand, out menuItem);
  358. //popMenu.Items.Add(menuItem);
  359. SetSelectTextOrImageMenuItem(T_RightMenuSelectionNote, "StickyNote", annotCommand, out menuItem);
  360. //popMenu.Items.Add(menuItem);
  361. separator = SetSeparator();
  362. popMenu.Items.Add(separator);
  363. SetSelectTextOrImageMenuItem(T_RightMenuSelectionRectangle, "Rect", annotCommand, out menuItem);
  364. popMenu.Items.Add(menuItem);
  365. SetSelectTextOrImageMenuItem(T_RightMenuSelectionOval, "Circle", annotCommand, out menuItem);
  366. popMenu.Items.Add(menuItem);
  367. SetSelectTextOrImageMenuItem(T_RightMenuSelectionStraightLine, "Line", annotCommand, out menuItem);
  368. //popMenu.Items.Add(menuItem);
  369. }
  370. separator = SetSeparator();
  371. popMenu.Items.Add(separator);
  372. SetSelectTextOrImageMenuItem(T_RightMenuSelectionAddLink, "Link", annotCommand, out menuItem);
  373. popMenu.Items.Add(menuItem);
  374. if (annotCommand.CommandTarget == TargetType.Annot)
  375. {
  376. SetSelectTextOrImageMenuItem(T_RightMenuSelectionAddOutline, "OutLine", annotCommand, out menuItem);
  377. popMenu.Items.Add(menuItem);
  378. }
  379. return popMenu;
  380. }
  381. private void SetSelectTextOrImageMenuItem(string header, string tag, AnnotCommandArgs annotCommand, out MenuItem menuItem)
  382. {
  383. menuItem = new MenuItem();
  384. menuItem.Header = header;
  385. menuItem.Tag = tag;
  386. if (tag == "OutLine")
  387. {
  388. if (viewContentViewModel.mainViewModel.IsBookMode)
  389. {
  390. menuItem.IsEnabled = false;
  391. }
  392. else
  393. {
  394. menuItem.IsEnabled = true;
  395. }
  396. }
  397. menuItem.Click -= AnnotToolMenu_Click;
  398. menuItem.Click += AnnotToolMenu_Click;
  399. menuItem.CommandParameter = annotCommand;
  400. }
  401. private Separator SetSeparator()
  402. {
  403. Separator separator = new Separator
  404. {
  405. Height = 1,
  406. BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33000000")),
  407. BorderThickness = new Thickness(1),
  408. Style = (Style)App.Current.FindResource(System.Windows.Controls.ToolBar.SeparatorStyleKey)
  409. };
  410. return separator;
  411. }
  412. #endregion 阅读页 - 右键菜单
  413. #region 注释-右键菜单
  414. #region 注释-右键菜单文案
  415. public string T_RightMenuAnnotCopy = App.MainPageLoader.GetString("ViewRightMenuSelection_Copy");
  416. public string T_RightMenuAnnotPaste = App.MainPageLoader.GetString("ViewRightMenuSelection_Paste");
  417. public string T_RightMenuAnnotHighlight = App.MainPageLoader.GetString("ViewRightMenuSelection_Highlight");
  418. public string T_RightMenuAnnotUnderline = App.MainPageLoader.GetString("ViewRightMenuSelection_Underline");
  419. public string T_RightMenuAnnotStrikethrough = App.MainPageLoader.GetString("ViewRightMenuSelection_Strikethrough");
  420. public string T_RightMenuAnnotText = App.MainPageLoader.GetString("ViewRightMenuSelection_Text");
  421. public string T_RightMenuAnnotNote = App.MainPageLoader.GetString("ViewRightMenuSelection_Note");
  422. #endregion 注释-右键菜单文案
  423. private ColorMenuItem colorContent;
  424. /// <summary>
  425. /// 高亮注释,右键菜单
  426. /// </summary>
  427. ///
  428. private void InitSelectHightAnnotMenu()
  429. {
  430. var popMenu = new ContextMenu();
  431. PopMenu pop = new PopMenu(popMenu);
  432. colorContent = new ColorMenuItem();
  433. colorContent.Name = "hightcolor";
  434. colorContent.ColorChanged -= colorContent_SelectedColorHandler;
  435. colorContent.ColorChanged += colorContent_SelectedColorHandler;
  436. colorContent.VerticalAlignment = VerticalAlignment.Top;
  437. colorContent.Margin = new Thickness(0, 0, 0, -15);
  438. var menuItem = new MenuItem();
  439. menuItem.Name = "hightColor";
  440. menuItem.Height = 20 + 15;
  441. menuItem.Header = colorContent;
  442. var hightColorStyle = App.Current.FindResource("UIElementMenuItem") as Style;
  443. if (hightColorStyle != null)
  444. menuItem.Style = hightColorStyle;
  445. colorContent.DataContext = pop.AddItem(menuItem);
  446. pop.AddItem(GetSeparator());
  447. menuItem = new MenuItem();
  448. menuItem.Name = "hightCopyText";
  449. menuItem.Header = "复制文本";
  450. pop.BindingEvent(pop.AddItem(menuItem), HightAnnotCopyText_MenuCommand);
  451. menuItem = new MenuItem();
  452. menuItem.Name = "hightdelete";
  453. menuItem.Header = "删除";
  454. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  455. pop.AddItem(GetSeparator());
  456. menuItem = new MenuItem();
  457. menuItem.Name = "hightAddNote";
  458. menuItem.Header = "添加笔记";
  459. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  460. menuItem = new MenuItem();
  461. menuItem.Name = "hightdefault";
  462. menuItem.Header = "设置当前属性为默认值";
  463. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  464. HightAnnotPopMenu = pop;
  465. }
  466. private Separator GetSeparator()
  467. {
  468. Separator separator = new Separator();
  469. separator.Height = 1;
  470. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  471. separator.BorderThickness = new Thickness(1);
  472. separator.Margin = new Thickness(-30, 0, 0, 0);
  473. return separator;
  474. }
  475. private async void colorContent_SelectedColorHandler(object sender, Color e)
  476. {
  477. if (e == null) return;
  478. if (sender is Ellipse)
  479. {
  480. var item = new ColorDropBoxPop();
  481. item.DataContext = (sender as Ellipse).DataContext;
  482. item.ColorSelected -= AnnotMenu_ColorSelected;
  483. item.ColorSelected += AnnotMenu_ColorSelected;
  484. if (popup == null)
  485. popup = new System.Windows.Controls.Primitives.Popup();
  486. ContentControl window = null;
  487. if (PDFViewer.Parent as ContentControl != null)
  488. window = PDFViewer.Parent as ContentControl;
  489. else
  490. window = App.Current.MainWindow;
  491. popup.Child = item;
  492. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  493. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  494. popup.PlacementTarget = window;
  495. popup.IsOpen = true;
  496. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  497. if (parentWnd != null)
  498. {
  499. parentWnd.MouseDown -= parentWnd_MouseDown;
  500. parentWnd.MouseDown += parentWnd_MouseDown;
  501. }
  502. while (popup.IsOpen)
  503. await Task.Delay(20);
  504. parentWnd.MouseDown -= parentWnd_MouseDown;
  505. popup = null;
  506. }
  507. else
  508. {
  509. var cusMenuItem = (sender as FrameworkElement).DataContext as CusMenuItem;
  510. if (cusMenuItem != null && cusMenuItem.Parameter != null)
  511. {
  512. if (cusMenuItem.Parameter is TextHighlightAnnotArgs textHighlightAnnotArgs)
  513. {
  514. var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textHighlightAnnotArgs, textHighlightAnnotArgs.GetAnnotAttrib());
  515. anvent.UpdateAttrib(AnnotAttrib.Color, e);
  516. anvent.UpdateAnnot();
  517. }
  518. if (cusMenuItem.Parameter is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  519. {
  520. var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textUnderlineAnnotArgs, textUnderlineAnnotArgs.GetAnnotAttrib());
  521. anvent.UpdateAttrib(AnnotAttrib.Color, e);
  522. anvent.UpdateAnnot();
  523. }
  524. if (cusMenuItem.Parameter is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  525. {
  526. var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textStrikeoutAnnotArgs, textStrikeoutAnnotArgs.GetAnnotAttrib());
  527. anvent.UpdateAttrib(AnnotAttrib.Color, e);
  528. anvent.UpdateAnnot();
  529. }
  530. //var test = cusMenuItem.Parameter as TextHighlightAnnotArgs;
  531. //if (test != null)
  532. //{
  533. // var anvent = AnnotAttribEvent.GetAnnotAttribEvent(test, test.GetAnnotAttrib());
  534. // anvent.UpdateAttrib(AnnotAttrib.Color, e);
  535. // anvent.UpdateAnnot();
  536. //}
  537. }
  538. }
  539. }
  540. /// <summary>
  541. /// 手绘
  542. /// </summary>
  543. private void InitSelectFreeHandAnnotMenu()
  544. {
  545. var popMenu = new ContextMenu();
  546. PopMenu pop = new PopMenu(popMenu);
  547. var menuItem = new MenuItem();
  548. menuItem.Name = "FreeHandCopy";
  549. menuItem.Header = "复制";
  550. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  551. menuItem = new MenuItem();
  552. menuItem.Name = "FreeHandCut";
  553. menuItem.Header = "剪切";
  554. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  555. menuItem = new MenuItem();
  556. menuItem.Name = "FreeHandPaste";
  557. menuItem.Header = "粘贴";
  558. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  559. menuItem = new MenuItem();
  560. menuItem.Name = "FreeHandDelete";
  561. menuItem.Header = "删除";
  562. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  563. pop.AddItem(GetSeparator());
  564. menuItem = new MenuItem();
  565. menuItem.Name = "FreeHandColor";
  566. menuItem.Header = "边框颜色";
  567. menuItem.Tag = "Color";
  568. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  569. menuItem = new MenuItem();
  570. menuItem.Name = "FreeHandLineStyle";
  571. menuItem.Header = "线段样式";
  572. pop.AddItem(menuItem);
  573. RadioButton radioButton = new RadioButton();
  574. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  575. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  576. radioButton.Name = "FreeHandSolid";
  577. radioButton.Content = "实线";
  578. radioButton.GroupName = "LineStyle";
  579. radioButton.Tag = "Solid";
  580. pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand);
  581. radioButton = new RadioButton();
  582. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  583. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  584. radioButton.Name = "FreeHandDash";
  585. radioButton.Content = "虚线";
  586. radioButton.GroupName = "LineStyle";
  587. radioButton.Tag = "Dash";
  588. pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand);
  589. menuItem = new MenuItem();
  590. menuItem.Name = "FreeHandAddNote";
  591. menuItem.Header = "添加笔记";
  592. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  593. menuItem = new MenuItem();
  594. menuItem.Name = "FreeHandDefault";
  595. menuItem.Header = "设置当前属性为默认值";
  596. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  597. FreeHandAnnotPopMenu = pop;
  598. }
  599. /// <summary>
  600. /// 文本
  601. /// </summary>
  602. private void InitSelectFreeTextAnnotMenu()
  603. {
  604. var popMenu = new ContextMenu();
  605. PopMenu pop = new PopMenu(popMenu);
  606. var menuItem = new MenuItem();
  607. menuItem.Name = "FreeTextCopy";
  608. menuItem.Header = "复制";
  609. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  610. menuItem = new MenuItem();
  611. menuItem.Name = "FreeTextCut";
  612. menuItem.Header = "剪切";
  613. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  614. menuItem = new MenuItem();
  615. menuItem.Name = "FreeTextPaste";
  616. menuItem.Header = "粘贴";
  617. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  618. menuItem = new MenuItem();
  619. menuItem.Name = "FreeTextDelete";
  620. menuItem.Header = "删除";
  621. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  622. pop.AddItem(GetSeparator());
  623. menuItem = new MenuItem();
  624. menuItem.Name = "FreeTextColor";
  625. menuItem.Header = "字体颜色";
  626. menuItem.Tag = "FontColor";
  627. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  628. menuItem = new MenuItem();
  629. menuItem.Name = "FreeTextFillColor";
  630. menuItem.Header = "填充颜色";
  631. menuItem.Tag = "FillColor";
  632. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  633. menuItem = new MenuItem();
  634. menuItem.Name = "FreeTextFontFamily";
  635. menuItem.Header = "字体";
  636. pop.AddItem(menuItem);
  637. var family = TextFont.GetFamily();
  638. foreach (var item in family)
  639. {
  640. RadioButton familyRdioBtn = new RadioButton();
  641. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  642. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  643. familyRdioBtn.Name = item.ValueStr;
  644. familyRdioBtn.Tag = item.ValueStr;
  645. familyRdioBtn.GroupName = "FontFamily";
  646. familyRdioBtn.Content = item.Content;
  647. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  648. }
  649. menuItem = new MenuItem();
  650. menuItem.Name = "FreeTextAglin";
  651. menuItem.Header = "文本对齐";
  652. pop.AddItem(menuItem);
  653. var radioButton = new RadioButton();
  654. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  655. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  656. radioButton.Name = "FreeTextAglinLeft";
  657. radioButton.Tag = "Left";
  658. radioButton.GroupName = "Aglin";
  659. radioButton.Content = "左对齐";
  660. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  661. radioButton = new RadioButton();
  662. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  663. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  664. radioButton.Name = "FreeTextAglinCenter";
  665. radioButton.Tag = "Center";
  666. radioButton.GroupName = "Aglin";
  667. radioButton.Content = "居中对齐";
  668. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  669. radioButton = new RadioButton();
  670. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  671. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  672. radioButton.Name = "FreeTextAglinRight";
  673. radioButton.Tag = "Right";
  674. radioButton.GroupName = "Aglin";
  675. radioButton.Content = "右对齐";
  676. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  677. radioButton = new RadioButton();
  678. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  679. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  680. radioButton.Name = "FreeTextAglinJustify";
  681. radioButton.Tag = "Justify";
  682. radioButton.GroupName = "Aglin";
  683. radioButton.Content = "两端对齐";
  684. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  685. menuItem = new MenuItem();
  686. menuItem.Name = "FreeHandDefault";
  687. menuItem.Header = "设置当前属性为默认值";
  688. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  689. FreeTextAnnotPopMenu = pop;
  690. }
  691. /// <summary>
  692. /// 便签
  693. /// </summary>
  694. private void InitSelectStrickNoteAnnotMenu()
  695. {
  696. var popMenu = new ContextMenu();
  697. PopMenu pop = new PopMenu(popMenu);
  698. var menuItem = new MenuItem();
  699. menuItem.Name = "StrickNoteCopy";
  700. menuItem.Header = "复制";
  701. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  702. menuItem = new MenuItem();
  703. menuItem.Name = "StrickNoteCut";
  704. menuItem.Header = "剪切";
  705. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  706. menuItem = new MenuItem();
  707. menuItem.Name = "StrickNotePaste";
  708. menuItem.Header = "粘贴";
  709. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  710. menuItem = new MenuItem();
  711. menuItem.Name = "StrickNoteDelete";
  712. menuItem.Header = "删除";
  713. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  714. pop.AddItem(GetSeparator());
  715. menuItem = new MenuItem();
  716. menuItem.Name = "StrickNoteColor";
  717. menuItem.Header = "颜色";
  718. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  719. menuItem = new MenuItem();
  720. menuItem.Name = "StrickNoteEdit";
  721. menuItem.Header = "编辑便签";
  722. pop.BindingEvent(pop.AddItem(menuItem), StrikeNoteEditStrike_MenuCommand);
  723. menuItem = new MenuItem();
  724. menuItem.Name = "StrickNoteDefault";
  725. menuItem.Header = "设置当前属性为默认值";
  726. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  727. StrickNoteAnnotPopMenu = pop;
  728. }
  729. /// <summary>
  730. /// 形状
  731. /// </summary>
  732. private void InitSelectShapeAnnotMenu()
  733. {
  734. var popMenu = new ContextMenu();
  735. PopMenu pop = new PopMenu(popMenu);
  736. var menuItem = new MenuItem();
  737. menuItem.Name = "ShapeCopy";
  738. menuItem.Header = "复制";
  739. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  740. menuItem = new MenuItem();
  741. menuItem.Name = "ShapeCut";
  742. menuItem.Header = "剪切";
  743. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  744. menuItem = new MenuItem();
  745. menuItem.Name = "ShapePaste";
  746. menuItem.Header = "粘贴";
  747. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  748. menuItem = new MenuItem();
  749. menuItem.Name = "ShapeDelete";
  750. menuItem.Header = "删除";
  751. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  752. pop.AddItem(GetSeparator());
  753. menuItem = new MenuItem();
  754. menuItem.Name = "ShapeColor";
  755. menuItem.Header = "边框颜色";
  756. menuItem.Tag = "Color";
  757. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  758. menuItem = new MenuItem();
  759. menuItem.Name = "ShapeFillColor";
  760. menuItem.Header = "填充颜色";
  761. menuItem.Tag = "FillColor";
  762. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  763. menuItem = new MenuItem();
  764. menuItem.Name = "ShapeLineStyle";
  765. menuItem.Header = "线段样式";
  766. pop.AddItem(menuItem);
  767. RadioButton radioButton = new RadioButton();
  768. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  769. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  770. radioButton.Name = "ShapeSolid";
  771. radioButton.Content = "实线";
  772. radioButton.GroupName = "LineStyle";
  773. radioButton.Tag = "Solid";
  774. pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand);
  775. radioButton = new RadioButton();
  776. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  777. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  778. radioButton.Name = "ShapeDash";
  779. radioButton.Content = "虚线";
  780. radioButton.GroupName = "LineStyle";
  781. radioButton.Tag = "Dash";
  782. pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand);
  783. menuItem = new MenuItem();
  784. menuItem.Name = "ShapeDirect";
  785. menuItem.Header = "线段方向";
  786. pop.AddItem(menuItem);
  787. menuItem = new MenuItem();
  788. menuItem.Name = "ShapeVer";
  789. menuItem.Header = "垂直";
  790. menuItem.Tag = "Ver";
  791. pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand);
  792. menuItem = new MenuItem();
  793. menuItem.Name = "ShapeHor";
  794. menuItem.Header = "横向";
  795. menuItem.Tag = "Hor";
  796. pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand);
  797. menuItem = new MenuItem();
  798. menuItem.Name = "ShapeNoteText";
  799. menuItem.Header = "添加笔记";
  800. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  801. menuItem = new MenuItem();
  802. menuItem.Name = "ShapeDefault";
  803. menuItem.Header = "设置当前属性为默认值";
  804. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  805. ShapeAnnotPopMenu = pop;
  806. }
  807. /// <summary>
  808. /// 链接
  809. /// </summary>
  810. private void InitSelectLinkAnnotMenu()
  811. {
  812. var popMenu = new ContextMenu();
  813. PopMenu pop = new PopMenu(popMenu);
  814. var menuItem = new MenuItem();
  815. menuItem.Name = "LinkCopy";
  816. menuItem.Header = "复制";
  817. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  818. menuItem = new MenuItem();
  819. menuItem.Name = "LinkCut";
  820. menuItem.Header = "剪切";
  821. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  822. menuItem = new MenuItem();
  823. menuItem.Name = "LinkPaste";
  824. menuItem.Header = "粘贴";
  825. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  826. menuItem = new MenuItem();
  827. menuItem.Name = "LinkDelete";
  828. menuItem.Header = "删除";
  829. pop.BindingEvent(pop.AddItem(menuItem), Link_MenuCommand);
  830. LinkAnnotPopMenu = pop;
  831. }
  832. /// <summary>
  833. /// 图章、签名
  834. /// </summary>
  835. private void InitSelectStampAnnotMenu()
  836. {
  837. var popMenu = new ContextMenu();
  838. PopMenu pop = new PopMenu(popMenu);
  839. var menuItem = new MenuItem();
  840. menuItem.Name = "StampCopy";
  841. menuItem.Header = "复制";
  842. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  843. menuItem = new MenuItem();
  844. menuItem.Name = "StampCut";
  845. menuItem.Header = "剪切";
  846. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  847. menuItem = new MenuItem();
  848. menuItem.Name = "StampPaste";
  849. menuItem.Header = "粘贴";
  850. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  851. menuItem = new MenuItem();
  852. menuItem.Name = "StampDelete";
  853. menuItem.Header = "删除";
  854. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  855. pop.AddItem(GetSeparator());
  856. menuItem = new MenuItem();
  857. menuItem.Name = "StampExportPicture";
  858. menuItem.Header = "导出";
  859. pop.AddItem(menuItem);
  860. menuItem = new MenuItem();
  861. menuItem.Name = "StampExportPNG";
  862. menuItem.Header = "PNG";
  863. menuItem.Tag = "PNG";
  864. pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  865. //已跟设计确认,暂时不需要JPG格式
  866. //menuItem = new MenuItem();
  867. //menuItem.Name = "StampExportPNG";
  868. //menuItem.Header = "JPG";
  869. //menuItem.Tag = "JPG";
  870. //pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  871. menuItem = new MenuItem();
  872. menuItem.Name = "StampExportPDF";
  873. menuItem.Header = "PDF";
  874. menuItem.Tag = "PDF";
  875. pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  876. menuItem = new MenuItem();
  877. menuItem.Name = "StampAddNote";
  878. menuItem.Header = "添加笔记";
  879. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  880. StampAnnotPopMenu = pop;
  881. }
  882. /// <summary>
  883. /// 多选注释
  884. /// </summary>
  885. private void InitSelectMultiAnnotMenu()
  886. {
  887. var popMenu = new ContextMenu();
  888. PopMenu pop = new PopMenu(popMenu);
  889. var menuItem = new MenuItem();
  890. menuItem.Name = "MultiCopy";
  891. menuItem.Header = "复制";
  892. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  893. menuItem = new MenuItem();
  894. menuItem.Name = "MultiCut";
  895. menuItem.Header = "剪切";
  896. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  897. menuItem = new MenuItem();
  898. menuItem.Name = "MultiDelete";
  899. menuItem.Header = "删除";
  900. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  901. MultiAnnotPopMenu = pop;
  902. }
  903. #endregion 注释-右键菜单
  904. }
  905. }