1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Vincent COUVERT
4 * Copyright (C) 2011 - DIGITEO - Vincent COUVERT
5 *
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 *
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
14 *
15 */
16
17 #include "gw_gui.h"
18 #include "api_scilab.h"
19 #include "localization.h"
20 #include "Scierror.h"
21 #include "getPropertyAssignedValue.h"
22 #include "HandleManagement.h"
23 #include "freeArrayOfString.h"
24
25 #include "createGraphicObject.h"
26 #include "graphicObjectProperties.h"
27 #include "setGraphicObjectProperty.h"
28 /*--------------------------------------------------------------------------*/
sci_progressionbar(char * fname,void * pvApiCtx)29 int sci_progressionbar(char *fname, void* pvApiCtx)
30 {
31 SciErr sciErr;
32
33 int* piAddrhandleAdr = NULL;
34 long long* handleAdr = NULL;
35 int* piAddrmessageAdr = NULL;
36 long long* stkAdr = NULL;
37
38 int iProgressionbarUID = 0;
39
40 int nbRow = 0, nbCol = 0;
41 int nbRowMessage = 0, nbColMessage = 0;
42
43 char **messageAdr = NULL;
44 int iValue = 0;
45 unsigned long GraphicHandle = 0;
46
47 CheckInputArgument(pvApiCtx, 1, 2);
48 CheckOutputArgument(pvApiCtx, 0, 1);
49
50 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrhandleAdr);
51 if (sciErr.iErr)
52 {
53 printError(&sciErr, 0);
54 return 1;
55 }
56
57 if (nbInputArgument(pvApiCtx) == 1)
58 {
59 if ((checkInputArgumentType(pvApiCtx, 1, sci_handles))) /* ProgressionBar to update */
60 {
61 // Retrieve a matrix of handle at position 1.
62 sciErr = getMatrixOfHandle(pvApiCtx, piAddrhandleAdr, &nbRow, &nbCol, &handleAdr);
63 if (sciErr.iErr)
64 {
65 printError(&sciErr, 0);
66 Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
67 return 1;
68 }
69
70 if (nbRow * nbCol != 1)
71 {
72 Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
73 return FALSE;
74 }
75 }
76 else if ((checkInputArgumentType(pvApiCtx, 1, sci_strings))) /* Message to display */
77 {
78 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmessageAdr);
79 if (sciErr.iErr)
80 {
81 printError(&sciErr, 0);
82 return 1;
83 }
84
85 // Retrieve a matrix of string at position 1.
86 if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRowMessage, &nbColMessage, &messageAdr))
87 {
88 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
89 return 1;
90 }
91 }
92 else
93 {
94 Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle or a string expected.\n"), fname, 1);
95 return FALSE;
96 }
97
98 if (handleAdr == 0)
99 {
100 /* Create a new ProgressionBar */
101 iProgressionbarUID = createGraphicObject(__GO_PROGRESSIONBAR__);
102 GraphicHandle = getHandle(iProgressionbarUID);
103 setGraphicObjectProperty(iProgressionbarUID, __GO_UI_MESSAGE__, messageAdr, jni_string_vector, nbColMessage * nbRowMessage);
104 freeAllocatedMatrixOfString(nbRowMessage, nbColMessage, messageAdr);
105 }
106 else
107 {
108 GraphicHandle = (unsigned long) * (handleAdr);
109 iProgressionbarUID = getObjectFromHandle(GraphicHandle);
110 setGraphicObjectProperty(iProgressionbarUID, __GO_UI_VALUE__, &iValue, jni_int, 1);
111 }
112 }
113 else if (nbInputArgument(pvApiCtx) == 2)
114 {
115 if ((checkInputArgumentType(pvApiCtx, 1, sci_handles)) && (checkInputArgumentType(pvApiCtx, 2, sci_strings))) /* progressionbar(id,mes) */
116 {
117 // Retrieve a matrix of handle at position 1.
118 sciErr = getMatrixOfHandle(pvApiCtx, piAddrhandleAdr, &nbRow, &nbCol, &handleAdr);
119 if (sciErr.iErr)
120 {
121 printError(&sciErr, 0);
122 Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
123 return 1;
124 }
125
126 if (nbRow * nbCol != 1)
127 {
128 Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
129 return FALSE;
130 }
131 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmessageAdr);
132 if (sciErr.iErr)
133 {
134 printError(&sciErr, 0);
135 return 1;
136 }
137
138 // Retrieve a matrix of string at position 2.
139 if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRowMessage, &nbColMessage, &messageAdr))
140 {
141 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
142 return 1;
143 }
144
145 GraphicHandle = (unsigned long) * handleAdr;
146 iProgressionbarUID = getObjectFromHandle(GraphicHandle);
147
148 setGraphicObjectProperty(iProgressionbarUID, __GO_UI_VALUE__, &iValue, jni_int, 1);
149 setGraphicObjectProperty(iProgressionbarUID, __GO_UI_MESSAGE__, messageAdr, jni_string_vector, nbColMessage * nbRowMessage);
150 freeAllocatedMatrixOfString(nbRowMessage, nbColMessage, messageAdr);
151 }
152 else
153 {
154 Scierror(999, _("%s: Wrong input arguments: '%s' expected.\n"), fname, "(id, mes)");
155 return FALSE;
156 }
157 }
158
159 if (nbOutputArgument(pvApiCtx) <= 1)
160 {
161 nbRow = 1;
162 nbCol = 1;
163
164 sciErr = allocMatrixOfHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &stkAdr);
165 if (sciErr.iErr)
166 {
167 printError(&sciErr, 0);
168 Scierror(999, _("%s: Memory allocation error.\n"), fname);
169 return 1;
170 }
171
172 *stkAdr = (long long)GraphicHandle;
173 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
174 }
175 else
176 {
177 AssignOutputVariable(pvApiCtx, 1) = 0;
178 }
179
180 ReturnArguments(pvApiCtx);
181 return TRUE;
182 }
183 /*--------------------------------------------------------------------------*/
184