| 1 |
masaki |
70 |
// |
| 2 |
|
|
// XspfMTableView.m |
| 3 |
|
|
// XspfManager |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 09/11/15. |
| 6 |
|
|
// Copyright 2009 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#import "XspfMTableView.h" |
| 10 |
|
|
|
| 11 |
|
|
|
| 12 |
masaki |
211 |
@interface XspfMTableView (XspfM_CocoaPravateMethodHack) |
| 13 |
|
|
- (NSColor *)_highlightColorForCell:(NSCell *)cell; |
| 14 |
|
|
@end |
| 15 |
|
|
|
| 16 |
|
|
|
| 17 |
masaki |
70 |
@implementation XspfMTableView |
| 18 |
masaki |
211 |
|
| 19 |
|
|
+(void)initialize |
| 20 |
|
|
{ |
| 21 |
|
|
static BOOL isFirst = YES; |
| 22 |
|
|
if(isFirst) { |
| 23 |
|
|
isFirst = NO; |
| 24 |
|
|
|
| 25 |
|
|
if(![self instancesRespondToSelector:@selector(_highlightColorForCell:)]) { |
| 26 |
|
|
HMLog(HMLogLevelError, @"this version of Mac OS X not supported!"); |
| 27 |
|
|
exit(-3); |
| 28 |
|
|
} |
| 29 |
|
|
} |
| 30 |
|
|
} |
| 31 |
|
|
|
| 32 |
|
|
#pragma mark#### NSMenu Delegate #### |
| 33 |
|
|
- (void)menuDidClose:(NSMenu *)menu |
| 34 |
|
|
{ |
| 35 |
|
|
HMLog(HMLogLevelDebug, @"Enter %@", NSStringFromSelector(_cmd)); |
| 36 |
|
|
NSMenuItem *hiddenItem = [menu itemAtIndex:0]; |
| 37 |
|
|
id rowValue = [hiddenItem representedObject]; |
| 38 |
|
|
HMLog(HMLogLevelDebug, @"rowValue is %@", rowValue); |
| 39 |
|
|
NSInteger row = [rowValue integerValue]; |
| 40 |
|
|
NSRect rowRect = [self rectOfRow:row]; |
| 41 |
|
|
[self setNeedsDisplayInRect:rowRect]; |
| 42 |
|
|
} |
| 43 |
|
|
- (NSMenu *)menuForEvent:(NSEvent *)event |
| 44 |
|
|
{ |
| 45 |
|
|
if([[self dataSource] respondsToSelector:@selector(tableView:menuForEvent:)]) { |
| 46 |
|
|
NSMenu *menu = [[self dataSource] tableView:self menuForEvent:event]; |
| 47 |
|
|
if(menu) { |
| 48 |
|
|
// draw select frame rectangle. |
| 49 |
|
|
NSPoint mouse = [self convertPoint:[event locationInWindow] fromView:nil]; |
| 50 |
|
|
NSInteger row = [self rowAtPoint:mouse]; |
| 51 |
|
|
NSInteger col = [self columnAtPoint:mouse]; |
| 52 |
|
|
NSRect rowRect= [self rectOfRow:row]; |
| 53 |
|
|
[self lockFocus]; |
| 54 |
|
|
[[self _highlightColorForCell:[self preparedCellAtColumn:col row:row]] set]; |
| 55 |
|
|
NSFrameRectWithWidth(rowRect, 2); |
| 56 |
|
|
[self unlockFocus]; |
| 57 |
|
|
|
| 58 |
|
|
if([menu delegate]) { |
| 59 |
|
|
HMLog(HMLogLevelAlert, @"-[%@ %@] method overwrite returned NSMenu's delegate.", |
| 60 |
|
|
NSStringFromClass([self class]), NSStringFromSelector(_cmd)); |
| 61 |
|
|
} |
| 62 |
|
|
NSMenuItem *hiddenItem = [menu insertItemWithTitle:@"hidden" action:Nil keyEquivalent:@"" atIndex:0]; |
| 63 |
|
|
[hiddenItem setHidden:YES]; |
| 64 |
|
|
[hiddenItem setRepresentedObject:[NSNumber numberWithInteger:row]]; |
| 65 |
|
|
[menu setDelegate:self]; |
| 66 |
|
|
|
| 67 |
|
|
return menu; |
| 68 |
|
|
} |
| 69 |
|
|
} |
| 70 |
|
|
|
| 71 |
|
|
return nil; |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
masaki |
70 |
- (void)keyDown:(NSEvent *)theEvent |
| 75 |
|
|
{ |
| 76 |
|
|
if([theEvent isARepeat]) return [super keyDown:theEvent]; |
| 77 |
|
|
|
| 78 |
|
|
#define kRETURN_KEY 36 |
| 79 |
|
|
#define kENTER_KEY 52 |
| 80 |
|
|
|
| 81 |
|
|
unsigned short code = [theEvent keyCode]; |
| 82 |
masaki |
187 |
// HMLog(HMLogLevelDebug, @"code -> %d", code); |
| 83 |
masaki |
70 |
switch(code) { |
| 84 |
|
|
case kRETURN_KEY: |
| 85 |
|
|
case kENTER_KEY: |
| 86 |
masaki |
73 |
if([self doubleAction]) { |
| 87 |
|
|
[self sendAction:[self doubleAction] to:[self target]]; |
| 88 |
masaki |
70 |
return; |
| 89 |
|
|
} |
| 90 |
|
|
break; |
| 91 |
|
|
} |
| 92 |
|
|
|
| 93 |
|
|
[super keyDown:theEvent]; |
| 94 |
|
|
} |
| 95 |
|
|
@end |