Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 100 lines (73 sloc) 2.681 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
//
// JAListViewItem.m
//
// Created by Josh Abernathy on 10/27/10.
// Copyright 2010 Maybe Apps. All rights reserved.
//

#import "JAListViewItem.h"
#import "JAListView.h"
#import "JASectionedListView.h"


@implementation JAListViewItem


#pragma mark NSView

- (void)scrollWheel:(NSEvent *)event {
[self.listView markViewBeingUsedForInertialScrolling:self];
    [super scrollWheel:event];
}


#pragma mark NSResponder

- (BOOL)acceptsFirstResponder {
    return YES;
}


#pragma mark API

@synthesize ignoreInListViewLayout;
@synthesize listView;
@synthesize selected;
@synthesize highlighted;
@synthesize listViewPosition;

- (NSImage *)draggingImage {
    NSBitmapImageRep *bitmap = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
    [self cacheDisplayInRect:self.bounds toBitmapImageRep:bitmap];
    
    NSSize imageSize = [bitmap size];
    NSImage *image = [[[NSImage alloc] initWithSize:imageSize] autorelease];
    [image addRepresentation:bitmap];
    
    NSImage *result = [[[NSImage alloc] initWithSize:imageSize] autorelease];
    [result lockFocus];
    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
    NSImageInterpolation savedInterpolation = [currentContext imageInterpolation];
    [currentContext setImageInterpolation:NSImageInterpolationHigh];
    [image drawInRect:NSMakeRect(0, 0, imageSize.width, imageSize.height) fromRect:NSMakeRect(0, 0, imageSize.width, imageSize.height) operation:NSCompositeSourceOver fraction:.5];
    [currentContext setImageInterpolation:savedInterpolation];
    [result unlockFocus];
    
    return result;
}

- (JAListViewPosition)listViewPosition {
JAListViewPosition position = JAListViewPositionNone;
NSUInteger index = (NSUInteger) [self.listView indexForView:self];
NSUInteger numberOfViews = [self.listView numberOfViews];

if([self.listView isKindOfClass:[JASectionedListView class]]) {
JASectionedListView *sectionedListView = (JASectionedListView *) self.listView;
NSUInteger section = 0;
NSUInteger newIndex = index;
[sectionedListView getSection:&section andIndex:&newIndex fromAbsoluteIndex:index];
index = newIndex;
numberOfViews = [sectionedListView numberOfViewsInSection:section];
}

if(index == numberOfViews - 1) {
position |= JAListViewPositionBottom;
}

if(index == 0) {
position |= JAListViewPositionTop;
}

if(position == JAListViewPositionNone) {
position = JAListViewPositionMiddle;
}

return position;
}

- (void)setSelected:(BOOL)newValue {
    selected = newValue;
    
    [self setNeedsDisplay:YES];
}

- (void)setHighlighted:(BOOL)newValue {
    highlighted = newValue;
    
    [self setNeedsDisplay:YES];
}

@end
Something went wrong with that request. Please try again.