//
//  BXImageBrowserView.h
//  BXAppKit
//
//  Created by Michael Ehrmann on 04.12.06.
//  Copyright 2006 Boinx Software. All rights reserved.
//

#pragma mark #define
//#define showMethodNames
//#define debugDrawing
//#define debugScaling
//#define debugSelection
//#define debugMouseDown
//#define debugDataSource
//#define debugSelectionRect
//#define debugDraggingImage

// extern CGFloat kBackgroundColorThreshold;


extern NSString * const BXImageBrowserSelectionDidChangeNotification;


extern NSString * const BXImageBrowserNSImageRepresentationType;			/* NSImage */
extern NSString * const BXImageBrowserCGImageRepresentationType;			/* CGImageRef */


@interface NSObject (BXImageBrowserDataSource)

- (NSUInteger) numberOfItemsInImageBrowser:(id)inImageBrowser;
- (id) imageBrowser:(id)inImageBrowser itemAtIndex:(NSUInteger)inIndex;

- (void) imageBrowser:(id)inImageBrowser writeItemsAtIndexes:(NSIndexSet *)inItemIndexes toPasteboard:(NSPasteboard *)inPasteboard;
- (NSImage*) imageBrowser:(id)inImageBrowser createDragImageForVisibleRect:(NSRect)inRect withSize:(NSSize)imageSize;

@end


@interface NSObject (BXImageBrowserItem)

- (NSString *) imageRepresentationType;
- (id) imageRepresentation;
- (NSString *) imageTitle;
- (BOOL) isUsedInDocument;

@end


@interface NSObject (BXImageBrowserDelegate)

- (void) imageBrowserSelectionDidChange:(NSNotification *)inNotification;
- (void) imageBrowser:(id)inImageBrowser cellWasDoubleClickedAtIndex:(NSUInteger)inIndex;
- (BOOL) imageBrowser:(id)inImageBrowser keyDown:(NSEvent*)inEvent;
//- (void) imageBrowser:(id)inImageBrowser backgroundWasRightClickedWithEvent:(NSEvent*)inEvent;
//- (void) imageBrowser:(id)inImageBrowser cellWasRightClickedAtIndex:(NSUInteger)inIndex withEvent:(NSEvent*)inEvent;

@end


@interface NSObject (BXImageBrowserDrop)

- (BOOL) imageBrowser:(id)inImageBrowser droppedPath:(NSString*)inPath;
- (BOOL) imageBrowser:(id)inImageBrowser droppedPaths:(NSArray*)inPaths;

@end


@interface BXImageBrowserView : NSView {
	
	NSUInteger rowCount, columnCount;

	NSSize maxCellSize;
	NSSize minCellSize;
	
	NSSize cellSize;
	NSSize cellPadding;
	NSSize innerCellPadding;
	NSSize cellSpacing;
	
	NSSize viewMargin;
	
	NSColor* backgroundColor;
	NSColor* imageNameColor;
	NSColor* selectionColor;

	CGFloat cellSizeScaleFactor;
	CGFloat cellSelectionCornerRadius;

	BOOL drawImageNames;
	BOOL drawShadow;
	BOOL drawBorder;
	
	BOOL hasFlexibleXCellSpacing;
	
	BOOL allowsMultipleSelection;
	//BOOL allowsEmptySelection;
	
	IBOutlet id zoomSlider;
	IBOutlet id dataSource;
	IBOutlet id dragNDropDelegate;
	IBOutlet id delegate;
	
	NSMutableArray *_cells;
	NSMutableIndexSet *_selectedCellsIndexes;
	NSUInteger _lastSelectedIndex;
	
	NSRect _selectionRect;
	NSPoint _mouseDownPoint;
	NSInteger _mouseOperation;

	@private
	BOOL _enabled;
	BOOL _ignoresMultiClick;
	BOOL _refusesFirstResponder;
	id _target;
	SEL _clickAction;
	SEL	_doubleClickAction;     
}

- (IBAction)selectAll:(id)sender;
- (IBAction)deselectAll:(id)sender;
- (IBAction)deselect:(id)sender;

- (void)awakeFromNib;

- (void)selectItemAtIndex:(NSUInteger)index;
- (void)deselectItemAtIndex:(NSUInteger)index;
- (void)toggleSelectionOfItemAtIndex:(NSUInteger)index;
- (void)selectItemsFromIndex:(NSUInteger)ancorIndex toIndex:(NSUInteger)endIndex;
- (void)selectAll;
- (void)deselectAll;
- (NSUInteger)numberOfSelectedItems;
- (NSUInteger)indexOfSelectedItem;
- (NSIndexSet *)selectedIndexes;
- (BOOL)isSelectedItemAtIndex:(NSUInteger)index;

- (NSArray *)cells;
- (NSArray *)selectedCells;
- (NSUInteger)numberOfCells;
- (NSUInteger)numberOfSelectedCells;

- (void)recalculateSizes;

- (void)clearData;
- (void)reloadData;
- (void)reloadDataAtIndex:(NSUInteger)index;

- (void)postSelectionDidChangeNotification;

- (IBAction)changeCellSizeScaleFactor:(id)sender;

- (BOOL)isEnabled;
- (void)setEnabled:(BOOL)flag;

- (BOOL)ignoresMultiClick;
- (void)setIgnoresMultiClick:(BOOL)flag;

- (BOOL)refusesFirstResponder;
- (void)setRefusesFirstResponder:(BOOL)flag;

- (id)target;
- (void)setTarget:(id)inTarget;

- (SEL)clickAction;
- (void)setClickAction:(SEL)inClickAction;

- (SEL)doubleClickAction;
- (void)setDoubleClickAction:(SEL)inDoubleClickAction;

- (BOOL) sendAction:(SEL)inAction to:(id)inTarget;

- (id)delegate;
- (void)setDelegate:(id)newDelegate;

- (id)dragNDropDelegate;
- (void)setDragNDropDelegate:(id)inDragNDropDelegate;

- (id)dataSource;
- (void)setDataSource:(id)newDataSource;

- (CGFloat)cellSizeScaleFactor;
- (void)setCellSizeScaleFactor:(CGFloat)factor;

- (BOOL)drawImageNames;
- (void)setDrawImageNames:(BOOL)value;

- (NSColor *)backgroundColor;
- (void)setBackgroundColor:(NSColor*)value;

- (NSColor *)selectionColor;
- (void)setSelectionColor:(NSColor*)value;

- (BOOL)drawShadow;
- (void)setDrawShadow:(BOOL)value;

- (BOOL)drawBorder;
- (void)setDrawBorder:(BOOL)value;

- (BOOL)hasFlexibleXCellSpacing;
- (void)setHasFlexibleXCellSpacing:(BOOL)value;

- (BOOL)allowsMultipleSelection;
- (void)setAllowsMultipleSelection:(BOOL)value;

//- (BOOL)allowsEmptySelection;
//- (void)setAllowsEmptySelection:(BOOL)value;

- (CGFloat)cellSelectionCornerRadius;
- (void)setCellSelectionCornerRadius:(CGFloat)value;

- (NSSize)cellSize;
- (void)setCellSize:(NSSize)size;

- (NSSize)minCellSize;
- (void)setMinCellSize:(NSSize)size;

- (NSSize)maxCellSize;
- (void)setMaxCellSize:(NSSize)size;

- (NSSize)cellSpacing;
- (void)setCellSpacing:(NSSize)size;

- (NSSize)cellPadding;
- (void)setCellPadding:(NSSize)size;

- (NSSize)innerCellPadding;
- (void)setInnerCellPadding:(NSSize)size;

- (NSSize)viewMargin;
- (void)setViewMargin:(NSSize)size;

- (NSRect)cellRectAtIndex:(NSUInteger)index;

@end