mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-23 19:51:00 +00:00
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
This commit is contained in:
parent
5b7a963bcf
commit
6005156b82
4 changed files with 143 additions and 210 deletions
|
@ -1,3 +1,10 @@
|
|||
2005-03-04 04:04 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* 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 <greg_casamento@yahoo.com>
|
||||
|
||||
* GNUmakefile: Added new files.
|
||||
|
|
|
@ -68,45 +68,57 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
|
|||
|
||||
- (unsigned int) draggingEntered: (id<NSDraggingInfo>)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<NSDraggingInfo>)sender
|
||||
- (unsigned int) draggingUpdated: (id<NSDraggingInfo>)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<NSDraggingInfo>)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<c;i++)
|
||||
{
|
||||
id placeHolder = nil;
|
||||
NSString *fileName = [data objectAtIndex: i];
|
||||
id placeHolder = [self placeHolderWithPath: [data objectAtIndex: i]];
|
||||
|
||||
NSLog(@"====> %@",[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<NSDraggingInfo>)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];
|
||||
|
|
|
@ -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
|
||||
|
||||
/*
|
||||
|
|
|
@ -28,36 +28,10 @@
|
|||
#include <AppKit/NSSound.h>
|
||||
#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<NSDraggingInfo>)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<NSDraggingInfo>)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<NSDraggingInfo>)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<c;i++)
|
||||
{
|
||||
id placeHolder = nil;
|
||||
|
||||
NSLog(@"====> %@",[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<NSDraggingInfo>)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<NSDraggingInfo>)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<NSDraggingInfo>)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];
|
||||
|
|
Loading…
Reference in a new issue