/*--------------------------------------------------------------------------*/ int sci_toolbar(char *fname, unsigned long l) { SciErr sciErr; int* piAddr1 = NULL; int* piStkAdr = NULL; int* piAddrstkAdr = NULL; long long* stkAdr = NULL; int* piAddrparam = NULL; int nbCol = 0; int nbRow = 0; char *Output = NULL; char **param = NULL; int figNum = -2; int iIsVisible = 0; int *piIsVisible = NULL; int iParentUID = 0; int iParentType = -1; int *piParentType = &iParentType; CheckInputArgument(pvApiCtx, 1, 2); CheckOutputArgument(pvApiCtx, 0, 1); /* Figure number */ if (checkInputArgumentType(pvApiCtx, 1, sci_matrix)) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr1, &nbRow, &nbCol, &piStkAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 1); return 1; } if (nbRow * nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1); return FALSE; } figNum = *piStkAdr; if (figNum < -1) { Scierror(999, _("%s: Wrong value for input argument #%d: Must be > %d expected.\n"), fname, 1, -1); return FALSE; } if (figNum != -1) /* Check that the figure exists */ { if (getFigureFromIndex(figNum) == 0) { Scierror(999, _("%s: Wrong value for input argument #%d: 'Graphic Window Number %d' does not exist.\n"), fname, 1, figNum); return FALSE; } } if (figNum == -1) { iParentUID = getConsoleIdentifier(); } else { iParentUID = getFigureFromIndex(figNum); } } else if (checkInputArgumentType(pvApiCtx, 1, sci_handles)) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstkAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrstkAdr, &nbRow, &nbCol, &stkAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } if (nbRow * nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } iParentUID = getObjectFromHandle((long) * stkAdr); if (iParentUID == 0) { Scierror(999, _("%s: Wrong value for input argument #%d: this handle does not exist.\n"), fname, 1); return FALSE; } getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType != __GO_FIGURE__) { Scierror(999, _("%s: Wrong type for input argument #%d: A real or a Figure handle expected.\n"), fname, 1); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real or a Figure handle expected.\n"), fname, 1); return FALSE; } if (nbInputArgument(pvApiCtx) == 2) /* New status */ { if ((checkInputArgumentType(pvApiCtx, 2, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrparam); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedMatrixOfString(pvApiCtx, piAddrparam, &nbRow, &nbCol, ¶m)) { Scierror(202, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2); return 1; } if (nbRow * nbCol != 1) { freeAllocatedMatrixOfString(nbRow, nbCol, param); Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2); return FALSE; } if ((strcmp(param[0], "off") == 0) || (strcmp(param[0], "on") == 0)) { iIsVisible = strcmp(param[0], "on") == 0; if (iParentUID != getConsoleIdentifier() || getScilabMode() == SCILAB_STD) { setGraphicObjectProperty(iParentUID, __GO_TOOLBAR_VISIBLE__, &iIsVisible, jni_bool, 1); } freeAllocatedMatrixOfString(nbRow, nbCol, param); } else { freeAllocatedMatrixOfString(nbRow, nbCol, param); Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "on", "off"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2); return FALSE; } } /* Returned value */ piIsVisible = &iIsVisible; getGraphicObjectProperty(iParentUID, __GO_TOOLBAR_VISIBLE__, jni_bool, (void **)&piIsVisible); if (iIsVisible) { Output = strdup("on"); } else { Output = strdup("off"); } nbCol = 1; nbRow = (int)strlen(Output); if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, Output)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; if (Output) { FREE(Output); Output = NULL; } ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_unsetmenu(char *fname, void* pvApiCtx) { SciErr sciErr; int* piAddrmenuNameAdr = NULL; char* menuNameAdr = NULL; int* piAddrfigureNumberAdr = NULL; double* figureNumberAdr = NULL; int* piAddrsubMenuIndexAdr = NULL; double* subMenuIndexAdr = NULL; int nbRow = 0; int nbCol = 0; // Check parameter number CheckInputArgument(pvApiCtx, 1, 3); CheckOutputArgument(pvApiCtx, 1, 1); if (nbInputArgument(pvApiCtx) == 1) { // Error message in not in standard mode (we need figure number) if (getScilabMode() != SCILAB_STD) { Scierror(999, _("%s: Figure number must be given when not in '%s' mode.\n"), fname, "STD"); return FALSE; } // Unset a Menu of Scilab Main Window if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings))) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return FALSE; } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmenuNameAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } EnableMenu(getConsoleIdentifier(), menuNameAdr, FALSE); freeAllocatedSingleString(menuNameAdr); } else if (nbInputArgument(pvApiCtx) == 2) { // Unset a Menu a Scilab Graphic Window if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)) && (checkInputArgumentType(pvApiCtx, 2, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfigureNumberAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrfigureNumberAdr, &nbRow, &nbCol, &figureNumberAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } if (nbRow * nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1); return FALSE; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmenuNameAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } EnableMenu(getFigureFromIndex((int)*figureNumberAdr), menuNameAdr, FALSE); freeAllocatedSingleString(menuNameAdr); } else if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)) && (checkInputArgumentType(pvApiCtx, 2, sci_matrix))) // Unset a submenu in main window { // Error message in not in standard mode (we need figure number) if (getScilabMode() != SCILAB_STD) { Scierror(999, _("%s: Figure number must be given when not in '%s' mode.\n"), fname, "STD"); return FALSE; } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmenuNameAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrsubMenuIndexAdr); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedSingleString(menuNameAdr); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrsubMenuIndexAdr, &nbRow, &nbCol, &subMenuIndexAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); freeAllocatedSingleString(menuNameAdr); return 1; } if (nbRow * nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 2); freeAllocatedSingleString(menuNameAdr); return FALSE; } EnableSubMenu(getConsoleIdentifier(), menuNameAdr, (int)*subMenuIndexAdr, FALSE); freeAllocatedSingleString(menuNameAdr); } else { Scierror(999, _("%s: Wrong input arguments: '%s' or '%s' expected.\n"), fname, "(button, nsub)", "(gwin, button)"); return FALSE; } } else // Unset a submenu in graphics window { if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfigureNumberAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrfigureNumberAdr, &nbRow, &nbCol, &figureNumberAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } if (nbRow * nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 1); return FALSE; } if ((checkInputArgumentType(pvApiCtx, 2, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmenuNameAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return FALSE; } if ((checkInputArgumentType(pvApiCtx, 3, sci_matrix))) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrsubMenuIndexAdr); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedSingleString(menuNameAdr); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDouble(pvApiCtx, piAddrsubMenuIndexAdr, &nbRow, &nbCol, &subMenuIndexAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); freeAllocatedSingleString(menuNameAdr); return 1; } if (nbRow * nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 3); freeAllocatedSingleString(menuNameAdr); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 3); freeAllocatedSingleString(menuNameAdr); return FALSE; } EnableSubMenu(getFigureFromIndex((int)*figureNumberAdr), menuNameAdr, (int)*subMenuIndexAdr, FALSE); freeAllocatedSingleString(menuNameAdr); } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int get_children_property(char *pobjUID) { int i = 0; int status = 0; long *plChildren = NULL; char **pstChildrenUID; int iHidden = 0; int *piHidden = &iHidden; int iNotHiddenChildrenNumber = 0; int iChildIndex = 0; int iShowHiddenHandles = 0; int *piShowHiddenHandles = &iShowHiddenHandles; // All Graphic Objects have __GO_CHILDREN__ & __GO_CHILDREN_COUNT__ properties. int iChildrenCount = 0; int *piChildrenCount = &iChildrenCount; getGraphicObjectProperty(pobjUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&piChildrenCount); if (piChildrenCount[0] == 0) { // No Child return sciReturnEmptyMatrix(); } getGraphicObjectProperty(pobjUID, __GO_CHILDREN__, jni_string_vector, (void **)&pstChildrenUID); getGraphicObjectProperty(getConsoleIdentifier(), __GO_SHOWHIDDENHANDLES__, jni_bool, (void **)&piShowHiddenHandles); if (iShowHiddenHandles == 0) { // Find number of not hidden children for (i = 0; i < piChildrenCount[0]; ++i) { getGraphicObjectProperty(pstChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden); if (iHidden == 0) { iNotHiddenChildrenNumber++; } } if (iNotHiddenChildrenNumber == 0) { // No Child return sciReturnEmptyMatrix(); } } else { iNotHiddenChildrenNumber = piChildrenCount[0]; } plChildren = MALLOC(iNotHiddenChildrenNumber * sizeof(long)); for (i = 0; i < piChildrenCount[0]; ++i) { getGraphicObjectProperty(pstChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden); if (iHidden == 0 || iShowHiddenHandles == 1) { plChildren[iChildIndex++] = getHandle(pstChildrenUID[i]); } } status = sciReturnColHandleVector(plChildren, iNotHiddenChildrenNumber); FREE(plChildren); return status; }
/*--------------------------------------------------------------------------*/ int sci_get(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; long long* l1 = NULL; int* piAddrl2 = NULL; char* l2 = NULL; int m1 = 0, n1 = 0; long hdl = 0; int lw = 0; int iObjUID = 0; int status = SET_PROPERTY_ERROR; CheckInputArgument(pvApiCtx, 1, 2); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isMListType(pvApiCtx, piAddrl1) || isTListType(pvApiCtx, piAddrl1)) { OverLoad(1); return 0; } /* * The first input argument can be an ID or a marker (in this case, get returns the value of the current object */ switch (getInputArgumentType(pvApiCtx, 1)) { case sci_matrix: //console handle { double dbll1 = 0; if (isScalar(pvApiCtx, piAddrl1) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } // Retrieve a matrix of double at position 1. if (getScalarDouble(pvApiCtx, piAddrl1, &dbll1)) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } if ((int)dbll1 == 0) /* Console property */ { int* piAddrstkAdr = NULL; char *stkAdr = NULL; if (nbInputArgument(pvApiCtx) == 1) { if (sciReturnHandle(getHandle(getConsoleIdentifier())) != 0) /* Get Console handle */ { ReturnArguments(pvApiCtx); return 0; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } CheckInputArgument(pvApiCtx, 2, 2); sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrstkAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrstkAdr, &stkAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (GetScreenProperty(pvApiCtx, stkAdr) != SET_PROPERTY_SUCCEED) { Scierror(999, _("%s: Could not read property '%s' for console object.\n"), "get", stkAdr[0]); freeAllocatedSingleString(stkAdr); return 1; } freeAllocatedSingleString(stkAdr); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } return 0; break; } case sci_handles: /* scalar argument (hdl + string) */ CheckInputArgument(pvApiCtx, 1, 2); // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } if (m1 != 1 || n1 != 1) { //lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx); OverLoad(1); return 0; } if (nbInputArgument(pvApiCtx) == 1) { //get path from handle int uic = getObjectFromHandle((long) * l1); char* path = get_path(uic); if (path[0] == '\0') { Scierror(999, _("%s: Unable to get useful path from this handle.\n"), fname); return 1; } createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, path); FREE(path); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddrl2) == 0 || isStringType(pvApiCtx, piAddrl2) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } hdl = (long) * l1; /* on recupere le pointeur d'objet par le handle */ break; case sci_strings: /* string argument (string) */ { char* pstFirst = NULL; CheckInputArgument(pvApiCtx, 1, 2); if (isScalar(pvApiCtx, piAddrl1) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, &pstFirst)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } if (strcmp(pstFirst, "default_figure") == 0 || strcmp(pstFirst, "default_axes") == 0 || strcmp(pstFirst, "current_figure") == 0 || strcmp(pstFirst, "current_axes") == 0 || strcmp(pstFirst, "current_entity") == 0 || strcmp(pstFirst, "hdl") == 0 || strcmp(pstFirst, "figures_id") == 0) { hdl = 0; l2 = pstFirst; } else { int uid = search_path(pstFirst); if (uid != 0) { freeAllocatedSingleString(pstFirst); hdl = getHandle(uid); if (nbInputArgument(pvApiCtx) == 1) { createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, hdl); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddrl2) == 0 || isStringType(pvApiCtx, piAddrl2) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } } else { createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } } break; } default: //lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx); OverLoad(1); return 0; break; } /* (l2) est la commande, l3 l'indice sur les parametres de la commande */ CheckOutputArgument(pvApiCtx, 0, 1); if (hdl == 0) { /* No handle specified */ if (callGetProperty(pvApiCtx, 0, (l2)) != 0) { /* An error has occurred */ freeAllocatedSingleString(l2); ReturnArguments(pvApiCtx); return 0; } } else { iObjUID = getObjectFromHandle(hdl); if (iObjUID != 0) { if (callGetProperty(pvApiCtx, iObjUID, (l2)) != 0) { /* An error has occurred */ freeAllocatedSingleString(l2); ReturnArguments(pvApiCtx); return 0; } } else { Scierror(999, _("%s: The handle is not or no more valid.\n"), fname); freeAllocatedSingleString(l2); return 0; } } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); freeAllocatedSingleString(l2); return 0; }