AnnotToolContentViewModel.Layout.cs 44 KB

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