1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- //
- // KMBatchTableRowView.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2023/10/8.
- //
- import Cocoa
- @objcMembers
- class KMBatchTableRowView: KMTableRowView {
- private var _backgroundView: NSView?
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- self.addSubview(self.backgroundView ?? NSView())
- self.backgroundView?.isHidden = true
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- override func layout() {
- super.layout()
-
- self.backgroundView?.frame = NSMakeRect(selectionInset.left, selectionInset.top, bounds.width - selectionInset.left - selectionInset.right, bounds.height - selectionInset.top - selectionInset.bottom)
- }
-
- override var selectionInset: NSEdgeInsets {
- didSet {
- needsLayout = true
- }
- }
-
- override var isSelected: Bool {
- didSet {
- if isSelected {
- backgroundView!.isHidden = true
- }
- }
- }
-
- //MARK: Mouse Event
-
- override func mouseExited(with event: NSEvent) {
- super.mouseExited(with: event)
-
- self.backgroundView?.isHidden = true
- for view in subviews {
- if let v = view as? NSView {
- for subview in v.subviews {
- if let button = subview as? NSButton {
- button.isHidden = true
- }
- }
- }
- }
- }
-
- override func mouseEntered(with event: NSEvent) {
- super.mouseEntered(with: event)
-
- if isSelected {
- backgroundView!.isHidden = true
- } else {
- backgroundView!.isHidden = false
- }
-
- for view in subviews {
- if let v = view as? NSView {
- for subview in v.subviews {
- if let button = subview as? NSButton {
- button.isHidden = false
- }
- }
- }
- }
- }
-
- //MARK: Get、Set
-
- var backgroundView: NSView? {
- get {
- if _backgroundView == nil {
- _backgroundView = NSView()
- _backgroundView?.wantsLayer = true
- _backgroundView?.layer?.backgroundColor = NSColor.clear.cgColor
- }
- return _backgroundView
- }
- }
- }
|