AnnotToolContentViewModel.Layout.cs 38 KB

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