123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using Microsoft.Office.Interop.Word;
- using Microsoft.Win32;
- using PDF_Office.CustomControl;
- using PDF_Office.EventAggregators;
- using PDF_Office.Helper;
- using PDF_Office.Model;
- using PDF_Office.Properties;
- using PDF_Office.ViewModels.BOTA;
- using PDF_Office.ViewModels.PropertyPanel;
- using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
- using PDF_Office.Views.BOTA;
- using PDF_Office.Views.PropertyPanel.AnnotPanel;
- using PDFSettings;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace PDF_Office.ViewModels.Tools
- {
- public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
- {
- private IEventAggregator events;
- private bool btnSelecttoolIsChecked = false;
- public bool BtnSelecttoolIsChecked
- {
- get { return btnSelecttoolIsChecked; }
- set
- {
- SetProperty(ref btnSelecttoolIsChecked, value);
- }
- }
- private bool btnLinkIsChecked = false;
- public bool BtnLinkIsChecked
- {
- get { return btnLinkIsChecked; }
- set
- {
- SetProperty(ref btnLinkIsChecked, value);
- }
- }
- private SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
- public SnapshotEditMenuViewModel SnapshotEditMenuViewModel { get => snapshotEditMenuViewModel; set => snapshotEditMenuViewModel = value; }
- public DelegateCommand<object> SetAddAnnotationCommand { get; set; }
- public AnnotToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
- {
- region = regionManager;
- events = eventAggregator;
- MyToolsCommand = new DelegateCommand<CustomIconToggleBtn>(BtnMyTools_Click);
- SetAddAnnotationCommand = new DelegateCommand<object>(AddAnnotation_Click);
- PropertyRegionName = Guid.NewGuid().ToString();
- BindingEvent();
- InitDefaultValue();
- }
- private Dictionary<string, bool> ToolExpandDict = new Dictionary<string, bool>();
- public void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
- {
- //不创建注释,属于注释模板
- bool isTemplateAnnot = false;
- bool isSnapshotEdit = false;
- AnnotHandlerEventArgs annotArgs = null;
- if (annotBtn.IsChecked == true)
- {
- switch (annotBtn.Tag.ToString())
- {
- case "SnapshotEdit"://内容选择
- annotArgs = GetSnapshotEdit(annotBtn);
- isSnapshotEdit = true;
- break;
- case "HighLight"://字体高亮
- annotArgs = GetHighLight();
- break;
- case "UnderLine"://下划线
- annotArgs = GetUnderLine();
- break;
- case "Squiggly"://波浪线
- annotArgs = GetSquiggly();
- break;
- case "Strikeout"://删除线
- annotArgs = GetStrikeout();
- break;
- case "Freehand"://手绘
- annotArgs = GetFreehand();
- break;
- case "Freetext"://文本
- annotArgs = GetFreetext();
- break;
- case "StickyNote"://便签
- annotArgs = GetStickyNote();
- break;
- case "Rect"://矩形
- annotArgs = GetRect();
- break;
- case "Circle"://圆
- annotArgs = GetCircle();
- break;
- case "Arrow"://箭头
- case "Line"://线
- annotArgs = GetArrowLine(annotBtn.Tag.ToString());
- break;
- case "Stamp"://图章
- annotArgs = GetStamp();
- isTemplateAnnot = true;
- break;
- case "Image":
- annotArgs = GetImage(annotBtn);
- break;
- case "Signature"://签名
- annotArgs = GetSignature();
- isTemplateAnnot = true;
- PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
- break;
- case "Link"://链接
- viewContentViewModel.IsCreateLink = false;
- annotArgs = GetLink();
- break;
- }
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- }
- }
- //当不是注释模板,且无创建注释时,属性面板显示为空内容
- if (isTemplateAnnot == false && annotArgs == null)
- {
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- if (isSnapshotEdit == true)
- {
- ShowPropertyPanel(false);
- isSnapshotEdit = false;
- }
- else
- {
- ShowPropertyPanel((bool)annotBtn.IsChecked);
- }
- }
- private void AnnotProperty_DefaultStored(object sender, object e)
- {
- }
- private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
- {
- if (e != null)
- {
- AnnotHandlerEventArgs annotArgs = null;
- foreach (AnnotArgsType argsType in e.Keys)
- {
- switch (argsType)
- {
- case AnnotArgsType.AnnotSquare:
- annotArgs = GetRect();
- break;
- case AnnotArgsType.AnnotCircle:
- annotArgs = GetCircle();
- break;
- case AnnotArgsType.AnnotLine:
- var LineTag = e[argsType] as string;
- annotArgs = GetArrowLine(LineTag);
- break;
- }
- if (annotArgs != null)
- {
- annotArgs.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotArgs);
- }
- ShowPropertyPanel();
- }
- }
- }
- private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
- {
- if (e != null)
- {
- foreach (AnnotArgsType argsType in e.Keys)
- {
- switch (argsType)
- {
- case AnnotArgsType.AnnotHighlight:
- if (e[argsType] is Color)
- {
- HighLightColor = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- HighLightOpacity = (double)e[argsType];
- }
- break;
- case AnnotArgsType.AnnotUnderline:
- if (e[argsType] is Color)
- {
- UnderLineColor = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- underLineOpacity = (double)e[argsType];
- }
- break;
- case AnnotArgsType.AnnotSquiggly:
- if (e[argsType] is Color)
- {
- SquigglyColor = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- SquigglyOpacity = (double)e[argsType];
- }
- break;
- case AnnotArgsType.AnnotStrikeout:
- if (e[argsType] is Color)
- {
- StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- StrikeoutOpacity = (double)e[argsType];
- }
- break;
- case AnnotArgsType.AnnotFreehand:
- if (e[argsType] is Color)
- {
- // FreehandPath.Fill = new SolidColorBrush((Color)e[argsType]);
- }
- if (e[argsType] is double)
- {
- // FreehandPath.Opacity = (double)e[argsType];
- }
- break;
- case AnnotArgsType.AnnotErase:
- if (e[argsType] is ToggleButton)
- {
- ToggleButton clickBtn = e[argsType] as ToggleButton;
- //PDFViewerCtrl viewCtrl = GetCurrentViewer();
- // ClearSelectedToolPanel(BtnFreeHand);
- // if (viewCtrl != null && viewCtrl.PdfViewer != null)
- {
- if (clickBtn.IsChecked == true)
- {
- if (clickBtn.Tag.ToString() == "PenBtn")
- {
- CustomIconToggleBtn btn = new CustomIconToggleBtn();
- btn.Tag = "Freehand"; btn.IsChecked = true;
- BtnMyTools_Click(btn);
- break;
- }
- EraseArgs eraseArgs = new EraseArgs();
- eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
- eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
- eraseArgs.Thickness = 10;
- DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
- if (annotProperty != null)
- {
- eraseArgs.Thickness = annotProperty.Thickness;
- }
- PDFViewer.ClearSelectAnnots(false);
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(eraseArgs);
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor;
- annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor;
- annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness;
- AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgs, annotAttribsList);
- //清空选中注释
- //viewCtrl.PdfViewer.ClearSelectAnnots(false);
- //viewCtrl.PdfViewer.SetMouseMode(MouseModes.AnnotCreate);
- //viewCtrl.PdfViewer.SetToolParam(eraseArgs);
- //if (viewCtrl.PropPanel.Children.Count > 0)
- //{
- // FreehandAnnotProperty freehandPropPanel = viewCtrl.PropPanel.Children[0] as FreehandAnnotProperty;
- // if (freehandPropPanel == null)
- // {
- // viewCtrl.PropPanel.Children.Clear();
- // freehandPropPanel = new FreehandAnnotProperty();
- // freehandPropPanel.EraseSet = true;
- // freehandPropPanel.SetInkThickness(eraseArgs.Thickness);
- // freehandPropPanel.DataChanged += AnnotPropertyPanel_DataChanged;
- // viewCtrl.PropPanel.Children.Add(freehandPropPanel);
- // }
- // Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- // annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor;
- // annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor;
- // annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness;
- // freehandPropPanel.AnnotEvent = null;
- // freehandPropPanel.SetEraseMode(true);
- // freehandPropPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(eraseArgs, annotAttribsList);
- //}
- //else
- //{
- // FreehandAnnotProperty freehandProperty = new FreehandAnnotProperty();
- // freehandProperty.DataChanged += AnnotPropertyPanel_DataChanged;
- // Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- // annotAttribsList[AnnotAttrib.Color] = eraseArgs.UIBorderColor;
- // annotAttribsList[AnnotAttrib.FillColor] = eraseArgs.UIFillColor;
- // annotAttribsList[AnnotAttrib.Thickness] = eraseArgs.Thickness;
- // freehandProperty.SetInkThickness(eraseArgs.Thickness);
- // freehandProperty.EraseSet = true;
- // freehandProperty.SetEraseMode(true);
- // freehandProperty.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(eraseArgs, annotAttribsList);
- // viewCtrl.AddAnnotPropertyPanel(freehandProperty);
- //}
- }
- else
- {
- // BtnFreeHand.IsChecked = true;
- // BtnTool_Click(BtnFreeHand, new RoutedEventArgs());
- }
- }
- }
- break;
- }
- }
- }
- }
- public IRegionManager region;
- public string PropertyRegionName { get; set; }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
- // navigationContext.Parameters.TryGetValue<PropertyPanelContentViewModel>(ParameterNames.PropertyPanelContentViewModel, out propertyPanelContentViewModel);
- if (PDFViewer != null)
- {
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
- PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
- PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
- PDFViewer.WidgetClickHander += PDFViewer_WidgetClickHander;
- PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
- PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
- }
- }
- private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
- {
- SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
- SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
- SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
- SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent; ;
- var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
- if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
- {
- e.PopupMenu = popMenu;
- e.Handle = true;
- if (popMenu != null && popMenu.Items.Count == 5)
- {
- //复制
- MenuItem menuItem = popMenu.Items[0] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
- //导出
- menuItem = popMenu.Items[1] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- if (menuItem.Items.Count == 3)
- {
- MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
- menuItem1.CommandTarget = PDFViewer;
- menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
- menuItem1 = menuItem.Items[1] as MenuItem;
- menuItem1.CommandTarget = PDFViewer;
- menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
- menuItem1 = menuItem.Items[2] as MenuItem;
- menuItem1.CommandTarget = PDFViewer;
- menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
- }
- //裁剪
- menuItem = popMenu.Items[2] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
- //缩放至所选区域
- menuItem = popMenu.Items[3] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- menuItem.Visibility = Visibility.Collapsed;
- //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
- //打印
- menuItem = popMenu.Items[4] as MenuItem;
- menuItem.CommandTarget = PDFViewer;
- menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
- }
- }
- }
- private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
- {
- switch (e.Key)
- {
- case "CloseSnap":
- {
- #region to do
- //var item = PDFViewerTab.SelectedItem as TabItem;
- //if (item == null)
- //{
- // ClearSelectedToolPanel();
- // return;
- //}
- //Grid grid = item.Content as Grid;
- //if (grid == null || grid.Children.Count == 0)
- //{
- // ClearSelectedToolPanel();
- // return;
- //}
- //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
- //if (pdfViewer == null)
- //{
- // ClearSelectedToolPanel();
- // return;
- //}
- #endregion to do
- switch (PDFViewer.MouseMode)
- {
- case MouseModes.SelectTextTool:
- break;
- default:
- BtnSelecttoolIsChecked = false;
- break;
- }
- }
- break;
- default:
- break;
- }
- }
- private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e)
- {
- }
- private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- {
- if (e != null && e.Count > 0)
- {
- for (int i = 0; i < e.Count; i++)
- {
- AnnotEditEvent editEvent = e[i];
- switch (editEvent.EditAction)
- {
- case ActionType.Add:
- BOTAContentViewModel bOTAContentViewModel = null;
- bool isTabItemAnnotation = IsTabItemAnnotationShow(out bOTAContentViewModel);
- if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- if (viewModel != null)
- {
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewModel.UpdateAddedAnnot(pageindex, annotindex);
- }
- }
- break;
- case ActionType.Del:
- isTabItemAnnotation = IsTabItemAnnotationShow(out bOTAContentViewModel);
- if (isTabItemAnnotation)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- if (viewModel != null)
- {
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
- }
- }
- break;
- case ActionType.Modify:
- isTabItemAnnotation = IsTabItemAnnotationShow(out bOTAContentViewModel);
- if (isTabItemAnnotation)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
- if (viewModel != null)
- {
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
- }
- }
- break;
- case ActionType.TextEdit:
- break;
- default:
- break;
- }
- }
- }
- }
- private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel)
- {
- AnnotationContentViewModel viewModel = null;
- if (bOTAContentViewModel != null)
- {
- if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
- {
- var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
- foreach (var item in views)
- {
- if (item is AnnotationContent annotation)
- {
- viewModel = annotation.DataContext as AnnotationContentViewModel;
- break;
- }
- }
- }
- }
- return viewModel;
- }
- private bool IsTabItemAnnotationShow(out BOTAContentViewModel bOTAContentViewModel)
- {
- bool isTabItemAnnotation = false;
- bOTAContentViewModel = null;
- if (region.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
- {
- var views = region.Regions[viewContentViewModel.BOTARegionName].Views;
- foreach (var item in views)
- {
- if (item is BOTAContent bOTAContent)
- {
- bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
- if (bOTAContentViewModel.CurrentBar == "TabItemAnnotation")
- {
- isTabItemAnnotation = true;
- break;
- }
- }
- }
- }
- return isTabItemAnnotation;
- }
- private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
- {
- if (e != null)
- {
- var annot = e.AnnotItemsList[0];
- if (annot != null)
- {
- if (e.AnnotItemsList.Count == 1 && e.IsAnnotCreateReset == false)
- {
- switch (annot.EventType)
- {
- case AnnotArgsType.AnnotHighlight:
- e.IsAnnotCreateReset = false;
- GetHighLight(annot as TextHighlightAnnotArgs);
- break;
- case AnnotArgsType.AnnotUnderline:
- GetUnderLine(annot as TextUnderlineAnnotArgs);
- break;
- case AnnotArgsType.AnnotStrikeout:
- GetStrikeout(annot as TextStrikeoutAnnotArgs);
- break;
- case AnnotArgsType.AnnotSquiggly:
- GetSquiggly(annot as TextSquigglyAnnotArgs);
- break;
- case AnnotArgsType.AnnotFreehand:
- GetFreehand(annot as FreehandAnnotArgs);
- break;
- case AnnotArgsType.AnnotFreeText:
- GetFreetext(annot as FreeTextAnnotArgs);
- break;
- case AnnotArgsType.AnnotSquare:
- GetRect(annot as SquareAnnotArgs);
- break;
- case AnnotArgsType.AnnotCircle:
- GetCircle(annot as CircleAnnotArgs);
- break;
- case AnnotArgsType.AnnotLine:
- bool isLine = true;
- if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
- {
- if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_NONE)
- {
- isLine = false;
- }
- }
- if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
- {
- if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_NONE)
- {
- isLine = false;
- }
- }
- if (isLine)
- GetArrowLine("Line", annot as LineAnnotArgs);
- else
- GetArrowLine("Arrow", annot as LineAnnotArgs);
- break;
- case AnnotArgsType.AnnotLink:
- viewContentViewModel.IsCreateLink = false;
- GetLink(annot as LinkAnnotArgs, e);
- break;
- case AnnotArgsType.AnnotSticky:
- GetStickyNote(annot as StickyAnnotArgs);
- break;
- }
- ShowPropertyPanel();
- }
- else if (e.AnnotItemsList.Count == 1 && e.IsAnnotCreateReset == true)
- {
- switch (annot.EventType)
- {
- case AnnotArgsType.AnnotLink:
- viewContentViewModel.IsCreateLink = false;
- GetLink(annot as LinkAnnotArgs, e);
- break;
- //case AnnotArgsType.AnnotStamp://图章
- // GetStamp();
- // break;
- //case AnnotArgsType.AnnotStamp://签名
- // annotArgs = GetSignature();
- // isTemplateAnnot = true;
- // break;
- }
- ShowPropertyPanel();
- }
- }
- }
- else
- {
- // PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- // viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- }
- private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
- {
- if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
- return;
-
- // var annotlist = e.AnnotEventArgsList;
- switch (e.CommandType)
- {
- case CommandType.Context:
- if (e.AnnotEventArgsList.Count > 0)
- {
- if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
- {
- //绑定标记密文处右键菜单
- events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
- }
- else
- {
- e.PopupMenu = SelectAnnotContextMenu(sender);
- }
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- if (e.PressOnSelectedText)
- {
- e.PopupMenu = NoneSelectAnnotContextMenu(sender, e);
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- e.PopupMenu = ViewerContextMenu();
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- }
- break;
- }
- }
- private ContextMenu ViewerContextMenu()
- {
- ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
- contextMenu.Loaded += ContextMenu_Loaded;
- return contextMenu;
- }
- private void ContextMenu_Loaded(object sender, RoutedEventArgs e)
- {
- ContextMenu contextMenu = sender as ContextMenu;
- if (contextMenu.Items.Count > 0)
- {
- //粘贴
- MenuItem menuItem = contextMenu.Items[0] as MenuItem;
- if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
- {
- menuItem.IsEnabled = false;
- menuItem.Opacity = 0.5;
- }
- else
- {
- menuItem.IsEnabled = true;
- menuItem.Opacity = 1;
- }
- //添加注释 >
- MenuItem menuItem1 = contextMenu.Items[2] as MenuItem;
- if (menuItem1.Items.Count > 0)
- {
- SetAddAnnotation(menuItem1.Items);
- }
- //隐藏注释 >
- MenuItem menuItem2 = contextMenu.Items[3] as MenuItem;
- //显示注释 >
- MenuItem menuItem3 = contextMenu.Items[4] as MenuItem;
- if (menuItem2.Visibility == Visibility.Visible)
- {
- menuItem3.Visibility = Visibility.Collapsed;
- }
- else
- {
- menuItem3.Visibility = Visibility.Visible;
- }
- //添加书签 >
- MenuItem menuItem4 = contextMenu.Items[5] as MenuItem;
- //删除书签 >
- MenuItem menuItem5 = contextMenu.Items[6] as MenuItem;
- if (menuItem4.Visibility == Visibility.Visible)
- {
- menuItem5.Visibility = Visibility.Collapsed;
- }
- else
- {
- menuItem5.Visibility = Visibility.Visible;
- }
- //工具模式 >
- MenuItem menuItem6 = contextMenu.Items[8] as MenuItem;
- //进入阅读模式 >
- MenuItem menuItem7 = contextMenu.Items[9] as MenuItem;
- //退出阅读模式 >
- MenuItem menuItem8 = contextMenu.Items[10] as MenuItem;
- if (App.IsBookMode)
- {
- menuItem7.Visibility = Visibility.Visible;
- }
- else
- {
- menuItem7.Visibility = Visibility.Collapsed;
- }
- if (menuItem7.Visibility == Visibility.Visible)
- {
- menuItem8.Visibility = Visibility.Collapsed;
- }
- else
- {
- menuItem8.Visibility = Visibility.Visible;
- }
- //视图缩放 >
- MenuItem menuItem9 = contextMenu.Items[12] as MenuItem;
- //页面显示 >
- MenuItem menuItem10 = contextMenu.Items[13] as MenuItem;
- //查找
- MenuItem menuItem11 = contextMenu.Items[15] as MenuItem;
- //打印...
- MenuItem menuItem12 = contextMenu.Items[16] as MenuItem;
- }
- }
- private void SetAddAnnotation(ItemCollection items)
- {
- foreach (var item in items)
- {
- if (item is MenuItem menuItem)
- {
- menuItem.CommandParameter = item;
- menuItem.Command = SetAddAnnotationCommand;
- }
- }
- }
- /// <summary>
- /// 右键菜单-添加注释
- /// </summary>
- /// <param name="sender"></param>
- private void AddAnnotation_Click(object sender)
- {
- if (sender is MenuItem menuItem)
- {
- AnnotHandlerEventArgs annotHandler = null;
- string str = menuItem.Tag.ToString();
- if (str == AddAnnotType.AnnotFreehand.ToString())
- {
- annotHandler = GetFreehand();
- }
- if (str == AddAnnotType.AnnotFreeText.ToString())
- {
- annotHandler = GetFreetext();
- }
- if (str == AddAnnotType.AnnotSticky.ToString())
- {
- annotHandler = GetStickyNote();
- }
- if (str == AddAnnotType.AnnotSquare.ToString())
- {
- annotHandler = GetRect();
- }
- if (str == AddAnnotType.AnnotCircle.ToString())
- {
- annotHandler = GetCircle();
- }
- if (str == AddAnnotType.AnnotArrow.ToString())
- {
- annotHandler = GetArrowLine("Arrow");
- }
- if (str == AddAnnotType.AnnotLine.ToString())
- {
- annotHandler = GetArrowLine("Line");
- }
- if (str == AddAnnotType.AnnotLink.ToString())
- {
- annotHandler = GetLink();
- }
- if (str == AddAnnotType.AnnotStamp.ToString())
- {
- annotHandler = GetStamp();
- }
- if (str == AddAnnotType.AnnotAutograph.ToString())
- {
- annotHandler = GetSignature();
- }
- if (annotHandler != null)
- {
- annotHandler.Author = Settings.Default.AppProperties.Description.Author;
- PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
- PDFViewer.SetToolParam(annotHandler);
- ShowPropertyPanel(true);
- }
- }
- }
- private ContextMenu SelectAnnotContextMenu(object sender)
- {
- var popMenu = App.Current.FindResource("SelectAnnotContextMenu") as ContextMenu;
- if (popMenu != null && popMenu.Items.Count == 4)
- {
- //剪切
- MenuItem menuItem = popMenu.Items[0] as MenuItem;
- menuItem.CommandTarget = (UIElement)sender;
- menuItem.Command = ApplicationCommands.Cut;
- //复制
- menuItem = popMenu.Items[1] as MenuItem;
- menuItem.CommandTarget = (UIElement)sender;
- menuItem.Command = ApplicationCommands.Copy;
- //删除
- menuItem = popMenu.Items[2] as MenuItem;
- menuItem.CommandTarget = (UIElement)sender;
- menuItem.Command = ApplicationCommands.Delete;
- //笔记
- //menuItem = popMenu.Items[2] as MenuItem;
- //menuItem.CommandTarget = (UIElement)sender;
- //menuItem.Command = ApplicationCommands.no;
- }
- return popMenu;
- }
- private ContextMenu NoneSelectAnnotContextMenu(object sender, AnnotCommandArgs annotCommand)
- {
- var popMenu = new ContextMenu();
- MenuItem menuItem = new MenuItem();
- menuItem.CommandTarget = (UIElement)sender;
- menuItem.Command = ApplicationCommands.Paste;
- popMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.CommandTarget = (UIElement)sender;
- menuItem.Command = ApplicationCommands.Copy;
- popMenu.Items.Add(menuItem);
- menuItem = new MenuItem();
- menuItem.CommandTarget = (UIElement)sender;
- menuItem.Header = "创建链接";
- menuItem.CommandParameter = new object[] { this, annotCommand };
- menuItem.Command = viewContentViewModel.CreateLinkCommand;
- menuItem.Click += MenuItem_Click;
- popMenu.Items.Add(menuItem);
- return popMenu;
- }
- private void MenuItem_Click(object sender, RoutedEventArgs e)
- {
- var args = PDFViewer.ToolManager.CurrentAnnotArgs;
- BtnLinkIsChecked = true;
- }
- /// <summary>
- /// 展开显示属性面板
- /// </summary>
- private void ShowPropertyPanel(bool show = true)
- {
- viewContentViewModel.IsPropertyOpen = show;
- }
- }
- }
|