Browse Source

【PDFListView】Pop框弹出修改+ Form注释提示框属性补充

dinglingui 2 years ago
parent
commit
19d2762c97

+ 24 - 0
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/AppKitCategories/CPDFListEditAnnotationViewController.m

@@ -85,6 +85,30 @@
         box.fillColor = self.colors[i];
     }
     
+    if([self.annotation isKindOfClass:[CPDFMarkupAnnotation class]] ||
+       [self.annotation isKindOfClass:[CPDFLineAnnotation class]] ||
+       [self.annotation isKindOfClass:[CPDFSquareAnnotation class]] ||
+       [self.annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
+       [self.annotation isKindOfClass:[CPDFTextAnnotation class]]) {
+        for(NSInteger i = 0;i<self.colors.count;i++) {
+            NSBox *box = self.buttons[i];
+            box.hidden = NO;
+        }
+        self.colorButton1.hidden =
+        self.colorButton2.hidden =
+        self.colorButton3.hidden =
+        self.colorButton4.hidden = NO;
+    } else {
+        for(NSInteger i = 0;i<self.colors.count;i++) {
+            NSBox *box = self.buttons[i];
+            box.hidden = YES;
+        }
+        self.colorButton1.hidden =
+        self.colorButton2.hidden =
+        self.colorButton3.hidden =
+        self.colorButton4.hidden = NO;
+    }
+    
     self.colorBox1.borderColor =
     self.colorBox2.borderColor =
     self.colorBox3.borderColor =

+ 3 - 13
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/AppKitCategories/CPDFListHoverAnnotationViewController.m

@@ -12,6 +12,7 @@
 
 #import "CPDFListHoverAnnotationViewController.h"
 #import "CPDFListView.h"
+#import "CPDFAnnotation+PDFListView.h"
 
 @interface CPDFListHoverAnnotationViewController ()
 
@@ -38,19 +39,8 @@
     self.view.layer.backgroundColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.8].CGColor;
     self.contentLabel.textColor = [NSColor whiteColor];
     
-    if([self.annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
-        CPDFLinkAnnotation *linkAnnotation = (CPDFLinkAnnotation *)self.annotation;
-        CPDFDestination *destination = linkAnnotation.destination;
-        if(destination) {
-            CPDFPage *page = destination.page;
-            self.contentLabel.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Go to Page %ld", nil),[self.pdflistView.document indexForPage:page]+1];
-        } else {
-            NSString *url = linkAnnotation.URL;
-            self.contentLabel.stringValue = url?:@"";
-        }
-    } else {
-        self.contentLabel.stringValue = self.annotation.contents?:@"";
-    }
+    self.contentLabel.stringValue = self.annotation.toolTipsString;
+
 }
 
 

+ 4 - 4
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotation+PDFListView.h

@@ -23,6 +23,8 @@
 
 - (instancetype)initPDFListViewNoteWithDocument:(CPDFDocument *)document;
 
+- (NSSet *)keysForValuesToObserveForUndo;
+
 - (CRectEdges)resizeHandleForPoint:(NSPoint)point scaleFactor:(CGFloat)scaleFactor;
 
 - (void)drawSelectionHighlightForView:(CPDFListView *)pdfView inContext:(CGContextRef)context isHover:(BOOL)isHover;
@@ -35,12 +37,8 @@
 
 - (BOOL)isMovable;
 
-- (CGSize)fetchFormMinSizeValueVia;
-
 - (BOOL)hitTest:(NSPoint)point;
 
-- (NSSet *)keysForValuesToObserveForUndo;
-
 - (CPDFBorderStyle)borderStyle;
 
 - (void)setBorderStyle:(CPDFBorderStyle)style;
@@ -53,4 +51,6 @@
 
 - (void)setDashPattern:(NSArray *)pattern;
 
+- (NSString *)toolTipsString;
+
 @end

+ 18 - 25
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotation+PDFListView.m

@@ -27,6 +27,20 @@
     return self;
 }
 
+- (NSSet *)keysForValuesToObserveForUndo {
+    static NSSet *keys = nil;
+    if (keys == nil)
+        keys = [[NSSet alloc] initWithObjects:CPDFAnnotationBoundsKey,
+                                              CPDFAnnotationContentKey,
+                                              CPDFAnnotationborderWidthKey,
+                                              CPDFAnnotationBorderKey,
+                                              CPDFAnnotationOpacityKey,
+                                              CPDFAnnotationColorKey,
+                                              CPDFAnnotationModificationDateKey,
+                                              CPDFAnnotationUserNameKey, nil];
+    return keys;
+}
+
 - (void)drawSelectionHighlightForView:(CPDFListView *)pdfView inContext:(CGContextRef)context isHover:(BOOL)isHover {
     if (NSIsEmptyRect([self bounds]))
         return;
@@ -79,35 +93,10 @@
     return [self isResizable] ? CPDFListViewResizeHandleForPointFromRect(point, rect, 4.0 / scaleFactor) : 0;
 }
 
-- (CGSize)fetchFormMinSizeValueVia {
-    if ([self isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
-        if ([(CPDFButtonWidgetAnnotation *)self controlType] == CPDFWidgetPushButtonControl) {
-            return CGSizeMake(8.0, 8.0);
-        }
-        return CGSizeMake(2, 2);
-    } else {
-        return CGSizeMake(8.0, 8.0);
-    }
-}
-
 - (BOOL)hitTest:(NSPoint)point {
     return [self shouldDisplay] ? NSPointInRect(point, [self bounds]) : NO;
 }
 
-- (NSSet *)keysForValuesToObserveForUndo {
-    static NSSet *keys = nil;
-    if (keys == nil)
-        keys = [[NSSet alloc] initWithObjects:CPDFAnnotationBoundsKey,
-                                              CPDFAnnotationContentKey,
-                                              CPDFAnnotationborderWidthKey,
-                                              CPDFAnnotationBorderKey,
-                                              CPDFAnnotationOpacityKey,
-                                              CPDFAnnotationColorKey,
-                                              CPDFAnnotationModificationDateKey,
-                                              CPDFAnnotationUserNameKey, nil];
-    return keys;
-}
-
 - (CPDFBorderStyle)borderStyle {
     return [[self border] style];
 }
@@ -139,4 +128,8 @@
     [self setBorder:border];
 }
 
+- (NSString *)toolTipsString {
+    return self.contents?:@"";
+}
+
 @end

+ 2 - 2
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFButtonWidgetAnnotation+PDFListView.h

@@ -14,8 +14,8 @@
 
 @interface CPDFButtonWidgetAnnotation (PDFListView)
 
-- (NSSet *)keysForValuesToObserveForUndo;
-
 - (instancetype)initPDFListViewNoteWithDocument:(CPDFDocument *)document controlType:(CPDFWidgetControlType)controlType;
 
+- (NSSet *)keysForValuesToObserveForUndo;
+
 @end

+ 13 - 0
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFLinkAnnotation+PDFListView.m

@@ -110,4 +110,17 @@
 //    CGContextRestoreGState(context);
 }
 
+- (NSString *)toolTipsString {
+    NSString *contentString = nil;
+    CPDFDestination *destination = self.destination;
+    if(destination) {
+        CPDFPage *page = destination.page;
+        contentString = [NSString stringWithFormat:NSLocalizedString(@"Go to Page %ld", nil),[page.document indexForPage:page]+1];
+    } else {
+        NSString *url = self.URL;
+        contentString = url;
+    }
+    return contentString?:@"";
+}
+
 @end

+ 4 - 0
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFWidgetAnnotation+PDFListView.m

@@ -104,4 +104,8 @@
     return [NSString stringWithFormat:@"%@_%@ %d", annotationType, dateString, rand()%10000];
 }
 
+- (NSString *)toolTipsString {
+    return self.toolTips?:@"";
+}
+
 @end

+ 10 - 3
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/CPDFListView.m

@@ -25,7 +25,7 @@
 #import "CPDFAnnotation+PDFListView.h"
 #import "CPDFSelection+PDFListView.h"
 #import "CPDFPage+PDFListView.h"
-#import "CPDFListView+CExtension.h"
+#import "CPDFListView+Extension.h"
 #import "NSString+PDFListView.h"
 #import "NSImage+PDFListView.h"
 
@@ -428,7 +428,6 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
              bounds.size.height = bounds.size.width/borderScale;
          }
         
-        
         CPDFListStampAnnotation *newAnnotation = [[CPDFListStampAnnotation alloc] initWithDocument:self.document image:image];
         newAnnotation.bounds = bounds;
         [newAnnotation setBorderBoundsWithPImage:image];
@@ -538,7 +537,15 @@ NSNotificationName const CPDFListViewActiveAnnotationsChangeNotification = @"CPD
             vc.changeColorCallBack = ^{
                 blockSelf.popOver.backgroundColor = annotation.color?:[NSColor whiteColor];
             };
-            _popOver.backgroundColor = annotation.color?:[NSColor whiteColor];
+            if([annotation isKindOfClass:[CPDFMarkupAnnotation class]] ||
+               [annotation isKindOfClass:[CPDFLineAnnotation class]] ||
+               [annotation isKindOfClass:[CPDFSquareAnnotation class]] ||
+               [annotation isKindOfClass:[CPDFCircleAnnotation class]] ||
+               [annotation isKindOfClass:[CPDFTextAnnotation class]]) {
+                _popOver.backgroundColor = annotation.color?:[NSColor whiteColor];
+            } else {
+                _popOver.backgroundColor = [NSColor whiteColor];
+            }
             _popOver.animates = YES;
             _popOver.behavior = NSPopoverBehaviorTransient;
             [_popOver showRelativeToRect:[self convertRect:annotation.bounds fromPage:annotation.page] ofView:self preferredEdge:NSMaxXEdge];

+ 7 - 4
PDF Office/PDF Office/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -23,7 +23,7 @@
 #import "NSBezierPath+PDFListView.h"
 #import "CPDFListHoverAnnotationViewController.h"
 
-#import "CPDFListView+CExtension.h"
+#import "CPDFListView+Extension.h"
 #import "CPDFAnnotation+PDFListView.h"
 #import "CPDFInkAnnotation+PDFListView.h"
 #import "CPDFLineAnnotation+PDFListView.h"
@@ -170,9 +170,12 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     
     [CPDFListView cancelPreviousPerformRequestsWithTarget:self selector:@selector(showHUDHint:) object:self.hoverAnnotation];
     
-    if ((CNoteToolMode == self.toolMode ||
-         CTextToolMode == self.toolMode ||
-         CRedactToolMode == self.toolMode) && newActiveAnnotation && ([newActiveAnnotation isKindOfClass:[CPDFTextAnnotation class]]|| [newActiveAnnotation isKindOfClass:[CPDFLinkAnnotation class]]) && (self.hoverAnnotation == newActiveAnnotation) && !self.popOver) {
+    if ((CNoteToolMode == self.toolMode || CTextToolMode == self.toolMode || CRedactToolMode == self.toolMode) &&
+        newActiveAnnotation &&
+        (self.hoverAnnotation == newActiveAnnotation) &&
+        !self.popOver &&
+        newActiveAnnotation.toolTipsString.length > 0 &&
+        ([newActiveAnnotation isKindOfClass:[CPDFTextAnnotation class]] || [newActiveAnnotation isKindOfClass:[CPDFLinkAnnotation class]] || [newActiveAnnotation isKindOfClass:[CPDFWidgetAnnotation class]])) {
         [self performSelector:@selector(showHUDHint:) withObject:newActiveAnnotation afterDelay:1.0];
     } else if ([self isSupportSelectAnnotation] && newActiveAnnotation && [newActiveAnnotation isKindOfClass:[CPDFRedactAnnotation class]] && (self.hoverAnnotation == newActiveAnnotation)) {
         [(CPDFRedactAnnotation *)newActiveAnnotation setDrawRedactionsAsRedacted:YES];