Re: NSMatrix NSimageCell and drag
Re: NSMatrix NSimageCell and drag
- Subject: Re: NSMatrix NSimageCell and drag
- From: Olivier <email@hidden>
- Date: Thu, 8 Aug 2002 17:45:33 -0500
I figured it out, actually i needed to look at the matrix level, not a
the cell level.
Anyway, in case somebody will be interested here is the code i use to do
that, it is a modification of the code to do the same thing but on a
NSImageView.
hope this will help someone
Olivier
.h file
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
@interface draggableMatrix: NSMatrix
{
@private
NSEvent * downEvent;
}
- (void)startDrag:(NSEvent *)event;
- (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent *)event;
- (BOOL)acceptsFirstMouse:(NSEvent *)event;
- (void)mouseDown:(NSEvent *)event;
- (void)mouseDragged:(NSEvent *)event;
- (NSEvent *)downEvent;
- (void)setDownEvent:(NSEvent *)event;
@end
.m file
#import "draggableMatrix.h"
@implementation draggableMatrix
- (void)startDrag:(NSEvent *)event
{
NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSDragPboard];
NSImage *dragImage;
NSImage *scaledImage;
NSPoint dragPoint;
int row, column;
NSRect theDraggedCellFrame;
[self getRow:&row column:&column forPoint: [self convertPoint:[event
locationInWindow] fromView:nil]];
scaledImage = [[self cellAtRow:row column:column] image];
theDraggedCellFrame = [self cellFrameAtRow:row column:column];
dragPoint = NSMakePoint(theDraggedCellFrame.origin.x + ([self
cellSize].width - [scaledImage size].width) / 2,
theDraggedCellFrame.origin.y + [scaledImage
size].height + ([self cellSize].height - [scaledImage size].height) / 2);
[pb declareTypes: [NSArray arrayWithObjects: NSTIFFPboardType, nil]
owner: self];
[pb set
Data:[scaledImage TIFFRepresentation]
forType:NSTIFFPboardType];
dragImage = [[[NSImage alloc] initWithSize: [scaledImage size]]
autorelease];
[dragImage lockFocus];
[scaledImage dissolveToPoint: NSMakePoint(0,0) fraction: .5];
[dragImage unlockFocus];
[self dragImage: dragImage
at: dragPoint
offset: NSMakeSize(0,0)
event: event
pasteboard: pb
source: self
slideBack: YES];
}
- (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent *)event
{
// maybe make more discerning?!
return YES;
}
- (BOOL)acceptsFirstMouse:(NSEvent *)event
{
return YES;
}
- (void)mouseDown:(NSEvent *)event
{
[self setDownEvent:event];
}
- (void)mouseDragged:(NSEvent *)event
{
//if we hit a cell, then start the drag
//
int row, column;
if ([self getRow:&row column:&column forPoint: [self
convertPoint:[event locationInWindow] fromView:nil]])
{
[self startDrag:downEvent];
}
[self setDownEvent:nil];
}
- (NSEvent *)downEvent
{
return downEvent;
}
- (void)setDownEvent:(NSEvent *)event
{
[downEvent autorelease];
downEvent = [event retain];
}
@end
On Thursday, August 8, 2002, at 04:45 PM, Olivier wrote:
I created a matrix with NSImageCell. Now i'd like to be able to drag
the image out of the ImageCell. I already found in the archive the code
to be able to drag an image out of an NSimageView, but apparently i
cannot reuse the same code for the cell.
First is it possible, and if yes how, or where can i find some more
info on that matter.
Olivier
_______________________________________________
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.
_______________________________________________
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.