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
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
- (void)mouseDown:(NSEvent *)theEvent {
|
2006-05-29 22:23:56 +00:00
|
|
|
NSPoint event_location = [theEvent locationInWindow];
|
|
|
|
NSPoint local_point = [self convertPoint:event_location fromView:nil];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
int column = (int)[self columnAtPoint:local_point];
|
2006-05-29 22:23:56 +00:00
|
|
|
|
2022-02-07 05:49:27 +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];
|
2022-02-07 05:49:27 +00:00
|
|
|
if(fabs(rect.origin.x - local_point.x) <= 1.0 && column > 0) {
|
2006-05-29 22:23:56 +00:00
|
|
|
--column;
|
|
|
|
clickedSeperator = YES;
|
|
|
|
}
|
|
|
|
// handle a click 3 pixels away at left
|
2022-02-07 05:49:27 +00:00
|
|
|
else if(fabs(rect.origin.x + rect.size.width - local_point.x) <= 3.0)
|
2006-05-29 22:23:56 +00:00
|
|
|
clickedSeperator = YES;
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
if(clickedSeperator) {
|
2007-03-12 23:29:42 +00:00
|
|
|
NSTableColumn *col = [[[self tableView] tableColumns] objectAtIndex:column];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
// Info about the font and such
|
2007-03-12 23:29:42 +00:00
|
|
|
NSCell *cell = [col dataCell];
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
// Binding info...reaching deep!
|
2007-03-12 23:29:42 +00:00
|
|
|
NSDictionary *bindingInfo = [col infoForBinding:@"value"];
|
|
|
|
NSArray *boundArray = [[bindingInfo objectForKey:NSObservedObjectKey] valueForKeyPath:[bindingInfo objectForKey:NSObservedKeyPathKey]];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
// find the longest string display length in that column
|
2007-03-12 23:29:42 +00:00
|
|
|
float max_width = -1;
|
2022-02-07 05:49:27 +00:00
|
|
|
for(id row in boundArray) {
|
2008-01-24 02:33:55 +00:00
|
|
|
[cell setObjectValue:row];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2008-01-24 02:33:55 +00:00
|
|
|
float width = [cell cellSize].width;
|
2022-02-07 05:49:27 +00:00
|
|
|
if(width > max_width)
|
2007-03-12 23:29:42 +00:00
|
|
|
max_width = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the new width (plus a 5 pixel extra to avoid "..." string substitution)
|
2022-02-07 05:49:27 +00:00
|
|
|
[col setWidth:max_width + 5];
|
|
|
|
|
|
|
|
} else
|
|
|
|
[super mouseDown:theEvent];
|
|
|
|
} else
|
|
|
|
[super mouseDown:theEvent];
|
2006-05-29 22:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|