1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- //
- // KMSecureEncryptComboBoxCellView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/11/28.
- //
- import Cocoa
- class KMSecureEncryptComboBoxCellView: NSTableCellView {
- var titleLabel: NSTextField = NSTextField(labelWithString: "")
- var comboBox: NSComboBox = NSComboBox()
-
- private var myEnabled: Bool!
- var kmEnabled: Bool {
- get {
- myEnabled
- }
- set {
- myEnabled = newValue
-
- if newValue {
- comboBox.isEnabled = newValue
- } else {
- comboBox.isEnabled = newValue
- }
- }
- }
-
- var itemClick: KMItemClickBlock<KMSecureEncryptComboBoxCellView>?
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- self.initSubViews()
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
-
- self.initSubViews()
- }
-
- override var isFlipped: Bool {
- return true
- }
-
- func initSubViews() {
- self.addSubview(self.titleLabel)
- self.addSubview(self.comboBox)
- self.comboBox.isEditable = false
- self.comboBox.delegate = self
- }
-
- override func layout() {
- super.layout()
-
- let width: CGFloat = NSWidth(self.bounds)
- titleLabel.frame = NSMakeRect(12, 5, width-12*2, 20)
-
- let comboBoxY: CGFloat = titleLabel.frame.maxY + 8
- comboBox.frame = NSMakeRect(10, comboBoxY, width-10-40, 25)
- }
- }
- extension KMSecureEncryptComboBoxCellView: NSComboBoxDelegate {
- func comboBoxSelectionDidChange(_ notification: Notification) {
- if comboBox.isEqual(to: notification.object) {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(nil, comboBox.indexOfSelectedItem)
- }
- }
- }
|