Browse Source

【OCToSwift】KMTableRowView替换为Swift

wanjun 1 year ago
parent
commit
9bb559ba01

+ 8 - 10
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -994,6 +994,9 @@
 		9FD0D2A72AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2A62AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift */; };
 		9FD0D2A82AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2A62AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift */; };
 		9FD0D2A92AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2A62AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift */; };
+		9FD0D2AB2AD5143D00DA3FF8 /* KMTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2AA2AD5143D00DA3FF8 /* KMTableRowView.swift */; };
+		9FD0D2AC2AD5143D00DA3FF8 /* KMTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2AA2AD5143D00DA3FF8 /* KMTableRowView.swift */; };
+		9FD0D2AD2AD5143D00DA3FF8 /* KMTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2AA2AD5143D00DA3FF8 /* KMTableRowView.swift */; };
 		9FD0FA2929CD3ED400F2AB0D /* KMRightSideEmptyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0FA2729CD3ED400F2AB0D /* KMRightSideEmptyVC.swift */; };
 		9FD0FA2A29CD3ED400F2AB0D /* KMRightSideEmptyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0FA2729CD3ED400F2AB0D /* KMRightSideEmptyVC.swift */; };
 		9FD0FA2B29CD3ED400F2AB0D /* KMRightSideEmptyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0FA2729CD3ED400F2AB0D /* KMRightSideEmptyVC.swift */; };
@@ -2887,9 +2890,6 @@
 		BBAFC84D298519F700D0648E /* KMSavePanelAccessoryController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BBAFC849298519F600D0648E /* KMSavePanelAccessoryController.xib */; };
 		BBAFC84E298519F700D0648E /* KMSavePanelAccessoryController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BBAFC849298519F600D0648E /* KMSavePanelAccessoryController.xib */; };
 		BBAFC84F298519F700D0648E /* KMSavePanelAccessoryController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BBAFC849298519F600D0648E /* KMSavePanelAccessoryController.xib */; };
-		BBAFC85B29851AF200D0648E /* KMTableRowView.m in Sources */ = {isa = PBXBuildFile; fileRef = BBAFC85629851AF200D0648E /* KMTableRowView.m */; };
-		BBAFC85C29851AF200D0648E /* KMTableRowView.m in Sources */ = {isa = PBXBuildFile; fileRef = BBAFC85629851AF200D0648E /* KMTableRowView.m */; };
-		BBAFC85D29851AF200D0648E /* KMTableRowView.m in Sources */ = {isa = PBXBuildFile; fileRef = BBAFC85629851AF200D0648E /* KMTableRowView.m */; };
 		BBAFFB1B29CDD19C00C56112 /* KMMergeSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBAFFB1A29CDD19C00C56112 /* KMMergeSelect.swift */; };
 		BBAFFB1C29CDD19C00C56112 /* KMMergeSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBAFFB1A29CDD19C00C56112 /* KMMergeSelect.swift */; };
 		BBAFFB1D29CDD19C00C56112 /* KMMergeSelect.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBAFFB1A29CDD19C00C56112 /* KMMergeSelect.swift */; };
@@ -3894,6 +3894,7 @@
 		9FCFECA72AD243C800EAD2CB /* KMBlankView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMBlankView.swift; sourceTree = "<group>"; };
 		9FD0D2A22AD4ECA800DA3FF8 /* KMPDFEditAppendCustomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPDFEditAppendCustomView.swift; sourceTree = "<group>"; };
 		9FD0D2A62AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSavePanelAccessoryController.swift; sourceTree = "<group>"; };
+		9FD0D2AA2AD5143D00DA3FF8 /* KMTableRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMTableRowView.swift; sourceTree = "<group>"; };
 		9FD0FA2729CD3ED400F2AB0D /* KMRightSideEmptyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRightSideEmptyVC.swift; sourceTree = "<group>"; };
 		9FD0FA2829CD3ED400F2AB0D /* KMRightSideEmptyVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMRightSideEmptyVC.xib; sourceTree = "<group>"; };
 		9FD0FA2F29CD947000F2AB0D /* KMOpacityPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMOpacityPanel.swift; sourceTree = "<group>"; };
@@ -4622,8 +4623,6 @@
 		BBAFC842298519A400D0648E /* KMFileAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMFileAttribute.m; sourceTree = "<group>"; };
 		BBAFC843298519A400D0648E /* KMFileAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMFileAttribute.h; sourceTree = "<group>"; };
 		BBAFC849298519F600D0648E /* KMSavePanelAccessoryController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMSavePanelAccessoryController.xib; sourceTree = "<group>"; };
-		BBAFC85629851AF200D0648E /* KMTableRowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMTableRowView.m; sourceTree = "<group>"; };
-		BBAFC85729851AF200D0648E /* KMTableRowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMTableRowView.h; sourceTree = "<group>"; };
 		BBAFFB1A29CDD19C00C56112 /* KMMergeSelect.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMMergeSelect.swift; sourceTree = "<group>"; };
 		BBB14A522978DD5400936EDB /* KMRedactTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRedactTools.swift; sourceTree = "<group>"; };
 		BBB14A562978E75D00936EDB /* KMRedactMutilPageFlagWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRedactMutilPageFlagWindowController.swift; sourceTree = "<group>"; };
@@ -8585,8 +8584,7 @@
 				BBAFC83B2985194800D0648E /* KMPDFEditAppendWindow.xib */,
 				9FD0D2A62AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift */,
 				BBAFC849298519F600D0648E /* KMSavePanelAccessoryController.xib */,
-				BBAFC85729851AF200D0648E /* KMTableRowView.h */,
-				BBAFC85629851AF200D0648E /* KMTableRowView.m */,
+				9FD0D2AA2AD5143D00DA3FF8 /* KMTableRowView.swift */,
 			);
 			path = OCPart;
 			sourceTree = "<group>";
@@ -10410,6 +10408,7 @@
 				ADF1569329A62D1D001D1018 /* KMLoginLeftImageView.swift in Sources */,
 				BBA762D229D2D98D00844513 /* KMCommonDefine.swift in Sources */,
 				AD867F9C29D9853200F00440 /* KMBOTAOutlineRowView.swift in Sources */,
+				9FD0D2AB2AD5143D00DA3FF8 /* KMTableRowView.swift in Sources */,
 				BB146FDB299DC0D100784A6A /* GTLRDriveService.m in Sources */,
 				F37322E7292DF9410013862C /* CPDFAnnotationModel.m in Sources */,
 				9FBA0EF92900188F001117AF /* KMFastToolCollectionView.swift in Sources */,
@@ -10649,7 +10648,6 @@
 				BB897229294B08720045787C /* KMWatermarkAdjectiveTopBarItemModel.swift in Sources */,
 				BB00301D298CB799002DD1A0 /* KMPreferenceManager.swift in Sources */,
 				89E93EFA299CB4C200F10F66 /* KMOCRBox.m in Sources */,
-				BBAFC85B29851AF200D0648E /* KMTableRowView.m in Sources */,
 				ADBC2D28299DCA76006280C8 /* NSTextField+Layer.swift in Sources */,
 				89E4E7222963FB23002DBA6F /* KMGeneralButton.m in Sources */,
 				ADF6B8762A48155E0090CB78 /* KMComparativeViewCollectionItem.swift in Sources */,
@@ -11449,7 +11447,6 @@
 				BB00301E298CB799002DD1A0 /* KMPreferenceManager.swift in Sources */,
 				89E93EFB299CB4C200F10F66 /* KMOCRBox.m in Sources */,
 				ADA9102F2A272CEA003352F0 /* KMImageOptimization.swift in Sources */,
-				BBAFC85C29851AF200D0648E /* KMTableRowView.m in Sources */,
 				AD9527DC2952EE700039D2BC /* KMPrintPage_C.swift in Sources */,
 				ADBC2D29299DCA76006280C8 /* NSTextField+Layer.swift in Sources */,
 				89E4E7232963FB23002DBA6F /* KMGeneralButton.m in Sources */,
@@ -11506,6 +11503,7 @@
 				9F1FE49429406E4700E952CA /* common.m in Sources */,
 				AD0FA51329A9FA8600EDEB50 /* KMResetPasswordView.swift in Sources */,
 				9F0201732A1B488C00C9B673 /* KMAITranslationVC.swift in Sources */,
+				9FD0D2AC2AD5143D00DA3FF8 /* KMTableRowView.swift in Sources */,
 				BBFBE74728DD7DB7008B2335 /* ViewController.swift in Sources */,
 				9FDD0F812952FC36000C4DAD /* KMDesignToken.swift in Sources */,
 				ADF6B8772A48155E0090CB78 /* KMComparativeViewCollectionItem.swift in Sources */,
@@ -12536,7 +12534,6 @@
 				AD9527D92952ED970039D2BC /* KMPrintPresenter_C.swift in Sources */,
 				9F0CB4E32986556400007028 /* KMDesignToken+PaddingTop.swift in Sources */,
 				BB2EDF6F296ECE17003BCF58 /* KMPageEditInsertDirectionItemView.swift in Sources */,
-				BBAFC85D29851AF200D0648E /* KMTableRowView.m in Sources */,
 				8942F80529262B2E00389627 /* KMSideViewController.swift in Sources */,
 				BB74DA812AC42959006EDFE7 /* NSButton+KMExtension.swift in Sources */,
 				9F0CB4F3298655BC00007028 /* KMDesignToken+ItemSpacing.swift in Sources */,
@@ -12636,6 +12633,7 @@
 				AD0E8ABB2A31BDDD00DBFD3C /* KMProduct.swift in Sources */,
 				BBC2BCC8295DA8F30036B983 /* KMCropPreviewController.swift in Sources */,
 				9F1FE50F29407B2B00E952CA /* KMUploadFilePanel.swift in Sources */,
+				9FD0D2AD2AD5143D00DA3FF8 /* KMTableRowView.swift in Sources */,
 				ADC0761C298A2E67006C752F /* KMBatchSecurityViewPresenter.swift in Sources */,
 				BB146FCB299DC0D100784A6A /* GTMSessionFetcher.m in Sources */,
 				9F0CB4CF298654FA00007028 /* KMDesignToken+Height.swift in Sources */,

+ 0 - 23
PDF Office/PDF Master/Class/Merge/OCPart/KMTableRowView.h

@@ -1,23 +0,0 @@
-//
-//  KMTableRowView.h
-//  PDF Reader Pro Edition
-//
-//  Created by zhipeng jiang on 2020/11/25.
-//
-
-#import <Cocoa/Cocoa.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface KMTableRowView : NSTableRowView
-
-@property (nonatomic, assign) BOOL hasBottomLine;
-@property (nonatomic, strong) NSColor *bottomLineColor;
-
-@property (nonatomic, assign) NSEdgeInsets selectionInset;
-@property (nonatomic, assign) CGFloat selectionRadius;
-@property (nonatomic, copy) NSColor *(^selectionBackgroundColorBlock)(void);
-
-@end
-
-NS_ASSUME_NONNULL_END

+ 0 - 84
PDF Office/PDF Master/Class/Merge/OCPart/KMTableRowView.m

@@ -1,84 +0,0 @@
-//
-//  KMTableRowView.m
-//  PDF Reader Pro Edition
-//
-//  Created by zhipeng jiang on 2020/11/25.
-//
-
-#import "KMTableRowView.h"
-
-@implementation KMTableRowView
-
-- (instancetype)init {
-    self = [super init];
-    if (self) {
-        [self addTrackingArea];
-        
-        self.selectionInset = NSEdgeInsetsZero;
-        self.selectionRadius = 0.f;
-    }
-    return self;
-}
-
-- (void)setHasBottomLine:(BOOL)hasBottomLine {
-    _hasBottomLine = hasBottomLine;
-    
-    [self setNeedsDisplay:YES];
-}
-
-- (void)setBottomLineColor:(NSColor *)bottomLineColor {
-    _bottomLineColor = bottomLineColor;
-    
-    [self setNeedsDisplay:YES];
-}
-
-#pragma mark - Private Methods
-
-- (void)addTrackingArea {
-    NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds options:NSTrackingMouseEnteredAndExited | NSTrackingInVisibleRect | NSTrackingActiveAlways |NSTrackingMouseMoved owner:self userInfo:nil];
-    [self addTrackingArea:trackingArea];
-}
-
-- (void)drawRect:(NSRect)dirtyRect {
-    [super drawRect:dirtyRect];
-    
-    if (self.hasBottomLine) {
-        NSColor *color = self.bottomLineColor;
-        if (color == nil) {
-            color = [NSColor lightGrayColor];
-        }
-        [color setStroke];
-        [color setFill];
-        NSRect lineRect = NSMakeRect(0, NSHeight(self.bounds)-1, NSWidth(self.bounds), 1);
-        NSBezierPath *linePath = [NSBezierPath bezierPathWithRoundedRect:lineRect xRadius:0 yRadius:0];
-        [linePath fill];
-        [linePath stroke];
-    }
-}
-
-- (void)drawSelectionInRect:(NSRect)dirtyRect {
-    if (!self.selectionBackgroundColorBlock) {
-//        [super drawSelectionInRect:dirtyRect];
-        NSRect selectionRect = self.bounds;
-        [[NSColor lightGrayColor] setFill];
-        NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect xRadius:0 yRadius:0];
-        [selectionPath fill];
-        return;
-    }
-
-//    NSRect selectionRect = NSInsetRect(self.bounds, 0, 0);
-    NSRect selectionRect = NSMakeRect(self.selectionInset.left, self.selectionInset.top, NSWidth(self.bounds)-self.selectionInset.left-self.selectionInset.right, NSHeight(self.bounds)-self.selectionInset.top-self.selectionInset.bottom);
-    NSColor *color = self.selectionBackgroundColorBlock();
-    [color setStroke];
-    [color setFill];
-    
-    NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect xRadius:self.selectionRadius yRadius:self.selectionRadius];
-    [selectionPath fill];
-    [selectionPath stroke];
-}
-
-- (void)mouseEntered:(NSEvent *)event {
-    [super mouseEntered:event];
-}
-
-@end

+ 98 - 0
PDF Office/PDF Master/Class/Merge/OCPart/KMTableRowView.swift

@@ -0,0 +1,98 @@
+//
+//  KMTableRowView.swift
+//  PDF Master
+//
+//  Created by wanjun on 2023/10/10.
+//
+
+import Cocoa
+
+class KMTableRowView: NSTableRowView {
+    
+    var _hasBottomLine: Bool = false
+    var _bottomLineColor: NSColor?
+
+    var selectionInset: NSEdgeInsets = NSEdgeInsets()
+    @objc var selectionRadius: CGFloat = 0.0
+    @objc var selectionBackgroundColorBlock: (() -> NSColor)?
+
+    override init(frame frameRect: NSRect) {
+        super.init(frame: frameRect)
+        addTrackingArea()
+        selectionInset = NSEdgeInsetsZero
+        selectionRadius = 0.0
+    }
+    
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
+    }
+    
+    var hasBottomLine: Bool {
+        get {
+            return _hasBottomLine
+        }
+        set {
+            _hasBottomLine = newValue
+            self.needsDisplay = true
+        }
+    }
+    
+    var bottomLineColor: NSColor? {
+        get {
+            return _bottomLineColor
+        }
+        set {
+            _bottomLineColor = newValue
+            self.needsDisplay = true
+        }
+    }
+    
+    //MARK: Private Methods
+    
+    func addTrackingArea() {
+        let trackingArea = NSTrackingArea.init(rect: self.bounds, options: [.mouseEnteredAndExited, .inVisibleRect, .activeAlways, .mouseMoved], owner: self)
+        self.addTrackingArea(trackingArea)
+    }
+
+    override func draw(_ dirtyRect: NSRect) {
+        super.draw(dirtyRect)
+        
+        if self.hasBottomLine {
+            var color = self.bottomLineColor
+            if color == nil {
+                color = NSColor.lightGray
+            }
+            color!.setStroke()
+            color!.setFill()
+            
+            let lineRect = NSRect(x: 0, y: NSHeight(bounds) - 1, width: NSWidth(bounds), height: 1)
+            let linePath = NSBezierPath(roundedRect: lineRect, xRadius: 0, yRadius: 0)
+            linePath.fill()
+            linePath.stroke()
+        }
+    }
+
+    override func drawSelection(in dirtyRect: NSRect) {
+        if selectionBackgroundColorBlock == nil {
+            let selectionRect = NSRect(x: selectionInset.left, y: selectionInset.top, width: NSWidth(bounds) - selectionInset.left - selectionInset.right, height: NSHeight(bounds) - selectionInset.top - selectionInset.bottom)
+            NSColor.lightGray.setFill()
+            let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: selectionRadius, yRadius: selectionRadius)
+            selectionPath.fill()
+            return
+        }
+
+        let selectionRect = NSRect(x: selectionInset.left, y: selectionInset.top, width: NSWidth(bounds) - selectionInset.left - selectionInset.right, height: NSHeight(bounds) - selectionInset.top - selectionInset.bottom)
+        let color = selectionBackgroundColorBlock!()
+        color.setStroke()
+        color.setFill()
+
+        let selectionPath = NSBezierPath(roundedRect: selectionRect, xRadius: selectionRadius, yRadius: selectionRadius)
+        selectionPath.fill()
+        selectionPath.stroke()
+    }
+
+    override func mouseEntered(with event: NSEvent) {
+        super.mouseEntered(with: event)
+    }
+
+}

+ 0 - 1
PDF Office/PDF Master/PDF_Master DMG-Bridging-Header.h

@@ -62,4 +62,3 @@
 #import "KMRecommondManager.h"
 #import "CPDFListView+Extension.h"
 #import <Sparkle/Sparkle.h>
-#import "KMTableRowView.h"

+ 0 - 1
PDF Office/PDF Master/PDF_Master Pro-Bridging-Header.h

@@ -42,4 +42,3 @@
 //广告
 #import "KMRecommondManager.h"
 #import "CPDFListView+Extension.h"
-#import "KMTableRowView.h"

+ 0 - 1
PDF Office/PDF Master/PDF_Master-Bridging-Header.h

@@ -62,4 +62,3 @@
 
 #import "NSGeometry+PDFListView.h"
 #import "CPDFAnnotationHeader.h"
-#import "KMTableRowView.h"