CocoaDev

Edit AllPages

This is a NSCollectionView like class that works on Tiger. It derives directly from NSView. I tried to customize NSTableView but there were too many bugs with drag/drop and scrollbars for it too work. If you don’t need those features then you might want to start there first (see http://www.joar.com/code ). –SaileshAgrawal

This is written specifically with the requirements I had in mind. It has the following features and limitations hard coded into it:

Remember that this is mostly sample code. Feel free to use it any way you like but there will likely be some bugs in it.


Interface

#import <Cocoa/Cocoa.h>

@class TigerCollectionViewItem;

@protocol TigerCollectionViewTarget

@end

@interface TigerCollectionView : NSView { IBOutlet id target; NSMutableArray *items; BOOL needsLayout; }

@end

@interface TigerCollectionViewItem : NSView { BOOL isSelected; NSPoint mouseDownPos; int dragTargetType; NSMutableDictionary *cachedTextColors; } @end


Implementation

#import “TigerCollectionView.h”

static const float DRAG_START_DISTANCE = 10; static const float DRAG_IMAGE_ALPHA = 0.5; static NSString * const DRAG_ITEM_TYPE = @”TigerCollectionViewDragType”;

typedef enum { DragTargetType_None, DragTargetType_Top, DragTargetType_Bottom, } DragTargetType;

@interface TigerCollectionView (Private)

// Override NSView

// Internal methods

@end

@interface TigerCollectionViewItem (Private)

// Override NSView

// Internal methods

@end

static float PointDistance(NSPoint start, NSPoint end) { float deltaX = end.x - start.x; float deltaY = end.y - start.y; return sqrt(deltaX * deltaX + deltaY * deltaY); }

@implementation TigerCollectionView

@end // TigerCollectionView

@implementation TigerCollectionView (Private)

@end // TigerCollectionView (Private)

@implementation TigerCollectionViewItem

@end // TigerCollectionViewItem

@implementation TigerCollectionViewItem (Private)

@end // [[TigerCollectionViewItem (Private)