AnnotToolContentViewModel.Layout.cs 38 KB

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