/*
 * AppController.j
 *
 * Created by Philippe Laval on 2009/03/24.
 * Copyright 2009 Philippe Laval. All rights reserved.
 */

@import <Foundation/CPObject.j>

@import <AppKit/CPView.j>
@import <AppKit/CPColor.j>
@import <AppKit/CPGraphicsContext.j>

@import "MyView.j"
@import "MyViewWithLayer.j"
@import "MyViewWithLayerDelegate.j"
@import "MyViewWithLayerSubclassing.j"


@implementation AppController : CPObject
{
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
    var contentView = [theWindow contentView];
    var bounds = [contentView bounds];

    var myView = [[MyView alloc] initWithFrame:CGRectMake(10, 10, CGRectGetWidth(bounds) / 2.0 - 20, CGRectGetHeight(bounds) / 2.0 - 20)];
    [myView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
    [contentView addSubview:myView];

    var myView2 = [[MyView alloc] initWithFrame:CGRectMake(CGRectGetWidth(bounds) / 2.0 + 10, CGRectGetHeight(bounds) / 2.0 + 10,
    												CGRectGetWidth(bounds) / 2.0  - 20, CGRectGetHeight(bounds) / 2.0 - 20)];
    [myView2 setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
    [contentView addSubview:myView2];

    [theWindow orderFront:self];

   [self showWindow1];
   [self showWindow2];
   [self showWindow3];

}

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

    var myView = [[MyViewWithLayer alloc] initWithFrame:CGRectMake(10, 10, CGRectGetWidth(bounds) - 20, CGRectGetHeight(bounds) - 20)];
    [myView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
    [contentView addSubview:myView];
        
    [theWindow setTitle:@"MyViewWithLayer"];
    [theWindow orderFront:self];
}

- (void)showWindow2
{
    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(20.0, 40.0, 400.0, 300.0) styleMask:CPTitledWindowMask | CPResizableWindowMask | CPClosableWindowMask];
    var contentView = [theWindow contentView];
    var bounds = [contentView bounds];

    var myView = [[MyViewWithLayerDelegate alloc] initWithFrame:CGRectMake(10, 10, CGRectGetWidth(bounds) - 20, CGRectGetHeight(bounds) - 20)];
    [myView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
    [contentView addSubview:myView];
        
    [theWindow setTitle:@"MyViewWithLayerDelegate"];
    [theWindow orderFront:self];
}

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

    var myView = [[MyViewWithLayerSubclassing alloc] initWithFrame:CGRectMake(10, 10, CGRectGetWidth(bounds) - 20, CGRectGetHeight(bounds) - 20)];
    [myView setAutoresizingMask:CPViewHeightSizable | CPViewWidthSizable];
    [contentView addSubview:myView];
        
    [theWindow setTitle:@"MyViewWithLayerSubclassing"];
    [theWindow orderFront:self];
}


@end

