1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //
- // KMHeaderFooterPageInfoView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/12/28.
- //
- import Cocoa
- class KMHeaderFooterPageInfoView: KMHeaderFooterAdjectiveInfoBaseView {
- var leftLabel = NSTextField(labelWithString: "")
- var leftComboBox = NSComboBox()
- private var rigthLabel = NSTextField(labelWithString: "")
- var rightComboBox = NSComboBox()
-
- override func initSubviews() {
- super.initSubviews()
-
- self.addSubview(self.leftLabel)
- self.addSubview(self.leftComboBox)
- self.addSubview(self.rigthLabel)
- self.addSubview(self.rightComboBox)
-
- self.titleLabel.isHidden = true
- self.rigthLabel.stringValue = NSLocalizedString("Start Page:", comment: "")
- self.leftComboBox.isEditable = false
- self.leftComboBox.delegate = self
-
- self.rightComboBox.isEditable = false
- self.rightComboBox.delegate = self
- }
-
- override func layout() {
- super.layout()
-
- let width: CGFloat = NSWidth(self.bounds)
- let hSpace: CGFloat = 10
-
- let leftMargin = self.contentInset.left
- let labelWidth: CGFloat = (width-leftMargin*2-hSpace)*0.5
- let labelHeight: CGFloat = 16
- self.leftLabel.frame = NSMakeRect(leftMargin, 0, labelWidth, labelHeight)
- self.rigthLabel.frame = NSMakeRect(self.rigthLabel.frame.maxX+hSpace, 0, labelWidth, labelHeight)
-
- let comboBoxY: CGFloat = self.leftLabel.frame.maxY+6
- let comboBoxSize: NSSize = NSMakeSize(labelWidth, 22)
- self.leftComboBox.frame = NSMakeRect(leftMargin, comboBoxY, comboBoxSize.width, comboBoxSize.height)
- self.rightComboBox.frame = NSMakeRect(self.leftComboBox.frame.maxX+hSpace, comboBoxY, comboBoxSize.width, comboBoxSize.height)
- }
-
- override var model: KMHeaderFooterAdjectiveModel {
- get {
- super.model
- }
- set {
- super.model = newValue
- }
- }
- }
- extension KMHeaderFooterPageInfoView: NSComboBoxDelegate {
- func comboBoxSelectionDidChange(_ notification: Notification) {
- guard let callback = self.itemClick else {
- return
- }
-
- var sender: NSComboBox?
- var itemID: Int = 0
- if (self.leftComboBox.isEqual(to: notification.object)) {
- sender = self.leftComboBox
- itemID = 1
- } else if (self.rightComboBox.isEqual(to: notification.object)) {
- sender = self.rightComboBox
- itemID = 2
- }
-
- if (sender == nil) {
- return
- }
-
- var index: Int = sender!.indexOfSelectedItem
- if (index < 0) {
- index = 0
- }
-
- callback(itemID, index)
- }
- }
|