-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSYMultiTextFieldCell.m
148 lines (119 loc) · 4.04 KB
/
SSYMultiTextFieldCell.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
#import "SSYMultiTextFieldCell.h"
#import "NSImage+SSYDarkMode.h"
#import "NSView+SSYDarkMode.h"
@implementation SSYMultiTextFieldCell
@synthesize images = m_images ;
@synthesize overdrawsRectOfDisclosureTriangle ;
- (id)init {
self = [super init] ;
if (self) {
// The following is important not just for drawing the
// cell normally but for drawing the expansion frame tool tip
// properly.
[self setScrollable:YES] ;
[self setLineBreakMode:NSLineBreakByTruncatingMiddle] ;
}
return self ;
}
- (id)copyWithZone:(NSZone *)zone {
SSYMultiTextFieldCell *result = [super copyWithZone:zone];
result->overdrawsRectOfDisclosureTriangle = [self overdrawsRectOfDisclosureTriangle] ;
// Each time NSTableView goes to track or edit a cell, it copies
// it, using copyWithZone. super just does an address copy,
// which does not give the required -retain. So, we chuck that:
result->m_images = nil ;
// and now instead we set it, which will give a retain.
[result setImages:m_images] ;
return result ;
}
- (void)dealloc {
[m_images release] ;
[super dealloc] ;
}
// Setting the following to non-zero makes images scale badly
// I don't know why ... maybe it's because my bookmark and sorted/unsorted
// icons were hand-tweak to look good with the common row height (reportFontSize)
#define MARGIN_FACTOR 0.0
- (NSRect)drawAtLeftImage:(NSImage*)image
cellFrame:(NSRect)cellFrame
controlView:(NSView*)controlView {
if (image != nil) {
CGFloat imageDimension = (1-MARGIN_FACTOR) * cellFrame.size.height ;
NSSize imageSize ;
imageSize.height = imageDimension ;
imageSize.width = imageDimension ;
NSRect imageFrame ;
NSDivideRect(cellFrame, &imageFrame, &cellFrame, imageSize.width, NSMinXEdge) ;
if ([self drawsBackground]) {
[[self backgroundColor] set];
NSRectFill(imageFrame);
}
NSCompositingOperation operation = [controlView isDarkMode_SSY]
? NSCompositingOperationPlusLighter
: NSCompositingOperationPlusDarker;
[image drawInRect:imageFrame
operation:operation
fraction:1.0
invertIfDarkMode:YES
inView:controlView];
}
return cellFrame ;
}
/* This method never seems to run
- (void)highlight:(BOOL)flag
withFrame:(NSRect)cellFrame
inView:(NSView *)controlView {
[super highlight:flag
withFrame:cellFrame
inView:controlView] ;
}
*/
// This is an over-ride of an NSCell method
#define LEFT_MARGIN 3.0
- (void)drawWithFrame:(NSRect)cellFrame
inView:(NSView *)controlView {
if ([self overdrawsRectOfDisclosureTriangle]) {
cellFrame.size.width += (cellFrame.origin.x - LEFT_MARGIN) ;
cellFrame.origin.x = LEFT_MARGIN ;
}
NSInteger i = 0 ;
for (NSImage* image in [self images]) {
// Because the following method returns the as cellFrame the part
// of the cell remaining for the text, and because this is fed
// back in, subsequent iterations place the given images in a row,
// starting from the left.
cellFrame = [self drawAtLeftImage:image
cellFrame:cellFrame
controlView:controlView] ;
i++ ;
}
[super drawWithFrame:cellFrame
inView:controlView] ;
}
@end
//-(BOOL)trackMouse:(NSEvent *)theEvent
// inRect:(NSRect)cellFrame
// ofView:(NSView *)controlView untilMouseUp:(BOOL)untiMouseUp
//{
// NSPoint mousePoint = [controlView convertPoint:[theEvent locationInWindow] fromView:nil];
// if (NSPointInRect(mousePoint cellFrame)
// {
// [self showPopUpWithEvent:theEvent ofView:controlView
// cellFrame:cellFrame];
// }
// else
// //do nothing
// return YES;
//
//}
//
//Now you will have to creat a contextual Menu do it in showPopUpWithEvent
//method:
//
//-(void)showPopUpWithEvent:(NSEvent*)theEvent ofView:(NSView *)controlView
// cellFrame:(NSRect *)inCellFrame
//{
// //Create a menu here ...say your menu object is aenu
// [NSMenu popUpContextMenu:aMenu withEvent:theEvent
// forView:controlView];
//}