AnnotToolContentViewModel.Layout.cs 38 KB

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