diff --git a/AppKit/AppKit.j b/AppKit/AppKit.j index 454480cc8..ec791365d 100644 --- a/AppKit/AppKit.j +++ b/AppKit/AppKit.j @@ -34,6 +34,7 @@ @import "CPCibLoading.j" @import "CPCibOutletConnector.j" @import "CPClipView.j" +@import "CPCollectionViewItem.j" @import "CPCollectionView.j" @import "CPColor.j" @import "CPColorPanel.j" @@ -75,6 +76,7 @@ @import "CPToolbar.j" @import "CPToolbarItem.j" @import "CPView.j" +@import "CPViewController.j" @import "CPWebView.j" @import "CPWindow.j" @import "CPWindowController.j" diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 8a896d29d..cf790dc07 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -26,7 +26,8 @@ @import @import -@import +@import "CPView.j" +@import "CPCollectionViewItem.j" /*! @@ -61,6 +62,7 @@ @param indices the indices to obtain drag types @return an array of drag types (CPString) */ + @implementation CPCollectionView : CPView { CPArray _content; @@ -668,95 +670,6 @@ @end -/*! - Represents an object inside a CPCollectionView. -*/ -@implementation CPCollectionViewItem : CPObject -{ - id _representedObject; - - CPView _view; - - BOOL _isSelected; -} - -// Setting the Represented Object -/*! - Sets the object to be represented by this item. - @param anObject the object to be represented -*/ -- (void)setRepresentedObject:(id)anObject -{ - if (_representedObject == anObject) - return; - - _representedObject = anObject; - - // FIXME: This should be set up by bindings - [_view setRepresentedObject:anObject]; -} - -/*! - Returns the object represented by this view item -*/ -- (id)representedObject -{ - return _representedObject; -} - -// Modifying the View -/*! - Sets the view that is used represent this object. - @param aView the view used to represent this object -*/ -- (void)setView:(CPView)aView -{ - _view = aView; -} - -/*! - Returns the view that represents this object. -*/ -- (CPView)view -{ - return _view; -} - -// Modifying the Selection -/*! - Sets whether this view item should be selected. - @param shouldBeSelected \c YES makes the item selected. \c NO deselects it. -*/ -- (void)setSelected:(BOOL)shouldBeSelected -{ - if (_isSelected == shouldBeSelected) - return; - - _isSelected = shouldBeSelected; - - // FIXME: This should be set up by bindings - [_view setSelected:_isSelected]; -} - -/*! - Returns \c YES if the item is currently selected. \c NO if the item is not selected. -*/ -- (BOOL)isSelected -{ - return _isSelected; -} - -// Parent Collection View -/*! - Returns the collection view of which this item is a part. -*/ -- (CPCollectionView)collectionView -{ - return [_view superview]; -} - -@end - var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", CPCollectionViewMaxItemSizeKey = @"CPCollectionViewMaxItemSizeKey", CPCollectionViewVerticalMarginKey = @"CPCollectionViewVerticalMarginKey", @@ -811,47 +724,3 @@ var CPCollectionViewMinItemSizeKey = @"CPCollectionViewMinItemSizeKey", } @end - -var CPCollectionViewItemViewKey = @"CPCollectionViewItemViewKey"; - -@implementation CPCollectionViewItem (CPCoding) - -/* - FIXME Not yet implemented -*/ -- (id)copy -{ - -} - -@end - -var CPCollectionViewItemViewKey = @"CPCollectionViewItemViewKey"; - -@implementation CPCollectionViewItem (CPCoding) - -/*! - Initializes the view item by unarchiving data from a coder. - @param aCoder the coder from which the data will be unarchived - @return the initialized collection view item -*/ -- (id)initWithCoder:(CPCoder)aCoder -{ - self = [super init]; - - if (self) - _view = [aCoder decodeObjectForKey:CPCollectionViewItemViewKey]; - - return self; -} - -/*! - Archives the colletion view item to the provided coder. - @param aCoder the coder to which the view item should be archived -*/ -- (void)encodeWithCoder:(CPCoder)aCoder -{ - [aCoder encodeObject:_view forKey:CPCollectionViewItemViewKey]; -} - -@end \ No newline at end of file diff --git a/AppKit/CPCollectionViewItem.j b/AppKit/CPCollectionViewItem.j new file mode 100644 index 000000000..1711df6c0 --- /dev/null +++ b/AppKit/CPCollectionViewItem.j @@ -0,0 +1,85 @@ +/* + * CPCollectionViewItem.j + * AppKit + * + * Created by Francisco Tolmasky. + * Copyright 2009, 280 North, Inc. + * + * 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.1 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import "CPViewController.j" + +/*! + Represents an object inside a CPCollectionView. +*/ +@implementation CPCollectionViewItem : CPViewController +{ + BOOL _isSelected; +} + +// Setting the Represented Object +/*! + Sets the object to be represented by this item. + @param anObject the object to be represented +*/ +- (void)setRepresentedObject:(id)anObject +{ + [super setRepresentedObject:anObject]; + + var view = [self view]; + + if ([view respondsToSelector:@selector(setRepresentedObject:)]) + [view setRepresentedObject:[self representedObject]]; +} + +// Modifying the Selection +/*! + Sets whether this view item should be selected. + @param shouldBeSelected \c YES makes the item selected. \c NO deselects it. +*/ +- (void)setSelected:(BOOL)shouldBeSelected +{ + shouldBeSelected = !!shouldBeSelected; + + if (_isSelected === shouldBeSelected) + return; + + _isSelected = shouldBeSelected; + + var view = [self view]; + + if ([view respondsToSelector:@selector(setSelected:)]) + [view setSelected:[self isSelected]]; +} + +/*! + Returns \c YES if the item is currently selected. \c NO if the item is not selected. +*/ +- (BOOL)isSelected +{ + return _isSelected; +} + +// Parent Collection View +/*! + Returns the collection view of which this item is a part. +*/ +- (CPCollectionView)collectionView +{ + return [_view superview]; +} + +@end diff --git a/AppKit/CPViewController.j b/AppKit/CPViewController.j index 98ca200d4..3529d29a3 100644 --- a/AppKit/CPViewController.j +++ b/AppKit/CPViewController.j @@ -163,3 +163,41 @@ } @end + + +var CPViewControllerViewKey = @"CPViewControllerViewKey", + CPViewControllerTitleKey = @"CPViewControllerTitleKey"; + +@implementation CPViewController (CPCoding) + +/*! + Initializes the view item by unarchiving data from a coder. + @param aCoder the coder from which the data will be unarchived + @return the initialized collection view item +*/ +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super initWithCoder:aCoder]; + + if (self) + { + _view = [aCoder decodeObjectForKey:CPViewControllerViewKey]; + _title = [aCoder decodeObjectForKey:CPViewControllerTitleKey]; + } + + return self; +} + +/*! + Archives the colletion view item to the provided coder. + @param aCoder the coder to which the view item should be archived +*/ +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [super encodeWithCoder:aCoder]; + + [aCoder encodeObject:_view forKey:CPViewControllerViewKey]; + [aCoder encodeObject:_title forKey:CPViewControllerTitleKey]; +} + +@end diff --git a/Tools/nib2cib/NSAppKit.j b/Tools/nib2cib/NSAppKit.j index 5fc83b30f..a18c503d8 100644 --- a/Tools/nib2cib/NSAppKit.j +++ b/Tools/nib2cib/NSAppKit.j @@ -27,6 +27,7 @@ @import "NSColor.j" @import "NSColorWell.j" @import "NSCollectionView.j" +@import "NSCollectionViewItem.j" @import "NSControl.j" @import "NSCustomObject.j" @import "NSCustomResource.j" @@ -54,6 +55,7 @@ @import "NSTextField.j" @import "NSToolbar.j" @import "NSView.j" +@import "NSViewController.j" @import "NSWindowTemplate.j" @import "WebView.j" diff --git a/Tools/nib2cib/NSCollectionView.j b/Tools/nib2cib/NSCollectionView.j index 809da77ef..b426aa18c 100644 --- a/Tools/nib2cib/NSCollectionView.j +++ b/Tools/nib2cib/NSCollectionView.j @@ -72,29 +72,3 @@ } @end - - -@implementation CPCollectionViewItem (NSCoding) - -- (id)NS_initWithCoder:(CPCoder)aCoder -{ - return [super init]; -} - -@end - -@implementation NSCollectionViewItem : CPCollectionViewItem -{ -} - -- (id)initWithCoder:(CPCoder)aCoder -{ - return [self NS_initWithCoder:aCoder]; -} - -- (Class)classForKeyedArchiver -{ - return [CPCollectionViewItem class]; -} - -@end \ No newline at end of file diff --git a/Tools/nib2cib/NSCollectionViewItem.j b/Tools/nib2cib/NSCollectionViewItem.j new file mode 100644 index 000000000..93ce88e40 --- /dev/null +++ b/Tools/nib2cib/NSCollectionViewItem.j @@ -0,0 +1,49 @@ +/* + * NSCollectionViewItem.j + * nib2cib + * + * Created by Francisco Tolmasky. + * Copyright 2009, 280 North, Inc. + * + * 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.1 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import + + +@implementation CPCollectionViewItem (NSCoding) + +- (id)NS_initWithCoder:(CPCoder)aCoder +{ + return [super NS_initWithCoder:aCoder]; +} + +@end + +@implementation NSCollectionViewItem : CPCollectionViewItem +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPCollectionViewItem class]; +} + +@end diff --git a/Tools/nib2cib/NSViewController.j b/Tools/nib2cib/NSViewController.j new file mode 100644 index 000000000..18fcc5527 --- /dev/null +++ b/Tools/nib2cib/NSViewController.j @@ -0,0 +1,49 @@ +/* + * NSViewController.j + * nib2cib + * + * Created by Francisco Tolmasky. + * Copyright 2008, 280 North, Inc. + * + * 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.1 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; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import + + +@implementation CPViewController (NSCoding) + +- (id)NS_initWithCoder:(CPCoder)aCoder +{ + return [super NS_initWithCoder:aCoder]; +} + +@end + +@implementation NSViewController : CPViewController +{ +} + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self NS_initWithCoder:aCoder]; +} + +- (Class)classForKeyedArchiver +{ + return [CPCollectionView class]; +} + +@end