/*    This function will get a yes or no answer from a users.  It tries
 * to be smart about how it opens the autorequest().
 *
 *    Also you should know that this some of this code came from the DME
 * source code of the same function.  However I have changed it a fair
 * amount....
 */

#include "ezlib.h"

void *AllocMem();

getyn(win, text)
struct Window *win;
char *text;
{
    int result, width;
    struct IntuiText *body, *pos, *neg;

    if (win <= 100)       /* quick sanity check */
      return NULL;

    /* this is a sneaky way to only have to do a single AllocMem instead
     * of 3 seperate ones (each with error checking).
     */
    body = (struct IntuiText *)AllocMem( (3*sizeof(struct IntuiText)), MEMF_CLEAR);
    if (body == NULL)
      return NULL;

    pos = &body[1]; neg = &body[2];

    body->BackPen  = pos->BackPen  = neg->BackPen  = 1;
    body->DrawMode = pos->DrawMode = neg->DrawMode = AUTODRAWMODE;
    body->LeftEdge = 10;
    body->TopEdge  = 12;
    body->IText    = (UBYTE *)text;
    pos->LeftEdge  = pos->TopEdge  = AUTOTOPEDGE;
    pos->IText	   = (UBYTE *)" OK ";
    neg->LeftEdge  = neg->TopEdge  = AUTOTOPEDGE;
    neg->IText	   = (UBYTE *)" CANCEL";

    width = IntuiTextLength(body) + 50;
    if (width < 150)
      width = 225;
    result = AutoRequest(win, body, pos, neg, 0, 0, width, 58);
    FreeMem(body, (3*sizeof(struct IntuiText)));

    return(result);
}

