AnnotToolContentViewModel.Layout.cs 34 KB

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