-
Notifications
You must be signed in to change notification settings - Fork 9
/
QSTableView.m
170 lines (138 loc) · 4.82 KB
/
QSTableView.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#import "QSTableView.h"
#import <QSFoundation/NSColor_QSModifications.h>
@interface NSTableView (SingleRowDisplay)
- (void)_setNeedsDisplayInRow:(int)fp8;
@end
@implementation QSTableView
//- (void)awakeFromNib {
// //[self setHeaderView:[[[ABPropertyHeaderView alloc] initWithFrame:[[self headerView] frame]]autorelease]];
//}
//
- (BOOL)canDragRowsWithIndexes:(NSIndexSet *)rowIndexes atPoint:(NSPoint)mouseDownPoint {
return YES;
}
- (NSDragOperation) draggingEntered:(id <NSDraggingInfo>)sender {
[draggingDelegate draggingEntered:sender];
return [super draggingEntered:sender];
}
- (NSDragOperation) draggingUpdated:(id <NSDraggingInfo>)sender {
[draggingDelegate draggingUpdated:sender];
return [super draggingUpdated:sender];
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
[draggingDelegate draggingExited:sender];
[super draggingExited:sender];
return;
}
- (NSDragOperation) draggingSourceOperationMaskForLocal:(BOOL)isLocal {
//NSLog(@"source");
if (isLocal) return NSDragOperationEvery;
else return NSDragOperationEvery;
}
- (BOOL)isOpaque {
return opaque;
}
- (void)setOpaque:(BOOL)flag {
opaque = flag;
}
- (void)drawRow:(int)rowIndex clipRect:(NSRect)clipRect {
// drawingRow = rowIndex;
if ([[self delegate] respondsToSelector:@selector(tableView:rowIsSeparator:)]
&& [[self delegate] tableView:self rowIsSeparator:rowIndex]) {
if (![[self delegate] respondsToSelector:@selector(tableView:shouldDrawRow:inClipRect:)]
|| [[self delegate] tableView:self shouldDrawRow:rowIndex inClipRect:clipRect]) {
[self drawSeparatorForRow:rowIndex clipRect:clipRect];
}
} else {
[super drawRow:rowIndex clipRect:clipRect];
}
}
- (id)initWithFrame:(NSRect) rect {
self = [super initWithFrame:rect];
if (self != nil) {
opaque = YES;
drawsBackground = YES;
}
return self;
}
- (void)awakeFromNib {
opaque = YES;
drawsBackground = YES;
}
- (void)drawBackgroundInClipRect:(NSRect)clipRect {
if (drawsBackground) {
if ([self backgroundColor]) {
[[self backgroundColor] set];
NSRectFillUsingOperation(clipRect, NSCompositeCopy);
} else {
[super drawBackgroundInClipRect:clipRect];
}
}
}
- (BOOL)drawsBackground {
return drawsBackground;
}
- (void)setDrawsBackground:(BOOL)value {
if (drawsBackground != value) {
drawsBackground = value;
}
}
- (void)setHighlightColorForBackgroundColor:(NSColor *)color {
[self setHighlightColor:[[self backgroundColor] blendedColorWithFraction:0.25 ofColor:[[self backgroundColor] readableTextColor]]];
}
- (id)_highlightColorForCell:(NSCell *)cell {
if (highlightColor)
return highlightColor;
//return [super _highlightColorForCell:(NSCell *)cell];
return [NSColor alternateSelectedControlColor];
}
- (NSColor *)highlightColor { return highlightColor; }
- (void)setHighlightColor:(NSColor *)aHighlightColor {
if (highlightColor != aHighlightColor) {
[highlightColor release];
highlightColor = [aHighlightColor copy];
[self setNeedsDisplay:YES];
}
}
- (void)setBackgroundColor:(NSColor *)color {
[super setBackgroundColor:color];
[self setNeedsDisplay:YES];
}
- (void)redisplayRows:(NSIndexSet *)indexes {
if ([self respondsToSelector:@selector(_setNeedsDisplayInRow:)])
[self _setNeedsDisplayInRow:[indexes firstIndex]];
// ***warning * incomplete
else [self setNeedsDisplay:YES];
}
- (NSMenu*)menuForEvent:(NSEvent*)evt {
// NSLog (@"event");
NSPoint point = [self convertPoint:[evt locationInWindow] fromView:NULL];
int column = [self columnAtPoint:point];
int row = [self rowAtPoint:point];
if ( column >= 0 && row >= 0 && [[self delegate] respondsToSelector:@selector(tableView:menuForTableColumn:row:)] )
return [[self delegate] tableView:self menuForTableColumn:[[self tableColumns] objectAtIndex:column] row:row];
return [super menuForEvent:evt];
}
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation {
[super draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation];
if ([[self dataSource] respondsToSelector:@selector(tableView:dropEndedWithOperation:)] )
[[self dataSource] tableView:self dropEndedWithOperation:operation];
}
- (id)draggingDelegate { return draggingDelegate; }
- (void)setDraggingDelegate:(id)aDraggingDelegate {
if (draggingDelegate != aDraggingDelegate) {
[draggingDelegate release];
draggingDelegate = [aDraggingDelegate retain];
}
}
@end
@implementation NSTableView (MenuExtensions)
- (NSMenu*)menuForEvent:(NSEvent*)evt {
NSPoint point = [self convertPoint:[evt locationInWindow] fromView:NULL];
int column = [self columnAtPoint:point];
int row = [self rowAtPoint:point];
if ( column >= 0 && row >= 0 && [[self delegate] respondsToSelector:@selector(tableView:menuForTableColumn:row:)] )
return [[self delegate] tableView:self menuForTableColumn:[[self tableColumns] objectAtIndex:column] row:row];
return [super menuForEvent:evt];
}
@end