mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-23 06:20:47 +00:00
Various restructuring and fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5493 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6d93762aa0
commit
e1b3f57a27
7 changed files with 583 additions and 163 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
Mon Dec 13 14:57:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Gorm.h: Added NSView additions
|
||||
* GormWindowEditor.m: new skeleton file.
|
||||
* GormDocument.m: handle class replacement on archiving/unarchiving.
|
||||
Add filesOwner and firstResponder dummy objects.
|
||||
* GormResourcesManager.m: tidy files owner and first responder stuff.
|
||||
* GormObjectEditor.m: Use neater mechanism for determining image to
|
||||
be displayed in matrix.
|
||||
|
||||
Wed Dec 8 20:54:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Gorm.m: ([-init]) make sure that the palettes manager is loaded.
|
||||
|
|
|
@ -66,6 +66,7 @@ Gorm_OBJC_FILES = \
|
|||
IBPalette.m \
|
||||
InfoPanel.m \
|
||||
GormObjectEditor.m \
|
||||
GormWindowEditor.m \
|
||||
GormInspectorsManager.m \
|
||||
GormPalettesManager.m \
|
||||
GormResourcesManager.m
|
||||
|
|
13
Gorm.h
13
Gorm.h
|
@ -33,7 +33,7 @@
|
|||
/*
|
||||
* Positions of handles for resizing items.
|
||||
*/
|
||||
enum IBKnowPosition {
|
||||
typedef enum {
|
||||
IBBottomLeftKnobPosition,
|
||||
IBMiddleLeftKnobPosition,
|
||||
IBTopLeftKnobPosition,
|
||||
|
@ -42,7 +42,7 @@ enum IBKnowPosition {
|
|||
IBMiddleRightKnobPosition,
|
||||
IBBottomRightKnobPosition,
|
||||
IBBottomMiddleKnobPosition
|
||||
};
|
||||
} IBKnobPosition;
|
||||
|
||||
/*
|
||||
* Pasteboard types used for DnD when views are dragged out of a palette
|
||||
|
@ -240,4 +240,13 @@ extern NSString *IBDidEndTestingInterfaceNotification;
|
|||
- (NSWindow*) window;
|
||||
@end
|
||||
|
||||
@interface NSView (ViewAdditions)
|
||||
- (BOOL) acceptsColor: (NSColor*)color atPoint: (NSPoint)point;
|
||||
- (BOOL) allowsAltDragging;
|
||||
- (void) depositColor: (NSColor*)color atPoint: (NSPoint)point;
|
||||
- (NSSize) maximumSizeFromKnobPosition: (IBKnobPosition)knobPosition;
|
||||
- (NSSize) minimumSizeFromKnobPosition: (IBKnobPosition)position;
|
||||
- (void) placeView: (NSRect)newFrame;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,30 @@
|
|||
#ifndef GORMDOCUMENT_H
|
||||
#define GORMDOCUMENT_H
|
||||
|
||||
/*
|
||||
* Each document has a GormFilesOwner object that is used as a placeholder
|
||||
* for the owner of the document.
|
||||
*/
|
||||
@class GormFilesOwner;
|
||||
|
||||
/*
|
||||
* Each document has a GormFirstResponder object that is used as a placeholder
|
||||
* for the first responder at any instant.
|
||||
*/
|
||||
@class GormFirstResponder;
|
||||
|
||||
/*
|
||||
* Each document may have a GormFontManager object that is used as a
|
||||
* placeholder for the current fornt manager.
|
||||
*/
|
||||
@class GormFontManager;
|
||||
|
||||
@interface GormDocument : GSNibContainer <IBDocuments>
|
||||
{
|
||||
GormResourcesManager *resourcesManager;
|
||||
GormFilesOwner *filesOwner;
|
||||
GormFirstResponder *firstResponder;
|
||||
GormFontManager *fontManager;
|
||||
NSString *documentPath;
|
||||
NSMapTable *objToName;
|
||||
id owner; /* Dummy object */
|
||||
|
|
204
GormDocument.m
204
GormDocument.m
|
@ -30,14 +30,81 @@ NSString *IBDidSaveDocumentNotification = @"IBDidSaveDocumentNotification";
|
|||
NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
||||
|
||||
/*
|
||||
* A private connector for child->parent relationships.
|
||||
* Each document has a GormFilesOwner object that is used as a placeholder
|
||||
* for the owner of the document.
|
||||
*/
|
||||
@interface GormConnector : NSNibConnector
|
||||
@interface GormFilesOwner : NSObject
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormConnector
|
||||
@implementation GormFilesOwner
|
||||
- (NSImage*) imageForViewer
|
||||
{
|
||||
static NSImage *image = nil;
|
||||
|
||||
if (image == nil)
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *path = [bundle pathForImageResource: @"GormFilesOwner"];
|
||||
|
||||
image = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* Each document has a GormFirstResponder object that is used as a placeholder
|
||||
* for the first responder at any instant.
|
||||
*/
|
||||
@interface GormFirstResponder : NSObject
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormFirstResponder
|
||||
- (NSImage*) imageForViewer
|
||||
{
|
||||
static NSImage *image = nil;
|
||||
|
||||
if (image == nil)
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *path = [bundle pathForImageResource: @"GormFirstResponder"];
|
||||
|
||||
image = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* Each document may have a GormFontManager object that is used as a
|
||||
* placeholder for the current fornt manager.
|
||||
*/
|
||||
@interface GormFontManager : NSObject
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormFontManager
|
||||
- (NSImage*) imageForViewer
|
||||
{
|
||||
static NSImage *image = nil;
|
||||
|
||||
if (image == nil)
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *path = [bundle pathForImageResource: @"GormFontManager"];
|
||||
|
||||
image = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation GormDocument
|
||||
|
||||
|
@ -64,16 +131,16 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
*/
|
||||
if (aParent == nil)
|
||||
{
|
||||
aParent = owner;
|
||||
aParent = filesOwner;
|
||||
}
|
||||
old = [self connectorsForSource: anObject ofClass: [GormConnector class]];
|
||||
old = [self connectorsForSource: anObject ofClass: [NSNibConnector class]];
|
||||
if ([old count] > 0)
|
||||
{
|
||||
[[old objectAtIndex: 0] setDestination: aParent];
|
||||
}
|
||||
else
|
||||
{
|
||||
GormConnector *con = [GormConnector new];
|
||||
NSNibConnector *con = [NSNibConnector new];
|
||||
|
||||
[con setSource: anObject];
|
||||
[con setDestination: aParent];
|
||||
|
@ -82,11 +149,8 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
}
|
||||
[self setName: nil forObject: anObject];
|
||||
|
||||
if ([anObject isKindOfClass: [NSWindow class]] == YES)
|
||||
{
|
||||
[resourcesManager addObject: anObject];
|
||||
}
|
||||
else if ([anObject isKindOfClass: [NSMenu class]] == YES)
|
||||
if ([anObject isKindOfClass: [NSWindow class]] == YES
|
||||
|| [anObject isKindOfClass: [NSMenu class]] == YES)
|
||||
{
|
||||
[resourcesManager addObject: anObject];
|
||||
}
|
||||
|
@ -103,6 +167,15 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A Gorm document is encoded in the archive as a GSNibContainer ...
|
||||
* A class that the gnustep gui library knbows about and can unarchive.
|
||||
*/
|
||||
- (Class) classForCoder
|
||||
{
|
||||
return [GSNibContainer class];
|
||||
}
|
||||
|
||||
- (NSArray*) connectorsForDestination: (id)destination
|
||||
{
|
||||
return [self connectorsForDestination: destination ofClass: 0];
|
||||
|
@ -194,9 +267,11 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
{
|
||||
[[resourcesManager window] performClose: self];
|
||||
RELEASE(resourcesManager);
|
||||
RELEASE(filesOwner);
|
||||
RELEASE(firstResponder);
|
||||
RELEASE(fontManager);
|
||||
NSFreeMapTable(objToName);
|
||||
RELEASE(documentPath);
|
||||
RELEASE(owner);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -215,11 +290,8 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
}
|
||||
}
|
||||
NSMapRemove(objToName, (void*)anObject);
|
||||
if ([anObject isKindOfClass: [NSWindow class]] == YES)
|
||||
{
|
||||
[resourcesManager removeObject: anObject];
|
||||
}
|
||||
else if ([anObject isKindOfClass: [NSMenu class]] == YES)
|
||||
if ([anObject isKindOfClass: [NSWindow class]] == YES
|
||||
|| [anObject isKindOfClass: [NSMenu class]] == YES)
|
||||
{
|
||||
[resourcesManager removeObject: anObject];
|
||||
}
|
||||
|
@ -323,8 +395,6 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
|
||||
/*
|
||||
* Map all connector sources and destinations to their name strings.
|
||||
* The 'owner' dummy object maps to 'NSOwner'.
|
||||
* The nil object maps to 'NSFirstResponder'.
|
||||
*/
|
||||
enumerator = [connections objectEnumerator];
|
||||
while ((con = [enumerator nextObject]) != nil)
|
||||
|
@ -339,13 +409,25 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
name = [self nameForObject: obj];
|
||||
[con setDestination: name];
|
||||
}
|
||||
/*
|
||||
* Remove objects that shouldn't be archived.
|
||||
*/
|
||||
[nameTable removeObjectForKey: @"NSOwner"];
|
||||
[nameTable removeObjectForKey: @"NSFirst"];
|
||||
|
||||
/*
|
||||
* Archive self into file
|
||||
*/
|
||||
[super encodeWithCoder: aCoder];
|
||||
|
||||
/*
|
||||
* Restore removed objects.
|
||||
*/
|
||||
[nameTable setObject: filesOwner forKey: @"NSOwner"];
|
||||
[nameTable setObject: firstResponder forKey: @"NSFirst"];
|
||||
|
||||
/*
|
||||
* Map all connector source and destination names to their objects.
|
||||
* The string 'NSOwner' maps to the 'owner' dummy object.
|
||||
* The string 'NSFirstResponder' maps to nil.
|
||||
*/
|
||||
enumerator = [connections objectEnumerator];
|
||||
while ((con = [enumerator nextObject]) != nil)
|
||||
|
@ -369,40 +451,30 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
{
|
||||
objToName = NSCreateMapTableWithZone(NSNonRetainedObjectMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks, 128, [self zone]);
|
||||
owner = [NSObject new];
|
||||
|
||||
resourcesManager = [GormResourcesManager newManagerForDocument: self];
|
||||
/*
|
||||
* Set up special-case dummy objects and add them to the resources mgr.
|
||||
*/
|
||||
filesOwner = [GormFilesOwner new];
|
||||
[self setName: @"NSOwner" forObject: filesOwner];
|
||||
[resourcesManager addObject: filesOwner];
|
||||
firstResponder = [GormFirstResponder new];
|
||||
[self setName: @"NSFirst" forObject: firstResponder];
|
||||
[resourcesManager addObject: firstResponder];
|
||||
fontManager = [GormFontManager new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString*) nameForObject: (id)anObject
|
||||
{
|
||||
if (anObject == nil)
|
||||
{
|
||||
return @"NSFirstResponder";
|
||||
}
|
||||
else if (anObject == owner)
|
||||
{
|
||||
return @"NSOwner";
|
||||
}
|
||||
else
|
||||
{
|
||||
return (NSString*)NSMapGet(objToName, (void*)anObject);
|
||||
}
|
||||
return (NSString*)NSMapGet(objToName, (void*)anObject);
|
||||
}
|
||||
|
||||
- (id) objectForName: (NSString*)name
|
||||
{
|
||||
id obj = [nameTable objectForKey: name];
|
||||
|
||||
if (obj == nil)
|
||||
{
|
||||
if ([name isEqualToString: @"NSOwner"] == YES)
|
||||
{
|
||||
obj = owner;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
return [nameTable objectForKey: name];
|
||||
}
|
||||
|
||||
- (NSArray*) objects
|
||||
|
@ -429,12 +501,12 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
if (result == NSOKButton)
|
||||
{
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
NSMutableDictionary *nt;
|
||||
NSString *aFile = [oPanel filename];
|
||||
NSData *data;
|
||||
NSUnarchiver *u;
|
||||
GSNibContainer *c;
|
||||
NSEnumerator *enumerator;
|
||||
NSDictionary *nt;
|
||||
id <IBConnectors> con;
|
||||
NSString *name;
|
||||
|
||||
|
@ -446,8 +518,15 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
@"OK", NULL, NULL);
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create an unarchiver, and use it to unarchive the nib file while
|
||||
* handling class replacement so that standard objects understood
|
||||
* by the gui library are converted to their Gorm internal equivalents.
|
||||
*/
|
||||
u = AUTORELEASE([[NSUnarchiver alloc] initForReadingWithData: data]);
|
||||
/* FIXME - need to handle class replacement here */
|
||||
[u decodeClassName: @"GSNibContainer"
|
||||
asClassName: @"GormDocument"];
|
||||
c = [u decodeObject];
|
||||
if (c == nil || [c isKindOfClass: [GSNibContainer class]] == NO)
|
||||
{
|
||||
|
@ -461,7 +540,8 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
* to hold the objects rather than their names (using our own dummy
|
||||
* object as the 'NSOwner'.
|
||||
*/
|
||||
[[c nameTable] setObject: owner forKey: @"NSOwner"];
|
||||
[[c nameTable] setObject: filesOwner forKey: @"NSOwner"];
|
||||
[[c nameTable] setObject: firstResponder forKey: @"NSFirst"];
|
||||
nt = [c nameTable];
|
||||
enumerator = [[c connections] objectEnumerator];
|
||||
while ((con = [enumerator nextObject]) != nil)
|
||||
|
@ -476,19 +556,22 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
obj = [nt objectForKey: name];
|
||||
[con setDestination: obj];
|
||||
}
|
||||
[[c nameTable] removeObjectForKey: @"NSOwner"];
|
||||
|
||||
|
||||
/*
|
||||
* Now we merge the objects from the nib container into our own
|
||||
* data structures.
|
||||
* Now we merge the objects from the nib container into our own data
|
||||
* structures, taking care not to overwrite our NSOwner and NSFirst.
|
||||
*/
|
||||
[nt removeObjectForKey: @"NSOwner"];
|
||||
[nt removeObjectForKey: @"NSFirst"];
|
||||
[connections addObjectsFromArray: [c connections]];
|
||||
[nameTable addEntriesFromDictionary: [c nameTable]];
|
||||
[nameTable addEntriesFromDictionary: nt];
|
||||
|
||||
/*
|
||||
* Now we build our reverse mapping information and other initialisation
|
||||
*/
|
||||
NSResetMapTable(objToName);
|
||||
NSMapInsert(objToName, (void*)filesOwner, (void*)@"NSOwner");
|
||||
NSMapInsert(objToName, (void*)firstResponder, (void*)@"NSFirst");
|
||||
enumerator = [nameTable keyEnumerator];
|
||||
while ((name = [enumerator nextObject]) != nil)
|
||||
{
|
||||
|
@ -496,11 +579,8 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
|
||||
NSMapInsert(objToName, (void*)obj, (void*)name);
|
||||
|
||||
if ([obj isKindOfClass: [NSWindow class]] == YES)
|
||||
{
|
||||
[resourcesManager addObject: obj];
|
||||
}
|
||||
else if ([obj isKindOfClass: [NSMenu class]] == YES)
|
||||
if ([obj isKindOfClass: [NSWindow class]] == YES
|
||||
|| [obj isKindOfClass: [NSMenu class]] == YES)
|
||||
{
|
||||
[resourcesManager addObject: obj];
|
||||
}
|
||||
|
@ -537,9 +617,9 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
NSArray *old;
|
||||
id<IBConnectors> con;
|
||||
|
||||
old = [self connectorsForSource: anObject ofClass: [GormConnector class]];
|
||||
old = [self connectorsForSource: anObject ofClass: [NSNibConnector class]];
|
||||
con = [old lastObject];
|
||||
if (con != nil && [con destination] != owner)
|
||||
if ([con destination] != filesOwner && [con destination] != firstResponder)
|
||||
{
|
||||
return [con destination];
|
||||
}
|
||||
|
@ -655,12 +735,6 @@ NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
|||
NSMapRemove(objToName, (void*)object);
|
||||
}
|
||||
}
|
||||
if ([aName isEqualToString: @"NSOwner"]
|
||||
|| [aName isEqualToString: @"NSFirstResponder"])
|
||||
{
|
||||
NSLog(@"Attempt to set object name to '%@' ignored", aName);
|
||||
return;
|
||||
}
|
||||
[nameTable setObject: object forKey: aName];
|
||||
NSMapInsert(objToName, (void*)object, (void*)aName);
|
||||
if (oldName != nil)
|
||||
|
|
|
@ -24,6 +24,28 @@
|
|||
|
||||
#include "GormPrivate.h"
|
||||
|
||||
/*
|
||||
* Method to return the image that should be used to display objects within
|
||||
* the matrix containing the objects in a document.
|
||||
*/
|
||||
@implementation NSObject (IBObjectAdditions)
|
||||
- (NSImage*) imageForViewer
|
||||
{
|
||||
static NSImage *image = nil;
|
||||
|
||||
if (image == nil)
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *path = [bundle pathForImageResource: @"GormObject"];
|
||||
|
||||
image = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface GormObjectEditor : NSMatrix <IBEditors>
|
||||
{
|
||||
NSMutableArray *objects;
|
||||
|
@ -60,60 +82,6 @@
|
|||
|
||||
@implementation GormObjectEditor
|
||||
|
||||
static NSImage *objectImage = nil;
|
||||
static NSImage *windowImage = nil;
|
||||
static NSImage *menuImage = nil;
|
||||
static NSImage *firstImage = nil;
|
||||
static NSImage *ownerImage = nil;
|
||||
static NSImage *fontImage = nil;
|
||||
static NSImage *dragImage = nil;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [GormObjectEditor class])
|
||||
{
|
||||
NSBundle *bundle;
|
||||
NSString *path;
|
||||
|
||||
bundle = [NSBundle mainBundle];
|
||||
path = [bundle pathForImageResource: @"GormLinkImage"];
|
||||
if (path != nil)
|
||||
{
|
||||
dragImage = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
path = [bundle pathForImageResource: @"GormObject"];
|
||||
if (path != nil)
|
||||
{
|
||||
objectImage = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
path = [bundle pathForImageResource: @"GormFilesOwner"];
|
||||
if (path != nil)
|
||||
{
|
||||
ownerImage = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
path = [bundle pathForImageResource: @"GormFirstResponder"];
|
||||
if (path != nil)
|
||||
{
|
||||
firstImage = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
path = [bundle pathForImageResource: @"GormFontManager"];
|
||||
if (path != nil)
|
||||
{
|
||||
fontImage = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
path = [bundle pathForImageResource: @"GormMenu"];
|
||||
if (path != nil)
|
||||
{
|
||||
menuImage = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
path = [bundle pathForImageResource: @"GormWindow"];
|
||||
if (path != nil)
|
||||
{
|
||||
windowImage = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addObject: (id)anObject
|
||||
{
|
||||
if ([objects indexOfObjectIdenticalTo: anObject] == NSNotFound)
|
||||
|
@ -159,8 +127,6 @@ static NSImage *dragImage = nil;
|
|||
[self setTarget: self];
|
||||
|
||||
objects = [NSMutableArray new];
|
||||
[objects addObject: ownerImage];
|
||||
[objects addObject: firstImage];
|
||||
proto = [NSButtonCell new];
|
||||
[proto setBordered: NO];
|
||||
[proto setAlignment: NSCenterTextAlignment];
|
||||
|
@ -273,10 +239,9 @@ static NSImage *dragImage = nil;
|
|||
offset.width = mouseDownPoint.x - dragPoint.x;
|
||||
offset.height = mouseDownPoint.y - dragPoint.y;
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
NSLog(@"Could do dragging");
|
||||
#else
|
||||
RELEASE(dragImage);
|
||||
dragImage = [NSImage new];
|
||||
rep = [[NSCachedImageRep alloc] initWithWindow: [self window]
|
||||
rect: rect];
|
||||
|
@ -310,10 +275,6 @@ NSLog(@"Could do dragging");
|
|||
if (index >= 0 && index < [objects count])
|
||||
{
|
||||
obj = [objects objectAtIndex: index];
|
||||
if (obj == ownerImage || obj == firstImage || obj == fontImage)
|
||||
{
|
||||
obj = nil; /* Can't select these. */
|
||||
}
|
||||
if (obj != selected)
|
||||
{
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
|
@ -371,36 +332,8 @@ NSLog(@"Could do dragging");
|
|||
id obj = [objects objectAtIndex: index];
|
||||
NSButtonCell *but = [self cellAtRow: index/cols column: index%cols];
|
||||
|
||||
if (obj == ownerImage)
|
||||
{
|
||||
[but setImage: obj];
|
||||
[but setTitle: @"File's Owner"];
|
||||
}
|
||||
else if (obj == firstImage)
|
||||
{
|
||||
[but setImage: obj];
|
||||
[but setTitle: @"1st Responder"];
|
||||
}
|
||||
else if (obj == fontImage)
|
||||
{
|
||||
[but setImage: obj];
|
||||
[but setTitle: @"Font Manager"];
|
||||
}
|
||||
else if ([obj isKindOfClass: [NSWindow class]])
|
||||
{
|
||||
[but setImage: windowImage];
|
||||
[but setTitle: [document nameForObject: obj]];
|
||||
}
|
||||
else if ([obj isKindOfClass: [NSMenu class]])
|
||||
{
|
||||
[but setImage: menuImage];
|
||||
[but setTitle: [document nameForObject: obj]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[but setImage: objectImage];
|
||||
[but setTitle: [document nameForObject: obj]];
|
||||
}
|
||||
[but setImage: [obj imageForViewer]];
|
||||
[but setTitle: [document nameForObject: obj]];
|
||||
[but setShowsStateBy: NSChangeGrayCellMask];
|
||||
[but setHighlightsBy: NSChangeGrayCellMask];
|
||||
}
|
||||
|
@ -428,10 +361,6 @@ NSLog(@"Could do dragging");
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (anObject == ownerImage || anObject == firstImage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
[objects removeObjectAtIndex: pos];
|
||||
[self refreshCells];
|
||||
}
|
||||
|
|
376
GormWindowEditor.m
Normal file
376
GormWindowEditor.m
Normal file
|
@ -0,0 +1,376 @@
|
|||
/* GormWindowEditor.m
|
||||
*
|
||||
* Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
*
|
||||
* Author: Richard Frith-Macdonald <richard@brainstrom.co.uk>
|
||||
* Date: 1999
|
||||
*
|
||||
* 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"
|
||||
|
||||
/*
|
||||
* Methods to return the images that should be used to display objects within
|
||||
* the matrix containing the objects in a document.
|
||||
*/
|
||||
@implementation NSMenu (IBObjectAdditions)
|
||||
- (NSImage*) imageForViewer
|
||||
{
|
||||
static NSImage *image = nil;
|
||||
|
||||
if (image == nil)
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *path = [bundle pathForImageResource: @"GormMenu"];
|
||||
|
||||
image = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSWindow (IBObjectAdditions)
|
||||
- (NSImage*) imageForViewer
|
||||
{
|
||||
static NSImage *image = nil;
|
||||
|
||||
if (image == nil)
|
||||
{
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSString *path = [bundle pathForImageResource: @"GormWindow"];
|
||||
|
||||
image = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
}
|
||||
return image;
|
||||
}
|
||||
@end
|
||||
|
||||
/*
|
||||
* Default implementations of methods used for updating a view by
|
||||
* direct action through an editor.
|
||||
*/
|
||||
@implementation NSView (ViewAdditions)
|
||||
|
||||
- (BOOL) acceptsColor: (NSColor*)color atPoint: (NSPoint)point
|
||||
{
|
||||
return NO; /* Can the view accept a color drag-and-drop? */
|
||||
}
|
||||
|
||||
- (BOOL) allowsAltDragging
|
||||
{
|
||||
return NO; /* Can the view be dragged into a matrix? */
|
||||
}
|
||||
|
||||
- (void) depositColor: (NSColor*)color atPoint: (NSPoint)point
|
||||
{
|
||||
/* Handle color drop in view. */
|
||||
}
|
||||
|
||||
- (NSSize) maximumSizeFromKnobPosition: (IBKnobPosition)knobPosition
|
||||
{
|
||||
NSView *s = [self superview];
|
||||
NSRect r = (s != nil) ? [s bounds] : [self bounds];
|
||||
|
||||
return r.size; /* maximum resize permitted */
|
||||
}
|
||||
|
||||
- (NSSize) minimumSizeFromKnobPosition: (IBKnobPosition)position
|
||||
{
|
||||
return NSZeroSize; /* Minimum resize permitted */
|
||||
}
|
||||
|
||||
- (void) placeView: (NSRect)newFrame
|
||||
{
|
||||
[self setFrame: newFrame]; /* View changed by editor. */
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface GormWindowEditor : NSView <IBEditors>
|
||||
{
|
||||
id<IBDocuments> document;
|
||||
id edited;
|
||||
NSMutableArray *selection;
|
||||
NSPoint mouseDownPoint;
|
||||
BOOL shouldBeginDrag;
|
||||
NSPasteboard *dragPb;
|
||||
}
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f;
|
||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag;
|
||||
- (BOOL) acceptsTypeFromArray: (NSArray*)types;
|
||||
- (BOOL) activate;
|
||||
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument;
|
||||
- (void) close;
|
||||
- (void) closeSubeditors;
|
||||
- (void) copySelection;
|
||||
- (void) deleteSelection;
|
||||
- (id<IBDocuments>) document;
|
||||
- (id) editedObject;
|
||||
- (void) makeSelectionVisible: (BOOL)flag;
|
||||
- (id<IBEditors>) openSubeditorForObject: (id)anObject;
|
||||
- (void) orderFront;
|
||||
- (void) pasteInSelection;
|
||||
- (void) resetObject: (id)anObject;
|
||||
- (void) selectObjects: (NSArray*)objects;
|
||||
- (void) validateEditing;
|
||||
- (BOOL) wantsSelection;
|
||||
- (NSWindow*) window;
|
||||
@end
|
||||
|
||||
@implementation GormWindowEditor
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(edited);
|
||||
RELEASE(selection);
|
||||
RELEASE(document);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialisation - register to receive DnD with our own types.
|
||||
*/
|
||||
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument
|
||||
{
|
||||
self = [super init];
|
||||
ASSIGN(document, aDocument);
|
||||
ASSIGN(edited, anObject);
|
||||
selection = [NSMutableArray new];
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dragging source protocol implementation
|
||||
*/
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f
|
||||
{
|
||||
NSString *type = [[dragPb types] lastObject];
|
||||
|
||||
/*
|
||||
* Windows are an exception to the normal DnD mechanism - we create them
|
||||
* if they are dropped anywhere except back in the pallettes view -
|
||||
* ie. if they are dragged, but the drop fails.
|
||||
*/
|
||||
if (f == NO && [type isEqual: IBWindowPboardType] == YES)
|
||||
{
|
||||
id<IBDocuments> active = [(id<IB>)NSApp activeDocument];
|
||||
|
||||
if (active != nil)
|
||||
{
|
||||
[active pasteType: type fromPasteboard: dragPb parent: nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
|
||||
{
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dragging destination protocol implementation
|
||||
*
|
||||
* We actually don't handle anything being dropped on the palette,
|
||||
* but we pretend to accept drops from ourself, so that the drag
|
||||
* session quietly terminates - and it looks like the drop has
|
||||
* been successful - this stops windows being created when they are
|
||||
* dropped back on the palette (a window is normally created if the
|
||||
* dnd drop is refused).
|
||||
*/
|
||||
- (unsigned) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return NSDragOperationCopy;;
|
||||
}
|
||||
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Intercepting events in the view and handling them
|
||||
*/
|
||||
- (NSView*) hitTest: (NSPoint)loc
|
||||
{
|
||||
/*
|
||||
* Stop the subviews receiving events - we grab them all.
|
||||
*/
|
||||
if ([super hitTest: loc] != nil)
|
||||
return self;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent*)theEvent
|
||||
{
|
||||
NSView *view;
|
||||
|
||||
mouseDownPoint = [theEvent locationInWindow];
|
||||
view = [super hitTest: mouseDownPoint];
|
||||
if (view == self)
|
||||
{
|
||||
shouldBeginDrag = NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
shouldBeginDrag = YES;
|
||||
}
|
||||
[super mouseDown: theEvent];
|
||||
}
|
||||
|
||||
- (void) mouseDragged: (NSEvent*)theEvent
|
||||
{
|
||||
if (shouldBeginDrag == YES)
|
||||
{
|
||||
NSPoint dragPoint = [theEvent locationInWindow];
|
||||
NSView *view = [super hitTest: mouseDownPoint];
|
||||
GormDocument *active = [(id<IB>)NSApp activeDocument];
|
||||
NSRect rect = [view frame];
|
||||
NSString *type;
|
||||
id obj;
|
||||
NSPasteboard *pb;
|
||||
NSImageRep *rep;
|
||||
NSSize offset;
|
||||
|
||||
offset.width = mouseDownPoint.x - dragPoint.x;
|
||||
offset.height = mouseDownPoint.y - dragPoint.y;
|
||||
|
||||
#if 1
|
||||
NSLog(@"Could do dragging");
|
||||
#else
|
||||
RELEASE(dragImage);
|
||||
dragImage = [NSImage new];
|
||||
rep = [[NSCachedImageRep alloc] initWithWindow: [self window]
|
||||
rect: rect];
|
||||
[dragImage setSize: rect.size];
|
||||
[dragImage addRepresentation: rep];
|
||||
|
||||
type = [IBPalette typeForView: view];
|
||||
obj = [IBPalette objectForView: view];
|
||||
pb = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
ASSIGN(dragPb, pb);
|
||||
[active copyObject: obj type: type toPasteboard: pb];
|
||||
|
||||
[self dragImage: dragImage
|
||||
at: rect.origin
|
||||
offset: offset
|
||||
event: theEvent
|
||||
pasteboard: pb
|
||||
source: self
|
||||
slideBack: [type isEqual: IBWindowPboardType] ? NO : YES];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) acceptsTypeFromArray: (NSArray*)types
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) activate
|
||||
{
|
||||
[window makeKeyAndOrderFront: self];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) close
|
||||
{
|
||||
[self closeSubeditors];
|
||||
}
|
||||
|
||||
- (void) closeSubeditors
|
||||
{
|
||||
}
|
||||
|
||||
- (void) copySelection
|
||||
{
|
||||
}
|
||||
|
||||
- (void) deleteSelection
|
||||
{
|
||||
}
|
||||
|
||||
- (void) drawSelection
|
||||
{
|
||||
}
|
||||
|
||||
- (id<IBDocuments>) document
|
||||
{
|
||||
return document;
|
||||
}
|
||||
|
||||
- (id) editedObject
|
||||
{
|
||||
return edited;
|
||||
}
|
||||
|
||||
- (void) makeSelectionVisible: (BOOL)flag
|
||||
{
|
||||
}
|
||||
|
||||
- (id<IBEditors>) openSubeditorForObject: (id)anObject
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) orderFront
|
||||
{
|
||||
[window orderFront: self];
|
||||
}
|
||||
|
||||
- (void) pasteInSelection
|
||||
{
|
||||
}
|
||||
|
||||
- (void) resetObject: (id)anObject
|
||||
{
|
||||
}
|
||||
|
||||
- (void) selectObjects: (NSArray*)anArray
|
||||
{
|
||||
}
|
||||
|
||||
- (NSArray*) selection
|
||||
{
|
||||
return AUTORELEASE([selection copy]);
|
||||
}
|
||||
|
||||
- (unsigned) selectionCount
|
||||
{
|
||||
return [selection count];
|
||||
}
|
||||
|
||||
- (void) validateEditing
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL) wantsSelection
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSWindow*) window
|
||||
{
|
||||
return [self window];
|
||||
}
|
||||
@end
|
Loading…
Reference in a new issue