/* 
   Controller.m

   Controller class for the mySTEP Interface Modeller

   Copyright (C) 2000 Free Software Foundation, Inc.

   Author:  Felipe A. Rodriguez <far@pcmagic.net>
   Date:	Sept 1998
  
   This file is part of the mySTEP Library and is provided
   under the terms of the GNU Library General Public License.
*/ 

#include <AppKit/AppKit.h>

#include "Controller.h"
#include "IMModelWindow.h"
#include "IMModelView.h"


@implementation Controller

- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
IMModelWindow *im_main;
NSRect wf0 = {{100, 100}, {600, 600}};
NSRect wcf0 = {{0, 0}, {600, 600}};
NSRect bf0 = {{10, 10}, {200, 50}};
NSRect bf1 = {{100, 100}, {200, 50}};
NSButton *b0, *b1;
NSView *contentView;

	user_models = [[NSMutableArray alloc] initWithCapacity: 2];
 														// Create main window
	im_main = [[IMModelWindow alloc] initWithContentRect:wf0	
									 styleMask:GSAllWindowMask		
									 backing:NSBackingStoreNonretained
									 defer:NO];
	contentView = [[IMModelView alloc] initWithFrame:wcf0];
	[im_main setContentView: contentView];
	[im_main setTitle:@"mySTEP IModel"];
	[im_main setFrame:wf0 display:YES];
	[im_main display];
	[im_main orderFront:nil];
														// create test controls
	b0 = [[NSButton alloc] initWithFrame: bf0];
	b1 = [[NSButton alloc] initWithFrame: bf1];
	[[im_main contentView] addSubview: b0];
	[[im_main contentView] addSubview: b1];
	[b0 display];

	[contentView display];
}

- (void) dealloc
{
	[user_models release];
	[super dealloc];
}

- (void) showPaintPanel:sender
{
NSRect r = {{0, 0}, {200, 200}};

	if (!paint_panel)							
		{
		paint_panel = [[NSPanel alloc] init];
		[paint_panel setFrame: r display: YES];
		[paint_panel center];
		}

	[paint_panel makeKeyAndOrderFront: sender];
}

- (id) createPalettePanel
{
NSRect pf = {{680, 510}, {270, 245}};
NSRect tf = {{10, 10}, {100, 32}};
NSRect bf = {{10, 52}, {100, 32}};
NSButton *b;

	palettePanel = [[NSPanel alloc] init];
	[palettePanel setTitle:@"Palettes"];

	b = [[NSButton alloc] initWithFrame: bf];
    [b setButtonType: NSOnOffButton];
    [b setTitle: @"Test Interface"];
    [b setTarget:self];
    [b setAction:@selector(setTestInterface:)];
	testInterface = NO;

	textfield = [[NSTextField alloc] initWithFrame: tf];
    [textfield setStringValue:@"model"];
	[[palettePanel contentView] addSubview: b];
	[[palettePanel contentView] addSubview: textfield];

	[palettePanel setFrame: pf display: NO];
	
	return palettePanel;
}

- (void) showPalettePanel:sender
{
	if (!palettePanel)									// create palette if 
		palettePanel = [self createPalettePanel];		// it doesn't exist

    [palettePanel display];
	[palettePanel makeKeyAndOrderFront: sender];
}

- (void) showInspectorPanel:sender
{
	if (!inspector_panel)
		inspector_panel = [[NSPanel alloc] init];

	[inspector_panel makeKeyAndOrderFront: sender];
}
													// Working with model files
- (void) newModelFile:sender
{
}

- (void) open:sender
{
}

- (void) closeModelFile:sender
{
}

- (void) save:sender
{
}

- (void) saveAs:sender
{
} 

- (void) method:menuCell							// temp for sake of menu
{
  	NSLog (@"method invoked from cell with title '%@'", [menuCell title]);
}

- (void) setTestInterface:(id)sender				// toggle between model and
{													// test interface modes
	NSLog (@"testInterface:");
	[textfield setStringValue:[sender intValue] ? @"test" : @"model"];
	[textfield display];
	testInterface = [sender intValue];
}

- (BOOL) testInterface
{													// return mode IM's mode
	return testInterface;							// YES == test mode
}													// NO  == model mode

@end
