KMBatchTableRowView.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // KMBatchTableRowView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2023/10/8.
  6. //
  7. import Cocoa
  8. @objcMembers
  9. class KMBatchTableRowView: KMTableRowView {
  10. private var _backgroundView: NSView?
  11. override init(frame frameRect: NSRect) {
  12. super.init(frame: frameRect)
  13. self.addSubview(self.backgroundView ?? NSView())
  14. self.backgroundView?.isHidden = true
  15. }
  16. required init?(coder: NSCoder) {
  17. fatalError("init(coder:) has not been implemented")
  18. }
  19. override func layout() {
  20. super.layout()
  21. self.backgroundView?.frame = NSMakeRect(selectionInset.left, selectionInset.top, bounds.width - selectionInset.left - selectionInset.right, bounds.height - selectionInset.top - selectionInset.bottom)
  22. }
  23. override var selectionInset: NSEdgeInsets {
  24. didSet {
  25. needsLayout = true
  26. }
  27. }
  28. override var isSelected: Bool {
  29. didSet {
  30. if isSelected {
  31. backgroundView!.isHidden = true
  32. }
  33. }
  34. }
  35. //MARK: Mouse Event
  36. override func mouseExited(with event: NSEvent) {
  37. super.mouseExited(with: event)
  38. self.backgroundView?.isHidden = true
  39. for view in subviews {
  40. if let v = view as? NSView {
  41. for subview in v.subviews {
  42. if let button = subview as? NSButton {
  43. button.isHidden = true
  44. }
  45. }
  46. }
  47. }
  48. }
  49. override func mouseEntered(with event: NSEvent) {
  50. super.mouseEntered(with: event)
  51. if isSelected {
  52. backgroundView!.isHidden = true
  53. } else {
  54. backgroundView!.isHidden = false
  55. }
  56. for view in subviews {
  57. if let v = view as? NSView {
  58. for subview in v.subviews {
  59. if let button = subview as? NSButton {
  60. button.isHidden = false
  61. }
  62. }
  63. }
  64. }
  65. }
  66. //MARK: Get、Set
  67. var backgroundView: NSView? {
  68. get {
  69. if _backgroundView == nil {
  70. _backgroundView = NSView()
  71. _backgroundView?.wantsLayer = true
  72. _backgroundView?.layer?.backgroundColor = NSColor.clear.cgColor
  73. }
  74. return _backgroundView
  75. }
  76. }
  77. }