//  Created by Joe Becker on 3/7/05.
//  Copyright 2005 __MyCompanyName__. All rights reserved.

#import "ZoomScrollView.h"

@implementation ZoomScrollView

- (IBAction)changeZoom:(id)sender
{
    [self setScaleFactor:[[sender selectedCell] tag] / 100.0];
}

- (BOOL)isOpaque { return NO; }   // Because NavView is on top of map...


- initWithFrame:(NSRect)theFrame
{
    [super initWithFrame:theFrame];
	
	//FIXME: set the background color of the NSScroll to something isn't
	//FIXME: white so that we can debug the drawing that leaves lines
	//FIXME: on the screen when we scroll over view...
	
    [self setBackgroundColor:[NSColor whiteColor]];
	
    scaleFactor = 1.0;
    return self;
}



-(void) awakeFromNib
{
    [self setHasHorizontalScroller:YES];
    [self setHasVerticalScroller:YES];
    [self setBorderType:NSLineBorder];

    // Set up the zoom button
    [[zoomButton cell] setBordered:NO];
    [[zoomButton cell] setBezeled:YES];
    [[zoomButton cell] setFont:[NSFont labelFontOfSize:10.0]];
    [self addSubview:zoomButton];

    // The next 2 lines install the subview (TrackingGraphView)
    //  and set its size to be the same as the NSScrollView.
    [self setDocumentView:subView];
    [subView setFrame:[[self contentView] frame]];
	
	[self addSubview:backgroundJpeg];
	
	
	return;		//FIXME: skip the backgroundJpeg //FIXME: premature exitulation

    [backgroundJpeg setFrame:[[self contentView] frame]];
    [self addSubview:backgroundJpeg];
}




- (void)setScaleFactor:(double)aFactor
{
    if (aFactor==0) {
        NSLog(@"Illegal scale factor. Set the tag!");
        return;
    }

    if (scaleFactor != aFactor) {
        double delta = aFactor/scaleFactor;
        scaleFactor = aFactor;
        [[self contentView]
         scaleUnitSquareToSize:NSMakeSize(delta,delta)];
    }
}


- (void)tile
{
    NSRect scrollerRect, buttonRect;

    [super tile];

    // Place the pop-up button next to the scroller
    scrollerRect = [[self horizontalScroller] frame];
    NSDivideRect(scrollerRect, &buttonRect, &scrollerRect, 
                 50.0, NSMaxXEdge);
    [[self horizontalScroller] setFrame: scrollerRect];
    [zoomButton setFrame: NSInsetRect(buttonRect, 1.0, 1.0)];
}



@synthesize zoomButton;
@synthesize subView;
@synthesize backgroundJpeg;
@end

