mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-24 03:51:22 +00:00
* GormCore/GormBoxEditor.m
* GormCore/GormInternalViewEditor.m * GormCore/GormViewWithSubviewsEditor.m: Changes to support standalone views. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@27751 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4ff4b72168
commit
e2c3acfe5d
4 changed files with 279 additions and 264 deletions
|
@ -1,3 +1,10 @@
|
|||
2009-02-01 09:20-EST Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* GormCore/GormBoxEditor.m
|
||||
* GormCore/GormInternalViewEditor.m
|
||||
* GormCore/GormViewWithSubviewsEditor.m: Changes to support
|
||||
standalone views.
|
||||
|
||||
2009-01-31 18:45-EST Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* GormCore/GormCustomView.m: Allow addition of plain NSView to
|
||||
|
|
|
@ -98,24 +98,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (id) initWithObject: (id)anObject
|
||||
inDocument: (id<IBDocuments>)aDocument
|
||||
{
|
||||
opened = NO;
|
||||
openedSubeditor = nil;
|
||||
|
||||
if ((self = [super initWithObject: anObject
|
||||
inDocument: aDocument]) == nil)
|
||||
return nil;
|
||||
|
||||
selection = [[NSMutableArray alloc] initWithCapacity: 5];
|
||||
|
||||
[self registerForDraggedTypes: [NSArray arrayWithObjects:
|
||||
IBViewPboardType, GormLinkPboardType, IBFormatterPboardType, nil]];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) makeSelectionVisible: (BOOL) value
|
||||
{
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ static NSImage *horizontalImage;
|
|||
}
|
||||
else
|
||||
{
|
||||
return @"GormViewEditor";
|
||||
return @"GormViewWithSubviewsEditor";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,8 +139,6 @@ static NSImage *horizontalImage;
|
|||
}
|
||||
else if ([[superview window] contentView] == _editedObject)
|
||||
{
|
||||
// NSRect frame = [_editedObject frame];
|
||||
// [self setFrame: frame];
|
||||
[[superview window] setContentView: self];
|
||||
}
|
||||
else if ([superview isKindOfClass: [NSClipView class]])
|
||||
|
@ -651,249 +649,6 @@ static NSImage *horizontalImage;
|
|||
|
||||
|
||||
|
||||
- (unsigned) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSRect rect = [_editedObject bounds];
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
loc = [_editedObject convertPoint: loc fromView: nil];
|
||||
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
return [parent draggingEntered: sender];
|
||||
}
|
||||
|
||||
if (NSMouseInRect(loc, [_editedObject bounds], NO) == NO)
|
||||
{
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.origin.x += 3;
|
||||
rect.origin.y += 2;
|
||||
rect.size.width -= 5;
|
||||
rect.size.height -= 5;
|
||||
|
||||
[_editedObject lockFocus];
|
||||
|
||||
[[NSColor darkGrayColor] set];
|
||||
NSFrameRectWithWidth(rect, 2);
|
||||
|
||||
[_editedObject unlockFocus];
|
||||
[[self window] flushWindow];
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) draggingExited: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
NSRect rect;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
[parent draggingExited: sender];
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
rect = [_editedObject bounds];
|
||||
rect.origin.x += 3;
|
||||
rect.origin.y += 2;
|
||||
rect.size.width -= 5;
|
||||
rect.size.height -= 5;
|
||||
|
||||
rect.origin.x --;
|
||||
rect.size.width ++;
|
||||
rect.size.height ++;
|
||||
|
||||
[[self window] disableFlushWindow];
|
||||
[self displayRect:
|
||||
[_editedObject convertRect: rect
|
||||
toView: self]];
|
||||
[[self window] enableFlushWindow];
|
||||
[[self window] flushWindow];
|
||||
}
|
||||
|
||||
- (unsigned int) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
NSRect rect = [_editedObject bounds];
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
loc = [_editedObject
|
||||
convertPoint: loc fromView: nil];
|
||||
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
return [parent draggingUpdated: sender];
|
||||
}
|
||||
|
||||
rect.origin.x += 3;
|
||||
rect.origin.y += 2;
|
||||
rect.size.width -= 5;
|
||||
rect.size.height -= 5;
|
||||
|
||||
if (NSMouseInRect(loc, [_editedObject bounds], NO) == NO)
|
||||
{
|
||||
[[self window] disableFlushWindow];
|
||||
rect.origin.x --;
|
||||
rect.size.width ++;
|
||||
rect.size.height ++;
|
||||
[self displayRect:
|
||||
[_editedObject convertRect: rect
|
||||
toView: self]];
|
||||
[[self window] enableFlushWindow];
|
||||
[[self window] flushWindow];
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
else
|
||||
{
|
||||
[_editedObject lockFocus];
|
||||
|
||||
[[NSColor darkGrayColor] set];
|
||||
NSFrameRectWithWidth(rect, 2);
|
||||
|
||||
[_editedObject unlockFocus];
|
||||
[[self window] flushWindow];
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSString *dragType;
|
||||
NSArray *types;
|
||||
NSPasteboard *dragPb;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
|
||||
types = [dragPb types];
|
||||
|
||||
if ([types containsObject: IBViewPboardType] == YES)
|
||||
{
|
||||
dragType = IBViewPboardType;
|
||||
}
|
||||
else if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
dragType = GormLinkPboardType;
|
||||
return [parent prepareForDragOperation: sender];
|
||||
}
|
||||
else
|
||||
{
|
||||
dragType = nil;
|
||||
}
|
||||
|
||||
if (dragType == IBViewPboardType)
|
||||
{
|
||||
/*
|
||||
* We can accept views dropped anywhere.
|
||||
*/
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
loc = [_editedObject
|
||||
convertPoint: loc fromView: nil];
|
||||
if (NSMouseInRect(loc, [_editedObject bounds], NO) == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSString *dragType;
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
|
||||
types = [dragPb types];
|
||||
|
||||
if ([types containsObject: IBViewPboardType] == YES)
|
||||
{
|
||||
dragType = IBViewPboardType;
|
||||
}
|
||||
else if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
dragType = GormLinkPboardType;
|
||||
}
|
||||
else
|
||||
{
|
||||
dragType = nil;
|
||||
}
|
||||
|
||||
if (dragType == IBViewPboardType)
|
||||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
NSArray *views;
|
||||
NSEnumerator *enumerator;
|
||||
NSView *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: dragPb
|
||||
parent: _editedObject];
|
||||
/*
|
||||
* 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 = [_editedObject convertPoint: loc fromView: nil];
|
||||
if (NSMouseInRect(loc, [_editedObject bounds], NO) == NO)
|
||||
{
|
||||
// Dropped outside our view frame
|
||||
NSLog(@"Dropped outside current edit view");
|
||||
dragType = nil;
|
||||
return NO;
|
||||
}
|
||||
enumerator = [views objectEnumerator];
|
||||
while ((sub = [enumerator nextObject]) != nil)
|
||||
{
|
||||
NSRect rect = [sub frame];
|
||||
|
||||
rect.origin = [_editedObject
|
||||
convertPoint: [sender draggedImageLocation]
|
||||
fromView: nil];
|
||||
rect.origin.x = (int) rect.origin.x;
|
||||
rect.origin.y = (int) rect.origin.y;
|
||||
rect.size.width = (int) rect.size.width;
|
||||
rect.size.height = (int) rect.size.height;
|
||||
[sub setFrame: rect];
|
||||
|
||||
[_editedObject addSubview: sub];
|
||||
|
||||
{
|
||||
id editor;
|
||||
editor = [document editorForObject: sub
|
||||
inEditor: self
|
||||
create: YES];
|
||||
[self selectObjects:
|
||||
[NSArray arrayWithObject: editor]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) pasteInSelection
|
||||
{
|
||||
|
|
|
@ -30,8 +30,35 @@
|
|||
|
||||
@class GormEditorToParent;
|
||||
|
||||
/*
|
||||
@implementation NSView (IBObjectAdditions)
|
||||
- (NSString*) editorClassName
|
||||
{
|
||||
return @"GormViewWithSubviewsEditor";
|
||||
}
|
||||
@end
|
||||
*/
|
||||
|
||||
@implementation GormViewWithSubviewsEditor
|
||||
|
||||
- (id) initWithObject: (id)anObject
|
||||
inDocument: (id<IBDocuments>)aDocument
|
||||
{
|
||||
opened = NO;
|
||||
openedSubeditor = nil;
|
||||
|
||||
if ((self = [super initWithObject: anObject
|
||||
inDocument: aDocument]) == nil)
|
||||
return nil;
|
||||
|
||||
selection = [[NSMutableArray alloc] initWithCapacity: 5];
|
||||
|
||||
[self registerForDraggedTypes: [NSArray arrayWithObjects:
|
||||
IBViewPboardType, GormLinkPboardType, IBFormatterPboardType, nil]];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) close
|
||||
{
|
||||
if (closed == NO)
|
||||
|
@ -268,4 +295,248 @@
|
|||
{
|
||||
return [selection count];
|
||||
}
|
||||
|
||||
- (unsigned) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSRect rect = [_editedObject bounds];
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
loc = [_editedObject convertPoint: loc fromView: nil];
|
||||
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
return [parent draggingEntered: sender];
|
||||
}
|
||||
|
||||
if (NSMouseInRect(loc, [_editedObject bounds], NO) == NO)
|
||||
{
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.origin.x += 3;
|
||||
rect.origin.y += 2;
|
||||
rect.size.width -= 5;
|
||||
rect.size.height -= 5;
|
||||
|
||||
[_editedObject lockFocus];
|
||||
|
||||
[[NSColor darkGrayColor] set];
|
||||
NSFrameRectWithWidth(rect, 2);
|
||||
|
||||
[_editedObject unlockFocus];
|
||||
[[self window] flushWindow];
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) draggingExited: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
NSRect rect;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
[parent draggingExited: sender];
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
rect = [_editedObject bounds];
|
||||
rect.origin.x += 3;
|
||||
rect.origin.y += 2;
|
||||
rect.size.width -= 5;
|
||||
rect.size.height -= 5;
|
||||
|
||||
rect.origin.x --;
|
||||
rect.size.width ++;
|
||||
rect.size.height ++;
|
||||
|
||||
[[self window] disableFlushWindow];
|
||||
[self displayRect:
|
||||
[_editedObject convertRect: rect
|
||||
toView: self]];
|
||||
[[self window] enableFlushWindow];
|
||||
[[self window] flushWindow];
|
||||
}
|
||||
|
||||
- (unsigned int) draggingUpdated: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
NSRect rect = [_editedObject bounds];
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
loc = [_editedObject
|
||||
convertPoint: loc fromView: nil];
|
||||
|
||||
if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
return [parent draggingUpdated: sender];
|
||||
}
|
||||
|
||||
rect.origin.x += 3;
|
||||
rect.origin.y += 2;
|
||||
rect.size.width -= 5;
|
||||
rect.size.height -= 5;
|
||||
|
||||
if (NSMouseInRect(loc, [_editedObject bounds], NO) == NO)
|
||||
{
|
||||
[[self window] disableFlushWindow];
|
||||
rect.origin.x --;
|
||||
rect.size.width ++;
|
||||
rect.size.height ++;
|
||||
[self displayRect:
|
||||
[_editedObject convertRect: rect
|
||||
toView: self]];
|
||||
[[self window] enableFlushWindow];
|
||||
[[self window] flushWindow];
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
else
|
||||
{
|
||||
[_editedObject lockFocus];
|
||||
|
||||
[[NSColor darkGrayColor] set];
|
||||
NSFrameRectWithWidth(rect, 2);
|
||||
|
||||
[_editedObject unlockFocus];
|
||||
[[self window] flushWindow];
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) prepareForDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSString *dragType;
|
||||
NSArray *types;
|
||||
NSPasteboard *dragPb;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
|
||||
types = [dragPb types];
|
||||
|
||||
if ([types containsObject: IBViewPboardType] == YES)
|
||||
{
|
||||
dragType = IBViewPboardType;
|
||||
}
|
||||
else if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
dragType = GormLinkPboardType;
|
||||
return [parent prepareForDragOperation: sender];
|
||||
}
|
||||
else
|
||||
{
|
||||
dragType = nil;
|
||||
}
|
||||
|
||||
if (dragType == IBViewPboardType)
|
||||
{
|
||||
/*
|
||||
* We can accept views dropped anywhere.
|
||||
*/
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
loc = [_editedObject
|
||||
convertPoint: loc fromView: nil];
|
||||
if (NSMouseInRect(loc, [_editedObject bounds], NO) == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSString *dragType;
|
||||
NSPasteboard *dragPb;
|
||||
NSArray *types;
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
|
||||
types = [dragPb types];
|
||||
|
||||
if ([types containsObject: IBViewPboardType] == YES)
|
||||
{
|
||||
dragType = IBViewPboardType;
|
||||
}
|
||||
else if ([types containsObject: GormLinkPboardType] == YES)
|
||||
{
|
||||
dragType = GormLinkPboardType;
|
||||
}
|
||||
else
|
||||
{
|
||||
dragType = nil;
|
||||
}
|
||||
|
||||
if (dragType == IBViewPboardType)
|
||||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
NSArray *views;
|
||||
NSEnumerator *enumerator;
|
||||
NSView *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: dragPb
|
||||
parent: _editedObject];
|
||||
/*
|
||||
* 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 = [_editedObject convertPoint: loc fromView: nil];
|
||||
if (NSMouseInRect(loc, [_editedObject bounds], NO) == NO)
|
||||
{
|
||||
// Dropped outside our view frame
|
||||
NSLog(@"Dropped outside current edit view");
|
||||
dragType = nil;
|
||||
return NO;
|
||||
}
|
||||
enumerator = [views objectEnumerator];
|
||||
while ((sub = [enumerator nextObject]) != nil)
|
||||
{
|
||||
NSRect rect = [sub frame];
|
||||
|
||||
rect.origin = [_editedObject
|
||||
convertPoint: [sender draggedImageLocation]
|
||||
fromView: nil];
|
||||
rect.origin.x = (int) rect.origin.x;
|
||||
rect.origin.y = (int) rect.origin.y;
|
||||
rect.size.width = (int) rect.size.width;
|
||||
rect.size.height = (int) rect.size.height;
|
||||
[sub setFrame: rect];
|
||||
|
||||
[_editedObject addSubview: sub];
|
||||
|
||||
{
|
||||
id editor;
|
||||
editor = [document editorForObject: sub
|
||||
inEditor: self
|
||||
create: YES];
|
||||
[self selectObjects:
|
||||
[NSArray arrayWithObject: editor]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue