Parcourir la source

compdfkit(win) - 数字签名右键菜单,完善部分细节

weixiangjie il y a 9 mois
Parent
commit
3ccf56d6ed

+ 85 - 24
Demo/Examples/Compdfkit_Tools/DigitalSignature/DigitalSignatureControl/DigitalSignatureControl.xaml.cs

@@ -146,15 +146,79 @@ namespace Compdfkit_Tools.PDFControl
             
             PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler -= PDFViewControl_MouseLeftButtonDownHandler;
             PDFViewControl.PDFViewTool.MouseLeftButtonDownHandler += PDFViewControl_MouseLeftButtonDownHandler;
-            
+            PDFViewControl.PDFViewTool.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
+            PDFViewControl.PDFViewTool.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
             
             panelState.PropertyChanged -= PanelState_PropertyChanged;
             panelState.PropertyChanged += PanelState_PropertyChanged;
         }
 
+        private void PDFViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
+        {
+            ContextMenu ContextMenu = PDFViewControl.GetRightMenu();
+            if (ContextMenu == null)
+            {
+                ContextMenu = new ContextMenu();
+            }
+            if (PDFViewControl.PDFViewTool.GetViewerModel() == MouseModes.WidgetEditTool && e.annotType== C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
+            {
+                BaseWidget baseWidget = PDFViewControl.GetCacheHitTestWidget();
+                if(baseWidget == null)
+                {
+                    return;
+                }
+
+                var widget = baseWidget.GetAnnotData().Annot as CPDFWidget;
+                if (widget == null || widget.WidgetType != C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
+                {
+                    return;
+                }
+                var signatureWidget = widget as CPDFSignatureWidget;
+                CPDFSignature sig = signatureWidget.GetSignature(PDFViewControl.GetCPDFViewer().GetDocument());
+                if (signatureWidget.IsSigned() && sig != null && sig?.SignerList.Count > 0)
+                {
+                    MenuItem deleteMenu = new MenuItem()
+                        { Header = LanguageHelper.CommonManager.GetString("Menu_Delete") };
+                    deleteMenu.Click += (o, args) =>
+                    {
+                        PDFViewControl.GetCPDFViewer().GetDocument().RemoveSignature(sig, true);
+                        signatureWidget.ResetForm();
+                        signatureWidget.SetIsLocked(false);
+                        //PDFViewControl.PDFView.ReloadVisibleAnnots();
+                        //PDFViewControl.GetCPDFViewer().UpdateRenderFrame();
+                        PDFViewControl.PDFViewTool.IsDocumentModified = true;
+                        SignatureStatusChanged?.Invoke(this, null);
+                    };
+                    ContextMenu.Items.Add(deleteMenu);
+                }
+                else
+                {
+                    ContextMenu.Items.Add(new MenuItem()
+                        { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
+                    ContextMenu.Items.Add(new MenuItem()
+                        { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
+                    ContextMenu.Items.Add(new MenuItem()
+                        { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                }
+                
+            }
+            else if(e.hitTestType == MouseHitTestType.Text)
+            {
+                ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
+                PDFViewControl.SetRightMenu(ContextMenu);
+            }
+            else
+            {
+                ContextMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
+                PDFViewControl.CreateViewerMenu(sender, ref ContextMenu);
+            }
+
+            PDFViewControl.SetRightMenu(ContextMenu);
+        }
+
         private void PDFViewControl_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
         {
-            if (e.annotType== C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
+            if (PDFViewControl.PDFViewTool.GetViewerModel() == MouseModes.PanTool && e.annotType== C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
             {
                 BaseWidget baseWidget = PDFViewControl.GetCacheHitTestWidget();
                 if(baseWidget == null)
@@ -167,30 +231,27 @@ namespace Compdfkit_Tools.PDFControl
                 {
                     return;
                 }
-                switch (widget.WidgetType)
+
+                if (widget.WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
                 {
-                    case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
-                        var signatureWidget = widget as CPDFSignatureWidget;
-                        CPDFSignature sig = signatureWidget.GetSignature(PDFViewControl.GetCPDFViewer().GetDocument());
-                        if (signatureWidget.IsSigned() && sig != null && sig?.SignerList.Count > 0)
-                        {
-                            ViewSignatureEvent(sender, sig);
-                        }
-                        else
+                    var signatureWidget = widget as CPDFSignatureWidget;
+                    CPDFSignature sig = signatureWidget.GetSignature(PDFViewControl.GetCPDFViewer().GetDocument());
+                    if (signatureWidget.IsSigned() && sig != null && sig?.SignerList.Count > 0)
+                    {
+                        ViewSignatureEvent(sender, sig);
+                    }
+                    else
+                    {
+                        Window parentWindow = Window.GetWindow((DependencyObject)sender);
+                        AddCertificationDialog addCertificationControl = new AddCertificationDialog
                         {
-                            Window parentWindow = Window.GetWindow((DependencyObject)sender);
-                            AddCertificationDialog addCertificationControl = new AddCertificationDialog
-                            {
-                                Owner = parentWindow
-                            };
-                            currentSignatureWidget = signatureWidget;
-                            addCertificationControl.FillSignatureEvent -= AddCertificationControl_FillSignatureEvent;
-                            addCertificationControl.FillSignatureEvent += AddCertificationControl_FillSignatureEvent;
-                            addCertificationControl.ShowDialog();
-                        }
-                        break;
-                    default:
-                        break;
+                            Owner = parentWindow
+                        };
+                        currentSignatureWidget = signatureWidget;
+                        addCertificationControl.FillSignatureEvent -= AddCertificationControl_FillSignatureEvent;
+                        addCertificationControl.FillSignatureEvent += AddCertificationControl_FillSignatureEvent;
+                        addCertificationControl.ShowDialog();
+                    }
                 }
             }
         }

+ 1 - 1
Demo/Examples/Compdfkit_Tools/DigitalSignature/FillDigitalSignatureControl/FillDigitalSignatureControl.xaml.cs

@@ -117,7 +117,7 @@ namespace Compdfkit_Tools.PDFControl
             tempSignatureConfig.IsDrawLogo = (bool)LogoChk.IsChecked;
             if (tempSignatureConfig.IsDrawLogo)
             {
-                //tempSignatureConfig.LogoBitmap = new Bitmap(logoPath);
+                tempSignatureConfig.LogoData = CommonHelper.ConvertBitmapToByteArray(new Bitmap(logoPath));
             }
             tempSignatureConfig.Content = Text;
             tempSignatureConfig.TextColor = textColor;

+ 2 - 1
Demo/Examples/Compdfkit_Tools/PDFView/PDFViewControl/PDFViewControl.xaml.cs

@@ -17,6 +17,7 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
 using Compdfkit_Tools.Helper;
+using ComPDFKit.Tool.DrawTool;
 using static ComPDFKit.Tool.CPDFToolManager;
 using static Compdfkit_Tools.PDFControlUI.CPDFViewModeUI;
 using SplitMode = Compdfkit_Tools.PDFControlUI.CPDFViewModeUI.SplitMode;
@@ -111,7 +112,7 @@ namespace Compdfkit_Tools.PDFControl
 
         }
 
-        private void PDFToolManager_AnnotDefaultEditedHandler(object sender, EventArgs e)
+        private void PDFToolManager_AnnotDefaultEditedHandler(object sender, SelectedAnnotData e)
         {
             UpdateAnnotFrame();
         }