AnnotToolContentViewModel.Layout.cs 42 KB

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