Browse Source

【2025】【PDFView】鼠标移动效果梳理

dinglingui 3 months ago
parent
commit
9ecfad30bd

+ 13 - 5
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/Form/CPDFButtonWidgetAnnotation+PDFListView.swift

@@ -46,17 +46,25 @@ import Foundation
         if (NSIsEmptyRect(self.bounds)) {
             return
         }
-        if (pdfView.toolMode != .CFormToolMode) {
-            return
-        }
-        
+     
         let rect = self.borderRecct(for: pdfView)
         
         let lineWidth = pdfView.unitWidth(on: self.page)
         context.saveGState()
         let color = CPDFListViewConfig.defaultManager.annotationBorderColor.cgColor
         context.setStrokeColor(color)
-        if (isHover || pdfView.activeAnnotations.count > 1) {
+        if isHover {
+            if(self.controlType() == .pushButtonControl) {
+                
+            } else {
+                let lengths: [CGFloat] = [2.0, 2.0]
+                context.setLineDash(phase: 0.0, lengths: lengths)
+                let clipRect = context.boundingBoxOfClipPath // 获取剪辑边界矩形
+                if(clipRect.width >= rect.width || clipRect.height >= rect.height ) {
+                    context.stroke(KMRectInset(NSRectToCGRect(rect), 0,0), width: lineWidth)
+                }
+            }
+        } else if (pdfView.activeAnnotations.count > 1) {
             let lengths: [CGFloat] = [2.0, 2.0]
             context.setLineDash(phase: 0.0, lengths: lengths)
             let clipRect = context.boundingBoxOfClipPath // 获取剪辑边界矩形

+ 0 - 3
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/Form/CPDFWidgetAnnotation+PDFListView.swift

@@ -24,9 +24,6 @@ enum CPDFWidgetShowState: Int, CaseIterable {
         if (NSIsEmptyRect(self.bounds)) {
             return
         }
-        if (pdfView.toolMode != .CFormToolMode) {
-            return
-        }
         var rect = self.borderRecct(for: pdfView)
         let lineWidth = pdfView.unitWidth(on: self.page)
         

+ 153 - 136
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+Event.m

@@ -126,14 +126,8 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             [self setNeedsDisplayAnnotationViewForPage:page];
             
         } else if (modifiers == NSEventModifierFlagOption && [newActiveAnnotation isMovable]) {
-            //            if ([newActiveAnnotation isKindOfClass:[CPDFSquareAnnotation class]] ||
-            //                [newActiveAnnotation isKindOfClass:[CPDFCircleAnnotation class]] ||
-            //                [newActiveAnnotation isKindOfClass:[CPDFLineAnnotation class]] ||
-            //                [newActiveAnnotation isKindOfClass:[CPDFTextAnnotation class]]) {
             CPDFAnnotation *newAnnotation = [newActiveAnnotation copy];
             [self addAnnotation:newAnnotation toPage:page];
-            //            [self addAnnotationWithType:CAnnotationTypeSquare selection:nil page:page bounds:newActiveAnnotation.bounds];
-            //            newActiveAnnotation.shouldDisplay = YES;
             newActiveAnnotation = newAnnotation;
             [self updateActiveAnnotations:@[newActiveAnnotation]];
             [self setNeedsDisplayAnnotationViewForVisiblePages];
@@ -284,7 +278,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
 - (void)mouseMoved:(NSEvent *)event {
     if(self.isPresentationMode) {
         NSPoint tPoint = [event locationInView:self];
-
+        
         if(CGRectContainsPoint(self.bounds, tPoint)) {
             if(self.presentationDrawView && self.presentationDrawView.isHidden == NO) {
                 NSImage *cursorImage = [[NSImage imageNamed:@"KMPresentationImageNameMouse"] copy];
@@ -309,73 +303,15 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             }
         }
     }
-        
+    
     if (self.isEditing) {
-//        [super mouseMoved:event];
         return;
     }
     NSPoint point = NSZeroPoint;
     CPDFPage *page = [self pageAndPoint:&point forEvent:event nearest:YES];
-    id annotations = [page annotations];
-    
-    CPDFAnnotation *newActiveAnnotation = nil;
-    for (CPDFAnnotation *annotation in annotations) {
-        if ([annotation hitTest:point] && [annotation annotationShouldDisplay]) {
-            newActiveAnnotation = annotation;
-            break;
-        }
-    }
-    CPDFAnnotation *clickNewActiveAnnotation = newActiveAnnotation;
-    if(![newActiveAnnotation isForm] && self.toolMode == CFormToolMode) {
-        newActiveAnnotation = nil;
-    }
-    
-    if ([clickNewActiveAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
-        [[KMImageToolTipWindow shared] showForImageContext:newActiveAnnotation at:NSZeroPoint];
-    }else{
-        [[KMImageToolTipWindow shared] fadeOut];
-    }
-    
-    if (([newActiveAnnotation isForm]) && self.toolMode != CFormToolMode) {
-        newActiveAnnotation = nil;
-    }
-    
-    //    if([newActiveAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
-    if(self.annotationType == CAnnotationTypeInk || self.annotationType == CAnnotationTypeEraser)
-        newActiveAnnotation = nil;
-    //    }
-    if (![self consistentTypeWithAnnotation:newActiveAnnotation]) {
-        newActiveAnnotation = nil;
-    }
-    
-    if(CRedactToolMode == self.toolMode && ![newActiveAnnotation isKindOfClass:[CPDFRedactAnnotation class]])
-        newActiveAnnotation = nil;
-    
-    [CPDFListView cancelPreviousPerformRequestsWithTarget:self selector:@selector(showHUDHint:) object:self.hoverAnnotation];
-    if ((CNoteToolMode == self.toolMode || CTextToolMode == self.toolMode || CRedactErasureToolMode == self.toolMode) &&
-        clickNewActiveAnnotation &&
-        (self.hoverAnnotation == newActiveAnnotation) &&
-        !self.popOver &&
-        clickNewActiveAnnotation.toolTipsString.length > 0 &&
-        ([clickNewActiveAnnotation isKindOfClass:[CPDFTextAnnotation class]] || [clickNewActiveAnnotation isKindOfClass:[CPDFLinkAnnotation class]] || [clickNewActiveAnnotation isKindOfClass:[CPDFWidgetAnnotation class]])) {
-        if ([newActiveAnnotation isKindOfClass:[CPDFTextAnnotation class]] || [newActiveAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
-            [self performSelector:@selector(showHUDHint:) withObject:newActiveAnnotation afterDelay:0.f];
-        } else {
-            [self performSelector:@selector(showHUDHint:) withObject:newActiveAnnotation afterDelay:0.3];
-        }
-    } else if ([self isSupportSelectAnnotation] && newActiveAnnotation && [newActiveAnnotation isKindOfClass:[CPDFRedactAnnotation class]] && (self.hoverAnnotation == newActiveAnnotation)) {
-        [(CPDFRedactAnnotation *)newActiveAnnotation setDrawRedactionsAsRedacted:YES];
-        [self setNeedsDisplayAnnotationViewForPage:page];
-    } else if([self isSupportSelectAnnotation] && self.hoverAnnotation && [self.hoverAnnotation isKindOfClass:[CPDFRedactAnnotation class]]){
-        [(CPDFRedactAnnotation *)self.hoverAnnotation setDrawRedactionsAsRedacted:NO];
-        [self setNeedsDisplayAnnotationViewForPage:page];
-    } else {
-        [self hidenHUDHint];
-    }
     
     if(self.clickLineAnnotation && self.isClickDoubleCreatLine) {
-        NSPoint pagePoint = NSZeroPoint;
-        CPDFPage *page = [self pageAndPoint:&pagePoint forEvent:event nearest:YES];
+        NSPoint pagePoint = point;
         
         NSPoint startPoint = [self.clickLineAnnotation startPoint];
         NSPoint *draggedPoint = &pagePoint;
@@ -406,8 +342,8 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             [self setNeedsDisplayAnnotation:self.clickLineAnnotation];
         }
     } else if (self.clickPolylineAnnotation) {
-        NSPoint pagePoint = NSZeroPoint;
-        CPDFPage *page = [self pageAndPoint:&pagePoint forEvent:event nearest:YES];
+        NSPoint pagePoint = point;
+        
         if(page == self.clickPolylineAnnotation.page) {
             NSMutableArray<NSValue *> *savePoints = [NSMutableArray arrayWithArray:self.clickPolylineAnnotation.savePoints];
             
@@ -452,8 +388,8 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             }
         }
     } else if (self.clickPolygonAnnotation) {
-        NSPoint pagePoint = NSZeroPoint;
-        CPDFPage *page = [self pageAndPoint:&pagePoint forEvent:event nearest:YES];
+        NSPoint pagePoint = point;
+        
         if(page == self.clickPolygonAnnotation.page) {
             NSMutableArray<NSValue *> *savePoints = [NSMutableArray arrayWithArray:self.clickPolygonAnnotation.savePoints];
             NSUInteger resizeIndex = self.polygonClickNumber;
@@ -497,8 +433,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             }
         }
     } else if (self.clickSquareFronPolygonAnnotation) {
-        NSPoint pagePoint = NSZeroPoint;
-        CPDFPage *page = [self pageAndPoint:&pagePoint forEvent:event nearest:YES];
+        NSPoint pagePoint = point;
         
         if (page == self.clickSquareFronPolygonAnnotation.page) {
             CRectEdges resizeHandle = CMaxXEdgeMask | CMinYEdgeMask;
@@ -509,84 +444,170 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                 [self.pdfListViewDelegate PDFListViewAnnotationMeasureInfoChange:self withAnnotation:self.clickSquareFronPolygonAnnotation];
             }
         }
-    } else if([self isSupportSelectAnnotation] && (newActiveAnnotation && (![self.activeAnnotations containsObject:newActiveAnnotation] || [newActiveAnnotation isKindOfClass:[CPDFRedactAnnotation class]]))) {
-        self.hoverAnnotation = newActiveAnnotation;
-        [self setNeedsDisplayAnnotationViewForPage:page];
-    } else if (!newActiveAnnotation && self.hoverAnnotation) {
-        self.hoverAnnotation = nil;
-        [self setNeedsDisplayAnnotationViewForPage:page];
-    }
-    
-    //    [super mouseMoved:event];
-    [self.window mouseMoved:event];
-    
-    if(!self.isEditing) {
-        [self removeShapeLayer];
+    } else {
+        id annotations = [page annotations];
+        
+        CPDFAnnotation *newActiveAnnotation = nil;
+        for (CPDFAnnotation *annotation in annotations) {
+            if ([annotation hitTest:point] && [annotation annotationShouldDisplay]) {
+                newActiveAnnotation = annotation;
+                break;
+            }
+        }
+        
+        CPDFAnnotation *clickNewActiveAnnotation = newActiveAnnotation;
+        NSLog(@"%@",newActiveAnnotation.type);
+        
+        [CPDFListView cancelPreviousPerformRequestsWithTarget:self selector:@selector(showHUDHint:) object:self.hoverAnnotation];
+        if(newActiveAnnotation != nil) {
+            if([newActiveAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+                if(self.popOver == nil && (CTextToolMode == self.toolMode ||
+                                           CMoveToolMode == self.toolMode ||
+                                           CEditPDFToolLink == self.toolMode)) {
+                    CPDFLinkAnnotation *linkNewAnnotation = (CPDFLinkAnnotation *)newActiveAnnotation;
+                    if(linkNewAnnotation.destination != nil) {
+                        [[KMImageToolTipWindow shared] showForImageContext:linkNewAnnotation at:NSZeroPoint];
+                        
+                        [self hidenHUDHint];
+                    } else if(linkNewAnnotation.URL.length > 0){
+                        [self performSelector:@selector(showHUDHint:) withObject:newActiveAnnotation afterDelay:0.f];
+                        
+                        if ([KMImageToolTipWindow shared].isVisible == YES) {
+                            [[KMImageToolTipWindow shared] fadeOut];
+                        }
+                    }
+                }
+                
+                if(!(CTextToolMode == self.toolMode || CEditPDFToolLink == self.toolMode || CMoveToolMode == self.toolMode)) {
+                    clickNewActiveAnnotation = nil;
+                }
+            } else if([newActiveAnnotation isKindOfClass:[CPDFRedactAnnotation class]]) {
+                if ([KMImageToolTipWindow shared].isVisible == YES) {
+                    [[KMImageToolTipWindow shared] fadeOut];
+                }
+                [self hidenHUDHint];
+            } else if ([newActiveAnnotation isKindOfClass:[CPDFMarkupAnnotation class]]) {
+                if ([KMImageToolTipWindow shared].isVisible == YES) {
+                    [[KMImageToolTipWindow shared] fadeOut];
+                }
+                [self hidenHUDHint];
+                if(!(CTextToolMode == self.toolMode || (CNoteToolMode == self.toolMode && [CPDFListView isMarkupAnnotationType:self.annotationType]))) {
+                    clickNewActiveAnnotation = nil;
+                }
+            } else if ([newActiveAnnotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+                if ([KMImageToolTipWindow shared].isVisible == YES) {
+                    [[KMImageToolTipWindow shared] fadeOut];
+                }
+                [self hidenHUDHint];
+                
+                if(!(CFormToolMode == self.toolMode ||
+                     CTextToolMode == self.toolMode ||
+                     CMoveToolMode== self.toolMode)) {
+                    clickNewActiveAnnotation = nil;
+                }
+            } else if ([newActiveAnnotation isKindOfClass:[CPDFMovieAnnotation class]] ||
+                       [newActiveAnnotation isKindOfClass:[CPDFSoundAnnotation class]]) {
+                if ([KMImageToolTipWindow shared].isVisible == YES) {
+                    [[KMImageToolTipWindow shared] fadeOut];
+                }
+                [self hidenHUDHint];
+                
+                if(!(CTextToolMode == self.toolMode || (CNoteToolMode == self.toolMode && ![CPDFListView isMarkupAnnotationType:self.annotationType]))) {
+                    clickNewActiveAnnotation = nil;
+                }
+            } else  {
+                if ([KMImageToolTipWindow shared].isVisible == YES) {
+                    [[KMImageToolTipWindow shared] fadeOut];
+                }
+                if(self.popOver == nil &&
+                   [newActiveAnnotation isKindOfClass:[CPDFTextAnnotation class]] &&
+                   (CTextToolMode == self.toolMode || CNoteToolMode == self.toolMode) &&
+                   (newActiveAnnotation.toolTipsString.length > 0)) {
+                    [self performSelector:@selector(showHUDHint:) withObject:newActiveAnnotation afterDelay:0.3];
+                } else {
+                    [self hidenHUDHint];
+                }
+                
+                if(!(CTextToolMode == self.toolMode || (CNoteToolMode == self.toolMode && ![CPDFListView isMarkupAnnotationType:self.annotationType]))) {
+                    clickNewActiveAnnotation = nil;
+                }
+            }
+            
+        } else {
+            if ([KMImageToolTipWindow shared].isVisible == YES) {
+                [[KMImageToolTipWindow shared] fadeOut];
+            }
+            
+            [self hidenHUDHint];
+        }
         
+        if (clickNewActiveAnnotation && [clickNewActiveAnnotation isKindOfClass:[CPDFRedactAnnotation class]] && (self.hoverAnnotation == newActiveAnnotation)) {
+            [(CPDFRedactAnnotation *)clickNewActiveAnnotation setDrawRedactionsAsRedacted:YES];
+            [self setNeedsDisplayAnnotationViewForPage:page];
+        } else if(self.hoverAnnotation && [self.hoverAnnotation isKindOfClass:[CPDFRedactAnnotation class]]){
+            [(CPDFRedactAnnotation *)self.hoverAnnotation setDrawRedactionsAsRedacted:NO];
+            [self setNeedsDisplayAnnotationViewForPage:page];
+        }
+        
+        NSLog(@"-----%@",clickNewActiveAnnotation.type);
+        //显示虚线
+        if((clickNewActiveAnnotation &&
+            (![self.activeAnnotations containsObject:clickNewActiveAnnotation] || [clickNewActiveAnnotation isKindOfClass:[CPDFRedactAnnotation class]]))) {
+            self.hoverAnnotation = newActiveAnnotation;
+            [self setNeedsDisplayAnnotationViewForPage:page];
+        } else if (!clickNewActiveAnnotation && self.hoverAnnotation) {
+            self.hoverAnnotation = nil;
+            [self setNeedsDisplayAnnotationViewForPage:page];
+        }
+        
+        //设置鼠标样式
         BOOL isIncludeText = NO;
         NSMutableArray *currentActiveAnnotations = [NSMutableArray array];
         for (CPDFAnnotation *an in self.activeAnnotations) {
             if([an.page isEqual:page]) {
                 if([an isKindOfClass:[CPDFFreeTextAnnotation class]])
                     isIncludeText = YES;
-                if(!([an isKindOfClass:[CPDFMarkupAnnotation class]] || [an isKindOfClass:[CPDFTextAnnotation class]])) {
+                if(!([an isKindOfClass:[CPDFMarkupAnnotation class]] ||
+                     [an isKindOfClass:[CPDFTextAnnotation class]])) {
                     [currentActiveAnnotations addObject:an];
                 }
             }
         }
         
-        if(CNoteToolMode == self.toolMode ||
-           CTextToolMode == self.toolMode ||
-           CFormToolMode == self.toolMode ||
-           CRedactToolMode == self.toolMode ||
-           CRedactErasureToolMode == self.toolMode) {
-            if(currentActiveAnnotations.count > 1) {
-                NSRect rect = [self selectionMultipleBoundsWithAnnotations:currentActiveAnnotations];
-                CRectEdges resizeHandle = CPDFListViewResizeHandleForPointFromRect(point, rect, 4.0 / [self scaleFactor]);
-    
-                [self setCursorForAreaOfInterest:CAreaOfInterestForResizeHandle(resizeHandle, page)];
-            } else {
-                if([self.activeAnnotation page] == page &&
-                   [self.activeAnnotation isResizable] &&
-                   [self.activeAnnotation resizeHandleForPoint:point scaleFactor:[self scaleFactor]] != 0) {
-                    CRectEdges resizeHandle = [self.activeAnnotation resizeHandleForPoint:point scaleFactor:[self scaleFactor]];
-                    [self setCursorForAreaOfInterest:CAreaOfInterestForResizeHandle(resizeHandle, page)];
-                } else {
-                    CPDFAreaOfInterest area = [self areaOfInterestForMouse:event];
-                    if(newActiveAnnotation && (self.annotationType != CAnnotationTypeSignSignature && self.annotationType != CAnnotationTypeStamp)) {
-                        area = CDragArea;
-                    }
-                    
-                    if (point.x < 0 || point.x > page.bounds.size.width) {
+        NSRect rect = [self selectionMultipleBoundsWithAnnotations:currentActiveAnnotations];
+        CRectEdges resizeHandle = CPDFListViewResizeHandleForPointFromRect(point, rect, 4.0 / [self scaleFactor]);
+        if(currentActiveAnnotations.count > 1 && resizeHandle != 0) {
+            [self setCursorForAreaOfInterest:CAreaOfInterestForResizeHandle(resizeHandle, page)];
+        } else if([self.activeAnnotation page] == page &&
+                  [self.activeAnnotation isResizable] &&
+                  [self.activeAnnotation resizeHandleForPoint:point scaleFactor:[self scaleFactor]] != 0){
+            CRectEdges resizeHandle = [self.activeAnnotation resizeHandleForPoint:point scaleFactor:[self scaleFactor]];
+            [self setCursorForAreaOfInterest:CAreaOfInterestForResizeHandle(resizeHandle, page)];
+        } else {
+            if(clickNewActiveAnnotation){
+                if ([clickNewActiveAnnotation isKindOfClass:[CPDFLinkAnnotation class]] ||
+                    [clickNewActiveAnnotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] ||
+                    [clickNewActiveAnnotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]] ||
+                    [clickNewActiveAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
+                    if(self.toolMode == CTextToolMode || self.toolMode == CMoveToolMode) {
+                        [[NSCursor pointingHandCursor] set];
+                    } else {
                         [[NSCursor arrowCursor] set];
-                    } else if (point.y < 0 || point.y > page.bounds.size.height) {
-                        
+                    }
+                } else if ([clickNewActiveAnnotation isKindOfClass:[CPDFFreeTextAnnotation class]] ||
+                           [clickNewActiveAnnotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
+                    if(self.toolMode == CTextToolMode || self.toolMode == CMoveToolMode) {
+                        [[NSCursor IBeamCursor] set];
                     } else {
-                        [self setCursorForAreaOfInterest:area];
+                        [[NSCursor arrowCursor] set];
                     }
                 }
+            } else {
+                [self setCursorForMouse:event];
             }
-            
-            if ((CFormToolMode == self.toolMode &&
-                 (self.annotationType >= CAnnotationTypeRadioButton &&
-                  self.annotationType <= CAnnotationTypeSignature)) || (CNoteToolMode == self.toolMode && self.stampObject)){
-                CPDFAnnotationModel *annotationModel = [[CPDFAnnotationModel alloc] initWithAnnotationType:self.annotationType];
-                CGFloat defaultWidth = annotationModel.noteWidth;
-                CGFloat defaultHeight = annotationModel.noteHeight;
-                NSSize defaultSize = ([page rotation] % 180 == 0) ? NSMakeSize(defaultWidth, defaultHeight) : NSMakeSize(defaultHeight, defaultWidth);
-                CGRect  bounds = CPDFListViewRectFromRightAndSize(point, defaultSize);
-                CRectEdges resizeHandle = CMinXEdgeMask | CMaxYEdgeMask;
-                
-                //                  [self.dragHoverPoints addObjectsFromArray:[self dragHoverPointsForRect:bounds forPage:page resizeHandle:resizeHandle]];
-                [self dragAnnotationReferenceLine:self.activeAnnotation];
-                self.dragHoverPage = page;
-            }
-            
-            [self setNeedsDisplayAnnotationViewForVisiblePages];
-        } else {
-            [self setCursorForMouse:event];
         }
     }
+    [self.window mouseMoved:event];
 }
 
 - (void)mouseExited:(NSEvent *)event {
@@ -4556,10 +4577,6 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
         newActiveAnnotation = nil;
     }
     
-//    if (([newActiveAnnotation isForm]) && self.toolMode != CFormToolMode) {
-//        newActiveAnnotation = nil;
-//    }
-    
     if([newActiveAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
         if(self.annotationType == CAnnotationTypeInk || self.annotationType == CAnnotationTypeEraser)
             newActiveAnnotation = nil;

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+Tool.h

@@ -29,6 +29,8 @@ typedef NS_ENUM(NSInteger, CAnnotationAlignState) {
 
 + (BOOL)isSelfSignAnnotationType:(CAnnotationType)annotationType;
 
++ (BOOL)isFormAnnotationType:(CAnnotationType)annotationType;
+
 + (BOOL)willDragMouse;
 
 - (void)resetPDFViewAnnotation;

+ 13 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+Tool.m

@@ -75,6 +75,19 @@
     return NO;
 }
 
++ (BOOL)isFormAnnotationType:(CAnnotationType)annotationType {
+    if(CAnnotationTypeRadioButton == annotationType ||
+       CAnnotationTypeCheckBox == annotationType ||
+       CAnnotationTypeTextField == annotationType ||
+       CAnnotationTypeComboBox == annotationType ||
+       CAnnotationTypeListMenu == annotationType ||
+       CAnnotationTypeActionButton == annotationType ||
+       CAnnotationTypeSignature == annotationType) {
+        return YES;
+    }
+    return NO;
+}
+
 + (BOOL)willDragMouse {
     return NSEventTypeLeftMouseDragged == [[[NSApplication sharedApplication] nextEventMatchingMask:(NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged) untilDate:[NSDate distantFuture] inMode:NSEventTrackingRunLoopMode dequeue:NO] type];
 }

+ 1 - 11
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.h

@@ -101,7 +101,7 @@ typedef NS_ENUM(NSInteger, CToolMode) {
     CSelectZoomToolMode,      //区域放大模式
     CFormToolMode,            //Form模式
     CEditPDFToolMode,         //内容编辑模式
-    CEditPDFToolLink,      //添加Link注释模式
+    CEditPDFToolLink,         //添加Link注释模式
     CRedactToolMode,          //密文模式
     CRedactErasureToolMode,   //密文擦除
     CDigitalSignToolMode,     //数字签名
@@ -120,16 +120,6 @@ typedef NS_ENUM(NSUInteger, KMPDFActiveFormsAlignType) {
     KMPDFActiveFormsAlignType_DisVertical
 };
 
-typedef NS_ENUM(NSUInteger, KMPDFViewActiveFormsType) {
-    KMPDFViewActiveFormsType_NotAllform = -1,//注释类型不全为form类型
-    KMPDFViewActiveFormsType_Mix = 0,//包含多种类型的form(全为form)
-    KMPDFViewActiveFormsType_Pure,//单纯只有一种form(全为form)
-    KMPDFViewActiveFormsType_PureSingle,//单纯只有一种form(全为form),个数为1
-    KMPDFViewActiveFormsType_Text,//单纯只有一种form,并且是text(全为form)
-    KMPDFViewActiveFormsType_TextSingle,//单纯只有一种form,并且是text(全为form),个数为1
-    KMPDFViewActiveFormsType_None
-};
-
 typedef NS_ENUM(NSUInteger, KMPDFViewMode) {
     KMPDFViewModeNormal = 0,
     KMPDFViewModeSoft,

+ 16 - 96
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.m

@@ -1496,60 +1496,25 @@ void CPDFListViewOCDrawLineHandles(CGContextRef context, CGRect rect, CGFloat ra
 }
 
 - (BOOL)consistentTypeWithAnnotation:(CPDFAnnotation *)annotation {
-    if (self.annotationType == CAnnotationTypeSignSignature) {
-        if (![annotation isKindOfClass:[CPDFSignatureAnnotation class]])
-            return NO;
-    } else if (self.annotationType == CAnnotationTypeStamp) {
-        if (![annotation isKindOfClass:[CPDFStampAnnotation class]])
-            return NO;
-    } else if (self.annotationType == CAnnotationTypeAnchored) {
-        if (![annotation isKindOfClass:[CPDFTextAnnotation class]])
-            return NO;
-    } else if (self.annotationType == CAnnotationTypeLink) {
-        if (![annotation isKindOfClass:[CPDFLinkAnnotation class]])
-            return NO;
-    } else if (self.annotationType == CAnnotationTypeFreeText) {
-        if (![annotation isKindOfClass:[CPDFFreeTextAnnotation class]])
-            return NO;
-    } else if (self.annotationType == CAnnotationTypeLine || self.annotationType == CAnnotationTypeArrow || self.annotationType == CAnnotationTypeSquare || self.annotationType == CAnnotationTypeCircle) {
-        if (![annotation isKindOfClass:[CPDFLineAnnotation class]] && ![annotation isKindOfClass:[CPDFSquareAnnotation class]] && ![annotation isKindOfClass:[CPDFCircleAnnotation class]])
-            return NO;
-    } else if (self.annotationType == CAnnotationTypeHighlight || self.annotationType == CAnnotationTypeUnderline || self.annotationType == CAnnotationTypeStrikeOut) {
+    if([CPDFListView isMarkupAnnotationType:self.annotationType]) {
         if (![annotation isKindOfClass:[CPDFMarkupAnnotation class]])
             return NO;
-    } else if (self.annotationType == CAnnotationTypeInk) {
-        if (![annotation isKindOfClass:[CPDFInkAnnotation class]])
+    } else if (CAnnotationTypeLink == self.annotationType) {
+        if (![annotation isKindOfClass:[CPDFLinkAnnotation class]])
             return NO;
-    } else if (self.annotationType == CAnnotationTypeRadioButton) {
-        
-    } else if (self.annotationType == CAnnotationTypeCheckBox) {
-        
-    } else if (self.annotationType == CAnnotationTypeTextField) {
-        
-    } else if (self.annotationType == CAnnotationTypeComboBox) {
-        
-    } else if (self.annotationType == CAnnotationTypeListMenu) {
-        
-    } else if (self.annotationType == CAnnotationTypeActionButton) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignature) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignText) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignFalse) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignTure) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignCircle) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignLine) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignDot) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignConfig) {
-        
-    } else if (self.annotationType == CAnnotationTypeSignDate) {
-        
+    } else  {
+        if(CFormToolMode == self.toolMode) {
+            if (![annotation isKindOfClass:[CPDFWidgetAnnotation class]])
+                return NO;
+        } else if(CRedactToolMode == self.toolMode) {
+            if(![annotation isKindOfClass:[CPDFRedactAnnotation class]])
+                return NO;
+        }
+        if ([annotation isForm]) {
+            if (self.toolMode != CFormToolMode)
+                return NO;
+        }
+
     }
     return YES;
 }
@@ -1764,51 +1729,6 @@ void CPDFListViewOCDrawLineHandles(CGContextRef context, CGRect rect, CGFloat ra
 
 #pragma mark - Form Alignment
 
-- (KMPDFViewActiveFormsType)formAnnotionsType:(NSArray *)annotationArray {
-    
-    NSSet *set = [NSSet setWithArray:[annotationArray valueForKey:@"type"]];
-    NSArray *array = [set allObjects];
-    
-    if (array.count > 1 || ![array.firstObject isEqualToString:@"Widget"]) {
-        return KMPDFViewActiveFormsType_NotAllform;
-    }
-    
-    PDFAnnotation *referenceAnnotation = annotationArray.firstObject;
-    Class referenceAnnotationClass = [referenceAnnotation class];
-    if ([referenceAnnotationClass isEqual:[CPDFButtonWidgetAnnotation class]]) {
-        referenceAnnotationClass = [CPDFButtonWidgetAnnotation superclass];
-    }
-    
-    if ([referenceAnnotationClass isEqual:[CPDFTextWidgetAnnotation class]]) {
-        referenceAnnotationClass = [CPDFTextWidgetAnnotation superclass];
-    }
-    
-    if ([referenceAnnotationClass isEqual:[CPDFChoiceWidgetAnnotation class]]) {
-          referenceAnnotationClass = [CPDFChoiceWidgetAnnotation superclass];
-      }
-    
-    if (annotationArray.count == 1) {
-        if ([referenceAnnotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
-            return KMPDFViewActiveFormsType_TextSingle;
-        } else {
-            return KMPDFViewActiveFormsType_PureSingle;
-        }
-    }
-    
-    for (NSInteger i = 0; i < annotationArray.count; i++) {
-        PDFAnnotation *annotation = [annotationArray objectAtIndex:i];
-        if (![annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] && ![annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] && ![annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
-            return KMPDFViewActiveFormsType_Mix;
-        }
-    }
-    
-    if ([referenceAnnotation isKindOfClass:[CPDFTextWidgetAnnotation class]]){
-        return KMPDFViewActiveFormsType_Text;
-    }
-    
-    return KMPDFViewActiveFormsType_Pure;
-}
-
 - (void)changeAnnotations:(NSArray<CPDFAnnotation *> *)annotations alignmentType:(KMPDFActiveFormsAlignType)type {
     CGRect zeroRect = CGRectNull;
     CGRect highestRect = CGRectZero;

+ 14 - 28
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -390,60 +390,46 @@ struct KMNMWCFlags {
             listView.annotationType = .unkown
             
         } else if toolbarMode == .Markup {
+            if subToolMode == .None  {
+                listView.toolMode = .CTextToolMode
+            } else {
+                listView.toolMode = .CNoteToolMode
+            }
             //MARK: -Markup
-            listView.toolMode = .CNoteToolMode
             
             if subToolMode == .None {
                 listView.annotationType = .unkown
             } else if subToolMode == .Highlight {
                 listView.annotationType = .highlight
-                
             } else if subToolMode == .Underline {
                 listView.annotationType = .underline
-                
             } else if subToolMode == .Waveline {
                 listView.annotationType = .squiggly
-                
             } else if subToolMode == .Strikethrough {
                 listView.annotationType = .strikeOut
-                
             } else if subToolMode == .Text {
                 listView.annotationType = .freeText
-                
             } else if subToolMode == .Note {
                 listView.annotationType = .anchored
-                
             } else if subToolMode == .Pen {
                 listView.annotationType = .ink
-                
             } else if subToolMode == .Eraser {
                 listView.annotationType = .eraser
-                
             } else if subToolMode == .Rectangle {
                 listView.annotationType = .square
-                
             } else if subToolMode == .Circle {
                 listView.annotationType = .circle
-                
             } else if subToolMode == .Arrow {
                 listView.annotationType = .arrow
-                
             } else if subToolMode == .Line {
                 listView.annotationType = .line
-                
             } else if subToolMode == .Measure {
-                listView.toolMode = .CNoteToolMode
-                
                 listView.annotationType = .measureLine
-                
             } else if subToolMode == .Stamp {
                 listView.annotationType = .stamp
-                
             } else if subToolMode == .Sign {
                 listView.annotationType = .signSignature
-                
             }
-            
         } else if toolbarMode == .Edit {
             //MARK: -编辑
             if subToolMode == .None {
@@ -477,6 +463,7 @@ struct KMNMWCFlags {
                 
             } else if subToolMode == .Edit_Crop {
                 listView.isHidden = true
+                listView.toolMode = .CCropToolMode
             }
             
             if viewManager.editType == .watermark ||
@@ -484,6 +471,8 @@ struct KMNMWCFlags {
                 viewManager.editType == .header_Footer ||
                 viewManager.editType == .bates {
                 listView.isHidden = true
+                listView.toolMode = .CTextToolMode
+
             }
             
             if subToolMode != .Edit_Crop {
@@ -495,32 +484,29 @@ struct KMNMWCFlags {
             listView.toolMode = .CFormToolMode
             if subToolMode == .None {
                 listView.annotationType = .unkown
-                
             } else if subToolMode == .Form_text {
                 listView.annotationType = .textField
-                
             } else if subToolMode == .Form_checkbox {
                 listView.annotationType = .checkBox
-                
             } else if subToolMode == .Form_radio {
                 listView.annotationType = .radioButton
-                
             } else if subToolMode == .Form_list {
                 listView.annotationType = .listMenu
-                
             } else if subToolMode == .Form_dropdown {
                 listView.annotationType = .comboBox
-                
             } else if subToolMode == .Form_OK {
                 listView.annotationType = .actionButton
-                
             } else if subToolMode == .Form_digitalSign {
-                
+                listView.annotationType = .signature
             }
             
         } else if toolbarMode == .Fill {
             //MARK: -填充
-            listView.toolMode = .CNoteToolMode
+            if subToolMode == .None  {
+                listView.toolMode = .CTextToolMode
+            } else {
+                listView.toolMode = .CNoteToolMode
+            }
             if subToolMode == .None {
                 
             } else if subToolMode == .Fill_tick {