NSMatrix drag & drop
NSMatrix drag & drop
- Subject: NSMatrix drag & drop
- From: Dave Riggle <email@hidden>
- Date: Mon, 18 Aug 2003 21:22:32 -0700
My little iPhoto-like app is coming along. Selection and drag & drop
are mostly working. I have a few new questions:
1. NSMatrix's mouseDown() function eats drag events. Is there a clean
way to overrride it so I can get drag events without having to
re-implement all the shift-click, cmd-click, double click logic?
2. Is there a way to change the highlight color of NSImageCells that
works well with NSImageFrameGrayBezel frame styles?
3. How do I get the cursor to change into a "+" arrow when I drag an
image to the finder? Right now I am putting a TIFF on the pasteboard.
Is that the problem? I plan on putting file names there eventually.
Dave
P.S. Here are the appropriate bits of my code:
#1
in my NSMatrix subclass:
- (void)mouseDown:(NSEvent *)event
{
// need to override this because NSMatrix eats drag events
int row, col;
if ([self getRow: &row column: &col forPoint:[self
convertPoint:[event locationInWindow] fromView: nil]]) {
// $$$ need to catch modifier keys and do the right thing
(shift click or CMD click)
// $$$ send double action, etc
[self selectCellAtRow: row column: col];
[self sendAction];
} else {
[super mouseDown: event];
}
}
#2
in my NSImageCell subclass:
- (void)drawInteriorWithFrame:(NSRect) cellFrame inView: (NSView *)
controlView
{
if (_cFlags.highlighted) {
// $$$ doesn't look very good; maybe I need to blend in a round rect
of the highlight color?
NSColor* controlColor = [NSColor selectedControlColor];
[controlColor set];
NSRectFillUsingOperation(cellFrame, NSCompositeCopy);
}
[super drawInteriorWithFrame: picFrame inView: controlView];
}
#3
in my NSMatrix subclass:
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationCopy;
}
- (void)startDrag:(NSEvent *)event
{
NSPasteboard *pb = [NSPasteboard pasteboardWithName: NSDragPboard];
NSImage *dragImage;
NSImage *scaledImage;
NSPoint dragPoint;
int row, col;
NSRect theDraggedCellFrame;
[self getRow:&row column:&col forPoint: [self convertPoint:[event
locationInWindow] fromView:nil]];
scaledImage = [[self cellAtRow:row column:col] scaledImage];
theDraggedCellFrame = [self cellFrameAtRow:row column:col];
dragPoint = NSMakePoint(
theDraggedCellFrame.origin.x + (m_cellSize.width - [scaledImage
size].width) / 2,
theDraggedCellFrame.origin.y + [scaledImage size].height +
(m_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]];
[dragImage lockFocus];
[scaledImage dissolveToPoint: NSZeroPoint fraction: .5];
[dragImage unlockFocus];
[self dragImage: dragImage
at: dragPoint
offset: NSZeroSize
event: event
pasteboard: pb
source: self
slideBack: YES];
[dragImage release];
}
_______________________________________________
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.