//
//  MSBasicInkDataSource.h
//  SimpleInkableView
//
//  Created by Raleigh Ledet on 3/3/07.
//  Copyright 2007 Mage Software. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@class MSInkableView;

// This is complete implementation of the MSInkableViewDataSource protocal.
// It can do quite a bit for you. You may only need to subclass parts of it.
// Or encapsulate it in an arry inside your own data source to make multiple pages.

@interface MSBasicInkDataSource : NSObject {
	NSMutableArray *_objects;
	NSMutableArray *_locations;
	
	NSUndoManager *_undoMgr;
}

// A binary data representation of the data to store in a file, database, etc... Pass back to -setData: recreate the data.
-(NSData*)data;

// Delete any existing data, replacing it with the passed in binary data. (This data should come from a  an otherwise previous call to -data;
-(void)setData:(NSData*)data;

// Returns the all the recognized ink (and text) in one NSString.
-(NSString*)stringValue;

// Returns all the recognized ink (and text) and sketch objects (as images) in one NSAttributed string.
-(NSAttributedString*)attributedStringValue;

// Returns an image of all the objects in the data source
// Note: the image size is the size of the bounding rectangle of the objects (not the inkable view frame). Thus, it is not useful to use this as a static replacement for an MSInkableView when the frame of the InkableView is required to line things up properly.
-(NSImage*)image;

// Extactly that. Deletes all data.
-(void)deleteAllData;

// Set the Undo Manager here and the data source will handle undo for you.
// Note: Unfortunatly, this data source does not know who it's parent inkable view is. So it is left as an excersize to the reader on how to get the appropriate inkable view to redraw itself.
-(void)setUndoManager:(NSUndoManager*)undoMgr;
-(NSUndoManager*)undoManager;

// KVO Compliance
- (unsigned int)countOfObjects;
- (id)objectInObjectsAtIndex:(unsigned int)index;
- (void)insertObject:(id)obj inObjectsAtIndex:(unsigned int)index;
- (void)removeObjectFromObjectsAtIndex:(unsigned int)index;

- (unsigned int)countOfLayouts;
- (id)objectInLayoutsAtIndex:(unsigned int)index;
- (void)insertObject:(NSValue *)layout inLayoutsAtIndex:(unsigned int)index;
- (void)removeObjectFromLayoutsAtIndex:(unsigned int)index;

// Ease of Use Accessors
- (NSRect)layoutOfObjectAtIndex:(int)idx;
- (void)setLayout:(NSRect)layout ofObjectAtIndex:(int)idx;
- (NSPoint)locationOfObjectAtIndex:(int)idx;
- (void)setLocation:(NSPoint)loc ofObjectAtIndex:(int)idx;
- (NSSize)sizeOfObjectAtIndex:(int)idx;
- (void)setSize:(NSSize)size ofObjectAtIndex:(int)idx;
- (unsigned int)indexOfObject:(id)object;
- (id)objectAtIndex:(int)idx;

// -insertObject:withLayout:atInded is the funnel method for object insertion. All other methods that add to the object array are for convenience and they funnel through here.
- (void)insertObject:(id)obj withLayout:(NSRect)layout atIndex:(int)idx;
- (void)addObject:(id)obj withLayout:(NSRect)layout;

// -removeObjectAtIndex: is the funnel method for object removal. All other methods that remove from the object array are for convenience and they funnel through.
- (void)removeObjectAtIndex:(int)idx;
- (void)removeObject:(id)obj;
- (void)removeObjectsInArray:(id)objs;
@end

// The standard MSInkableViewDataSource methods.
@interface MSBasicInkDataSource(MSInkableViewDataSource)
- (int)numberOfObjectsInInkableView:(MSInkableView *)inkableView;
- (NSRect)inkableView:(MSInkableView *)inkableView boundsOfObjectAtIndex:(int)idx;
- (NSPoint)inkableView:(MSInkableView *)inkableView locationOfObjectAtIndex:(int)idx;
- (void)inkableView:(MSInkableView *)inkableView setLocation:(NSPoint)loc ofObjectAtIndex:(int)idx;
- (NSSize)inkableView:(MSInkableView *)inkableView sizeOfObjectAtIndex:(int)idx;
- (void)inkableView:(MSInkableView *)inkableView setSize:(NSSize)size ofObjectAtIndex:(int)idx;
- (id)inkableView:(MSInkableView *)inkableView objectAtIndex:(int)idx;

- (void)inkableView:(MSInkableView *)inkableView addObject:(id)obj atLocation:(NSPoint)loc;
- (void)inkableView:(MSInkableView *)inkableView insertObject:(id)obj
												 atLocation:(NSPoint)loc
												 atIndex:(UInt32)idx;
- (void)inkableView:(MSInkableView *)inkableView removeObject:(id)obj;
- (void)inkableView:(MSInkableView *)inkableView removeObjectsInArray:(NSArray*)objs;

// Drag -n- Drop
// This data source supports dragging and dropping of Images, Image files, text, and native Ink objects.
- (BOOL)inkableView:(MSInkableView *)inkableView writeObjects:(NSArray*)objs
												 toPasteboard:(NSPasteboard*)pboard;

- (NSDragOperation)inkableView:(MSInkableView *)inkableView validateDrop:(id <NSDraggingInfo>)info;

- (BOOL)inkableView:(MSInkableView *)inkableView acceptDropFromPasteBoard:(NSPasteboard*)pboard
												 atLoc:(NSPoint)loc;

@end

extern NSString *MSInkLocPboardType;
