NSSavePanel, NSSearchFieldCell fixes

This commit is contained in:
Christopher Lloyd 2010-10-22 15:14:54 -04:00
parent 1036031846
commit 215fea88e8
3 changed files with 92 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd /* Copyright (c) 2006-2007 Christopher J. W. Lloyd <cjwl@objc.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@ -10,6 +10,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@class NSView; @class NSView;
enum {
NSFileHandlingPanelCancelButton=NSCancelButton,
NSFileHandlingPanelOKButton =NSOKButton,
};
@interface NSSavePanel : NSPanel { @interface NSSavePanel : NSPanel {
NSString *_dialogTitle; NSString *_dialogTitle;
@ -25,7 +30,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
+(NSSavePanel *)savePanel; +(NSSavePanel *)savePanel;
-(NSURL *)URL;
-(NSString *)filename; -(NSString *)filename;
-(int)runModalForDirectory:(NSString *)directory file:(NSString *)file; -(int)runModalForDirectory:(NSString *)directory file:(NSString *)file;
@ -43,6 +48,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)setTreatsFilePackagesAsDirectories:(BOOL)flag; -(void)setTreatsFilePackagesAsDirectories:(BOOL)flag;
-(void)setAccessoryView:(NSView *)view; -(void)setAccessoryView:(NSView *)view;
-(void)setCanCreateDirectories:(BOOL)value;
-(void)setAllowedFileTypes:(NSArray *)value;
-(void)setAllowsOtherFileTypes:(BOOL)value;
-(void)setMessage:(NSString*)message; -(void)setMessage:(NSString*)message;
-(NSString*)message; -(NSString*)message;

View File

@ -1,16 +1,15 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd, 2008 Johannes Fortmann /* Copyright (c) 2006-2007 Christopher J. W. Lloyd <cjwl@objc.net>, 2008 Johannes Fortmann
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// Original - Christopher Lloyd <cjwl@objc.net>
#import <AppKit/NSSavePanel.h> #import <AppKit/NSSavePanel.h>
#import <AppKit/NSView.h> #import <AppKit/NSView.h>
#import <AppKit/NSApplication.h> #import <AppKit/NSApplication.h>
#import <AppKit/NSDisplay.h> #import <AppKit/NSDisplay.h>
#import <AppKit/NSRaise.h>
@implementation NSSavePanel @implementation NSSavePanel
@ -51,6 +50,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
} }
} }
-(NSURL *)URL {
return [NSURL fileURLWithPath:[self filename]];
}
-(NSString *)filename { -(NSString *)filename {
id ret=nil; id ret=nil;
@synchronized(self) @synchronized(self)
@ -168,8 +171,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
_accessoryView=view; _accessoryView=view;
} }
#pragma mark - -(void)setCanCreateDirectories:(BOOL)value {
#pragma mark Sheet methods NSUnimplementedMethod();
}
-(void)setAllowedFileTypes:(NSArray *)value {
NSUnimplementedMethod();
}
-(void)setAllowsOtherFileTypes:(BOOL)value {
NSUnimplementedMethod();
}
- (void)beginSheetForDirectory:(NSString *)path - (void)beginSheetForDirectory:(NSString *)path
file:(NSString *)name file:(NSString *)name
modalForWindow:(NSWindow *)docWindow modalForWindow:(NSWindow *)docWindow

View File

@ -9,10 +9,35 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSSearchFieldCell.h> #import <AppKit/NSSearchFieldCell.h>
#import <AppKit/NSButtonCell.h> #import <AppKit/NSButtonCell.h>
#import <AppKit/NSMenu.h> #import <AppKit/NSMenu.h>
#import <AppKit/NSImage.h>
#import <AppKit/NSRaise.h> #import <AppKit/NSRaise.h>
@implementation NSSearchFieldCell @implementation NSSearchFieldCell
-initWithCoder:(NSCoder *)coder {
[super initWithCoder:coder];
_searchButtonCell=[[NSButtonCell alloc] initImageCell:[NSImage imageNamed:@"NSSearchGlass"]];
[_searchButtonCell setImageScaling:NSImageScaleProportionallyUpOrDown];
_cancelButtonCell=[[NSButtonCell alloc] initImageCell:[NSImage imageNamed:@"NSSearchClose"]];
[_cancelButtonCell setImageScaling:NSImageScaleProportionallyUpOrDown];
return self;
}
-initTextCell:(NSString *)string {
[super initTextCell:string];
_searchButtonCell=[[NSButtonCell alloc] initImageCell:[NSImage imageNamed:@"NSSearchGlass"]];
[_searchButtonCell setImageScaling:NSImageScaleProportionallyUpOrDown];
_cancelButtonCell=[[NSButtonCell alloc] initImageCell:[NSImage imageNamed:@"NSSearchClose"]];
[_cancelButtonCell setImageScaling:NSImageScaleProportionallyUpOrDown];
return self;
}
-(void)dealloc {
[_searchButtonCell release];
[_cancelButtonCell release];
[super dealloc];
}
-(NSArray *)recentSearches { -(NSArray *)recentSearches {
return _recentSearches; return _recentSearches;
} }
@ -88,18 +113,25 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
} }
-(NSRect)searchTextRectForBounds:(NSRect)rect { -(NSRect)searchTextRectForBounds:(NSRect)rect {
NSUnimplementedMethod(); return [self titleRectForBounds:rect];
return NSZeroRect;
} }
-(NSRect)searchButtonRectForBounds:(NSRect)rect { -(NSRect)searchButtonRectForBounds:(NSRect)rect {
NSUnimplementedMethod(); NSRect result=[self titleRectForBounds:rect];
return NSZeroRect;
result.size.width=result.size.height;
result.origin.x-=result.size.width;
return result;
} }
-(NSRect)cancelButtonRectForBounds:(NSRect)rect { -(NSRect)cancelButtonRectForBounds:(NSRect)rect {
NSUnimplementedMethod(); NSRect result=[self titleRectForBounds:rect];
return NSZeroRect;
result.origin.x+=result.size.width;
result.size.width=result.size.height;
return result;
} }
-(void)resetCancelButtonCell { -(void)resetCancelButtonCell {
@ -110,4 +142,30 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
NSUnimplementedMethod(); NSUnimplementedMethod();
} }
-(NSRect)titleRectForBounds:(NSRect)rect {
CGFloat radius=rect.size.height/2;
NSRect result=[super titleRectForBounds:rect];
result=NSInsetRect(result,radius,0);
return result;
}
-(BOOL)trackMouse:(NSEvent *)event inRect:(NSRect)frame ofView:(NSView *)view untilMouseUp:(BOOL)untilMouseUp {
if([_cancelButtonCell trackMouse:event inRect:[self cancelButtonRectForBounds:frame] ofView:view untilMouseUp:YES]){
[self setStringValue:@""];
return YES;
}
return [super trackMouse:event inRect:frame ofView:view untilMouseUp:untilMouseUp];
}
-(void)drawWithFrame:(NSRect)frame inView:(NSView *)control {
[super drawWithFrame:frame inView:control];
[_searchButtonCell drawWithFrame:[self searchButtonRectForBounds:frame] inView:control];
if([[self attributedStringValue] length]>0)
[_cancelButtonCell drawWithFrame:[self cancelButtonRectForBounds:frame] inView:control];
}
@end @end