1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument.Action;
- using ComPDFKit.PDFDocument;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer.PdfViewer;
- using PDF_Office.CustomControl;
- using PDF_Office.EventAggregators;
- using PDF_Office.Helper;
- using PDF_Office.Properties;
- using PDF_Office.ViewModels.BOTA;
- using PDF_Office.Views.BOTA;
- using PDFSettings;
- 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.Media;
- using System.Diagnostics;
- using PDF_Office.Model.AnnotPanel;
- using System.Windows.Input;
- using PDF_Office.ViewModels.Tools.AnnotManager;
- namespace PDF_Office.ViewModels.Tools
- {
- public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
- {
- #region 事件绑定和解绑
- private void BindingEvent()
- {
- //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
- //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
- propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
- propertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
- propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
- propertyPanel.DefaultStored += AnnotProperty_DefaultStored;
- propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
- propertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
- //快捷键
- KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
- KeyEventsHelper.KeyDown += ShortCut_KeyDown;
- }
- private void UnBindingEvent()
- {
- propertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
- propertyPanel.DefaultStored -= AnnotProperty_DefaultStored;
- propertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
- //快捷盘解绑
- KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
- }
- private void BindingPDFViewerHandler()
- {
- //来自PDFViewer的响应事件
- 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;
- PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
- PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
- PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
- PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
- PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
- PDFViewer.PreviewMouseLeftButtonDown += PDFViewer_PreviewMouseLeftButtonDown;
- }
- }
- private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
- {
- if (action == null)
- {
- return;
- }
- switch (action.ActionType)
- {
- case C_ACTION_TYPE.ACTION_TYPE_GOTO:
- if (PDFViewer != null)
- {
- CPDFGoToAction gotoAction = action as CPDFGoToAction;
- CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
- if (dest != null)
- {
- PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
- }
- }
- break;
- case C_ACTION_TYPE.ACTION_TYPE_URI:
- {
- CPDFUriAction uriAction = action as CPDFUriAction;
- string uri = uriAction.GetUri();
- try
- {
- if (!string.IsNullOrEmpty(uri))
- {
- Process.Start(uri);
- }
- }
- catch (Exception ex)
- {
- }
- }
- break;
- }
- }
- private void UnBindingPDFViewerHandler()
- {
- if (PDFViewer != null)
- {
- PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
- PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
- PDFViewer.WidgetClickHander -= PDFViewer_WidgetClickHander;
- PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
- PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
- PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
- PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
- }
- }
- #endregion 事件绑定和解绑
- #region 与触发事件调用相关的函数
- //鼠标左键双击注释
- private void PDFViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (e.ClickCount == 2)
- {
- if (CurrentSelectedAnnot != null)
- {
- var type = CurrentSelectedAnnot.EventType;
- if (type != AnnotArgsType.AnnotSticky && type != AnnotArgsType.AnnotFreeText &&
- type != AnnotArgsType.AnnotHighlight && type != AnnotArgsType.AnnotUnderline && type != AnnotArgsType.AnnotStrikeout)
- {
- var rect = CurrentSelectedAnnot.ClientRect;
- var ui = PDFViewer.Parent as ContentControl;
- if (ui != null)
- {
- var point = e.GetPosition(ui);
- if (rect.Left < point.X && rect.Top < point.Y && (rect.Width + rect.X) >= point.X && (rect.Height + rect.Y) >= point.Y)
- {
- PopAnnotNoteText(CurrentSelectedAnnot);
- }
- }
- }
-
- }
-
- }
- }
- //是否为形状注释
- private bool isShapAnnot(AnnotHandlerEventArgs annot)
- {
- if (annot.EventType == AnnotArgsType.AnnotCircle ||
- annot.EventType == AnnotArgsType.AnnotSquare ||
- annot.EventType == AnnotArgsType.AnnotLine
- )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- //是否为高亮注释
- private bool isHightAnnot(AnnotHandlerEventArgs annot)
- {
- if (annot.EventType == AnnotArgsType.AnnotUnderline ||
- annot.EventType == AnnotArgsType.AnnotSquiggly ||
- annot.EventType == AnnotArgsType.AnnotHighlight ||
- annot.EventType == AnnotArgsType.AnnotStrikeout
- )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private void GetSelectedAnnots(AnnotAttribEvent e)
- {
- var annot = e.AnnotItemsList[0];
- switch (annot.EventType)
- {
- case AnnotArgsType.AnnotHighlight:
- GetHighLight(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotUnderline:
- GetUnderLine(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotStrikeout:
- GetStrikeout(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotSquiggly:
- GetSquiggly(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotFreehand:
- GetFreehand(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotFreeText:
- GetFreetext(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotSquare:
- GetRect(e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotCircle:
- GetCircle(e.AnnotItemsList);
- 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", e.AnnotItemsList);
- else
- GetArrowLine("Arrow", e.AnnotItemsList);
- break;
- case AnnotArgsType.AnnotLink:
- //viewContentViewModel.IsCreateLink = false;
- //e.IsAnnotCreateReset= true;
- if (btnLinkIsChecked == false)
- {
- propertyPanel.IsAddLink = false;
- }
- GetLink(e.AnnotItemsList, e);
- break;
- case AnnotArgsType.AnnotSticky:
- GetStickyNote(e.AnnotItemsList);
- customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
- customStickyPopup.GetPDFViewer = PDFViewer;
- break;
- case AnnotArgsType.AnnotStamp:
- GetStamp();
- break;
- }
- }
- private void SelectedSignature(List<AnnotHandlerEventArgs> annotlist)
- {
- if (annotlist == null || annotlist.Count == 0)
- return;
- var annot = annotlist[0];
- if (annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand)
- return;
- if (annot.PageIndex < 0 || annot.AnnotIndex < 0)
- return;
- var signAnnot = AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
- if (signAnnot == null)
- {
- if (annot.EventType == AnnotArgsType.AnnotStamp)
- {
- StrAnnotToolChecked = "Stamp";
- }
- else
- {
- StrAnnotToolChecked = "";
- }
- }
- else
- {
- GetSignature();
- StrAnnotToolChecked = "Signature";
- }
- }
- private void AddAnnotSignature(AnnotHandlerEventArgs annot)
- {
- if ((annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand) ||
- (annot.PageIndex < 0 || annot.AnnotIndex < 0)) return;
- if (StrAnnotToolChecked == "Signature")
- {
- if (AnnotSignatures == null)
- AnnotSignatures = new List<Tuple<int, int>>();
- var signAnnot = AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
- if (signAnnot == null)
- {
- AnnotSignatures.Add(new Tuple<int, int>(annot.PageIndex, annot.AnnotIndex));
- }
- }
- }
- #endregion 与触发事件调用相关的函数
- #region PDFViewer事件
- private AnnotHandlerEventArgs CurrentSelectedAnnot = null;
- //选中和非选中注释
- private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
- {
- if (e != null)
- {
- var annot = e.AnnotItemsList[0];
- if (annot != null)
- {
- if (e.AnnotItemsList.Count == 1)
- {
- //IsAnnotCreateReset:是否为创建注释的状态
- if (e.IsAnnotCreateReset == false)
- {
- GetSelectedAnnots(e);
- SelectedSignature(e.AnnotItemsList);
- CurrentSelectedAnnot = annot;
- if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty)
- ShowPropertyPanel(true);
- }
- else
- {
- switch (annot.EventType)
- {
- case AnnotArgsType.AnnotLink:
- //viewContentViewModel.IsCreateLink = false;
- GetLink(e.AnnotItemsList, e);
- PDFViewer.SetToolParam(annot);
- break;
- }
- //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
- //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
- //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
- //annot.EventType != AnnotArgsType.AnnotUnderline &&
- //annot.EventType != AnnotArgsType.AnnotHighlight &&
- //annot.EventType != AnnotArgsType.AnnotSquiggly &&
- //annot.EventType != AnnotArgsType.AnnotLink &&
- //annot.EventType != AnnotArgsType.AnnotFreehand &&
- //annot.EventType != AnnotArgsType.AnnotSticky &&
- //)
- //{
- // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
- // {
- // var strLineAnnotTag = "";
- // if (e.AnnotItemsList[0] is LineAnnotArgs)
- // {
- // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
- // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
- // {
- // strLineAnnotTag = "Line";
- // }
- // else
- // {
- // strLineAnnotTag = "Arrow";
- // }
- // }
- // foreach (var item in ToolExpandDict)
- // {
- // if (item.Value == e.AnnotItemsList[0].EventType)
- // {
- // annot = null;//新建注释时,回到默认值
- // if (string.IsNullOrEmpty(strLineAnnotTag))
- // {
- // FindAnnotTypeKey(item.Key, ref annot);
- // break;
- // }
- // else
- // {
- // if (strLineAnnotTag == item.Key)
- // {
- // FindAnnotTypeKey(item.Key, ref annot);
- // break;
- // }
- // }
- // }
- // }
- // PDFViewer.SetToolParam(annot);
- // }
- //}
- #region TO DO
- //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
- //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
- //{
- // ShowPropertyPanel(false);
- //}
- //else
- //{
- // ShowPropertyPanel();
- //}
- #endregion TO DO
- }
- }
- else
- {
- bool isDifferentAnnotTyle = false;
- var lastAnnot = annot;
- foreach (var item in e.AnnotItemsList)
- {
- if (lastAnnot.EventType != item.EventType)
- {
- if ((isShapAnnot(annot) == true && isShapAnnot(item) == true) || (isHightAnnot(annot) == true && isHightAnnot(item) == true))
- {
- lastAnnot = item;
- continue;
- }
- lastAnnot = item;
- isDifferentAnnotTyle = true;
- break;
- }
- }
- if (isDifferentAnnotTyle)
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- else
- GetSelectedAnnots(e);
- }
- }
- //注释列表同步选中
- var list = e.GetPageAnnotsIndex();
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
- {
- if (list.Keys.Count == 0)
- {
- return;
- }
- var pageindex = new List<int>(list.Keys);
- List<int> annotes = new List<int>();
- list.TryGetValue(pageindex[0], out annotes);
- int annoteindex = annotes[0];
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- if (viewModel != null)
- {
- viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
- }
- }
- }
- else
- {
- if (BtnLinkIsChecked == false)
- {
- if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
- {
- if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
- {
- viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
- }
- }
- }
- }
- }
- //在注释工具的状态下,右键菜单
- private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
- {
- if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
- return;
- 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
- {
- if (e.AnnotEventArgsList.Count == 1)
- {
- var selectedAnnot = e.AnnotEventArgsList[0];
- PopMenuCheckedLineDash(selectedAnnot);
- PopMenuCheckedFontFamily(selectedAnnot);
- PopMenuCheckedTextAglin(selectedAnnot);
- switch (selectedAnnot.EventType)
- {
- case AnnotArgsType.AnnotHighlight:
- case AnnotArgsType.AnnotUnderline:
- case AnnotArgsType.AnnotStrikeout:
- case AnnotArgsType.AnnotSquiggly:
- if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
- {
- colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
- }
- else
- {
- colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
- }
- e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotFreehand:
- e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotFreeText:
- e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotSticky:
- e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotSquare:
- case AnnotArgsType.AnnotCircle:
- ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
- ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
- e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotLine:
- ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
- ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
- e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotLink:
- e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- case AnnotArgsType.AnnotStamp:
- e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
- break;
- }
- }
- else
- {
- bool isHigh = true;//是否为高亮
- foreach (var item in e.AnnotEventArgsList)
- {
- if (isHightAnnot(item) == false)
- {
- isHigh = false;
- break;
- }
- }
- MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
- MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
- e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
- }
- }
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
- {
- e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- else
- {
- e.PopupMenu = ViewerContextMenu(sender);
- if (e.PopupMenu != null)
- {
- e.Handle = true;
- }
- }
- }
- break;
- }
- }
- //右键菜单,选中字体样式按钮状态
- private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
- {
- if (annot != null)
- {
- if (annot.EventType == AnnotArgsType.AnnotFreeText)
- {
- var freeText = annot as FreeTextAnnotArgs;
- FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
- }
- }
- }
- //右键菜单,选中文本内容对齐按钮状态
- private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
- {
- if (annot != null)
- {
- if (annot.EventType == AnnotArgsType.AnnotFreeText)
- {
- var freeText = annot as FreeTextAnnotArgs;
- switch (freeText.Align)
- {
- case TextAlignment.Left:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
- break;
- case TextAlignment.Center:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
- break;
- case TextAlignment.Right:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
- break;
- case TextAlignment.Justify:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
- break;
- default:
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
- FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
- break;
- }
- }
- }
- }
- //右键菜单,选中虚实线按钮状态
- private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
- {
- if (annot != null)
- {
- bool isSolidLineDash = true;
- if (annot.EventType == AnnotArgsType.AnnotFreehand)
- {
- var freeHand = annot as FreehandAnnotArgs;
- isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
- FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
- }
- else if (annot.EventType == AnnotArgsType.AnnotSquare)
- {
- var square = annot as SquareAnnotArgs;
- isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
- ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
- }
- else if (annot.EventType == AnnotArgsType.AnnotCircle)
- {
- var circle = annot as CircleAnnotArgs;
- isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
- ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
- }
- else if (annot.EventType == AnnotArgsType.AnnotLine)
- {
- var line = annot as LineAnnotArgs;
- isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
- ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
- }
- }
- }
- /// <summary>
- /// 内容选择工具
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
- {
- SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
- SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
- SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
- SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
- 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;
- BtnHandIsChecked = true;
- PDFViewer.EnableZoom(true);
- PDFViewer.EnableScroll(true);
- break;
- }
- }
- break;
- default:
- break;
- }
- }
- 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:
- bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
- if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- if (viewModel != null)
- {
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewModel.UpdateAddedAnnot(pageindex, annotindex);
- }
- }
- var annot = e[0].EditAnnotArgs;
- if (
- annot.EventType == AnnotArgsType.AnnotSquare ||
- annot.EventType == AnnotArgsType.AnnotCircle ||
- annot.EventType == AnnotArgsType.AnnotLine ||
- annot.EventType == AnnotArgsType.AnnotStamp
- )
- {
- PDFViewer.ClearSelectAnnots();
- if (StrAnnotToolChecked != "Signature")
- {
- PDFViewer.SelectAnnotation(annot.PageIndex, annot.AnnotIndex);
- }
- else
- {
- AddAnnotSignature(annot);
- PDFViewer.SelectAnnotation(annot.PageIndex, annot.AnnotIndex);
- }
- }
-
- break;
- case ActionType.Del:
- isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
- if (isTabItemAnnotation)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- if (viewModel != null)
- {
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
- }
- }
- break;
- case ActionType.Modify:
- isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
- if (bOTAContent.TabItemAnnotation.IsSelected)
- {
- AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
- if (viewModel != null)
- {
- int pageindex = editEvent.PageIndex;
- int annotindex = editEvent.AnnotIndex;
- viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
- }
- }
- break;
- case ActionType.TextEdit:
- break;
- default:
- break;
- }
- }
- //空白处 右键菜单 添加注释 为单次添加,不连续添加
- if (IsNoSelectMenu)
- {
- IsNoSelectMenu = false;
- PDFViewer.SetMouseMode(MouseModes.PanTool);
- }
- }
- }
- private void PDFViewer_WidgetClickHander(object sender, WidgetArgs e)
- {
- }
- private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
- {
- if (e != null && e.DrawContext != null)
- {
- Rect hoverRect = new Rect(
- e.PaintRect.Left - 2,
- e.PaintRect.Top - 2,
- e.PaintRect.Width + 4,
- e.PaintRect.Height + 4);
- Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
- hoverPen.DashStyle = DashStyles.Dash;
- e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
- //便签,显示ToolTip内容
- if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
- {
- if (PDFViewer.ToolTip == null)
- {
- var content = e.Annot.GetContent();
- if (string.IsNullOrEmpty(content) == false)
- {
- ToolTip TipChild = new ToolTip();
- TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
- TipChild.MaxWidth = 246;
- TipChild.Content = content;
- TipChild.Visibility = Visibility.Visible;
- TipChild.IsOpen = true;
- TipChild.Placement = PlacementMode.Right;
- var rec = e.Annot.GetRect();
- TipChild.PlacementRectangle = new Rect(rec.left, rec.top, rec.right, rec.bottom);
- TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
- TipChild.Placement = PlacementMode.MousePoint;
- PDFViewer.ToolTip = TipChild;
- oldRect = hoverRect;
- PDFViewer.MouseMove -= PDFViewer_MouseMove;
- PDFViewer.MouseMove += PDFViewer_MouseMove;
- return;
- }
- }
- }
- }
- CloseAnnotToolTip();
- }
- private Rect oldRect = new Rect(0, 0, 0, 0);
- private void CloseAnnotToolTip()
- {
- if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
- {
- ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
- oldTips.IsOpen = false;
- oldTips.Visibility = Visibility.Collapsed;
- PDFViewer.ToolTip = null;
- PDFViewer.MouseMove -= PDFViewer_MouseMove;
- oldRect = new Rect(0, 0, 0, 0);
- }
- }
- private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
- {
- if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
- {
- var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
- var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
- var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
- if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
- {
- CloseAnnotToolTip();
- }
- }
- }
- #endregion PDFViewer事件
- #region BindingEvent事件
- 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 FreehandAnnotArgs)
- {
- var annot = e[argsType] as FreehandAnnotArgs;
- if (annot != null)
- {
- if (propertyPanel != null)
- {
- //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
- var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
- propertyPanel.AnnotEvent = AnnotEvent;
- var AnnotEvents = new List<AnnotAttribEvent>();
- AnnotEvents.Add(AnnotEvent);
- propertyPanel.AnnotEvents = AnnotEvents;
- propertyPanel.annot = annot;
- //手绘注释工具按钮的属性
- // FreehandPath.Opacity = annot.Transparency;
- // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
- }
- PDFViewer.SetToolParam(annot);
- }
- }
- break;
- case AnnotArgsType.AnnotErase:
- if (e[argsType] is ToggleButton)
- {
- ToggleButton clickBtn = e[argsType] as ToggleButton;
- 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);
- List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
- if (eraseArgs != null)
- eraseArgsList.Add(eraseArgs);
- AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
- }
- }
- break;
- case AnnotArgsType.AnnotSquare:
- case AnnotArgsType.AnnotCircle:
- case AnnotArgsType.AnnotLine:
- case AnnotArgsType.AnnotFreeText:
- //创建注释后,修改注释属性,可用于下次创建的注释
- if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
- {
- PDFViewer.SetToolParam(propertyPanel.annot);
- }
- break;
- }
- }
- }
- }
- #endregion BindingEvent事件
- }
- }
|