/*
 * PLWindowController.j
 * Tutorial-Drawing-part2
 *
 * Created by Philippe Laval on 2009/04/20.
 * Copyright 2009 Philippe Laval. All rights reserved.
 */

@import <AppKit/CPWindowController.j>

@import "PLGraphicView.j"

@implementation PLWindowController : CPWindowController
{
	PLGraphicView _graphicView;
}

- (id)init
{
	var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(100.0, 100.0, 400.0, 300.0) 
						styleMask:CPTitledWindowMask | CPResizableWindowMask | CPClosableWindowMask];
	var contentView = [theWindow contentView];
    var bounds = [contentView bounds];

	_graphicView = [[PLGraphicView alloc] initWithFrame:CGRectMake(10, 10, CGRectGetWidth(bounds) - 20, CGRectGetHeight(bounds) -20)];
    [_graphicView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];

    [contentView addSubview:_graphicView];

	[theWindow makeFirstResponder:_graphicView];
	
	
    self = [super initWithWindow:theWindow];
    if (self)
    {
    }
    
    return self;
}

-(PLGraphicView)graphicView
{
	return _graphicView;
}

-(void)setGraphicView:(PLGraphicView)graphicView
{
	_graphicView = graphicView;
}

- (CPArray)graphics 
{    
    var graphics = [[self document] graphics];
    if (!graphics) {
		graphics = [CPArray array];
    }
    return graphics;
}

- (CPIndexSet)selectionIndexes 
{
    return [[self document] selectionIndexes];
}

- (void)setSelectionIndexes:(CPIndexSet)selectionIndexes
{
	[[self document] setSelectionIndexes:selectionIndexes];
}

@end