| 1 |
// |
| 2 |
// MyTableHeaderView.m |
| 3 |
// |
| 4 |
// Created by Toshi Nagata on Sun Jun 24 2001. |
| 5 |
/* |
| 6 |
Copyright (c) 2000-2011 Toshi Nagata. All rights reserved. |
| 7 |
|
| 8 |
This program is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation version 2 of the License. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
*/ |
| 17 |
|
| 18 |
#import "MyTableHeaderView.h" |
| 19 |
|
| 20 |
@implementation MyTableHeaderView |
| 21 |
|
| 22 |
- (void)mouseDown:(NSEvent *)theEvent |
| 23 |
{ |
| 24 |
int column; |
| 25 |
NSPoint point; |
| 26 |
NSRect rect; |
| 27 |
NSMenu *menu; |
| 28 |
id delegate; |
| 29 |
point = [self convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 30 |
// NSLog(@"Mouse down at %@ (view coordinate)\n", NSStringFromPoint(point)); |
| 31 |
for (column = (int)[[self tableView] numberOfColumns] - 1; column >= 0; column--) { |
| 32 |
rect = [self headerRectOfColumn:column]; |
| 33 |
rect = NSInsetRect(rect, 5.0f, 0.0f); |
| 34 |
// NSLog(@"Column %d, rect %@\n", column, NSStringFromRect(rect)); |
| 35 |
if (NSPointInRect(point, rect)) { |
| 36 |
// NSBeep(); |
| 37 |
delegate = [[self tableView] delegate]; |
| 38 |
if (delegate != nil && [delegate respondsToSelector:@selector(tableHeaderView:popUpMenuAtHeaderColumn:)]) { |
| 39 |
menu = [delegate tableHeaderView:self popUpMenuAtHeaderColumn:column]; |
| 40 |
if (menu != nil) { |
| 41 |
if ([NSMenu respondsToSelector: @selector(popUpContextMenu:withEvent:forView:withFont:)]) |
| 42 |
/* 10.3-and-later-only method */ |
| 43 |
[NSMenu popUpContextMenu:menu withEvent:theEvent forView:self withFont: [NSFont systemFontOfSize: [NSFont smallSystemFontSize]]]; |
| 44 |
else |
| 45 |
[NSMenu popUpContextMenu:menu withEvent:theEvent forView:self]; |
| 46 |
return; |
| 47 |
} |
| 48 |
} |
| 49 |
break; |
| 50 |
} |
| 51 |
} |
| 52 |
[super mouseDown:theEvent]; |
| 53 |
} |
| 54 |
|
| 55 |
@end |