Re: NSCell subclass editing
Re: NSCell subclass editing
- Subject: Re: NSCell subclass editing
- From: tiennou <email@hidden>
- Date: Tue, 2 Oct 2007 18:47:59 +0200
Sorry, forgot to sent to the list ;-)
Le 2 oct. 07 à 18:54, Boris Remizov a écrit :
Hi and you!
As my own way, I solve these problems by creating compound NSCells
subclasses like
@interface CompoundCell: NSActionCell
{
NSImageCell* cell1;
NSImageCell* cell2;
NSTextCell* cell3;
NSButtonCell* cell4;
InfoButtonCell* cell5;
....
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)
controlView
@end
In drawInteriorWithFrame i call the drawInteriorWithFrame methods
of sub-cells with appropriate coordinates.
As about tableView:setObjectValue delegate, you may return any
object from objectValueForTableColumn method with any properties,
and read ones in Cell's setObjectValue method.
I'm sorry I don't understand what you mean... ;-)
What I'm basically trying to achieve is that I want my delegate
method tableView:setObjectValue called when the NSOpenPanel closes,
so I'm not forced to use ugly hacks (like resorting to the Responder
chain...).
Here is code I have, that display an NSOpenPanel as a sheet, the only
thing missing is how I call the delegate method... There is some
twiddling included with the NSText field, since it seems to be
responsible of the delegate's calls...
@implementation ARPathCell
- (NSImage*) fileImage
{
if (fileImage == nil)
{
fileImage = [[[NSWorkspace sharedWorkspace] iconForFile:
[self objectValue]] retain];
[fileImage setFlipped:YES];
}
return fileImage;
}
- (NSImage*) editImage
{
if (editImage == nil)
{
editImage = [[[NSWorkspace sharedWorkspace] iconForFile:
[self objectValue]] retain];
[editImage setFlipped:YES];
}
return editImage;
}
- (NSRect) imageRectForBounds:(NSRect)frame
{
NSRect result = frame;
float iconSize = MIN( frame.size.width, frame.size.height );
result.size = NSMakeSize( iconSize, iconSize );
return result;
}
- (NSRect) textRectForBounds:(NSRect)frame
{
NSRect result = frame;
float iconSize = MIN( frame.size.width, frame.size.height );
result.origin.x += iconSize + 5;
result.origin.y += (frame.size.height / 3);
result.size.width = frame.size.width - ( iconSize + 5 );
return result;
}
- (NSRect) buttonRectForBounds:(NSRect)frame
{
NSRect result = frame;
result.origin.x += frame.size.width - 16 ;
result.origin.y += (frame.size.height / 3);
result.size = NSMakeSize( 16, 16 );
return result;
}
- (void) drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
[[self fileImage] drawInRect:[self imageRectForBounds:cellFrame]
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
NSString * displayName = [[NSFileManager defaultManager]
displayNameAtPath:[self objectValue]];
[displayName drawInRect:[self textRectForBounds:cellFrame]
withAttributes:nil];
[[self editImage] drawInRect:[self buttonRectForBounds:cellFrame]
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView
editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
NSLog(@"%s %@ %@ %@ %@ %@", _cmd, NSStringFromRect(aRect),
controlView, textObj, anObject, theEvent);
NSOpenPanel * oPanel = [NSOpenPanel openPanel];
[textObj setDelegate:anObject];
[oPanel setAllowsMultipleSelection:NO];
[oPanel beginSheetForDirectory:nil
file:nil
modalForWindow:[controlView window]
modalDelegate:self
didEndSelector:@selector
(editPathCellSheetDidEnd:returnCode:context:)
contextInfo:textObj];
}
- (void) editPathCellSheetDidEnd:(NSOpenPanel *)panel returnCode:(int)
returnCode context:(void*)contextInfo
{
NSText * text = contextInfo;
if (returnCode == NSOKButton)
{
NSString * file = [[panel filenames] objectAtIndex:0];
[self setObjectValue:file];
[text setString:file];
}
[self endEditing:text];
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden