git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5576 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-12-18 11:08:18 +00:00
parent e8cbc4a69d
commit 9ffd6f3071
5 changed files with 259 additions and 232 deletions

View file

@ -21,3 +21,19 @@ the selection owner (normally the editor itsself) as the notification owner.
The main application watches for these notifications in order to keep track
of who has the selection.
Connections
===========
The connection API is the same as that for IB, but with the extension that the
document object must implement [-windowAndRect:forObject:] to return the
window in which the object is being displayed, and the rectangle enclosing
the object (in window base coordinates).
This information is neede by Gorm so that it can mark the connection.
The editors mananging the drag-and-drop operation for a connection must call
[NSApp -displayConnectionBetween:and:] to tell Gorm to update its display.
This method sets the values currently returned by
[BSApp -connectSource] and [NSApp -connectDestination]

31
Gorm.h
View file

@ -89,10 +89,36 @@ extern NSString *IBDidEndTestingInterfaceNotification;
@end
@interface NSApplication (IBConnections)
/*
* [NSApp -connectSource] returns the source object as set by the most recent
* [NSApp -displayConnectionBetween:and:]
*/
- (id) connectSource;
/*
* [NSApp -connectDestination] returns the target object as set by the most
* recent [NSApp -displayConnectionBetween:and:]
*/
- (id) connectDestination;
/*
* [NSApp -isConnecting] simply lets you know if a connection is in progress.
*/
- (BOOL) isConnecting;
/*
* [NSApp -stopConnecting] terminates the current connection process and
* removes the connection marks from the display.
*/
- (void) stopConnecting;
/*
* [NSApp -displayConnectionBetween:and:] is used to set the source and target
* objects and mark the display appropriately. Setting either source or
* target to 'nil' will remove markup from any previous source or target.
* NB. This method expects to be able to call the active document to ask it
* for the window adn rectangle in which to perform markup.
*/
- (void) displayConnectionBetween: (id)source and: (id)destination;
@end
@ -168,6 +194,11 @@ extern NSString *IBDidEndTestingInterfaceNotification;
- (void) setName: (NSString*)aName forObject: (id)object;
- (void) setSelectionFromEditor: (id<IBEditors>)anEditor;
- (void) touch; /* Mark document as having been changed. */
/*
* windowAndRect:forObject: is called by Gorm to determine where it should
* draw selection markup
*/
- (NSWindow*) windowAndRect: (NSRect*)r forObject: (id)object;
@end

View file

@ -83,6 +83,17 @@ static NSMapTable *docMap = 0;
}
}
- (BOOL) acceptsTypeFromArray: (NSArray*)types
{
return NO;
}
- (BOOL) activate
{
[window makeKeyAndOrderFront: self];
return YES;
}
- (void) addObject: (id)anObject
{
if (anObject != nil
@ -93,12 +104,150 @@ static NSMapTable *docMap = 0;
}
}
- (id) changeSelection: (id)sender
{
int row = [self selectedRow];
int col = [self selectedColumn];
int index = row * [self numberOfColumns] + col;
id obj = nil;
if (index >= 0 && index < [objects count])
{
obj = [objects objectAtIndex: index];
if (obj != selected)
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
selected = obj;
[nc postNotificationName: IBSelectionChangedNotification
object: self];
}
}
return obj;
}
- (void) close
{
[self closeSubeditors];
}
- (void) closeSubeditors
{
}
- (BOOL) containsObject: (id)object
{
if ([objects indexOfObjectIdenticalTo: object] == NSNotFound)
return NO;
return YES;
}
- (void) copySelection
{
}
- (void) dealloc
{
RELEASE(objects);
[super dealloc];
}
- (void) deleteSelection
{
}
/*
* 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) draggingEntered: (id<NSDraggingInfo>)sender
{
NSArray *types;
dragPb = [sender draggingPasteboard];
types = [dragPb types];
if ([types containsObject: IBObjectPboardType] == YES)
{
dragType = IBObjectPboardType;
}
else if ([types containsObject: GormLinkPboardType] == YES)
{
dragType = GormLinkPboardType;
}
else
{
dragType = nil;
}
return [self draggingUpdated: sender];
}
- (unsigned) draggingUpdated: (id<NSDraggingInfo>)sender
{
if (dragType == IBObjectPboardType)
{
return NSDragOperationCopy;
}
else if (dragType == GormLinkPboardType)
{
NSPoint loc = [sender draggingLocation];
int r, c;
int pos;
id obj = nil;
loc = [self convertPoint: loc fromView: nil];
[self getRow: &r column: &c forPoint: loc];
pos = r * [self numberOfColumns] + c;
if (pos >= 0 && pos < [objects count])
{
obj = [objects objectAtIndex: pos];
}
[NSApp displayConnectionBetween: [NSApp connectSource] and: obj];
return NSDragOperationLink;
}
else
{
return 0;
}
}
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
{
return NSDragOperationLink;
}
- (void) drawSelection
{
}
- (id<IBDocuments>) document
{
return document;
}
- (id) editedObject
{
return selected;
}
/*
* Initialisation - register to receive DnD with our own types.
*/
@ -122,8 +271,7 @@ static NSMapTable *docMap = 0;
document = aDocument;
[self registerForDraggedTypes: [NSArray arrayWithObjects:
IBCellPboardType, IBMenuPboardType, IBMenuCellPboardType,
IBObjectPboardType, IBViewPboardType, IBWindowPboardType, nil]];
IBObjectPboardType, GormLinkPboardType, nil]];
[self setAutosizesCells: NO];
[self setCellSize: NSMakeSize(72,72)];
@ -152,69 +300,20 @@ static NSMapTable *docMap = 0;
return self;
}
/*
* Dragging source protocol implementation
*/
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f
- (void) makeSelectionVisible: (BOOL)flag
{
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)
if (flag == YES && selected != nil)
{
id<IBDocuments> active = [(id<IB>)NSApp activeDocument];
unsigned pos = [objects indexOfObjectIdenticalTo: selected];
int r = pos / [self numberOfColumns];
int c = pos % [self numberOfColumns];
if (active != nil)
{
[active pasteType: type fromPasteboard: dragPb parent: nil];
}
[self selectCellAtRow: r column: c];
}
else
{
[self deselectAllCells];
}
}
- (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
@ -222,81 +321,31 @@ static NSMapTable *docMap = 0;
NSView *view;
mouseDownPoint = [theEvent locationInWindow];
view = [super hitTest: mouseDownPoint];
if (view == self)
{
shouldBeginDrag = NO;
}
else
{
shouldBeginDrag = YES;
}
[super mouseDown: theEvent];
}
- (void) mouseDragged: (NSEvent*)theEvent
- (id<IBEditors>) openSubeditorForObject: (id)anObject
{
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
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
}
return nil;
}
- (id) changeSelection: (id)sender
- (void) orderFront
{
int row = [self selectedRow];
int col = [self selectedColumn];
int index = row * [self numberOfColumns] + col;
id obj = nil;
[window orderFront: self];
}
if (index >= 0 && index < [objects count])
{
obj = [objects objectAtIndex: index];
if (obj != selected)
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
- (void) pasteInSelection
{
}
selected = obj;
[nc postNotificationName: IBSelectionChangedNotification
object: self];
}
}
return obj;
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
{
return YES;
}
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
{
return YES;
}
- (id) raiseSelection: (id)sender
@ -314,6 +363,29 @@ NSLog(@"Could do dragging");
return self;
}
/*
* Return the rectangle in which an objects image will be displayed.
*/
- (NSRect) rectForObject: (id)anObject
{
unsigned pos = [objects indexOfObjectIdenticalTo: anObject];
NSRect rect;
int r;
int c;
if (pos == NSNotFound)
return NSZeroRect;
r = pos / [self numberOfColumns];
c = pos % [self numberOfColumns];
rect = [self cellFrameAtRow: r column: c];
/*
* Adjust to image area.
*/
rect.size.width -= 15;
rect.size.height -= 15;
return rect;
}
- (void) refreshCells
{
unsigned count = [objects count];
@ -377,112 +449,15 @@ NSLog(@"Could do dragging");
[self refreshCells];
}
- (void) resetObject: (id)anObject
{
}
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize
{
[self refreshCells];
}
- (BOOL) acceptsTypeFromArray: (NSArray*)types
{
return NO;
}
- (BOOL) activate
{
[window makeKeyAndOrderFront: self];
return YES;
}
- (void) close
{
[self closeSubeditors];
}
- (void) closeSubeditors
{
}
- (BOOL) containsObject: (id)object
{
if ([objects indexOfObjectIdenticalTo: object] == NSNotFound)
return NO;
return YES;
}
- (void) copySelection
{
}
- (void) deleteSelection
{
}
- (void) drawSelection
{
}
- (id<IBDocuments>) document
{
return document;
}
- (id) editedObject
{
return selected;
}
- (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];
}
}
- (id<IBEditors>) openSubeditorForObject: (id)anObject
{
return nil;
}
- (void) orderFront
{
[window orderFront: self];
}
- (void) pasteInSelection
{
}
/*
* Return the rectangle in which an objects image will be displayed.
*/
- (NSRect) rectForObject: (id)anObject
{
unsigned pos = [objects indexOfObjectIdenticalTo: anObject];
NSRect rect;
int r;
int c;
if (pos == NSNotFound)
return NSZeroRect;
r = pos / [self numberOfColumns];
c = pos % [self numberOfColumns];
rect = [self cellFrameAtRow: r column: c];
return rect;
}
- (void) resetObject: (id)anObject
{
}
- (void) selectObjects: (NSArray*)anArray
{
id obj = [anArray lastObject];
@ -518,6 +493,6 @@ NSLog(@"Could do dragging");
- (NSWindow*) window
{
return [self window];
return [super window];
}
@end

View file

@ -74,8 +74,8 @@ extern NSString *GormLinkPboardType;
id<IBDocuments> document;
id selected;
NSPoint mouseDownPoint;
BOOL shouldBeginDrag;
NSPasteboard *dragPb;
NSString *dragType;
}
- (void) addObject: (id)anObject;
- (void) draggedImage: (NSImage*)i endedAt: (NSPoint)p deposited: (BOOL)f;

View file

@ -142,7 +142,7 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
NSView *original;
NSMutableArray *selection;
NSMutableArray *subeditors;
BOOL shouldBeginDrag;
BOOL isLinkSource;
BOOL isClosed;
NSPasteboard *dragPb;
NSString *dragType;
@ -344,6 +344,7 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
[pb setString: name forType: GormLinkPboardType];
[NSApp displayConnectionBetween: view and: nil];
isLinkSource = YES;
[self dragImage: [NSApp linkImage]
at: dragPoint
offset: NSZeroSize
@ -351,6 +352,7 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
pasteboard: pb
source: self
slideBack: YES];
isLinkSource = NO;
[self makeSelectionVisible: YES];
return;
}
@ -818,7 +820,10 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)flag
{
return NSDragOperationCopy;
if (isLinkSource == YES)
return NSDragOperationLink;
else
return NSDragOperationCopy;
}
- (unsigned) draggingEntered: (id<NSDraggingInfo>)sender