Add drag 'n drop methods.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6476 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Jonathan Gapen 2000-04-18 02:28:13 +00:00
parent 4cbc844da0
commit 0e7e8e5b3d

View file

@ -30,9 +30,11 @@
#include <gnustep/gui/config.h>
#include <AppKit/NSActionCell.h>
#include <AppKit/NSColorPanel.h>
#include <AppKit/NSColorWell.h>
#include <AppKit/NSColor.h>
#include <AppKit/NSGraphics.h>
#include <AppKit/NSPasteboard.h>
@implementation NSColorWell
@ -66,12 +68,16 @@
is_active = NO;
the_color = [[NSColor blackColor] retain];
[self registerForDraggedTypes:
[NSArray arrayWithObjects: NSColorPboardType, nil]];
return self;
}
- (void)dealloc
{
[the_color release];
[self unregisterDraggedTypes];
[super dealloc];
}
@ -127,6 +133,13 @@
[the_color drawSwatchInRect: insideRect];
}
- (void) mouseDown: (NSEvent *)theEvent
{
[NSColorPanel dragColor: the_color
withEvent: theEvent
fromView: self];
}
- (BOOL) isOpaque
{
return is_bordered;
@ -185,6 +198,53 @@
[self display];
}
//
// NSDraggingSource
//
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
{
return NSDragOperationCopy;
}
//
// NSDraggingDestination
//
- (unsigned int) draggingEntered: (id <NSDraggingInfo>)sender
{
NSPasteboard *pb;
NSDragOperation sourceDragMask;
NSDebugLLog(@"NSColorWell", @"%@: draggingEntered", self);
sourceDragMask = [sender draggingSourceOperationMask];
pb = [sender draggingPasteboard];
if ([[pb types] indexOfObject: NSColorPboardType] != NSNotFound)
{
if (sourceDragMask & NSDragOperationCopy)
{
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL) performDragOperation: (id <NSDraggingInfo>)sender
{
NSPasteboard *pb = [sender draggingPasteboard];
NSDebugLLog(@"NSColorWell", @"%@: performDragOperation", self);
[self setColor: [NSColor colorFromPasteboard: pb]];
return YES;
}
//
// NSCoding protocol
//