Clean up and addition of cut/copy/paste methods, based on code

by Nikolaus Schaller <hns@computer.org>.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29178 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2009-12-29 11:24:01 +00:00
parent 6dd84b196f
commit 028f8b2698
3 changed files with 125 additions and 38 deletions

View file

@ -1,3 +1,9 @@
2009-12-29 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSImageView.h: Clean up.
* Source/NSImageView.m: Clean up and addition of cut/copy/paste
methods, based on code by Nikolaus Schaller <hns@computer.org>.
2009-12-27 Quentin Mathe <quentin.mathe@gmail.com> 2009-12-27 Quentin Mathe <quentin.mathe@gmail.com>
* Headers/NSTableView.h * Headers/NSTableView.h
@ -66,7 +72,7 @@
panel is requested. panel is requested.
2009-12-21 Fred Kiefer <FredKiefer@gmx.de> 2009-12-21 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSIconManager.h, * Source/GSIconManager.h,
* Source/GSIconManager.m: New files. Allows to get icon placement * Source/GSIconManager.m: New files. Allows to get icon placement
from separate process. from separate process.
@ -102,7 +108,7 @@
occurred to an instance variable. occurred to an instance variable.
2009-12-21 Fred Kiefer <FredKiefer@gmx.de> 2009-12-21 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTableColumn.m (-initWithCoder:, -encodeWithCoder:): Add * Source/NSTableColumn.m (-initWithCoder:, -encodeWithCoder:): Add
the keyed encoding/decoding code for Quentin's extensions. the keyed encoding/decoding code for Quentin's extensions.
@ -444,7 +450,7 @@
* Source/NSSlider.m: Clean up. * Source/NSSlider.m: Clean up.
* Source/NSSliderCell.m: Remove isFlipped method, correct * Source/NSSliderCell.m: Remove isFlipped method, correct
copyWithZone:, clean up. copyWithZone:, clean up.
2009-11-16 Fred Kiefer <FredKiefer@gmx.de> 2009-11-16 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSCell.m (-setObjectValue:, -setStringValue:): Handle a * Source/NSCell.m (-setObjectValue:, -setStringValue:): Handle a
@ -465,7 +471,7 @@
in NSTextView_actions.m. in NSTextView_actions.m.
2009-11-15 Fred Kiefer <FredKiefer@gmx.de> 2009-11-15 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSButtonCell.m: Change default value for * Source/NSButtonCell.m: Change default value for
keyEquivalentModifierMask to 0. Add keyed decoding and encoding of keyEquivalentModifierMask to 0. Add keyed decoding and encoding of
keyEquivalentModifierMask. keyEquivalentModifierMask.
@ -549,7 +555,7 @@
* Source/NSTextFieldCell.m: White space changes. * Source/NSTextFieldCell.m: White space changes.
* Headers/AppKit/NSTableHeaderCell.h, * Headers/AppKit/NSTableHeaderCell.h,
* Source/NSTableHeaderCell.m: Add new 10.3 methods. * Source/NSTableHeaderCell.m: Add new 10.3 methods.
2009-11-09 Fred Kiefer <FredKiefer@gmx.de> 2009-11-09 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSControl.m, * Source/NSControl.m,
@ -573,7 +579,7 @@
* Headers/AppKit/NSAnimation.h: Change to new MacOSX type definitions. * Headers/AppKit/NSAnimation.h: Change to new MacOSX type definitions.
* Source/NSAnimation.m: Remove externs and white space changes. * Source/NSAnimation.m: Remove externs and white space changes.
* Source/externs.m: Move externs from NSAnimation to here. * Source/externs.m: Move externs from NSAnimation to here.
2009-11-08 Fred Kiefer <FredKiefer@gmx.de> 2009-11-08 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSApplication.m (-finishLaunching): Only activate the * Source/NSApplication.m (-finishLaunching): Only activate the
@ -616,7 +622,7 @@
* Source/NSColor.m (-colorUsingColorSpace): Support more color spaces. * Source/NSColor.m (-colorUsingColorSpace): Support more color spaces.
* Source/NSColorSpace.m (COLORSPACE): Initialize the static variable. * Source/NSColorSpace.m (COLORSPACE): Initialize the static variable.
2009-11-03 Fred Kiefer <FredKiefer@gmx.de> 2009-11-03 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSThemeDrawing.m: Add more includes to apeace Riccardo's compiler. * Source/GSThemeDrawing.m: Add more includes to apeace Riccardo's compiler.
@ -630,7 +636,7 @@
* Source/NSApplication.m (-nextEventMatchingMask:...): Only set * Source/NSApplication.m (-nextEventMatchingMask:...): Only set
the current event when dequeuing and never return the null_event. the current event when dequeuing and never return the null_event.
2009-11-02 Fred Kiefer <FredKiefer@gmx.de> 2009-11-02 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSTheme.m: Remove some compiler warnings. * Source/GSTheme.m: Remove some compiler warnings.
@ -639,7 +645,7 @@
* Source/GSThemeDrawing.m, * Source/GSThemeDrawing.m,
* Headers/Additions/GNUstepGUI/GSTheme.h: New theme methods for * Headers/Additions/GNUstepGUI/GSTheme.h: New theme methods for
toolbar and menu item drawing. toolbar and menu item drawing.
2009-11-01 Fred Kiefer <FredKiefer@gmx.de> 2009-11-01 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSImage.m: Switch to the new shared composite and * Source/NSImage.m: Switch to the new shared composite and
@ -663,7 +669,7 @@
* Images/common_ProgressIndeterminate_?.tiff * Images/common_ProgressIndeterminate_?.tiff
New image files by Uli Kusterer <witness.of.teachtext@gmx.net>. New image files by Uli Kusterer <witness.of.teachtext@gmx.net>.
* Images/GNUmakefile: Add the new images. * Images/GNUmakefile: Add the new images.
2009-10-27 Thomas Gamper <icicle@cg.tuwien.ac.at> 2009-10-27 Thomas Gamper <icicle@cg.tuwien.ac.at>
* Source/GSDisplayServer.m * Source/GSDisplayServer.m
@ -689,11 +695,11 @@
at geometry maths. at geometry maths.
2009-10-23 Riccardo Mottola <rmottola@users.sf.net> 2009-10-23 Riccardo Mottola <rmottola@users.sf.net>
* Headers/AppKit/NSBezierPath.h: added some documentation * Headers/AppKit/NSBezierPath.h: added some documentation
2009-10-22 Riccardo Mottola <rmottola@users.sf.net> 2009-10-22 Riccardo Mottola <rmottola@users.sf.net>
* Images/common_3DArrowRightH.tiff: Made background transparent, * Images/common_3DArrowRightH.tiff: Made background transparent,
allows for better theming allows for better theming
@ -713,7 +719,7 @@
colour gradients. colour gradients.
* Headers/AppKit/AppKit.h: Add include for NSGradient.h * Headers/AppKit/AppKit.h: Add include for NSGradient.h
* Source/GNUmakefile: Add new files. * Source/GNUmakefile: Add new files.
2009-10-20 Wolfgang Lux <wolfgang.lux@gmail.com> 2009-10-20 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/NSDocumentController.m(-openDocumentWithContentsOfURL:display:, * Source/NSDocumentController.m(-openDocumentWithContentsOfURL:display:,
@ -886,13 +892,13 @@
into GSTheme. into GSTheme.
2009-10-10 Fred Kiefer <FredKiefer@gmx.de> 2009-10-10 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSEvent.m, * Source/NSEvent.m,
* Source/NSImage.m, * Source/NSImage.m,
* Source/GSTextStorage.m: Remove usage of NSDeallocateObject. * Source/GSTextStorage.m: Remove usage of NSDeallocateObject.
2009-10-10 Fred Kiefer <FredKiefer@gmx.de> 2009-10-10 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSApplication.m (-endModalSession:): Bring the window of * Source/NSApplication.m (-endModalSession:): Bring the window of
the next modal session to the front. the next modal session to the front.
* Source/NSApplication.m (-runModalSession:): Better check whether * Source/NSApplication.m (-runModalSession:): Better check whether
@ -901,25 +907,25 @@
2009-09-27 Richard Frith-Macdonald <rfm@gnu.org> 2009-09-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSImage.m: ([-setName:]) fix bug which was removing the * Source/NSImage.m: ([-setName:]) fix bug which was removing the
wrong name when given an image which already had a name. wrong name when given an image which already had a name.
Make named images thread-safe using a lock. Make named images thread-safe using a lock.
Add private method to update names on theme change. Add private method to update names on theme change.
* Source/GSTheme.m: Use new method to update theme images. * Source/GSTheme.m: Use new method to update theme images.
2009-09-26 Fred Kiefer <FredKiefer@gmx.de> 2009-09-26 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSApplication.m (-setApplicationIconImage:, * Source/NSApplication.m (-setApplicationIconImage:,
-finishLaunching): Move the set name code to finishLaunching, as -finishLaunching): Move the set name code to finishLaunching, as
the image called NSApplicationIcon should stay the same all the time. the image called NSApplicationIcon should stay the same all the time.
2009-09-26 Fred Kiefer <FredKiefer@gmx.de> 2009-09-26 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTextContainer.m (init): Add this method as suggested * Source/NSTextContainer.m (init): Add this method as suggested
by Derek Fawcus <dfawcus@cisco.com>. by Derek Fawcus <dfawcus@cisco.com>.
2009-09-21 Fred Kiefer <FredKiefer@gmx.de> 2009-09-21 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSWindow.m (+standardWindowButton:forStyleMask:): Add * Source/NSWindow.m (+standardWindowButton:forStyleMask:): Add
support for toolbar button. support for toolbar button.
* Source/NSWindow.m (-toggleToolbarShown:): Reorder the code. * Source/NSWindow.m (-toggleToolbarShown:): Reorder the code.

View file

@ -29,14 +29,14 @@
#define _GNUstep_H_NSImageView #define _GNUstep_H_NSImageView
#import <GNUstepBase/GSVersionMacros.h> #import <GNUstepBase/GSVersionMacros.h>
#include <AppKit/NSControl.h> #import <AppKit/NSControl.h>
#include <AppKit/NSImageCell.h> #import <AppKit/NSImageCell.h>
@interface NSImageView : NSControl @interface NSImageView : NSControl
{ {
id _target; id _target;
SEL _action; SEL _action;
BOOL _allowsCutCopyPaste; BOOL _allowsCutCopyPaste;
} }
- (NSImage *)image; - (NSImage *)image;

View file

@ -26,13 +26,14 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#include "AppKit/NSDragging.h" #import "AppKit/NSDragging.h"
#include "AppKit/NSEvent.h" #import "AppKit/NSEvent.h"
#include "AppKit/NSImage.h" #import "AppKit/NSImage.h"
#include "AppKit/NSImageCell.h" #import "AppKit/NSImageCell.h"
#include "AppKit/NSImageView.h" #import "AppKit/NSImageView.h"
#include "AppKit/NSPasteboard.h" #import "AppKit/NSMenuItem.h"
#include "AppKit/NSWindow.h" #import "AppKit/NSPasteboard.h"
#import "AppKit/NSWindow.h"
/* /*
* Class variables * Class variables
@ -69,14 +70,11 @@ static Class imageCellClass;
} }
- (id) init
{
return [self initWithFrame: NSZeroRect];
}
- (id) initWithFrame: (NSRect)aFrame - (id) initWithFrame: (NSRect)aFrame
{ {
[super initWithFrame: aFrame]; self = [super initWithFrame: aFrame];
if (!self)
return self;
// set the default values // set the default values
[self setImageAlignment: NSImageAlignCenter]; [self setImageAlignment: NSImageAlignCenter];
@ -170,9 +168,86 @@ static Class imageCellClass;
_allowsCutCopyPaste = flag; _allowsCutCopyPaste = flag;
} }
@end - (void) delete: (id)sender
{
if (_allowsCutCopyPaste)
[self setImage: nil];
}
@implementation NSImageView (NSDraggingDestination) - (void) deleteBackward: (id)sender
{
if (_allowsCutCopyPaste)
[self setImage: nil];
}
- (void) cut: (id)sender
{
if (_allowsCutCopyPaste)
{
[self copy];
[self setImage: nil];
}
}
- (void) copy: (id)sender
{
if (_allowsCutCopyPaste)
{
NSImage *anImage = [self image];
if (anImage != nil)
{
// copy to pasteboard
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard declareTypes: [NSArray arrayWithObject: NSTIFFPboardType]
owner: self];
[pboard setData: [anImage TIFFRepresentation]
forType: NSTIFFPboardType];
}
}
}
- (void) paste: (id)sender
{
if (_allowsCutCopyPaste)
{
// paste from pasteboard
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
NSImage *image = [[NSImage alloc] initWithPasteboard: pboard];
if (image != nil)
{
[self setImage: image];
RELEASE(image);
}
}
}
- (BOOL) validateUserInterfaceItem: (id <NSValidatedUserInterfaceItem>)anItem
{
SEL action = [anItem action];
if (_allowsCutCopyPaste)
{
if (sel_eq(action, @selector(cut:)) ||
sel_eq(action, @selector(copy:)) ||
sel_eq(action, @selector(deleteBackward:)) ||
sel_eq(action, @selector(delete:)))
return [self image] != nil;
if (sel_eq(action, @selector(paste:)))
{
return [NSImage canInitWithPasteboard:
[NSPasteboard generalPasteboard]];
}
}
return NO;
}
- (BOOL) validateMenuItem: (NSMenuItem *)anItem
{
return [self validateUserInterfaceItem: anItem];
}
- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>)sender - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>)sender
{ {
@ -188,6 +263,8 @@ static Class imageCellClass;
} }
} }
// NSDraggingDestination protocol
- (void) draggingExited: (id <NSDraggingInfo>)sender - (void) draggingExited: (id <NSDraggingInfo>)sender
{ {
[_cell setHighlighted: NO]; [_cell setHighlighted: NO];
@ -303,6 +380,8 @@ static Class imageCellClass;
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
if ([aCoder allowsKeyedCoding]) if ([aCoder allowsKeyedCoding])
{ {
[aCoder encodeObject: [NSImage imagePasteboardTypes]
forKey: @"NSDragTypes"];
[aCoder encodeBool: [self isEditable] forKey: @"NSEditable"]; [aCoder encodeBool: [self isEditable] forKey: @"NSEditable"];
} }
else else
@ -315,6 +394,8 @@ static Class imageCellClass;
- (id) initWithCoder: (NSCoder *)aDecoder - (id) initWithCoder: (NSCoder *)aDecoder
{ {
self = [super initWithCoder: aDecoder]; self = [super initWithCoder: aDecoder];
if (!self)
return self;
if ([aDecoder allowsKeyedCoding]) if ([aDecoder allowsKeyedCoding])
{ {