From 6005156b829f4fbb4f89db23eac647a674bb783c Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Fri, 4 Mar 2005 08:55:36 +0000 Subject: [PATCH] Streamlined implementation of image/sound editor. Also prepared for eventual refactorization of image/sound editors into GormResourceEditor. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20842 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 ++ GormImageEditor.m | 90 +++++++++------- GormPrivate.h | 1 + GormSoundEditor.m | 255 +++++++++++++++------------------------------- 4 files changed, 143 insertions(+), 210 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b318998..46d4dab8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-03-04 04:04 Gregory John Casamento + + * GormImageEditor.m + * GormPrivate.h: Added declaration for new method. + * GormSoundEditor.m: Streamlined drag/drop code in image/sound + editors. + 2005-03-01 21:34 Gregory John Casamento * GNUmakefile: Added new files. diff --git a/GormImageEditor.m b/GormImageEditor.m index 4701aaaa..dd6e3c65 100644 --- a/GormImageEditor.m +++ b/GormImageEditor.m @@ -68,45 +68,57 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat - (unsigned int) draggingEntered: (id)sender { - NSArray *types=[[sender draggingPasteboard] types]; - unsigned int mask=[sender draggingSourceOperationMask]; + NSPasteboard *pb = [sender draggingPasteboard]; + NSArray *pbtypes = [pb types]; + unsigned int mask = [sender draggingSourceOperationMask]; - // NSDebugLLog(@"GormImageEditor draggingEntered mask=%d types=%@",mask,types); - - if ( mask&handled_mask && - ([types containsObject: NSFilenamesPboardType] || - [types containsObject: NSTIFFPboardType])) + if ((mask & handled_mask) && [pbtypes containsObject: NSFilenamesPboardType]) + { + NSArray *data; + NSEnumerator *en; + NSString *fileName; + NSArray *types = [NSImage imageFileTypes]; - return NSDragOperationCopy; + data = [pb propertyListForType: NSFilenamesPboardType]; + if (!data) + { + data = [NSUnarchiver unarchiveObjectWithData: [pb dataForType: NSFilenamesPboardType]]; + } + + en = [data objectEnumerator]; + while((fileName = (NSString *)[en nextObject]) != nil) + { + NSString *ext = [fileName pathExtension]; + if([types containsObject: ext] == YES) + { + return NSDragOperationCopy; + } + else + { + return NSDragOperationNone; + } + } + + return NSDragOperationCopy; + } return NSDragOperationNone; } -- (unsigned) draggingUpdated: (id)sender +- (unsigned int) draggingUpdated: (id)sender { - NSArray *types=[[sender draggingPasteboard] types]; - unsigned int mask=[sender draggingSourceOperationMask]; - - NSDebugLLog(@"dragndrop",@"GormImageEditor draggingEntered mask=%x types=%@",mask,types); - - if (mask&handled_mask && - ([types containsObject: NSFilenamesPboardType] || - [types containsObject: NSTIFFPboardType])) - return NSDragOperationCopy; - - - return NSDragOperationNone; + return [self draggingEntered: sender]; } - (BOOL) performDragOperation: (id)sender { - NSPasteboard *pb=[sender draggingPasteboard]; - NSArray *types=[pb types]; - unsigned int mask=[sender draggingSourceOperationMask]; + NSPasteboard *pb = [sender draggingPasteboard]; + NSArray *types = [pb types]; + unsigned int mask = [sender draggingSourceOperationMask]; NSDebugLLog(@"dragndrop",@"performDrag %x %@",mask,types); - if (!(mask&handled_mask)) + if (!(mask & handled_mask)) return NO; if ([types containsObject: NSFilenamesPboardType]) @@ -114,20 +126,17 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat NSArray *data; int i,c; - data=[pb propertyListForType: NSFilenamesPboardType]; + data = [pb propertyListForType: NSFilenamesPboardType]; if (!data) - data=[NSUnarchiver unarchiveObjectWithData: [pb dataForType: NSFilenamesPboardType]]; + data = [NSUnarchiver unarchiveObjectWithData: [pb dataForType: NSFilenamesPboardType]]; c=[data count]; - printf("count %i\n",c); for (i=0;i %@",[data objectAtIndex:i]); - placeHolder = [GormImage imageForPath: [data objectAtIndex: i]]; - NSLog(@"here1 %@", [data objectAtIndex: i]); - if (placeHolder) { NSLog(@"here %@", [data objectAtIndex: i]); @@ -137,8 +146,6 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat return YES; } return NO; - - } - (BOOL) prepareForDragOperation: (id)sender @@ -146,6 +153,16 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat return YES; } +- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag +{ + return NSDragOperationCopy; +} + +- (id) placeHolderWithPath: (NSString *)string +{ + return [GormImage imageForPath: string]; +} + - (void) drawSelection { } @@ -434,11 +451,6 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat } } -- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag -{ - return NSDragOperationCopy; -} - - (id) raiseSelection: (id)sender { id obj = [self changeSelection: sender]; diff --git a/GormPrivate.h b/GormPrivate.h index a58ca8ea..01a86e8d 100644 --- a/GormPrivate.h +++ b/GormPrivate.h @@ -264,6 +264,7 @@ extern NSString *GormResizeCellNotification; - (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f; - (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag; - (void) refreshCells; +- (id) placeHolderWithPath: (NSString *)path; @end /* diff --git a/GormSoundEditor.m b/GormSoundEditor.m index 392eddb4..c7a81c2a 100644 --- a/GormSoundEditor.m +++ b/GormSoundEditor.m @@ -28,36 +28,10 @@ #include #include "GormSound.h" -/* - * Method to return the image that should be used to display objects within - * the matrix containing the objects in a document. - */ -@implementation NSObject (GormSoundAdditions) -- (NSString*) soundInspectorClassName -{ - return @"GormSoundInspector"; -} - -- (NSImage*) soundImageForViewer -{ - static NSImage *image = nil; - - if (image == nil) - { - NSBundle *bundle = [NSBundle mainBundle]; - NSString *path = [bundle pathForImageResource: @"GormSound"]; - - image = [[NSImage alloc] initWithContentsOfFile: path]; - } - return image; -} -@end - - - @implementation GormSoundEditor static NSMapTable *docMap = 0; +static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperationPrivate; + (void) initialize { @@ -107,63 +81,96 @@ static NSMapTable *docMap = 0; - (unsigned) draggingEntered: (id)sender { - NSArray *types; + NSPasteboard *pb = [sender draggingPasteboard]; + NSArray *pbtypes = [pb types]; + unsigned int mask = [sender draggingSourceOperationMask]; - dragPb = [sender draggingPasteboard]; - types = [dragPb types]; - if ([types containsObject: IBObjectPboardType] == YES) + if ((mask & handled_mask) && [pbtypes containsObject: NSFilenamesPboardType]) { - dragType = IBObjectPboardType; + NSArray *data; + NSEnumerator *en; + NSString *fileName; + NSArray *types = [NSSound soundUnfilteredFileTypes]; + + data = [pb propertyListForType: NSFilenamesPboardType]; + if (!data) + { + data = [NSUnarchiver unarchiveObjectWithData: [pb dataForType: NSFilenamesPboardType]]; + } + + en = [data objectEnumerator]; + while((fileName = (NSString *)[en nextObject]) != nil) + { + NSString *ext = [fileName pathExtension]; + if([types containsObject: ext] == YES) + { + return NSDragOperationCopy; + } + else + { + return NSDragOperationNone; + } + } + + return NSDragOperationCopy; } - else if ([types containsObject: GormLinkPboardType] == YES) - { - dragType = GormLinkPboardType; - } - else - { - dragType = nil; - } - return [self draggingUpdated: sender]; + + return NSDragOperationNone; } - (unsigned) draggingUpdated: (id)sender { - if (dragType == IBObjectPboardType) - { - return NSDragOperationCopy; - } - else if (dragType == GormLinkPboardType) - { - NSPoint loc = [sender draggingLocation]; - int r, c; - int pos; - id obj = nil; + return [self draggingEntered: sender]; +} - loc = [self convertPoint: loc fromView: nil]; - [self getRow: &r column: &c forPoint: loc]; - pos = r * [self numberOfColumns] + c; - if (pos >= 0 && pos < [objects count]) - { - obj = [objects objectAtIndex: pos]; - } - if (obj == [NSApp connectSource]) - { - return NSDragOperationNone; /* Can't drag an object onto itsself */ - } - [NSApp displayConnectionBetween: [NSApp connectSource] and: obj]; - if (obj != nil) - { - return NSDragOperationLink; - } - else - { - return NSDragOperationNone; - } - } - else +- (BOOL) performDragOperation: (id)sender +{ + NSPasteboard *pb = [sender draggingPasteboard]; + NSArray *types = [pb types]; + unsigned int mask = [sender draggingSourceOperationMask]; + + NSDebugLLog(@"dragndrop",@"performDrag %x %@",mask,types); + + if (!(mask & handled_mask)) + return NO; + + if ([types containsObject: NSFilenamesPboardType]) { - return NSDragOperationNone; + NSArray *data; + int i,c; + + data = [pb propertyListForType: NSFilenamesPboardType]; + if (!data) + data = [NSUnarchiver unarchiveObjectWithData: [pb dataForType: NSFilenamesPboardType]]; + + c=[data count]; + for (i=0;i %@",[data objectAtIndex:i]); + placeHolder = [GormSound soundForPath: [data objectAtIndex: i]]; + NSLog(@"here1 %@", [data objectAtIndex: i]); + + if (placeHolder) + { + NSLog(@"here %@", [data objectAtIndex: i]); + [self addObject: placeHolder]; + } + } + return YES; } + return NO; +} + +- (BOOL) prepareForDragOperation: (id)sender +{ + return YES; +} + +- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL) flag +{ + return NSDragOperationCopy; } - (void) drawSelection @@ -206,7 +213,7 @@ static NSMapTable *docMap = 0; GormPalettesManager *palettesManager = [(Gorm *)NSApp palettesManager]; [self registerForDraggedTypes: [NSArray arrayWithObjects: - IBObjectPboardType, GormLinkPboardType, nil]]; + NSFilenamesPboardType, nil]]; [self setAutosizesCells: NO]; [self setCellSize: NSMakeSize(72,72)]; @@ -388,7 +395,7 @@ static NSMapTable *docMap = 0; owner: self]; [pb setString: [(GormResource *)[objects objectAtIndex: pos] name] forType: GormSoundPboardType]; - [self dragImage: [[objects objectAtIndex: pos] soundImageForViewer] + [self dragImage: [[objects objectAtIndex: pos] imageForViewer] at: lastLocation offset: NSZeroSize event: theEvent @@ -438,100 +445,6 @@ static NSMapTable *docMap = 0; } } -- (BOOL) performDragOperation: (id)sender -{ - if (dragType == IBObjectPboardType) - { - NSArray *array; - NSEnumerator *enumerator; - id obj; - - /* - * Ask the document to get the dragged objects from the pasteboard and - * add them to it's collection of known objects. - */ - array = [document pasteType: IBViewPboardType - fromPasteboard: dragPb - parent: [objects objectAtIndex: 0]]; - enumerator = [array objectEnumerator]; - while ((obj = [enumerator nextObject]) != nil) - { - [self addObject: obj]; - } - return YES; - } - else if (dragType == GormLinkPboardType) - { - NSPoint loc = [sender draggingLocation]; - int r, c; - int pos; - id obj = nil; - - loc = [self convertPoint: loc fromView: nil]; - [self getRow: &r column: &c forPoint: loc]; - pos = r * [self numberOfColumns] + c; - if (pos >= 0 && pos < [objects count]) - { - obj = [objects objectAtIndex: pos]; - } - if (obj == nil) - { - return NO; - } - else - { - [NSApp displayConnectionBetween: [NSApp connectSource] and: obj]; - [NSApp startConnecting]; - return YES; - } - } - else - { - NSDebugLog(@"Drop with unrecognized type!"); - return NO; - } -} - -- (BOOL) prepareForDragOperation: (id)sender -{ - /* - * Tell the source that we will accept the drop if we can. - */ - if (dragType == IBObjectPboardType) - { - /* - * We can accept objects dropped anywhere. - */ - return YES; - } - else if (dragType == GormLinkPboardType) - { - NSPoint loc = [sender draggingLocation]; - int r, c; - int pos; - id obj = nil; - - loc = [self convertPoint: loc fromView: nil]; - [self getRow: &r column: &c forPoint: loc]; - pos = r * [self numberOfColumns] + c; - if (pos >= 0 && pos < [objects count]) - { - obj = [objects objectAtIndex: pos]; - } - if (obj != nil) - { - return YES; - } - } - return NO; -} - -- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL) flag -{ - return NSDragOperationCopy; -} - - - (id) raiseSelection: (id)sender { id obj = [self changeSelection: sender]; @@ -581,7 +494,7 @@ static NSMapTable *docMap = 0; NSString *name = [(GormResource *)obj name]; NSDebugLog(@"sound name = %@",name); - [but setImage: [obj soundImageForViewer]]; + [but setImage: [obj imageForViewer]]; [but setTitle: name]; [but setShowsStateBy: NSChangeGrayCellMask]; [but setHighlightsBy: NSChangeGrayCellMask];