// Cocoa variant of the "minimal" demo originally written for Carbon
// Nibless application 
// By Ingemar 2009

program CocoaMinimal;
{$mode objfpc}
{$modeswitch objectivec1}

uses
	ctypes, MacOSAll, CocoaAll;

// -------------------- View ------------------------

type TestView = objcclass(NSView)
	public
	procedure drawRect (rect: NSRect); override;
	procedure windowWillClose (note: NSNotification); message 'windowWillClose:';
  end;

var
	NSApp: NSApplication;
	view: NSView;

procedure TestView.drawRect (rect: NSRect);
var
	p1: NSPoint = (x: 100; y: 100);
	p2: NSPoint = (x: 200; y: 200);
begin
	NSBezierPath.strokeLineFromPoint_toPoint(p1, p2);
end;

procedure TestView.windowWillClose (note: NSNotification);
begin
	NSApp.terminate(NSApp);
end;

// ------------------ Main program ---------------------

var
	pool: NSAutoreleasePool;
	window: NSWindow;
	frame: NSRect = (origin:(x: 10; y: 1000); size:(width: 400; height: 400));
begin
	pool := NSAutoreleasePool.new;
	NSApp := NSApplication.sharedApplication;
	
	window := NSWindow.alloc;
	window.initWithContentRect_styleMask_backing_defer(frame,
		NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask,
		NSBackingStoreBuffered, LongBool(0));
	window.setTitle(NSSTR('Minimal (Cocoa)'));
	
	view := TestView.alloc;
	view.initWithFrame(frame);
	window.setContentView(view);
	window.setDelegate(view);
	window.makeKeyAndOrderFront(nil);

	// Main loop
	NSApp.run;
	pool.dealloc; // Free;
end.
