Browse Source

【2025】【综合】
1、Form按钮名称处理
2、组件库ToolTip内容优化

niehaoyu 2 months ago
parent
commit
06ceb8ecd2

+ 11 - 1
PDF Office/KMComponentLibrary/KMComponentLibrary/View/CheckBox/ComponentCheckBox.swift

@@ -64,6 +64,17 @@ public class ComponentCheckBox: ComponentBaseXibView {
         }
     }
     
+    public override var toolTip: String? {
+        didSet {
+            if properties.showhelp {
+                
+                helpTooltips.toolTip = toolTipString
+                
+                toolTipString = nil
+            }
+        }
+    }
+    
     public func reloadData() {
         
         setupUI()
@@ -77,7 +88,6 @@ public class ComponentCheckBox: ComponentBaseXibView {
     }
      
     func setupUI() {
-        
         if (properties.text) != nil {
             titleLabel.stringValue = properties.text ?? ""
             titleLabel.textColor = properties.propertyInfo.textColor

+ 24 - 22
PDF Office/KMComponentLibrary/KMComponentLibrary/View/ComponentBaseXibView.swift

@@ -103,27 +103,29 @@ import AppKit
     }
     
     func showToolTips(_ isMode: Bool = false) {
-        
-        var point = self.convert(self.contentView.frame.origin, to: self.window?.contentView)
-        point.y += CGRectGetHeight(self.frame)
-        
-        if toolTipView == nil {
-            toolTipView = ComponentToolTip()
-        }
-        let properties: ComponentTooltipProperty = ComponentTooltipProperty(arrowPosition: .bottom_Center,
-                                                                            title: self.toolTipString ?? "")
-        
-        toolTipView?.properties = properties
-        
-        if let tipView = toolTipView {
-            point.x += CGRectGetWidth(self.frame)/2
-            point.x -= CGRectGetWidth(tipView.frame)/2
+        if let string = toolTipString, string.count > 0 {
+            var point = self.convert(self.contentView.frame.origin, to: self.window?.contentView)
+            point.y += CGRectGetHeight(self.frame)
+            
+            if toolTipView == nil {
+                toolTipView = ComponentToolTip()
+            }
+            let properties: ComponentTooltipProperty = ComponentTooltipProperty(arrowPosition: .bottom_Center,
+                                                                                title: self.toolTipString ?? "")
+            
+            toolTipView?.properties = properties
+            
+            if let tipView = toolTipView {
+                point.x += CGRectGetWidth(self.frame)/2
+                point.x -= CGRectGetWidth(tipView.frame)/2
+            }
+            toolTipView?.showWithPoint(point, inView: self.window?.contentView)
+            
+            //        if isMode {
+            //            ComponentManager.manager.isTooltipMode = true
+            //        }
+            
         }
-        toolTipView?.showWithPoint(point, inView: self.window?.contentView)
-        
-//        if isMode {
-//            ComponentManager.manager.isTooltipMode = true
-//        }
     }
     
     func hideToolTips() {
@@ -136,7 +138,7 @@ import AppKit
     public override func mouseEntered(with event: NSEvent) {
         super.mouseEntered(with: event)
         
-        if self.toolTipString != nil {
+        if let string = toolTipString, string.count > 0 {
             //Tooltips
             let newWorkItem = DispatchWorkItem {
                 self.showToolTips(true)
@@ -160,7 +162,7 @@ import AppKit
     public override func mouseExited(with event: NSEvent) {
         super.mouseExited(with: event)
         
-        if toolTipString != nil {
+        if let string = toolTipString, string.count > 0 {
             workItem.cancel()
             
             hideToolTips()

+ 11 - 0
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Radio/ComponentRadio.swift

@@ -51,6 +51,17 @@ public class ComponentRadio: ComponentBaseXibView {
     
     // MARK: - Set & Get
     
+    public override var toolTip: String? {
+        didSet {
+            if properties.showhelp {
+                
+                helpTooltips.toolTip = toolTipString
+                
+                toolTipString = nil
+            }
+        }
+    }
+    
     public var properties : ComponentCheckBoxProperty {
         get {
            return _properties

+ 19 - 6
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/Form/CPDFButtonWidgetAnnotation+PDFListView.swift

@@ -108,12 +108,25 @@ import Foundation
             return string
         }
         var availableIndex = 1
-        for annotation in page.annotations {
-            if annotation is CPDFButtonWidgetAnnotation {
-                let name = (annotation as! CPDFButtonWidgetAnnotation).fieldName() ?? ""
-                if name.hasPrefix(string) {
-                    if let index = Int(name.dropFirst(string.count)), index >= availableIndex {
-                        availableIndex = index + 1
+        if controlType() == .radioButtonControl {
+            for annotation in page.annotations {
+                if annotation is CPDFButtonWidgetAnnotation {
+                    let name = (annotation as! CPDFButtonWidgetAnnotation).buttonWidgetStateString() ?? ""
+                    if name.hasPrefix(string) {
+                        if let index = Int(name.dropFirst(string.count)), index >= availableIndex {
+                            availableIndex = index + 1
+                        }
+                    }
+                }
+            }
+        } else {
+            for annotation in page.annotations {
+                if annotation is CPDFButtonWidgetAnnotation {
+                    let name = (annotation as! CPDFButtonWidgetAnnotation).fieldName() ?? ""
+                    if name.hasPrefix(string) {
+                        if let index = Int(name.dropFirst(string.count)), index >= availableIndex {
+                            availableIndex = index + 1
+                        }
                     }
                 }
             }

+ 6 - 3
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFListViewExtension/CPDFListView+Event.m

@@ -4219,8 +4219,11 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     if (newAnnotation) {
         [newAnnotation registerUserName];
         if (type == CAnnotationTypeRadioButton) {
-            [(CPDFWidgetAnnotation *)newAnnotation setFieldName:@"Group1"];
-            [(CPDFButtonWidgetAnnotation *)newAnnotation setOnStateValue:[(CPDFButtonWidgetAnnotation *)newAnnotation getValidNameInPage:page]];
+            [(CPDFButtonWidgetAnnotation *)newAnnotation setFieldName:@"Group1"];
+            NSString *validStr = [(CPDFButtonWidgetAnnotation *)newAnnotation getValidNameInPage:page];
+            [(CPDFButtonWidgetAnnotation *)newAnnotation setButtonWidgetStateString: validStr];
+//            NSString *test = [(CPDFButtonWidgetAnnotation *)newAnnotation buttonWidgetStateString];
+//            NSLog(@"1");
         } else {
             NSString *annotationType = @"";
             if (type == CAnnotationTypeCheckBox) {
@@ -5399,7 +5402,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
                             }
                         } else if ([newAnnotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
                             if ([(CPDFButtonWidgetAnnotation * )newAnnotation controlType] == CPDFWidgetRadioButtonControl) {
-                                annotationType = [(CPDFButtonWidgetAnnotation * )newAnnotation getValidNameInPage:page];
+                                annotationType = @"Group1";
                             } else if ([(CPDFButtonWidgetAnnotation * )newAnnotation controlType] == CPDFWidgetCheckBoxControl) {
                                 annotationType = [(CPDFButtonWidgetAnnotation * )newAnnotation getValidNameInPage:page];
                             } else if ([(CPDFButtonWidgetAnnotation * )newAnnotation controlType] == CPDFWidgetPushButtonControl) {

+ 1 - 0
PDF Office/PDF Master/KMClass/ComponentLibraryDemo/Demo/CheckBoxVC.swift

@@ -81,6 +81,7 @@ class CheckBoxVC: NSViewController {
         }
         
         let properties: ComponentCheckBoxProperty = ComponentCheckBoxProperty.init(size: size, state: .normal, isDisabled: isDisabel, showhelp: showhelp, text: string, checkboxType: checkboxType)
+        checkBox.toolTip = "12312312312312"
         checkBox.properties = properties
         
         

+ 3 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/Toolbar/Model/KMPDFToolbarManager.swift

@@ -280,6 +280,9 @@ class KMPDFToolbarManager: NSObject {
                     validRightPropertys.append(buttonProperty)
                 }
             }
+            if propertys.contains(shareProperty.identifier) {
+                validRightPropertys.append(shareProperty)
+            }
         } else {
             validRightPropertys = [undoProperty, redoProperty, printProperty, shareProperty]
         }