(fixes issue #501) NSPathControl implementation by Sven Weidauer

This commit is contained in:
Christopher Lloyd 2010-03-02 16:13:56 +00:00
parent c21f2f33dc
commit 9f325482c4
8 changed files with 599 additions and 15 deletions

View File

@ -85,6 +85,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSPanel.h>
#import <AppKit/NSParagraphStyle.h>
#import <AppKit/NSPasteboard.h>
#import <AppKit/NSPathCell.h>
#import <AppKit/NSPathComponentCell.h>
#import <AppKit/NSPathControl.h>
#import <AppKit/NSPDFImageRep.h>
#import <AppKit/NSPopUpButton.h>
#import <AppKit/NSPopUpButtonCell.h>

View File

@ -2129,11 +2129,11 @@
FE463D8A102CAF4A00B265D6 /* NSDockTile.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463D84102CAF4A00B265D6 /* NSDockTile.m */; };
FE463D8B102CAF4A00B265D6 /* NSDockTile.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463D83102CAF4A00B265D6 /* NSDockTile.h */; };
FE463D8C102CAF4A00B265D6 /* NSDockTile.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463D84102CAF4A00B265D6 /* NSDockTile.m */; };
FE463ED4102D0F9D00B265D6 /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; };
FE463ED4102D0F9D00B265D6 /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463ED5102D0F9D00B265D6 /* NSPathCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC5102D0F9C00B265D6 /* NSPathCell.m */; };
FE463ED6102D0F9D00B265D6 /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; };
FE463ED6102D0F9D00B265D6 /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463ED7102D0F9D00B265D6 /* NSPathComponentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC7102D0F9C00B265D6 /* NSPathComponentCell.m */; };
FE463ED8102D0F9D00B265D6 /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; };
FE463ED8102D0F9D00B265D6 /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463ED9102D0F9D00B265D6 /* NSPathControl.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC9102D0F9D00B265D6 /* NSPathControl.m */; };
FE463EDA102D0F9D00B265D6 /* NSPredicateEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ECA102D0F9D00B265D6 /* NSPredicateEditor.h */; };
FE463EDB102D0F9D00B265D6 /* NSPredicateEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ECB102D0F9D00B265D6 /* NSPredicateEditor.m */; };
@ -2145,11 +2145,11 @@
FE463EE1102D0F9D00B265D6 /* NSTreeNode.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ED1102D0F9D00B265D6 /* NSTreeNode.m */; };
FE463EE2102D0F9D00B265D6 /* NSViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ED2102D0F9D00B265D6 /* NSViewController.h */; };
FE463EE3102D0F9D00B265D6 /* NSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ED3102D0F9D00B265D6 /* NSViewController.m */; };
FE463EE4102D0F9D00B265D6 /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; };
FE463EE4102D0F9D00B265D6 /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463EE5102D0F9D00B265D6 /* NSPathCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC5102D0F9C00B265D6 /* NSPathCell.m */; };
FE463EE6102D0F9D00B265D6 /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; };
FE463EE6102D0F9D00B265D6 /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463EE7102D0F9D00B265D6 /* NSPathComponentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC7102D0F9C00B265D6 /* NSPathComponentCell.m */; };
FE463EE8102D0F9D00B265D6 /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; };
FE463EE8102D0F9D00B265D6 /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463EE9102D0F9D00B265D6 /* NSPathControl.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC9102D0F9D00B265D6 /* NSPathControl.m */; };
FE463EEA102D0F9D00B265D6 /* NSPredicateEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ECA102D0F9D00B265D6 /* NSPredicateEditor.h */; };
FE463EEB102D0F9D00B265D6 /* NSPredicateEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ECB102D0F9D00B265D6 /* NSPredicateEditor.m */; };
@ -2161,11 +2161,11 @@
FE463EF1102D0F9D00B265D6 /* NSTreeNode.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ED1102D0F9D00B265D6 /* NSTreeNode.m */; };
FE463EF2102D0F9D00B265D6 /* NSViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ED2102D0F9D00B265D6 /* NSViewController.h */; };
FE463EF3102D0F9D00B265D6 /* NSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ED3102D0F9D00B265D6 /* NSViewController.m */; };
FE463EF4102D0F9D00B265D6 /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; };
FE463EF4102D0F9D00B265D6 /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463EF5102D0F9D00B265D6 /* NSPathCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC5102D0F9C00B265D6 /* NSPathCell.m */; };
FE463EF6102D0F9D00B265D6 /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; };
FE463EF6102D0F9D00B265D6 /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463EF7102D0F9D00B265D6 /* NSPathComponentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC7102D0F9C00B265D6 /* NSPathComponentCell.m */; };
FE463EF8102D0F9D00B265D6 /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; };
FE463EF8102D0F9D00B265D6 /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463EF9102D0F9D00B265D6 /* NSPathControl.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC9102D0F9D00B265D6 /* NSPathControl.m */; };
FE463EFA102D0F9D00B265D6 /* NSPredicateEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ECA102D0F9D00B265D6 /* NSPredicateEditor.h */; };
FE463EFB102D0F9D00B265D6 /* NSPredicateEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ECB102D0F9D00B265D6 /* NSPredicateEditor.m */; };
@ -2177,11 +2177,11 @@
FE463F01102D0F9D00B265D6 /* NSTreeNode.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ED1102D0F9D00B265D6 /* NSTreeNode.m */; };
FE463F02102D0F9D00B265D6 /* NSViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ED2102D0F9D00B265D6 /* NSViewController.h */; };
FE463F03102D0F9D00B265D6 /* NSViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ED3102D0F9D00B265D6 /* NSViewController.m */; };
FE463F04102D0F9D00B265D6 /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; };
FE463F04102D0F9D00B265D6 /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463F05102D0F9D00B265D6 /* NSPathCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC5102D0F9C00B265D6 /* NSPathCell.m */; };
FE463F06102D0F9D00B265D6 /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; };
FE463F06102D0F9D00B265D6 /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463F07102D0F9D00B265D6 /* NSPathComponentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC7102D0F9C00B265D6 /* NSPathComponentCell.m */; };
FE463F08102D0F9D00B265D6 /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; };
FE463F08102D0F9D00B265D6 /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE463F09102D0F9D00B265D6 /* NSPathControl.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463EC9102D0F9D00B265D6 /* NSPathControl.m */; };
FE463F0A102D0F9D00B265D6 /* NSPredicateEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ECA102D0F9D00B265D6 /* NSPredicateEditor.h */; };
FE463F0B102D0F9D00B265D6 /* NSPredicateEditor.m in Sources */ = {isa = PBXBuildFile; fileRef = FE463ECB102D0F9D00B265D6 /* NSPredicateEditor.m */; };
@ -2564,9 +2564,9 @@
FE5A8A4310C6F50E005E348A /* NSAnimationContext.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463D63102CAE3500B265D6 /* NSAnimationContext.h */; };
FE5A8A4410C6F50E005E348A /* NSCollectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463D6D102CAEF500B265D6 /* NSCollectionView.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE5A8A4510C6F50E005E348A /* NSDockTile.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463D83102CAF4A00B265D6 /* NSDockTile.h */; };
FE5A8A4610C6F50E005E348A /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; };
FE5A8A4710C6F50E005E348A /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; };
FE5A8A4810C6F50E005E348A /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; };
FE5A8A4610C6F50E005E348A /* NSPathCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC4102D0F9C00B265D6 /* NSPathCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE5A8A4710C6F50E005E348A /* NSPathComponentCell.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC6102D0F9C00B265D6 /* NSPathComponentCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE5A8A4810C6F50E005E348A /* NSPathControl.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463EC8102D0F9C00B265D6 /* NSPathControl.h */; settings = {ATTRIBUTES = (Public, ); }; };
FE5A8A4910C6F50E005E348A /* NSPredicateEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ECA102D0F9D00B265D6 /* NSPredicateEditor.h */; };
FE5A8A4A10C6F50E005E348A /* NSPredicateEditorRowTemplate.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ECC102D0F9D00B265D6 /* NSPredicateEditorRowTemplate.h */; };
FE5A8A4B10C6F50E005E348A /* NSRuleEditor.h in Headers */ = {isa = PBXBuildFile; fileRef = FE463ECE102D0F9D00B265D6 /* NSRuleEditor.h */; };

View File

@ -0,0 +1,65 @@
#import <AppKit/NSActionCell.h>
#import <AppKit/NSSavePanel.h>
@class NSPathComponentCell;
@class NSURL;
@class NSColor;
enum {
NSPathStyleStandard,
NSPathStyleNavigationBar,
NSPathStylePopUp,
};
typedef NSInteger NSPathStyle;
@interface NSPathCell : NSActionCell // < NSOpenSavePanelDelegate >
{
NSURL *_URL;
NSPathStyle _pathStyle;
SEL _doubleAction;
NSArray *_pathComponentCells;
id _delegate;
NSColor *_backgroundColor;
NSArray *_allowedTypes;
NSAttributedString *_placeholder;
}
- (void)mouseEntered:(NSEvent *)event withFrame:(NSRect)frame inView:(NSView *)view;
- (void)mouseExited:(NSEvent *)event withFrame:(NSRect)frame inView:(NSView *)view;
- (NSArray *)allowedTypes;
- (void)setAllowedTypes:(NSArray *)allowedTypes;
- (NSPathStyle)pathStyle;
- (void)setPathStyle:(NSPathStyle)style;
- (id) objectValue;
- (void)setObjectValue:(id <NSCopying>)obj;
- (NSAttributedString *)placeholderAttributedString;
- (void)setPlaceholderAttributedString:(NSAttributedString *)string;
- (NSString *)placeholderString;
- (void)setPlaceholderString:(NSString *)string;
- (NSColor *)backgroundColor;
- (void)setBackgroundColor:(NSColor *)color;
+ (Class)pathComponentCellClass;
- (NSRect)rectOfPathComponentCell:(NSPathComponentCell *)cell withFrame:(NSRect)frame inView:(NSView *)view;
- (NSPathComponentCell *)pathComponentCellAtPoint:(NSPoint)point withFrame:(NSRect)frame inView:(NSView *)view;
- (NSPathComponentCell *)clickedPathComponentCell;
- (NSArray *)pathComponentCells;
- (void)setPathComponentCells:(NSArray *)cells;
- (SEL)doubleAction;
- (void)setDoubleAction:(SEL)action;
- (NSURL *)URL;
- (void)setURL:(NSURL *)url;
- (id)delegate;
- (void)setDelegate:(id)delegate;
@end

View File

@ -0,0 +1,266 @@
#import "NSPathCell.h"
#import <AppKit/NSPathComponentCell.h>
#import <AppKit/AppKit.h>
#import "AppKit/NSRaise.h"
@implementation NSPathCell
- initWithCoder: (NSCoder *) coder;
{
self = [super initWithCoder: coder];
if (self) {
if (![coder allowsKeyedCoding]) {
[NSException raise:NSInvalidArgumentException format:@"%@ can not initWithCoder:%@",isa,[coder class]];
}
NSKeyedUnarchiver *keyed = (NSKeyedUnarchiver *)coder;
[self setPlaceholderString: [keyed decodeObjectForKey: @"NSPlaceholderString"]];
[self setBackgroundColor: [keyed decodeObjectForKey: @"NSBackgroundColor"]];
[self setPathComponentCells: [keyed decodeObjectForKey: @"NSPathComponentCells"]];
[self setPathStyle: [keyed decodeIntForKey: @"NSPathStyle"]];
[self setDelegate: [keyed decodeObjectForKey: @"NSDelegate"]];
[self setAllowedTypes: [keyed decodeObjectForKey: @"NSAllowedTypes"]];
}
return self;
}
- (void)mouseEntered:(NSEvent *)event withFrame:(NSRect)frame inView:(NSView *)view;
{
NSUnimplementedMethod();
}
- (void)mouseExited:(NSEvent *)event withFrame:(NSRect)frame inView:(NSView *)view;
{
NSUnimplementedMethod();
}
- (NSArray *)allowedTypes;
{
return [[_allowedTypes retain] autorelease];
}
- (void)setAllowedTypes:(NSArray *)allowedTypes;
{
if (allowedTypes != _allowedTypes) {
[_allowedTypes release];
_allowedTypes = [allowedTypes copy];
}
}
- (NSPathStyle)pathStyle;
{
return _pathStyle;
}
- (void)setPathStyle:(NSPathStyle)style;
{
if (_pathStyle != style) {
_pathStyle = style;
[[self controlView] setNeedsDisplay: YES];
}
}
- (id) objectValue;
{
return [self URL];
}
- (void)setObjectValue:(id <NSCopying>)newObj;
{
id obj = newObj;
NSAssert( [obj isKindOfClass: [NSURL class]] || [obj isKindOfClass: [NSString class]], @"NSPathCell accepts URLs or strings as path" );
if ([obj isKindOfClass: [NSURL class]]) [self setURL: obj];
else [self setURL: [NSURL fileURLWithPath: obj]];
}
- (NSAttributedString *)placeholderAttributedString;
{
return [[_placeholder retain] autorelease];
}
- (void)setPlaceholderAttributedString:(NSAttributedString *)string;
{
if (_placeholder != string) {
[_placeholder release];
_placeholder = [string copy];
}
}
- (NSString *)placeholderString;
{
return [_placeholder string];
}
- (void)setPlaceholderString:(NSString *)string;
{
[self setPlaceholderAttributedString: [[[NSAttributedString alloc] initWithString: string] autorelease]];
}
- (NSColor *)backgroundColor;
{
return [[_backgroundColor retain] autorelease];
}
- (void)setBackgroundColor:(NSColor *)color;
{
if (_backgroundColor != color) {
[_backgroundColor release];
_backgroundColor = [color copy];
}
}
+ (Class)pathComponentCellClass;
{
return [NSPathComponentCell class];
}
- (NSRect)rectOfPathComponentCell:(NSPathComponentCell *)cell withFrame:(NSRect)frame inView:(NSView *)view;
{
NSRect rect = frame;
for (NSPathComponentCell *currentCell in _pathComponentCells) {
rect.size.width = [currentCell cellSize].width;
if (cell == currentCell) return rect;
rect.origin.x += rect.size.width + 5;
}
return NSZeroRect;
}
- (NSPathComponentCell *)pathComponentCellAtPoint:(NSPoint)point withFrame:(NSRect)frame inView:(NSView *)view;
{
for (NSPathComponentCell *cell in _pathComponentCells) {
NSRect cellFrame = [self rectOfPathComponentCell: cell withFrame: frame inView: view];
if (NSPointInRect( point, cellFrame )) return cell;
}
return nil;
}
- (NSPathComponentCell *)clickedPathComponentCell;
{
NSUnimplementedMethod();
return nil;
}
- (NSArray *)pathComponentCells;
{
return [[_pathComponentCells retain] autorelease];
}
- (void)setPathComponentCells:(NSArray *)cells;
{
if (_pathComponentCells != cells) {
[_pathComponentCells release];
_pathComponentCells = [cells retain];
[[self controlView] setNeedsDisplay: YES];
}
}
- (SEL)doubleAction;
{
return _doubleAction;
}
- (void)setDoubleAction:(SEL)action;
{
_doubleAction = action;
}
- (NSURL *)URL;
{
return [[_URL retain] autorelease];
}
- (void)setURL:(NSURL *)url;
{
if (url != _URL) {
[_URL release];
_URL = [url copy];
NSMutableArray *cells = nil;
if (url) {
NSString *host = [url host];
NSString *path = [url path];
NSString *scheme = [url scheme];
NSArray *pathComponents = [path pathComponents];
cells = [NSMutableArray arrayWithCapacity: [pathComponents count]];
BOOL isFileURL = [url isFileURL];
NSFileManager *fm = nil;
NSWorkspace *ws = nil;
if (isFileURL) {
fm = [NSFileManager defaultManager];
ws = [NSWorkspace sharedWorkspace];
}
NSMutableString *currentPath = [NSMutableString stringWithCapacity: [path length]];
[currentPath appendString: @"/"];
Class pcClass = [[self class] pathComponentCellClass];
for (NSString *path in pathComponents) {
[currentPath appendString: path];
NSURL *currentUrl = [[[NSURL alloc] initWithScheme: scheme host: host path: currentPath] autorelease];
NSString *title = path;
NSImage *image = nil;
if (isFileURL) {
NSString *currentPath = [currentUrl path];
title = [fm displayNameAtPath: currentPath];
image = [ws iconForFile: currentPath];
}
NSPathComponentCell *cell = [[[pcClass alloc] initTextCell: nil] autorelease];
[cell setURL: currentUrl];
[cell setImage: image];
[cell setStringValue: title];
[cells addObject: cell];
[currentPath appendString: @"/"];
}
}
[self setPathComponentCells: cells];
}
}
- (id)delegate;
{
return _delegate;
}
- (void)setDelegate:(id)delegate;
{
_delegate = delegate;
}
- (void) dealloc;
{
[self setAllowedTypes: nil];
[self setURL: nil];
[self setBackgroundColor: nil];
[super dealloc];
}
- (void) drawInteriorWithFrame:(NSRect)frame inView:(NSView *)view;
{
[_backgroundColor set];
[NSBezierPath fillRect: frame];
for (NSPathComponentCell *cell in _pathComponentCells) {
NSRect cellFrame = [self rectOfPathComponentCell: cell withFrame: frame inView: view];
[cell drawInteriorWithFrame: cellFrame inView: view];
}
}
@end

View File

@ -0,0 +1,11 @@
#import <AppKit/NSTextFieldCell.h>
@interface NSPathComponentCell : NSTextFieldCell
{
NSURL *_URL;
}
- (NSURL *) URL;
- (void) setURL: (NSURL *) newURL;
@end

View File

@ -0,0 +1,65 @@
#import <AppKit/NSPathComponentCell.h>
#import "AppKit/NSRaise.h"
#import <AppKit/NSStringDrawing.h>
#import <AppKit/NSImage.h>
#import <Appkit/NSAttributedString.h>
@implementation NSPathComponentCell
- (NSURL *) URL;
{
return [[_URL retain] autorelease];
}
- (void) setURL: (NSURL *) newURL;
{
if (_URL != newURL) {
[_URL release];
_URL = [newURL retain];
}
}
- (NSString *) description;
{
return [NSString stringWithFormat: @"<%@: %p %@ URL: %@, Image: %@)>", [self class], self, [self title], _URL, [self image]];
}
- (NSDictionary *) textAttributes;
{
NSFont *font = [self font];
return [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, nil];
}
- (void) drawInteriorWithFrame:(NSRect)frame inView:(NSView *)control
{
NSDictionary *attributes = [self textAttributes];
NSString *title = [self stringValue];
NSSize textSize = [title sizeWithAttributes: attributes];
frame.origin.y += (frame.size.height - textSize.height) / 2.0;
frame.size.height = textSize.height;
NSImage *icon = [self image];
if (icon) {
NSRect iconRect = frame;
iconRect.size.width = frame.size.height;
frame.size.width -= iconRect.size.width + 2;
frame.origin.x += iconRect.size.width + 2;
[icon drawInRect: iconRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1.0];
}
[title drawAtPoint: frame.origin withAttributes: [self textAttributes]];
}
- (NSSize) cellSize;
{
NSSize textSize = [[self stringValue] sizeWithAttributes: [self textAttributes]];
if ([self image]) textSize.width += textSize.height;
textSize.width += 5;
return textSize;
}
@end

View File

@ -0,0 +1,52 @@
#import <Appkit/NSControl.h>
#import <AppKit/NSPathCell.h>
#import <AppKit/NSDragging.h>
@class NSPathComponentCell;
@class NSPathControl;
@class NSOpenPanel;
@protocol NSPathControlDelegate
@optional
- (BOOL)pathControl:(NSPathControl *)pathControl acceptDrop:(id < NSDraggingInfo >)info;
- (BOOL)pathControl:(NSPathControl *)pathControl shouldDragPathComponentCell:(NSPathComponentCell *)pathComponentCell withPasteboard:(NSPasteboard *)pasteboard;
- (NSDragOperation)pathControl:(NSPathControl *)pathControl validateDrop:(id < NSDraggingInfo >)info;
- (void)pathControl:(NSPathControl *)pathControl willDisplayOpenPanel:(NSOpenPanel *)openPanel;
- (void)pathControl:(NSPathControl *)pathControl willPopUpMenu:(NSMenu *)menu;
@end
@interface NSPathControl : NSControl {
}
- (NSPathStyle)pathStyle;
- (void)setPathStyle:(NSPathStyle)style;
- (NSColor *) backgroundColor;
- (void)setBackgroundColor:(NSColor *)color;
- (NSPathComponentCell *)clickedPathComponentCell;
- (NSArray *)pathComponentCells;
- (void)setPathComponentCells:(NSArray *)cells;
- (SEL)doubleAction;
- (void)setDoubleAction:(SEL)action;
- (NSURL *)URL;
- (void)setURL:(NSURL *)url;
- (id < NSPathControlDelegate >)delegate;
- (void)setDelegate:(id < NSPathControlDelegate >)delegate;
- (void)setDraggingSourceOperationMask:(NSDragOperation)mask forLocal:(BOOL)isLocal;
- (NSMenu *)menu;
- (void)setMenu:(NSMenu *)menu;
@end

View File

@ -0,0 +1,122 @@
#import "NSPathControl.h"
#import "AppKit/NSRaise.h"
@implementation NSPathControl
- (NSPathStyle)pathStyle;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
return [cell pathStyle];
}
- (void)setPathStyle:(NSPathStyle)style;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
[cell setPathStyle: style];
}
- (NSColor *) backgroundColor;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
return [cell backgroundColor];
}
- (void)setBackgroundColor:(NSColor *)color;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
[cell setBackgroundColor: color];
}
- (NSPathComponentCell *)clickedPathComponentCell
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
return [cell clickedPathComponentCell];
}
- (NSArray *)pathComponentCells;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
return [cell pathComponentCells];
}
- (void)setPathComponentCells:(NSArray *)cells;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
[cell setPathComponentCells: cells];
}
- (SEL)doubleAction;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
return [cell doubleAction];
}
- (void)setDoubleAction:(SEL)action;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
[cell setDoubleAction: action];
}
- (NSURL *)URL;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
return [cell URL];
}
- (void)setURL:(NSURL *)url;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
[cell setURL: url];
}
- (id < NSPathControlDelegate >)delegate;
{
NSUnimplementedMethod();
return nil;
}
- (void)setDelegate:(id < NSPathControlDelegate >)delegate;
{
NSUnimplementedMethod();
}
- (void)setDraggingSourceOperationMask:(NSDragOperation)mask forLocal:(BOOL)isLocal;
{
NSUnimplementedMethod();
}
- (NSMenu *)menu;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
// return [cell menu];
return nil;
}
- (void)setMenu:(NSMenu *)menu;
{
NSPathCell *cell = [self cell];
NSAssert( [cell isKindOfClass: [NSPathCell class]], @"NSPathControl needs a NSPathCell" );
// [cell setMenu: menu];
}
+ (void) initialize;
{
if (self == [NSPathControl class]) {
[self setCellClass: [NSPathCell class]];
}
}
@end