using ComPDFKit.PDFDocument; using ComPDFKitViewer; using ComPDFKitViewer.AnnotEvent; using ComPDFKitViewer.PdfViewer; using PDF_Master.CustomControl; using PDF_Master.CustomControl.CompositeControl; using PDF_Master.Helper; using PDF_Master.Model; using PDF_Master.Model.PropertyPanel.AnnotPanel; using PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs; using PDF_Master.Views.Dialog.ChatGPTAIDialogs; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using WIA; using static Dropbox.Api.TeamLog.AdminAlertSeverityEnum; using MenuItem = System.Windows.Controls.MenuItem; namespace PDF_Master.ViewModels.Tools { //文件说明:与布局相关的代码逻辑:菜单、属性面板 public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware { #region 属性面板 /// /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线 /// /// 对应的注释面板 /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线 /// 注释 /// 更改注释属性的键值对,更改值后会自动记录undoRedo容器里 private void AddToPropertyPanel(string viewContent, string toolTag = null, List annots = null, AnnotAttribEvent annotAttribEvent = null) { if (annots != null) { PropertyPanel.annotlists = annots; PropertyPanel.annot = annots[0]; } else { PropertyPanel.annotlists = null; PropertyPanel.annot = null; } PropertyPanel.AnnotEvents = null; PropertyPanel.AnnotEvent = null; if (annots != null) { if (annots.Count > 1) { if (PropertyPanel.AnnotEvents == null) { PropertyPanel.AnnotEvents = new List(); } PropertyPanel.AnnotEvents.Clear(); foreach (var itemAnnot in annots) { var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, itemAnnot.GetAnnotAttrib(), PDFViewer); //eventitem.ClearChangeAttribute(); PropertyPanel.AnnotEvents.Add(eventitem); } } PropertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annots[0].GetAnnotAttrib(), PDFViewer); //propertyPanel.AnnotEvent.ClearChangeAttribute(); if (annots[0] is LinkAnnotArgs && annotAttribEvent != null) { PropertyPanel.AnnotEvent = annotAttribEvent; } } PropertyPanel.SetIsTextFill(false); if (string.IsNullOrEmpty(viewContent) == false) { ViewContentViewModel.SelectedPrpoertyPanel(viewContent, PropertyPanel); } } /// /// 展开显示属性面板 /// private void ShowPropertyPanel(bool show = true) { ViewContentViewModel.IsPropertyOpen = show; } #endregion 属性面板 #region 阅读页 - 右键菜单 #region 右击菜单文案 /// /// 右键菜单文案 /// /// public string T_RightMenuSelectionCopy = App.MainPageLoader.GetString("ViewRightMenuSelection_Copy"); public string T_RightMenuSelectionPaste = App.MainPageLoader.GetString("ViewRightMenuSelection_Paste"); public string T_RightMenuSelectionHighlight = App.MainPageLoader.GetString("ViewRightMenuSelection_Highlight"); public string T_RightMenuSelectionUnderline = App.MainPageLoader.GetString("ViewRightMenuSelection_Underline"); public string T_RightMenuSelectionStrikethrough = App.MainPageLoader.GetString("ViewRightMenuSelection_Strikethrough"); public string T_RightMenuSelectionText = App.MainPageLoader.GetString("ViewRightMenuSelection_Text"); public string T_RightMenuSelectionNote = App.MainPageLoader.GetString("ViewRightMenuSelection_Note"); public string T_RightMenuSelectionRectangle = App.MainPageLoader.GetString("ViewRightMenuSelection_Rectangle"); public string T_RightMenuSelectionOval = App.MainPageLoader.GetString("ViewRightMenuSelection_Oval"); public string T_RightMenuSelectionStraightLine = App.MainPageLoader.GetString("ViewRightMenuSelection_StraightLine"); public string T_RightMenuSelectionAddLink = App.MainPageLoader.GetString("ViewRightMenuSelection_AddLink"); public string T_RightMenuSelectionAddOutline = App.MainPageLoader.GetString("ViewRightMenuSelection_AddOutline"); public string T_RightMenuSelectionExtractImage = App.MainPageLoader.GetString("ViewRightMenuSelection_ExtractImage"); #endregion 右击菜单文案 private ContextMenu ViewerContextMenu(object sender) { //ContextMenu contextMenu = CommonHelper.DeepClone(App.Current.FindResource("ViewerContextMenu") as ContextMenu); string xaml = XamlWriter.Save(App.Current.FindResource("ViewerContextMenu") as ContextMenu); ContextMenu contextMenu = XamlReader.Parse(xaml) as ContextMenu; //contextMenu.Loaded += ContextMenu_Loaded; ViewerContextMenu_Loaded(contextMenu, sender); return contextMenu; } private void ViewerContextMenu_Loaded(object sender, object e) { ContextMenu contextMenu = sender as ContextMenu; contextMenu.DataContext = ViewContentViewModel; if (contextMenu.Items.Count > 0) { int index = PDFViewer.CurrentIndex; //检测是否已存在相同数据 CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index); if (list != null) { isAddBookMark = false; } else { isAddBookMark = true; } var separator = contextMenu.Items[contextMenu.Items.Count - 3]; InBookModeSetIsHidden(separator); foreach (var item in contextMenu.Items) { if (item is MenuItem menuItem1) { switch (menuItem1.Tag.ToString()) { case "Paste": Separator separator1 = (Separator)contextMenu.Items[1]; //粘贴 if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)e)) { //menuItem1.IsEnabled = false; //menuItem1.Opacity = 0.5; menuItem1.Visibility = Visibility.Collapsed; separator1.Visibility = Visibility.Collapsed; } else { //menuItem1.IsEnabled = true; //menuItem1.Opacity = 1; menuItem1.Visibility = Visibility.Visible; separator1.Visibility = Visibility.Visible; } menuItem1.CommandTarget = (UIElement)e; menuItem1.Command = ApplicationCommands.Paste; break; case "AddAnnotation": if (menuItem1.Items.Count > 0) { SetAddAnnotation(menuItem1.Items); } break; case "HiddenAnnot": menuItem1.Click -= HiddenAnnot_Click; menuItem1.Click += HiddenAnnot_Click; SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", BtnShowAnnotIsChecked); break; case "DisplayAnnot": menuItem1.Click -= DisplayAnnot_Click; menuItem1.Click += DisplayAnnot_Click; SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", BtnShowAnnotIsChecked); break; case "AddBookMark": menuItem1.Command = AddBookMarkCommand; SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark); break; case "DelBookMark": menuItem1.Click -= DelBookMark_Click; menuItem1.Click += DelBookMark_Click; SetMenuItemVisibility(menuItem1, "DelBookMark", "AddBookMark", isAddBookMark); break; case "ToolMode": if (menuItem1.Items.Count > 0) { SetToolMode(menuItem1.Items); } break; case "ReadModel": SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", ViewContentViewModel.mainViewModel.IsBookMode); menuItem1.Click -= ReadModel_Click; menuItem1.Click += ReadModel_Click; break; case "UnReadModel": SetMenuItemVisibility(menuItem1, "ReadModel", "UnReadModel", ViewContentViewModel.mainViewModel.IsBookMode); menuItem1.Click -= UnReadModel_Click; menuItem1.Click += UnReadModel_Click; break; case "ViewZoom": InBookModeSetIsHidden(menuItem1); if (menuItem1.Items.Count > 0) { ViewZoom(menuItem1.Items); } break; case "PageDisplay": if (menuItem1.Items.Count > 0) { PageDisplay(menuItem1.Items); } break; case "Select": InBookModeSetIsHidden(menuItem1); menuItem1.Click -= Select_Click; menuItem1.Click += Select_Click; break; case "Print": InBookModeSetIsHidden(menuItem1); menuItem1.Command = ViewContentViewModel.PrintCommand; break; case "HighlightLinks": InBookModeSetIsHidden(menuItem1); if (OpenFileInfo != null) { menuItem1.IsChecked = OpenFileInfo.ShowHighLightLink; } menuItem1.Click -= HighlightLinks_Click; menuItem1.Click += HighlightLinks_Click; break; } } } } } private void HighlightLinks_Click(object sender, RoutedEventArgs e) { if (sender is MenuItem menuItem) { //if (OpenFileInfo != null) //{ // menuItem.IsChecked = OpenFileInfo.ShowHighLightLink; //} if (menuItem.IsChecked) { PDFViewer.SetShowLink(true); } else { PDFViewer.SetShowLink(false); } if (OpenFileInfo != null) { OpenFileInfo.ShowHighLightLink = menuItem.IsChecked; } //if (menuItem.IsChecked == true) //{ // menuItem.IsChecked = false; //} } } private void SetMenuItemVisibility(MenuItem menuItem1, string right, string deny, bool flag) { if (menuItem1.Tag.ToString() == right && flag) { menuItem1.Visibility = Visibility.Collapsed; } if (menuItem1.Tag.ToString() == right && flag == false) { menuItem1.Visibility = Visibility.Visible; } if (menuItem1.Tag.ToString() == deny && flag == false) { menuItem1.Visibility = Visibility.Collapsed; } if (menuItem1.Tag.ToString() == deny && flag) { menuItem1.Visibility = Visibility.Visible; } } private void CopyMenu_Click(object sender, RoutedEventArgs e) { //限制权限密码文档的图片复制 if (!ViewContentViewModel.CheckPermissionBeforeOption()) { return; } try { Clipboard.Clear(); Dictionary> imageDict = PDFViewer?.GetSelectedImages(); if (imageDict != null && imageDict.Count > 0) { foreach (int pageIndex in imageDict.Keys) { List imageList = imageDict[pageIndex]; foreach (System.Drawing.Bitmap image in imageList) { MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); BitmapImage imageData = new BitmapImage(); imageData.BeginInit(); imageData.StreamSource = ms; imageData.CacheOption = BitmapCacheOption.OnLoad; imageData.EndInit(); imageData.Freeze(); Clipboard.SetImage(imageData); break; } } } } catch { } } /// /// 选择文本或者图像的右键菜单 /// /// /// /// private ContextMenu SelectedTextOrImageContextMenu(object sender, AnnotCommandArgs annotCommand) { StrAnnotToolChecked = ""; ContextMenu popMenu = new ContextMenu(); popMenu.FontSize = 14; MenuItem menuItem = new MenuItem(); menuItem = new MenuItem(); menuItem.CommandTarget = (UIElement)sender; menuItem.Header = T_RightMenuSelectionCopy; menuItem.InputGestureText = "Ctrl+C"; if (annotCommand.CommandTarget == TargetType.ImageSelection && PDFViewer.GetSelectImageCount() > 0) { menuItem.IsEnabled = true; PDFViewer.ClearCopyData(); menuItem.Click -= CopyMenu_Click; menuItem.Click += CopyMenu_Click; } else { menuItem.Command = ApplicationCommands.Copy; } popMenu.Items.Add(menuItem); menuItem = new MenuItem(); menuItem.Header = T_RightMenuSelectionPaste; if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender)) { //menuItem1.IsEnabled = false; //menuItem1.Opacity = 0.5; menuItem.Visibility = Visibility.Collapsed; } else { //menuItem1.IsEnabled = true; //menuItem1.Opacity = 1; menuItem.Visibility = Visibility.Visible; } menuItem.CommandTarget = (UIElement)sender; menuItem.Command = ApplicationCommands.Paste; popMenu.Items.Add(menuItem); Separator separator = null; if (annotCommand.CommandTarget == TargetType.ImageSelection) { separator = SetSeparator(); popMenu.Items.Add(separator); SetSelectTextOrImageMenuItem(T_RightMenuSelectionExtractImage, "ExportPicture", annotCommand, out menuItem); if (PDFViewer.GetSelectImageCount() > 0) { menuItem.IsEnabled = true; } popMenu.Items.Add(menuItem); } else if (annotCommand.CommandTarget == TargetType.Annot) { separator = SetSeparator(); popMenu.Items.Add(separator); SetSelectTextOrImageMenuItem(T_RightMenuSelectionHighlight, "HighLight", annotCommand, out menuItem); popMenu.Items.Add(menuItem); SetSelectTextOrImageMenuItem(T_RightMenuSelectionUnderline, "UnderLine", annotCommand, out menuItem); popMenu.Items.Add(menuItem); SetSelectTextOrImageMenuItem(T_RightMenuSelectionStrikethrough, "Strikeout", annotCommand, out menuItem); popMenu.Items.Add(menuItem); separator = SetSeparator(); //popMenu.Items.Add(separator); SetSelectTextOrImageMenuItem(T_RightMenuSelectionText, "Freetext", annotCommand, out menuItem); //popMenu.Items.Add(menuItem); SetSelectTextOrImageMenuItem(T_RightMenuSelectionNote, "StickyNote", annotCommand, out menuItem); //popMenu.Items.Add(menuItem); separator = SetSeparator(); popMenu.Items.Add(separator); SetSelectTextOrImageMenuItem(T_RightMenuSelectionRectangle, "Rect", annotCommand, out menuItem); popMenu.Items.Add(menuItem); SetSelectTextOrImageMenuItem(T_RightMenuSelectionOval, "Circle", annotCommand, out menuItem); popMenu.Items.Add(menuItem); SetSelectTextOrImageMenuItem(T_RightMenuSelectionStraightLine, "Line", annotCommand, out menuItem); //popMenu.Items.Add(menuItem); } separator = SetSeparator(); popMenu.Items.Add(separator); InBookModeSetIsHidden(separator); SetSelectTextOrImageMenuItem(T_RightMenuSelectionAddLink, "Link", annotCommand, out menuItem); popMenu.Items.Add(menuItem); if (annotCommand.CommandTarget == TargetType.Annot) { SetSelectTextOrImageMenuItem(T_RightMenuSelectionAddOutline, "OutLine", annotCommand, out menuItem); popMenu.Items.Add(menuItem); SetSelectTextOrImageMenuItem("AI Translation", "Translation", annotCommand, out menuItem); popMenu.Items.Add(menuItem); } return popMenu; } private void MenuTranslate_Click(object sender, RoutedEventArgs eventArgs) { DialogParameters printValue = new DialogParameters(); printValue.Add(ParameterNames.PDFViewer, PDFViewer); dialogs.ShowDialog(DialogNames.SelectedTranslation, printValue, e => { }); } private void SetSelectTextOrImageMenuItem(string header, string tag, AnnotCommandArgs annotCommand, out MenuItem menuItem) { menuItem = new MenuItem(); menuItem.Header = header; menuItem.Tag = tag; if (tag == "Translation") { menuItem.Click -= MenuTranslate_Click; menuItem.Click += MenuTranslate_Click; return; } if (tag == "OutLine" || tag == "Link") { InBookModeSetIsHidden(menuItem); } menuItem.Click -= AnnotToolMenu_Click; menuItem.Click += AnnotToolMenu_Click; menuItem.CommandParameter = annotCommand; } private Separator SetSeparator() { Separator separator = new Separator { Height = 1, BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#33000000")), BorderThickness = new Thickness(1), Style = (Style)App.Current.FindResource(System.Windows.Controls.ToolBar.SeparatorStyleKey) }; return separator; } #endregion 阅读页 - 右键菜单 #region 注释-右键菜单 #region 注释-右键菜单文案 //public string T_RightMenuAnnotCopy = App.MainPageLoader.GetString("ViewRightMenuSelection_Copy"); //public string T_RightMenuAnnotPaste = App.MainPageLoader.GetString("ViewRightMenuSelection_Paste"); //public string T_RightMenuAnnotHighlight = App.MainPageLoader.GetString("ViewRightMenuSelection_Highlight"); //public string T_RightMenuAnnotUnderline = App.MainPageLoader.GetString("ViewRightMenuSelection_Underline"); //public string T_RightMenuAnnotStrikethrough = App.MainPageLoader.GetString("ViewRightMenuSelection_Strikethrough"); //public string T_RightMenuAnnotText = App.MainPageLoader.GetString("ViewRightMenuSelection_Text"); //public string T_RightMenuAnnotNote = App.MainPageLoader.GetString("ViewRightMenuSelection_Note"); public string T_RightMenuAnnotCopy = App.MainPageLoader.GetString("ViewRightMenuAnnot_Copy"); public string T_RightMenuAnnotCut = App.MainPageLoader.GetString("ViewRightMenuAnnot_Cut"); public string T_RightMenuAnnotPaste = App.MainPageLoader.GetString("ViewRightMenuAnnot_Paste"); public string T_RightMenuAnnotDelete = App.MainPageLoader.GetString("ViewRightMenuAnnot_Delete"); public string T_RightMenuAnnotAddNote = App.MainPageLoader.GetString("ViewRightMenuAnnot_AddNote"); public string T_RightMenuAnnotDefault = App.MainPageLoader.GetString("ViewRightMenuAnnot_Default"); public string T_RightMenuFreehandAnnotColor = App.MainPageLoader.GetString("ViewRightMenuFreehandAnnot_Color"); public string T_RightMenuFreehandAnnotLineStyle = App.MainPageLoader.GetString("ViewRightMenuFreehandAnnot_LineStyle"); public string T_RightMenuFreehandAnnotLineStyleSolid = App.MainPageLoader.GetString("ViewRightMenuFreehandAnnotLineStyle_SolidLine"); public string T_RightMenuFreehandAnnotLineStyleDotted = App.MainPageLoader.GetString("ViewRightMenuFreehandAnnotLineStyle_DottedLine"); public string T_RightMenuFreetextAnnotFontColor = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_FontColor"); public string T_RightMenuFreetextAnnotFillColor = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_FillColor"); public string T_RightMenuFreetextAnnotFont = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_Font"); public string T_RightMenuFreetextAnnotFontCourierNew = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_CourierNew"); public string T_RightMenuFreetextAnnotFontHelvetica = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_Helvetica"); public string T_RightMenuFreetextAnnotFontTimesNewRoman = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_TimesNewRoman"); public string T_RightMenuFreetextAnnotTextAlignment = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_TextAlignment"); public string T_RightMenuFreetextAnnotTextAlignmentAlignLeft = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignLeft"); public string T_RightMenuFreetextAnnotTextAlignmentAlignCenter = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignCenter"); public string T_RightMenuFreetextAnnotTextAlignmentAlignRight = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignRight"); public string T_RightMenuFreetextAnnotTextAlignmentFullyJustified = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_FullyJustified"); public string T_RightMenuStickyNoteAnnotColor = App.MainPageLoader.GetString("ViewRightMenuStickyNoteAnnot_Color"); public string T_RightMenuStickyNoteAnnotEdit = App.MainPageLoader.GetString("ViewRightMenuStickyNoteAnnot_Edit"); public string T_RightMenuSharpsNoteAnnotColor = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnot_Color"); public string T_RightMenuSharpsNoteAnnotLineStyleSolidline = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnotLineStyle_SolidLine"); public string T_RightMenuSharpsNoteAnnotLineStyleDottedLine = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnotLineStyle_DottedLine"); public string T_RightMenuSharpsNoteAnnotLineStyle = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnot_LineStyle"); public string T_RightMenuSharpsNoteAnnotDirection = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnot_Direction"); public string T_RightMenuSharpsNoteAnnotDirectionVertical = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnotDirection_Vertical"); public string T_RightMenuSharpsNoteAnnotDirectionHorizontal = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnotDirection_Horizontal"); public string T_RightMenuSharpsNoteAnnotBorderColor = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnot_BorderColor"); public string T_RightMenuSharpsNoteAnnotFillColor = App.MainPageLoader.GetString("ViewRightMenuSharpsAnnot_FillColor"); public string T_RightMenuStampNoteAnnotExport = App.MainPageLoader.GetString("ViewRightMenuStampAnnot_Export"); public string T_RightMenuStampNoteAnnotExportPNG = App.MainPageLoader.GetString("ViewRightMenuStampAnnotExport_PNG"); public string T_RightMenuStampNoteAnnotExportPDF = App.MainPageLoader.GetString("ViewRightMenuStampAnnotExport_PDF"); public string T_RightMenuTextNoteAnnotCopyText = App.MainPageLoader.GetString("ViewRightMenuTextAnnot_CopyText"); public string T_RightMenuTextNoteAnnotDelete = App.MainPageLoader.GetString("ViewRightMenuTextAnnot_Delete"); #endregion 注释-右键菜单文案 private ColorMenuItem colorContent; /// /// 高亮注释,右键菜单 /// /// private void InitSelectHightAnnotMenu() { var popMenu = new ContextMenu(); PopMenu pop = new PopMenu(popMenu); colorContent = new ColorMenuItem(); colorContent.Name = "hightcolor"; colorContent.ColorChanged -= colorContent_SelectedColorHandler; colorContent.ColorChanged += colorContent_SelectedColorHandler; colorContent.VerticalAlignment = VerticalAlignment.Top; colorContent.Margin = new Thickness(0, 0, 0, -15); var menuItem = new MenuItem(); menuItem.Name = "hightColor"; menuItem.Height = 20 + 15; menuItem.Header = colorContent; var hightColorStyle = App.Current.FindResource("UIElementMenuItem") as Style; if (hightColorStyle != null) menuItem.Style = hightColorStyle; colorContent.DataContext = pop.AddItem(menuItem); pop.AddItem(GetSeparator()); menuItem = new MenuItem(); menuItem.Name = "hightCopyText"; menuItem.Header = T_RightMenuTextNoteAnnotCopyText; pop.BindingEvent(pop.AddItem(menuItem), HightAnnotCopyText_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "hightdelete"; menuItem.Header = T_RightMenuTextNoteAnnotDelete; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete); pop.AddItem(GetSeparator()); menuItem = new MenuItem(); menuItem.Name = "hightAddNote"; menuItem.Header = T_RightMenuAnnotAddNote; pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "hightdefault"; menuItem.Header = T_RightMenuAnnotDefault; pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand); HightAnnotPopMenu = pop; } private Separator GetSeparator() { Separator separator = new Separator(); separator.Height = 1; separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00)); separator.BorderThickness = new Thickness(1); separator.Margin = new Thickness(-30, 0, 0, 0); return separator; } private async void colorContent_SelectedColorHandler(object sender, Color e) { if (e == null) return; if (sender is Ellipse) { var item = new ColorDropBoxPop(); item.DataContext = (sender as Ellipse).DataContext; item.ColorSelected -= AnnotMenu_ColorSelected; item.ColorSelected += AnnotMenu_ColorSelected; if (popup == null) popup = new System.Windows.Controls.Primitives.Popup(); ContentControl window = null; if (PDFViewer.Parent as ContentControl != null) window = PDFViewer.Parent as ContentControl; else window = App.Current.MainWindow; popup.Child = item; popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height)); popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; popup.PlacementTarget = window; popup.IsOpen = true; Window parentWnd = Window.GetWindow(App.Current.MainWindow); if (parentWnd != null) { parentWnd.MouseDown -= parentWnd_MouseDown; parentWnd.MouseDown += parentWnd_MouseDown; } while (popup.IsOpen) await Task.Delay(20); parentWnd.MouseDown -= parentWnd_MouseDown; popup = null; } else { var cusMenuItem = (sender as FrameworkElement).DataContext as CusMenuItem; if (cusMenuItem != null && cusMenuItem.Parameter != null) { if (cusMenuItem.Parameter is TextHighlightAnnotArgs textHighlightAnnotArgs) { var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textHighlightAnnotArgs, textHighlightAnnotArgs.GetAnnotAttrib(), PDFViewer); anvent.UpdateAttrib(AnnotAttrib.Color, e); anvent.UpdateAnnot(); } if (cusMenuItem.Parameter is TextUnderlineAnnotArgs textUnderlineAnnotArgs) { var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textUnderlineAnnotArgs, textUnderlineAnnotArgs.GetAnnotAttrib(), PDFViewer); anvent.UpdateAttrib(AnnotAttrib.Color, e); anvent.UpdateAnnot(); } if (cusMenuItem.Parameter is TextStrikeoutAnnotArgs textStrikeoutAnnotArgs) { var anvent = AnnotAttribEvent.GetAnnotAttribEvent(textStrikeoutAnnotArgs, textStrikeoutAnnotArgs.GetAnnotAttrib()); anvent.UpdateAttrib(AnnotAttrib.Color, e); anvent.UpdateAnnot(); } //var test = cusMenuItem.Parameter as TextHighlightAnnotArgs; //if (test != null) //{ // var anvent = AnnotAttribEvent.GetAnnotAttribEvent(test, test.GetAnnotAttrib()); // anvent.UpdateAttrib(AnnotAttrib.Color, e); // anvent.UpdateAnnot(); //} } } } /// /// 手绘 /// private void InitSelectFreeHandAnnotMenu() { var popMenu = new ContextMenu(); PopMenu pop = new PopMenu(popMenu); var menuItem = new MenuItem(); menuItem.Name = "FreeHandCopy"; menuItem.Header = T_RightMenuAnnotCopy; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy); menuItem = new MenuItem(); menuItem.Name = "FreeHandCut"; menuItem.Header = T_RightMenuAnnotCut; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut); menuItem = new MenuItem(); menuItem.Name = "FreeHandPaste"; menuItem.Header = T_RightMenuAnnotPaste; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste); menuItem = new MenuItem(); menuItem.Name = "FreeHandDelete"; menuItem.Header = T_RightMenuAnnotDelete; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete); pop.AddItem(GetSeparator()); menuItem = new MenuItem(); menuItem.Name = "FreeHandColor"; menuItem.Header = T_RightMenuFreehandAnnotColor; menuItem.Tag = "Color"; pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "FreeHandLineStyle"; menuItem.Header = T_RightMenuFreehandAnnotLineStyle; pop.AddItem(menuItem); RadioButton radioButton = new RadioButton(); radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; radioButton.Background = new SolidColorBrush(Colors.Transparent); radioButton.Name = "FreeHandSolid"; radioButton.Content = T_RightMenuFreehandAnnotLineStyleSolid; radioButton.GroupName = "LineStyle"; radioButton.Tag = "Solid"; pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand); radioButton = new RadioButton(); radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; radioButton.Background = new SolidColorBrush(Colors.Transparent); radioButton.Name = "FreeHandDash"; radioButton.Content = T_RightMenuFreehandAnnotLineStyleDotted; radioButton.GroupName = "LineStyle"; radioButton.Tag = "Dash"; pop.BindingEvent(pop.AddChild("FreeHandLineStyle", radioButton), FreeHandLineStyle_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "FreeHandAddNote"; menuItem.Header = T_RightMenuAnnotAddNote; pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "FreeHandDefault"; menuItem.Header = T_RightMenuAnnotDefault; pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand); FreeHandAnnotPopMenu = pop; } /// /// 文本 /// private void InitSelectFreeTextAnnotMenu() { var popMenu = new ContextMenu(); PopMenu pop = new PopMenu(popMenu); var menuItem = new MenuItem(); menuItem.Name = "FreeTextCopy"; menuItem.Header = T_RightMenuAnnotCopy; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy); menuItem = new MenuItem(); menuItem.Name = "FreeTextCut"; menuItem.Header = T_RightMenuAnnotCut; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut); menuItem = new MenuItem(); menuItem.Name = "FreeTextPaste"; menuItem.Header = T_RightMenuAnnotPaste; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste); menuItem = new MenuItem(); menuItem.Name = "FreeTextDelete"; menuItem.Header = T_RightMenuAnnotDelete; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete); pop.AddItem(GetSeparator()); menuItem = new MenuItem(); menuItem.Name = "FreeTextColor"; menuItem.Header = T_RightMenuFreetextAnnotFontColor; menuItem.Tag = "FontColor"; pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "FreeTextFillColor"; menuItem.Header = T_RightMenuFreetextAnnotFillColor; menuItem.Tag = "FillColor"; pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "FreeTextFontFamily"; menuItem.Header = T_RightMenuFreetextAnnotFont; pop.AddItem(menuItem); var family = TextFont.GetFamily(); foreach (var item in family) { RadioButton familyRdioBtn = new RadioButton(); familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent); familyRdioBtn.Name = item.ValueStr; familyRdioBtn.Tag = item.ValueStr; familyRdioBtn.GroupName = "FontFamily"; familyRdioBtn.Content = item.Content; pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand); } menuItem = new MenuItem(); menuItem.Name = "FreeTextAglin"; menuItem.Header = T_RightMenuFreetextAnnotTextAlignment; pop.AddItem(menuItem); var radioButton = new RadioButton(); radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; radioButton.Background = new SolidColorBrush(Colors.Transparent); radioButton.Name = "FreeTextAglinLeft"; radioButton.Tag = "Left"; radioButton.GroupName = "Aglin"; radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignLeft; pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand); radioButton = new RadioButton(); radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; radioButton.Background = new SolidColorBrush(Colors.Transparent); radioButton.Name = "FreeTextAglinCenter"; radioButton.Tag = "Center"; radioButton.GroupName = "Aglin"; radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignCenter; pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand); radioButton = new RadioButton(); radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; radioButton.Background = new SolidColorBrush(Colors.Transparent); radioButton.Name = "FreeTextAglinRight"; radioButton.Tag = "Right"; radioButton.GroupName = "Aglin"; radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignRight; pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand); radioButton = new RadioButton(); radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; radioButton.Background = new SolidColorBrush(Colors.Transparent); radioButton.Name = "FreeTextAglinJustify"; radioButton.Tag = "Justify"; radioButton.GroupName = "Aglin"; radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentFullyJustified; //pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "FreeHandDefault"; menuItem.Header = T_RightMenuAnnotDefault; pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand); FreeTextAnnotPopMenu = pop; } /// /// 便签 /// private void InitSelectStrickNoteAnnotMenu() { var popMenu = new ContextMenu(); PopMenu pop = new PopMenu(popMenu); var menuItem = new MenuItem(); menuItem.Name = "StrickNoteCopy"; menuItem.Header = T_RightMenuAnnotCopy; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy); menuItem = new MenuItem(); menuItem.Name = "StrickNoteCut"; menuItem.Header = T_RightMenuAnnotCut; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut); menuItem = new MenuItem(); menuItem.Name = "StrickNotePaste"; menuItem.Header = T_RightMenuAnnotPaste; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste); menuItem = new MenuItem(); menuItem.Name = "StrickNoteDelete"; menuItem.Header = T_RightMenuAnnotDelete; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete); pop.AddItem(GetSeparator()); menuItem = new MenuItem(); menuItem.Name = "StrickNoteColor"; menuItem.Header = T_RightMenuStickyNoteAnnotColor; pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "StrickNoteEdit"; menuItem.Header = T_RightMenuStickyNoteAnnotEdit; pop.BindingEvent(pop.AddItem(menuItem), StrikeNoteEditStrike_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "StrickNoteDefault"; menuItem.Header = T_RightMenuAnnotDefault; pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand); StrickNoteAnnotPopMenu = pop; } /// /// 形状 /// private void InitSelectShapeAnnotMenu() { var popMenu = new ContextMenu(); PopMenu pop = new PopMenu(popMenu); var menuItem = new MenuItem(); menuItem.Name = "ShapeCopy"; menuItem.Header = T_RightMenuAnnotCopy; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy); menuItem = new MenuItem(); menuItem.Name = "ShapeCut"; menuItem.Header = T_RightMenuAnnotCut; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut); menuItem = new MenuItem(); menuItem.Name = "ShapePaste"; menuItem.Header = T_RightMenuAnnotPaste; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste); menuItem = new MenuItem(); menuItem.Name = "ShapeDelete"; menuItem.Header = T_RightMenuAnnotDelete; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete); pop.AddItem(GetSeparator()); menuItem = new MenuItem(); menuItem.Name = "ShapeColor"; menuItem.Header = T_RightMenuSharpsNoteAnnotBorderColor; menuItem.Tag = "Color"; pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "ShapeFillColor"; menuItem.Header = T_RightMenuSharpsNoteAnnotFillColor; menuItem.Tag = "FillColor"; pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "ShapeLineStyle"; menuItem.Header = T_RightMenuSharpsNoteAnnotLineStyle; pop.AddItem(menuItem); RadioButton radioButton = new RadioButton(); radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; radioButton.Background = new SolidColorBrush(Colors.Transparent); radioButton.Name = "ShapeSolid"; radioButton.Content = T_RightMenuSharpsNoteAnnotLineStyleSolidline; radioButton.GroupName = "LineStyle"; radioButton.Tag = "Solid"; pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand); radioButton = new RadioButton(); radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style; radioButton.Background = new SolidColorBrush(Colors.Transparent); radioButton.Name = "ShapeDash"; radioButton.Content = T_RightMenuSharpsNoteAnnotLineStyleDottedLine; radioButton.GroupName = "LineStyle"; radioButton.Tag = "Dash"; pop.BindingEvent(pop.AddChild("ShapeLineStyle", radioButton), ShapeLineStyle_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "ShapeDirect"; menuItem.Header = T_RightMenuSharpsNoteAnnotDirection; pop.AddItem(menuItem); menuItem = new MenuItem(); menuItem.Name = "ShapeVer"; menuItem.Header = T_RightMenuSharpsNoteAnnotDirectionVertical; menuItem.Tag = "Ver"; pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "ShapeHor"; menuItem.Header = T_RightMenuSharpsNoteAnnotDirectionHorizontal; menuItem.Tag = "Hor"; pop.BindingEvent(pop.AddChild("ShapeDirect", menuItem), ShapeLineDirect_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "ShapeNoteText"; menuItem.Header = T_RightMenuAnnotAddNote; pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "ShapeDefault"; menuItem.Header = T_RightMenuAnnotDefault; pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand); ShapeAnnotPopMenu = pop; } /// /// 链接 /// private void InitSelectLinkAnnotMenu() { var popMenu = new ContextMenu(); PopMenu pop = new PopMenu(popMenu); var menuItem = new MenuItem(); menuItem.Name = "LinkCopy"; menuItem.Header = T_RightMenuAnnotCopy; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy); menuItem = new MenuItem(); menuItem.Name = "LinkCut"; menuItem.Header = T_RightMenuAnnotCut; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut); menuItem = new MenuItem(); menuItem.Name = "LinkPaste"; menuItem.Header = T_RightMenuAnnotPaste; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste); menuItem = new MenuItem(); menuItem.Name = "LinkDelete"; menuItem.Header = T_RightMenuAnnotDelete; //pop.BindingEvent(pop.AddItem(menuItem), Link_MenuCommand); pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete); LinkAnnotPopMenu = pop; } /// /// 图章、签名 /// private void InitSelectStampAnnotMenu() { var popMenu = new ContextMenu(); PopMenu pop = new PopMenu(popMenu); var menuItem = new MenuItem(); menuItem.Name = "StampCopy"; menuItem.Header = T_RightMenuAnnotCopy; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy); menuItem = new MenuItem(); menuItem.Name = "StampCut"; menuItem.Header = T_RightMenuAnnotCut; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut); menuItem = new MenuItem(); menuItem.Name = "StampPaste"; menuItem.Header = T_RightMenuAnnotPaste; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste); menuItem = new MenuItem(); menuItem.Name = "StampDelete"; menuItem.Header = T_RightMenuAnnotDelete; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete); pop.AddItem(GetSeparator()); menuItem = new MenuItem(); menuItem.Name = "StampExportPicture"; menuItem.Header = T_RightMenuStampNoteAnnotExport; pop.AddItem(menuItem); menuItem = new MenuItem(); menuItem.Name = "StampExportPNG"; menuItem.Header = T_RightMenuStampNoteAnnotExportPNG; menuItem.Tag = "PNG"; pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand); //已跟设计确认,暂时不需要JPG格式 //menuItem = new MenuItem(); //menuItem.Name = "StampExportPNG"; //menuItem.Header = "JPG"; //menuItem.Tag = "JPG"; //pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "StampExportPDF"; menuItem.Header = T_RightMenuStampNoteAnnotExportPDF; menuItem.Tag = "PDF"; pop.BindingEvent(pop.AddChild("StampExportPicture", menuItem), StampExportPicture_MenuCommand); menuItem = new MenuItem(); menuItem.Name = "StampAddNote"; menuItem.Header = T_RightMenuAnnotAddNote; pop.BindingEvent(pop.AddItem(menuItem), AnnotAddNoteText_MenuCommand); StampAnnotPopMenu = pop; } /// /// 多选注释 /// private void InitSelectMultiAnnotMenu() { var popMenu = new ContextMenu(); PopMenu pop = new PopMenu(popMenu); var menuItem = new MenuItem(); menuItem.Name = "MultiCopy"; menuItem.Header = T_RightMenuAnnotCopy; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy); menuItem = new MenuItem(); menuItem.Name = "MultiCut"; menuItem.Header = T_RightMenuAnnotCut; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut); menuItem = new MenuItem(); menuItem.Name = "MultiDelete"; menuItem.Header = T_RightMenuAnnotDelete; pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete); MultiAnnotPopMenu = pop; } #endregion 注释-右键菜单 } }