* MYTask: Added -commandLine, overhauled logging.
* MYDirectoryWatcher: Overhauled logging.
* MYErrorUtils: Disabled use of Security API (so it'll build without linking against Security.framework.)
3 Copyright (c) 2001-2006, Apple Computer, Inc., all rights reserved.
7 * 03-01-2001: Initial creation by Chuck Pisula
8 * 11-04-2005: Added hitTestForEvent:inRect:ofView: for better NSOutlineView support by Corbin Dunn
10 Subclass of NSTextFieldCell which can display text and an image simultaneously.
14 IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in
15 consideration of your agreement to the following terms, and your use, installation,
16 modification or redistribution of this Apple software constitutes acceptance of these
17 terms. If you do not agree with these terms, please do not use, install, modify or
18 redistribute this Apple software.
20 In consideration of your agreement to abide by the following terms, and subject to these
21 terms, Apple grants you a personal, non-exclusive license, under AppleÕs copyrights in
22 this original Apple software (the "Apple Software"), to use, reproduce, modify and
23 redistribute the Apple Software, with or without modifications, in source and/or binary
24 forms; provided that if you redistribute the Apple Software in its entirety and without
25 modifications, you must retain this notice and the following text and disclaimers in all
26 such redistributions of the Apple Software. Neither the name, trademarks, service marks
27 or logos of Apple Computer, Inc. may be used to endorse or promote products derived from
28 the Apple Software without specific prior written permission from Apple. Except as expressly
29 stated in this notice, no other rights or licenses, express or implied, are granted by Apple
30 herein, including but not limited to any patent rights that may be infringed by your
31 derivative works or by other works in which the Apple Software may be incorporated.
33 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
34 EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
35 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS
36 USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
38 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
39 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE,
41 REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND
42 WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR
43 OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 #import "ImageAndTextCell.h"
47 #import <AppKit/NSCell.h>
49 @implementation ImageAndTextCell
54 [self setLineBreakMode:NSLineBreakByTruncatingTail];
55 [self setSelectable:YES];
65 - (id)copyWithZone:(NSZone *)zone {
66 ImageAndTextCell *cell = (ImageAndTextCell *)[super copyWithZone:zone];
67 // The image ivar will be directly copied; we need to retain or copy it.
68 cell->image = [image retain];
72 - (void)setImage:(NSImage *)anImage {
73 if (anImage != image) {
75 image = [anImage retain];
83 - (NSRect)imageRectForBounds:(NSRect)cellFrame {
86 result.size = [image size];
87 result.origin = cellFrame.origin;
89 result.origin.y += ceil((cellFrame.size.height - result.size.height) / 2);
96 // We could manually implement expansionFrameWithFrame:inView: and drawWithExpansionFrame:inView: or just properly implement titleRectForBounds to get expansion tooltips to automatically work for us
97 - (NSRect)titleRectForBounds:(NSRect)cellFrame {
100 CGFloat imageWidth = [image size].width;
102 result.origin.x += (3 + imageWidth);
103 result.size.width -= (3 + imageWidth);
111 - (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent {
112 NSRect textFrame, imageFrame;
113 NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
114 [super editWithFrame: textFrame inView: controlView editor:textObj delegate:anObject event: theEvent];
117 - (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength {
118 NSRect textFrame, imageFrame;
119 NSDivideRect (aRect, &imageFrame, &textFrame, 3 + [image size].width, NSMinXEdge);
120 [super selectWithFrame: textFrame inView: controlView editor:textObj delegate:anObject start:selStart length:selLength];
123 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
126 NSSize imageSize = [image size];
127 NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge);
128 if ([self drawsBackground]) {
129 [[self backgroundColor] set];
130 NSRectFill(imageFrame);
132 imageFrame.origin.x += 3;
133 imageFrame.size = imageSize;
135 if ([controlView isFlipped])
136 imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2);
138 imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
140 [image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
142 [super drawWithFrame:cellFrame inView:controlView];
146 NSSize cellSize = [super cellSize];
147 cellSize.width += (image ? [image size].width : 0) + 3;
151 - (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView {
152 NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil];
153 // If we have an image, we need to see if the user clicked on the image portion.
155 // This code closely mimics drawWithFrame:inView:
156 NSSize imageSize = [image size];
158 NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge);
160 imageFrame.origin.x += 3;
161 imageFrame.size = imageSize;
162 // If the point is in the image rect, then it is a content hit
163 if (NSMouseInRect(point, imageFrame, [controlView isFlipped])) {
164 // We consider this just a content area. It is not trackable, nor it it editable text. If it was, we would or in the additional items.
165 // By returning the correct parts, we allow NSTableView to correctly begin an edit when the text portion is clicked on.
166 return NSCellHitContentArea;
169 // At this point, the cellFrame has been modified to exclude the portion for the image. Let the superclass handle the hit testing at this point.
170 return [super hitTestForEvent:event inRect:cellFrame ofView:controlView];