mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-24 03:51:22 +00:00
Tidied connection handling code.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5575 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e76017e72f
commit
e8cbc4a69d
6 changed files with 150 additions and 151 deletions
1
Gorm.h
1
Gorm.h
|
@ -168,6 +168,7 @@ extern NSString *IBDidEndTestingInterfaceNotification;
|
|||
- (void) setName: (NSString*)aName forObject: (id)object;
|
||||
- (void) setSelectionFromEditor: (id<IBEditors>)anEditor;
|
||||
- (void) touch; /* Mark document as having been changed. */
|
||||
- (NSWindow*) windowAndRect: (NSRect*)r forObject: (id)object;
|
||||
@end
|
||||
|
||||
@protocol IB <NSObject>
|
||||
|
|
180
Gorm.m
180
Gorm.m
|
@ -136,6 +136,89 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
|
|||
|
||||
- (void) displayConnectionBetween: (id)source and: (id)destination
|
||||
{
|
||||
NSWindow *w;
|
||||
NSRect r;
|
||||
|
||||
if (source != connectSource)
|
||||
{
|
||||
if (connectSource != nil)
|
||||
{
|
||||
w = [activeDocument windowAndRect: &r forObject: connectSource];
|
||||
if (w != nil)
|
||||
{
|
||||
NSView *wv = [[w contentView] superview];
|
||||
|
||||
/*
|
||||
* Erase image from old location.
|
||||
*/
|
||||
r.origin.x -= 1.0;
|
||||
r.origin.y += 1.0;
|
||||
r.size = [sourceImage size];
|
||||
r.size.width += 2.0;
|
||||
r.size.height += 2.0;
|
||||
|
||||
[wv lockFocus];
|
||||
[wv displayRect: r];
|
||||
[wv unlockFocus];
|
||||
[w flushWindow];
|
||||
}
|
||||
}
|
||||
connectSource = source;
|
||||
if (connectSource != nil)
|
||||
{
|
||||
w = [activeDocument windowAndRect: &r forObject: connectSource];
|
||||
if (w != nil)
|
||||
{
|
||||
NSView *wv = [[w contentView] superview];
|
||||
|
||||
[wv lockFocus];
|
||||
[sourceImage compositeToPoint: r.origin
|
||||
operation: NSCompositeCopy];
|
||||
[wv unlockFocus];
|
||||
[w flushWindow];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (destination != connectDestination)
|
||||
{
|
||||
if (connectDestination != nil)
|
||||
{
|
||||
w = [activeDocument windowAndRect: &r forObject: connectDestination];
|
||||
if (w != nil)
|
||||
{
|
||||
NSView *wv = [[w contentView] superview];
|
||||
|
||||
/*
|
||||
* Erase image from old location.
|
||||
*/
|
||||
r.origin.x -= 1.0;
|
||||
r.origin.y += 1.0;
|
||||
r.size = [targetImage size];
|
||||
r.size.width += 2.0;
|
||||
r.size.height += 2.0;
|
||||
|
||||
[wv lockFocus];
|
||||
[wv displayRect: r];
|
||||
[wv unlockFocus];
|
||||
[w flushWindow];
|
||||
}
|
||||
}
|
||||
connectDestination = destination;
|
||||
if (connectDestination != nil)
|
||||
{
|
||||
w = [activeDocument windowAndRect: &r forObject: connectDestination];
|
||||
if (w != nil)
|
||||
{
|
||||
NSView *wv = [[w contentView] superview];
|
||||
|
||||
[wv lockFocus];
|
||||
[targetImage compositeToPoint: r.origin
|
||||
operation: NSCompositeCopy];
|
||||
[wv unlockFocus];
|
||||
[w flushWindow];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (id) endTesting: (id)sender
|
||||
|
@ -371,98 +454,6 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
|
|||
return [[selectionOwner selection] lastObject];
|
||||
}
|
||||
|
||||
- (void) setConnectDestination: (id)o window: (NSWindow*)w rect: (NSRect)r
|
||||
{
|
||||
if (connectSource != nil && o == connectSource)
|
||||
{
|
||||
return; /* Can't link to self */
|
||||
}
|
||||
|
||||
if (connectDestination != o)
|
||||
{
|
||||
connectDestination = o;
|
||||
|
||||
if (connectDWindow != nil)
|
||||
{
|
||||
NSView *wv = [[connectDWindow contentView] superview];
|
||||
NSRect rect = connectDRect;
|
||||
|
||||
/*
|
||||
* Erase image from old location.
|
||||
*/
|
||||
rect.origin.x -= 1.0;
|
||||
rect.origin.y += 1.0;
|
||||
rect.size = [targetImage size];
|
||||
rect.size.width += 2.0;
|
||||
rect.size.height += 2.0;
|
||||
|
||||
[wv lockFocus];
|
||||
[wv displayRect: rect];
|
||||
[wv unlockFocus];
|
||||
[connectDWindow flushWindow];
|
||||
}
|
||||
connectDWindow = w;
|
||||
connectDRect = r;
|
||||
if (connectDWindow != nil)
|
||||
{
|
||||
NSView *wv = [[connectDWindow contentView] superview];
|
||||
NSRect rect = connectDRect;
|
||||
|
||||
[wv lockFocus];
|
||||
[targetImage compositeToPoint: rect.origin
|
||||
operation: NSCompositeCopy];
|
||||
[wv unlockFocus];
|
||||
[connectDWindow flushWindow];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setConnectSource: (id)o window: (NSWindow*)w rect: (NSRect)r
|
||||
{
|
||||
if (connectDestination != nil && o == connectDestination)
|
||||
{
|
||||
return; /* Can't link to self */
|
||||
}
|
||||
|
||||
if (connectSource != o)
|
||||
{
|
||||
connectSource = o;
|
||||
|
||||
if (connectSWindow != nil)
|
||||
{
|
||||
NSView *wv = [[connectSWindow contentView] superview];
|
||||
NSRect rect = connectSRect;
|
||||
|
||||
/*
|
||||
* Erase image from old location.
|
||||
*/
|
||||
rect.origin.x -= 1.0;
|
||||
rect.origin.y += 1.0;
|
||||
rect.size = [sourceImage size];
|
||||
rect.size.width += 2.0;
|
||||
rect.size.height += 2.0;
|
||||
|
||||
[wv lockFocus];
|
||||
[wv displayRect: rect];
|
||||
[wv unlockFocus];
|
||||
[connectSWindow flushWindow];
|
||||
}
|
||||
connectSWindow = w;
|
||||
connectSRect = r;
|
||||
if (connectSWindow != nil)
|
||||
{
|
||||
NSView *wv = [[connectSWindow contentView] superview];
|
||||
NSRect rect = connectSRect;
|
||||
|
||||
[wv lockFocus];
|
||||
[sourceImage compositeToPoint: rect.origin
|
||||
operation: NSCompositeCopy];
|
||||
[wv unlockFocus];
|
||||
[connectSWindow flushWindow];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (id) setName: (id)sender
|
||||
{
|
||||
/* FIXME */
|
||||
|
@ -473,7 +464,7 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
|
|||
{
|
||||
if (isConnecting == YES)
|
||||
{
|
||||
[self stopConnecting];
|
||||
return;
|
||||
}
|
||||
if (connectDestination == nil || connectSource == nil)
|
||||
{
|
||||
|
@ -495,8 +486,7 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
|
|||
|
||||
- (void) stopConnecting
|
||||
{
|
||||
[self setConnectDestination: nil window: nil rect: NSZeroRect];
|
||||
[self setConnectSource: nil window: nil rect: NSZeroRect];
|
||||
[self displayConnectionBetween: nil and: nil];
|
||||
isConnecting = NO;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,6 @@ NSString *IBWillSaveDocumentNotification = @"IBWillSaveDocumentNotification";
|
|||
NSString *IBDidSaveDocumentNotification = @"IBDidSaveDocumentNotification";
|
||||
NSString *IBWillCloseDocumentNotification = @"IBWillCloseDocumentNotification";
|
||||
|
||||
@class GormObjectEditor;
|
||||
|
||||
/*
|
||||
* Each document has a GormFilesOwner object that is used as a placeholder
|
||||
* for the owner of the document.
|
||||
|
@ -1222,6 +1220,31 @@ static NSImage *classesImage = nil;
|
|||
[window setDocumentEdited: YES];
|
||||
}
|
||||
|
||||
- (NSWindow*) windowAndRect: (NSRect*)r forObject: (id)object
|
||||
{
|
||||
if ([objectsView containsObject: object] == YES)
|
||||
{
|
||||
NSRect rect = [objectsView rectForObject: object];
|
||||
|
||||
rect = [objectsView convertRect: rect toView: nil];
|
||||
*r = rect;
|
||||
return [objectsView window];
|
||||
}
|
||||
else if ([object isKindOfClass: [NSView class]] == YES)
|
||||
{
|
||||
NSRect rect = [object bounds];
|
||||
|
||||
rect = [object convertRect: rect toView: nil];
|
||||
*r = rect;
|
||||
return [object window];
|
||||
}
|
||||
else
|
||||
{
|
||||
*r = NSZeroRect;
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) windowShouldClose
|
||||
{
|
||||
if ([window isDocumentEdited] == YES)
|
||||
|
|
|
@ -70,40 +70,6 @@
|
|||
|
||||
|
||||
|
||||
@interface GormObjectEditor : NSMatrix <IBEditors>
|
||||
{
|
||||
NSMutableArray *objects;
|
||||
id<IBDocuments> document;
|
||||
id selected;
|
||||
NSPoint mouseDownPoint;
|
||||
BOOL shouldBeginDrag;
|
||||
NSPasteboard *dragPb;
|
||||
}
|
||||
- (void) addObject: (id)anObject;
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f;
|
||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag;
|
||||
- (void) refreshCells;
|
||||
- (void) removeObject: (id)anObject;
|
||||
- (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 GormObjectEditor
|
||||
|
||||
static NSMapTable *docMap = 0;
|
||||
|
|
|
@ -15,8 +15,6 @@ extern NSString *GormLinkPboardType;
|
|||
|
||||
@interface NSApplication (Gorm)
|
||||
- (NSImage*) linkImage;
|
||||
- (void) setConnectDestination: (id)o window: (NSWindow*)w rect: (NSRect)r;
|
||||
- (void) setConnectSource: (id)o window: (NSWindow*)w rect: (NSRect)r;
|
||||
- (void) startConnecting;
|
||||
@end
|
||||
|
||||
|
@ -70,6 +68,42 @@ extern NSString *GormLinkPboardType;
|
|||
- (id) testInterface: (id)sender;
|
||||
@end
|
||||
|
||||
@interface GormObjectEditor : NSMatrix <IBEditors>
|
||||
{
|
||||
NSMutableArray *objects;
|
||||
id<IBDocuments> document;
|
||||
id selected;
|
||||
NSPoint mouseDownPoint;
|
||||
BOOL shouldBeginDrag;
|
||||
NSPasteboard *dragPb;
|
||||
}
|
||||
- (void) addObject: (id)anObject;
|
||||
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f;
|
||||
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag;
|
||||
- (void) refreshCells;
|
||||
- (void) removeObject: (id)anObject;
|
||||
- (BOOL) acceptsTypeFromArray: (NSArray*)types;
|
||||
- (BOOL) activate;
|
||||
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument;
|
||||
- (void) close;
|
||||
- (void) closeSubeditors;
|
||||
- (BOOL) containsObject: (id)anObject;
|
||||
- (void) copySelection;
|
||||
- (void) deleteSelection;
|
||||
- (id<IBDocuments>) document;
|
||||
- (id) editedObject;
|
||||
- (void) makeSelectionVisible: (BOOL)flag;
|
||||
- (id<IBEditors>) openSubeditorForObject: (id)anObject;
|
||||
- (void) orderFront;
|
||||
- (void) pasteInSelection;
|
||||
- (NSRect) rectForObject: (id)anObject;
|
||||
- (void) resetObject: (id)anObject;
|
||||
- (void) selectObjects: (NSArray*)objects;
|
||||
- (void) validateEditing;
|
||||
- (BOOL) wantsSelection;
|
||||
- (NSWindow*) window;
|
||||
@end
|
||||
|
||||
/*
|
||||
* Functions for drawing knobs etc.
|
||||
*/
|
||||
|
|
|
@ -337,15 +337,12 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
|
|||
NSPoint dragPoint = [theEvent locationInWindow];
|
||||
NSPasteboard *pb;
|
||||
NSString *name = [document nameForObject: view];
|
||||
NSRect r = [view bounds];
|
||||
|
||||
pb = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
[pb declareTypes: [NSArray arrayWithObject: GormLinkPboardType]
|
||||
owner: self];
|
||||
[pb setString: name forType: GormLinkPboardType];
|
||||
[NSApp setConnectSource: view
|
||||
window: [view window]
|
||||
rect: [view convertRect: r toView: nil]];
|
||||
[NSApp displayConnectionBetween: view and: nil];
|
||||
|
||||
[self dragImage: [NSApp linkImage]
|
||||
at: dragPoint
|
||||
|
@ -855,25 +852,16 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
|
|||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
NSView *sub = [super hitTest: loc];
|
||||
NSRect r;
|
||||
|
||||
if (sub == self)
|
||||
{
|
||||
sub = nil;
|
||||
r = NSZeroRect;
|
||||
}
|
||||
else if (sub == [NSApp connectSource])
|
||||
{
|
||||
sub = nil;
|
||||
r = NSZeroRect;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = [sub convertRect: [sub bounds] toView: nil];
|
||||
}
|
||||
[NSApp setConnectDestination: sub
|
||||
window: [sub window]
|
||||
rect: r];
|
||||
[NSApp displayConnectionBetween: [NSApp connectSource] and: sub];
|
||||
return NSDragOperationLink;
|
||||
}
|
||||
else
|
||||
|
@ -1061,12 +1049,9 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
|
|||
NSPoint loc = [sender draggingLocation];
|
||||
NSString *name = [dragPb stringForType: GormLinkPboardType];
|
||||
NSView *sub = [super hitTest: loc];
|
||||
NSRect r = [sub convertRect: [sub bounds] toView: nil];
|
||||
|
||||
NSLog(@"Got link from %@", name);
|
||||
[NSApp setConnectDestination: sub
|
||||
window: [sub window]
|
||||
rect: r];
|
||||
[NSApp displayConnectionBetween: [NSApp connectSource] and: sub];
|
||||
[NSApp startConnecting];
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue