AnnotToolContentViewModel.Layout.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. var test = cusMenuItem.Parameter as TextHighlightAnnotArgs;
  476. if (test != null)
  477. {
  478. var anvent = AnnotAttribEvent.GetAnnotAttribEvent(test, test.GetAnnotAttrib());
  479. anvent.UpdateAttrib(AnnotAttrib.Color, e);
  480. anvent.UpdateAnnot();
  481. }
  482. }
  483. }
  484. }
  485. /// <summary>
  486. /// 手绘
  487. /// </summary>
  488. private void InitSelectFreeHandAnnotMenu()
  489. {
  490. var popMenu = new ContextMenu();
  491. PopMenu pop = new PopMenu(popMenu);
  492. var menuItem = new MenuItem();
  493. menuItem.Name = "FreeHandCopy";
  494. menuItem.Header = "复制";
  495. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  496. menuItem = new MenuItem();
  497. menuItem.Name = "FreeHandCut";
  498. menuItem.Header = "剪切";
  499. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  500. menuItem = new MenuItem();
  501. menuItem.Name = "FreeHandPaste";
  502. menuItem.Header = "粘贴";
  503. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  504. menuItem = new MenuItem();
  505. menuItem.Name = "FreeHandDelete";
  506. menuItem.Header = "删除";
  507. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  508. pop.AddItem(GetSeparator());
  509. menuItem = new MenuItem();
  510. menuItem.Name = "FreeHandColor";
  511. menuItem.Header = "边框颜色";
  512. menuItem.Tag = "Color";
  513. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  514. menuItem = new MenuItem();
  515. menuItem.Name = "FreeHandLineStyle";
  516. menuItem.Header = "线段样式";
  517. pop.AddItem(menuItem);
  518. RadioButton radioButton = new RadioButton();
  519. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  520. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  521. radioButton.Name = "FreeHandSolid";
  522. radioButton.Content = "实线";
  523. radioButton.GroupName = "LineStyle";
  524. radioButton.Tag = "Solid";
  525. pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand);
  526. radioButton = new RadioButton();
  527. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  528. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  529. radioButton.Name = "FreeHandDash";
  530. radioButton.Content = "虚线";
  531. radioButton.GroupName = "LineStyle";
  532. radioButton.Tag = "Dash";
  533. pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand);
  534. menuItem = new MenuItem();
  535. menuItem.Name = "FreeHandAddNote";
  536. menuItem.Header = "添加笔记";
  537. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  538. menuItem = new MenuItem();
  539. menuItem.Name = "FreeHandDefault";
  540. menuItem.Header = "设置当前属性为默认值";
  541. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  542. FreeHandAnnotPopMenu = pop;
  543. }
  544. /// <summary>
  545. /// 文本
  546. /// </summary>
  547. private void InitSelectFreeTextAnnotMenu()
  548. {
  549. var popMenu = new ContextMenu();
  550. PopMenu pop = new PopMenu(popMenu);
  551. var menuItem = new MenuItem();
  552. menuItem.Name = "FreeTextCopy";
  553. menuItem.Header = "复制";
  554. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  555. menuItem = new MenuItem();
  556. menuItem.Name = "FreeTextCut";
  557. menuItem.Header = "剪切";
  558. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  559. menuItem = new MenuItem();
  560. menuItem.Name = "FreeTextPaste";
  561. menuItem.Header = "粘贴";
  562. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  563. menuItem = new MenuItem();
  564. menuItem.Name = "FreeTextDelete";
  565. menuItem.Header = "删除";
  566. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  567. pop.AddItem(GetSeparator());
  568. menuItem = new MenuItem();
  569. menuItem.Name = "FreeTextColor";
  570. menuItem.Header = "字体颜色";
  571. menuItem.Tag = "FontColor";
  572. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  573. menuItem = new MenuItem();
  574. menuItem.Name = "FreeTextFillColor";
  575. menuItem.Header = "填充颜色";
  576. menuItem.Tag = "FillColor";
  577. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  578. menuItem = new MenuItem();
  579. menuItem.Name = "FreeTextFontFamily";
  580. menuItem.Header = "字体";
  581. pop.AddItem(menuItem);
  582. var family = TextFont.GetFamily();
  583. foreach (var item in family)
  584. {
  585. RadioButton familyRdioBtn = new RadioButton();
  586. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  587. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  588. familyRdioBtn.Name = item.ValueStr;
  589. familyRdioBtn.Tag = item.ValueStr;
  590. familyRdioBtn.GroupName = "FontFamily";
  591. familyRdioBtn.Content = item.Content;
  592. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  593. }
  594. menuItem = new MenuItem();
  595. menuItem.Name = "FreeTextAglin";
  596. menuItem.Header = "文本对齐";
  597. pop.AddItem(menuItem);
  598. var radioButton = new RadioButton();
  599. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  600. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  601. radioButton.Name = "FreeTextAglinLeft";
  602. radioButton.Tag = "Left";
  603. radioButton.GroupName = "Aglin";
  604. radioButton.Content = "左对齐";
  605. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  606. radioButton = new RadioButton();
  607. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  608. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  609. radioButton.Name = "FreeTextAglinCenter";
  610. radioButton.Tag = "Center";
  611. radioButton.GroupName = "Aglin";
  612. radioButton.Content = "居中对齐";
  613. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  614. radioButton = new RadioButton();
  615. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  616. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  617. radioButton.Name = "FreeTextAglinRight";
  618. radioButton.Tag = "Right";
  619. radioButton.GroupName = "Aglin";
  620. radioButton.Content = "右对齐";
  621. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  622. radioButton = new RadioButton();
  623. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  624. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  625. radioButton.Name = "FreeTextAglinJustify";
  626. radioButton.Tag = "Justify";
  627. radioButton.GroupName = "Aglin";
  628. radioButton.Content = "两端对齐";
  629. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  630. menuItem = new MenuItem();
  631. menuItem.Name = "FreeHandDefault";
  632. menuItem.Header = "设置当前属性为默认值";
  633. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  634. FreeTextAnnotPopMenu = pop;
  635. }
  636. /// <summary>
  637. /// 便签
  638. /// </summary>
  639. private void InitSelectStrickNoteAnnotMenu()
  640. {
  641. var popMenu = new ContextMenu();
  642. PopMenu pop = new PopMenu(popMenu);
  643. var menuItem = new MenuItem();
  644. menuItem.Name = "StrickNoteCopy";
  645. menuItem.Header = "复制";
  646. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  647. menuItem = new MenuItem();
  648. menuItem.Name = "StrickNoteCut";
  649. menuItem.Header = "剪切";
  650. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  651. menuItem = new MenuItem();
  652. menuItem.Name = "StrickNotePaste";
  653. menuItem.Header = "粘贴";
  654. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  655. menuItem = new MenuItem();
  656. menuItem.Name = "StrickNoteDelete";
  657. menuItem.Header = "删除";
  658. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  659. pop.AddItem(GetSeparator());
  660. menuItem = new MenuItem();
  661. menuItem.Name = "StrickNoteColor";
  662. menuItem.Header = "颜色";
  663. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  664. menuItem = new MenuItem();
  665. menuItem.Name = "StrickNoteEdit";
  666. menuItem.Header = "编辑便签";
  667. pop.BindingEvent(pop.AddItem(menuItem), StrikeNoteEditStrike_MenuCommand);
  668. menuItem = new MenuItem();
  669. menuItem.Name = "StrickNoteDefault";
  670. menuItem.Header = "设置当前属性为默认值";
  671. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  672. StrickNoteAnnotPopMenu = pop;
  673. }
  674. /// <summary>
  675. /// 形状
  676. /// </summary>
  677. private void InitSelectShapeAnnotMenu()
  678. {
  679. var popMenu = new ContextMenu();
  680. PopMenu pop = new PopMenu(popMenu);
  681. var menuItem = new MenuItem();
  682. menuItem.Name = "ShapeCopy";
  683. menuItem.Header = "复制";
  684. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  685. menuItem = new MenuItem();
  686. menuItem.Name = "ShapeCut";
  687. menuItem.Header = "剪切";
  688. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  689. menuItem = new MenuItem();
  690. menuItem.Name = "ShapePaste";
  691. menuItem.Header = "粘贴";
  692. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  693. menuItem = new MenuItem();
  694. menuItem.Name = "ShapeDelete";
  695. menuItem.Header = "删除";
  696. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  697. pop.AddItem(GetSeparator());
  698. menuItem = new MenuItem();
  699. menuItem.Name = "ShapeColor";
  700. menuItem.Header = "边框颜色";
  701. menuItem.Tag = "Color";
  702. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  703. menuItem = new MenuItem();
  704. menuItem.Name = "ShapeFillColor";
  705. menuItem.Header = "填充颜色";
  706. menuItem.Tag = "FillColor";
  707. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  708. menuItem = new MenuItem();
  709. menuItem.Name = "ShapeLineStyle";
  710. menuItem.Header = "线段样式";
  711. pop.AddItem(menuItem);
  712. RadioButton radioButton = new RadioButton();
  713. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  714. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  715. radioButton.Name = "ShapeSolid";
  716. radioButton.Content = "实线";
  717. radioButton.GroupName = "LineStyle";
  718. radioButton.Tag = "Solid";
  719. pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand);
  720. radioButton = new RadioButton();
  721. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  722. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  723. radioButton.Name = "ShapeDash";
  724. radioButton.Content = "虚线";
  725. radioButton.GroupName = "LineStyle";
  726. radioButton.Tag = "Dash";
  727. pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand);
  728. menuItem = new MenuItem();
  729. menuItem.Name = "ShapeDirect";
  730. menuItem.Header = "线段方向";
  731. pop.AddItem(menuItem);
  732. menuItem = new MenuItem();
  733. menuItem.Name = "ShapeVer";
  734. menuItem.Header = "垂直";
  735. menuItem.Tag = "Ver";
  736. pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand);
  737. menuItem = new MenuItem();
  738. menuItem.Name = "ShapeHor";
  739. menuItem.Header = "横向";
  740. menuItem.Tag = "Hor";
  741. pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand);
  742. menuItem = new MenuItem();
  743. menuItem.Name = "ShapeNoteText";
  744. menuItem.Header = "添加笔记";
  745. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  746. menuItem = new MenuItem();
  747. menuItem.Name = "ShapeDefault";
  748. menuItem.Header = "设置当前属性为默认值";
  749. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  750. ShapeAnnotPopMenu = pop;
  751. }
  752. /// <summary>
  753. /// 链接
  754. /// </summary>
  755. private void InitSelectLinkAnnotMenu()
  756. {
  757. var popMenu = new ContextMenu();
  758. PopMenu pop = new PopMenu(popMenu);
  759. var menuItem = new MenuItem();
  760. menuItem.Name = "LinkCopy";
  761. menuItem.Header = "复制";
  762. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  763. menuItem = new MenuItem();
  764. menuItem.Name = "LinkCut";
  765. menuItem.Header = "剪切";
  766. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  767. menuItem = new MenuItem();
  768. menuItem.Name = "LinkPaste";
  769. menuItem.Header = "粘贴";
  770. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  771. menuItem = new MenuItem();
  772. menuItem.Name = "LinkDelete";
  773. menuItem.Header = "删除";
  774. pop.BindingEvent(pop.AddItem(menuItem), Link_MenuCommand);
  775. LinkAnnotPopMenu = pop;
  776. }
  777. /// <summary>
  778. /// 图章、签名
  779. /// </summary>
  780. private void InitSelectStampAnnotMenu()
  781. {
  782. var popMenu = new ContextMenu();
  783. PopMenu pop = new PopMenu(popMenu);
  784. var menuItem = new MenuItem();
  785. menuItem.Name = "StampCopy";
  786. menuItem.Header = "复制";
  787. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  788. menuItem = new MenuItem();
  789. menuItem.Name = "StampCut";
  790. menuItem.Header = "剪切";
  791. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  792. menuItem = new MenuItem();
  793. menuItem.Name = "StampPaste";
  794. menuItem.Header = "粘贴";
  795. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  796. menuItem = new MenuItem();
  797. menuItem.Name = "StampDelete";
  798. menuItem.Header = "删除";
  799. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  800. pop.AddItem(GetSeparator());
  801. menuItem = new MenuItem();
  802. menuItem.Name = "StampExportPicture";
  803. menuItem.Header = "导出";
  804. pop.AddItem(menuItem);
  805. menuItem = new MenuItem();
  806. menuItem.Name = "StampExportPNG";
  807. menuItem.Header = "PNG";
  808. menuItem.Tag = "PNG";
  809. pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  810. //已跟设计确认,暂时不需要JPG格式
  811. //menuItem = new MenuItem();
  812. //menuItem.Name = "StampExportPNG";
  813. //menuItem.Header = "JPG";
  814. //menuItem.Tag = "JPG";
  815. //pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  816. menuItem = new MenuItem();
  817. menuItem.Name = "StampExportPDF";
  818. menuItem.Header = "PDF";
  819. menuItem.Tag = "PDF";
  820. pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  821. menuItem = new MenuItem();
  822. menuItem.Name = "StampAddNote";
  823. menuItem.Header = "添加笔记";
  824. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  825. StampAnnotPopMenu = pop;
  826. }
  827. /// <summary>
  828. /// 多选注释
  829. /// </summary>
  830. private void InitSelectMultiAnnotMenu()
  831. {
  832. var popMenu = new ContextMenu();
  833. PopMenu pop = new PopMenu(popMenu);
  834. var menuItem = new MenuItem();
  835. menuItem.Name = "MultiCopy";
  836. menuItem.Header = "复制";
  837. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  838. menuItem = new MenuItem();
  839. menuItem.Name = "MultiCut";
  840. menuItem.Header = "剪切";
  841. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  842. menuItem = new MenuItem();
  843. menuItem.Name = "MultiDelete";
  844. menuItem.Header = "删除";
  845. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  846. MultiAnnotPopMenu = pop;
  847. }
  848. #endregion 注释-右键菜单
  849. }
  850. }