AnnotToolContentViewModel.Layout.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  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. Clipboard.Clear();
  278. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  279. if (imageDict != null && imageDict.Count > 0)
  280. {
  281. foreach (int pageIndex in imageDict.Keys)
  282. {
  283. List<System.Drawing.Bitmap> imageList = imageDict[pageIndex];
  284. foreach (System.Drawing.Bitmap image in imageList)
  285. {
  286. MemoryStream ms = new MemoryStream();
  287. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  288. BitmapImage imageData = new BitmapImage();
  289. imageData.BeginInit();
  290. imageData.StreamSource = ms;
  291. imageData.CacheOption = BitmapCacheOption.OnLoad;
  292. imageData.EndInit();
  293. imageData.Freeze();
  294. Clipboard.SetImage(imageData);
  295. break;
  296. }
  297. }
  298. }
  299. }
  300. catch (Exception ex)
  301. {
  302. }
  303. }
  304. /// <summary>
  305. /// 选择文本或者图像的右键菜单
  306. /// </summary>
  307. /// <param name="sender"></param>
  308. /// <param name="annotCommand"></param>
  309. /// <returns></returns>
  310. private ContextMenu SelectedTextOrImageContextMenu(object sender, AnnotCommandArgs annotCommand)
  311. {
  312. ContextMenu popMenu = new ContextMenu();
  313. popMenu.FontSize = 14;
  314. MenuItem menuItem = new MenuItem();
  315. menuItem = new MenuItem();
  316. menuItem.CommandTarget = (UIElement)sender;
  317. menuItem.Header = T_RightMenuSelectionCopy;
  318. if (annotCommand.CommandTarget == TargetType.ImageSelection && PDFViewer.GetSelectImageCount() > 0)
  319. {
  320. menuItem.IsEnabled = true;
  321. PDFViewer.ClearCopyData();
  322. menuItem.Click -= CopyMenu_Click;
  323. menuItem.Click += CopyMenu_Click;
  324. }
  325. else
  326. {
  327. menuItem.Command = ApplicationCommands.Copy;
  328. }
  329. popMenu.Items.Add(menuItem);
  330. menuItem = new MenuItem();
  331. menuItem.CommandTarget = (UIElement)sender;
  332. menuItem.Command = ApplicationCommands.Paste;
  333. menuItem.Header = T_RightMenuSelectionPaste;
  334. popMenu.Items.Add(menuItem);
  335. Separator separator = null;
  336. if (annotCommand.CommandTarget == TargetType.ImageSelection)
  337. {
  338. separator = SetSeparator();
  339. popMenu.Items.Add(separator);
  340. SetSelectTextOrImageMenuItem(T_RightMenuSelectionExtractImage, "ExportPicture", annotCommand, out menuItem);
  341. if (PDFViewer.GetSelectImageCount() > 0)
  342. {
  343. menuItem.IsEnabled = true;
  344. }
  345. popMenu.Items.Add(menuItem);
  346. }
  347. else if (annotCommand.CommandTarget == TargetType.Annot)
  348. {
  349. separator = SetSeparator();
  350. popMenu.Items.Add(separator);
  351. SetSelectTextOrImageMenuItem(T_RightMenuSelectionHighlight, "HighLight", annotCommand, out menuItem);
  352. popMenu.Items.Add(menuItem);
  353. SetSelectTextOrImageMenuItem(T_RightMenuSelectionUnderline, "UnderLine", annotCommand, out menuItem);
  354. popMenu.Items.Add(menuItem);
  355. SetSelectTextOrImageMenuItem(T_RightMenuSelectionStrikethrough, "Strikeout", annotCommand, out menuItem);
  356. popMenu.Items.Add(menuItem);
  357. separator = SetSeparator();
  358. //popMenu.Items.Add(separator);
  359. SetSelectTextOrImageMenuItem(T_RightMenuSelectionText, "Freetext", annotCommand, out menuItem);
  360. //popMenu.Items.Add(menuItem);
  361. SetSelectTextOrImageMenuItem(T_RightMenuSelectionNote, "StickyNote", annotCommand, out menuItem);
  362. //popMenu.Items.Add(menuItem);
  363. separator = SetSeparator();
  364. popMenu.Items.Add(separator);
  365. SetSelectTextOrImageMenuItem(T_RightMenuSelectionRectangle, "Rect", annotCommand, out menuItem);
  366. popMenu.Items.Add(menuItem);
  367. SetSelectTextOrImageMenuItem(T_RightMenuSelectionOval, "Circle", annotCommand, out menuItem);
  368. popMenu.Items.Add(menuItem);
  369. SetSelectTextOrImageMenuItem(T_RightMenuSelectionStraightLine, "Line", annotCommand, out menuItem);
  370. //popMenu.Items.Add(menuItem);
  371. }
  372. separator = SetSeparator();
  373. popMenu.Items.Add(separator);
  374. SetSelectTextOrImageMenuItem(T_RightMenuSelectionAddLink, "Link", annotCommand, out menuItem);
  375. popMenu.Items.Add(menuItem);
  376. if (annotCommand.CommandTarget == TargetType.Annot)
  377. {
  378. SetSelectTextOrImageMenuItem(T_RightMenuSelectionAddOutline, "OutLine", annotCommand, out menuItem);
  379. popMenu.Items.Add(menuItem);
  380. }
  381. return popMenu;
  382. }
  383. private void SetSelectTextOrImageMenuItem(string header, string tag, AnnotCommandArgs annotCommand, out MenuItem menuItem)
  384. {
  385. menuItem = new MenuItem();
  386. menuItem.Header = header;
  387. menuItem.Tag = tag;
  388. if (tag == "OutLine")
  389. {
  390. if (viewContentViewModel.mainViewModel.IsBookMode)
  391. {
  392. menuItem.IsEnabled = false;
  393. }
  394. else
  395. {
  396. menuItem.IsEnabled = true;
  397. }
  398. }
  399. menuItem.Click -= AnnotToolMenu_Click;
  400. menuItem.Click += AnnotToolMenu_Click;
  401. menuItem.CommandParameter = annotCommand;
  402. }
  403. private Separator SetSeparator()
  404. {
  405. Separator separator = new Separator
  406. {
  407. Height = 1,
  408. BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33000000")),
  409. BorderThickness = new Thickness(1),
  410. Style = (Style)App.Current.FindResource(System.Windows.Controls.ToolBar.SeparatorStyleKey)
  411. };
  412. return separator;
  413. }
  414. #endregion 阅读页 - 右键菜单
  415. #region 注释-右键菜单
  416. #region 注释-右键菜单文案
  417. public string T_RightMenuAnnotCopy = App.MainPageLoader.GetString("ViewRightMenuSelection_Copy");
  418. public string T_RightMenuAnnotPaste = App.MainPageLoader.GetString("ViewRightMenuSelection_Paste");
  419. public string T_RightMenuAnnotHighlight = App.MainPageLoader.GetString("ViewRightMenuSelection_Highlight");
  420. public string T_RightMenuAnnotUnderline = App.MainPageLoader.GetString("ViewRightMenuSelection_Underline");
  421. public string T_RightMenuAnnotStrikethrough = App.MainPageLoader.GetString("ViewRightMenuSelection_Strikethrough");
  422. public string T_RightMenuAnnotText = App.MainPageLoader.GetString("ViewRightMenuSelection_Text");
  423. public string T_RightMenuAnnotNote = App.MainPageLoader.GetString("ViewRightMenuSelection_Note");
  424. #endregion 注释-右键菜单文案
  425. private ColorMenuItem colorContent;
  426. /// <summary>
  427. /// 高亮注释,右键菜单
  428. /// </summary>
  429. ///
  430. private void InitSelectHightAnnotMenu()
  431. {
  432. var popMenu = new ContextMenu();
  433. PopMenu pop = new PopMenu(popMenu);
  434. colorContent = new ColorMenuItem();
  435. colorContent.Name = "hightcolor";
  436. colorContent.ColorChanged -= colorContent_SelectedColorHandler;
  437. colorContent.ColorChanged += colorContent_SelectedColorHandler;
  438. colorContent.VerticalAlignment = VerticalAlignment.Top;
  439. colorContent.Margin = new Thickness(0, 0, 0, -15);
  440. var menuItem = new MenuItem();
  441. menuItem.Name = "hightColor";
  442. menuItem.Height = 20 + 15;
  443. menuItem.Header = colorContent;
  444. var hightColorStyle = App.Current.FindResource("UIElementMenuItem") as Style;
  445. if (hightColorStyle != null)
  446. menuItem.Style = hightColorStyle;
  447. colorContent.DataContext = pop.AddItem(menuItem);
  448. pop.AddItem(GetSeparator());
  449. menuItem = new MenuItem();
  450. menuItem.Name = "hightCopyText";
  451. menuItem.Header = "复制文本";
  452. pop.BindingEvent(pop.AddItem(menuItem), HightAnnotCopyText_MenuCommand);
  453. menuItem = new MenuItem();
  454. menuItem.Name = "hightdelete";
  455. menuItem.Header = "删除";
  456. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  457. pop.AddItem(GetSeparator());
  458. menuItem = new MenuItem();
  459. menuItem.Name = "hightAddNote";
  460. menuItem.Header = "添加笔记";
  461. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  462. menuItem = new MenuItem();
  463. menuItem.Name = "hightdefault";
  464. menuItem.Header = "设置当前属性为默认值";
  465. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  466. HightAnnotPopMenu = pop;
  467. }
  468. private Separator GetSeparator()
  469. {
  470. Separator separator = new Separator();
  471. separator.Height = 1;
  472. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  473. separator.BorderThickness = new Thickness(1);
  474. separator.Margin = new Thickness(-30, 0, 0, 0);
  475. return separator;
  476. }
  477. private async void colorContent_SelectedColorHandler(object sender, Color e)
  478. {
  479. if (e == null) return;
  480. if (sender is Ellipse)
  481. {
  482. var item = new ColorDropBoxPop();
  483. item.DataContext = (sender as Ellipse).DataContext;
  484. item.ColorSelected -= AnnotMenu_ColorSelected;
  485. item.ColorSelected += AnnotMenu_ColorSelected;
  486. if (popup == null)
  487. popup = new System.Windows.Controls.Primitives.Popup();
  488. ContentControl window = null;
  489. if (PDFViewer.Parent as ContentControl != null)
  490. window = PDFViewer.Parent as ContentControl;
  491. else
  492. window = App.Current.MainWindow;
  493. popup.Child = item;
  494. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  495. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  496. popup.PlacementTarget = window;
  497. popup.IsOpen = true;
  498. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  499. if (parentWnd != null)
  500. {
  501. parentWnd.MouseDown -= parentWnd_MouseDown;
  502. parentWnd.MouseDown += parentWnd_MouseDown;
  503. }
  504. while (popup.IsOpen)
  505. await Task.Delay(20);
  506. parentWnd.MouseDown -= parentWnd_MouseDown;
  507. popup = null;
  508. }
  509. else
  510. {
  511. var cusMenuItem = (sender as FrameworkElement).DataContext as CusMenuItem;
  512. if (cusMenuItem != null && cusMenuItem.Parameter != null)
  513. {
  514. if (cusMenuItem.Parameter is TextHighlightAnnotArgs textHighlightAnnotArgs)
  515. {
  516. var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textHighlightAnnotArgs, textHighlightAnnotArgs.GetAnnotAttrib());
  517. anvent.UpdateAttrib(AnnotAttrib.Color, e);
  518. anvent.UpdateAnnot();
  519. }
  520. if (cusMenuItem.Parameter is TextUnderlineAnnotArgs textUnderlineAnnotArgs)
  521. {
  522. var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textUnderlineAnnotArgs, textUnderlineAnnotArgs.GetAnnotAttrib());
  523. anvent.UpdateAttrib(AnnotAttrib.Color, e);
  524. anvent.UpdateAnnot();
  525. }
  526. if (cusMenuItem.Parameter is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs)
  527. {
  528. var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textStrikeoutAnnotArgs, textStrikeoutAnnotArgs.GetAnnotAttrib());
  529. anvent.UpdateAttrib(AnnotAttrib.Color, e);
  530. anvent.UpdateAnnot();
  531. }
  532. //var test = cusMenuItem.Parameter as TextHighlightAnnotArgs;
  533. //if (test != null)
  534. //{
  535. // var anvent = AnnotAttribEvent.GetAnnotAttribEvent(test, test.GetAnnotAttrib());
  536. // anvent.UpdateAttrib(AnnotAttrib.Color, e);
  537. // anvent.UpdateAnnot();
  538. //}
  539. }
  540. }
  541. }
  542. /// <summary>
  543. /// 手绘
  544. /// </summary>
  545. private void InitSelectFreeHandAnnotMenu()
  546. {
  547. var popMenu = new ContextMenu();
  548. PopMenu pop = new PopMenu(popMenu);
  549. var menuItem = new MenuItem();
  550. menuItem.Name = "FreeHandCopy";
  551. menuItem.Header = "复制";
  552. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  553. menuItem = new MenuItem();
  554. menuItem.Name = "FreeHandCut";
  555. menuItem.Header = "剪切";
  556. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  557. menuItem = new MenuItem();
  558. menuItem.Name = "FreeHandPaste";
  559. menuItem.Header = "粘贴";
  560. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  561. menuItem = new MenuItem();
  562. menuItem.Name = "FreeHandDelete";
  563. menuItem.Header = "删除";
  564. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  565. pop.AddItem(GetSeparator());
  566. menuItem = new MenuItem();
  567. menuItem.Name = "FreeHandColor";
  568. menuItem.Header = "边框颜色";
  569. menuItem.Tag = "Color";
  570. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  571. menuItem = new MenuItem();
  572. menuItem.Name = "FreeHandLineStyle";
  573. menuItem.Header = "线段样式";
  574. pop.AddItem(menuItem);
  575. RadioButton radioButton = new RadioButton();
  576. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  577. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  578. radioButton.Name = "FreeHandSolid";
  579. radioButton.Content = "实线";
  580. radioButton.GroupName = "LineStyle";
  581. radioButton.Tag = "Solid";
  582. pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand);
  583. radioButton = new RadioButton();
  584. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  585. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  586. radioButton.Name = "FreeHandDash";
  587. radioButton.Content = "虚线";
  588. radioButton.GroupName = "LineStyle";
  589. radioButton.Tag = "Dash";
  590. pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand);
  591. menuItem = new MenuItem();
  592. menuItem.Name = "FreeHandAddNote";
  593. menuItem.Header = "添加笔记";
  594. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  595. menuItem = new MenuItem();
  596. menuItem.Name = "FreeHandDefault";
  597. menuItem.Header = "设置当前属性为默认值";
  598. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  599. FreeHandAnnotPopMenu = pop;
  600. }
  601. /// <summary>
  602. /// 文本
  603. /// </summary>
  604. private void InitSelectFreeTextAnnotMenu()
  605. {
  606. var popMenu = new ContextMenu();
  607. PopMenu pop = new PopMenu(popMenu);
  608. var menuItem = new MenuItem();
  609. menuItem.Name = "FreeTextCopy";
  610. menuItem.Header = "复制";
  611. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  612. menuItem = new MenuItem();
  613. menuItem.Name = "FreeTextCut";
  614. menuItem.Header = "剪切";
  615. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  616. menuItem = new MenuItem();
  617. menuItem.Name = "FreeTextPaste";
  618. menuItem.Header = "粘贴";
  619. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  620. menuItem = new MenuItem();
  621. menuItem.Name = "FreeTextDelete";
  622. menuItem.Header = "删除";
  623. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  624. pop.AddItem(GetSeparator());
  625. menuItem = new MenuItem();
  626. menuItem.Name = "FreeTextColor";
  627. menuItem.Header = "字体颜色";
  628. menuItem.Tag = "FontColor";
  629. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  630. menuItem = new MenuItem();
  631. menuItem.Name = "FreeTextFillColor";
  632. menuItem.Header = "填充颜色";
  633. menuItem.Tag = "FillColor";
  634. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  635. menuItem = new MenuItem();
  636. menuItem.Name = "FreeTextFontFamily";
  637. menuItem.Header = "字体";
  638. pop.AddItem(menuItem);
  639. var family = TextFont.GetFamily();
  640. foreach (var item in family)
  641. {
  642. RadioButton familyRdioBtn = new RadioButton();
  643. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  644. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  645. familyRdioBtn.Name = item.ValueStr;
  646. familyRdioBtn.Tag = item.ValueStr;
  647. familyRdioBtn.GroupName = "FontFamily";
  648. familyRdioBtn.Content = item.Content;
  649. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  650. }
  651. menuItem = new MenuItem();
  652. menuItem.Name = "FreeTextAglin";
  653. menuItem.Header = "文本对齐";
  654. pop.AddItem(menuItem);
  655. var radioButton = new RadioButton();
  656. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  657. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  658. radioButton.Name = "FreeTextAglinLeft";
  659. radioButton.Tag = "Left";
  660. radioButton.GroupName = "Aglin";
  661. radioButton.Content = "左对齐";
  662. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  663. radioButton = new RadioButton();
  664. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  665. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  666. radioButton.Name = "FreeTextAglinCenter";
  667. radioButton.Tag = "Center";
  668. radioButton.GroupName = "Aglin";
  669. radioButton.Content = "居中对齐";
  670. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  671. radioButton = new RadioButton();
  672. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  673. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  674. radioButton.Name = "FreeTextAglinRight";
  675. radioButton.Tag = "Right";
  676. radioButton.GroupName = "Aglin";
  677. radioButton.Content = "右对齐";
  678. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  679. radioButton = new RadioButton();
  680. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  681. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  682. radioButton.Name = "FreeTextAglinJustify";
  683. radioButton.Tag = "Justify";
  684. radioButton.GroupName = "Aglin";
  685. radioButton.Content = "两端对齐";
  686. //pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  687. menuItem = new MenuItem();
  688. menuItem.Name = "FreeHandDefault";
  689. menuItem.Header = "设置当前属性为默认值";
  690. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  691. FreeTextAnnotPopMenu = pop;
  692. }
  693. /// <summary>
  694. /// 便签
  695. /// </summary>
  696. private void InitSelectStrickNoteAnnotMenu()
  697. {
  698. var popMenu = new ContextMenu();
  699. PopMenu pop = new PopMenu(popMenu);
  700. var menuItem = new MenuItem();
  701. menuItem.Name = "StrickNoteCopy";
  702. menuItem.Header = "复制";
  703. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  704. menuItem = new MenuItem();
  705. menuItem.Name = "StrickNoteCut";
  706. menuItem.Header = "剪切";
  707. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  708. menuItem = new MenuItem();
  709. menuItem.Name = "StrickNotePaste";
  710. menuItem.Header = "粘贴";
  711. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  712. menuItem = new MenuItem();
  713. menuItem.Name = "StrickNoteDelete";
  714. menuItem.Header = "删除";
  715. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  716. pop.AddItem(GetSeparator());
  717. menuItem = new MenuItem();
  718. menuItem.Name = "StrickNoteColor";
  719. menuItem.Header = "颜色";
  720. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  721. menuItem = new MenuItem();
  722. menuItem.Name = "StrickNoteEdit";
  723. menuItem.Header = "编辑便签";
  724. pop.BindingEvent(pop.AddItem(menuItem), StrikeNoteEditStrike_MenuCommand);
  725. menuItem = new MenuItem();
  726. menuItem.Name = "StrickNoteDefault";
  727. menuItem.Header = "设置当前属性为默认值";
  728. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  729. StrickNoteAnnotPopMenu = pop;
  730. }
  731. /// <summary>
  732. /// 形状
  733. /// </summary>
  734. private void InitSelectShapeAnnotMenu()
  735. {
  736. var popMenu = new ContextMenu();
  737. PopMenu pop = new PopMenu(popMenu);
  738. var menuItem = new MenuItem();
  739. menuItem.Name = "ShapeCopy";
  740. menuItem.Header = "复制";
  741. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  742. menuItem = new MenuItem();
  743. menuItem.Name = "ShapeCut";
  744. menuItem.Header = "剪切";
  745. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  746. menuItem = new MenuItem();
  747. menuItem.Name = "ShapePaste";
  748. menuItem.Header = "粘贴";
  749. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  750. menuItem = new MenuItem();
  751. menuItem.Name = "ShapeDelete";
  752. menuItem.Header = "删除";
  753. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  754. pop.AddItem(GetSeparator());
  755. menuItem = new MenuItem();
  756. menuItem.Name = "ShapeColor";
  757. menuItem.Header = "边框颜色";
  758. menuItem.Tag = "Color";
  759. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  760. menuItem = new MenuItem();
  761. menuItem.Name = "ShapeFillColor";
  762. menuItem.Header = "填充颜色";
  763. menuItem.Tag = "FillColor";
  764. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  765. menuItem = new MenuItem();
  766. menuItem.Name = "ShapeLineStyle";
  767. menuItem.Header = "线段样式";
  768. pop.AddItem(menuItem);
  769. RadioButton radioButton = new RadioButton();
  770. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  771. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  772. radioButton.Name = "ShapeSolid";
  773. radioButton.Content = "实线";
  774. radioButton.GroupName = "LineStyle";
  775. radioButton.Tag = "Solid";
  776. pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand);
  777. radioButton = new RadioButton();
  778. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  779. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  780. radioButton.Name = "ShapeDash";
  781. radioButton.Content = "虚线";
  782. radioButton.GroupName = "LineStyle";
  783. radioButton.Tag = "Dash";
  784. pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand);
  785. menuItem = new MenuItem();
  786. menuItem.Name = "ShapeDirect";
  787. menuItem.Header = "线段方向";
  788. pop.AddItem(menuItem);
  789. menuItem = new MenuItem();
  790. menuItem.Name = "ShapeVer";
  791. menuItem.Header = "垂直";
  792. menuItem.Tag = "Ver";
  793. pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand);
  794. menuItem = new MenuItem();
  795. menuItem.Name = "ShapeHor";
  796. menuItem.Header = "横向";
  797. menuItem.Tag = "Hor";
  798. pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand);
  799. menuItem = new MenuItem();
  800. menuItem.Name = "ShapeNoteText";
  801. menuItem.Header = "添加笔记";
  802. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  803. menuItem = new MenuItem();
  804. menuItem.Name = "ShapeDefault";
  805. menuItem.Header = "设置当前属性为默认值";
  806. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  807. ShapeAnnotPopMenu = pop;
  808. }
  809. /// <summary>
  810. /// 链接
  811. /// </summary>
  812. private void InitSelectLinkAnnotMenu()
  813. {
  814. var popMenu = new ContextMenu();
  815. PopMenu pop = new PopMenu(popMenu);
  816. var menuItem = new MenuItem();
  817. menuItem.Name = "LinkCopy";
  818. menuItem.Header = "复制";
  819. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  820. menuItem = new MenuItem();
  821. menuItem.Name = "LinkCut";
  822. menuItem.Header = "剪切";
  823. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  824. menuItem = new MenuItem();
  825. menuItem.Name = "LinkPaste";
  826. menuItem.Header = "粘贴";
  827. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  828. menuItem = new MenuItem();
  829. menuItem.Name = "LinkDelete";
  830. menuItem.Header = "删除";
  831. pop.BindingEvent(pop.AddItem(menuItem), Link_MenuCommand);
  832. LinkAnnotPopMenu = pop;
  833. }
  834. /// <summary>
  835. /// 图章、签名
  836. /// </summary>
  837. private void InitSelectStampAnnotMenu()
  838. {
  839. var popMenu = new ContextMenu();
  840. PopMenu pop = new PopMenu(popMenu);
  841. var menuItem = new MenuItem();
  842. menuItem.Name = "StampCopy";
  843. menuItem.Header = "复制";
  844. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  845. menuItem = new MenuItem();
  846. menuItem.Name = "StampCut";
  847. menuItem.Header = "剪切";
  848. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  849. menuItem = new MenuItem();
  850. menuItem.Name = "StampPaste";
  851. menuItem.Header = "粘贴";
  852. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  853. menuItem = new MenuItem();
  854. menuItem.Name = "StampDelete";
  855. menuItem.Header = "删除";
  856. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  857. pop.AddItem(GetSeparator());
  858. menuItem = new MenuItem();
  859. menuItem.Name = "StampExportPicture";
  860. menuItem.Header = "导出";
  861. pop.AddItem(menuItem);
  862. menuItem = new MenuItem();
  863. menuItem.Name = "StampExportPNG";
  864. menuItem.Header = "PNG";
  865. menuItem.Tag = "PNG";
  866. pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  867. //已跟设计确认,暂时不需要JPG格式
  868. //menuItem = new MenuItem();
  869. //menuItem.Name = "StampExportPNG";
  870. //menuItem.Header = "JPG";
  871. //menuItem.Tag = "JPG";
  872. //pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  873. menuItem = new MenuItem();
  874. menuItem.Name = "StampExportPDF";
  875. menuItem.Header = "PDF";
  876. menuItem.Tag = "PDF";
  877. pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  878. menuItem = new MenuItem();
  879. menuItem.Name = "StampAddNote";
  880. menuItem.Header = "添加笔记";
  881. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  882. StampAnnotPopMenu = pop;
  883. }
  884. /// <summary>
  885. /// 多选注释
  886. /// </summary>
  887. private void InitSelectMultiAnnotMenu()
  888. {
  889. var popMenu = new ContextMenu();
  890. PopMenu pop = new PopMenu(popMenu);
  891. var menuItem = new MenuItem();
  892. menuItem.Name = "MultiCopy";
  893. menuItem.Header = "复制";
  894. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  895. menuItem = new MenuItem();
  896. menuItem.Name = "MultiCut";
  897. menuItem.Header = "剪切";
  898. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  899. menuItem = new MenuItem();
  900. menuItem.Name = "MultiDelete";
  901. menuItem.Header = "删除";
  902. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  903. MultiAnnotPopMenu = pop;
  904. }
  905. #endregion 注释-右键菜单
  906. }
  907. }