/* 
   PXKApplication.m

   NSApplication for GNUstep GUI X/DPS Backend

   The NSApplication class manages the main event loop of
   the program, keeps track of the application's windows
   and which one is the key window.

   Copyright (C) 1996 Free Software Foundation, Inc.

   Author:  Pascal Forget <pascal@wsc.com>
   Date: January 1996
   
   This file is part of the GNUstep GUI X/DPS Backend.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   If you are interested in a warranty or support for this source code,
   contact Scott Christley <scottc@net-community.com> for more information.
   
   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ 

#include <gnustep/xdps/PXKApplication.h>
#include <gnustep/xdps/PXKEventFactory.h>

//NSWindow *keyWindow;
//NSWindow *mainWindow;
 
static char *progname; /* name this program was invoked by */

//NSMutableArray *_allWindows; /* The app's windows are registered */

#if 0
/*
 * Current event settings stored here as we don't want to
 * waste CPU cycles creating / destroying these variables
 * each time we go through a cycle in the event loop
 */
XEvent xEvent;
NSEvent *_currentEvent;
NSEventType eventType;
unsigned short eventModifierFlags;
NSPoint eventLocation;
unsigned int eventFlags;
NSTimeInterval eventTime;
KeySym keysym;
unsigned short keyCode;
#endif

#define pxkArrowSize 9

@implementation PXKApplication

- createSystemImages;
{
#if 0
    NSImage *im;
    NSSize size;
    
    [NSImage initialize];

    size.width = NSArrowSize;
    size.height= NSArrowSize;
    
    im = [[NSImage alloc] initWithSize:&size];
    [im setName:"NSRightArrow"];
    [im buildImageFromString:_NSRightArrow];

    im = [[NSImage alloc] initWithSize:&size];
    [im setName:"NSLeftArrow"];
    [im buildImageFromString:_NSLeftArrow];

    im = [[NSImage alloc] initWithSize:&size];
    [im setName:"NSDownArrow"];
    [im buildImageFromString:_NSDownArrow];

    im = [[NSImage alloc] initWithSize:&size];
    [im setName:"NSUpArrow"];
    [im buildImageFromString:_NSUpArrow];

    im = [[NSImage alloc] initWithSize:&size];
    [im setName:"NSDimple"];
    [im buildImageFromString:_NSDimple];
#endif
    return self;
}

- loadObjectArchive:(const char *)path
{
  return nil;
}

- init;
{
    [super init];
    [self createSystemImages];

    return self;
}

@end

//
// GNUstep Backend methods
//
@implementation PXKApplication (GNUstepBackend)

// Get next event
- (NSEvent *)getNextEvent
{
  NSEvent *e;
  e = nextEvent();
  [event_queue enqueueObject: e];
  NSLog(@"Event is for window %d\n", [e windowNumber]);

  return e;
}

// handle a non-translated event
- (void)handleNullEvent
{}

@end

@implementation PXKApplication (NonOpenStep)

- (void)registerWindow:(NSWindow *)newWindow;
{
    [window_list addObject:newWindow];
}

- (void)removeWindow:(NSWindow *)defunctWindow;
{
    [window_list removeObject:defunctWindow];
}

- (void)updateKeyAndMainWindow;
{
    NSWindow *keyWindow = [self keyWindow];

#ifdef NSPANEL_H__
    if ([keyWindow isKindOfClass:[NSPanel class]] == NO) {
	main_window = keyWindow;
    }
#else /* class NSPanel not implemented yet */
    if (YES) {
	main_window = keyWindow;
    }
#endif
}

@end
