2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2013 - Pedro Arthur dos S. Souza
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14 #include "DatatipManager.hxx"
18 #include "api_scilab.h"
19 #include "getScilabJavaVM.h"
20 #include "localization.h"
23 #include "HandleManagement.h"
24 #include "CurrentFigure.h"
27 using namespace org_scilab_modules_gui_datatip;
29 int sci_datatip_manager_mode(char *fname, unsigned long fname_len)
31 int n = 0, iRows = 0, iCols = 0, l1 = 0, i = 0;
34 const char* pstFigureUID = NULL;
42 CheckInputArgument(pvApiCtx, 0, 2);
43 CheckOutputArgument(pvApiCtx, 1, 1);
47 pstFigureUID = getCurrentFigure();
50 enabled = DatatipManager::isEnabled(getScilabJavaVM(), pstFigureUID);
51 DatatipManager::setEnabled(getScilabJavaVM(), pstFigureUID, (!enabled));
56 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
59 printError(&sciErr, 0);
63 sciErr = getVarType(pvApiCtx, piAddr, &iType);
66 printError(&sciErr, 0);
73 sciErr = getMatrixOfBoolean(pvApiCtx, piAddr, &iRows, &iCols, &pbValue);
76 printError(&sciErr, 0);
79 if (iRows * iCols != 1)
81 Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 1);
84 pstFigureUID = getCurrentFigure();
85 enabled = (bool) pbValue[0];
88 sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
91 printError(&sciErr, 0);
94 if (iRows * iCols != 1)
96 Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 1);
99 sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, &iLen, NULL);
102 printError(&sciErr, 0);
105 pstData = (char*) malloc(sizeof(char) * (iLen + 1));
106 sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, &iLen, &pstData);
109 printError(&sciErr, 0);
112 if (strcmp("on", pstData) == 0 || strcmp("T", pstData) == 0 || strcmp("1", pstData) == 0)
114 pstFigureUID = getCurrentFigure();
117 else if (strcmp("off", pstData) == 0 || strcmp("F", pstData) == 0 || strcmp("0", pstData) == 0)
119 pstFigureUID = getCurrentFigure();
125 Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, "on", "off");
131 GetRhsVar(1, GRAPHICAL_HANDLE_DATATYPE, &iRows, &iCols, &stkAdr);
132 if (iRows * iCols != 1)
134 Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
137 pstFigureUID = (char *)getObjectFromHandle((unsigned long) * (hstk(stkAdr)));
140 enabled = !(DatatipManager::isEnabled(getScilabJavaVM(), pstFigureUID));
144 Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 1);
150 GetRhsVar(1, GRAPHICAL_HANDLE_DATATYPE, &iRows, &iCols, &stkAdr);
151 if (iRows * iCols != 1)
153 Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
156 pstFigureUID = (char *)getObjectFromHandle((unsigned long) * (hstk(stkAdr)));
158 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
161 printError(&sciErr, 0);
165 sciErr = getVarType(pvApiCtx, piAddr, &iType);
168 printError(&sciErr, 0);
175 sciErr = getMatrixOfBoolean(pvApiCtx, piAddr, &iRows, &iCols, &pbValue);
178 printError(&sciErr, 0);
181 if (iRows * iCols != 1)
183 Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 1);
186 pstFigureUID = getCurrentFigure();
187 enabled = (bool) pbValue[0];
190 sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
193 printError(&sciErr, 0);
196 if (iRows * iCols != 1)
198 Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 1);
201 sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, &iLen, NULL);
204 printError(&sciErr, 0);
207 pstData = (char*) malloc(sizeof(char) * (iLen + 1));
208 sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, &iLen, &pstData);
211 printError(&sciErr, 0);
214 if (strcmp("on", pstData) == 0 || strcmp("T", pstData) == 0 || strcmp("1", pstData) == 0)
216 pstFigureUID = getCurrentFigure();
219 else if (strcmp("off", pstData) == 0 || strcmp("F", pstData) == 0 || strcmp("0", pstData) == 0)
221 pstFigureUID = getCurrentFigure();
227 Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, "on", "off");
233 Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
239 Scierror(999, _("%s: Wrong number for input argument: %d expected.\n"), fname, 2);
245 DatatipManager::setEnabled(getScilabJavaVM(), pstFigureUID, enabled);