Browse Source

【2025】【Layout】工具栏极限状态 逻辑处理

niehaoyu 4 months ago
parent
commit
6d871e60fb

+ 7 - 7
PDF Office/KMComponentLibrary/KMComponentLibrary/View/Tabs/ComponentTabsItem.xib

@@ -6,7 +6,7 @@
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="ComponentTabsItem" customModule="WComponentLibrary" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="ComponentTabsItem" customModule="KMComponentLibrary" customModuleProvider="target">
             <connections>
                 <outlet property="contendBox" destination="CtO-CW-nGf" id="nQu-iZ-v2R"/>
                 <outlet property="iconImage" destination="O1i-7D-OT9" id="IXC-KT-2a2"/>
@@ -23,14 +23,14 @@
             <rect key="frame" x="0.0" y="0.0" width="87" height="32"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <box boxType="custom" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="CtO-CW-nGf">
+                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="CtO-CW-nGf">
                     <rect key="frame" x="0.0" y="0.0" width="87" height="32"/>
                     <view key="contentView" id="0rP-N9-KAg">
-                        <rect key="frame" x="1" y="1" width="85" height="30"/>
+                        <rect key="frame" x="0.0" y="0.0" width="87" height="32"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Amh-dO-tdg">
-                                <rect key="frame" x="34" y="7" width="37" height="16"/>
+                                <rect key="frame" x="34" y="9" width="37" height="16"/>
                                 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
                                 <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="39d-xc-W1E">
                                     <font key="font" usesAppearanceFont="YES"/>
@@ -39,14 +39,14 @@
                                 </textFieldCell>
                             </textField>
                             <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="O1i-7D-OT9">
-                                <rect key="frame" x="16" y="7" width="16" height="16"/>
+                                <rect key="frame" x="16" y="8" width="16" height="16"/>
                                 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
                                 <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="segmented_active" id="R39-H4-k5a"/>
                             </imageView>
                             <box boxType="custom" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="QCe-dR-x7e">
-                                <rect key="frame" x="0.0" y="0.0" width="85" height="3"/>
+                                <rect key="frame" x="0.0" y="0.0" width="87" height="3"/>
                                 <view key="contentView" id="QPs-Qp-vKz">
-                                    <rect key="frame" x="1" y="1" width="83" height="1"/>
+                                    <rect key="frame" x="1" y="1" width="85" height="1"/>
                                     <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                 </view>
                                 <constraints>

+ 91 - 45
PDF Office/PDF Master/KMClass/KMPDFViewController/Toolbar/KMPDFToolbarController.swift

@@ -11,11 +11,11 @@ import KMComponentLibrary
 @objc protocol KMPDFToolbarControllerDelegate: AnyObject {
     
     @objc optional func kmPDFToolbarControllerDidToolbarItemClicked(_ controller: KMPDFToolbarController, _ itemIdentifier: String)
- 
+    
 }
 
 class KMPDFToolbarController: NSViewController {
-
+    
     @IBOutlet var contendBox: NSBox!
     
     @IBOutlet var mainToolbarContendView: NSView!
@@ -33,9 +33,13 @@ class KMPDFToolbarController: NSViewController {
     @IBOutlet var tabsMoreButton: ComponentButton!
     
     @IBOutlet var rightToolsView: NSView!
-     
+    
     @IBOutlet var secondContendView: NSView!
     
+    @IBOutlet var tabsLeftConst: NSLayoutConstraint!
+    @IBOutlet var tabsRightConst: NSLayoutConstraint!
+    
+    
     @IBOutlet var rightViewWidthConst: NSLayoutConstraint!
     
     var scrollDocumentView: NSView = NSView.init()
@@ -64,39 +68,48 @@ class KMPDFToolbarController: NSViewController {
     private var convert_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Convert"), identifier: "markup_Menuitem_PropertyKey")
     private var protect_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Protect"), identifier: "markup_Menuitem_PropertyKey")
     private var tools_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Tools"), identifier: "markup_Menuitem_PropertyKey")
- 
+    
     var pdfView: CPDFListView?
     
     var secondToolBar: KMPDFSecToolbarController = KMPDFSecToolbarController.init()
     
     weak open var delegate: KMPDFToolbarControllerDelegate?
-
-    
-    override func viewDidLayout() {
-        super.viewDidLayout()
-     
-    }
     
     override func viewWillLayout() {
         super.viewWillLayout()
         
-        tabsScrollView.frame = CGRectMake(max(0, CGRectGetWidth(tabsContendView.frame)/2 - tabsView.viewWidth/2),
-                                          0,
-                                          min(tabsView.viewWidth, CGRectGetWidth(tabsContendView.frame)-21),
-                                          tabsContendView.frame.size.height)
-
-        if tabsView.viewWidth > CGRectGetWidth(tabsContendView.frame)-21 {
-            tabsMoreButton.isHidden = false
+        var pointX: CGFloat = (CGRectGetWidth(view.frame) - tabsView.viewWidth)/2
+        
+        var xValue: CGFloat = 0
+        
+        if pointX-12-264 > 10 {
+            xValue = pointX - 12 - 264
+            tabsLeftConst.constant = xValue
+            tabsRightConst.constant = CGRectGetWidth(view.frame) - tabsView.viewWidth - 12 - 264 - rightViewWidthConst.constant - 12 - xValue
         } else {
-            tabsMoreButton.isHidden = true
+            xValue = 10
+            let rightXValue = CGRectGetWidth(view.frame) - tabsView.viewWidth - 12 - 264 - rightViewWidthConst.constant - 12 - xValue
+            
+            if rightXValue < 10 {
+                tabsMoreButton.superview?.isHidden = false
+                tabsRightConst.constant = 44
+            } else {
+                tabsMoreButton.superview?.isHidden = true
+                tabsRightConst.constant = rightXValue
+            }
         }
- 
+    }
+    
+    override func viewDidLayout() {
+        super.viewDidLayout()
+        
+        refreshTabsScrollViewVisiableRect()
     }
     
     override func viewDidLoad() {
         super.viewDidLoad()
         // Do view setup here.
-         
+        
         contendBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
         
         leftToolsView.wantsLayer = true
@@ -108,6 +121,9 @@ class KMPDFToolbarController: NSViewController {
         tabsContendView.wantsLayer = true
         tabsContendView.layer?.backgroundColor = contendBox.fillColor.cgColor
         
+        tabsMoreButton.superview?.wantsLayer = true
+        tabsMoreButton.superview?.layer?.backgroundColor = contendBox.fillColor.cgColor
+        
         tabsView = ComponentTabs.init()
         
         scrollDocumentView.wantsLayer = true
@@ -135,22 +151,22 @@ class KMPDFToolbarController: NSViewController {
         
         toolsView.properties = KMPDFToolbarManager.manager.toolsProperty
         toolsView.delegate = self
-     
+        
         selectZoom.properties = KMPDFToolbarManager.manager.selectZoomProperty
         selectZoom.delegate = self
         
-        tabsView.updateItemProperty([KMPDFToolbarManager.manager.markupMode_Property, 
+        tabsView.updateItemProperty([KMPDFToolbarManager.manager.markupMode_Property,
                                      KMPDFToolbarManager.manager.editMode_Property,
-                                     KMPDFToolbarManager.manager.formMode_Property, 
+                                     KMPDFToolbarManager.manager.formMode_Property,
                                      KMPDFToolbarManager.manager.fillMode_Property,
-                                     KMPDFToolbarManager.manager.convertMode_Property, 
+                                     KMPDFToolbarManager.manager.convertMode_Property,
                                      KMPDFToolbarManager.manager.protectMode_Property,
                                      KMPDFToolbarManager.manager.toolsMode_Property])
         tabsView.frame = CGRectMake(0, 0, tabsView.viewWidth, CGRectGetHeight(tabsContendView.frame))
         tabsView.delegate = self
         
-        tabsScrollView.frame = CGRectMake(CGRectGetWidth(tabsContendView.frame)/2 - tabsView.viewWidth/2, 0, tabsView.viewWidth, tabsContendView.frame.size.height)
-        tabsScrollView.autoresizingMask = [.minXMargin, .maxXMargin]
+        //        tabsScrollView.frame = CGRectMake(CGRectGetWidth(tabsContendView.frame)/2 - tabsView.viewWidth/2, 0, tabsView.viewWidth, tabsContendView.frame.size.height)
+        //        tabsScrollView.autoresizingMask = [.minXMargin, .maxXMargin]
         
         scrollDocumentView.frame = CGRectMake(0, 0, tabsView.viewWidth, 28)
         
@@ -158,7 +174,7 @@ class KMPDFToolbarController: NSViewController {
         tabsView.autoresizingMask = [.width, .height]
         
         scrollDocumentView.addSubview(tabsView)
-
+        
         tabsMoreButton.properties = ComponentButtonProperty(type: .text_gray,
                                                             size: .xs,
                                                             onlyIcon: true,
@@ -173,7 +189,7 @@ class KMPDFToolbarController: NSViewController {
                             ppt_Menuitem_Property,
                             print_Menuitem_Property,
                             share_Menuitem_Property]
-         
+        
         moreTabsItems = [markup_Menuitem_Property,
                          edit_Menuitem_Property,
                          form_Menuitem_Property,
@@ -181,8 +197,8 @@ class KMPDFToolbarController: NSViewController {
                          convert_Menuitem_Property,
                          protect_Menuitem_Property,
                          tools_Menuitem_Property]
-                         
-                         
+        
+        
     }
     
     //MARK: - 刷新一级工具栏
@@ -228,6 +244,35 @@ class KMPDFToolbarController: NSViewController {
         
     }
     
+    func refreshTabsScrollViewVisiableRect() {
+        if tabsView.viewWidth > CGRectGetWidth(tabsContendView.frame)-21 {
+            if KMPDFManager.manager.toolMode != .None {
+                var pointx: CGFloat = 0
+                print(tabsScrollView.documentVisibleRect)
+                let _manager = KMPDFToolbarManager.manager
+                
+                if KMPDFManager.manager.toolMode == .Markup {
+                    pointx = 0
+                } else if KMPDFManager.manager.toolMode == .Edit {
+                    pointx = _manager.markupMode_Property.propertyInfo.viewWidth
+                } else if KMPDFManager.manager.toolMode == .Form {
+                    pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth
+                } else if KMPDFManager.manager.toolMode == .Fill {
+                    pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth
+                } else if KMPDFManager.manager.toolMode == .Convert {
+                    pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth
+                } else if KMPDFManager.manager.toolMode == .Protect {
+                    pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.convertMode_Property.propertyInfo.viewWidth
+                } else if KMPDFManager.manager.toolMode == .Tools {
+                    pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.convertMode_Property.propertyInfo.viewWidth + _manager.protectMode_Property.propertyInfo.viewWidth
+                }
+                if tabsScrollView.documentVisibleRect.origin.x > pointx {
+                    tabsScrollView.scroll(tabsScrollView.contentView, to: CGPoint(x: pointx, y: 0))
+                }
+            }
+        }
+    }
+    
     //MARK: -右侧工具模块
     func setUpRightViews() {
         let subviews = rightToolsView.subviews
@@ -259,7 +304,7 @@ class KMPDFToolbarController: NSViewController {
                 adddividerB = true
             }
         }
-             
+        
         for property in _manager.validRightPropertys {
             if adddividerA == true {
                 if property == _manager.aiToolsProperty ||
@@ -324,7 +369,7 @@ class KMPDFToolbarController: NSViewController {
         itemXvalue -= 12
         
         rightViewWidthConst.constant = itemXvalue
-         
+        
     }
     
     //MARK: - 二级工具栏
@@ -453,11 +498,11 @@ class KMPDFToolbarController: NSViewController {
         if (customRightGroupView?.superview) != nil {
             return
         }
-    
+        
         updateRightMenuItemSelectedState()
         
         let items: [ComponentMenuitemProperty] = [ComponentMenuitemProperty.header(KMLocalizedString("Show Right Tools")), undoRedo_Menuitem_Property, save_Menuitem_Property, ComponentMenuitemProperty.divider(),
-        aiTools_Menuitem_Property, batch_Menuitem_Property, tts_Menuitem_Property, ppt_Menuitem_Property, print_Menuitem_Property, share_Menuitem_Property]
+                                                  aiTools_Menuitem_Property, batch_Menuitem_Property, tts_Menuitem_Property, ppt_Menuitem_Property, print_Menuitem_Property, share_Menuitem_Property]
         
         showGroupView(items, point)
         customRightGroupView.clickedAutoHide = false
@@ -488,7 +533,7 @@ class KMPDFToolbarController: NSViewController {
         customRightGroupView.groupDelegate = self
         customRightGroupView.showWithPoint(CGPoint(x: point.x, y: point.y-viewHeight), relativeTo: self.contendBox)
         customRightGroupView?.updateGroupInfo(items)
-         
+        
     }
     
     func hideGroupView() {
@@ -540,9 +585,8 @@ class KMPDFToolbarController: NSViewController {
         
         var clickEnabled = true
         let windowPoint = event.locationInWindow
-
-        var point = view.convert(windowPoint, from: nil)
-        if tabsMoreButton.isHidden == false {
+         
+        if tabsMoreButton.superview?.isHidden == false {
             if CGRectContainsPoint(tabsMoreButton.frame, mainToolbarContendView.convert(windowPoint, from: nil)) {
                 clickEnabled = false
             }
@@ -735,21 +779,23 @@ extension KMPDFToolbarController: ComponentTabsDelegate {
             }
         }
         
+        refreshTabsScrollViewVisiableRect()
+        
         delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, property.identifier)
         
         reloadData()
     }
 }
- 
+
 //MARK: - KMPDFSecToolbarControllerDelegate:二级工具栏
 extension KMPDFToolbarController: KMPDFSecToolbarControllerDelegate {
     func kmPDFSecToolbarControllerDidItemClicked(_ controller: KMPDFSecToolbarController, _ property: Any) {
         if let value = property as? ComponentButtonProperty {
             delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, value.identifier)
-
+            
         } else if let value = property as? ComponentMenuitemProperty {
             delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, value.identifier)
-
+            
         }
     }
 }
@@ -763,7 +809,7 @@ extension KMPDFToolbarController: ComponentGroupDelegate {
     }
     
     func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
-
+        
         guard let property = menuItemProperty else {
             return
         }
@@ -797,9 +843,9 @@ extension KMPDFToolbarController: ComponentGroupDelegate {
             if share_Menuitem_Property.itemSelected {
                 validItems.append(_manager.shareProperty)
             }
-        
+            
             let sortArray = _manager.totalRightPropertys
-
+            
             let sortedArray = validItems.sorted {
                 guard let indexA = sortArray.firstIndex(of: $0 as NSObject),
                       let indexB = sortArray.firstIndex(of: $1 as NSObject) else {
@@ -834,7 +880,7 @@ extension KMPDFToolbarController: ComponentGroupDelegate {
                 _manager.toolMode = .Tools
             }
             tabsView.refreshItems()
-
+            
             delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, property.identifier)
             
             reloadData()

+ 14 - 6
PDF Office/PDF Master/KMClass/KMPDFViewController/Toolbar/KMPDFToolbarController.xib

@@ -19,7 +19,9 @@
                 <outlet property="secondContendView" destination="l3n-KG-leC" id="rAu-2n-c0w"/>
                 <outlet property="selectZoom" destination="sWP-oz-Pbl" id="RQl-q0-ySD"/>
                 <outlet property="tabsContendView" destination="ocQ-f5-AfT" id="otj-NR-vWu"/>
-                <outlet property="tabsMoreButton" destination="J9S-Xz-2bZ" id="obh-Ta-Cbv"/>
+                <outlet property="tabsLeftConst" destination="B26-fP-wCQ" id="Ssq-jk-6XA"/>
+                <outlet property="tabsMoreButton" destination="ZOR-OC-eGy" id="y7l-kz-Lzj"/>
+                <outlet property="tabsRightConst" destination="HaL-t5-wit" id="o63-hP-j81"/>
                 <outlet property="tabsScrollView" destination="wqG-VT-qtV" id="Zuk-Kj-JuU"/>
                 <outlet property="toolsView" destination="Jlg-Qt-Zb3" id="F11-kM-j9E"/>
                 <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
@@ -45,7 +47,7 @@
                                         <subviews>
                                             <scrollView fixedFrame="YES" borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" horizontalScrollElasticity="none" verticalScrollElasticity="none" translatesAutoresizingMaskIntoConstraints="NO" id="wqG-VT-qtV">
                                                 <rect key="frame" x="0.0" y="0.0" width="126" height="28"/>
-                                                <autoresizingMask key="autoresizingMask" flexibleMinY="YES" flexibleMaxY="YES"/>
+                                                <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
                                                 <clipView key="contentView" drawsBackground="NO" id="syi-se-C8a">
                                                     <rect key="frame" x="0.0" y="0.0" width="126" height="28"/>
                                                     <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -131,10 +133,16 @@
                                             <constraint firstAttribute="width" constant="264" id="dh8-di-9PV"/>
                                         </constraints>
                                     </customView>
-                                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="J9S-Xz-2bZ" customClass="ComponentButton" customModule="KMComponentLibrary">
-                                        <rect key="frame" x="406" y="6" width="28" height="28"/>
+                                    <customView translatesAutoresizingMaskIntoConstraints="NO" id="J9S-Xz-2bZ">
+                                        <rect key="frame" x="406" y="6" width="44" height="28"/>
+                                        <subviews>
+                                            <customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ZOR-OC-eGy" customClass="ComponentButton" customModule="KMComponentLibrary">
+                                                <rect key="frame" x="0.0" y="0.0" width="28" height="28"/>
+                                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" heightSizable="YES"/>
+                                            </customView>
+                                        </subviews>
                                         <constraints>
-                                            <constraint firstAttribute="width" constant="28" id="53b-eg-zIm"/>
+                                            <constraint firstAttribute="width" constant="44" id="53b-eg-zIm"/>
                                             <constraint firstAttribute="height" constant="28" id="8Ks-k0-95N"/>
                                         </constraints>
                                     </customView>
@@ -150,9 +158,9 @@
                                     <constraint firstItem="ocQ-f5-AfT" firstAttribute="leading" secondItem="IlW-fu-gVn" secondAttribute="trailing" constant="24" id="B26-fP-wCQ"/>
                                     <constraint firstItem="IlW-fu-gVn" firstAttribute="centerY" secondItem="ZQN-TX-rwt" secondAttribute="centerY" id="DVT-W8-jps"/>
                                     <constraint firstItem="u0U-bP-RVi" firstAttribute="leading" secondItem="ocQ-f5-AfT" secondAttribute="trailing" constant="24" id="HaL-t5-wit"/>
-                                    <constraint firstItem="u0U-bP-RVi" firstAttribute="leading" secondItem="J9S-Xz-2bZ" secondAttribute="trailing" constant="16" id="MZY-cP-roa"/>
                                     <constraint firstItem="ocQ-f5-AfT" firstAttribute="centerY" secondItem="ZQN-TX-rwt" secondAttribute="centerY" id="Rqr-P0-tJL"/>
                                     <constraint firstAttribute="bottom" secondItem="fWG-WR-IBe" secondAttribute="bottom" id="SO4-xQ-rju"/>
+                                    <constraint firstItem="u0U-bP-RVi" firstAttribute="leading" secondItem="J9S-Xz-2bZ" secondAttribute="trailing" id="YwN-I8-rcf"/>
                                     <constraint firstItem="fWG-WR-IBe" firstAttribute="leading" secondItem="ZQN-TX-rwt" secondAttribute="leading" id="amy-OK-SoP"/>
                                     <constraint firstAttribute="height" constant="40" id="boZ-Z5-9Qp"/>
                                     <constraint firstItem="J9S-Xz-2bZ" firstAttribute="centerY" secondItem="ZQN-TX-rwt" secondAttribute="centerY" id="bsv-dS-l6f"/>