Re: NSImageView as image well (solved)
Re: NSImageView as image well (solved)
- Subject: Re: NSImageView as image well (solved)
- From: Jeff LaMarche <email@hidden>
- Date: Sun, 8 Feb 2004 21:09:51 -0500
On Feb 8, 2004, at 10:25 AM, Jeff LaMarche wrote:
Also, if I do subclass, which class do I subclass, NSImageView or
NSImageCell?
I figured out that subclassing NSImageView. I created a rather generic
subclass that implements a delegate and an informal protocol for the
delegate that passes on the sender from the performDragOperation:
method. By doing this, it allows me to keep the full-resolution image
around until I need it. It's relatively simple, but useful, so I
thought I'd post it here:
In NKDImageViewWithDelegate.h:
#import <AppKit/AppKit.h>
@interface NKDImageViewWithDelegate : NSImageView
{
id _delegate;
}
- (id)delegate;
- (void)setDelegate:(id)new_delegate;
@end
@interface NSObject (NKDImageViewWithDelegate)
- (void)imageView:(NKDImageViewWithDelegate *)theView
didReceiveDrop:(id <NSDraggingInfo>)dragSender;
@end
And in NKDImageViewWithDelegate.m:
#include "NKDImageViewWithDelegate.h"
@implementation NKDImageViewWithDelegate
//
------------------------------------------------------------------------
--------------------------------
- (id)initWithFrame:(NSRect)frame
//
------------------------------------------------------------------------
--------------------------------
{
self = [super initWithFrame:frame];
if (nil != self)
{
[self registerForDraggedTypes:[NSArray
arrayWithObjects:NSPostScriptPboardType,
NSPICTPboardType, NSPDFPboardType,
NSFileContentsPboardType, NSTIFFPboardType,
NSFilenamesPboardType, nil]];
}
return self;
}
//
------------------------------------------------------------------------
--------------------------------
- (id)delegate
//
------------------------------------------------------------------------
--------------------------------
{
return _delegate;
}
//
------------------------------------------------------------------------
--------------------------------
- (void)setDelegate:(id)new_delegate
//
------------------------------------------------------------------------
--------------------------------
{
_delegate = new_delegate;
}
//
------------------------------------------------------------------------
--------------------------------
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
//
------------------------------------------------------------------------
--------------------------------
{
[super performDragOperation:sender];
if ([_delegate
respondsToSelector:@selector(imageView:didReceiveDrop:)])
[_delegate imageView:self didReceiveDrop:sender];
else
[NSException raise:NSInternalInconsistencyException
format:@"Delegate doesn't respond to imageViewDidReceiveDrop:"];
return YES;
}
//
------------------------------------------------------------------------
--------------------------------
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
//
------------------------------------------------------------------------
--------------------------------
{
return YES;
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.