/*  Little.m

A minimal program from Chapter 7 of the NeXT System Reference Manual.
It has one standard window that you can type in, a main menu with just
the three basic commands, and an empty information panel that contains
no information.  Nevertheless, all three windows behave exactly as
they would in a more elaborate application.

Updated for OpenStep by Pascal Bourguignon <pjb@imaginet.fr>.
*/


#include <AppKit/AppKit.h>
#include <Foundation/Foundation.h>

@interface SetUp:NSObject
    -(id)init;
    -(void)doSetUp:sender;
@end //SetUp;


@implementation SetUp

    -(id)init
    {
        self=[super init];
        if(self!=nil){
            [[NSNotificationCenter defaultCenter] addObserver:self
                selector:@selector(doSetUp:) 
                name:NSApplicationDidFinishLaunchingNotification
                object:nil];
        }
        return(self);
    }//init;


    -(void)doSetUp:sender
    {
    id   myWindow, myPanel, myMenu, item, windowText, button;
    NSRect   aRect;


    /*** Step 1:  Set up a Window ***/
    aRect=NSMakeRect(100.0, 250.0, 300.0, 300.0);
    myWindow = [[NSWindow alloc]
                 initWithContentRect:aRect
                 styleMask:NSTitledWindowMask
                          |NSClosableWindowMask
                          |NSMiniaturizableWindowMask
                 backing:NSBackingStoreBuffered
                 defer:NO];
    [myWindow setTitle:@"A Little Demonstration"];

    aRect=NSMakeRect(0.0, 0.0, 300.0, 300.0);
    windowText = [[NSText alloc] initWithFrame:aRect];
//  [windowText setOpaque:YES];
    [windowText setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
    [[myWindow contentView] addSubview:windowText];


    /*** Step 2:  Set up a Panel ***/
    aRect=NSMakeRect( 100.0, 200.0, 300.0, 100.0);
    myPanel = [[NSPanel alloc]
                 initWithContentRect:aRect
                 styleMask:NSTitledWindowMask|NSClosableWindowMask
                 backing:NSBackingStoreBuffered
                 defer:YES];
    [myPanel setTitle:@"About Little"];
//  [myPanel removeFromEventMask:(NS_KEYDOWNMASK | NS_KEYUPMASK)];
    button=[[NSButton alloc]initWithFrame:NSMakeRect(50.0,25.0,200.0,50.0)];
    [button setTitle:@"Little"];
    [button setTarget:myPanel];
    [button setAction:@selector(performClose:)];
    [button setAutoresizingMask:NSViewMinXMargin|NSViewMaxXMargin
                                |NSViewMinYMargin|NSViewMaxYMargin];
    [[myPanel contentView]addSubview:button];

    /*** Step 3:  Set up a Menu ***/
    myMenu = [[NSMenu alloc] initWithTitle:@"Little"];

    item=[myMenu addItemWithTitle:@"Info..."
             action:@selector(orderFront:)
             keyEquivalent:nil];
    [item setTarget:myPanel];
    [item setEnabled:YES];

    item=[myMenu addItemWithTitle:@"Hide"
            action:@selector(hide:)
            keyEquivalent:@"h"];
    [item setEnabled:YES];

    item=[myMenu addItemWithTitle:@"Quit"
            action:@selector(terminate:)
            keyEquivalent:@"q"];
    [item setEnabled:YES];

    [myMenu sizeToFit];
    [NSApp setMainMenu:myMenu];


    /*** Step 4:  Display all windows that aren't deferred ***/
    [myWindow display];


    /*** Step 5:  Move myWindow on-screen ***/
    [myWindow orderFront:nil];


    /*** Step 6:  Make it the key window ***/
    [myWindow makeKeyWindow];


    /*** Step 7:  Show a selection in the key window ***/
    [windowText selectAll:nil];
    }//doSetUp:;

@end // SetUp;




int main(void)
{
    extern BOOL initialize_gnustep_backend(void);
    NSAutoreleasePool* pool=[NSAutoreleasePool new];
    (void)initialize_gnustep_backend();
    (void)[NSApplication sharedApplication];
    (void)[[[SetUp alloc]init]autorelease];
    [NSApp run];
    [pool release];
    return(0);
}//main;


/*** Little.m                         -- 2003-12-27 07:55:19 -- pascal   ***/
