
#include "includes.h"
#include "installergui_data.h"

/********************************************************************
 *
 *  DESCRIPTION
 *
 *  build and show the ASKBOOL panel; the C= installer just
 *  modifies the gadget texts, but this will not work with my
 *  InstallerNG, since the ASKBOOL function can appear in a
 *  SWING funtion and the buttons are used by the SWING function;
 *  the best thing to solve this conflict was a ASKBOOL panel
 *  with two MX buttons for "Yes" and "No"
 *
 *  IN:  application - pointer to the private application structure
 *       localenv - the local environment of the related ASKBOOL
 *                  function
 *  OUT: 1 - if the user choses "Yes"
 *       0 - if the user choses "No"
 *
 */

/********************************************************************
 *
 *  STATIC
 *
 */

static const struct Hook askbool_MXTwoHook = { { NULL, NULL }, (VOID *) guistuff_MXTwoFun, NULL, NULL };
static const struct Hook askbool_SetValHook = { { NULL, NULL }, (VOID *) guistuff_SetValFun, NULL, NULL };

/********************************************************************
 *
 *  EXTERN
 *
 */

/********************************************************************
 *
 *  PUBLIC
 *
 */

/********************************************************************
 *
 *  CODE
 *
 */

long __asm igui_AskBool(register __a0 APTR application,
                        register __a1 struct FunctionEnvironment *localenv)
{
  #ifdef DEBUG
  DEBUG_MAKRO
  #endif

  {
    struct Application *app = (struct Application *) application;

    struct Node *yesnode, *nonode;

    // the default text values
    char *yestext = app->app_Texts[YES],
         *notext = app->app_Texts[NO];

    // by default, this returns 1
    long retval = 1;

    // the different mui objects
    APTR askbool, MX_yes, MX_no;

    // if there ware choices for ASKBOOL, then these choices are hold in an
    // exec list and ln_Name does hold the values themselves
    yesnode = sav_GetHead((struct List *) &(localenv->fe_Choices));
    if (yesnode)
    {
      yestext = yesnode->ln_Name;
      if (nonode = sav_GetSucc(yesnode)) { notext = nonode->ln_Name; }
    }

    // no create and setup the mui object
    // ---> note the tricky access to the retval via hooks ;)
    askbool = GroupObject,
                Child, TextObject,
                  MUIA_Text_Contents, localenv->fe_Prompt,
                  MUIA_Text_SetMin, TRUE,
                  MUIA_Text_PreParse, "\33c",
                End,
                Child, HVSpace,
                Child, HGroup,
                  Child, HVSpace,
                  Child, GroupObject,
                    MUIA_Group_Columns, 2,
                    Child, LLabel(yestext),
                    Child, MX_yes = guistuff_InitRadio(TRUE, FALSE),
                    Child, LLabel(notext),
                    Child, MX_no = guistuff_InitRadio(FALSE, FALSE),
                  End,
                  Child, HVSpace,
                End,
                Child, HVSpace,
              End;

    if (askbool)
    {
      DoMethod(MX_yes, MUIM_Notify, MUIA_Pressed, TRUE,
               MUIV_Notify_Self, 4, MUIM_CallHook, &askbool_MXTwoHook, MX_yes, MX_no);
      DoMethod(MX_no, MUIM_Notify, MUIA_Pressed, TRUE,
               MUIV_Notify_Self, 4, MUIM_CallHook, &askbool_MXTwoHook, MX_no, MX_yes);

      DoMethod(MX_yes, MUIM_Notify, MUIA_Pressed, TRUE,
               MUIV_Notify_Self, 4, MUIM_CallHook, &askbool_SetValHook, &retval, 1);
      DoMethod(MX_no, MUIM_Notify, MUIA_Pressed, TRUE,
               MUIV_Notify_Self, 4, MUIM_CallHook, &askbool_SetValHook, &retval, 0);

      if (guistuff_NewContent(app, askbool))
      {
        // wait for the user
        igui_WaitApp(app);
      }
    }
    else { /* NO GUI OBJECT */ }

    // and done
    igui_EmptyPanel(app);
    return(retval);
  }
}

