2013-04-18 03:57:49 +00:00
|
|
|
/** <title>NSCollectionViewItem</title>
|
|
|
|
|
|
|
|
Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Doug Simons (doug.simons@testplant.com)
|
|
|
|
Frank LeGrand (frank.legrand@testplant.com)
|
|
|
|
Date: February 2013
|
|
|
|
|
|
|
|
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 Lesser 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
#import <Foundation/NSArray.h>
|
2013-04-18 03:57:49 +00:00
|
|
|
#import <Foundation/NSKeyedArchiver.h>
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
#import "AppKit/NSCollectionView.h"
|
|
|
|
#import "AppKit/NSCollectionViewItem.h"
|
|
|
|
#import "AppKit/NSImageView.h"
|
|
|
|
#import "AppKit/NSTextField.h"
|
2013-04-18 03:57:49 +00:00
|
|
|
|
|
|
|
@implementation NSCollectionViewItem
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (void) awakeFromNib
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (BOOL) isSelected
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
|
|
|
return _isSelected;
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (void) dealloc
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
2013-04-21 13:28:47 +00:00
|
|
|
DESTROY(textField);
|
|
|
|
DESTROY(imageView);
|
2013-04-18 03:57:49 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (NSCollectionView *) collectionView
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
|
|
|
return (NSCollectionView *)[[self view] superview];
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (NSArray *) draggingImageComponents
|
|
|
|
{
|
|
|
|
// FIXME: We don't have NSDraggingImageComponent
|
|
|
|
return [NSArray array];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSelected: (BOOL)flag
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
|
|
|
if (_isSelected != flag)
|
|
|
|
{
|
|
|
|
_isSelected = flag;
|
2013-04-21 13:28:47 +00:00
|
|
|
}
|
2013-04-18 03:57:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (id) representedObject
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
|
|
|
return [super representedObject];
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (void) setRepresentedObject: (id)anObject
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
|
|
|
[super setRepresentedObject:anObject];
|
|
|
|
//[textField setStringValue:[self representedObject]];
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (NSTextField *) textField
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
|
|
|
return textField;
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (void) setTextField: (NSTextField *)aTextField
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
2015-03-08 22:23:06 +00:00
|
|
|
ASSIGN(textField, aTextField);
|
2013-04-18 03:57:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (NSImageView *) imageView
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
|
|
|
return imageView;
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (void) setImageView: (NSImageView *)anImageView
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
2015-03-08 22:23:06 +00:00
|
|
|
ASSIGN(imageView, anImageView);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSView *) view
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
[[self textField] setStringValue: [self representedObject]];
|
|
|
|
return [self textField];
|
2013-04-18 03:57:49 +00:00
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *)aCoder
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
2013-04-21 13:28:47 +00:00
|
|
|
self = [super initWithCoder: aCoder];
|
2013-04-18 03:57:49 +00:00
|
|
|
if (nil != self)
|
|
|
|
{
|
2013-04-21 13:28:47 +00:00
|
|
|
if (YES == [aCoder allowsKeyedCoding])
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
2015-03-08 22:23:06 +00:00
|
|
|
if ([aCoder containsValueForKey: @"textField"])
|
|
|
|
{
|
|
|
|
[self setTextField: [aCoder decodeObjectForKey: @"textField"]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textField = [[NSTextField alloc] initWithFrame: NSMakeRect(0.0, 0.0, 100.0, 20.0)];
|
|
|
|
}
|
|
|
|
if ([aCoder containsValueForKey: @"imageView"])
|
|
|
|
{
|
|
|
|
[self setImageView: [aCoder decodeObjectForKey: @"imageView"]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imageView = [[NSImageView alloc] initWithFrame: NSMakeRect(0.0, 0.0, 100.0, 100.0)];
|
|
|
|
}
|
2013-04-18 03:57:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-08 22:23:06 +00:00
|
|
|
[self setTextField: [aCoder decodeObject]];
|
|
|
|
[self setImageView: [aCoder decodeObject]];
|
2013-04-18 03:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)encodeWithCoder:(NSCoder *)aCoder
|
|
|
|
{
|
2013-04-21 13:28:47 +00:00
|
|
|
[super encodeWithCoder: aCoder];
|
|
|
|
if (YES == [aCoder allowsKeyedCoding])
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
2013-04-21 13:28:47 +00:00
|
|
|
[aCoder encodeObject: textField forKey: @"textField"];
|
|
|
|
[aCoder encodeObject: imageView forKey: @"imageView"];
|
2013-04-18 03:57:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-21 13:28:47 +00:00
|
|
|
[aCoder encodeObject: textField];
|
|
|
|
[aCoder encodeObject: imageView];
|
2013-04-18 03:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:28:47 +00:00
|
|
|
- (id) copyWithZone: (NSZone *)zone
|
2013-04-18 03:57:49 +00:00
|
|
|
{
|
2013-04-21 13:28:47 +00:00
|
|
|
NSData *itemAsData = [NSKeyedArchiver archivedDataWithRootObject: self];
|
2013-04-18 03:57:49 +00:00
|
|
|
NSCollectionViewItem *newItem =
|
2013-04-21 13:28:47 +00:00
|
|
|
[NSKeyedUnarchiver unarchiveObjectWithData: itemAsData];
|
2013-04-18 03:57:49 +00:00
|
|
|
return newItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|