Beispiel #1
0
/*--------------------------------------------------------------------------*/
int sci_messagebox(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrmessageAdr       = NULL;
    int* piAddrtitleAdr         = NULL;
    int* piAddriconAdr          = NULL;
    int* piAddrbuttonsTextAdr   = NULL;
    int* piAddrmodalOptionAdr   = NULL;
    double* buttonNumberAdr     = NULL;

    int messageBoxID = 0;

    /* Used to read input arguments */
    int nbRow = 0, nbCol = 0;
    int nbRowButtons = 0, nbColButtons = 0;
    int nbRowMessage = 0, nbColMessage = 0;

    char **buttonsTextAdr   = 0;
    char **messageAdr       = 0;
    char **titleAdr         = 0;
    char **modalOptionAdr   = 0;
    char **iconAdr          = 0;

    /* Used to write output argument */
    int buttonNumber = 0;

    CheckInputArgument(pvApiCtx, 1, 5);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* Message to be displayed */
    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmessageAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRowMessage, &nbColMessage, &messageAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
            return 1;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
        return FALSE;
    }

    /* Title to be displayed */
    if (nbInputArgument(pvApiCtx) >= 2)
    {
        if (checkInputArgumentType(pvApiCtx, 2, sci_strings))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrtitleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrtitleAdr, &nbRow, &nbCol, &titleAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 2);
                return FALSE;
            }
            /* The title argument can be used to give the modal option */
            if (isModalOption(titleAdr[0]))
            {
                modalOptionAdr = titleAdr;
                titleAdr = NULL;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
            return FALSE;
        }
    }

    /* Icon to be displayed */
    if (nbInputArgument(pvApiCtx) >= 3)
    {
        if ((checkInputArgumentType(pvApiCtx, 3, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddriconAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddriconAdr, &nbRow, &nbCol, &iconAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow * nbCol == 1)
            {
                /* The icon argument can be used to give the modal option or the buttons names */
                if (isModalOption(iconAdr[0]))
                {
                    modalOptionAdr = (char **)iconAdr;
                    iconAdr = NULL;
                }
                else if (!isIconName(iconAdr[0]))
                {
                    buttonsTextAdr = (char **)iconAdr;
                    nbRowButtons = nbRow;
                    nbColButtons = nbCol;
                    iconAdr = NULL;
                }
            }
            else  /* More than one string --> buttons names */
            {
                buttonsTextAdr = (char **)iconAdr;
                nbRowButtons = nbRow;
                nbColButtons = nbCol;
                iconAdr = NULL;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string or string vector expected.\n"), fname, 3);
            return FALSE;
        }
    }

    /* Buttons names */
    if (nbInputArgument(pvApiCtx) >= 4)
    {
        if ((checkInputArgumentType(pvApiCtx, 4, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrbuttonsTextAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 4.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrbuttonsTextAdr, &nbRowButtons, &nbColButtons, &buttonsTextAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 4);
                return 1;
            }

            if (nbRow * nbCol == 1)
            {
                /* The buttons names argument can be used to give the modal option */
                if (isModalOption(buttonsTextAdr[0]))
                {
                    modalOptionAdr = buttonsTextAdr;
                    buttonsTextAdr = NULL;
                }
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string or string vector expected.\n"), fname, 3);
            return FALSE;
        }
    }

    /* Modal option */
    if (nbInputArgument(pvApiCtx) == 5)
    {
        if ((checkInputArgumentType(pvApiCtx, 5, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrmodalOptionAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 5.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrmodalOptionAdr, &nbRow, &nbCol, &modalOptionAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 5);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 5);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 5);
            return FALSE;
        }
    }
    /* Create the Java Object */
    messageBoxID = createMessageBox();

    /* Message */
    setMessageBoxMultiLineMessage(messageBoxID, messageAdr, nbColMessage * nbRowMessage);
    freeAllocatedMatrixOfString(nbRowMessage, nbColMessage, messageAdr);

    /* Title */
    if (titleAdr != NULL)
    {
        setMessageBoxTitle(messageBoxID, titleAdr[0]);
        freeAllocatedMatrixOfString(nbRow, nbCol, titleAdr);
    }
    else
    {
        setMessageBoxTitle(messageBoxID, _("Scilab Message"));
    }

    /* Icon */
    if (iconAdr != NULL)
    {
        setMessageBoxIcon(messageBoxID, iconAdr[0]);
        freeAllocatedMatrixOfString(nbRow, nbCol, iconAdr);
    }

    /* Buttons */
    if (buttonsTextAdr != NULL)
    {
        setMessageBoxButtonsLabels(messageBoxID, buttonsTextAdr, nbColButtons * nbRowButtons);
        freeAllocatedMatrixOfString(nbRowButtons, nbColButtons, buttonsTextAdr);
    }

    /* Modal ? */
    if (modalOptionAdr != NULL)
    {
        setMessageBoxModal(messageBoxID, !stricmp(modalOptionAdr[0], "modal"));
        freeAllocatedMatrixOfString(nbRow, nbCol, modalOptionAdr);
    }
    else
    {
        setMessageBoxModal(messageBoxID, FALSE);
    }

    /* Display it and wait for a user input */
    messageBoxDisplayAndWait(messageBoxID);

    /* Return the index of the button selected */
    if (nbOutputArgument(pvApiCtx) == 1)
    {
        /* Read the user answer */
        buttonNumber = getMessageBoxSelectedButton(messageBoxID);

        nbRow = 1;
        nbCol = 1;

        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &buttonNumberAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        buttonNumberAdr[0] = buttonNumber;

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    }
    else
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
    }

    ReturnArguments(pvApiCtx);
    return TRUE;
}
/*--------------------------------------------------------------------------*/
int sci_messagebox(char *fname,unsigned long fname_len)
{
  int messageBoxID = 0;

  /* Used to read input arguments */
  int nbRow = 0, nbCol = 0;
  int nbRowButtons = 0, nbColButtons = 0;
  int nbRowMessage = 0, nbColMessage = 0;

  char **buttonsTextAdr = 0;
  char **messageAdr = 0;
  char **titleAdr = 0;
  char **modalOptionAdr = 0;
  char **iconAdr = 0;

  /* Used to write output argument */
  int buttonNumberAdr = 0;
  int buttonNumber = 0;

  CheckRhs(1,5);
  CheckLhs(0,1);

  /* Message to be displayed */
  if (VarType(1) == sci_strings) 
    {
      GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &nbRowMessage, &nbColMessage, &messageAdr);
    }
  else
    {
      Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
      return FALSE;
    }

  /* Title to be displayed */
  if (Rhs >= 2) 
    {
      if (VarType(2) == sci_strings)
        {
          GetRhsVar(2, MATRIX_OF_STRING_DATATYPE, &nbRow, &nbCol, &titleAdr);
          if (nbRow*nbCol!=1)
            {
              Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
              return FALSE;
            }
          /* The title argument can be used to give the modal option */
          if (isModalOption(getStringMatrixFromStack((size_t)titleAdr)[0]))
            {
              modalOptionAdr = titleAdr;
              titleAdr = NULL;
            }
        }
      else
        {
          Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
          return FALSE;
        }
    }

  /* Icon to be displayed */
  if (Rhs >= 3)
    {
      if (VarType(3) == sci_strings)
        {
          GetRhsVar(3,MATRIX_OF_STRING_DATATYPE,&nbRow,&nbCol,&iconAdr);
          if (nbRow*nbCol == 1)
            {
              /* The icon argument can be used to give the modal option or the buttons names */
              if (isModalOption(getStringMatrixFromStack((size_t)iconAdr)[0]))
                {
                  modalOptionAdr = (char **)iconAdr;
                  iconAdr = NULL;
                }
              else if(!isIconName(getStringMatrixFromStack((size_t)iconAdr)[0]))
                {
                  buttonsTextAdr = (char **)iconAdr;
                  nbRowButtons = nbRow;
                  nbColButtons = nbCol;
                  iconAdr = NULL;
                }
            }
          else  /* More than one string --> buttons names */
            {
              buttonsTextAdr = (char **)iconAdr;
              nbRowButtons = nbRow;
              nbColButtons = nbCol;
              iconAdr = NULL;
            }

        }
      else
        {
          Scierror(999, _("%s: Wrong type for input argument #%d: A string or a string vector expected.\n"), fname, 3);
          return FALSE;
        }
    }

  /* Buttons names */
  if (Rhs >= 4)
    {
      if (VarType(4) == sci_strings)
        {
          GetRhsVar(4,MATRIX_OF_STRING_DATATYPE,&nbRowButtons,&nbColButtons,&buttonsTextAdr);
          if (nbRow*nbCol == 1)
            {
              /* The buttons names argument can be used to give the modal option */
              if (isModalOption(getStringMatrixFromStack((size_t)buttonsTextAdr)[0]))
                {
                  modalOptionAdr = buttonsTextAdr;
                  buttonsTextAdr = NULL;
                }
            }
        }
      else
        {
          Scierror(999, _("%s: Wrong type for input argument #%d: A string or a string vector expected.\n"), fname, 3);
          return FALSE;
        }
    }
  
  /* Modal option */
  if (Rhs == 5)
    {
      if (VarType(5) == sci_strings)
        {
          GetRhsVar(5,MATRIX_OF_STRING_DATATYPE,&nbRow,&nbCol,&modalOptionAdr);
          if (nbRow*nbCol != 1)
            {
              Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 5);
              return FALSE;
            }
        }
      else
        {
          Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 5);
          return FALSE;
        }
    }
  /* Create the Java Object */
  messageBoxID = createMessageBox();

  /* Message */
  setMessageBoxMultiLineMessage(messageBoxID, getStringMatrixFromStack((size_t)messageAdr), nbColMessage*nbRowMessage);

  /* Title */
  if (titleAdr != NULL)
    {
      setMessageBoxTitle(messageBoxID, getStringMatrixFromStack((size_t)titleAdr)[0]);
    }
  else
    {
      setMessageBoxTitle(messageBoxID, _("Scilab Message"));
    }

  /* Icon */
  if (iconAdr != NULL)
    {
      setMessageBoxIcon(messageBoxID, getStringMatrixFromStack((size_t)iconAdr)[0]);
    }
    
  /* Buttons */
  if (buttonsTextAdr != NULL)
    {
      setMessageBoxButtonsLabels(messageBoxID, getStringMatrixFromStack((size_t)buttonsTextAdr), nbColButtons*nbRowButtons);
    }

  /* Modal ? */
  if (modalOptionAdr != NULL)
    {
      setMessageBoxModal(messageBoxID, !stricmp(getStringMatrixFromStack((size_t)modalOptionAdr)[0],"modal"));
    }
  else
    {
      setMessageBoxModal(messageBoxID, FALSE);
    }
  
  /* Display it and wait for a user input */
  messageBoxDisplayAndWait(messageBoxID);

  /* Return the index of the button selected */
  
  if (Lhs == 1)
    {
      /* Read the user answer */
      buttonNumber = getMessageBoxSelectedButton(messageBoxID);
      
      nbRow = 1; nbCol = 1;
      CreateVar(Rhs+1, MATRIX_OF_DOUBLE_DATATYPE, &nbRow, &nbCol, &buttonNumberAdr);
      *stk(buttonNumberAdr) = buttonNumber;
      
      LhsVar(1) = Rhs+1;
    }
  else
    {
      LhsVar(1) = 0;
    }
  
  PutLhsVar();
  return TRUE;
}
/*--------------------------------------------------------------------------*/
int sci_x_choose_modeless(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddritemsAdr = NULL;
    int* piAddrmessageAdr = NULL;
    int* piAddrbuttonLabelAdr = NULL;
    double* userValueAdr = NULL;

    int nbRow = 0, nbCol = 0;
    int nbRowItems = 0, nbColItems = 0;

    int messageBoxID = 0;

    char **itemsAdr = NULL;
    char **buttonLabelAdr = NULL;

    char **messageAdr = NULL;

    int userValue = 0;

    CheckInputArgument(pvApiCtx, 2, 3);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddritemsAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddritemsAdr, &nbRowItems, &nbColItems, &itemsAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1);
            return 1;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 1);
        return FALSE;
    }

    if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmessageAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 2.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRow, &nbCol, &messageAdr))
        {
            freeAllocatedMatrixOfString(nbRowItems, nbColItems, itemsAdr);
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
            return 1;
        }

    }
    else
    {
        freeAllocatedMatrixOfString(nbRowItems, nbColItems, itemsAdr);
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 2);
        return FALSE;
    }

    /* Create the Java Object */
    messageBoxID = createMessageBox();

    /* Title is a default title */
    setMessageBoxTitle(messageBoxID, _("Scilab Choose Message"));
    /* Message */
    setMessageBoxMultiLineMessage(messageBoxID, messageAdr, nbCol * nbRow);
    /* ListBox Items */
    setMessageBoxListBoxItems(messageBoxID, itemsAdr, nbColItems * nbRowItems);
    /* Modality */
    setMessageBoxModal(messageBoxID, FALSE);

    freeAllocatedMatrixOfString(nbRowItems, nbColItems, itemsAdr);
    freeAllocatedMatrixOfString(nbRow, nbCol, messageAdr);

    if (nbInputArgument(pvApiCtx) == 3)
    {
        if (VarType(3) ==  sci_strings)
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrbuttonLabelAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrbuttonLabelAdr, &nbRow, &nbCol, &buttonLabelAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, buttonLabelAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 3);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 3);
            return FALSE;
        }

        setMessageBoxButtonsLabels(messageBoxID, buttonLabelAdr, nbCol * nbRow);
        freeAllocatedMatrixOfString(nbRow, nbCol, buttonLabelAdr);
    }

    /* Display it and wait for a user input */
    messageBoxDisplayAndWait(messageBoxID);

    /* Read the user answer */
    userValue = getMessageBoxSelectedItem(messageBoxID);

    nbRow = 1;
    nbCol = 1;

    sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &userValueAdr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    *userValueAdr = userValue;

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
Beispiel #4
0
/*--------------------------------------------------------------------------*/
int sci_x_choose(char *fname, unsigned long fname_len)
{
    int nbRow = 0, nbCol = 0;
    int nbRowItems = 0, nbColItems = 0;

    int messageBoxID = 0;

    char **itemsAdr = NULL;
    char **buttonLabelAdr = NULL;

    char **messageAdr = NULL;

    int userValueAdr = 0;
    int userValue = 0;

    CheckRhs(2, 3);
    CheckLhs(0, 1);

    if (VarType(1) == sci_strings)
    {
        GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &nbRowItems, &nbColItems, &itemsAdr);
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname);
        return FALSE;
    }

    if (VarType(2) == sci_strings)
    {
        GetRhsVar(2, MATRIX_OF_STRING_DATATYPE, &nbRow, &nbCol, &messageAdr);
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 2);
        return FALSE;
    }

    /* Create the Java Object */
    messageBoxID = createMessageBox();

    /* Title is a default title */
    setMessageBoxTitle(messageBoxID, _("Scilab Choose Message"));
    /* Message */
    setMessageBoxMultiLineMessage(messageBoxID, getStringMatrixFromStack((size_t)messageAdr), nbCol * nbRow);
    /* ListBox Items */
    setMessageBoxListBoxItems(messageBoxID, getStringMatrixFromStack((size_t)itemsAdr), nbColItems * nbRowItems);
    /* Modality */
    setMessageBoxModal(messageBoxID, TRUE);

    if (Rhs == 3)
    {
        if (VarType(3) ==  sci_strings)
        {
            GetRhsVar(3, MATRIX_OF_STRING_DATATYPE, &nbRow, &nbCol, &buttonLabelAdr);
            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 3);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 3);
            return FALSE;
        }

        setMessageBoxButtonsLabels(messageBoxID, getStringMatrixFromStack((size_t)buttonLabelAdr), nbCol * nbRow);
    }

    /* Display it and wait for a user input */
    messageBoxDisplayAndWait(messageBoxID);

    /* Read the user answer */
    userValue = getMessageBoxSelectedItem(messageBoxID);

    nbRow = 1;
    nbCol = 1;
    CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &nbRow, &nbCol, &userValueAdr);
    *stk(userValueAdr) = (double)userValue;

    LhsVar(1) = Rhs + 1;
    PutLhsVar();
    return TRUE;
}