// // KMThumbnailTableView.swift // PDF Master // // Created by tangchao on 2023/11/16. // import Cocoa /* @protocol SKThumbnailTableViewDelegate @optional - (NSUInteger)tableView:(NSTableView *)tableView highlightLevelForRow:(NSInteger)row; - (BOOL)tableView:(NSTableView *)tableView commandSelectRow:(NSInteger)rowIndex; - (BOOL)tableView:(NSTableView *)tableView shiftSelectRow:(NSInteger)rowIndex; @end */ @objc protocol KMThumbnailTableViewDelegate: KMBotaTableViewDelegate { @objc optional func tableView(_ tableView: NSTableView, highlightLevelForRow row: Int) -> UInt @objc optional func tableView(_ tableView: NSTableView, commandSelectRow rowIndex: Int) -> Bool @objc optional func tableView(_ tableView: NSTableView, shiftSelectRow rowIndex: Int) -> Bool } class KMThumbnailTableView: KMBotaTableView { /* - (id )delegate; - (void)setDelegate:(id )newDelegate; */ override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } /* - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } - (void)drawRow:(NSInteger)row clipRect:(NSRect)clipRect { // if ([[self delegate] respondsToSelector:@selector(tableView:highlightLevelForRow:)] && // [self isRowSelected:row] == NO) { // // NSUInteger level = [[self delegate] tableView:self highlightLevelForRow:row]; // // if (level < MAX_HIGHLIGHTS) { // // NSColor *color = [NSColor sourceListHighlightColorForView:self]; // if (color) { // NSRect rect = [self rectOfRow:row]; // if (NSIntersectsRect(rect, clipRect)) { // [NSGraphicsContext saveGraphicsState]; // [[color colorWithAlphaComponent:0.1 * (MAX_HIGHLIGHTS - level)] setFill]; // [NSBezierPath fillRect:rect]; // [NSGraphicsContext restoreGraphicsState]; // } // } // } // } [super drawRow:row clipRect:clipRect]; } - (void)highlightSelectionInClipRect:(NSRect)clipRect { if ([self selectionHighlightStyle] == NSTableViewSelectionHighlightStyleRegular) { [NSGraphicsContext saveGraphicsState]; NSColor *color = [NSColor colorWithRed:227.0/255.0 green:238.0/255.0 blue:250.0/255.0 alpha:1.0]; if (@available(macOS 10.14, *)) { NSAppearanceName appearanceName = [[NSApp effectiveAppearance] bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; if ([appearanceName isEqualToString:NSAppearanceNameDarkAqua]) { color = [NSColor colorWithRed:50.0/255.0 green:68.0/255.0 blue:92.0/255.0 alpha:1.0]; } } [color setFill]; [[self selectedRowIndexes] enumerateIndexesUsingBlock:^(NSUInteger row, BOOL *stop){ NSRectFill([self rectOfRow:row]); }]; [NSGraphicsContext restoreGraphicsState]; } else { [super highlightSelectionInClipRect:clipRect]; } } - (NSCell *)preparedCellAtColumn:(NSInteger)column row:(NSInteger)row { NSCell *cell = [super preparedCellAtColumn:column row:row]; if ([self selectionHighlightStyle] == NSTableViewSelectionHighlightStyleRegular && [self isRowSelected:row] && [cell type] == NSTextCellType) { NSMutableAttributedString *attrString = [[cell attributedStringValue] mutableCopy]; [attrString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [attrString length])]; [cell setAttributedStringValue:attrString]; [attrString release]; } return cell; } - (void)handleHighlightsChanged { if ([[self delegate] respondsToSelector:@selector(tableView:highlightLevelForRow:)]) [self setNeedsDisplay:YES]; } - (void)selectRowIndexes:(NSIndexSet *)indexes byExtendingSelection:(BOOL)extendSelection { [super selectRowIndexes:indexes byExtendingSelection:extendSelection]; [self handleHighlightsChanged]; } - (void)deselectRow:(NSInteger)row { [super deselectRow:row]; [self handleHighlightsChanged]; } - (BOOL)becomeFirstResponder { if ([super becomeFirstResponder]) { [self handleHighlightsChanged]; return YES; } return NO; } - (BOOL)resignFirstResponder { if ([super resignFirstResponder]) { [self handleHighlightsChanged]; return YES; } return NO; } - (void)handleKeyOrMainStateChanged:(NSNotification *)note { if ([self selectionHighlightStyle] == NSTableViewSelectionHighlightStyleSourceList) { [self handleHighlightsChanged]; } else { if ([[self window] isMainWindow] || [[self window] isKeyWindow]) [self setBackgroundColor:[KMAppearance viewBackgroundColor]]; else [self setBackgroundColor:[NSColor controlColor]]; [self setNeedsDisplay:YES]; } } - (void)viewWillMoveToWindow:(NSWindow *)newWindow { NSWindow *oldWindow = [self window]; NSArray *names = [NSArray arrayWithObjects:NSWindowDidBecomeMainNotification, NSWindowDidResignMainNotification, NSWindowDidBecomeKeyNotification, NSWindowDidResignKeyNotification, nil]; if (oldWindow) { for (NSString *name in names) [[NSNotificationCenter defaultCenter] removeObserver:self name:name object:oldWindow]; } if (newWindow) { for (NSString *name in names) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyOrMainStateChanged:) name:name object:newWindow]; } [super viewWillMoveToWindow:newWindow]; } - (void)viewDidMoveToWindow { [super viewDidMoveToWindow]; if ([self window]) [self handleKeyOrMainStateChanged:nil]; } - (void)mouseDown:(NSEvent *)theEvent { if (([theEvent modifierFlags] & NSCommandKeyMask) && [[self delegate] respondsToSelector:@selector(tableView:commandSelectRow:)]) { NSInteger row = [self rowAtPoint:[theEvent locationInView:self]]; if (row != -1 && [[self delegate] tableView:self commandSelectRow:row]) return; } else if (([theEvent modifierFlags] & NSShiftKeyMask) && [[self delegate] respondsToSelector:@selector(tableView:shiftSelectRow:)]) { NSInteger row = [self rowAtPoint:[theEvent locationInView:self]]; if (row != -1 && [[self delegate] tableView:self shiftSelectRow:row]) return; } [super mouseDown:theEvent]; } - (id )delegate { return (id )[super delegate]; } - (void)setDelegate:(id )newDelegate { [super setDelegate:newDelegate]; } */ }