AnnotToolContentViewModel.Layout.cs 44 KB

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