mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-23 11:41:05 +00:00
Refactoring of Image/Sound editors.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20854 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6005156b82
commit
0178caba77
6 changed files with 578 additions and 864 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2005-03-05 23:07 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* GNUmakefile: Added new class.
|
||||
* GormImageEditor.m: Refactored all of the code into the
|
||||
new parent. Implemented only those methods needed.
|
||||
* GormPrivate.h: Changed hierarchy of GormImageEditor and
|
||||
GormSoundEditor to have GormResourceEditor as their parent
|
||||
* GormResourceEditor.m: New parent for sound/image editors.
|
||||
* GormSoundEditor.m: Refactored all of the code into the
|
||||
new parent class. Implemented needed methods.
|
||||
|
||||
2005-03-04 04:04 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* GormImageEditor.m
|
||||
|
|
|
@ -217,6 +217,7 @@ Gorm_OBJC_FILES = \
|
|||
GormPalettesPref.m \
|
||||
GormPrefController.m \
|
||||
GormResource.m \
|
||||
GormResourceEditor.m \
|
||||
GormScrollViewAttributesInspector.m \
|
||||
GormScrollViewEditor.m \
|
||||
GormSetNameController.m \
|
||||
|
|
|
@ -30,8 +30,7 @@
|
|||
|
||||
@implementation GormImageEditor
|
||||
|
||||
static NSMapTable *docMap = 0;
|
||||
static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperationPrivate;
|
||||
static NSMapTable *docMap = 0;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
|
@ -54,108 +53,19 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
|
|||
return editor;
|
||||
}
|
||||
|
||||
- (BOOL) acceptsTypeFromArray: (NSArray*)types
|
||||
- (NSArray *) fileTypes
|
||||
{
|
||||
return NO;
|
||||
return [NSImage imageFileTypes];
|
||||
}
|
||||
|
||||
/*
|
||||
* Dragging source protocol implementation
|
||||
*/
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f
|
||||
- (NSArray *)pbTypes
|
||||
{
|
||||
return [NSArray arrayWithObject: GormImagePboardType];
|
||||
}
|
||||
|
||||
- (unsigned int) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
- (NSString *) resourceType
|
||||
{
|
||||
NSPasteboard *pb = [sender draggingPasteboard];
|
||||
NSArray *pbtypes = [pb types];
|
||||
unsigned int mask = [sender draggingSourceOperationMask];
|
||||
|
||||
if ((mask & handled_mask) && [pbtypes containsObject: NSFilenamesPboardType])
|
||||
{
|
||||
NSArray *data;
|
||||
NSEnumerator *en;
|
||||
NSString *fileName;
|
||||
NSArray *types = [NSImage imageFileTypes];
|
||||
|
||||
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 int) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return [self draggingEntered: sender];
|
||||
}
|
||||
|
||||
- (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])
|
||||
{
|
||||
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++)
|
||||
{
|
||||
NSString *fileName = [data objectAtIndex: i];
|
||||
id placeHolder = [self placeHolderWithPath: [data objectAtIndex: i]];
|
||||
|
||||
NSLog(@"====> %@",[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;
|
||||
return @"image";
|
||||
}
|
||||
|
||||
- (id) placeHolderWithPath: (NSString *)string
|
||||
|
@ -163,23 +73,23 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
|
|||
return [GormImage imageForPath: string];
|
||||
}
|
||||
|
||||
- (void) drawSelection
|
||||
- (void) addSystemResources
|
||||
{
|
||||
}
|
||||
|
||||
- (id<IBDocuments>) document
|
||||
{
|
||||
return document;
|
||||
}
|
||||
|
||||
- (void) handleNotification: (NSNotification*)aNotification
|
||||
{
|
||||
NSString *name = [aNotification name];
|
||||
if([name isEqual: GormResizeCellNotification])
|
||||
NSMutableArray *list = [NSMutableArray array];
|
||||
NSEnumerator *en;
|
||||
id obj;
|
||||
GormPalettesManager *palettesManager = [(Gorm *)NSApp palettesManager];
|
||||
|
||||
// add all of the system objects...
|
||||
[list addObjectsFromArray: systemImagesList()];
|
||||
[list addObjectsFromArray: [palettesManager importedImages]];
|
||||
en = [list objectEnumerator];
|
||||
while((obj = [en nextObject]) != nil)
|
||||
{
|
||||
NSDebugLog(@"Recieved notification");
|
||||
[self setCellSize: defaultCellSize()];
|
||||
}
|
||||
GormImage *image = [GormImage imageForPath: obj];
|
||||
[image setSystemResource: YES];
|
||||
[self addObject: image];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -197,65 +107,11 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
|
|||
return self;
|
||||
}
|
||||
|
||||
self = [super initWithObject: anObject inDocument: aDocument];
|
||||
if (self != nil)
|
||||
if ((self = [super initWithObject: anObject inDocument: aDocument]) != nil)
|
||||
{
|
||||
NSButtonCell *proto;
|
||||
NSMutableArray *list = [NSMutableArray array];
|
||||
NSEnumerator *en;
|
||||
id obj;
|
||||
GormPalettesManager *palettesManager = [(Gorm *)NSApp palettesManager];
|
||||
|
||||
[self registerForDraggedTypes: [NSArray arrayWithObjects:
|
||||
NSFilenamesPboardType, nil]];
|
||||
|
||||
[self setAutosizesCells: NO];
|
||||
[self setCellSize: NSMakeSize(72,72)];
|
||||
[self setIntercellSpacing: NSMakeSize(8,8)];
|
||||
[self setAutoresizingMask: NSViewMinYMargin|NSViewWidthSizable];
|
||||
[self setMode: NSRadioModeMatrix];
|
||||
/*
|
||||
* Send mouse click actions to self, so we can handle selection.
|
||||
*/
|
||||
[self setAction: @selector(changeSelection:)];
|
||||
[self setDoubleAction: @selector(raiseSelection:)];
|
||||
[self setTarget: self];
|
||||
|
||||
objects = [NSMutableArray new];
|
||||
proto = [NSButtonCell new];
|
||||
[proto setBordered: NO];
|
||||
[proto setAlignment: NSCenterTextAlignment];
|
||||
[proto setImagePosition: NSImageAbove];
|
||||
[proto setSelectable: NO];
|
||||
[proto setEditable: NO];
|
||||
[self setPrototype: proto];
|
||||
RELEASE(proto);
|
||||
NSMapInsert(docMap, (void*)aDocument, (void*)self);
|
||||
|
||||
// do not insert it if it's nil.
|
||||
if(anObject != nil)
|
||||
{
|
||||
[self addObject: anObject];
|
||||
}
|
||||
|
||||
// add all of the system objects...
|
||||
[list addObjectsFromArray: systemImagesList()];
|
||||
[list addObjectsFromArray: [palettesManager importedImages]];
|
||||
en = [list objectEnumerator];
|
||||
while((obj = [en nextObject]) != nil)
|
||||
{
|
||||
GormImage *image = [GormImage imageForPath: obj];
|
||||
[image setSystemResource: YES];
|
||||
[self addObject: image];
|
||||
}
|
||||
|
||||
// set up the notification...
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(handleNotification:)
|
||||
name: GormResizeCellNotification
|
||||
object: nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -274,258 +130,6 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
|
|||
- (void) close
|
||||
{
|
||||
[super close];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
NSMapRemove(docMap,document);
|
||||
}
|
||||
|
||||
- (void) addObject: (id)anObject
|
||||
{
|
||||
if([objects containsObject: anObject] == NO)
|
||||
{
|
||||
[super addObject: anObject];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSRunAlertPanel (_(@"Problem adding image"),
|
||||
_(@"An image with the same name exists, remove it first."),
|
||||
_(@"OK"),
|
||||
nil,
|
||||
nil);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) makeSelectionVisible: (BOOL)flag
|
||||
{
|
||||
if (flag == YES && selected != nil)
|
||||
{
|
||||
unsigned pos = [objects indexOfObjectIdenticalTo: selected];
|
||||
int r = pos / [self numberOfColumns];
|
||||
int c = pos % [self numberOfColumns];
|
||||
|
||||
[self selectCellAtRow: r column: c];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self deselectAllCells];
|
||||
}
|
||||
[self displayIfNeeded];
|
||||
[[self window] flushWindow];
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent*)theEvent
|
||||
{
|
||||
int row, column;
|
||||
int newRow, newColumn;
|
||||
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask
|
||||
| NSMouseMovedMask | NSLeftMouseDraggedMask
|
||||
| NSPeriodicMask;
|
||||
NSPoint lastLocation = [theEvent locationInWindow];
|
||||
NSEvent* lastEvent = theEvent;
|
||||
NSPoint initialLocation;
|
||||
|
||||
/*
|
||||
* Pathological case -- ignore mouse down
|
||||
*/
|
||||
if ((_numRows == 0) || (_numCols == 0))
|
||||
{
|
||||
[super mouseDown: theEvent];
|
||||
return;
|
||||
}
|
||||
|
||||
lastLocation = [self convertPoint: lastLocation
|
||||
fromView: nil];
|
||||
initialLocation = lastLocation;
|
||||
// If mouse down was on a selectable cell, start editing/selecting.
|
||||
if ([self getRow: &row
|
||||
column: &column
|
||||
forPoint: lastLocation])
|
||||
{
|
||||
if ([_cells[row][column] isEnabled])
|
||||
{
|
||||
if ((_mode == NSRadioModeMatrix) && _selectedCell != nil)
|
||||
{
|
||||
[_selectedCell setState: NSOffState];
|
||||
[self drawCellAtRow: _selectedRow column: _selectedColumn];
|
||||
_selectedCells[_selectedRow][_selectedColumn] = NO;
|
||||
_selectedCell = nil;
|
||||
_selectedRow = _selectedColumn = -1;
|
||||
}
|
||||
[_cells[row][column] setState: NSOnState];
|
||||
[self drawCellAtRow: row column: column];
|
||||
[_window flushWindow];
|
||||
_selectedCells[row][column] = YES;
|
||||
_selectedCell = _cells[row][column];
|
||||
_selectedRow = row;
|
||||
_selectedColumn = column;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastEvent = [NSApp nextEventMatchingMask: eventMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
lastLocation = [self convertPoint: [lastEvent locationInWindow]
|
||||
fromView: nil];
|
||||
|
||||
|
||||
while ([lastEvent type] != NSLeftMouseUp)
|
||||
{
|
||||
if((![self getRow: &newRow
|
||||
column: &newColumn
|
||||
forPoint: lastLocation])
|
||||
||
|
||||
(row != newRow)
|
||||
||
|
||||
(column != newColumn)
|
||||
||
|
||||
((lastLocation.x - initialLocation.x) *
|
||||
(lastLocation.x - initialLocation.x) +
|
||||
(lastLocation.y - initialLocation.y) *
|
||||
(lastLocation.y - initialLocation.y)
|
||||
>= 25))
|
||||
{
|
||||
NSPasteboard *pb;
|
||||
int pos;
|
||||
pos = row * [self numberOfColumns] + column;
|
||||
|
||||
// don't allow the user to drag empty resources.
|
||||
if(pos < [objects count])
|
||||
{
|
||||
pb = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
[pb declareTypes: [NSArray arrayWithObject: GormImagePboardType]
|
||||
owner: self];
|
||||
[pb setString: [(GormResource *)[objects objectAtIndex: pos] name]
|
||||
forType: GormImagePboardType];
|
||||
[self dragImage: [[objects objectAtIndex: pos] image]
|
||||
at: lastLocation
|
||||
offset: NSZeroSize
|
||||
event: theEvent
|
||||
pasteboard: pb
|
||||
source: self
|
||||
slideBack: YES];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
lastEvent = [NSApp nextEventMatchingMask: eventMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
lastLocation = [self convertPoint: [lastEvent locationInWindow]
|
||||
fromView: nil];
|
||||
|
||||
}
|
||||
|
||||
[self changeSelection: self];
|
||||
|
||||
}
|
||||
|
||||
- (void) pasteInSelection
|
||||
{
|
||||
}
|
||||
|
||||
- (void) deleteSelection
|
||||
{
|
||||
if(![selected isSystemResource])
|
||||
{
|
||||
if([selected isInWrapper])
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *path = [selected path];
|
||||
BOOL removed = [mgr removeFileAtPath: path
|
||||
handler: nil];
|
||||
if(!removed)
|
||||
{
|
||||
NSString *msg = [NSString stringWithFormat: @"Could not delete file %@", path];
|
||||
NSLog(msg);
|
||||
}
|
||||
}
|
||||
[super deleteSelection];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) raiseSelection: (id)sender
|
||||
{
|
||||
id obj = [self changeSelection: sender];
|
||||
id e;
|
||||
|
||||
e = [document editorForObject: obj create: YES];
|
||||
[e orderFront];
|
||||
[e resetObject: obj];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) refreshCells
|
||||
{
|
||||
unsigned count = [objects count];
|
||||
unsigned index;
|
||||
int cols = 0;
|
||||
int rows;
|
||||
int width;
|
||||
|
||||
// return if the superview is not available.
|
||||
if(![self superview])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
width = [[self superview] bounds].size.width;
|
||||
while (width >= 72)
|
||||
{
|
||||
width -= (72 + 8);
|
||||
cols++;
|
||||
}
|
||||
if (cols == 0)
|
||||
{
|
||||
cols = 1;
|
||||
}
|
||||
rows = count / cols;
|
||||
if (rows == 0 || rows * cols != count)
|
||||
{
|
||||
rows++;
|
||||
}
|
||||
[self renewRows: rows columns: cols];
|
||||
|
||||
for (index = 0; index < count; index++)
|
||||
{
|
||||
id obj = [objects objectAtIndex: index];
|
||||
NSButtonCell *but = [self cellAtRow: index/cols column: index%cols];
|
||||
NSString *name = [(GormResource *)obj name];
|
||||
|
||||
[but setImage: [obj imageForViewer]];
|
||||
[but setTitle: name];
|
||||
[but setShowsStateBy: NSChangeGrayCellMask];
|
||||
[but setHighlightsBy: NSChangeGrayCellMask];
|
||||
}
|
||||
while (index < rows * cols)
|
||||
{
|
||||
NSButtonCell *but = [self cellAtRow: index/cols column: index%cols];
|
||||
|
||||
[but setImage: nil];
|
||||
[but setTitle: @""];
|
||||
[but setShowsStateBy: NSNoCellMask];
|
||||
[but setHighlightsBy: NSNoCellMask];
|
||||
index++;
|
||||
}
|
||||
[self setIntercellSpacing: NSMakeSize(8,8)];
|
||||
[self sizeToCells];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
/*
|
||||
- (void) dealloc
|
||||
{
|
||||
NSLog(@"deallocing..");
|
||||
[super dealloc];
|
||||
}
|
||||
*/
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -250,21 +250,29 @@ extern NSString *GormResizeCellNotification;
|
|||
- (void) removeAllInstancesOfClass: (NSString *)className;
|
||||
@end
|
||||
|
||||
@interface GormSoundEditor : GormGenericEditor
|
||||
{
|
||||
}
|
||||
+ (GormSoundEditor*) editorForDocument: (id<IBDocuments>)aDocument;
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f;
|
||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag;
|
||||
@end
|
||||
|
||||
@interface GormImageEditor : GormGenericEditor
|
||||
@interface GormResourceEditor : GormGenericEditor
|
||||
{
|
||||
}
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f;
|
||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag;
|
||||
- (void) refreshCells;
|
||||
- (id) placeHolderWithPath: (NSString *)path;
|
||||
- (NSArray *) fileTypes;
|
||||
- (NSArray *) pbTypes;
|
||||
- (NSString *) resourceType;
|
||||
- (void) addSystemResources;
|
||||
@end
|
||||
|
||||
@interface GormSoundEditor : GormResourceEditor
|
||||
{
|
||||
}
|
||||
+ (GormSoundEditor*) editorForDocument: (id<IBDocuments>)aDocument;
|
||||
@end
|
||||
|
||||
@interface GormImageEditor : GormResourceEditor
|
||||
{
|
||||
}
|
||||
+ (GormImageEditor*) editorForDocument: (id<IBDocuments>)aDocument;
|
||||
@end
|
||||
|
||||
/*
|
||||
|
|
489
GormResourceEditor.m
Normal file
489
GormResourceEditor.m
Normal file
|
@ -0,0 +1,489 @@
|
|||
/* GormResourceEditor.m
|
||||
*
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
*
|
||||
* Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
* Date: 2002
|
||||
*
|
||||
* This file is part of GNUstep.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "GormPrivate.h"
|
||||
#include "GormFunctions.h"
|
||||
#include "GormPalettesManager.h"
|
||||
#include <AppKit/NSImage.h>
|
||||
#include "GormResource.h"
|
||||
|
||||
@implementation GormResourceEditor
|
||||
|
||||
// for the resource editors
|
||||
static int handled_mask= NSDragOperationCopy | NSDragOperationGeneric | NSDragOperationPrivate;
|
||||
|
||||
- (BOOL) acceptsTypeFromArray: (NSArray*)types
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSArray *) fileTypes
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *) pbTypes
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dragging source protocol implementation
|
||||
*/
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f
|
||||
{
|
||||
}
|
||||
|
||||
- (unsigned int) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *pb = [sender draggingPasteboard];
|
||||
NSArray *pbtypes = [pb types];
|
||||
unsigned int mask = [sender draggingSourceOperationMask];
|
||||
|
||||
if ((mask & handled_mask) && [pbtypes containsObject: NSFilenamesPboardType])
|
||||
{
|
||||
NSArray *data;
|
||||
NSEnumerator *en;
|
||||
NSString *fileName;
|
||||
NSArray *types = [self fileTypes];
|
||||
|
||||
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 int) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return [self draggingEntered: sender];
|
||||
}
|
||||
|
||||
- (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])
|
||||
{
|
||||
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++)
|
||||
{
|
||||
NSString *fileName = [data objectAtIndex: i];
|
||||
id placeHolder = [self placeHolderWithPath: fileName];
|
||||
|
||||
NSLog(@"====> %@", fileName);
|
||||
if (placeHolder)
|
||||
{
|
||||
NSLog(@"here %@", fileName);
|
||||
[self addObject: placeHolder];
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
|
||||
{
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
|
||||
- (id) placeHolderWithPath: (NSString *)string
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) drawSelection
|
||||
{
|
||||
}
|
||||
|
||||
- (id<IBDocuments>) document
|
||||
{
|
||||
return document;
|
||||
}
|
||||
|
||||
- (void) handleNotification: (NSNotification*)aNotification
|
||||
{
|
||||
NSString *name = [aNotification name];
|
||||
if([name isEqual: GormResizeCellNotification])
|
||||
{
|
||||
NSDebugLog(@"Recieved notification");
|
||||
[self setCellSize: defaultCellSize()];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addSystemResources
|
||||
{
|
||||
// NSMutableArray *list = [NSMutableArray array];
|
||||
// do nothing... this is the parent class.
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialisation - register to receive DnD with our own types.
|
||||
*/
|
||||
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument
|
||||
{
|
||||
if ((self = [super initWithObject: anObject inDocument: aDocument]) != nil)
|
||||
{
|
||||
NSButtonCell *proto;
|
||||
|
||||
[self registerForDraggedTypes: [NSArray arrayWithObjects:
|
||||
NSFilenamesPboardType, nil]];
|
||||
|
||||
[self setAutosizesCells: NO];
|
||||
[self setCellSize: NSMakeSize(72,72)];
|
||||
[self setIntercellSpacing: NSMakeSize(8,8)];
|
||||
[self setAutoresizingMask: NSViewMinYMargin|NSViewWidthSizable];
|
||||
[self setMode: NSRadioModeMatrix];
|
||||
/*
|
||||
* Send mouse click actions to self, so we can handle selection.
|
||||
*/
|
||||
[self setAction: @selector(changeSelection:)];
|
||||
[self setDoubleAction: @selector(raiseSelection:)];
|
||||
[self setTarget: self];
|
||||
|
||||
objects = [NSMutableArray new];
|
||||
proto = [NSButtonCell new];
|
||||
[proto setBordered: NO];
|
||||
[proto setAlignment: NSCenterTextAlignment];
|
||||
[proto setImagePosition: NSImageAbove];
|
||||
[proto setSelectable: NO];
|
||||
[proto setEditable: NO];
|
||||
[self setPrototype: proto];
|
||||
RELEASE(proto);
|
||||
|
||||
// do not insert it if it's nil.
|
||||
if(anObject != nil)
|
||||
{
|
||||
[self addObject: anObject];
|
||||
}
|
||||
|
||||
// add any initial objects
|
||||
[self addSystemResources];
|
||||
|
||||
// set up the notification...
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(handleNotification:)
|
||||
name: GormResizeCellNotification
|
||||
object: nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) close
|
||||
{
|
||||
[super close];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
}
|
||||
|
||||
- (NSString *) resourceType
|
||||
{
|
||||
return @"resource";
|
||||
}
|
||||
|
||||
- (void) addObject: (id)anObject
|
||||
{
|
||||
if([objects containsObject: anObject] == NO)
|
||||
{
|
||||
[super addObject: anObject];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *type = [self resourceType];
|
||||
NSString *msg = [NSString stringWithFormat: _(@"Problem adding %@"), type];
|
||||
NSRunAlertPanel(msg,
|
||||
_(@"A resource with the same name exists, remove it first."),
|
||||
_(@"OK"),
|
||||
nil,
|
||||
nil);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) makeSelectionVisible: (BOOL)flag
|
||||
{
|
||||
if (flag == YES && selected != nil)
|
||||
{
|
||||
unsigned pos = [objects indexOfObjectIdenticalTo: selected];
|
||||
int r = pos / [self numberOfColumns];
|
||||
int c = pos % [self numberOfColumns];
|
||||
|
||||
[self selectCellAtRow: r column: c];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self deselectAllCells];
|
||||
}
|
||||
[self displayIfNeeded];
|
||||
[[self window] flushWindow];
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent*)theEvent
|
||||
{
|
||||
int row, column;
|
||||
int newRow, newColumn;
|
||||
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask
|
||||
| NSMouseMovedMask | NSLeftMouseDraggedMask
|
||||
| NSPeriodicMask;
|
||||
NSPoint lastLocation = [theEvent locationInWindow];
|
||||
NSEvent* lastEvent = theEvent;
|
||||
NSPoint initialLocation;
|
||||
|
||||
/*
|
||||
* Pathological case -- ignore mouse down
|
||||
*/
|
||||
if ((_numRows == 0) || (_numCols == 0))
|
||||
{
|
||||
[super mouseDown: theEvent];
|
||||
return;
|
||||
}
|
||||
|
||||
lastLocation = [self convertPoint: lastLocation
|
||||
fromView: nil];
|
||||
initialLocation = lastLocation;
|
||||
// If mouse down was on a selectable cell, start editing/selecting.
|
||||
if ([self getRow: &row
|
||||
column: &column
|
||||
forPoint: lastLocation])
|
||||
{
|
||||
if ([_cells[row][column] isEnabled])
|
||||
{
|
||||
if ((_mode == NSRadioModeMatrix) && _selectedCell != nil)
|
||||
{
|
||||
[_selectedCell setState: NSOffState];
|
||||
[self drawCellAtRow: _selectedRow column: _selectedColumn];
|
||||
_selectedCells[_selectedRow][_selectedColumn] = NO;
|
||||
_selectedCell = nil;
|
||||
_selectedRow = _selectedColumn = -1;
|
||||
}
|
||||
[_cells[row][column] setState: NSOnState];
|
||||
[self drawCellAtRow: row column: column];
|
||||
[_window flushWindow];
|
||||
_selectedCells[row][column] = YES;
|
||||
_selectedCell = _cells[row][column];
|
||||
_selectedRow = row;
|
||||
_selectedColumn = column;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastEvent = [NSApp nextEventMatchingMask: eventMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
lastLocation = [self convertPoint: [lastEvent locationInWindow]
|
||||
fromView: nil];
|
||||
|
||||
|
||||
while ([lastEvent type] != NSLeftMouseUp)
|
||||
{
|
||||
if((![self getRow: &newRow
|
||||
column: &newColumn
|
||||
forPoint: lastLocation])
|
||||
||
|
||||
(row != newRow)
|
||||
||
|
||||
(column != newColumn)
|
||||
||
|
||||
((lastLocation.x - initialLocation.x) *
|
||||
(lastLocation.x - initialLocation.x) +
|
||||
(lastLocation.y - initialLocation.y) *
|
||||
(lastLocation.y - initialLocation.y)
|
||||
>= 25))
|
||||
{
|
||||
NSPasteboard *pb;
|
||||
int pos;
|
||||
pos = row * [self numberOfColumns] + column;
|
||||
|
||||
// don't allow the user to drag empty resources.
|
||||
if(pos < [objects count])
|
||||
{
|
||||
pb = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
[pb declareTypes: [self pbTypes]
|
||||
owner: self];
|
||||
[pb setString: [(GormResource *)[objects objectAtIndex: pos] name]
|
||||
forType: [[self pbTypes] objectAtIndex: 0]];
|
||||
[self dragImage: [[objects objectAtIndex: pos] imageForViewer]
|
||||
at: lastLocation
|
||||
offset: NSZeroSize
|
||||
event: theEvent
|
||||
pasteboard: pb
|
||||
source: self
|
||||
slideBack: YES];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
lastEvent = [NSApp nextEventMatchingMask: eventMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
lastLocation = [self convertPoint: [lastEvent locationInWindow]
|
||||
fromView: nil];
|
||||
|
||||
}
|
||||
|
||||
[self changeSelection: self];
|
||||
|
||||
}
|
||||
|
||||
- (void) pasteInSelection
|
||||
{
|
||||
}
|
||||
|
||||
- (void) deleteSelection
|
||||
{
|
||||
if(![selected isSystemResource])
|
||||
{
|
||||
if([selected isInWrapper])
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *path = [selected path];
|
||||
BOOL removed = [mgr removeFileAtPath: path
|
||||
handler: nil];
|
||||
if(!removed)
|
||||
{
|
||||
NSString *msg = [NSString stringWithFormat: @"Could not delete file %@", path];
|
||||
NSLog(msg);
|
||||
}
|
||||
}
|
||||
[super deleteSelection];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) raiseSelection: (id)sender
|
||||
{
|
||||
id obj = [self changeSelection: sender];
|
||||
id e;
|
||||
|
||||
e = [document editorForObject: obj create: YES];
|
||||
[e orderFront];
|
||||
[e resetObject: obj];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) refreshCells
|
||||
{
|
||||
unsigned count = [objects count];
|
||||
unsigned index;
|
||||
int cols = 0;
|
||||
int rows;
|
||||
int width;
|
||||
|
||||
// return if the superview is not available.
|
||||
if(![self superview])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
width = [[self superview] bounds].size.width;
|
||||
while (width >= 72)
|
||||
{
|
||||
width -= (72 + 8);
|
||||
cols++;
|
||||
}
|
||||
if (cols == 0)
|
||||
{
|
||||
cols = 1;
|
||||
}
|
||||
rows = count / cols;
|
||||
if (rows == 0 || rows * cols != count)
|
||||
{
|
||||
rows++;
|
||||
}
|
||||
[self renewRows: rows columns: cols];
|
||||
|
||||
for (index = 0; index < count; index++)
|
||||
{
|
||||
id obj = [objects objectAtIndex: index];
|
||||
NSButtonCell *but = [self cellAtRow: index/cols column: index%cols];
|
||||
NSString *name = [(GormResource *)obj name];
|
||||
|
||||
[but setImage: [obj imageForViewer]];
|
||||
[but setTitle: name];
|
||||
[but setShowsStateBy: NSChangeGrayCellMask];
|
||||
[but setHighlightsBy: NSChangeGrayCellMask];
|
||||
}
|
||||
while (index < rows * cols)
|
||||
{
|
||||
NSButtonCell *but = [self cellAtRow: index/cols column: index%cols];
|
||||
|
||||
[but setImage: nil];
|
||||
[but setTitle: @""];
|
||||
[but setShowsStateBy: NSNoCellMask];
|
||||
[but setHighlightsBy: NSNoCellMask];
|
||||
index++;
|
||||
}
|
||||
[self setIntercellSpacing: NSMakeSize(8,8)];
|
||||
[self sizeToCells];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
@ -30,15 +30,14 @@
|
|||
|
||||
@implementation GormSoundEditor
|
||||
|
||||
static NSMapTable *docMap = 0;
|
||||
static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperationPrivate;
|
||||
static NSMapTable *docMap = 0;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [GormSoundEditor class])
|
||||
{
|
||||
docMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 2);
|
||||
NSObjectMapValueCallBacks, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,138 +53,43 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
|
|||
return editor;
|
||||
}
|
||||
|
||||
- (BOOL) acceptsTypeFromArray: (NSArray*)types
|
||||
- (NSArray *) fileTypes
|
||||
{
|
||||
if ([types containsObject: IBObjectPboardType] == YES)
|
||||
return YES;
|
||||
return NO;
|
||||
return [NSSound soundUnfilteredFileTypes];
|
||||
}
|
||||
|
||||
|
||||
- (void) copySelection
|
||||
- (NSArray *)pbTypes
|
||||
{
|
||||
if (selected != nil)
|
||||
return [NSArray arrayWithObject: GormSoundPboardType];
|
||||
}
|
||||
|
||||
- (NSString *) resourceType
|
||||
{
|
||||
return @"sound";
|
||||
}
|
||||
|
||||
- (id) placeHolderWithPath: (NSString *)string
|
||||
{
|
||||
return [GormSound soundForPath: string];
|
||||
}
|
||||
|
||||
- (void) addSystemResources
|
||||
{
|
||||
NSMutableArray *list = [NSMutableArray array];
|
||||
NSEnumerator *en;
|
||||
id obj;
|
||||
GormPalettesManager *palettesManager = [(Gorm *)NSApp palettesManager];
|
||||
|
||||
// add all of the system objects...
|
||||
[list addObjectsFromArray: systemSoundsList()];
|
||||
[list addObjectsFromArray: [palettesManager importedSounds]];
|
||||
en = [list objectEnumerator];
|
||||
while((obj = [en nextObject]) != nil)
|
||||
{
|
||||
[document copyObjects: [self selection]
|
||||
type: IBViewPboardType
|
||||
toPasteboard: [NSPasteboard generalPasteboard]];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Dragging source protocol implementation
|
||||
*/
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f
|
||||
{
|
||||
}
|
||||
|
||||
- (unsigned) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *pb = [sender draggingPasteboard];
|
||||
NSArray *pbtypes = [pb types];
|
||||
unsigned int mask = [sender draggingSourceOperationMask];
|
||||
|
||||
if ((mask & handled_mask) && [pbtypes containsObject: NSFilenamesPboardType])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (unsigned) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return [self draggingEntered: sender];
|
||||
}
|
||||
|
||||
- (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])
|
||||
{
|
||||
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
|
||||
{
|
||||
}
|
||||
|
||||
- (void) handleNotification: (NSNotification*)aNotification
|
||||
{
|
||||
NSString *name = [aNotification name];
|
||||
|
||||
if([name isEqual: GormResizeCellNotification])
|
||||
{
|
||||
NSDebugLog(@"Recieved notification");
|
||||
[self setCellSize: defaultCellSize()];
|
||||
}
|
||||
GormSound *sound = [GormSound soundForPath: obj];
|
||||
[sound setSystemResource: YES];
|
||||
[self addObject: sound];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -203,320 +107,17 @@ static int handled_mask= NSDragOperationCopy|NSDragOperationGeneric|NSDragOperat
|
|||
return self;
|
||||
}
|
||||
|
||||
self = [super initWithObject: anObject inDocument: aDocument];
|
||||
if (self != nil)
|
||||
if ((self = [super initWithObject: anObject inDocument: aDocument]) != nil)
|
||||
{
|
||||
NSButtonCell *proto;
|
||||
NSMutableArray *list = [NSMutableArray array];
|
||||
NSEnumerator *en;
|
||||
id obj;
|
||||
GormPalettesManager *palettesManager = [(Gorm *)NSApp palettesManager];
|
||||
|
||||
[self registerForDraggedTypes: [NSArray arrayWithObjects:
|
||||
NSFilenamesPboardType, nil]];
|
||||
|
||||
[self setAutosizesCells: NO];
|
||||
[self setCellSize: NSMakeSize(72,72)];
|
||||
[self setIntercellSpacing: NSMakeSize(8,8)];
|
||||
[self setAutoresizingMask: NSViewMinYMargin|NSViewWidthSizable];
|
||||
[self setMode: NSRadioModeMatrix];
|
||||
/*
|
||||
* Send mouse click actions to self, so we can handle selection.
|
||||
*/
|
||||
[self setAction: @selector(changeSelection:)];
|
||||
[self setDoubleAction: @selector(raiseSelection:)];
|
||||
[self setTarget: self];
|
||||
|
||||
objects = [NSMutableArray new];
|
||||
proto = [NSButtonCell new];
|
||||
[proto setBordered: NO];
|
||||
[proto setAlignment: NSCenterTextAlignment];
|
||||
[proto setImagePosition: NSImageAbove];
|
||||
[proto setSelectable: NO];
|
||||
[proto setEditable: NO];
|
||||
[self setPrototype: proto];
|
||||
RELEASE(proto);
|
||||
NSMapInsert(docMap, (void*)aDocument, (void*)self);
|
||||
|
||||
// do not insert it if it's nil.
|
||||
if(anObject != nil)
|
||||
{
|
||||
[self addObject: anObject];
|
||||
}
|
||||
|
||||
// add all of the system objects...
|
||||
[list addObjectsFromArray: systemSoundsList()];
|
||||
[list addObjectsFromArray: [palettesManager importedSounds]];
|
||||
en = [list objectEnumerator];
|
||||
while((obj = [en nextObject]) != nil)
|
||||
{
|
||||
GormSound *sound = [GormSound soundForPath: obj];
|
||||
[sound setSystemResource: YES];
|
||||
[self addObject: sound];
|
||||
}
|
||||
|
||||
// set up the notification...
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(handleNotification:)
|
||||
name: GormResizeCellNotification
|
||||
object: nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) close
|
||||
{
|
||||
[super close];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
NSMapRemove(docMap,document);
|
||||
}
|
||||
|
||||
- (void) addObject: (id)anObject
|
||||
{
|
||||
if([objects containsObject: anObject] == NO)
|
||||
{
|
||||
[super addObject: anObject];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSRunAlertPanel (_(@"Problem adding sound"),
|
||||
_(@"An sound with the same name exists, remove it first."),
|
||||
_(@"OK"),
|
||||
nil,
|
||||
nil);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) makeSelectionVisible: (BOOL)flag
|
||||
{
|
||||
if (flag == YES && selected != nil)
|
||||
{
|
||||
unsigned pos = [objects indexOfObjectIdenticalTo: selected];
|
||||
int r = pos / [self numberOfColumns];
|
||||
int c = pos % [self numberOfColumns];
|
||||
|
||||
[self selectCellAtRow: r column: c];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self deselectAllCells];
|
||||
}
|
||||
[self displayIfNeeded];
|
||||
[[self window] flushWindow];
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent*)theEvent
|
||||
{
|
||||
int row, column;
|
||||
int newRow, newColumn;
|
||||
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask
|
||||
| NSMouseMovedMask | NSLeftMouseDraggedMask
|
||||
| NSPeriodicMask;
|
||||
NSPoint lastLocation = [theEvent locationInWindow];
|
||||
NSEvent* lastEvent = theEvent;
|
||||
NSPoint initialLocation;
|
||||
|
||||
/*
|
||||
* Pathological case -- ignore mouse down
|
||||
*/
|
||||
if ((_numRows == 0) || (_numCols == 0))
|
||||
{
|
||||
[super mouseDown: theEvent];
|
||||
return;
|
||||
}
|
||||
|
||||
lastLocation = [self convertPoint: lastLocation
|
||||
fromView: nil];
|
||||
initialLocation = lastLocation;
|
||||
// If mouse down was on a selectable cell, start editing/selecting.
|
||||
if ([self getRow: &row
|
||||
column: &column
|
||||
forPoint: lastLocation])
|
||||
{
|
||||
if ([_cells[row][column] isEnabled])
|
||||
{
|
||||
if ((_mode == NSRadioModeMatrix) && _selectedCell != nil)
|
||||
{
|
||||
[_selectedCell setState: NSOffState];
|
||||
[self drawCellAtRow: _selectedRow column: _selectedColumn];
|
||||
_selectedCells[_selectedRow][_selectedColumn] = NO;
|
||||
_selectedCell = nil;
|
||||
_selectedRow = _selectedColumn = -1;
|
||||
}
|
||||
[_cells[row][column] setState: NSOnState];
|
||||
[self drawCellAtRow: row column: column];
|
||||
[_window flushWindow];
|
||||
_selectedCells[row][column] = YES;
|
||||
_selectedCell = _cells[row][column];
|
||||
_selectedRow = row;
|
||||
_selectedColumn = column;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastEvent = [NSApp nextEventMatchingMask: eventMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
lastLocation = [self convertPoint: [lastEvent locationInWindow]
|
||||
fromView: nil];
|
||||
|
||||
|
||||
while ([lastEvent type] != NSLeftMouseUp)
|
||||
{
|
||||
if((![self getRow: &newRow
|
||||
column: &newColumn
|
||||
forPoint: lastLocation])
|
||||
||
|
||||
(row != newRow)
|
||||
||
|
||||
(column != newColumn)
|
||||
||
|
||||
((lastLocation.x - initialLocation.x) *
|
||||
(lastLocation.x - initialLocation.x) +
|
||||
(lastLocation.y - initialLocation.y) *
|
||||
(lastLocation.y - initialLocation.y)
|
||||
>= 25))
|
||||
{
|
||||
NSPasteboard *pb;
|
||||
int pos;
|
||||
pos = row * [self numberOfColumns] + column;
|
||||
|
||||
// don't allow the user to drag empty resources.
|
||||
if(pos < [objects count])
|
||||
{
|
||||
pb = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
[pb declareTypes: [NSArray arrayWithObject: GormSoundPboardType]
|
||||
owner: self];
|
||||
[pb setString: [(GormResource *)[objects objectAtIndex: pos] name]
|
||||
forType: GormSoundPboardType];
|
||||
[self dragImage: [[objects objectAtIndex: pos] imageForViewer]
|
||||
at: lastLocation
|
||||
offset: NSZeroSize
|
||||
event: theEvent
|
||||
pasteboard: pb
|
||||
source: self
|
||||
slideBack: YES];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
lastEvent = [NSApp nextEventMatchingMask: eventMask
|
||||
untilDate: [NSDate distantFuture]
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
|
||||
lastLocation = [self convertPoint: [lastEvent locationInWindow]
|
||||
fromView: nil];
|
||||
|
||||
}
|
||||
|
||||
[self changeSelection: self];
|
||||
|
||||
}
|
||||
|
||||
- (void) pasteInSelection
|
||||
{
|
||||
}
|
||||
|
||||
- (void) deleteSelection
|
||||
{
|
||||
if(![selected isSystemResource])
|
||||
{
|
||||
if([selected isInWrapper])
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *path = [selected path];
|
||||
BOOL removed = [mgr removeFileAtPath: path
|
||||
handler: nil];
|
||||
if(!removed)
|
||||
{
|
||||
NSString *msg = [NSString stringWithFormat: @"Could not delete file %@", path];
|
||||
NSLog(msg);
|
||||
}
|
||||
}
|
||||
[super deleteSelection];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) raiseSelection: (id)sender
|
||||
{
|
||||
id obj = [self changeSelection: sender];
|
||||
id e;
|
||||
|
||||
e = [document editorForObject: obj create: YES];
|
||||
[e orderFront];
|
||||
[e resetObject: obj];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) refreshCells
|
||||
{
|
||||
unsigned count = [objects count];
|
||||
unsigned index;
|
||||
int cols = 0;
|
||||
int rows;
|
||||
int width;
|
||||
|
||||
// return if the superview is not available.
|
||||
if(![self superview])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
width = [[self superview] bounds].size.width;
|
||||
while (width >= 72)
|
||||
{
|
||||
width -= (72 + 8);
|
||||
cols++;
|
||||
}
|
||||
if (cols == 0)
|
||||
{
|
||||
cols = 1;
|
||||
}
|
||||
rows = count / cols;
|
||||
if (rows == 0 || rows * cols != count)
|
||||
{
|
||||
rows++;
|
||||
}
|
||||
[self renewRows: rows columns: cols];
|
||||
|
||||
for (index = 0; index < count; index++)
|
||||
{
|
||||
id obj = [objects objectAtIndex: index];
|
||||
NSButtonCell *but = [self cellAtRow: index/cols column: index%cols];
|
||||
NSString *name = [(GormResource *)obj name];
|
||||
|
||||
NSDebugLog(@"sound name = %@",name);
|
||||
[but setImage: [obj imageForViewer]];
|
||||
[but setTitle: name];
|
||||
[but setShowsStateBy: NSChangeGrayCellMask];
|
||||
[but setHighlightsBy: NSChangeGrayCellMask];
|
||||
}
|
||||
while (index < rows * cols)
|
||||
{
|
||||
NSButtonCell *but = [self cellAtRow: index/cols column: index%cols];
|
||||
|
||||
[but setImage: nil];
|
||||
[but setTitle: @""];
|
||||
[but setShowsStateBy: NSNoCellMask];
|
||||
[but setHighlightsBy: NSNoCellMask];
|
||||
index++;
|
||||
}
|
||||
[self setIntercellSpacing: NSMakeSize(8,8)];
|
||||
[self sizeToCells];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
- (void) resetObject: (id)anObject
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in a new issue