-
Notifications
You must be signed in to change notification settings - Fork 20
/
JAListViewItem.m
101 lines (74 loc) · 2.65 KB
/
JAListViewItem.m
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
101
//
// 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;
@synthesize ignoresListViewPadding;
- (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:§ion 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