2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSImageView</title>
|
1998-01-09 22:28:14 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
|
|
|
Date: January 1998
|
1999-06-05 20:30:29 +00:00
|
|
|
Updated by: Jonathan Gapen <jagapen@smithlab.chem.wisc.edu>
|
|
|
|
Date: May 1999
|
1998-01-09 22:28:14 +00:00
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
2005-05-26 02:52:46 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
1998-01-09 22:28:14 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSDragging.h"
|
|
|
|
#include "AppKit/NSEvent.h"
|
|
|
|
#include "AppKit/NSImage.h"
|
|
|
|
#include "AppKit/NSImageCell.h"
|
|
|
|
#include "AppKit/NSImageView.h"
|
|
|
|
#include "AppKit/NSPasteboard.h"
|
2005-01-21 21:43 Alexander Malmberg <alexander@malmberg.org>
Various whitespace cleanups, comment type fixes, and changes
to avoid warnings from recent versions of gcc.
* Headers/Additions/GNUstepGUI/GSToolbar.h (-_toolbars): Declare.
* Source/NSWindow+Toolbar.m: Remove conflicting declaration of
[NSToolbar -_toolbars].
* Headers/Additions/GNUstepGUI/GSServicesManager.h,
Source/GSServicesMananger.m (-item2title:, -validateMenuItem:):
Adjust argument types.
* Headers/AppKit/NSMenu.h (-validateMenuItem:): Adjust argument
type.
* Source/NSTextView.m (-sizeToFit): Don't use size uninitialized
if neither resizable flags is set.
(-insertText:): Adjust argument type.
* Headers/AppKit/NSResponder.h, Source/NSResponder.m (-insertText:):
Adjust argument type. Document.
* Headers/AppKit/NSView.h: Change type of ivar _window to NSWindow *.
* Source/GSTitleView.m (-mouseDown:): Always initialize
startWindowOrigin.
* Source/NSApplication.m (-setApplicationIconImage:): Add casts
to avoid warnings.
* Source/NSCell.m (-cellSize): Add default: case.
* Source/NSPasteboard.m
([GSFiltered -pasteboard:provideDataForType:]): Detect and warn if we
can't find a filter that will get us the desired type.
* Source/NSProgressIndicator.m: Comment out unused variable 'images'.
* Source/NSBezierPath.m: Declare GSBezierPath fully before using it.
(-bezierPathByFlatteningPath, -bezierPathByReversingPath): Make sure
variables are always initialized.
* Source/NSMenuView.m,
* Source/NSPrintOperation.m,
* Source/NSSplitView.m,
* Source/NSTableHeaderView.m: Make sure variables are always
initialized.
* Source/NSBox.m,
* Source/NSImageview.m,
* Source/NSText.m,
* Source/NSTextStorage.m: Add missing includes.
* Source/GSKeyBindingTable.m,
* Source/GSLayoutManager.m,
* Source/NSBitmapImageRep+PNM.m,
* Source/NSBundleAdditions.m,
* Source/NSLayoutManager.m,
* Source/nsimage-tiff.h,
* Source/tiff.m,
* Headers/Additions/GNUstepGUI/GSDisplayServer.h,
* Source/GSDisplayServer.m: Change signedness of various variables.
* Source/NSPanel.m (-sendEvent:): Remove.
* Source/NSWindow.m (-becomesKeyOnlyIfNeeded): New method.
(-_sendEvent:becomesKeyOnlyIfNeeded:): Remove. Move code ...
(-sendEvent:): ... here. Use -becomesKeyOnlyIfNeeded instead
of the argument.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20590 72102866-910b-0410-8b05-ffd578937521
2005-01-21 20:39:18 +00:00
|
|
|
#include "AppKit/NSWindow.h"
|
1998-01-09 22:28:14 +00:00
|
|
|
|
2001-04-09 21:28:49 +00:00
|
|
|
/*
|
|
|
|
* Class variables
|
|
|
|
*/
|
|
|
|
static Class usedCellClass;
|
|
|
|
static Class imageCellClass;
|
|
|
|
|
1998-01-09 22:28:14 +00:00
|
|
|
@implementation NSImageView
|
|
|
|
|
2001-04-09 21:28:49 +00:00
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSImageView class])
|
|
|
|
{
|
2004-01-15 23:57:54 +00:00
|
|
|
[self setVersion: 2];
|
2001-04-09 21:28:49 +00:00
|
|
|
imageCellClass = [NSImageCell class];
|
|
|
|
usedCellClass = imageCellClass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting the Cell class
|
|
|
|
*/
|
1999-06-05 20:30:29 +00:00
|
|
|
+ (Class) cellClass
|
1998-01-09 22:28:14 +00:00
|
|
|
{
|
2001-04-09 21:28:49 +00:00
|
|
|
return usedCellClass;
|
1998-01-09 22:28:14 +00:00
|
|
|
}
|
|
|
|
|
2001-04-09 21:28:49 +00:00
|
|
|
+ (void) setCellClass: (Class)factoryId
|
|
|
|
{
|
|
|
|
usedCellClass = factoryId ? factoryId : imageCellClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-05 20:30:29 +00:00
|
|
|
- (id) init
|
1998-01-09 22:28:14 +00:00
|
|
|
{
|
1999-06-05 20:30:29 +00:00
|
|
|
return [self initWithFrame: NSZeroRect];
|
1998-01-09 22:28:14 +00:00
|
|
|
}
|
|
|
|
|
1999-06-30 03:10:38 +00:00
|
|
|
- (id) initWithFrame: (NSRect)aFrame
|
1998-01-09 22:28:14 +00:00
|
|
|
{
|
1999-06-30 03:10:38 +00:00
|
|
|
[super initWithFrame: aFrame];
|
1999-06-05 20:30:29 +00:00
|
|
|
|
|
|
|
// set the default values
|
|
|
|
[self setImageAlignment: NSImageAlignCenter];
|
|
|
|
[self setImageFrameStyle: NSImageFrameNone];
|
|
|
|
[self setImageScaling: NSScaleProportionally];
|
|
|
|
[self setEditable: YES];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setImage: (NSImage *)image
|
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setImage: image];
|
|
|
|
[self updateCell: _cell];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setImageAlignment: (NSImageAlignment)align
|
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setImageAlignment: align];
|
|
|
|
[self updateCell: _cell];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setImageScaling: (NSImageScaling)scaling
|
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setImageScaling: scaling];
|
|
|
|
[self updateCell: _cell];
|
1998-01-09 22:28:14 +00:00
|
|
|
}
|
|
|
|
|
1999-06-05 20:30:29 +00:00
|
|
|
- (void) setImageFrameStyle: (NSImageFrameStyle)style
|
1998-01-09 22:28:14 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setImageFrameStyle: style];
|
|
|
|
[self updateCell: _cell];
|
1998-01-09 22:28:14 +00:00
|
|
|
}
|
|
|
|
|
1999-06-05 20:30:29 +00:00
|
|
|
- (void) setEditable: (BOOL)flag
|
1998-01-09 22:28:14 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setEditable: flag];
|
2002-12-05 00:37:30 +00:00
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
[self registerForDraggedTypes: [NSImage imagePasteboardTypes]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self unregisterDraggedTypes];
|
|
|
|
}
|
1998-01-09 22:28:14 +00:00
|
|
|
}
|
|
|
|
|
1999-06-05 20:30:29 +00:00
|
|
|
- (NSImage *) image
|
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell image];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImageAlignment) imageAlignment
|
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell imageAlignment];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImageScaling) imageScaling
|
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell imageScaling];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImageFrameStyle) imageFrameStyle
|
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell imageFrameStyle];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isEditable
|
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell isEditable];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 21:08:54 +00:00
|
|
|
- (BOOL) animates
|
|
|
|
{
|
|
|
|
// FIXME: Should be passed on to cell.
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAnimates: (BOOL) flag
|
|
|
|
{
|
|
|
|
// FIXME: Should be passed on to cell.
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) allowsCutCopyPaste
|
|
|
|
{
|
|
|
|
return _allowsCutCopyPaste;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAllowsCutCopyPaste: (BOOL)flag
|
|
|
|
{
|
|
|
|
_allowsCutCopyPaste = flag;
|
|
|
|
}
|
|
|
|
|
1999-06-05 20:30:29 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSImageView (NSDraggingDestination)
|
|
|
|
|
2006-05-10 22:11:28 +00:00
|
|
|
- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>)sender
|
1999-06-05 20:30:29 +00:00
|
|
|
{
|
2006-10-12 14:10:27 +00:00
|
|
|
if (([sender draggingSource] != self) && ([self isEditable])
|
|
|
|
&& ([NSImage canInitWithPasteboard: [sender draggingPasteboard]]))
|
2002-12-05 00:37:30 +00:00
|
|
|
{
|
|
|
|
[_cell setHighlighted: YES];
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) draggingExited: (id <NSDraggingInfo>)sender
|
|
|
|
{
|
2002-12-05 00:37:30 +00:00
|
|
|
[_cell setHighlighted: NO];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>)sender
|
|
|
|
{
|
2002-12-05 00:37:30 +00:00
|
|
|
if (([sender draggingSource] != self) && ([self isEditable]))
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
1999-06-05 20:30:29 +00:00
|
|
|
else
|
2002-12-05 00:37:30 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) performDragOperation: (id <NSDraggingInfo>)sender
|
|
|
|
{
|
2002-12-05 00:37:30 +00:00
|
|
|
NSImage *image;
|
|
|
|
|
|
|
|
image = [[NSImage alloc] initWithPasteboard: [sender draggingPasteboard]];
|
|
|
|
if (image == nil)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setImage: image];
|
2004-01-15 23:57:54 +00:00
|
|
|
[self sendAction: _action to: _target];
|
2002-12-05 00:37:30 +00:00
|
|
|
RELEASE(image);
|
|
|
|
return YES;
|
|
|
|
}
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) concludeDragOperation: (id <NSDraggingInfo>)sender
|
|
|
|
{
|
2002-12-05 00:37:30 +00:00
|
|
|
[_cell setHighlighted: NO];
|
1999-06-05 20:30:29 +00:00
|
|
|
}
|
1998-01-09 22:28:14 +00:00
|
|
|
|
2002-12-10 00:19:11 +00:00
|
|
|
- (void) mouseDown: (NSEvent*)theEvent
|
2002-12-05 00:37:30 +00:00
|
|
|
{
|
|
|
|
if ([self isEditable])
|
|
|
|
{
|
|
|
|
NSPasteboard *pboard;
|
|
|
|
NSImage *anImage = [self image];
|
|
|
|
|
|
|
|
if (anImage != nil)
|
|
|
|
{
|
|
|
|
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
|
|
|
|
[pboard declareTypes: [NSArray arrayWithObject: NSTIFFPboardType]
|
|
|
|
owner: self];
|
|
|
|
if ([pboard setData: [anImage TIFFRepresentation]
|
|
|
|
forType: NSTIFFPboardType])
|
|
|
|
{
|
2005-04-01 14:10:39 +00:00
|
|
|
NSSize s;
|
|
|
|
NSPoint p;
|
|
|
|
|
|
|
|
// Center the image on the mouse position ... is this right?
|
|
|
|
s = [anImage size];
|
|
|
|
p = [theEvent locationInWindow];
|
|
|
|
p.x -= s.width/2;
|
2007-02-04 13:00:15 +00:00
|
|
|
p.y -= s.height/2;
|
2002-12-05 00:37:30 +00:00
|
|
|
[_window dragImage: anImage
|
2005-04-01 14:10:39 +00:00
|
|
|
at: p
|
2002-12-05 00:37:30 +00:00
|
|
|
offset: NSMakeSize(0, 0)
|
|
|
|
event: theEvent
|
|
|
|
pasteboard: pboard
|
|
|
|
source: self
|
|
|
|
slideBack: YES];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-10 00:19:11 +00:00
|
|
|
[super mouseDown: theEvent];
|
2002-12-05 00:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) draggingSourceOperationMaskForLocal: (BOOL)isLocal
|
|
|
|
{
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
|
2004-01-15 23:57:54 +00:00
|
|
|
//
|
|
|
|
// Target and Action
|
|
|
|
//
|
|
|
|
// Target and action are handled by NSImageView itself, not its own cell.
|
|
|
|
//
|
|
|
|
- (id) target
|
|
|
|
{
|
|
|
|
return _target;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTarget: (id)anObject
|
|
|
|
{
|
|
|
|
_target = anObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SEL) action
|
|
|
|
{
|
|
|
|
return _action;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAction: (SEL)aSelector
|
|
|
|
{
|
|
|
|
_action = aSelector;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// NSCoding Protocol
|
|
|
|
//
|
|
|
|
- (void) encodeWithCoder: (NSCoder *)aCoder
|
|
|
|
{
|
|
|
|
[super encodeWithCoder: aCoder];
|
2006-10-15 08:34:47 +00:00
|
|
|
if ([aCoder allowsKeyedCoding])
|
2006-08-09 05:48:54 +00:00
|
|
|
{
|
|
|
|
[aCoder encodeBool: [self isEditable] forKey: @"NSEditable"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[aCoder encodeConditionalObject: _target];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(SEL) at: &_action];
|
|
|
|
}
|
2004-01-15 23:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder *)aDecoder
|
|
|
|
{
|
|
|
|
self = [super initWithCoder: aDecoder];
|
2004-02-02 21:40:00 +00:00
|
|
|
|
|
|
|
if ([aDecoder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
//NSArray *dragType = [aDecoder decodeObjectForKey: @"NSDragTypes"];
|
|
|
|
if ([aDecoder containsValueForKey: @"NSEditable"])
|
|
|
|
{
|
|
|
|
[self setEditable: [aDecoder decodeBoolForKey: @"NSEditable"]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-01-15 23:57:54 +00:00
|
|
|
{
|
2004-02-02 21:40:00 +00:00
|
|
|
if ([aDecoder versionForClassName: @"NSImageView"] >= 2)
|
|
|
|
{
|
|
|
|
_target = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action];
|
|
|
|
}
|
2004-01-15 23:57:54 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1998-01-09 22:28:14 +00:00
|
|
|
@end
|
1999-06-05 20:30:29 +00:00
|
|
|
|