Browse Source

合并代码-部分右键菜单

zhuyi 1 year ago
parent
commit
f111b69da4

+ 46 - 10
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -17,6 +17,7 @@ using Compdfkit_Tools.Helper;
 using ComPDFKit.DigitalSign;
 using ComPDFKit.PDFAnnotation.Form;
 using ComPDFKit.PDFAnnotation;
+using ComPDFKit.Tool;
 
 namespace Compdfkit_Tools.PDFControl
 {
@@ -70,7 +71,7 @@ namespace Compdfkit_Tools.PDFControl
                     if (PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanRedo ||
                         PDFViewControl.PDFViewTool.GetCPDFViewer().UndoManager.CanUndo)
                     {
-                       return true;
+                        return true;
                     }
                 }
 
@@ -123,7 +124,7 @@ namespace Compdfkit_Tools.PDFControl
             displaySettingsControl = null;
             PDFViewControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_NONE);
         }
-        
+
         public void SetBOTAContainer(CPDFBOTABarControl botaControl)
         {
             this.BotaContainer.Child = botaControl;
@@ -194,13 +195,48 @@ namespace Compdfkit_Tools.PDFControl
             //PDFViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
             //PDFViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
             //PDFViewControl.PDFView.AnnotActiveHandler += PDFView_AnnotActiveHandler;
-            
-            //PDFViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
-            //PDFViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
+
+            PDFViewControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
+            PDFViewControl.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
             //PDFViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
             //PDFViewControl.PDFView.WidgetClickHandler += PDFView_WidgetClickHandler;
         }
 
+        private void PDFViewControl_MouseRightButtonDownHandler(object sender, ComPDFKit.Tool.MouseEventObject e)
+        {
+            ContextMenu ContextMenu = PDFViewControl.GetRightMenu();
+            if (ContextMenu == null)
+            {
+                ContextMenu = new ContextMenu();
+            }
+            switch (e.hitTestType)
+            {
+                case MouseHitTestType.kAnnot:
+                case MouseHitTestType.kSelectRect:
+                    CreateAnnotContextMenu(sender, ref ContextMenu, e.annotType);
+                    break;
+                default:
+                    ContextMenu=null;
+                    break;
+            }
+            PDFViewControl.SetRightMenu(ContextMenu);
+
+        }
+
+        private void CreateAnnotContextMenu(object sender, ref ContextMenu menu, C_ANNOTATION_TYPE annotType)
+        {
+            switch (annotType)
+            {
+                case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
+                    break;
+                default:
+                    menu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
+                    break;
+            }
+        }
+
         public void UnloadEvent()
         {
             //PDFViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
@@ -365,7 +401,7 @@ namespace Compdfkit_Tools.PDFControl
         //                {
         //                    e.Handle = true;
         //                    e.PopupMenu = new ContextMenu();
-                           
+
         //                    e.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
         //                    e.PopupMenu.Items.Add(new Separator());
 
@@ -666,7 +702,7 @@ namespace Compdfkit_Tools.PDFControl
                 OnCanSaveChanged?.Invoke(this, CanSave);
             }
         }
-        
+
         private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
@@ -715,7 +751,7 @@ namespace Compdfkit_Tools.PDFControl
         //    PropertyContainer.Child = PDFAnnotationControl;
         //    PDFAnnotationControl.SetAnnotEventData(e);
         //}
-        
+
         //private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
         //{
         //    if ((e is WidgetSignArgs args))
@@ -729,7 +765,7 @@ namespace Compdfkit_Tools.PDFControl
         //                return;
         //            }
         //        }
-                
+
         //        if (args.WidgetType == C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS)
         //        {
         //            panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
@@ -781,6 +817,6 @@ namespace Compdfkit_Tools.PDFControl
             AnnotationBarControl.SetAnnotationType(CPDFAnnotationType.Squiggly);
         }
         #endregion
-        
+
     }
 }

+ 7 - 0
Demo/Examples/Compdfkit_Tools/Annotation/PDFAnnotationPanel/PDFAnnotationControl/CPDFAnnotationControl.xaml.cs

@@ -83,9 +83,16 @@ namespace Compdfkit_Tools.PDFControl
                 //this.pdfViewerControl.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
                 //this.pdfViewerControl.AnnotEditHandler -= PdfViewer_AnnotEditHandler;
                 //this.pdfViewerControl.AnnotEditHandler += PdfViewer_AnnotEditHandler;
+                pdfViewerControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
+                pdfViewerControl.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
             }
         }
 
+        private void PDFViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
+        {
+            //throw new NotImplementedException();
+        }
+
         private void PdfViewerControl_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
         {
             if (e.IsCreate)

+ 34 - 0
Demo/Examples/Compdfkit_Tools/Edit/ContentEditCOntrol/ContentEditControl.xaml.cs

@@ -361,6 +361,8 @@ namespace Compdfkit_Tools.PDFControl
             PdfViewControl.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
             PdfViewControl.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
             PdfViewControl.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
+            PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
+            PdfViewControl.MouseRightButtonDownHandler += PdfViewControl_MouseRightButtonDownHandler;
             PdfViewControl = view;
             PDFGrid.Child = PdfViewControl;
             FloatPageTool.InitWithPDFViewer(view);
@@ -368,6 +370,38 @@ namespace Compdfkit_Tools.PDFControl
             DataContext = this;
         }
 
+        private void PdfViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
+        {
+            ContextMenu ContextMenu = PdfViewControl.GetRightMenu();
+            if (ContextMenu == null)
+            {
+                ContextMenu = new ContextMenu();
+            }
+            switch (e.hitTestType)
+            {
+                case MouseHitTestType.kAnnot:
+                case MouseHitTestType.kSelectRect:
+                    CreateAnnotContextMenu(sender, ref ContextMenu, e.annotType);
+                    break;
+                default:
+                    ContextMenu = null;
+                    break;
+            }
+            PdfViewControl.SetRightMenu(ContextMenu);
+        }
+        private void CreateAnnotContextMenu(object sender, ref ContextMenu menu, C_ANNOTATION_TYPE annotType)
+        {
+            switch (annotType)
+            {
+                case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
+                    break;
+                default:
+                    menu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
+                    break;
+            }
+        }
         private void PDFToolManager_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
         {
             if (e.IsCreate)

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

@@ -326,9 +326,45 @@ namespace Compdfkit_Tools.PDFControl
             PDFFormTool.ClearAllToolState();
             PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
             PdfViewControl.PDFViewTool.GetCPDFViewer().UndoManager.PropertyChanged += UndoManager_PropertyChanged;
+            PdfViewControl.MouseRightButtonDownHandler -= PdfViewControl_MouseRightButtonDownHandler;
+            PdfViewControl.MouseRightButtonDownHandler += PdfViewControl_MouseRightButtonDownHandler;
+
             newPDFViewer.CustomSignHandle = true;
         }
 
+        private void PdfViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
+        {
+            ContextMenu ContextMenu = PdfViewControl.GetRightMenu();
+            if (ContextMenu == null)
+            {
+                ContextMenu = new ContextMenu();
+            }
+            switch (e.hitTestType)
+            {
+                case MouseHitTestType.kAnnot:
+                case MouseHitTestType.kSelectRect:
+                    CreateFormContextMenu(sender, ref ContextMenu, e.annotType);
+                    break;
+                default:
+                    ContextMenu = null;
+                    break;
+            }
+            PdfViewControl.SetRightMenu(ContextMenu);
+        }
+        private void CreateFormContextMenu(object sender, ref ContextMenu menu, C_ANNOTATION_TYPE annotType)
+        {
+            switch (annotType)
+            {
+                case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
+                    menu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
+                    menu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
+                    break;
+                default:
+                    break;
+            }
+        }
+
         public void UnloadEvent()
         {
 

+ 3 - 3
Demo/Examples/Compdfkit_Tools/PDFView/PDFViewControl/PDFViewControl.xaml

@@ -16,10 +16,10 @@
             <RowDefinition Height="0"/>
             <RowDefinition Tag="SplitViewerTool" Height="0"/>
         </Grid.RowDefinitions>
-        <Border Tag="ViewerTool" GotFocus="PDFView_GotFocus" MinWidth="20" MinHeight="20" x:Name="PDFView" Grid.Row="0" Grid.Column="0"/>
+        <Border Tag="ViewerTool" MouseDown="PDFView_MouseDown"  MinWidth="20" MinHeight="20" x:Name="PDFView" Grid.Row="0" Grid.Column="0"/>
         <GridSplitter x:Name="VerticalSplitter" ResizeDirection="Columns" HorizontalAlignment="Stretch" Grid.Column="1" Width="15" Background="LightGray" Visibility="Collapsed"/>
         <GridSplitter x:Name="HorizontalSplitter" ResizeDirection="Rows" VerticalAlignment="Stretch" Grid.Row="1" Width="{Binding ElementName=ViewToolGrid,Path=ActualWidth}" Height="15" Background="LightGray" Visibility="Collapsed"/>
-        <Border Tag="SplitViewerTool" GotFocus="PDFView_GotFocus" MinWidth="20" x:Name="VerticalView" Grid.Row="0" Grid.Column="2" Visibility="Collapsed"/>
-        <Border Tag="SplitViewerTool" GotFocus="PDFView_GotFocus" MinHeight="20" x:Name="HorizontalView" Grid.Column="0" Grid.Row="2" Visibility="Collapsed"/>
+        <Border Tag="SplitViewerTool" MouseDown="PDFView_MouseDown" MinWidth="20" x:Name="VerticalView" Grid.Row="0" Grid.Column="2" Visibility="Visible"/>
+        <Border Tag="SplitViewerTool" MouseDown="PDFView_MouseDown" MinHeight="20" x:Name="HorizontalView" Grid.Column="0" Grid.Row="2" Visibility="Collapsed"/>
     </Grid>
 </UserControl>

+ 38 - 14
Demo/Examples/Compdfkit_Tools/PDFView/PDFViewControl/PDFViewControl.xaml.cs

@@ -40,7 +40,9 @@ namespace Compdfkit_Tools.PDFControl
         public event EventHandler<MouseEventObject> MouseLeftButtonDownHandler;
         public event EventHandler<MouseEventObject> MouseLeftButtonUpHandler;
         public event EventHandler<MouseEventObject> MouseMoveHandler;
+        public event EventHandler<MouseEventObject> MouseRightButtonDownHandler;
 
+        //private ContextMenu RightMenu;
         #region Properties
 
         public bool CustomSignHandle { get; set; }
@@ -50,6 +52,8 @@ namespace Compdfkit_Tools.PDFControl
         public PDFViewControl()
         {
             InitializeComponent();
+
+
             viewerTool = new CPDFViewerTool();
             toolManager = new CPDFToolManager(viewerTool);
             PDFViewTool = viewerTool;
@@ -68,24 +72,44 @@ namespace Compdfkit_Tools.PDFControl
             PDFToolManager.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
             PDFToolManager.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
             PDFToolManager.MouseMoveHandler -= PDFToolManager_MouseMoveHandler;
+            PDFToolManager.MouseRightButtonDownHandler -= PDFToolManager_MouseRightButtonDownHandler;
 
             PDFViewTool.SizeChanged += PDFViewTool_SizeChanged;
             PDFViewTool.GetCPDFViewer().MouseWheelZoomHandler += PDFViewControl_MouseWheelZoomHandler;
             PDFToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
             PDFToolManager.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
             PDFToolManager.MouseMoveHandler += PDFToolManager_MouseMoveHandler;
+            PDFToolManager.MouseRightButtonDownHandler += PDFToolManager_MouseRightButtonDownHandler;
 
             splitViewerTool.SizeChanged -= SplitViewerTool_SizeChanged;
             splitViewerTool.GetCPDFViewer().MouseWheelZoomHandler -= SplitPDFViewControl_MouseWheelZoomHandler;
             splitToolManager.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
             splitToolManager.MouseLeftButtonUpHandler -= PDFToolManager_MouseLeftButtonUpHandler;
             splitToolManager.MouseMoveHandler -= PDFToolManager_MouseMoveHandler;
+            splitToolManager.MouseRightButtonDownHandler += PDFToolManager_MouseRightButtonDownHandler;
 
             splitViewerTool.SizeChanged += SplitViewerTool_SizeChanged;
             splitViewerTool.GetCPDFViewer().MouseWheelZoomHandler += SplitPDFViewControl_MouseWheelZoomHandler;
             splitToolManager.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
             splitToolManager.MouseLeftButtonUpHandler += PDFToolManager_MouseLeftButtonUpHandler;
             splitToolManager.MouseMoveHandler += PDFToolManager_MouseMoveHandler;
+            splitToolManager.MouseRightButtonDownHandler += PDFToolManager_MouseRightButtonDownHandler;
+        }
+
+        public ContextMenu GetRightMenu()
+        {
+            FocusPDFViewTool.ContextMenu?.Items.Clear();
+            return FocusPDFViewTool.ContextMenu;
+        }
+
+        public void SetRightMenu(ContextMenu contextMenu)
+        {
+            FocusPDFViewTool.ContextMenu = contextMenu;
+        }
+
+        private void PDFToolManager_MouseRightButtonDownHandler(object sender, MouseEventObject e)
+        {
+            MouseRightButtonDownHandler?.Invoke(sender, e);
         }
 
         private void PDFToolManager_MouseMoveHandler(object sender, MouseEventObject e)
@@ -291,20 +315,6 @@ namespace Compdfkit_Tools.PDFControl
             HorizontalView.Child = null;
         }
 
-        private void PDFView_GotFocus(object sender, RoutedEventArgs e)
-        {
-            switch((sender as Border).Tag)
-            {
-                case "ViewerTool":
-                    FocusPDFViewTool = viewerTool;
-                    break;
-                case "SplitViewerTool":
-                    FocusPDFViewTool = splitViewerTool;
-                    break;
-            }
-            SelectedPDFViewToolChanged?.Invoke(this,EventArgs.Empty);
-        }
-
         #region Private Command Methods
         private double CheckZoomLevel(double zoom, bool IsGrowth)
         {
@@ -337,5 +347,19 @@ namespace Compdfkit_Tools.PDFControl
         }
 
         #endregion
+
+        private void PDFView_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            switch ((sender as Border).Tag)
+            {
+                case "ViewerTool":
+                    FocusPDFViewTool = viewerTool;
+                    break;
+                case "SplitViewerTool":
+                    FocusPDFViewTool = splitViewerTool;
+                    break;
+            }
+            SelectedPDFViewToolChanged?.Invoke(this, EventArgs.Empty);
+        }
     }
 }