// // KMSecureEncryptComboBoxCellView.swift // PDF Master // // 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? 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) } } }