2004-06-06 12:32:15 +00:00
|
|
|
/* GormImageEditor.m
|
2002-11-18 20:54:26 +00:00
|
|
|
*
|
|
|
|
* 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
|
2007-11-05 23:44:36 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-11-18 20:54:26 +00:00
|
|
|
* (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
|
2005-05-26 03:37:38 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
2002-11-18 20:54:26 +00:00
|
|
|
*/
|
|
|
|
|
2019-11-03 01:57:39 +00:00
|
|
|
#include <AppKit/AppKit.h>
|
|
|
|
|
2005-04-23 18:43:36 +00:00
|
|
|
#include "GormImageEditor.h"
|
|
|
|
#include "GormProtocol.h"
|
2004-05-03 22:43:50 +00:00
|
|
|
#include "GormFunctions.h"
|
2004-07-14 03:10:44 +00:00
|
|
|
#include "GormPalettesManager.h"
|
2004-12-05 20:52:36 +00:00
|
|
|
#include "GormImage.h"
|
2002-11-18 20:54:26 +00:00
|
|
|
|
|
|
|
@implementation GormImageEditor
|
|
|
|
|
2005-03-06 04:05:03 +00:00
|
|
|
static NSMapTable *docMap = 0;
|
2002-11-18 20:54:26 +00:00
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [GormImageEditor class])
|
|
|
|
{
|
|
|
|
docMap = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks,
|
2008-04-24 04:55:40 +00:00
|
|
|
NSNonRetainedObjectMapValueCallBacks, 2);
|
2002-11-18 20:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (GormImageEditor*) editorForDocument: (id<IBDocuments>)aDocument
|
|
|
|
{
|
|
|
|
id editor = NSMapGet(docMap, (void*)aDocument);
|
|
|
|
|
|
|
|
if (editor == nil)
|
|
|
|
{
|
|
|
|
editor = [[self alloc] initWithObject: nil inDocument: aDocument];
|
|
|
|
AUTORELEASE(editor);
|
|
|
|
}
|
|
|
|
return editor;
|
|
|
|
}
|
|
|
|
|
2005-03-06 04:05:03 +00:00
|
|
|
- (NSArray *) fileTypes
|
2002-11-18 20:54:26 +00:00
|
|
|
{
|
2005-03-06 04:05:03 +00:00
|
|
|
return [NSImage imageFileTypes];
|
2002-11-18 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2005-03-06 04:05:03 +00:00
|
|
|
- (NSArray *)pbTypes
|
2002-11-18 20:54:26 +00:00
|
|
|
{
|
2005-03-06 04:05:03 +00:00
|
|
|
return [NSArray arrayWithObject: GormImagePboardType];
|
2002-11-18 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
2005-03-06 04:05:03 +00:00
|
|
|
- (NSString *) resourceType
|
2002-11-18 20:54:26 +00:00
|
|
|
{
|
2005-03-06 04:05:03 +00:00
|
|
|
return @"image";
|
2005-03-04 08:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) placeHolderWithPath: (NSString *)string
|
|
|
|
{
|
|
|
|
return [GormImage imageForPath: string];
|
|
|
|
}
|
|
|
|
|
2005-03-06 04:05:03 +00:00
|
|
|
- (void) addSystemResources
|
2002-11-18 20:54:26 +00:00
|
|
|
{
|
2005-03-06 04:05:03 +00:00
|
|
|
NSMutableArray *list = [NSMutableArray array];
|
|
|
|
NSEnumerator *en;
|
|
|
|
id obj;
|
2023-06-17 16:14:48 +00:00
|
|
|
GormPalettesManager *palettesManager = [(id<GormAppDelegate>)[NSApp delegate] palettesManager];
|
2005-03-06 04:05:03 +00:00
|
|
|
|
|
|
|
// add all of the system objects...
|
|
|
|
[list addObjectsFromArray: systemImagesList()];
|
|
|
|
[list addObjectsFromArray: [palettesManager importedImages]];
|
|
|
|
en = [list objectEnumerator];
|
|
|
|
while((obj = [en nextObject]) != nil)
|
2004-05-03 22:43:50 +00:00
|
|
|
{
|
2005-03-06 04:05:03 +00:00
|
|
|
GormImage *image = [GormImage imageForPath: obj];
|
|
|
|
[image setSystemResource: YES];
|
|
|
|
[self addObject: image];
|
|
|
|
}
|
2002-11-18 20:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialisation - register to receive DnD with our own types.
|
|
|
|
*/
|
|
|
|
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument
|
|
|
|
{
|
|
|
|
id old = NSMapGet(docMap, (void*)aDocument);
|
|
|
|
|
|
|
|
if (old != nil)
|
|
|
|
{
|
|
|
|
RELEASE(self);
|
|
|
|
self = RETAIN(old);
|
|
|
|
[self addObject: anObject];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2005-03-06 04:05:03 +00:00
|
|
|
if ((self = [super initWithObject: anObject inDocument: aDocument]) != nil)
|
2002-11-18 20:54:26 +00:00
|
|
|
{
|
|
|
|
NSMapInsert(docMap, (void*)aDocument, (void*)self);
|
|
|
|
}
|
2005-03-06 04:05:03 +00:00
|
|
|
|
2002-11-18 20:54:26 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2004-12-07 05:23:00 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2008-10-20 01:48:37 +00:00
|
|
|
if(closed == NO)
|
|
|
|
[self close];
|
2004-12-07 05:23:00 +00:00
|
|
|
|
2006-06-05 02:12:00 +00:00
|
|
|
// It is not necessary to call super dealloc here.
|
|
|
|
// images are cached throughout the lifetime of the app.
|
|
|
|
// Once loaded, they are in the cache permanently and
|
|
|
|
// are release on app termination.
|
|
|
|
|
2008-04-24 05:22:44 +00:00
|
|
|
// RELEASE(objects);
|
|
|
|
NSDebugLog(@"Released image editor...");
|
|
|
|
// GSNOSUPERDEALLOC;
|
|
|
|
[super dealloc];
|
2004-12-07 05:23:00 +00:00
|
|
|
}
|
|
|
|
|
2008-10-20 01:48:37 +00:00
|
|
|
- (void) willCloseDocument: (NSNotification *)aNotification
|
|
|
|
{
|
|
|
|
NSMapRemove(docMap,document);
|
|
|
|
[super willCloseDocument: aNotification];
|
|
|
|
}
|
|
|
|
|
2004-05-13 05:13:36 +00:00
|
|
|
- (void) close
|
|
|
|
{
|
|
|
|
[super close];
|
|
|
|
NSMapRemove(docMap,document);
|
|
|
|
}
|
2002-11-18 20:54:26 +00:00
|
|
|
@end
|