KMSecureEncryptComboBoxCellView.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // KMSecureEncryptComboBoxCellView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2022/11/28.
  6. //
  7. import Cocoa
  8. class KMSecureEncryptComboBoxCellView: NSTableCellView {
  9. var titleLabel: NSTextField = NSTextField(labelWithString: "")
  10. var comboBox: NSComboBox = NSComboBox()
  11. private var myEnabled: Bool!
  12. var kmEnabled: Bool {
  13. get {
  14. myEnabled
  15. }
  16. set {
  17. myEnabled = newValue
  18. if newValue {
  19. comboBox.isEnabled = newValue
  20. } else {
  21. comboBox.isEnabled = newValue
  22. }
  23. }
  24. }
  25. var itemClick: KMItemClickBlock<KMSecureEncryptComboBoxCellView>?
  26. override init(frame frameRect: NSRect) {
  27. super.init(frame: frameRect)
  28. self.initSubViews()
  29. }
  30. required init?(coder: NSCoder) {
  31. super.init(coder: coder)
  32. self.initSubViews()
  33. }
  34. override var isFlipped: Bool {
  35. return true
  36. }
  37. func initSubViews() {
  38. self.addSubview(self.titleLabel)
  39. self.addSubview(self.comboBox)
  40. self.comboBox.isEditable = false
  41. self.comboBox.delegate = self
  42. }
  43. override func layout() {
  44. super.layout()
  45. let width: CGFloat = NSWidth(self.bounds)
  46. titleLabel.frame = NSMakeRect(12, 5, width-12*2, 20)
  47. let comboBoxY: CGFloat = titleLabel.frame.maxY + 8
  48. comboBox.frame = NSMakeRect(10, comboBoxY, width-10-40, 25)
  49. }
  50. }
  51. extension KMSecureEncryptComboBoxCellView: NSComboBoxDelegate {
  52. func comboBoxSelectionDidChange(_ notification: Notification) {
  53. if comboBox.isEqual(to: notification.object) {
  54. guard let callback = self.itemClick else {
  55. return
  56. }
  57. callback(nil, comboBox.indexOfSelectedItem)
  58. }
  59. }
  60. }