/**FSWindow.c************************************************************
 *									*
 *   SeePix -- by Hank Schafer						*
 *									*
 *   SeePix is an IFF Picture Viewer.  It works with Lo-Res,		*
 *   Med-Res, Hi-Res, HAM, and EHB formats.  I'm working on support     *
 *   for X-Specs, and Anim5 formats.					*
 *									*
 *   SeePix is based on a program by Olaf Barthel, called		*
 *   'LoadImage'.  As released, LoadImage had a couple of bugs. 	*
 *   The Amiga-Key alternatives to menu use didn't all work.  That's	*
 *   been fixed.  There were two separate print functions in LoadImage	*
 *   which behaved exactly the same.  The redundancy was eliminated.	*
 *   LoadImage used the Topaz ROMFONT, and made no allowances for a	*
 *   different system default font (under 2.04).  I added a built-in	*
 *   font.  I've reworked the code considerably from the original       *
 *   release, to allow for optimizations based on time and space.	*
 *									*
 *   SeePix features a palette tool which allows "tweaking" of colors	*
 *   prior to printing, allowing you to modify the color printout to	*
 *   more closely resemble the original graphics (Blue is Blue, not	*
 *   Purple).  SeePix can be Iconified.  SeePix features an ARP 	*
 *   interface.  SeePix now uses the PathMaster File Selector.		*
 *									*
 ************************************************************************
 *                                                                      *
 *   SeePix Copyright © 1992 by Hank Schafer; all rights reserved.      *
 *                                                                      *
 *   This program is free software; you can redistribute it and/or      *
 *   modify it under the terms of the GNU General Public License as     *
 *   published by the Free Software Foundation, either version 1, or    *
 *   (at your option) any later version.                                *
 *                                                                      *
 *   This program 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  *
 *   General Public License for more details.                           *
 *                                                                      *
 *   You should have received a copy of the GNU General Public License  *
 *   along with this program; if not, write to:                         *
 *                 Free Software Foundation, Inc.                       *
 *                 675 Massachusetts Ave.                               *
 *                 Cambridge  MA  02139, USA                            *
 *                                                                      *
 **************** Special Function Copyright Notices ********************
 *									*
 ****LoadImage Copyright Notice:					*
 *									*
 *   LoadImage is © Copyright 1988, 1989, 1990 by MXM, all rights	*
 *   reserved, written by Olaf Barthel.  No guarantees of any kind are	*
 *   made that this program is 100% reliable.  Use this program on	*
 *   your own risk!							*
 *									*
 ****Iconify Copyright Notice:						*
 *									*
 *   Copyright 1987 by Leo L. Schwab.					*
 *   Permission is hereby granted for use in any and all programs,	*
 *   both Public Domain and commercial in nature, provided this 	*
 *   Copyright notice is left intact.					*
 *									*
 ****ColorWindow (Palette) Copyright Notice:				*
 *									*
 * ColorWindow Routine	--  Color Window Routines			*
 *     from Book 1 of the Amiga Programmers' Suite by RJ Mical          *
 *									*
 * Copyright (C) 1986, 1987, Robert J. Mical				*
 * All Rights Reserved. 						*
 *									*
 ****PathMaster Copyright Notice:					*
 *									*
 * -------------------------------------------------------------------- *
 *   Copyright © 1989 Justin V. McCormick.  All Rights Reserved.	*
 * -------------------------------------------------------------------- *
 *									*
 *    The PathMaster name is a trademark of Justin V. McCormick.	*
 *									*
 *   PathMaster File Selector source and documentation written by:	*
 *									*
 *			 Justin V. McCormick.				*
 *	       Copyright © 1989 by Justin V. McCormick. 		*
 *			 All Rights Reserved.				*
 *									*
 * -------------------------------------------------------------------- *
 ************************************************************************
 *									*
 *   Hope this is something you can use and enjoy.			*
 *									*
 ************************************************************************/

#ifdef	PATHMASTER

LONG
InitFSWindow()
{
    LONG            i, xinc, xleft, xmax;
    struct Gadget  *tgad;

    /* Initialize a timer device for delays */

    if (InitFSVBDelay() == 0) {
	return (0L);
    }
    /* Initialize FSWin title string */

    safestrcpy(FSWinTitleStr, FSReq->titlestr, 28L);
    (VOID) strcat(FSWinTitleStr, " ");
    fstitlelength = strlen(FSWinTitleStr);
    fserrmsgs[27] = FSReq->readingstr;
    fserrmsgs[28] = FSReq->sortingstr;
    fserrmsgs[22] = FSReq->emptydirstr;
    fserrmsgs[24] = FSReq->nomatchstr;
    fserrmsgs[29] = FSReq->selectfilestr;
    if (fserrmsgs[27] == 0)
	fserrmsgs[27] = fserrmsg27;
    if (fserrmsgs[28] == 0)
	fserrmsgs[28] = fserrmsg28;
    if (fserrmsgs[22] == 0)
	fserrmsgs[22] = fserrmsg22;
    if (fserrmsgs[24] == 0)
	fserrmsgs[24] = fserrmsg24;
    if (fserrmsgs[29] == 0)
	fserrmsgs[29] = fserrmsg29;
    if (FSReq->pathgadstr != 0)
	FSPathTxt.IText = (UBYTE *) FSReq->pathgadstr;
    else
	FSPathTxt.IText = FSPathLabelStr;
    if (FSReq->filegadstr != 0)
	FSFileTxt.IText = (UBYTE *) FSReq->filegadstr;
    else
	FSFileTxt.IText = FSFileLabelStr;

    /* Set our directory gadget names to whatever the user has out there */

    if (devList == 0) {		/* If already set, don't reset */
	if (FSGetDevs() == 0) {
	    return (0L);
	}
	SetDevGads();
    }
    /* Set Select and Cancel gadget texts */

    FSSelectTxt.IText = (UBYTE *) FSReq->selectstr;
    FSSelectTxt.LeftEdge = 37 - strlen(FSReq->selectstr) * 4;
    FSCancelTxt.IText = (UBYTE *) FSReq->cancelstr;
    FSCancelTxt.LeftEdge = 37 - strlen(FSReq->cancelstr) * 4;

    /* Center the Select, Cancel, and LastDir gadgets */

    if (FSReq->specgadstr != 0) {
	FSnw.FirstGadget = &FSUserGad;
	FSUserTxt.IText = (UBYTE *) FSReq->specgadstr;
	FSUserTxt.LeftEdge = 37 - strlen(FSReq->specgadstr) * 4;
	xleft = 4;
	xmax = 4;
	xinc = 75;
    } else {
	FSnw.FirstGadget = &FSSelectGad;
	xleft = 38;
	xmax = 3;
	xinc = 95;
    }

    tgad = FSnw.FirstGadget;
    for (i = 0; i < xmax; i++) {
	tgad->LeftEdge = xleft + i * xinc;
	tgad = tgad->NextGadget;
    }

    /* Determine which screen to open the FileSelect Window on */

    if (FSReq->userscreen == 0) {
	FSnw.Type = WBENCHSCREEN;
	FSnw.Screen = 0;
    } else {
	FSnw.Type = CUSTOMSCREEN;
	FSnw.Screen = FSReq->userscreen;
    }
    FSnw.LeftEdge = FSReq->leftedge;
    FSnw.TopEdge = FSReq->topedge;
    if (FSReq->windowflags != 0)
	FSnw.Flags = FSReq->windowflags;

    if ((FSWin = OpenWindow(&FSnw)) == 0) {
	return (0L);
    } else {

	/* Allocate/clone/initialize RastPort copy for rendering Text */

	if ((MainFont = OpenFont(&SPFont[0])) == 0)
	    return (0L);

	if ((FSRPort = (struct RastPort *) AllocMem((LONG) sizeof(struct RastPort), 0L)) == 0)
	    return (0L);
	CopyMem((BYTE *) FSWin->RPort, (BYTE *) FSRPort, (LONG) sizeof(struct RastPort));

	SetFont(FSRPort, MainFont);

	if (FSReq->initfunc != 0)
	    (VOID) (FSReq->initfunc) (FSReq, FSWin);

	FSSignal = 1L << FSWin->UserPort->mp_SigBit;
	FSSignalMask = FSSignal;
	if (FSReq->userport != 0 && FSReq->userfunc != 0) {
	    FSUserSignal = 1L << FSReq->userport->mp_SigBit;
	    FSSignalMask |= FSUserSignal;
	} else
	    FSUserSignal = 0;

	ScreenToFront(FSWin->WScreen);

	PrintIText(FSWin->RPort, &FSPathTxt, 4L, 125L);

	MyActivateGad(&FSFileGad, FSWin);
	FSCountDown = 0;
	return (1L);
    }
}

#endif	/* PATHMASTER */
