/*
(c) Copyright 1988-1994 Microsoft Corporation.

Microsoft Bars&Pipes Professional Source Code License

This License governs use of the accompanying Software.  
Microsoft hopes you find this Software useful.

You are licensed to do anything you want with the Software. 

In return, we simply require that you agree:

1.      Not to remove any copyright notices from the Software.

2.      That the Software comes "as is", with no warranties.  
        None whatsoever. This means no implied warranty of merchantability or 
        fitness for a particular purpose or any warranty of non-infringement.  
        Also, you must pass this disclaimer on whenever you distribute the Software.

3.      That we will not be liable for any of those types of damages known as indirect, 
        special, consequential, or incidental related to the Software or this License, 
        to the maximum extent the law permits. Also, you must pass this limitation of 
        liability on whenever you distribute the Software.

4.      That if you sue anyone over patents that you think may apply to the Software 
        for that person’s use of the Software, your license to the Software ends automatically.

5.      That the patent rights Microsoft is licensing only apply to the Software, 
        not to any derivatives you make.

6.      That your rights under the License end automatically if you breach this in any way.
*/

#include "/CompilerSpecific.h"
#include <intuition/intuition.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/graphics.h>
#include <exec/memory.h>
#include <string.h>
#include "tools.h"
#include <dos/dos.h>
#include "/v.h"
#include "all.h"

extern struct Functions functions;
extern short dontcolorpointer;
extern struct NewWindow sureNewWindowStructure1;
extern struct NewWindow waitNewWindowStructure2;
extern struct NewWindow warnNewWindowStructure3;
extern struct NewWindow memhelpNewWindowStructure4;
extern struct NewWindow closeNewWindowStructure5;
extern struct IntuiText closeIText19;
extern struct IntuiText waitIText5;
extern struct IntuiText sureIText3;
extern struct IntuiText sureIText4;

#ifdef FRENCH
#include "requestwf.c"
#endif

#define RK_Y 0x15
#define RK_N 0x36
#define RK_O 0x37
#define RK_C 0x33

static struct Window *waitwindow = 0;

SAVEDS  void openwait()

{
    /* geta4(); */
    if (!waitwindow) {
        preparerequester(&waitNewWindowStructure2);
        dontcolorpointer = 1;
        onholdreqtask();
        waitwindow = (struct Window *) OpenWindow(&waitNewWindowStructure2);
        if (waitwindow) {
            beginrequest();
            EmbossRequestOn(waitwindow,"");
            PrintIText(waitwindow->RPort,&waitIText5,0,0);
        }
        dontcolorpointer = 0;
    }
}

SAVEDS  void closewait()

{
    /* geta4(); */
    if (waitwindow){
        CloseWindow(waitwindow);
        endrequest();
        offholdreqtask();
    }
    waitwindow = 0;
}

SAVEDS  long areyousure(text)

char *text;

{
    register struct IntuiMessage *message;
    register long class, code;
    register struct Gadget *gadget;
    struct Window *window;
    long returnval = 4;

    /* geta4(); */
    if (functions.flags & FLAGS_DEMOMODE) return(1);
    class = strlen(text);
    if (class < 25) class = 25;
    class = class << 3;
    class += 30;
    sureNewWindowStructure1.Width = class;
    class = class >> 1;
    preparerequester(&sureNewWindowStructure1);
    window = (struct Window *) OpenWindow(&sureNewWindowStructure1);
    sureIText4.IText = text;
    if (window) {
        beginrequest();
        startreqtask(window);
        EmbossRequestOn(window,"Bars&Pipes Pro");
        EmbossOn(window,1,1);
        EmbossOn(window,2,1);
        PrintIText(window->RPort,&sureIText3,0,0);
        for (;returnval == 4;) {
            message = (struct IntuiMessage *) GetIntuiMessage(window);
            class = message->Class;
            code = message->Code;
            gadget = (struct Gadget *) message->IAddress;
            ReplyMsg((struct Message *)message);
            if (class == GADGETUP) {
                switch(gadget->GadgetID) {
                    case 1 :
                    case 2 :
                        returnval = (2 - gadget->GadgetID);
                }
            }
            else if (class == RAWKEY)
            {
                switch(code)
                {
                        case RK_Y :
                                returnval = (1);
                                break;
                        case RK_N :
                                returnval = (0);
                }
            }
        }
        EmbossOff(window,1);
        EmbossOff(window,2);
        endreqtask();
        CloseWindow(window);
        endrequest();
        return(returnval);
    }
}

SAVEDS int yesnocancel()

{
    register struct IntuiMessage *message;
    register long class, code;
    register struct Gadget *gadget;
    struct Window *window;
    long returnval = 4;
    /* geta4(); */
    if (functions.flags & FLAGS_DEMOMODE) return(2);
    preparerequester(&closeNewWindowStructure5);
    window = (struct Window *) OpenWindow(&closeNewWindowStructure5);
    if (window) {
        beginrequest();
        startreqtask(window);
        EmbossRequestOn(window,"");
        for(class=1;class<4;class++) EmbossOn(window,class,1);
        PrintIText(window->RPort,&closeIText19,0,0);
        for (;returnval == 4;) {
            message = (struct IntuiMessage *) GetIntuiMessage(window);
            class = message->Class;
            code = message->Code;
            gadget = (struct Gadget *) message->IAddress;
            ReplyMsg((struct Message *)message);
            if (class == GADGETUP) {
                switch(gadget->GadgetID) {
                    case 1 :
                    case 2 :
                    case 3 :
                        returnval = ((long)gadget->GadgetID);
                }
            }
            else if (class == RAWKEY)
            {
                switch(code)
                {
                        case RK_Y :
                                returnval = 1;
                                break;
                        case RK_N :
                                returnval = 2;
                                break;
                        case RK_C :
                                returnval = 3;
                }
            }
        }
        endreqtask();
        for(class=1;class<4;class++) EmbossOff(window,class);
                CloseWindow(window);
        endrequest();
        return(returnval);
    }
}

SAVEDS  void warnlowmem()

{
    register struct IntuiMessage *message;
    long class;
    struct Window *window;
    struct Gadget *gadget;
    /* geta4(); */
    if (functions.flags & FLAGS_DEMOMODE) return;
    ScreenToFront(functions.screen);
    preparerequester(&warnNewWindowStructure3);
    window = (struct Window *) OpenWindow(&warnNewWindowStructure3);
    if (window) {
        beginrequest();
        startreqtask(window);
#ifdef GERMAN
        EmbossRequestOn(window,"Warnung! Wenig Speicher!");
#endif
#ifdef ENGLISH
        EmbossRequestOn(window,"Warning! Low Memory!");
#endif
#ifdef FRENCH
        EmbossRequestOn(window,"Attention! Trop peu de mémoire!");
#endif
        EmbossOn(window,2,1);
        EmbossOn(window,1,1);
        message = (struct IntuiMessage *) GetIntuiMessage(window);
        class = message->Class;
        gadget = (struct Gadget *) message->IAddress;
        ReplyMsg((struct Message *)message);
        EmbossOff(window,2);
        EmbossOff(window,1);
        endreqtask();
        CloseWindow(window);
        endrequest();
        if ((class == GADGETDOWN) || (class == GADGETUP)) {
            if (gadget->GadgetID == 2) return;
        }
        else return;
    }
    else return;
    preparerequester(&memhelpNewWindowStructure4);
    window = (struct Window *) OpenWindow(&memhelpNewWindowStructure4);
    if (window) {
        beginrequest();
        startreqtask(window);
#ifdef GERMAN
        EmbossRequestOn(window,"Speichern sparen");
#endif
#ifdef ENGLISH
        EmbossRequestOn(window,"Memory Savers");
#endif
#ifdef FRENCH
        EmbossRequestOn(window,"Economiser la mémoire");
#endif
        EmbossOn(window,1,1);
        message = (struct IntuiMessage *) GetIntuiMessage(window);
        ReplyMsg((struct Message *)message);
        EmbossOff(window,1);
        endreqtask();
        CloseWindow(window);
        endrequest();
    }
}
