KMBatchTableRowView.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // KMBatchTableRowView.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by zhipeng jiang on 2020/11/2.
  6. //
  7. #import "KMBatchTableRowView.h"
  8. @interface KMBatchTableRowView ()
  9. @property (nonatomic, strong) NSView *backgroundView;
  10. @end
  11. @implementation KMBatchTableRowView
  12. - (instancetype)initWithFrame:(NSRect)frameRect {
  13. if (self = [super initWithFrame:frameRect]) {
  14. [self addSubview:self.backgroundView];
  15. self.backgroundView.hidden = YES;
  16. }
  17. return self;
  18. }
  19. - (void)layout {
  20. [super layout];
  21. self.backgroundView.frame = NSMakeRect(self.selectionInset.left, self.selectionInset.top, NSWidth(self.bounds)-self.selectionInset.left-self.selectionInset.right, NSHeight(self.bounds)-self.selectionInset.top-self.selectionInset.bottom);
  22. }
  23. - (void)setSelectionInset:(NSEdgeInsets)selectionInset {
  24. [super setSelectionInset:selectionInset];
  25. [self setNeedsLayout:YES];
  26. }
  27. - (void)setSelected:(BOOL)selected {
  28. [super setSelected:selected];
  29. if (selected) {
  30. self.backgroundView.hidden = YES;
  31. }
  32. }
  33. #pragma mark - Mouse Event
  34. - (void)mouseExited:(NSEvent *)event {
  35. [super mouseExited:event];
  36. self.backgroundView.hidden = YES;
  37. for (NSUInteger i = 0; i < self.subviews.count; i++) {
  38. NSView *v = [self.subviews objectAtIndex:i];
  39. for (NSUInteger j = 0; j < v.subviews.count; j++) {
  40. NSView *sub = [v.subviews objectAtIndex:j];
  41. if ([sub isKindOfClass:[NSButton class]]) {
  42. sub.hidden = YES;
  43. }
  44. }
  45. }
  46. }
  47. - (void)mouseEntered:(NSEvent *)event {
  48. [super mouseEntered:event];
  49. if (self.isSelected) {
  50. self.backgroundView.hidden = YES;
  51. } else {
  52. self.backgroundView.hidden = NO;
  53. }
  54. for (NSUInteger i = 0; i < self.subviews.count; i++) {
  55. NSView *v = [self.subviews objectAtIndex:i];
  56. for (NSUInteger j = 0; j < v.subviews.count; j++) {
  57. NSView *sub = [v.subviews objectAtIndex:j];
  58. if ([sub isKindOfClass:[NSButton class]]) {
  59. sub.hidden = NO;
  60. }
  61. }
  62. }
  63. }
  64. #pragma mark -
  65. #pragma mark - Getting
  66. - (NSView *)backgroundView {
  67. if (!_backgroundView) {
  68. _backgroundView = [[NSView alloc] init];
  69. _backgroundView.wantsLayer = YES;
  70. _backgroundView.layer.backgroundColor = [NSColor clearColor].CGColor;
  71. }
  72. return _backgroundView;
  73. }
  74. @end