Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Fix #14, add .framework target, fix warnings #16

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#pragma mark Constants

#define LISTVIEW_CELL_IDENTIFIER @"MyListViewCell"
#define NUM_EXAMPLE_ITEMS 10
#define NUM_EXAMPLE_ITEMS 1000


@implementation AppDelegate
Expand Down Expand Up @@ -74,18 +74,23 @@ - (PXListViewCell*)listView:(PXListView*)aListView cellForRow:(NSUInteger)row

- (CGFloat)listView:(PXListView*)aListView heightOfRow:(NSUInteger)row
{
#pragma unused(aListView)
#pragma unused(row)
return 50;
}

- (void)listViewSelectionDidChange:(NSNotification*)aNotification
{
#pragma unused(aNotification)
NSLog(@"Selection changed");
}


// The following are only needed for drag'n drop:
- (BOOL)listView:(PXListView*)aListView writeRowsWithIndexes:(NSIndexSet*)rowIndexes toPasteboard:(NSPasteboard*)dragPasteboard
{
#pragma unused(aListView)
#pragma unused(rowIndexes)
// +++ Actually drag the items, not just dummy data.
[dragPasteboard declareTypes: [NSArray arrayWithObjects: NSStringPboardType, nil] owner: self];
[dragPasteboard setString: @"Just Testing" forType: NSStringPboardType];
Expand All @@ -96,11 +101,16 @@ - (BOOL)listView:(PXListView*)aListView writeRowsWithIndexes:(NSIndexSet*)rowInd
- (NSDragOperation)listView:(PXListView*)aListView validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSUInteger)row
proposedDropHighlight:(PXListViewDropHighlight)dropHighlight;
{
#pragma unused(aListView)
#pragma unused(dropHighlight)
#pragma unused(info)
#pragma unused(row)
return NSDragOperationCopy;
}

- (IBAction) reloadTable:(id)sender
{
#pragma unused(sender)
[listView reloadData];
}

Expand Down
1 change: 1 addition & 0 deletions Classes/MyListViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ - (void)prepareForReuse

- (void)drawRect:(NSRect)dirtyRect
{
#pragma unused(dirtyRect)
if([self isSelected]) {
[[NSColor selectedControlColor] set];
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/PXListDocumentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}

@property (assign) PXListView *listView;
@property (assign) PXListViewDropHighlight dropHighlight;
@property (assign,nonatomic) PXListViewDropHighlight dropHighlight;

-(void) setDropHighlight: (PXListViewDropHighlight)inState;

Expand Down
9 changes: 9 additions & 0 deletions Classes/PXListView+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
// Copyright 2010 Alex Rozanski. http://perspx.com. All rights reserved.
//

// Apple sadly doesn't provide CGFloat variants of these:
#if CGFLOAT_IS_DOUBLE
#define CGFLOATABS(n) fabs(n)
#else
#define CGFLOATABS(n) fabsf(n)
#endif

// This is a renamed copy of UKIsDragStart from <http://github.com/uliwitness/UliKit>:
// Possible return values from UKIsDragStart:
enum
Expand Down Expand Up @@ -40,4 +47,6 @@ typedef NSInteger PXIsDragStartResult;
- (void)contentViewBoundsDidChange:(NSNotification*)notification;
-(void)layoutCellsForResizeEvent;

- (void)windowSizing:(NSNotification *)inNot;

@end
23 changes: 10 additions & 13 deletions Classes/PXListView+UserInteraction.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
#import "PXListView+UserInteraction.h"
#import "PXListView+Private.h"

// Apple sadly doesn't provide CGFloat variants of these:
#if CGFLOAT_IS_DOUBLE
#define CGFLOATABS(n) fabs(n)
#else
#define CGFLOATABS(n) fabsf(n)
#endif

// This is a renamed copy of UKIsDragStart from <http://github.com/uliwitness/UliKit>:
static PXIsDragStartResult PXIsDragStart( NSEvent *startEvent, NSTimeInterval theTimeout )
{
Expand All @@ -31,7 +24,7 @@ static PXIsDragStartResult PXIsDragStart( NSEvent *startEvent, NSTimeInterval th
NSAutoreleasePool *pool = nil;
while( ([expireTime timeIntervalSinceReferenceDate] -[NSDate timeIntervalSinceReferenceDate]) > 0 )
{
[pool release];
[pool drain];
pool = [[NSAutoreleasePool alloc] init];

NSEvent* currEvent = [NSApp nextEventMatchingMask: NSLeftMouseUpMask | NSRightMouseUpMask | NSOtherMouseUpMask
Expand All @@ -45,7 +38,7 @@ static PXIsDragStartResult PXIsDragStart( NSEvent *startEvent, NSTimeInterval th
case NSRightMouseUp:
case NSOtherMouseUp:
{
[pool release];
[pool drain];
return PXIsDragStartMouseReleased; // Mouse released within the wait time.
break;
}
Expand All @@ -59,7 +52,7 @@ static PXIsDragStartResult PXIsDragStart( NSEvent *startEvent, NSTimeInterval th
CGFloat yMouseMovement = CGFLOATABS(newPos.y -startPos.y);
if( xMouseMovement > 2 or yMouseMovement > 2 )
{
[pool release];
[pool drain];
return (xMouseMovement > yMouseMovement) ? PXIsDragStartMouseMovedHorizontally : PXIsDragStartMouseMovedVertically; // Mouse moved within the wait time, probably a drag!
}
break;
Expand All @@ -69,7 +62,7 @@ static PXIsDragStartResult PXIsDragStart( NSEvent *startEvent, NSTimeInterval th

}

[pool release];
[pool drain];
return PXIsDragStartTimedOut; // If they held the mouse that long, they probably wanna drag.
}

Expand Down Expand Up @@ -112,6 +105,7 @@ - (void)keyDown:(NSEvent *)theEvent

- (void)moveUp:(id)sender
{
#pragma unused(sender)
if([_selectedRows count]>0) {
NSUInteger firstIndex = [_selectedRows firstIndex];

Expand All @@ -126,6 +120,7 @@ - (void)moveUp:(id)sender

- (void)moveDown:(id)sender
{
#pragma unused(sender)
if([_selectedRows count]>0) {
NSUInteger lastIndex = [_selectedRows lastIndex];

Expand Down Expand Up @@ -217,7 +212,6 @@ - (void)handleMouseDown:(NSEvent*)theEvent inCell:(PXListViewCell*)theCell // Ce

- (void)handleMouseDownOutsideCells: (NSEvent*)theEvent
{
#pragma unused(theEvent)
//[[self window] makeFirstResponder: self];
//
if( _allowsEmptySelection )
Expand All @@ -243,6 +237,9 @@ - (void)handleMouseDownOutsideCells: (NSEvent*)theEvent

- (BOOL)attemptDragWithMouseDown:(NSEvent*)theEvent inCell:(PXListViewCell*)theCell
{
if(!_dragSupported)
return NO;

PXIsDragStartResult dragResult = PXIsDragStart( theEvent, 0.0 );
if( dragResult != PXIsDragStartMouseReleased /*&& (_verticalMotionCanBeginDrag || dragResult != PXIsDragStartMouseMovedVertically)*/ ) // Was a drag, not a click? Cool!
{
Expand Down Expand Up @@ -271,7 +268,7 @@ -(NSImage*) dragImageForRowsWithIndexes: (NSIndexSet *)dragRows event: (NSEvent*
NSPoint localMouse = [self convertPoint: NSZeroPoint fromView: clickedCell];

if ([clickedCell isFlipped]) {
localMouse = [self convertPoint:CGPointMake(0, NSHeight(clickedCell.frame) * 2) fromView:clickedCell];
localMouse = [self convertPoint:NSMakePoint(0, NSHeight(clickedCell.frame) * 2) fromView:clickedCell];
}

localMouse.y += [self documentVisibleRect].origin.y;
Expand Down
8 changes: 6 additions & 2 deletions Classes/PXListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#import "PXListViewDelegate.h"
#import "PXListViewCell.h"

#import "PXListDocumentView.h"

#if DEBUG
#define PXLog(...) NSLog(__VA_ARGS__)
Expand Down Expand Up @@ -38,6 +38,7 @@
BOOL _allowsMultipleSelection;
NSInteger _lastSelectedRow;

BOOL _dragSupported;
BOOL _verticalMotionCanBeginDrag;

BOOL _usesLiveResize;
Expand All @@ -54,11 +55,15 @@

@property (nonatomic, assign) BOOL allowsEmptySelection;
@property (nonatomic, assign) BOOL allowsMultipleSelection;

@property (nonatomic, assign) BOOL verticalMotionCanBeginDrag;
@property (nonatomic, assign) BOOL dragSupported;

@property (nonatomic, assign) CGFloat cellSpacing;
@property (nonatomic, assign) BOOL usesLiveResize;

- (PXListDocumentView *)documentView;

- (void)reloadData;
-(void)reloadRowAtIndex:(NSInteger)inIndex;

Expand All @@ -72,7 +77,6 @@
- (void)deselectRows;
- (void)selectRowIndexes:(NSIndexSet*)rows byExtendingSelection:(BOOL)doExtend;

- (void)scrollToRow:(NSUInteger)row;
- (void)scrollRowToVisible:(NSUInteger)row;

@end
51 changes: 23 additions & 28 deletions Classes/PXListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#import "PXListViewCell+Private.h"
#import "PXListView+UserInteraction.h"

#import "PXListDocumentView.h"

NSString * const PXListViewSelectionDidChange = @"PXListViewSelectionDidChange";


Expand All @@ -21,9 +23,14 @@ @implementation PXListView
@synthesize cellSpacing = _cellSpacing;
@synthesize allowsMultipleSelection = _allowsMultipleSelection;
@synthesize allowsEmptySelection = _allowsEmptySelection;
@synthesize dragSupported = _dragSupported;
@synthesize verticalMotionCanBeginDrag = _verticalMotionCanBeginDrag;
@synthesize usesLiveResize = _usesLiveResize;

- (PXListDocumentView *)documentView {
return [super documentView];
}

#pragma mark -
#pragma mark Init/Dealloc

Expand All @@ -36,6 +43,7 @@ - (id)initWithFrame:(NSRect)theFrame
_selectedRows = [[NSMutableIndexSet alloc] init];
_allowsEmptySelection = YES;
_usesLiveResize = YES;
_dragSupported = YES;
}

return self;
Expand All @@ -50,6 +58,7 @@ - (id)initWithCoder:(NSCoder*)decoder
_selectedRows = [[NSMutableIndexSet alloc] init];
_allowsEmptySelection = YES;
_usesLiveResize = YES;
_dragSupported = YES;
}

return self;
Expand Down Expand Up @@ -108,6 +117,7 @@ - (void)setDelegate:(id<PXListViewDelegate>)delegate

-(void)reloadRowAtIndex:(NSInteger)inIndex;
{
#pragma unused(inIndex)
[self cacheCellLayout];
[self layoutCells];
//[self layoutCellsForResizeEvent];
Expand Down Expand Up @@ -337,7 +347,9 @@ - (void)updateCells
{
for(NSUInteger i = NSMaxRange(_currentRange); i > NSMaxRange(visibleRange); i--)
{
[self enqueueCell:[_visibleCells lastObject]];
if([_visibleCells lastObject]) {
[self enqueueCell:[_visibleCells lastObject]];
}
}
}
}
Expand All @@ -350,13 +362,15 @@ - (void)updateCells

- (void)selectAll:(id)sender
{
#pragma unused(sender)
if(_allowsMultipleSelection) {
[self setSelectedRows:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, _numberOfRows)]];
}
}

- (void)deselectAll:(id)sender
{
#pragma unused(sender)
[self setSelectedRows:[NSIndexSet indexSet]];
}

Expand Down Expand Up @@ -502,7 +516,7 @@ - (void)cacheCellLayout
- (void)layoutCells
{
//Set the frames of the cells
for(id cell in _visibleCells)
for(PXListViewCell *cell in _visibleCells)
{
NSInteger row = [cell row];
[cell setFrame:[self rectOfRow:row]];
Expand Down Expand Up @@ -552,30 +566,10 @@ - (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize

- (void)contentViewBoundsDidChange:(NSNotification *)notification
{
#pragma unused(notification)
[self updateCells];
}

- (void)scrollToRow:(NSUInteger)row
{
if(row >= _numberOfRows) {
return;
}

// Use minimal scroll necessary, so we don't force the selection to upper left of window:
NSRect visibleRect = [self documentVisibleRect];
NSRect rowRect = [self rectOfRow:row];

NSPoint newScrollPoint = rowRect.origin;

//Have we over-scrolled?
if(NSMaxY(rowRect) > NSMaxY(visibleRect)) {
newScrollPoint.y = _totalHeight - NSHeight(visibleRect);
}

[[self contentView] scrollToPoint:newScrollPoint];
[self reflectScrolledClipView:[self contentView]];
}

- (void)scrollRowToVisible:(NSUInteger)row
{
if(row >= _numberOfRows) {
Expand All @@ -592,11 +586,11 @@ - (void)scrollRowToVisible:(NSUInteger)row

NSPoint newScrollPoint = rowRect.origin;

//Have we over-scrolled?
if(NSMaxY(rowRect) > NSMaxY(visibleRect)) {
newScrollPoint.y = _totalHeight - NSHeight(visibleRect);
}
if(NSMaxY(visibleRect) > NSMaxY(rowRect))
newScrollPoint.y = NSMinY(rowRect);
else
newScrollPoint.y = NSMinY(visibleRect) - (NSMaxY(visibleRect) - NSMinY(rowRect)) + NSHeight(rowRect);

[[self contentView] scrollToPoint:newScrollPoint];
[self reflectScrolledClipView:[self contentView]];
}
Expand Down Expand Up @@ -657,6 +651,7 @@ -(void)viewDidEndLiveResize

-(void)windowSizing:(NSNotification *)inNot
{
#pragma unused(inNot)
[self layoutCellsForResizeEvent];
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/PXListViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@property (readonly) NSUInteger row;

@property (readonly,getter=isSelected) BOOL selected;
@property (assign) PXListViewDropHighlight dropHighlight;
@property (assign,nonatomic) PXListViewDropHighlight dropHighlight;

+ (id)cellLoadedFromNibNamed:(NSString*)nibName reusableIdentifier:(NSString*)identifier;
+ (id)cellLoadedFromNibNamed:(NSString*)nibName bundle:(NSBundle*)bundle reusableIdentifier:(NSString*)identifier;
Expand Down
5 changes: 3 additions & 2 deletions Classes/PXListViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ + (id)cellLoadedFromNibNamed:(NSString*)nibName bundle:(NSBundle*)bundle reusabl

- (id)initWithReusableIdentifier:(NSString*)identifier
{
if((self = [super initWithFrame: NSZeroRect]))
if((self = [self initWithFrame: NSZeroRect]))
{
_reusableIdentifier = [identifier copy];
}
Expand All @@ -66,7 +66,7 @@ - (id)initWithReusableIdentifier:(NSString*)identifier

- (id)initWithCoder:(NSCoder *)aDecoder
{
if((self = [super initWithCoder: aDecoder]))
if((self = [self initWithCoder: aDecoder]))
{
_reusableIdentifier = NSStringFromClass([self class]);
}
Expand Down Expand Up @@ -108,6 +108,7 @@ - (void)setDropHighlight:(PXListViewDropHighlight)inState

- (void)drawRect:(NSRect)dirtyRect
{
#pragma unused(dirtyRect)
if(_dropHighlight == PXListViewDropAbove)
{
[[NSColor alternateSelectedControlColor] set];
Expand Down
Loading