AnnotToolContentViewModel.Layout.cs 39 KB

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