AnnotToolContentViewModel.Layout.cs 38 KB

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