KMSecureEncryptCheckCellView.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // KMSecureEncryptCheckCellView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/2/7.
  6. //
  7. import Cocoa
  8. typealias KMSecureEncryptCheckCellViewItemClick = (Bool) ->()
  9. class KMSecureEncryptCheckCellView: NSTableCellView {
  10. var check: NSButton?
  11. private var myEnabled: Bool!
  12. var kmEnabled: Bool {
  13. get {
  14. myEnabled
  15. }
  16. set {
  17. myEnabled = newValue
  18. if newValue {
  19. check!.isEnabled = newValue
  20. } else {
  21. check!.isEnabled = newValue
  22. }
  23. }
  24. }
  25. var itemClick: KMSecureEncryptCheckCellViewItemClick!
  26. override init(frame frameRect: NSRect) {
  27. super.init(frame: frameRect)
  28. initSubViews()
  29. }
  30. required init?(coder: NSCoder) {
  31. super.init(coder: coder)
  32. initSubViews()
  33. }
  34. public func initSubViews() {
  35. self.check = NSButton(checkboxWithTitle: "", target: self, action: #selector(checkAction))
  36. self.addSubview(self.check!)
  37. }
  38. override func layout() {
  39. super.layout()
  40. let height: CGFloat = NSHeight(self.bounds)
  41. let width: CGFloat = NSWidth(self.bounds)
  42. let checkH: CGFloat = 22
  43. let checkX: CGFloat = 10
  44. self.check?.frame = NSMakeRect(checkX, (height-checkH)*0.5, width-checkX, 22)
  45. }
  46. @objc private func checkAction(sender: NSButton) {
  47. guard let callback = itemClick else {
  48. return
  49. }
  50. callback(sender.state == .on)
  51. }
  52. }