Connection mechanism started.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5558 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-12-17 17:22:18 +00:00
parent c11ab2237f
commit c01d75390e
8 changed files with 223 additions and 81 deletions

View file

@ -51,8 +51,7 @@ Gorm_RESOURCE_FILES = \
Images/GormSound.tiff \
Images/GormSourceTag.tiff \
Images/GormTargetTag.tiff \
Images/Gorm.tiff \
Images/GormLinkImage.tiff
Images/Gorm.tiff
Gorm_HEADERS = \
Gorm.h \

8
Gorm.h
View file

@ -88,6 +88,14 @@ extern NSString *IBDidEndTestingInterfaceNotification;
- (void) setSource: (id)anObject;
@end
@interface NSApplication (IBConnections)
- (id) connectSource;
- (id) connectDestination;
- (BOOL) isConnecting;
- (void) stopConnecting;
- (void) displayConnectionBetween: (id)source and: (id)destination;
@end
@interface NSObject (IBEditorSpecification)
- (NSString*) editorClassName;
@end

73
Gorm.m
View file

@ -33,6 +33,9 @@ NSString *IBWillEndTestingInterfaceNotification
NSString *IBDidEndTestingInterfaceNotification
= @"IBDidEndTestingInterfaceNotification";
NSString *GormLinkPboardType = @"GormLinkPboardType";
@class InfoPanel;
@implementation Gorm
@ -89,6 +92,16 @@ NSString *IBDidEndTestingInterfaceNotification
return self;
}
- (id) connectDestination
{
return connectDestination;
}
- (id) connectSource
{
return connectSource;
}
- (id) cut: (id)sender
{
if ([[selectionOwner selection] count] == 0
@ -121,6 +134,10 @@ NSString *IBDidEndTestingInterfaceNotification
return self;
}
- (void) displayConnectionBetween: (id)source and: (id)destination
{
}
- (id) endTesting: (id)sender
{
if (isTesting == NO)
@ -185,8 +202,6 @@ NSString *IBDidEndTestingInterfaceNotification
NSBundle *bundle = [NSBundle mainBundle];
NSString *path;
path = [bundle pathForImageResource: @"GormLinkImage"];
linkImage = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormSourceTag"];
sourceImage = [[NSImage alloc] initWithContentsOfFile: path];
path = [bundle pathForImageResource: @"GormTargetTag"];
@ -226,16 +241,30 @@ NSString *IBDidEndTestingInterfaceNotification
return inspectorsManager;
}
- (BOOL) isConnecting
{
if (connectDestination == nil || connectSource == nil)
{
return NO;
}
if ([activeDocument containsObject: connectDestination] == NO)
{
NSLog(@"Oops - connectDestination not in active document");
return NO;
}
if ([activeDocument containsObject: connectSource] == NO)
{
NSLog(@"Oops - connectSource not in active document");
return NO;
}
return YES;
}
- (BOOL) isTestingInterface
{
return isTesting;
}
- (NSImage*) linkImage
{
return linkImage;
}
- (id) loadPalette: (id) sender
{
return [[self palettesManager] openPalette: sender];
@ -341,6 +370,26 @@ NSString *IBDidEndTestingInterfaceNotification
return [[selectionOwner selection] lastObject];
}
- (void) setConnectDestination: (id)anObject
{
connectDestination = anObject;
if ([self isConnecting])
{
[self displayConnectionBetween: connectSource and: connectDestination];
[[self inspectorsManager] updateSelection];
}
}
- (void) setConnectSource: (id)anObject
{
connectSource = anObject;
if ([self isConnecting])
{
[self displayConnectionBetween: connectSource and: connectDestination];
[[self inspectorsManager] updateSelection];
}
}
- (id) setName: (id)sender
{
/* FIXME */
@ -352,6 +401,16 @@ NSString *IBDidEndTestingInterfaceNotification
return sourceImage;
}
- (void) stopConnecting
{
if ([self isConnecting])
{
[self displayConnectionBetween: nil and: nil];
}
connectDestination = nil;
connectSource = nil;
}
- (NSImage*) targetImage
{
return targetImage;

View file

@ -4,6 +4,7 @@
@interface GormInspectorsManager : NSObject
{
NSPanel *panel;
NSPopUpButton *popup;
NSView *selectionView;
NSView *inspectorView;
NSView *buttonView;

View file

@ -217,7 +217,6 @@
- (id) init
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSPopUpButton *popup;
NSMenuItem *item;
NSRect contentRect = {{0, 0}, {272, 420}};
NSRect popupRect = {{60, 15}, {152, 20}};
@ -317,7 +316,16 @@
- (void) updateSelection
{
[self setCurrentInspector: self];
if ([NSApp isConnecting] == YES)
{
[popup selectItemAtIndex: 1];
[popup setNeedsDisplay: YES];
[panel makeKeyAndOrderFront: self];
}
else
{
[self setCurrentInspector: self];
}
}
- (void) setCurrentInspector: (id)anObj
@ -454,6 +462,10 @@
[newView setFrame: rect];
[inspectorView addSubview: newView];
}
/*
* Tell inspector to update from its object.
*/
[inspector revert: self];
}
@end

View file

@ -11,6 +11,8 @@
#include "GormInspectorsManager.h"
#include "GormPalettesManager.h"
extern NSString *GormLinkPboardType;
@interface Gorm : NSApplication <IB>
{
id infoPanel;
@ -20,16 +22,23 @@
id activeDocument;
NSMutableArray *documents;
BOOL isTesting;
NSImage *linkImage;
NSImage *sourceImage;
NSImage *targetImage;
id connectSource;
id connectDestination;
}
- (id<IBDocuments>) activeDocument;
- (id) connectSource;
- (id) connectDestination;
- (void) displayConnectionBetween: (id)source and: (id)destination;
- (void) handleNotification: (NSNotification*)aNotification;
- (GormInspectorsManager*) inspectorsManager;
- (NSImage*) linkImage;
- (BOOL) isConnecting;
- (GormPalettesManager*) palettesManager;
- (void) setConnectDestination: (id)anObject;
- (void) setConnectSource: (id)anObject;
- (NSImage*) sourceImage;
- (void) stopConnecting;
- (NSImage*) targetImage;
- (id) copy: (id)sender;

View file

@ -327,6 +327,42 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
view = nil;
}
/*
* Control-click on a subview initiates a connection attempt.
*/
if (view != nil && view != self && knob == IBNoneKnobPosition
&& ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)
{
NSPoint dragPoint = [theEvent locationInWindow];
NSPasteboard *pb;
NSString *name = [document nameForObject: view];
pb = [NSPasteboard pasteboardWithName: NSDragPboard];
[pb declareTypes: [NSArray arrayWithObject: GormLinkPboardType]
owner: self];
[pb setString: name forType: GormLinkPboardType];
[(Gorm*)NSApp setConnectSource: view];
/*
* Mark the view as being a drag source.
*/
[self lockFocus];
[[(Gorm*)NSApp sourceImage]
compositeToPoint: [view frame].origin operation: NSCompositeCopy];
[self unlockFocus];
[[self window] flushWindow];
[self dragImage: [(Gorm*)NSApp targetImage]
at: dragPoint
offset: NSZeroSize
event: theEvent
pasteboard: pb
source: self
slideBack: YES];
[self makeSelectionVisible: YES];
return;
}
/*
* Having determined the current selection, we now handle events.
*/
@ -483,25 +519,17 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
dragStarted = YES;
[self makeSelectionVisible: NO];
}
if ([theEvent modifierFlags] & NSControlKeyMask)
enumerator = [selection objectEnumerator];
while ((subview = [enumerator nextObject]) != nil)
{
NSLog(@"Control key not yet supported");
/* FIXME */
}
else
{
enumerator = [selection objectEnumerator];
while ((subview = [enumerator nextObject]) != nil)
{
NSRect oldFrame = [subview frame];
NSRect oldFrame = [subview frame];
r = oldFrame;
r.origin.x += xDiff;
r.origin.y += yDiff;
[subview setFrame: r];
[self displayRect: oldFrame];
[subview display];
}
r = oldFrame;
r.origin.x += xDiff;
r.origin.y += yDiff;
[subview setFrame: r];
[self displayRect: oldFrame];
[subview display];
}
}
else
@ -665,19 +693,10 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
}
}
- (void) mouseDragged: (NSEvent*)theEvent
{
if ([(id<IB>)NSApp isTestingInterface] == YES)
{
[super mouseDown: theEvent];
return;
}
}
- (BOOL) acceptsTypeFromArray: (NSArray*)types
{
/*
* A window editor can accept views dropped in to the window.
* A window editor can accept views pasted in to the window.
*/
return [types containsObject: IBViewPboardType];
}
@ -799,22 +818,10 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
*/
- (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.
* FIXME - handle this.
* Notification that a drag failed/succeeded.
*/
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
@ -884,10 +891,10 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
subeditors = [NSMutableArray new];
/*
* Permit views to be dragged in to the window.
* Permit views and connections to be dragged in to the window.
*/
[self registerForDraggedTypes: [NSArray arrayWithObjects:
IBViewPboardType, nil]];
IBViewPboardType, GormLinkPboardType, nil]];
return self;
}
@ -974,43 +981,90 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
{
NSPoint loc = [sender draggedImageLocation];
NSPasteboard *pb = [sender draggingPasteboard];
NSArray *views;
NSEnumerator *enumerator;
NSView *sub;
NSArray *types = [pb types];
/*
* Ask the document to get the dragged views from the pasteboard and add
* them to it's collection of known objects.
*/
views = [document pasteType: IBViewPboardType
fromPasteboard: pb
parent: edited];
/*
* Now make all the views subviews of ourself, setting their origin to be
* the point at which they were dropped (converted from window coordinates
* to our own coordinates).
*/
loc = [self convertPoint: loc fromView: nil];
enumerator = [views objectEnumerator];
while ((sub = [enumerator nextObject]) != nil)
if ([types containsObject: IBViewPboardType] == YES)
{
NSRect rect = [sub frame];
NSPoint loc = [sender draggedImageLocation];
NSArray *views;
NSEnumerator *enumerator;
NSView *sub;
rect.origin = loc;
[sub setFrame: rect];
[self addSubview: sub];
/*
* Ask the document to get the dragged views from the pasteboard and add
* them to it's collection of known objects.
*/
views = [document pasteType: IBViewPboardType
fromPasteboard: pb
parent: edited];
/*
* Now make all the views subviews of ourself, setting their origin to
* be the point at which they were dropped (converted from window
* coordinates to our own coordinates).
*/
loc = [self convertPoint: loc fromView: nil];
enumerator = [views objectEnumerator];
while ((sub = [enumerator nextObject]) != nil)
{
NSRect rect = [sub frame];
rect.origin = loc;
[sub setFrame: rect];
[self addSubview: sub];
}
}
else if ([types containsObject: GormLinkPboardType] == YES)
{
NSPoint loc = [sender draggingLocation];
NSString *name = [pb stringForType: GormLinkPboardType];
NSView *sub = [super hitTest: loc];
NSLog(@"Got link from %@", name);
[(Gorm*)NSApp setConnectDestination: sub];
[self lockFocus];
[[(Gorm*)NSApp targetImage]
compositeToPoint: [sub frame].origin operation: NSCompositeCopy];
[self unlockFocus];
[[self window] flushWindow];
}
else
{
NSLog(@"Drop with unrecognized type!");
return NO;
}
return YES;
}
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
{
NSPasteboard *pb = [sender draggingPasteboard];
NSArray *types = [pb types];
/*
* Tell the source that we will accept the drop.
* Tell the source that we will accept the drop if we can.
*/
return YES;
if ([types containsObject: IBViewPboardType] == YES)
{
/*
* We can accept views dropped anywhere.
*/
return YES;
}
else if ([types containsObject: GormLinkPboardType] == YES)
{
NSPoint loc = [sender draggingLocation];
NSView *sub = [super hitTest: loc];
/*
* We can accept a link dropped on any of our subviews.
*/
if (sub != nil && sub != self)
{
return YES;
}
}
return NO;
}
- (void) resetObject: (id)anObject

Binary file not shown.