Metropoli BBS
VIEWER: wbcopyrt.c MODE: TEXT (ASCII)
/***************************************************************************
 *		  Copyright (C) 1994  Charles P. Peterson                  *
 *	     4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
 *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
 *                                                                         *
 *		  This is free software with NO WARRANTY.                  *
 *	      See gfft.c, or run program itself, for details.              *
 *		      Support is available for a fee.                      *
 ***************************************************************************
 *
 * Program:     gfft--General FFT analysis
 * File:        wbcopyrt.c
 * Purpose:     copyright dialog requester
 * Author:      Charles Peterson (CPP)
 * History:     11-Feb-1994 CPP; Created.
 *              10-Jul-1994 CPP (0.76); Fixed "fast click" bug
 *              14-Dec-94 CPP (1.17); Fix button gadgets for >4 colors
 * Comments:    Workbench GUI.  Amiga Dependent!
 */

#ifdef AMIGA  /* This module is AMIGA dependent */

#include <stdio.h>     /* sprintf() */
#include <string.h>

/*
 * Amiga includes
 */
#include <exec/types.h>
#include <workbench/workbench.h>
#include <intuition/intuition.h>
#include <clib/intuition_protos.h>
#include <clib/exec_protos.h>
#include <dos.h> /* chkabort() */

/*
 * GFFT includes
 */
#include "gfft.h"
#include "settings.h"  /* for testing */
#include "wbench.h"

/*
 * External globals
 */
extern struct Window *dialog_window_p;
extern char *Author_Strings[];
extern short Max_Columns;
extern char *Copyrt_Req_Prolog;
extern char *Author_Info_Button;
extern char *No_Warranty_Button;
extern char *Sharing_Rights_Button;
extern char *Idea_Contributor_Button;
extern char *Code_Contributor_Button;

#define FIRST_AUTHOR_LINE 1  /* Line 0 is blank */

static struct Requester *copyright_rp = NULL;
static struct Requester *author_rp = NULL;

static struct Gadget *author_gadgetp;
static struct Gadget *copying_gadgetp, *nowarranty_gadgetp;
static struct Gadget *idea_contributor_gadgetp, *code_contributor_gadgetp;
static struct Gadget *financial_contributor_gadgetp;
static struct Gadget *end_copyright_gadgetp, *ok_author_gadgetp;

#define MAX_AUTHOR_LINES 7

static struct IntuiText *prolog_textp;
static struct IntuiText *author_textp[MAX_AUTHOR_LINES];
static struct Gadget *next_author_gadgetp;
static struct Gadget *previous_author_gadgetp;

static void author (int start_line);

void copyright_requester (void)
{
    struct IntuiMessage *message;
    APTR *address = NULL;
    ULONG class = 0;

    if (!copyright_rp)
    {
	gadget__begin (GTYP_REQGADGET);
/*
 * Setup Text
 */
	prolog_textp = requester_text__new (Copyrt_Req_Prolog, 0, 0);

/*
 * Setup Gadgets
 */
	author_gadgetp = action_button__new (Author_Info_Button, 0, 1);

	nowarranty_gadgetp = action_button__new (No_Warranty_Button, 0, 2);

	copying_gadgetp = action_button__new (Sharing_Rights_Button, 0, 3);

	idea_contributor_gadgetp = action_button__new 
	  (Idea_Contributor_Button, 0, 4);

	code_contributor_gadgetp = action_button__new
	  (Code_Contributor_Button, 0, 5);

/*
 *	financial_contributor_gadgetp = action_button__new
 *	  ("Financial support has been contributed by...",
 *	   0, 6);
 */

	end_copyright_gadgetp = tall_action_button__new
	  ("...OK", Max_Columns - 5, 7);

	copyright_rp = requester__new ();
	copyright_rp->ReqGadget = end_copyright_gadgetp;
	copyright_rp->ReqText = prolog_textp;

    } /* Ok, copyright_rp has been created */
    
    if (requester__display (copyright_rp, dialog_window_p))
    {
	while (TRUE)
	{
	    Wait (1 << dialog_window_p->UserPort->mp_SigBit);
	    while (message = (struct IntuiMessage *) GetMsg 
		   (dialog_window_p->UserPort))
	    {
		CATCH_ERROR
		class = message->Class;
		address = message->IAddress;
		ReplyMsg ((struct Message *) message);
		if (address == (APTR) author_gadgetp)
		{
		    author (FIRST_AUTHOR_LINE);
		}
		else if (address == (APTR) copying_gadgetp)
		{
		    copying_message (NullString);
		}
		else if (address == (APTR) nowarranty_gadgetp)
		{
		    no_warranty_message (NullString);
		}
		else if (address == (APTR) idea_contributor_gadgetp)
		{
		    help_message ("idea contributors");
		}
		else if (address == (APTR) code_contributor_gadgetp)
		{
		    help_message ("code contributors");
		}
		else if (address == (APTR) financial_contributor_gadgetp)
		{
		    help_message ("financial contributors");
		}
		else if (address == (APTR) end_copyright_gadgetp)
		{
		    requester__remove (copyright_rp, dialog_window_p);
		    return;
		}
		END_CATCH_ERROR
	    }
	}
    }
}

static void author (int start_line)
{
    struct IntuiMessage *message;
    APTR *address = NULL;
    ULONG class = 0;
    static int author_line_count = 0;
    int start_line_here = start_line;
    int end_line_here;
    int line_count_here;
    int i, j;
    int col;
    static BOOLEAN all_pages_seen = FALSE;

    if (!author_line_count)
    {
	while (Author_Strings[author_line_count++]);
    }
    if (author_rp)
    {
	gfree (author_rp);  /* should free text also... */
	author_rp = NULL;
    }

    while (Author_Strings[start_line_here] && 
	   strlen (Author_Strings[start_line_here++]) <= 1);
    end_line_here = --start_line_here;

    while (Author_Strings[end_line_here])
    {
	col = strlen (Author_Strings[end_line_here]);
	if (col <= 1) break;
	end_line_here++;
    }
    end_line_here--;

    line_count_here = 1 + end_line_here - start_line_here;
    if (line_count_here < 1 || line_count_here > MAX_AUTHOR_LINES) return;

    gadget__begin (GTYP_REQGADGET);

    for (i = start_line_here, j = 0; i <= end_line_here; i++, j++)
    {
	author_textp[j] = requester_text__new (Author_Strings[i], 0, j);
    }

    next_author_gadgetp = action_button__new ("Next", 11, j);
    if (end_line_here + 3 >= author_line_count)
    {
	next_author_gadgetp->Flags |= GFLG_DISABLED;
	all_pages_seen = TRUE;
    }

    previous_author_gadgetp = action_button__new ("Previous", 0, j);
    if (start_line_here <= FIRST_AUTHOR_LINE || !all_pages_seen)
      previous_author_gadgetp->Flags |= GFLG_DISABLED;

    ok_author_gadgetp = action_button__new ("...OK", Max_Columns - 5, j);
    if (!all_pages_seen)
      ok_author_gadgetp->Flags |= GFLG_DISABLED;

    author_rp = requester__new ();
    author_rp->ReqGadget = ok_author_gadgetp;
    author_rp->ReqText = author_textp[j-1];

    if (requester__display (author_rp, dialog_window_p))
    {
	while (TRUE)
	{
	    Wait (1 << dialog_window_p->UserPort->mp_SigBit);
	    while (message = (struct IntuiMessage *) GetMsg 
		   (dialog_window_p->UserPort))
	    {
		class = message->Class;
		address = message->IAddress;
		ReplyMsg ((struct Message *) message);
		if (address == (APTR) ok_author_gadgetp)
		{
		    requester__remove (author_rp, dialog_window_p);
		    return;
		}
		else if (address == (APTR) next_author_gadgetp)
		{
		    requester__remove (author_rp, dialog_window_p);
		    author (end_line_here + 2);
		    return;
		}
		else if (address == (APTR) previous_author_gadgetp)
		{
		    i = start_line_here - 1;
		    if (i-1 < FIRST_AUTHOR_LINE) break;
		    while (Author_Strings[i] &&
			   (strlen (Author_Strings[--i]) > 1));
		    requester__remove (author_rp, dialog_window_p);
		    author (i);
		    return;
		}
	    }
	}
    }
}

#endif /* end ifdef AMIGA */
[ RETURN TO DIRECTORY ]