/*
        SlideShowMenu.m

	SlideShowMenu.m : This file is part of SlideShow

	Copyright (C) 2004 Fabien VALLON
	Additional copyrights here

	Authors: Fabien VALLON <fabien.vallon@fr.alcove.com>
	Date:	15 October 2004

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License as
	published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

	See the GNU General Public License for more details.

	You should have received a copy of the GNU General Public
	License along with this program; if not, write to:

		Free Software Foundation, Inc.
		59 Temple Place - Suite 330
		Boston, MA  02111-1307, USA
*/

#include "SlideShowMenu.h"


#include <AppKit/NSButton.h>
#include <AppKit/NSButtonCell.h>
#include <AppKit/NSImage.h>
#include <AppKit/NSMatrix.h>

#include <Foundation/NSGeometry.h>
#include <AppKit/NSBezierPath.h>
#include <AppKit/NSGraphics.h>


@interface ButtonCell : NSButtonCell
{
   NSImage *_image;
}
@end

@implementation ButtonCell

 -(BOOL) isOpaque 
 {
   return NO;
}

-(void) setImage: (NSImage *) image
{
  _image = image;
}

-(NSImage *) image
{
  return _image;
}

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
  NSPoint position = NSMakePoint(4,4);
  [[self image] compositeToPoint: position 
		operation: NSCompositeSourceOver];
}
@end



@implementation SlideShowMenu

-(BOOL) isOpaque
{
  return NO;
}

-(void) drawRect:(NSRect) aRect
{
   NSColor *blackColor = [NSColor blackColor];
   float width =  aRect.size.width;
   float height =  aRect.size.height;
   NSBezierPath *bezierPath = [NSBezierPath  bezierPath];
   [bezierPath setLineWidth:8.0];

   [bezierPath moveToPoint: NSMakePoint (0.0,0.0)];
   [bezierPath lineToPoint: NSMakePoint(0.0, height)];

   [bezierPath moveToPoint: NSMakePoint (0.0,0.0)];
   [bezierPath lineToPoint: NSMakePoint(width, 0.0)];

   [bezierPath moveToPoint: NSMakePoint (width,0.0)];
   [bezierPath lineToPoint: NSMakePoint(width,height)];

   [bezierPath moveToPoint: NSMakePoint (0.0,height)];
   [bezierPath lineToPoint: NSMakePoint(width,height)];

   
   

   [blackColor set];
   [bezierPath stroke];

   [[NSColor colorWithDeviceRed:0.32 green:0.32 blue:0.32 alpha:0.5] set];
   NSRectFill (aRect);

}

-(void) addItemAtIndex:(unsigned int) index
	     withImage: (NSImage *) image
	alternateImage: (NSImage *) altImage
		target:(id) target
	      selector:(SEL) selector

{
  unsigned int startX = (index * 100) + 10;
  id cell = [[ButtonCell alloc] init];
  
  NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(startX,10,64,64)];
  [button setCell: cell];
  [button setBordered:NO];
  [button setImage:image];
  [button setAlternateImage:altImage];
  [button setTarget:target];
  [button setAction:selector];
  
  [self addSubview:button];  
  [self setFrame:NSMakeRect(300,300,startX+100,100)];
  [self setNeedsDisplay:YES];
}


@end
