Skip to content

Goal Header

kolinkrewinkel edited this page Aug 3, 2011 · 3 revisions
//  ==============================================================================
//  Defines
//  ==============================================================================

typedef enum {
    XGridViewScrollPositionNone,        
    XGridViewScrollPositionTop,    
    XGridViewScrollPositionMiddle,   
    XGridViewScrollPositionBottom
} XGridViewScrollPosition;

typedef enum {
    XGridViewItemAnimationFade,
    XGridViewItemAnimationRight,
    XGridViewItemAnimationLeft,
    XGridViewItemAnimationTop,
    XGridViewItemAnimationBottom,
    XGridViewItemAnimationNone,
    XGridViewItemAnimationMiddle,
    XGridViewItemAnimationAutomatic = 100
} XGridViewItemAnimation;

//  ==============================================================================
//  XGridViewDataSource
//  ==============================================================================

@class XGridView, XGridViewItem;
@protocol XGridViewDataSource <NSObject>

@required

- (NSUInteger)gridView:(XGridView *)gridView numberOfItemsInSection:(NSInteger)section;
- (NSUInteger)gridView:(XGridView *)gridView numberOfColumnsInSection:(NSInteger)section;
- (CGSize)gridView:(XGridView *)gridView sizeForItemsInSection:(NSInteger)section;

- (XGridViewItem *)gridView:(XGridView *)gridView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

@optional

- (NSInteger)numberOfSectionsInGridView:(XGridView *)gridView;
- (CGFloat)gridView:(XGridView *)gridView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)gridView:(XGridView *)gridView heightForFooterInSection:(NSInteger)section;
- (NSString *)gridView:(XGridView *)gridView titleForHeaderInSection:(NSInteger)section;
- (NSString *)gridView:(XGridView *)gridView titleForFooterInSection:(NSInteger)section;

- (BOOL)gridView:(XGridView *)gridView canSelectItemAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)gridView:(XGridView *)gridView canDeselctItemAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)gridView:(XGridView *)gridView canEditItemAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)gridView:(XGridView *)gridView canMoveItemAtIndexPath:(NSIndexPath *)indexPath;

- (void)gridView:(XGridView *)gridView didMoveItemAtIndexPath:(NSIndexPath *)sourceIndexPath 
     toIndexPath:(NSIndexPath *)destinationIndexPath;


@end

//  ==============================================================================
//  XGridViewDelegate
//  ==============================================================================

@protocol XGridViewDelegate <NSObject, UIScrollViewDelegate>

- (void)gridView:(XGridView *)gridView willDisplayItem:(XGridViewItem *)item forIndexPath:(NSIndexPath *)indexPath;
- (void)gridView:(XGridView *)gridView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
- (void)gridView:(XGridView *)gridView didDeselectAtItemIndexPath:(NSIndexPath *)indexPath;

@end

//  ==============================================================================
//  XGridView
//  ==============================================================================

@interface XGridView : UIScrollView {
@private
    struct {
        unsigned int dataSourceRespondsToHeightForFooterInSection:1;
        unsigned int dataSourceRespondsToHeightForHeaderInSection:1;
        unsigned int dataSourceRespondsToNumberOfSections:1;
        unsigned int delegateRespondsToDidSelectItem:1;
    } _dataSourceFlags;
    
    NSMutableDictionary *_numberOfColumns;
    NSMutableDictionary *_numberOfItems;
    NSMutableDictionary *_reusableItems;
    NSMutableSet *_visibleItems;
    NSMutableSet *_selectedItems;
    
    NSInteger _numberOfSections;
}

@property (nonatomic, assign) id <XGridViewDataSource> dataSource;
@property (nonatomic, assign) id <XGridViewDelegate> delegate;
@property (nonatomic, retain) UIView *backgroundView;
@property (nonatomic, retain) UIView *gridHeaderView;
@property (nonatomic, retain) UIView *gridFooterView;
@property (nonatomic, getter = isEditing) BOOL editing;
@property (nonatomic, getter = isAllowingSelection) BOOL allowsSelection;
@property (nonatomic, getter = isAllowingSelectionDuringEditing) BOOL allowsSelectionDuringEditing;
@property (nonatomic, getter = isAllowingMultipleSelection) BOOL allowsMultipleSelection;
@property (nonatomic, getter = isAllowingMultipleSelectionDuringEditing) BOOL allowsMultipleSelectionDuringEditing;

- (id)initWithFrame:(CGRect)frame;
- (id)initWithFrame:(CGRect)frame dataSource:(id <XGridViewDataSource>)dataSource delegate:(id <XGridViewDelegate>)delegate;

- (NSArray *)visibleItems;
- (NSArray *)indexPathsForVisibleItems;
- (NSArray *)indexPathsForSelectedItems;

- (NSInteger)numberOfItemsInSection:(NSInteger)section;
- (NSInteger)numberOfColumnsInSection:(NSInteger)section;

- (NSIndexPath *)indexPathForItem:(XGridViewItem *)item;

- (XGridViewItem *)dequeueReusableItemWithIdentifier:(NSString *)identifier;
- (XGridViewItem *)itemForRowAtIndexPath:(NSIndexPath *)indexPath;

- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath 
               atScrollPosition:(XGridViewScrollPosition)scrollPosition 
                       animated:(BOOL)animated;

- (void)beginUpdates;
- (void)endUpdates;

- (void)insertSections:(NSIndexSet *)sections withItemAnimation:(XGridViewItemAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withItemAnimation:(XGridViewItemAnimation)animation;
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(XGridViewItemAnimation)animation;
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection;

- (void)insertItemsAtIndexPaths:(NSArray *)indexPaths withItemAnimation:(XGridViewItemAnimation)animation;
- (void)deleteItemAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(XGridViewItemAnimation)animation;
- (void)reloadItemAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(XGridViewItemAnimation)animation;
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;

- (void)reloadData;

- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath
                     animated:(BOOL)animated
               scrollPosition:(XGridViewScrollPosition)scrollPosition;
- (void)deselectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

@end
Clone this wiki locally