AnnotToolContentViewModel.Layout.cs 38 KB

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