AnnotToolContentViewModel.Layout.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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. if (tag == "Link")
  317. {
  318. if (viewContentViewModel.mainViewModel.IsBookMode)
  319. {
  320. menuItem.IsEnabled = false;
  321. }
  322. else
  323. {
  324. menuItem.IsEnabled = true;
  325. }
  326. }
  327. menuItem.Click -= AnnotToolMenu_Click;
  328. menuItem.Click += AnnotToolMenu_Click;
  329. menuItem.CommandParameter = annotCommand;
  330. }
  331. private Separator SetSeparator()
  332. {
  333. Separator separator = new Separator
  334. {
  335. Height = 1,
  336. BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33000000")),
  337. BorderThickness = new Thickness(1),
  338. Style = (Style)App.Current.FindResource(System.Windows.Controls.ToolBar.SeparatorStyleKey)
  339. };
  340. return separator;
  341. }
  342. #endregion 阅读页 - 右键菜单
  343. #region 注释-右键菜单
  344. private ColorMenuItem colorContent;
  345. /// <summary>
  346. /// 高亮注释,右键菜单
  347. /// </summary>
  348. private void InitSelectHightAnnotMenu()
  349. {
  350. var popMenu = new ContextMenu();
  351. PopMenu pop = new PopMenu(popMenu);
  352. colorContent = new ColorMenuItem();
  353. colorContent.Name = "hightcolor";
  354. colorContent.ColorChanged -= colorContent_SelectedColorHandler;
  355. colorContent.ColorChanged += colorContent_SelectedColorHandler;
  356. colorContent.VerticalAlignment = VerticalAlignment.Top;
  357. colorContent.Margin = new Thickness(0, 0, 0, -15);
  358. var menuItem = new MenuItem();
  359. menuItem.Name = "hightColor";
  360. menuItem.Height = 20 + 15;
  361. menuItem.Header = colorContent;
  362. var hightColorStyle = App.Current.FindResource("UIElementMenuItem") as Style;
  363. if (hightColorStyle != null)
  364. menuItem.Style = hightColorStyle;
  365. colorContent.DataContext = pop.AddItem(menuItem);
  366. pop.AddItem(GetSeparator());
  367. menuItem = new MenuItem();
  368. menuItem.Name = "hightCopyText";
  369. menuItem.Header = "复制文本";
  370. pop.BindingEvent(pop.AddItem(menuItem), HightAnnotCopyText_MenuCommand);
  371. menuItem = new MenuItem();
  372. menuItem.Name = "hightdelete";
  373. menuItem.Header = "删除";
  374. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  375. pop.AddItem(GetSeparator());
  376. menuItem = new MenuItem();
  377. menuItem.Name = "hightAddNote";
  378. menuItem.Header = "添加笔记";
  379. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  380. menuItem = new MenuItem();
  381. menuItem.Name = "hightdefault";
  382. menuItem.Header = "设置当前属性为默认值";
  383. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  384. HightAnnotPopMenu = pop;
  385. }
  386. private Separator GetSeparator()
  387. {
  388. Separator separator = new Separator();
  389. separator.Height = 1;
  390. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  391. separator.BorderThickness = new Thickness(1);
  392. return separator;
  393. }
  394. private async void colorContent_SelectedColorHandler(object sender, Color e)
  395. {
  396. if (e == null) return;
  397. if (sender is Ellipse)
  398. {
  399. var item = new ColorDropBoxPop();
  400. item.DataContext = (sender as Ellipse).DataContext;
  401. item.ColorSelected -= AnnotMenu_ColorSelected;
  402. item.ColorSelected += AnnotMenu_ColorSelected;
  403. if (popup == null)
  404. popup = new System.Windows.Controls.Primitives.Popup();
  405. ContentControl window = null;
  406. if (PDFViewer.Parent as ContentControl != null)
  407. window = PDFViewer.Parent as ContentControl;
  408. else
  409. window = App.Current.MainWindow;
  410. popup.Child = item;
  411. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  412. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  413. popup.PlacementTarget = window;
  414. popup.IsOpen = true;
  415. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  416. if (parentWnd != null)
  417. {
  418. parentWnd.MouseDown -= parentWnd_MouseDown;
  419. parentWnd.MouseDown += parentWnd_MouseDown;
  420. }
  421. while (popup.IsOpen)
  422. await Task.Delay(20);
  423. parentWnd.MouseDown -= parentWnd_MouseDown;
  424. popup = null;
  425. }
  426. else
  427. {
  428. var cusMenuItem = (sender as FrameworkElement).DataContext as CusMenuItem;
  429. if (cusMenuItem != null && cusMenuItem.Parameter != null)
  430. {
  431. var test = cusMenuItem.Parameter as TextHighlightAnnotArgs;
  432. if (test != null)
  433. {
  434. var anvent = AnnotAttribEvent.GetAnnotAttribEvent(test, test.GetAnnotAttrib());
  435. anvent.UpdateAttrib(AnnotAttrib.Color, e);
  436. anvent.UpdateAnnot();
  437. }
  438. }
  439. }
  440. }
  441. /// <summary>
  442. /// 手绘
  443. /// </summary>
  444. private void InitSelectFreeHandAnnotMenu()
  445. {
  446. var popMenu = new ContextMenu();
  447. PopMenu pop = new PopMenu(popMenu);
  448. var menuItem = new MenuItem();
  449. menuItem.Name = "FreeHandCopy";
  450. menuItem.Header = "复制";
  451. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  452. menuItem = new MenuItem();
  453. menuItem.Name = "FreeHandCut";
  454. menuItem.Header = "剪切";
  455. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  456. menuItem = new MenuItem();
  457. menuItem.Name = "FreeHandPaste";
  458. menuItem.Header = "粘贴";
  459. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  460. menuItem = new MenuItem();
  461. menuItem.Name = "FreeHandDelete";
  462. menuItem.Header = "删除";
  463. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  464. pop.AddItem(GetSeparator());
  465. menuItem = new MenuItem();
  466. menuItem.Name = "FreeHandColor";
  467. menuItem.Header = "边框颜色";
  468. menuItem.Tag = "Color";
  469. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  470. menuItem = new MenuItem();
  471. menuItem.Name = "FreeHandLineStyle";
  472. menuItem.Header = "线段样式";
  473. pop.AddItem(menuItem);
  474. RadioButton radioButton = new RadioButton();
  475. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  476. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  477. radioButton.Name = "FreeHandSolid";
  478. radioButton.Content = "实线";
  479. radioButton.GroupName = "LineStyle";
  480. radioButton.Tag = "Solid";
  481. pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand);
  482. radioButton = new RadioButton();
  483. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  484. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  485. radioButton.Name = "FreeHandDash";
  486. radioButton.Content = "虚线";
  487. radioButton.GroupName = "LineStyle";
  488. radioButton.Tag = "Dash";
  489. pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand);
  490. menuItem = new MenuItem();
  491. menuItem.Name = "FreeHandAddNote";
  492. menuItem.Header = "添加笔记";
  493. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  494. menuItem = new MenuItem();
  495. menuItem.Name = "FreeHandDefault";
  496. menuItem.Header = "设置当前属性为默认值";
  497. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  498. FreeHandAnnotPopMenu = pop;
  499. }
  500. /// <summary>
  501. /// 文本
  502. /// </summary>
  503. private void InitSelectFreeTextAnnotMenu()
  504. {
  505. var popMenu = new ContextMenu();
  506. PopMenu pop = new PopMenu(popMenu);
  507. var menuItem = new MenuItem();
  508. menuItem.Name = "FreeTextCopy";
  509. menuItem.Header = "复制";
  510. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  511. menuItem = new MenuItem();
  512. menuItem.Name = "FreeTextCut";
  513. menuItem.Header = "剪切";
  514. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  515. menuItem = new MenuItem();
  516. menuItem.Name = "FreeTextPaste";
  517. menuItem.Header = "粘贴";
  518. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  519. menuItem = new MenuItem();
  520. menuItem.Name = "FreeTextDelete";
  521. menuItem.Header = "删除";
  522. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  523. pop.AddItem(GetSeparator());
  524. menuItem = new MenuItem();
  525. menuItem.Name = "FreeTextColor";
  526. menuItem.Header = "字体颜色";
  527. menuItem.Tag = "FontColor";
  528. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  529. menuItem = new MenuItem();
  530. menuItem.Name = "FreeTextColor";
  531. menuItem.Header = "填充颜色";
  532. menuItem.Tag = "FillColor";
  533. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  534. menuItem = new MenuItem();
  535. menuItem.Name = "FreeTextFontFamily";
  536. menuItem.Header = "字体";
  537. pop.AddItem(menuItem);
  538. var family = TextFont.GetFamily();
  539. foreach (var item in family)
  540. {
  541. RadioButton familyRdioBtn = new RadioButton();
  542. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  543. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  544. familyRdioBtn.Name = item.ValueStr;
  545. familyRdioBtn.Tag = item.ValueStr;
  546. familyRdioBtn.GroupName = "FontFamily";
  547. familyRdioBtn.Content = item.Content;
  548. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  549. }
  550. menuItem = new MenuItem();
  551. menuItem.Name = "FreeTextAglin";
  552. menuItem.Header = "文本对齐";
  553. pop.AddItem(menuItem);
  554. var radioButton = new RadioButton();
  555. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  556. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  557. radioButton.Name = "FreeTextAglinLeft";
  558. radioButton.Tag = "Left";
  559. radioButton.GroupName = "Aglin";
  560. radioButton.Content = "左对齐";
  561. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  562. radioButton = new RadioButton();
  563. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  564. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  565. radioButton.Name = "FreeTextAglinCenter";
  566. radioButton.Tag = "Center";
  567. radioButton.GroupName = "Aglin";
  568. radioButton.Content = "居中对齐";
  569. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  570. radioButton = new RadioButton();
  571. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  572. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  573. radioButton.Name = "FreeTextAglinRight";
  574. radioButton.Tag = "Right";
  575. radioButton.GroupName = "Aglin";
  576. radioButton.Content = "右对齐";
  577. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  578. radioButton = new RadioButton();
  579. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  580. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  581. radioButton.Name = "FreeTextAglinJustify";
  582. radioButton.Tag = "Justify";
  583. radioButton.GroupName = "Aglin";
  584. radioButton.Content = "两端对齐";
  585. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  586. menuItem = new MenuItem();
  587. menuItem.Name = "FreeHandDefault";
  588. menuItem.Header = "设置当前属性为默认值";
  589. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  590. FreeTextAnnotPopMenu = pop;
  591. }
  592. /// <summary>
  593. /// 便签
  594. /// </summary>
  595. private void InitSelectStrickNoteAnnotMenu()
  596. {
  597. var popMenu = new ContextMenu();
  598. PopMenu pop = new PopMenu(popMenu);
  599. var menuItem = new MenuItem();
  600. menuItem.Name = "StrickNoteCopy";
  601. menuItem.Header = "复制";
  602. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  603. menuItem = new MenuItem();
  604. menuItem.Name = "StrickNoteCut";
  605. menuItem.Header = "剪切";
  606. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  607. menuItem = new MenuItem();
  608. menuItem.Name = "StrickNotePaste";
  609. menuItem.Header = "粘贴";
  610. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  611. menuItem = new MenuItem();
  612. menuItem.Name = "StrickNoteDelete";
  613. menuItem.Header = "删除";
  614. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  615. pop.AddItem(GetSeparator());
  616. menuItem = new MenuItem();
  617. menuItem.Name = "StrickNoteColor";
  618. menuItem.Header = "颜色";
  619. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  620. menuItem = new MenuItem();
  621. menuItem.Name = "StrickNoteEdit";
  622. menuItem.Header = "编辑便签";
  623. pop.BindingEvent(pop.AddItem(menuItem), StrikeNoteEditStrike_MenuCommand);
  624. menuItem = new MenuItem();
  625. menuItem.Name = "StrickNoteDefault";
  626. menuItem.Header = "设置当前属性为默认值";
  627. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  628. StrickNoteAnnotPopMenu = pop;
  629. }
  630. /// <summary>
  631. /// 形状
  632. /// </summary>
  633. private void InitSelectShapeAnnotMenu()
  634. {
  635. var popMenu = new ContextMenu();
  636. PopMenu pop = new PopMenu(popMenu);
  637. var menuItem = new MenuItem();
  638. menuItem.Name = "ShapeCopy";
  639. menuItem.Header = "复制";
  640. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  641. menuItem = new MenuItem();
  642. menuItem.Name = "ShapeCut";
  643. menuItem.Header = "剪切";
  644. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  645. menuItem = new MenuItem();
  646. menuItem.Name = "ShapePaste";
  647. menuItem.Header = "粘贴";
  648. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  649. menuItem = new MenuItem();
  650. menuItem.Name = "ShapeDelete";
  651. menuItem.Header = "删除";
  652. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  653. pop.AddItem(GetSeparator());
  654. menuItem = new MenuItem();
  655. menuItem.Name = "ShapeColor";
  656. menuItem.Header = "边框颜色";
  657. menuItem.Tag = "Color";
  658. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  659. menuItem = new MenuItem();
  660. menuItem.Name = "ShapeFillColor";
  661. menuItem.Header = "填充颜色";
  662. menuItem.Tag = "FillColor";
  663. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  664. menuItem = new MenuItem();
  665. menuItem.Name = "ShapeLineStyle";
  666. menuItem.Header = "线段样式";
  667. pop.AddItem(menuItem);
  668. RadioButton radioButton = new RadioButton();
  669. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  670. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  671. radioButton.Name = "ShapeSolid";
  672. radioButton.Content = "实线";
  673. radioButton.GroupName = "LineStyle";
  674. radioButton.Tag = "Solid";
  675. pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand);
  676. radioButton = new RadioButton();
  677. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  678. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  679. radioButton.Name = "ShapeDash";
  680. radioButton.Content = "虚线";
  681. radioButton.GroupName = "LineStyle";
  682. radioButton.Tag = "Dash";
  683. pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand);
  684. menuItem = new MenuItem();
  685. menuItem.Name = "ShapeDirect";
  686. menuItem.Header = "线段方向";
  687. pop.AddItem(menuItem);
  688. menuItem = new MenuItem();
  689. menuItem.Name = "ShapeVer";
  690. menuItem.Header = "垂直";
  691. menuItem.Tag = "Ver";
  692. pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand);
  693. menuItem = new MenuItem();
  694. menuItem.Name = "ShapeHor";
  695. menuItem.Header = "横向";
  696. menuItem.Tag = "Hor";
  697. pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand);
  698. menuItem = new MenuItem();
  699. menuItem.Name = "ShapeNoteText";
  700. menuItem.Header = "添加笔记";
  701. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  702. menuItem = new MenuItem();
  703. menuItem.Name = "ShapeDefault";
  704. menuItem.Header = "设置当前属性为默认值";
  705. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  706. ShapeAnnotPopMenu = pop;
  707. }
  708. /// <summary>
  709. /// 链接
  710. /// </summary>
  711. private void InitSelectLinkAnnotMenu()
  712. {
  713. var popMenu = new ContextMenu();
  714. PopMenu pop = new PopMenu(popMenu);
  715. var menuItem = new MenuItem();
  716. menuItem.Name = "LinkCopy";
  717. menuItem.Header = "复制";
  718. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  719. menuItem = new MenuItem();
  720. menuItem.Name = "LinkCut";
  721. menuItem.Header = "剪切";
  722. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  723. menuItem = new MenuItem();
  724. menuItem.Name = "LinkPaste";
  725. menuItem.Header = "粘贴";
  726. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  727. menuItem = new MenuItem();
  728. menuItem.Name = "LinkDelete";
  729. menuItem.Header = "删除";
  730. pop.BindingEvent(pop.AddItem(menuItem), Link_MenuCommand);
  731. LinkAnnotPopMenu = pop;
  732. }
  733. /// <summary>
  734. /// 图章、签名
  735. /// </summary>
  736. private void InitSelectStampAnnotMenu()
  737. {
  738. var popMenu = new ContextMenu();
  739. PopMenu pop = new PopMenu(popMenu);
  740. var menuItem = new MenuItem();
  741. menuItem.Name = "StampCopy";
  742. menuItem.Header = "复制";
  743. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  744. menuItem = new MenuItem();
  745. menuItem.Name = "StampCut";
  746. menuItem.Header = "剪切";
  747. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  748. menuItem = new MenuItem();
  749. menuItem.Name = "StampPaste";
  750. menuItem.Header = "粘贴";
  751. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  752. menuItem = new MenuItem();
  753. menuItem.Name = "StampDelete";
  754. menuItem.Header = "删除";
  755. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  756. pop.AddItem(GetSeparator());
  757. menuItem = new MenuItem();
  758. menuItem.Name = "StampExportPicture";
  759. menuItem.Header = "导出";
  760. pop.AddItem(menuItem);
  761. //已跟设计确认,暂时不需要PNG格式
  762. //menuItem = new MenuItem();
  763. //menuItem.Name = "StampExportPNG";
  764. //menuItem.Header = "PNG";
  765. //menuItem.Tag = "PNG";
  766. //pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  767. menuItem = new MenuItem();
  768. menuItem.Name = "StampExportPNG";
  769. menuItem.Header = "JPG";
  770. menuItem.Tag = "JPG";
  771. pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  772. menuItem = new MenuItem();
  773. menuItem.Name = "StampExportPNG";
  774. menuItem.Header = "PDF";
  775. menuItem.Tag = "PDF";
  776. pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand);
  777. menuItem = new MenuItem();
  778. menuItem.Name = "StampAddNote";
  779. menuItem.Header = "添加笔记";
  780. pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand);
  781. StampAnnotPopMenu = pop;
  782. }
  783. /// <summary>
  784. /// 多选注释
  785. /// </summary>
  786. private void InitSelectMultiAnnotMenu()
  787. {
  788. var popMenu = new ContextMenu();
  789. PopMenu pop = new PopMenu(popMenu);
  790. var menuItem = new MenuItem();
  791. menuItem.Name = "MultiCopy";
  792. menuItem.Header = "复制";
  793. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  794. menuItem = new MenuItem();
  795. menuItem.Name = "MultiCut";
  796. menuItem.Header = "剪切";
  797. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  798. menuItem = new MenuItem();
  799. menuItem.Name = "MultiDelete";
  800. menuItem.Header = "删除";
  801. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  802. MultiAnnotPopMenu = pop;
  803. }
  804. #endregion 注释-右键菜单
  805. }
  806. }