123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- //
- // 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)
- }
- }
|