1/* vim: set ft=objc ts=4 nowrap: */ 2/* 3 * TrackListView.m 4 * 5 * Copyright (c) 2003 6 * 7 * Author: Andreas Schik <andreas@schik.de> 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24#include "TrackListView.h" 25 26/* This class is for displaying the drag image. 27 */ 28@interface TrackTable : NSTableView 29{ 30} 31 32- (NSImage *) dragImageForRows: (NSArray *) dragRows 33 event: (NSEvent *) dragEvent 34 dragImageOffset: (NSPoint *) dragImageOffset; 35@end 36 37@implementation TrackTable 38 39- (NSImage *) dragImageForRows: (NSArray *) dragRows 40 event: (NSEvent *) dragEvent 41 dragImageOffset: (NSPoint *) dragImageOffset 42{ 43 if ([dragRows count] > 1) { 44 return [NSImage imageNamed: @"iconDnDAudioMulti.tiff"]; 45 } else { 46 return [NSImage imageNamed: @"iconDnDAudio.tiff"]; 47 } 48} 49 50@end 51 52 53@implementation TrackListView 54 55- (id) initWithFrame: (NSRect) frameRect 56{ 57 NSTableColumn *column; 58 NSRect frame = NSMakeRect(0,0,frameRect.size.width,frameRect.size.height); 59 60 self = [super initWithFrame: frameRect]; 61 if (self) { 62 table = [[TrackTable alloc] initWithFrame: frame]; 63 [table setAllowsMultipleSelection: YES]; 64 [table setAllowsEmptySelection: NO]; 65 [table setAllowsColumnSelection: NO]; 66 [table setDrawsGrid: YES]; 67 [table setAllowsColumnResizing: YES]; 68 [table setAutoresizesAllColumnsToFit: YES]; 69 [table setTarget: self]; 70 [table setDoubleAction: @selector(tableDoubleClicked:)]; 71 // we set the delegate and data source in awakeFromNib!! 72 // we don't know them, yet!! 73 74 column = [[NSTableColumn alloc] initWithIdentifier: @"Nr"]; 75 [column setEditable: NO]; 76 [column setResizable: YES]; 77 [[column headerCell] setStringValue: _(@"Nr")]; 78 [[column dataCell] setAlignment: NSRightTextAlignment]; 79 [column setMinWidth: 20]; 80 [column setMaxWidth: 40]; 81 [column setWidth: 30]; 82 83 [table addTableColumn: column]; 84 [column release]; 85 86 column = [[NSTableColumn alloc] initWithIdentifier: @"Artist"]; 87 [column setEditable: NO]; 88 [column setResizable: YES]; 89 [[column headerCell] setStringValue: _(@"Artist")]; 90 [column setMinWidth: 20]; 91 [column setMaxWidth: 100000]; 92 [column setWidth: 120]; 93 94 [table addTableColumn: column]; 95 [column release]; 96 97 column = [[NSTableColumn alloc] initWithIdentifier: @"Title"]; 98 [column setEditable: NO]; 99 [column setResizable: YES]; 100 [[column headerCell] setStringValue: _(@"Title")]; 101 [column setMinWidth: 20]; 102 [column setMaxWidth: 100000]; 103 [column setWidth: 120]; 104 105 [table addTableColumn: column]; 106 [column release]; 107 108 column = [[NSTableColumn alloc] initWithIdentifier: @"Duration"]; 109 [column setEditable: NO]; 110 [column setResizable: NO]; 111 [[column headerCell] setStringValue: _(@"Duration")]; 112 [[column dataCell] setAlignment: NSRightTextAlignment]; 113 [column setMinWidth: 20]; 114 [column setMaxWidth: 80]; 115 [column setWidth: 80]; 116 [[column dataCell] setAlignment: NSCenterTextAlignment]; 117 118 [table addTableColumn: column]; 119 [column release]; 120 121 scroll = [[NSScrollView alloc] initWithFrame: frame]; 122 [scroll setHasHorizontalScroller: NO]; 123 [scroll setHasVerticalScroller: YES]; 124 [scroll setDocumentView: table]; 125 [scroll setBorderType: NSBezelBorder]; 126 [scroll setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; 127 128 [self addSubview: scroll]; 129 } 130 131 return self; 132} 133 134- (void) dealloc 135{ 136 [table release]; 137 [scroll release]; 138 [super dealloc]; 139} 140 141- (void) awakeFromNib 142{ 143 [table setDelegate: delegate]; 144 [table setDataSource: delegate]; 145} 146 147- (void) reloadData 148{ 149 [table reloadData]; 150} 151 152- (void) forwardInvocation: (NSInvocation *)invocation 153{ 154 if ([table respondsToSelector: [invocation selector]]) 155 [invocation invokeWithTarget: table]; 156 else 157 [self doesNotRecognizeSelector: [invocation selector]]; 158} 159 160- (void) tableDoubleClicked: (id)sender 161{ 162 int track = [table selectedRow]+1; 163 NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: 164 [NSNumber numberWithInt: track], @"Track", nil]; 165 166 [[NSNotificationCenter defaultCenter] 167 postNotificationName: @"PlayTrack" 168 object: nil 169 userInfo: dict]; 170} 171 172@end 173