/* 
   drop.m

   Drop site for Drag 'n Drop

   Copyright (C) 1999 Free Software Foundation, Inc.

   Author:	Felipe A. Rodriguez <far@ix.netcom.com>
   Date:	March 1999
   
   This file is part of the mySTEP Library and is provided
   under the terms of the GNU Library General Public License.
*/ 

#include <Foundation/NSArray.h>
#include <AppKit/AppKit.h>
#include <AppKit/NSDragging.h>


@interface NSApplication (AppIconWindow)

- (NSWindow*) appIcon;

@end

@implementation NSApplication (AppIconWindow)

- (NSWindow*) appIcon						{ return _appIconWindow; }

@end


@interface Controller : NSObject
{
	NSMutableArray *imageArray;
	int index;
	BOOL cycled;
}

@end


@implementation Controller

- (void) method:menuCell
{
	NSLog (@"method invoked from cell with title '%@'", [menuCell title]);
}

- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
	[NSApp setApplicationIconImage:[NSImage imageNamed:@"g0.tiff"]];
	[[NSApp appIcon] setDelegate:self];
	[[[NSApp appIcon] contentView] registerForDraggedTypes:nil];

	imageArray = [NSMutableArray new];		// produce an image objects array
	[imageArray addObject: [NSImage imageNamed:@"g0"]];		// open
	[imageArray addObject: [NSImage imageNamed:@"g20"]];	// open
	[imageArray addObject: [NSImage imageNamed:@"g21"]];
	[imageArray addObject: [NSImage imageNamed:@"g22"]];
	[imageArray addObject: [NSImage imageNamed:@"g23"]];
	[imageArray addObject: [NSImage imageNamed:@"g24"]];	// clos
	[imageArray addObject: [NSImage imageNamed:@"g4"]];
	[imageArray addObject: [NSImage imageNamed:@"g4"]];
	[imageArray addObject: [NSImage imageNamed:@"g4"]];
}

- (void) fireAnimator:sender
{
	if(cycled)
		index--;
	else
		index++;

	NSDebugLog (@"fireAnimator counter at %d", index);
	[NSApp setApplicationIconImage:[imageArray objectAtIndex:index]];

	if(index >= 8)
		cycled = YES;
	
	if(cycled && index == 0)
		{
		[sender invalidate];
		cycled = NO;
		}
}

- (BOOL) performDragOperation:(id <NSDraggingInfo>)sender
{
	NSDebugLog (@"performDragOperation");
	[NSTimer scheduledTimerWithTimeInterval: 0.2
			 target: self
			 selector: @selector(fireAnimator:)
			 userInfo: nil
			 repeats: YES];

	return YES;
}

- (unsigned int) draggingUpdated:(id <NSDraggingInfo>)sender
{
	return NSDragOperationGeneric;
}

@end
