Kaynağa Gözat

Merge branch 'compdfkit_demo_win_rebuild' of http://git.kdan.cc:8865/Others/kmpdfkit_demo into compdfkit_demo_win_rebuild

zhuyi 9 ay önce
ebeveyn
işleme
ab056ced46

+ 1 - 0
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -223,6 +223,7 @@ namespace Compdfkit_Tools.PDFControl
                     break;
                 default:
                     ContextMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
+                    PDFViewControl.CreateViewerMenu(sender, ref ContextMenu);
                     break;
             }
             PDFViewControl.SetRightMenu(ContextMenu);

+ 22 - 176
Demo/Examples/Compdfkit_Tools/DigitalSignature/DigitalSignatureControl/DigitalSignatureControl.xaml.cs

@@ -11,6 +11,7 @@ using System.Windows.Media;
 using Compdfkit_Tools.Helper;
 using ComPDFKit.DigitalSign;
 using ComPDFKit.PDFAnnotation.Form;
+using ComPDFKit.Tool;
 using ComPDFKitViewer;
 
 namespace Compdfkit_Tools.PDFControl
@@ -480,182 +481,27 @@ namespace Compdfkit_Tools.PDFControl
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
-        //private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
-        //{
-        //    if (e != null && e.CommandType == CommandType.Context)
-        //    {
-        //        if (e.CommandTarget == TargetType.WidgetView)
-        //        {
-        //            e.Handle = true;
-        //            e.PopupMenu = new ContextMenu();
-        //            var sign = e.Sign.GetSignature(PDFViewControl.PDFView.Document);
-        //            if (e.Sign.IsSigned() && sign != null && sign.SignerList.Any())
-        //            {
-        //                MenuItem DeleteMenu = new MenuItem()
-        //                    { Header = LanguageHelper.CommonManager.GetString("Menu_Delete") };
-        //                DeleteMenu.Click += (o, args) =>
-        //                {
-        //                    PDFViewControl.PDFView.Document.RemoveSignature(sign, true);
-        //                    e.Sign.ResetForm();
-        //                    e.Sign.SetIsLocked(false);
-        //                    PDFViewControl.PDFView.ReloadVisibleAnnots();
-                            
-        //                    PDFViewControl.PDFView.UndoManager.CanSave = true;
-        //                    SignatureStatusChanged?.Invoke(this, null);
-        //                };
-        //                e.PopupMenu.Items.Add(DeleteMenu);
-        //            }
-        //            else
-        //            {
-        //                e.PopupMenu.Items.Add(new MenuItem()
-        //                    { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
-        //                e.PopupMenu.Items.Add(new MenuItem()
-        //                    { Header = LanguageHelper.CommonManager.GetString("Menu_Cut"), Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
-        //                e.PopupMenu.Items.Add(new MenuItem()
-        //                    { Header = LanguageHelper.CommonManager.GetString("Menu_Delete"), Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
-        //            }
-        //        }
-        //        else if (e.PressOnSelectedText)
-        //        {
-        //            e.Handle = true;
-        //            e.PopupMenu = new ContextMenu();
-        //            e.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
-        //        }
-        //        else
-        //        {
-        //            e.Handle = true;
-        //            e.PopupMenu = new ContextMenu();
-
-        //            e.PopupMenu.Items.Add(new MenuItem()
-        //                { Header = LanguageHelper.CommonManager.GetString("Menu_Paste"), Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
-        //            e.PopupMenu.Items.Add(new Separator());
-
-        //            MenuItem fitWidthMenu = new MenuItem();
-        //            fitWidthMenu.Header = LanguageHelper.CommonManager.GetString("Menu_AutoSize");
-        //            fitWidthMenu.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    PDFViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(fitWidthMenu);
-
-        //            MenuItem fitSizeMenu = new MenuItem();
-        //            fitSizeMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RealSize");
-        //            fitSizeMenu.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    PDFViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(fitSizeMenu);
-
-        //            MenuItem zoomInMenu = new MenuItem();
-        //            zoomInMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomIn");
-        //            zoomInMenu.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    double newZoom = CommandHelper.CheckZoomLevel(zoomLevelList,
-        //                        PDFViewControl.PDFView.ZoomFactor + 0.01, true);
-        //                    PDFViewControl.PDFView?.Zoom(newZoom);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(zoomInMenu);
-
-        //            MenuItem zoomOutMenu = new MenuItem();
-        //            zoomOutMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomOut");
-        //            zoomOutMenu.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    double newZoom = CommandHelper.CheckZoomLevel(zoomLevelList,
-        //                        PDFViewControl.PDFView.ZoomFactor - 0.01, false);
-        //                    PDFViewControl.PDFView?.Zoom(newZoom);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(zoomOutMenu);
-        //            e.PopupMenu.Items.Add(new Separator());
-
-        //            MenuItem singleView = new MenuItem();
-        //            singleView.Header = LanguageHelper.CommonManager.GetString("Menu_SinglePage");
-        //            singleView.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    PDFViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(singleView);
-
-        //            MenuItem singleContinuousView = new MenuItem();
-        //            singleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_SingleContinuous");
-        //            singleContinuousView.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    PDFViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(singleContinuousView);
-
-        //            MenuItem doubleView = new MenuItem();
-        //            doubleView.Header = LanguageHelper.CommonManager.GetString("Menu_DoublePage");
-        //            doubleView.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    PDFViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
-        //                }
-        //            };
-
-        //            e.PopupMenu.Items.Add(doubleView);
-
-        //            MenuItem doubleContinuousView = new MenuItem();
-        //            doubleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_DoubleContinuous");
-        //            doubleContinuousView.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    PDFViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
-        //                }
-        //            };
-        //            e.PopupMenu.Items.Add(doubleContinuousView);
-
-        //            MenuItem resetFormMenu = new MenuItem();
-        //            resetFormMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Reset");
-        //            resetFormMenu.Click += (o, p) =>
-        //            {
-        //                if (PDFViewControl != null)
-        //                {
-        //                    PDFViewControl.PDFView?.ResetForm(null);
-        //                }
-        //            };
-        //            e.PopupMenu.Items.Add(new Separator());
-        //            e.PopupMenu.Items.Add(resetFormMenu);
-        //        }
-        //    }
-        //    if (e != null && e.CommandType == CommandType.Copy)
-        //    {
-        //        if (PDFViewControl?.PDFView == null) return;
-        //        if (!PDFViewControl.PDFView.Document.GetPermissionsInfo().AllowsCopying)
-        //        {
-        //            if(!PasswordHelper.UnlockWithOwnerPassword(PDFViewControl.PDFView.Document))
-        //            {
-        //                return;
-        //            }
-        //        }
-        //    }
-        //    e?.DoCommand();
-        //}
+        private void PDFView_AnnotCommandHandler(object sender, MouseEventObject e)
+        {
+            ContextMenu ContextMenu = PDFViewControl.GetRightMenu();
+            if (ContextMenu == null)
+            {
+                ContextMenu = new ContextMenu();
+            }
+            switch (e.hitTestType)
+            {
+                case MouseHitTestType.kAnnot:
+                case MouseHitTestType.kSelectRect:
+                    break;
+                case MouseHitTestType.kText:
+                    ContextMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
+                    break;
+                default:
+                    PDFViewControl.CreateViewerMenu(sender, ref ContextMenu);
+                    break;
+            }
+            PDFViewControl.SetRightMenu(ContextMenu);
+        }
         #endregion
 
         #region Load Unload Event

+ 1 - 0
Demo/Examples/Compdfkit_Tools/Form/FormControl/FormControl.xaml.cs

@@ -351,6 +351,7 @@ namespace Compdfkit_Tools.PDFControl
                     break;
                 default:
                     ContextMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
+                    PdfViewControl.CreateViewerMenu(sender, ref ContextMenu);
                     break;
             }
             PdfViewControl.SetRightMenu(ContextMenu);

+ 91 - 0
Demo/Examples/Compdfkit_Tools/PDFView/PDFViewControl/PDFViewControl.xaml.cs

@@ -16,6 +16,7 @@ using System.Reflection;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
+using Compdfkit_Tools.Helper;
 using static ComPDFKit.Tool.CPDFToolManager;
 using static Compdfkit_Tools.PDFControlUI.CPDFViewModeUI;
 using SplitMode = Compdfkit_Tools.PDFControlUI.CPDFViewModeUI.SplitMode;
@@ -360,6 +361,96 @@ namespace Compdfkit_Tools.PDFControl
             return FocusPDFViewTool?.GetCacheHitTestAnnot();
         }
 
+        public void CreateViewerMenu(object sender, ref ContextMenu contextMenu)
+        {
+            MenuItem fitWidthMenu = new MenuItem();
+            fitWidthMenu.Header = LanguageHelper.CommonManager.GetString("Menu_AutoSize");
+            fitWidthMenu.Click += (o, p) =>
+            {
+                FocusPDFViewTool?.GetCPDFViewer()?.SetFitMode(FitMode.FitWidth);
+                FocusPDFViewTool?.GetCPDFViewer()?.UpDateRenderFrame();
+            };
+            contextMenu.Items.Add(fitWidthMenu);
+            
+            MenuItem fitSizeMenu = new MenuItem();
+            fitSizeMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RealSize");
+            fitSizeMenu.Click += (o, p) =>
+            {
+                FocusPDFViewTool?.GetCPDFViewer()?.SetFitMode(FitMode.FitOriginal);
+                FocusPDFViewTool?.GetCPDFViewer()?.UpDateRenderFrame();
+            };
+            contextMenu.Items.Add(fitSizeMenu);
+            
+            MenuItem zoomInMenu = new MenuItem();
+            zoomInMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomIn");
+            zoomInMenu.Click += (o, p) =>
+            {
+                FocusPDFViewTool?.GetCPDFViewer()?.SetFitMode(FitMode.FitZoom);
+                double zoom = FocusPDFViewTool?.GetCPDFViewer()?.GetZoom() ?? 1;
+                FocusPDFViewTool?.GetCPDFViewer()?.SetZoom(CheckZoomLevel(zoom, true));
+                FocusPDFViewTool?.GetCPDFViewer()?.UpDateRenderFrame();
+            };
+            contextMenu.Items.Add(zoomInMenu);
+            
+            MenuItem zoomOutMenu = new MenuItem();
+            zoomOutMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomOut");
+            zoomOutMenu.Click += (o, p) =>
+            {
+                FocusPDFViewTool?.GetCPDFViewer()?.SetFitMode(FitMode.FitZoom);
+                double zoom = FocusPDFViewTool?.GetCPDFViewer()?.GetZoom() ?? 1;
+                FocusPDFViewTool?.GetCPDFViewer()?.SetZoom(CheckZoomLevel(zoom, false));
+                FocusPDFViewTool?.GetCPDFViewer()?.UpDateRenderFrame();
+            };
+            contextMenu.Items.Add(zoomOutMenu);
+            
+            contextMenu.Items.Add(new Separator());
+            
+            MenuItem singleView = new MenuItem();
+            singleView.Header = LanguageHelper.CommonManager.GetString("Menu_SinglePage");
+            singleView.Click += (o, p) =>
+            {
+                FocusPDFViewTool?.GetCPDFViewer()?.SetViewMode(ViewMode.Single);
+                FocusPDFViewTool?.GetCPDFViewer()?.UpDateRenderFrame();
+            };
+            contextMenu.Items.Add(singleView);
+            
+            MenuItem singleContinuousView = new MenuItem();
+            singleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_SingleContinuous");
+            singleContinuousView.Click += (o, p) =>
+            {
+                FocusPDFViewTool?.GetCPDFViewer()?.SetViewMode(ViewMode.SingleContinuous);
+                FocusPDFViewTool?.GetCPDFViewer()?.UpDateRenderFrame();
+            };
+            contextMenu.Items.Add(singleContinuousView);
+            
+            MenuItem doubleView = new MenuItem();
+            doubleView.Header = LanguageHelper.CommonManager.GetString("Menu_DoublePage");
+            doubleView.Click += (o, p) =>
+            {
+                FocusPDFViewTool?.GetCPDFViewer()?.SetViewMode(ViewMode.Double);
+                FocusPDFViewTool?.GetCPDFViewer()?.UpDateRenderFrame();
+            };
+            contextMenu.Items.Add(doubleView);
+            
+            MenuItem doubleContinuousView = new MenuItem();
+            doubleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_DoubleContinuous");
+            doubleContinuousView.Click += (o, p) =>
+            {
+                FocusPDFViewTool?.GetCPDFViewer()?.SetViewMode(ViewMode.DoubleContinuous);
+                FocusPDFViewTool?.GetCPDFViewer()?.UpDateRenderFrame();
+            };
+            contextMenu.Items.Add(doubleContinuousView);
+            contextMenu.Items.Add(new Separator());
+            
+            MenuItem resetFormMenu = new MenuItem();
+            resetFormMenu.Header = LanguageHelper.CommonManager.GetString("Menu_Reset");
+            resetFormMenu.Click += (o, p) =>
+            {
+                //FocusPDFViewTool?.GetCPDFViewer()?.ResetForm();
+            };
+            contextMenu.Items.Add(resetFormMenu);
+        }
+
         private void RemoveSplitViewerTool()
         {
             UpdateRenderFrame();

+ 1 - 1
Demo/Examples/Compdfkit_Tools/PDFView/RegularViewerControl.xaml.cs

@@ -128,7 +128,7 @@ namespace Compdfkit_Tools.PDFView
                     CreateSelectTextContextMenu(sender, ref ContextMenu);
                     break;
                 default:
-                    ContextMenu = null;
+                    PdfViewControl.CreateViewerMenu(sender, ref ContextMenu);
                     break;
             }
             PdfViewControl.SetRightMenu(ContextMenu);