/*
 *     Generated by the NeXT Interface Builder.
 * 
 * History:
 *	27 Feb 91	Modified TBL to initialise NXArgv early on
 *	19 Mar 91	Page info deafults
 */

#import <stdlib.h>
#import <appkit/Application.h>
// #import <appkit/defaults.h>			/* TBL */
#import "HTUtils.h"				/* TBL */
#import <string.h>				/* TBL */
#import <libc.h>				/* TBL */
#import <appkit/PrintInfo.h>			/* TBL */
#import <appkit/defaults.h>			/* TBL */

extern char * appDirectory;	/* Name of the directory containing the application */

/*	Get Integer default value
*/
static int int_default(const char * param)
{
    int	result = 0;
    const char * string = NXGetDefaultValue("WorldWideWeb", param);
    if (string) sscanf(string, "%i", &result);
    return result;
}

void main(int argc, char *argv[])
{
//    NXArgc = argc;		/* TBL */
//    NXArgv = argv;		/* TBL */

    char *p;
    
    static NXDefaultsVector myDefaults = {
        { "PaperType", "Letter"},		// Non-USA users will have to override
	{ "LeftMargin", "72"},			//  (72) Space for ring binding
	{ "RightMargin", "36"},			//  (72) Note printers need some margin 
	{ "TopMargin", "36"},			// (108) All margins in points
	{ "BottomMargin", "36"},		// (108) PrintInfo defaults in brackets
	{ NULL, NULL}				// Terminate list.
    };
    
    
    appDirectory = malloc(strlen(argv[0]));
    strcpy(appDirectory, argv[0]);
    if (p = strrchr(appDirectory, '/')) p[1]=0;	/* Chop home directory after slash */
    if (TRACE) printf("WWW: Run from %s\n", appDirectory);

    NXApp = [Application new];
    NXRegisterDefaults("WorldWideWeb", myDefaults);
    [NXApp loadNibSection:"WorldWideWeb.nib" owner:NXApp];

//	The deafult Margins seem to be 72, 72, 108, 108 which is a lot.    
    {
	int leftM = int_default("LeftMargin");
	int rightM = int_default("RightMargin");
	int topM = int_default("TopMargin");
	int bottomM = int_default("BottomMargin");
	
        PrintInfo * pi = [NXApp printInfo];
        [pi setPaperType:NXGetDefaultValue("WorldWideWeb", "PaperType") andAdjust:YES];
	[pi setVertCentered:NO];
	[pi setMarginLeft:leftM right:rightM top:topM bottom:bottomM]; // Points.
    }
    
    [NXApp run];
    [NXApp free];
    exit(0);
}
