/*
 * GToolKit - Objective-C interface to the GIMP Toolkit
 * Copyright (c) 1998, 1999, 2000  Elmar Ludwig
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef GTOOLKIT_GTKAPPLICATION_H
#define GTOOLKIT_GTKAPPLICATION_H

#include <GToolKit/GTKMain.h>

@class NSException, NSNotificationCenter;
@class GTKWindow;

#define GTKRunStoppedResponse	0

/*
 * Display a modal message box or alert panel with up to 3 buttons and
 * a format string. Return value is n-1 if button number n is clicked.
 */
extern int GTKRunMessageBox (NSString *title, NSString *format,
			     NSString *button1, NSString *button2,
			     NSString *button3, /* format args */...);

/*
 * Notification strings
 */
extern NSString *GTKApplicationDidBecomeActiveNotification;
extern NSString *GTKApplicationDidFinishLaunchingNotification;
extern NSString *GTKApplicationDidResignActiveNotification;
extern NSString *GTKApplicationWillFinishLaunchingNotification;
extern NSString *GTKApplicationWillTerminateNotification;

/*
 * The GTKApplication class controls the running application, and exactly
 * one instance of this class must be created when the program starts. This
 * GTKApplication object is globally accessible through the variable GTKApp!!,
 * so there is no need to pass it as an argument to method calls.<p>
 * Most of the methods of GTKApplication are implemented in its base class
 * @GTKMain, so look there for additional methods to control the event loop.
 */
@interface GTKApplication : GTKMain
{
    id delegate;		    // delegate of the application object
    NSNotificationCenter *center;   // default notification center of this task
    NSMutableArray *windows;	    // application's window list
    GTKWindow *volatile mainWindow; // application's main window
@private
    volatile int modalCode;	    // return code of the current event loop
}

/* initializing the application object */
+ (GTKApplication *) sharedApplication;
- (id) initWithArgc:(int *) argc argv:(char ***) argv;
- (void) finishLaunching;
- (void) setDelegate:(id) delegate;
- (id) delegate;

/* controlling the event loop */
- (void) run;
- (BOOL) isRunning;
- (int) runModalForWindow:(GTKWindow *) window;
- (void) stopModal;
- (void) stopModalWithCode:(int) code;
- (void) stop:(id) sender;
- (void) terminate:(id) sender;
- (void) reportException:(NSException *) exception;

/* managing the window list */
- (BOOL) isActive;
- (GTKWindow *) mainWindow;
- (NSArray *) windows;
@end

/*
 * These methods may be implemented by the delegate.
 */
@protocol GTKApplicationDelegate
- (void) applicationDidBecomeActive:(NSNotification *) event;
- (void) applicationDidFinishLaunching:(NSNotification *) event;
- (void) applicationDidResignActive:(NSNotification *) event;
- (BOOL) applicationShouldTerminate:(GTKApplication *) sender;
- (BOOL) applicationShouldTerminateAfterLastWindowClosed:
	 (GTKApplication *) sender;
- (void) applicationWillFinishLaunching:(NSNotification *) event;
- (void) applicationWillTerminate:(NSNotification *) event;
@end

extern GTKApplication *GTKApp;		// the application object

#endif /* GTOOLKIT_GTKAPPLICATION_H */
