/*----------------------------------------------------------------------*
   con.c version 2.0 -  © Copyright 1990 Jaba Development

   Author : Jan van den Baard
   Purpose: startup configuration window
 *----------------------------------------------------------------------*/

/*
 * configuration window gadgets e.c.t.
 */
static struct IntuiText WText1 =
 { 1,0,JAM1,67,39,NULL,(UBYTE *)"Screen depth :",NULL
 };
static struct IntuiText WText =
 { 1,0,JAM1,54,13,NULL,(UBYTE *)"Edit gadgets for :",&WText1
 };
static struct Gadget txt =
 { NULL,0,0,1,1,GADGHNONE,NULL,BOOLGADGET,
   NULL,NULL,&WText,NULL,NULL,NULL,NULL
 };
static SHORT WBPairs[] =
 { 0,0,234,0,234,12,0,12,0,0
 };
static struct Border WBBorder =
 { -1,-1,1,0,JAM1,5,WBPairs,NULL
 };
static struct IntuiText WBText =
 { 1,0,JAM1,79,2,NULL,(UBYTE *)"WORKBENCH",NULL
 };
static struct Gadget WB =
 { &txt,7,66,233,11,SELECTED,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
   (APTR)&WBBorder,NULL,&WBText,31L,NULL,9,NULL
 };
static SHORT OKPairs[] =
 { 0,0,114,0,114,12,0,12,0,0
 };
static struct Border OKBorder =
 { -1,-1,1,0,JAM1,5,OKPairs,NULL
 };

static struct IntuiText OKText =
 { 1,0,JAM1,49,2,NULL,(UBYTE *)"OK",NULL
 };
static struct Gadget OK =
 { &WB,7,82,113,11,NULL,RELVERIFY,BOOLGADGET,
   (APTR)&OKBorder,NULL,&OKText,NULL,NULL,8,NULL
 };

static struct IntuiText CNCText =
 { 1,0,JAM1,33,2,NULL,(UBYTE *)"CANCEL",NULL
 };
static struct Gadget CNC =
 { &OK,127,82,113,11,NULL,RELVERIFY,BOOLGADGET,
   (APTR)&OKBorder,NULL,&CNCText,NULL,NULL,7,NULL
 };

static SHORT DPairs[] =
 { 0,0,29,0,29,12,0,12,0,0
 };
static struct Border DBorder =
 { -1,-1,1,0,JAM1,5,DPairs,NULL
 };
static struct IntuiText D5Text =
 { 1,0,JAM1,10,2,NULL,(UBYTE *)"5",NULL
 };
static struct Gadget D5 =
 { &CNC,212,50,28,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
   (APTR)&DBorder,NULL,&D5Text,143L,NULL,6,NULL
 };
static struct IntuiText D4Text =
 { 1,0,JAM1,10,2,NULL,(UBYTE *)"4",NULL
 };
static struct Gadget D4 =
 { &D5,160,50,28,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
   (APTR)&DBorder,NULL,&D4Text,151L,NULL,5,NULL
 };
static struct IntuiText D3Text =
 { 1,0,JAM1,10,2,NULL,(UBYTE *)"3",NULL
 };
static struct Gadget D3 =
 { &D4,108,50,28,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
   (APTR)&DBorder,NULL,&D3Text,155L,NULL,4,NULL
 };
static struct IntuiText D2Text =
 { 1,0,JAM1,10,2,NULL,(UBYTE *)"2",NULL
 };
static struct Gadget D2 =
 { &D3,58,50,28,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
   (APTR)&DBorder,NULL,&D2Text,157L,NULL,3,NULL
 };
static struct IntuiText D1Text =
 { 1,0,JAM1,10,2,NULL,(UBYTE *)"1",NULL
 };
static struct Gadget D1 =
 { &D2,7,50,28,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
   (APTR)&DBorder,NULL,&D1Text,158L,NULL,2,NULL
 };
static SHORT WRPairs[] =
 { 0,0,114,0,114,12,0,12,0,0
 };
static struct Border WRBorder =
 { -1,-1,1,0,JAM1,5,WRPairs,NULL
 };
static struct IntuiText REQText =
 { 1,0,JAM1,19,2,NULL,(UBYTE *)"REQUESTER",NULL
 };
static struct Gadget REQ =
 { &D1,127,25,113,11,NULL,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
   (APTR)&WRBorder,NULL,&REQText,1L,NULL,1,NULL
 };
static struct IntuiText WNDText =
 { 1,0,JAM1,33,2,NULL,(UBYTE *)"WINDOW",NULL
 };
static struct Gadget WND =
 { &REQ,7,25,113,11,SELECTED,GADGIMMEDIATE+TOGGLESELECT,BOOLGADGET,
   (APTR)&WRBorder,NULL,&WNDText,2L,NULL,0,NULL
 };
static struct NewWindow nw_conf =
 { 197,60,246,97,3,2,GADGETUP+GADGETDOWN,ACTIVATE+RMBTRAP+NOCAREREFRESH,
   &WND,NULL,(UBYTE *)"Please specify",NULL,NULL,0,0,0,0,WBENCHSCREEN
 };

/*
 * static data
 */
static struct Window *w;
static USHORT         gad_id;

/*
 * globals
 */
extern struct Gadget    *Gadget;
extern struct NewWindow  nw_main;
extern BOOL              REQUESTER;
extern BOOL              WBSCREEN;
extern USHORT            DEPTH, Code;
extern ULONG             Class;
extern char              wdt[80],wlb[MAXLABEL];

/*
 * open the configuration window
 */
VOID get_config()
{
    if(NOT(w = OpenWindow(&nw_conf)))
        close_up("   - ERROR: Can't open the configurations window !");

    do
    {   Wait(1 << w->UserPort->mp_SigBit);
        while(read_msg(w))
        {   gad_id    = Gadget->GadgetID;
            switch(gad_id)
            {   case 9:
                case 6:
                case 5:
                case 4:
                case 3:
                case 2: MutualExclude(w,Gadget,&D1,NULL);
                        SelectGadget(w,Gadget,NULL);
                        break;
                case 1:
                case 0: MutualExclude(w,Gadget,&WND,NULL);
                        SelectGadget(w,Gadget,NULL);
                        break;
            }
        }
    } while((gad_id != 7)&&(gad_id != 8));
    CloseWindow(w);
    if(gad_id == 8)
    {
        if(SelectTest(&WND))  REQUESTER = FALSE;
        else
        {   REQUESTER = TRUE;
            nw_main.Flags  = WINDOWDRAG+WINDOWSIZING+SIZEBRIGHT+SIZEBBOTTOM;
            nw_main.Flags |= GIMMEZEROZERO+BORDERLESS+NOCAREREFRESH+SMART_REFRESH+ACTIVATE;
            strcpy((char *)&wdt,"Requester");
            strcpy((char *)&wlb,"requester");
        }
        if(SelectTest(&D1))        DEPTH = 1;
        else if(SelectTest(&D2))   DEPTH = 2;
        else if(SelectTest(&D3))   DEPTH = 3;
        else if(SelectTest(&D4))   DEPTH = 4;
        else if(SelectTest(&WB)) { DEPTH = 2; WBSCREEN = TRUE; }
        else                       DEPTH = 5;
        return;
    }
    close_up("    - BYE BYE......");
}
