//
//  pqImageBrowser.h
//  plasqKit
//
//  Created by Robert Grant on Tue Sep 14 2004.
//  Copyright (c) 2006 plasq. All rights reserved.
//

#import <AppKit/AppKit.h>

typedef enum { pqImageBrowserDropOn, pqImageBrowserDropAbove } pqImageBrowserDropOperation;

@interface pqImageBrowser : NSControl {

	IBOutlet id m_delegate;
	IBOutlet id m_dataSource;

	id			m_target;
	SEL			m_action;
	SEL			m_doubleAction;
	
	NSMutableIndexSet*  m_selectedItems;
	NSMutableArray*		m_cachedImages;

	int			m_columns;
	float		m_columnWidth;
	float		m_cellWidth;
	int			m_rows;
	float		m_zoom;
	BOOL		m_drawShadow;
	NSColor*	m_bgColor;
	float		m_dragAlpha;
	BOOL		m_showTitles;
}

- (void)reloadData;

- (void)setZoom:(float)zoom; // zoom level of 1 means show 1 column in the entire width of the view.
- (float)zoom;

- (void)setShowsTitles:(BOOL)showTitles;

- (void)setShadow:(BOOL)shadow;

+ (void)setTitleFont:(NSFont*)font;

- (void)selectItemAtIndex:(int)index;
- (int)selectedItem;

- (void)deselectAll:(id)sender;
- (void)resetToTop:(id)sender;

- (IBAction)setZoomLevel:(id)sender;

- (void)setTarget:(id)target;
- (void)setAction:(SEL)action;
- (void)setDoubleClickAction:(SEL)action;
- (void)setDragAlpha:(float)alpha;

@end

@interface NSObject (pqImageBrowserDataSource)


- (int)numberOfItemsInBrowser:(pqImageBrowser*)ib;

- (NSImage*)imageBrowser:(pqImageBrowser*)ib imageForItemAtIndex:(int)index;
- (NSString*)imageBrowser:(pqImageBrowser*)ib nameForItemAtIndex:(int)index;


@end

@interface NSObject (pqImageBrowserDelegate)

- (BOOL)imageBrowser:(pqImageBrowser*)ib itemAtIndexIsDraggable:(int)index;

// optional - drag and drop support
- (BOOL)imageBrowser:(pqImageBrowser *)ib writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
    // This method is called after it has been determined that a drag should begin, but before the drag has been started.
	// To refuse the drag, return NO.
	// To start a drag, return YES and place the drag data onto the pasteboard (data, owner, etc...).
	// The drag image and other drag related information will be set up and provided by the matrix once this call returns with YES. 
	// The cells array is the list of cells that will be participating in the drag.

- (NSDragOperation)imageBrowser:(pqImageBrowser*)ib validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedColumn:(int)column proposedDropOperation:(pqImageBrowserDropOperation)op;
    // This method is used by DraggableMatrix to determine a valid drop target.
	// Based on the mouse position, the matrix will suggest a proposed drop location.
	// This method must return a value that indicates which dragging operation the data source will perform.
	// The data source may "re-target" a drop if desired by calling setDropRow:dropOperation: and returning something other than NSDragOperationNone.
	// One may choose to re-target for various reasons (eg. for better visual feedback when inserting into a sorted position).

- (BOOL)imageBrowser:(pqImageBrowser*)ib acceptDrop:(id <NSDraggingInfo>)info row:(int)row column:(int)column  dropOperation:(pqImageBrowserDropOperation)op;
    // This method is called when the mouse is released over an outline view that previously decided to allow a drop via the validateDrop method.
	// The data source should incorporate the data from the dragging pasteboard at this time.

@end
