浏览代码

ComPDFKit.Tool(Win) - 表单多选移动框选增加控制开关

liyuxuan 2 月之前
父节点
当前提交
752cdcb637
共有 1 个文件被更改,包括 80 次插入81 次删除
  1. 80 81
      Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.AnnotSelector.cs

+ 80 - 81
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.AnnotSelector.cs

@@ -11,11 +11,9 @@ using ComPDFKitViewer.Layer;
 using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Reflection;
 using System.Windows;
 using System.Windows.Input;
 using System.Windows.Media;
-using static ComPDFKit.Tool.CPDFViewerTool;
 
 namespace ComPDFKit.Tool
 {
@@ -33,10 +31,11 @@ namespace ComPDFKit.Tool
         private AnnotSelectAreaData AreaDrawData { get; set; } = new AnnotSelectAreaData();
         private AnnotSelectAreaData AreaMoveData { get; set; } = new AnnotSelectAreaData();
         private bool DrawSelect { get; set; } = true;
-        private bool AllowMultiSelect { get; set; } = false;
+        private bool AllowMultiSelect { get; set; }
+        private bool AllowAreaSelect { get; set; }
         private bool IsMoved { get; set; } = false;
-        private Point OffsetPos { get; set; }=new Point(0,0);
-        private List<AnnotParam> AnnotParamList { get; set; }=new List<AnnotParam>();
+        private Point OffsetPos { get; set; } = new Point(0, 0);
+        private List<AnnotParam> AnnotParamList { get; set; } = new List<AnnotParam>();
         private void AnnotSelectInsert()
         {
             Selector = new AnnotSelector();
@@ -52,7 +51,7 @@ namespace ComPDFKit.Tool
             {
                 return;
             }
-            if(Selector==null || Selector.SelectAnnots==null)
+            if (Selector == null || Selector.SelectAnnots == null)
             {
                 return;
             }
@@ -84,7 +83,7 @@ namespace ComPDFKit.Tool
             {
                 return;
             }
-            if (DrawSelect==false)
+            if (DrawSelect == false)
             {
                 return;
             }
@@ -96,9 +95,9 @@ namespace ComPDFKit.Tool
             Selector?.CleanDraw();
         }
 
-        private void AnnotSelectAddItem(AnnotData annotData,bool clean=true)
+        private void AnnotSelectAddItem(AnnotData annotData, bool clean = true)
         {
-            if (!AllowMultiSelect || annotData==null)
+            if (!AllowMultiSelect || annotData == null)
             {
                 return;
             }
@@ -107,7 +106,7 @@ namespace ComPDFKit.Tool
             {
                 if (Selector?.HasItem(annotData) == true)
                 {
-                    if(Selector?.GetSelectCount()!=1)
+                    if (Selector?.GetSelectCount() != 1)
                     {
                         Selector?.RemoveItem(annotData);
                     }
@@ -119,7 +118,7 @@ namespace ComPDFKit.Tool
                 return;
             }
 
-            if(clean)
+            if (clean)
             {
                 Selector?.ClearItem();
                 Selector?.AddItem(annotData);
@@ -133,17 +132,17 @@ namespace ComPDFKit.Tool
                 return;
             }
             AreaDrawData.HitPageIndex = -1;
-            if (PDFViewer == null || Selector==null)
+            if (PDFViewer == null || Selector == null || !AllowAreaSelect)
             {
                 return;
             }
             AreaDrawData.HitAreaPos = Mouse.GetPosition(PDFViewer);
             AreaDrawData.MoveAreaPos = AreaDrawData.HitAreaPos;
-            PDFViewer.GetPointPageInfo(AreaDrawData.HitAreaPos,out int pageIndex,out Rect paintRect, out Rect pageBound);
+            PDFViewer.GetPointPageInfo(AreaDrawData.HitAreaPos, out int pageIndex, out Rect paintRect, out Rect pageBound);
             if (pageIndex >= 0)
             {
                 AreaDrawData.HitPageIndex = pageIndex;
-                AreaDrawData.HitAreaBound =pageBound;
+                AreaDrawData.HitAreaBound = pageBound;
                 PDFViewer.CanHorizontallyScroll = false;
                 PDFViewer.CanVerticallyScroll = false;
                 PDFViewer.EnableZoom(false);
@@ -178,7 +177,7 @@ namespace ComPDFKit.Tool
             {
                 return;
             }
-            if (AreaDrawData.HitPageIndex <0 || PDFViewer==null || Selector==null)
+            if (AreaDrawData.HitPageIndex < 0 || PDFViewer == null || Selector == null)
             {
                 return;
             }
@@ -190,7 +189,7 @@ namespace ComPDFKit.Tool
             drawDC.Close();
         }
 
-        private bool AnnotSelectAreaSelect(bool onlyWidget=false,bool onlyAnnot = false)
+        private bool AnnotSelectAreaSelect(bool onlyWidget = false, bool onlyAnnot = false)
         {
             if (!AllowMultiSelect)
             {
@@ -208,7 +207,7 @@ namespace ComPDFKit.Tool
             Selector.ClearItem();
             Selector.CleanDraw();
             AreaDrawData.HitPageIndex = -1;
-            DrawSelect=true;
+            DrawSelect = true;
 
             if (PDFViewer.CurrentRenderFrame != null && PDFViewer.CurrentRenderFrame.AnnotDataList != null)
             {
@@ -220,7 +219,7 @@ namespace ComPDFKit.Tool
                     {
                         continue;
                     }
-                    if(onlyAnnot && checkItem.AnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
+                    if (onlyAnnot && checkItem.AnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
                     {
                         continue;
                     }
@@ -238,17 +237,17 @@ namespace ComPDFKit.Tool
 
         private BaseAnnot AnnotSelectGetAnnot()
         {
-            if (PDFViewer != null && Selector != null && Selector.SelectAnnots!=null && Selector.SelectAnnots.Count==1)
+            if (PDFViewer != null && Selector != null && Selector.SelectAnnots != null && Selector.SelectAnnots.Count == 1)
             {
                 AnnotData annotData = Selector.SelectAnnots[0];
                 BaseLayer checkLayer = PDFViewer.GetViewForTag(PDFViewer.GetAnnotViewTag());
                 if (checkLayer != null && checkLayer is AnnotLayer)
                 {
-                    AnnotLayer annotLayer= (AnnotLayer)checkLayer;
-                   return  annotLayer.GetAnnotForIndex(annotData.PageIndex,annotData.AnnotIndex);
+                    AnnotLayer annotLayer = (AnnotLayer)checkLayer;
+                    return annotLayer.GetAnnotForIndex(annotData.PageIndex, annotData.AnnotIndex);
                 }
             }
-           
+
             return null;
         }
 
@@ -268,36 +267,36 @@ namespace ComPDFKit.Tool
                 return;
             }
 
-            if(PDFViewer==null ||  Selector==null || Selector.GetSelectCount()<2)
+            if (PDFViewer == null || Selector == null || Selector.GetSelectCount() < 2)
             {
                 return;
             }
 
             Point movePos = Mouse.GetPosition(PDFViewer);
-            PointControlType hitPoint= Selector.GetHitControlIndex(movePos);
+            PointControlType hitPoint = Selector.GetHitControlIndex(movePos);
             Cursor oldCursor = this.Cursor;
             Cursor newCursor = this.Cursor;
-           
+
             switch (hitPoint)
             {
                 case PointControlType.LeftTop:
                 case PointControlType.RightBottom:
-                    newCursor= Cursors.SizeNWSE;
+                    newCursor = Cursors.SizeNWSE;
                     break;
                 case PointControlType.LeftMiddle:
                 case PointControlType.RightMiddle:
-                    newCursor= Cursors.SizeWE;
+                    newCursor = Cursors.SizeWE;
                     break;
                 case PointControlType.LeftBottom:
                 case PointControlType.RightTop:
-                    newCursor= Cursors.SizeNESW;
+                    newCursor = Cursors.SizeNESW;
                     break;
                 case PointControlType.MiddlBottom:
                 case PointControlType.MiddleTop:
-                    newCursor= Cursors.SizeNS;
+                    newCursor = Cursors.SizeNS;
                     break;
                 case PointControlType.Body:
-                    newCursor= Cursors.SizeAll;
+                    newCursor = Cursors.SizeAll;
                     break;
                 default:
                     newCursor = Cursors.Arrow;
@@ -338,8 +337,8 @@ namespace ComPDFKit.Tool
             {
                 return false;
             }
-           
-            if (AreaMoveData.HitPageIndex<0 || PDFViewer == null || Selector == null || Selector.GetSelectCount() < 2)
+
+            if (AreaMoveData.HitPageIndex < 0 || PDFViewer == null || Selector == null || Selector.GetSelectCount() < 2)
             {
                 return false;
             }
@@ -352,7 +351,7 @@ namespace ComPDFKit.Tool
             Point moveOffset = new Point(movePos.X - AreaMoveData.HitAreaPos.X, movePos.Y - AreaMoveData.HitAreaPos.Y);
             PointControlType hitPointType = Selector.GetHitControlIndex(AreaMoveData.HitAreaPos);
 
-            switch(hitPointType)
+            switch (hitPointType)
             {
                 default:
                 case PointControlType.None:
@@ -368,7 +367,7 @@ namespace ComPDFKit.Tool
                 case PointControlType.RightMiddle:
                 case PointControlType.RightTop:
                 case PointControlType.MiddleTop:
-                    if(CanResize(hitPointType, moveOffset, Selector.GetOutBoundRect(),AreaMoveData.HitAreaBound))
+                    if (CanResize(hitPointType, moveOffset, Selector.GetOutBoundRect(), AreaMoveData.HitAreaBound))
                     {
                         AnnotSelectResize(hitPointType, moveOffset, Selector.GetOutBoundRect(), AreaMoveData.HitAreaBound);
                     }
@@ -400,7 +399,7 @@ namespace ComPDFKit.Tool
             drawDC.DrawRectangle(Selector.DrawBrush, Selector.DrawPen, moveRect);
             foreach (AnnotData checkItem in Selector.SelectAnnots)
             {
-                Rect childRect=new Rect(checkItem.PaintRect.X+OffsetPos.X,checkItem.PaintRect.Y+OffsetPos.Y,checkItem.PaintRect.Width,checkItem.PaintRect.Height);
+                Rect childRect = new Rect(checkItem.PaintRect.X + OffsetPos.X, checkItem.PaintRect.Y + OffsetPos.Y, checkItem.PaintRect.Width, checkItem.PaintRect.Height);
                 drawDC.DrawRectangle(Selector.DrawBrush, Selector.DrawPen, childRect);
             }
             drawDC.Close();
@@ -445,7 +444,7 @@ namespace ComPDFKit.Tool
             double top = maxRect.Top;
             double right = maxRect.Right;
             double bottom = maxRect.Bottom;
-          
+
             switch (controlType)
             {
                 case PointControlType.LeftTop://左上
@@ -514,7 +513,7 @@ namespace ComPDFKit.Tool
                     drawDC.DrawRectangle(Selector.DrawBrush, Selector.DrawPen, newClient);
                 }
             }
-           
+
             drawDC.Close();
         }
 
@@ -644,7 +643,7 @@ namespace ComPDFKit.Tool
                 case PointControlType.RightMiddle:
                 case PointControlType.RightTop:
                 case PointControlType.MiddleTop:
-                    AnnotSelectResizeSave(hitPointType, OffsetPos,Selector.GetOutBoundRect(), AreaMoveData.HitAreaBound);
+                    AnnotSelectResizeSave(hitPointType, OffsetPos, Selector.GetOutBoundRect(), AreaMoveData.HitAreaBound);
                     PDFViewer?.UpdateRenderFrame();
                     return;
             }
@@ -656,7 +655,7 @@ namespace ComPDFKit.Tool
 
             foreach (AnnotData checkItem in Selector.SelectAnnots)
             {
-                if(checkItem.Annot==null || checkItem.Annot.IsValid()==false)
+                if (checkItem.Annot == null || checkItem.Annot.IsValid() == false)
                 {
                     continue;
                 }
@@ -667,12 +666,12 @@ namespace ComPDFKit.Tool
                     childRect.Width,
                     childRect.Height);
 
-                Rect noZoomRect=new Rect(
-                    saveRect.Left/checkItem.CurrentZoom,
-                    saveRect.Top/checkItem.CurrentZoom,
-                    saveRect.Width/checkItem.CurrentZoom, 
-                    saveRect.Height/checkItem.CurrentZoom);
-                Rect rawRect= DpiHelper.StandardRectToPDFRect(noZoomRect);
+                Rect noZoomRect = new Rect(
+                    saveRect.Left / checkItem.CurrentZoom,
+                    saveRect.Top / checkItem.CurrentZoom,
+                    saveRect.Width / checkItem.CurrentZoom,
+                    saveRect.Height / checkItem.CurrentZoom);
+                Rect rawRect = DpiHelper.StandardRectToPDFRect(noZoomRect);
 
                 AnnotHistory historyItem = ParamConverter.CreateHistory(checkItem.Annot);
                 AnnotParam prevParam = ParamConverter.CPDFDataConverterToAnnotParam(PDFViewer.GetDocument(), checkItem.PageIndex, checkItem.Annot);
@@ -812,7 +811,7 @@ namespace ComPDFKit.Tool
                 return false;
             }
 
-            if (uiCmd==null || PDFViewer == null || Selector == null)
+            if (uiCmd == null || PDFViewer == null || Selector == null)
             {
                 return false;
             }
@@ -824,7 +823,7 @@ namespace ComPDFKit.Tool
                 case "Delete":
                     return Selector.GetSelectCount() >= 2;
                 case "Paste":
-                   return AnnotParamList.Count() >= 2;
+                    return AnnotParamList.Count() >= 2;
                 default:
                     break;
             }
@@ -841,7 +840,7 @@ namespace ComPDFKit.Tool
             {
                 return;
             }
-          
+
             switch (uiCmd.Name)
             {
                 case "Copy":
@@ -869,7 +868,7 @@ namespace ComPDFKit.Tool
                 return;
             }
 
-            if (Selector.GetSelectCount()< 2)
+            if (Selector.GetSelectCount() < 2)
             {
                 return;
             }
@@ -902,7 +901,7 @@ namespace ComPDFKit.Tool
                 return;
             }
 
-            GroupHistory historyGroup=new GroupHistory();
+            GroupHistory historyGroup = new GroupHistory();
             Dictionary<AnnotHistory, CPDFAnnotation> removeDict = new Dictionary<AnnotHistory, CPDFAnnotation>();
             foreach (AnnotData checkItem in Selector.SelectAnnots)
             {
@@ -912,7 +911,7 @@ namespace ComPDFKit.Tool
                 }
                 AnnotHistory historyItem = ParamConverter.CreateHistory(checkItem.Annot);
                 AnnotParam prevParam = ParamConverter.CPDFDataConverterToAnnotParam(PDFViewer.GetDocument(), checkItem.PageIndex, checkItem.Annot);
-                if (prevParam == null || historyItem==null)
+                if (prevParam == null || historyItem == null)
                 {
                     continue;
                 }
@@ -920,12 +919,12 @@ namespace ComPDFKit.Tool
                 historyItem.CurrentParam = prevParam;
                 historyItem.Action = HistoryAction.Remove;
                 historyItem.PDFDoc = PDFViewer.GetDocument();
-                removeDict[historyItem]=checkItem.Annot;
+                removeDict[historyItem] = checkItem.Annot;
             }
 
-            foreach(AnnotHistory annotKey in removeDict.Keys)
+            foreach (AnnotHistory annotKey in removeDict.Keys)
             {
-                CPDFAnnotation removeAnnot= removeDict[annotKey];
+                CPDFAnnotation removeAnnot = removeDict[annotKey];
                 if (removeAnnot.RemoveAnnot())
                 {
                     historyGroup.Histories.Add(annotKey);
@@ -959,8 +958,8 @@ namespace ComPDFKit.Tool
 
             for (int i = 0; i < AnnotParamList.Count; i++)
             {
-                AnnotParam checkParam= AnnotParamList[i];
-                if(i==0)
+                AnnotParam checkParam = AnnotParamList[i];
+                if (i == 0)
                 {
                     left = checkParam.ClientRect.left;
                     top = checkParam.ClientRect.top;
@@ -1001,16 +1000,16 @@ namespace ComPDFKit.Tool
             foreach (AnnotParam annotParam in AnnotParamList)
             {
                 AnnotParam cloneItem = CloneAnnotParam(annotParam);
-                if(cloneItem==null)
+                if (cloneItem == null)
                 {
                     continue;
                 }
-                Rect saveRect= new Rect(cloneItem.ClientRect.left,cloneItem.ClientRect.top,cloneItem.ClientRect.width(),cloneItem.ClientRect.height());
+                Rect saveRect = new Rect(cloneItem.ClientRect.left, cloneItem.ClientRect.top, cloneItem.ClientRect.width(), cloneItem.ClientRect.height());
                 saveRect.X = saveRect.Left - left + offsetPos.X;
                 saveRect.Y = saveRect.Top - top + offsetPos.Y;
 
-                cloneItem.PageIndex= pageIndex;
-                cloneItem.ClientRect=new CRect((float)saveRect.Left, (float)saveRect.Bottom, (float)saveRect.Right, (float)saveRect.Top);   
+                cloneItem.PageIndex = pageIndex;
+                cloneItem.ClientRect = new CRect((float)saveRect.Left, (float)saveRect.Bottom, (float)saveRect.Right, (float)saveRect.Top);
                 AnnotHistory historyItem = ParamConverter.CreateHistory(annotParam);
                 historyItem.CurrentParam = cloneItem;
                 historyItem.PDFDoc = PDFViewer.GetDocument();
@@ -1032,7 +1031,7 @@ namespace ComPDFKit.Tool
         {
             if (oldParam != null)
             {
-                AnnotParam newParam= new AnnotParam();
+                AnnotParam newParam = new AnnotParam();
                 switch (oldParam.CurrentType)
                 {
                     case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
@@ -1040,85 +1039,85 @@ namespace ComPDFKit.Tool
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
-                        newParam=new FreeTextParam();
+                        newParam = new FreeTextParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
-                        newParam=new HighlightParam();
+                        newParam = new HighlightParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
-                        newParam=new InkParam();
+                        newParam = new InkParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
-                        newParam= new LineParam();
+                        newParam = new LineParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
-                        newParam=new LinkParam();
+                        newParam = new LinkParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_CARET:
-                        newParam=new RedactParam();
+                        newParam = new RedactParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
-                        newParam=new SquareParam();
+                        newParam = new SquareParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
-                        newParam=new SquareParam();
+                        newParam = new SquareParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
-                        newParam=new StampParam();
+                        newParam = new StampParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
-                        newParam=new StickyNoteParam();
+                        newParam = new StickyNoteParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
-                        newParam=new StickyNoteParam();
+                        newParam = new StickyNoteParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
-                        newParam=new UnderlineParam();
+                        newParam = new UnderlineParam();
                         oldParam.CopyTo(newParam);
                         break;
                     case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
-                        WidgetParm widgetParam=oldParam as WidgetParm;
+                        WidgetParm widgetParam = oldParam as WidgetParm;
                         if (widgetParam != null)
                         {
                             switch (widgetParam.WidgetType)
                             {
                                 case C_WIDGET_TYPE.WIDGET_CHECKBOX:
-                                    newParam=new CheckBoxParam();
+                                    newParam = new CheckBoxParam();
                                     oldParam.CopyTo(newParam);
                                     break;
                                 case C_WIDGET_TYPE.WIDGET_COMBOBOX:
-                                    newParam=new ComboBoxParam();
+                                    newParam = new ComboBoxParam();
                                     oldParam.CopyTo(newParam);
                                     break;
                                 case C_WIDGET_TYPE.WIDGET_LISTBOX:
-                                    newParam=new ListBoxParam();
+                                    newParam = new ListBoxParam();
                                     oldParam.CopyTo(newParam);
                                     break;
                                 case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
-                                    newParam=new PushButtonParam();
+                                    newParam = new PushButtonParam();
                                     oldParam.CopyTo(newParam);
                                     break;
                                 case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
-                                    newParam=new RadioButtonParam();
+                                    newParam = new RadioButtonParam();
                                     oldParam.CopyTo(newParam);
                                     break;
                                 case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
-                                    newParam=new SignatureParam();
+                                    newParam = new SignatureParam();
                                     oldParam.CopyTo(newParam);
                                     break;
                                 case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
-                                    newParam=new TextBoxParam();
+                                    newParam = new TextBoxParam();
                                     oldParam.CopyTo(newParam);
                                     break;
                                 default: