AnnotToolContentViewModel.Layout.cs 36 KB

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