/* Copyright (c) 2004, Noah Sorscher
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 	¥ 	Redistributions of source code must retain the above copyright
 * 	notice, this list of conditions and the following disclaimer.
 * 	¥ 	Redistributions in binary form must reproduce the above copyright
 * 	notice, this list of conditions and the following disclaimer in the
 * 	documentation and/or other materials provided with the distribution.
 * 	¥ 	Neither the name of the Noah Sorscher nor the names of its
 * 	contributors may be used to endorse or promote products derived from
 * 	this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */
/* MHSprite */

#import <Cocoa/Cocoa.h>
#import "Movies.h"
//#import "MHSpriteTrack.h"
#import "MHChapters.h"
#import "MHMovie.h"
#import "Object.h"
#import "MHTableView.h"


typedef enum {
    gotoTime, // by TimeValue
    gotoTimeAndPlay,
    gotoTimeByName, // also plays
    setAudioTrack, // by track number, not the number of audio tracks
    setAudioTrackByName, // applies to all tracks by that name
    setTextTrack, // ditto audio track stuff, -1 for the value to turn off all text tracks
    setTextTrackByName,
    gotoBeginning,
    gotoEnd,
    stepForward,
    stepBackward
} MHSpriteAction;


@interface NSMovie(MHSAdditions)

- (void)setMenu:(id)menu;
- (id)menu;

@end

@interface MHSprite : NSObject
{
    IBOutlet id spriteMovieView;
    IBOutlet id bgColor, theOutline, theImageView, setImageButton, viewImageButton, imageSelect, imageType, actionType, actionValue;
    IBOutlet id spriteWindow, inspectorWindow;
    IBOutlet id progBar, progWindow, progText;
    IBOutlet id alwaysDelete, byNumber, moreButton, moreDrawer, preloadSize;
    IBOutlet id transparencyColor, transparencySwitch, visibleSwitch;
    IBOutlet id loopSwitch;
    IBOutlet id loadTemplateButton, saveTemplateButton, wizSize;
    IBOutlet id qScriptBox;
    
    //NSMutableArray *tracks;
    NSSize naturalSize;
    BOOL cancelled;
    NSString *workingPath;
    NSMenuItem *quickModeMenu;
    NSLock *loadLock;
    NSTask *updateTask;
}
+ (id)nibInstance;
- (void)postUpdate:(NSString *)string done:(double)done;
+ (id)goWithMovie:(NSMovie *)aMovie;
- (void)populateMenu:(NSMenu *)aMenu;
+ (void)setX:(int)x Y:(int)y;
+ (NSColor *)bgColor;
+ (NSSize)naturalSize;
+ (id)selectedItem;
+ (int)selectedImage;
+ (void)selectItem:(id)item;
+ (void)reloadOutline;
+ (BOOL)qsMode;
+ (void)newSpriteWithRect:(NSRect)rect;
+ (NSMenu *)rightClickMenu;
- (NSMenu *)rightClickMenu;
- (void)newSpriteWithRect:(NSRect)rect;
- (BOOL)qsMode;
- (void)reload;
- (void)selectItem:(id)item;
- (id)selectedTableItem;
- (NSSize)size;
- (NSColor *)color;
- (IBAction)setColor:(id)sender;
- (IBAction)setImage:(id)sender;
- (NSImage *)imageFromFrame:(TimeValue)time height:(int)height;
- (NSImage *)imageFromFrame:(TimeValue)time height:(int)height movie:(MHMovie *)movie;
- (NSImage *)imageFromFrame:(TimeValue)time height:(int)height movieURL:(NSURL *)url;
- (NSMutableDictionary *)newMenu;
- (IBAction)newPage:(id)sender;
- (IBAction)deletePage:(id)sender;
- (NSMutableDictionary *)duplicate:(id)sender;
- (IBAction)newSprite:(id)sender;
- (IBAction)updateMovie:(id)sender;
-(NSMutableDictionary *)plist:(NSDictionary *)input;
- (NSString *)stringClass:(id)input;
- (int)getTrackNumber:(NSString *)trackName;
//- (void)updateMovieThreaded;
- (void)setMovieToSize:(NSSize)size;
- (IBAction)done:(id)sender;
- (IBAction)dump:(id)sender;
- (IBAction)more:(id)sender;
- (IBAction)quickMode:(id)sender;
- (IBAction)savePrefs:(id)sender;
- (IBAction)transparencySwitch:(id)sender;
- (IBAction)visibleSwitch:(id)sender;
- (IBAction)loopSwitch:(id)sender;
- (void)prefs:(int)flag;
- (void)restorePrefs;
- (IBAction)deleteSpriteTracks:(id)sender;
- (IBAction)updateWidgets:(id)sender;
- (void)syncWidgets:(NSMutableDictionary *)sprite;
- (NSArray *)pageNumbers;
- (IBAction)updateData:(id)sender;
- (NSString *)stringForAction:(int)type value:(NSString *)value;
- (IBAction)selectActionType:(id)sender;
- (IBAction)setAction:(id)sender;
- (IBAction)selectActionValue:(id)sender;
- (IBAction)viewFrame:(id)sender;
- (IBAction)setBackground:(id)sender;
- (IBAction)wizard:(id)sender;
- (void)wizardThreaded;
- (IBAction)cancel:(id)sender;
- (IBAction)loadTemplate:(id)sender;
- (IBAction)saveTemplate:(id)sender;
- (BOOL)writeSpriteTemplate:(NSDictionary *)sprite toPath:(NSString *)path;
- (BOOL)readSpriteTemplateFromPath:(NSString *)path toSprite:(NSMutableDictionary *)aSprite;

- (NSMutableDictionary *)addPageWithChapters:(MHChapters *)ch startingAt:(int)index count:(int)count;
- (void)addNavButton:(NSString *)nav destination:(TimeValue)dest;
- (NSArray *)getTracksOfType:(OSType)type;

- (void)awakeFromNib;
- (IBAction)customizeToolbar:(id)sender;
- (void)open;
- (void)setMovie:(NSMovie *)aMovie;
- (NSRect)rightSize;
- (void)iSetX:(int)x Y:(int)y;


// OutlineView Use
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item;
//- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item;
- (void)outlineViewSelectionDidChange:(NSNotification *)notification;
//- (void)selectItem:(id)item;
//- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item;
//- (void)expandItem:(id)item;
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;

@end
