// // KMSecureEncryptCheckCellView.swift // PDF Master // // Created by tangchao on 2023/2/7. // import Cocoa typealias KMSecureEncryptCheckCellViewItemClick = (Bool) ->() class KMSecureEncryptCheckCellView: NSTableCellView { var check: NSButton? private var myEnabled: Bool! var kmEnabled: Bool { get { myEnabled } set { myEnabled = newValue if newValue { check!.isEnabled = newValue } else { check!.isEnabled = newValue } } } var itemClick: KMSecureEncryptCheckCellViewItemClick! override init(frame frameRect: NSRect) { super.init(frame: frameRect) initSubViews() } required init?(coder: NSCoder) { super.init(coder: coder) initSubViews() } public func initSubViews() { self.check = NSButton(checkboxWithTitle: "", target: self, action: #selector(checkAction)) self.addSubview(self.check!) } override func layout() { super.layout() let height: CGFloat = NSHeight(self.bounds) let width: CGFloat = NSWidth(self.bounds) let checkH: CGFloat = 22 let checkX: CGFloat = 10 self.check?.frame = NSMakeRect(checkX, (height-checkH)*0.5, width-checkX, 22) } @objc private func checkAction(sender: NSButton) { guard let callback = itemClick else { return } callback(sender.state == .on) } }