Code to allow addition of sounds/images to cells in an NSMatrix.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@20191 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2004-10-03 16:48:24 +00:00
parent 835917baf5
commit 78f716b8b8
5 changed files with 91 additions and 38 deletions

View file

@ -1,3 +1,14 @@
2004-10-03 12:51 Gregory John Casamento <greg_casamento@yahoo.com>
* GormMatrixEditor.m: Added performDragOperation implementation
to allow the drag and drop of sound/images to a matrix cell.
* GormPrivate.h: Moved a category which defines a method called
on setArchiveByName to this header so it's useful to more than
just the editors.
* GormViewEditor.m: Removed category declaration.
* Palettes/2Controls/GormButtonEditor.m: Removed some old,
commented out code.
2004-10-02 13:08 Gregory John Casamento <greg_casamento@yahoo.com>
* Resources/GormDocument.gorm: Changed the spacing of the

View file

@ -24,6 +24,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <AppKit/AppKit.h>
#include "GormPrivate.h"
#include "GormViewEditor.h"
#include "GormMatrixEditor.h"
@ -105,6 +107,8 @@ static BOOL done_editing;
*/
- (id) initWithObject: (id)anObject inDocument: (id<IBDocuments>)aDocument
{
NSMutableArray *draggedTypes = [NSMutableArray array];
opened = NO;
selected = nil;
selectedCol = -1;
@ -112,6 +116,15 @@ static BOOL done_editing;
_displaySelection = YES;
self = [super initWithObject: anObject
inDocument: aDocument];
// dragged types...
[draggedTypes addObject: GormImagePboardType];
[draggedTypes addObject: GormLinkPboardType];
[draggedTypes addObject: GormSoundPboardType];
// register...
[self registerForDraggedTypes: draggedTypes];
return self;
}
@ -381,9 +394,7 @@ static BOOL done_editing;
- (BOOL) acceptsTypeFromArray: (NSArray*)types
{
if ([types containsObject: IBObjectPboardType] == YES)
return YES;
return NO;
return ([types containsObject: IBObjectPboardType] || [types containsObject: GormImagePboardType]);
}
- (void) postDraw: (NSRect) rect
@ -669,6 +680,58 @@ static BOOL done_editing;
return;
}
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
{
NSPasteboard *dragPb;
NSArray *types;
NSPoint dropPoint = [sender draggedImageLocation];
NSPoint mouseDownPoint =
[_EO convertPoint: dropPoint fromView: nil];
dragPb = [sender draggingPasteboard];
types = [dragPb types];
if ([types containsObject: GormLinkPboardType])
{
[NSApp displayConnectionBetween: [NSApp connectSource]
and: _EO];
[NSApp startConnecting];
}
else if([types containsObject: GormImagePboardType] == YES ||
[types containsObject: GormSoundPboardType] == YES)
{
int row, col;
if([_EO getRow: &row column: &col forPoint: mouseDownPoint] == YES)
{
id object = [_EO cellAtRow: row column: col];
if ([types containsObject: GormImagePboardType] == YES)
{
NSString *name = [dragPb stringForType: GormImagePboardType];
NSImage *image = [NSImage imageNamed: name];
[image setArchiveByName: NO];
if([object respondsToSelector: @selector(setSound:)])
{
[object setImage: image];
}
return YES;
}
else if([types containsObject: GormSoundPboardType] == YES)
{
NSString *name;
name = [dragPb stringForType: GormSoundPboardType];
if([object respondsToSelector: @selector(setSound:)])
{
[object setSound: [NSSound soundNamed: name]];
}
return YES;
}
}
}
return NO;
}
@end

View file

@ -351,6 +351,12 @@ extern NSString *GormResizeCellNotification;
- (void) addImage: (NSString*) path;
@end
// to allow us to load the image by name, but save it within the archive.
// this is a bit of a cheat.
@interface NSImage (GormNSImageAddition)
- (void) setArchiveByName: (BOOL) archiveByName;
@end
/*
* Functions for drawing knobs etc.
*/

View file

@ -35,6 +35,13 @@
#include <math.h>
#include <stdlib.h>
@implementation NSImage (GormNSImageAddition)
- (void) setArchiveByName: (BOOL) archiveByName
{
_flags.archiveByName = archiveByName;
}
@end
@implementation GormPlacementInfo
@end
@ -114,19 +121,6 @@
}
@end
// to allow us to load the image by name, but save it within the archive.
// this is a bit of a cheat.
@interface NSImage (GormAddition)
- (void) setArchiveByName: (BOOL) archiveByName;
@end
@implementation NSImage (GormAddition)
- (void) setArchiveByName: (BOOL) archiveByName
{
_flags.archiveByName = archiveByName;
}
@end
static BOOL currently_displaying = NO;

View file

@ -85,18 +85,6 @@
if (backgroundColor == nil)
backgroundColor = [NSColor controlBackgroundColor];
/* Draw the cell's background color.
We draw when there is a border or when highlightsByMask
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
as required by our nextstep-like look and feel. */
if (_cell.is_bordered
|| (_highlightsByMask & NSChangeBackgroundCellMask)
|| (_highlightsByMask & NSChangeGrayCellMask))
{
// [backgroundColor set];
// NSRectFill (cellFrame);
}
/*
* Determine the image and the title that will be
* displayed. If the NSContentsCellMask is set the
@ -121,19 +109,10 @@
if (imageToDisplay)
{
/* FIXME - the following is a hack! Because we don't seem to be
getting alpha composing of images right, we use this hack of
hard-setting manually the background color of the image to
the wanted background color ... this should go away when
alpha composing of images works 100%. */
// [imageToDisplay setBackgroundColor: backgroundColor];
imageSize = [imageToDisplay size];
}
// if (titleToDisplay && (ipos == NSImageAbove || ipos == NSImageBelow))
// {
titleSize = [self _sizeText: titleToDisplay];
// }
titleSize = [self _sizeText: titleToDisplay];
if (flippedView == YES)
{