2006-05-29 22:23:56 +00:00
|
|
|
//
|
|
|
|
// PlaylistHeaderView.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Simon on 06-05-24.
|
2006-09-04 18:46:18 +00:00
|
|
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
2006-05-29 22:23:56 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "PlaylistHeaderView.h"
|
|
|
|
|
|
|
|
|
|
|
|
@implementation PlaylistHeaderView
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
NSPoint event_location = [theEvent locationInWindow];
|
|
|
|
NSPoint local_point = [self convertPoint:event_location fromView:nil];
|
|
|
|
|
|
|
|
int column = [self columnAtPoint:local_point];
|
|
|
|
|
2007-10-20 19:14:12 +00:00
|
|
|
if ([theEvent clickCount] == 2 && column != -1) {
|
2006-05-29 22:23:56 +00:00
|
|
|
|
|
|
|
// compute whether the clickpoint is a column separator or not
|
|
|
|
BOOL clickedSeperator = NO;
|
|
|
|
// handle a click one pixel away at right
|
|
|
|
NSRect rect = [self headerRectOfColumn:column];
|
|
|
|
if (abs(rect.origin.x - local_point.x) <= 1 && column > 0) {
|
|
|
|
--column;
|
|
|
|
clickedSeperator = YES;
|
|
|
|
}
|
|
|
|
// handle a click 3 pixels away at left
|
|
|
|
else if (abs(rect.origin.x + rect.size.width - local_point.x) <= 3)
|
|
|
|
clickedSeperator = YES;
|
|
|
|
|
|
|
|
if (clickedSeperator) {
|
2007-03-12 23:29:42 +00:00
|
|
|
NSTableColumn *col = [[[self tableView] tableColumns] objectAtIndex:column];
|
2008-01-24 02:33:55 +00:00
|
|
|
|
2007-03-12 23:29:42 +00:00
|
|
|
//Info about the font and such
|
|
|
|
NSCell *cell = [col dataCell];
|
|
|
|
|
|
|
|
//Binding info...reaching deep!
|
|
|
|
NSDictionary *bindingInfo = [col infoForBinding:@"value"];
|
|
|
|
NSArray *boundArray = [[bindingInfo objectForKey:NSObservedObjectKey] valueForKeyPath:[bindingInfo objectForKey:NSObservedKeyPathKey]];
|
2006-05-29 22:23:56 +00:00
|
|
|
|
2007-03-12 23:29:42 +00:00
|
|
|
//find the longest string display length in that column
|
|
|
|
float max_width = -1;
|
|
|
|
id row;
|
|
|
|
NSEnumerator *enumerator = [boundArray objectEnumerator];
|
|
|
|
while (row = [enumerator nextObject]) {
|
2008-01-24 02:33:55 +00:00
|
|
|
|
|
|
|
[cell setObjectValue:row];
|
|
|
|
|
|
|
|
float width = [cell cellSize].width;
|
2007-03-12 23:29:42 +00:00
|
|
|
if (width > max_width)
|
|
|
|
max_width = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// set the new width (plus a 5 pixel extra to avoid "..." string substitution)
|
|
|
|
[col setWidth:max_width+5];
|
|
|
|
|
2006-05-29 22:23:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
[super mouseDown: theEvent];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[super mouseDown: theEvent];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|