1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006 - INRIA - Allan CORNET
4 * Copyright (C) 2007 - INRIA - Vincent COUVERT
5 * Copyright (C) 2011 - DIGITEO - Vincent COUVERT
6 *
7 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 *
9 * This file is hereby licensed under the terms of the GNU GPL v2.0,
10 * pursuant to article 5.3.4 of the CeCILL v.2.1.
11 * This file was originally licensed under the terms of the CeCILL v2.1,
12 * and continues to be available under such terms.
13 * For more information, see the COPYING file which you should have received
14 * along with this program.
15 *
16 */
17
18 #include "gw_gui.h"
19 #include "api_scilab.h"
20 #include "localization.h"
21 #include "Scierror.h"
22 #include "InitUIMenu.h"
23 #include "configvariable_interface.h"
24 #include "FigureList.h"
25 #include "getConsoleIdentifier.h"
26 /*--------------------------------------------------------------------------*/
sci_unsetmenu(char * fname,void * pvApiCtx)27 int sci_unsetmenu(char *fname, void* pvApiCtx)
28 {
29 SciErr sciErr;
30
31 int* piAddrmenuNameAdr = NULL;
32 char* menuNameAdr = NULL;
33 int* piAddrfigureNumberAdr = NULL;
34 double* figureNumberAdr = NULL;
35 int* piAddrsubMenuIndexAdr = NULL;
36 double* subMenuIndexAdr = NULL;
37
38 int nbRow = 0;
39 int nbCol = 0;
40
41 // Check parameter number
42 CheckInputArgument(pvApiCtx, 1, 3);
43 CheckOutputArgument(pvApiCtx, 0, 1);
44
45 if (nbInputArgument(pvApiCtx) == 1)
46 {
47 // Error message in not in standard mode (we need figure number)
48 if (getScilabMode() != SCILAB_STD)
49 {
50 Scierror(999, _("%s: Figure number must be given when not in '%s' mode.\n"), fname, "STD");
51 return FALSE;
52 }
53
54 // Unset a Menu of Scilab Main Window
55 if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings)))
56 {
57 Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
58 return FALSE;
59 }
60
61 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmenuNameAdr);
62 if (sciErr.iErr)
63 {
64 printError(&sciErr, 0);
65 return 1;
66 }
67
68 // Retrieve a matrix of double at position 1.
69 if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr))
70 {
71 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
72 return 1;
73 }
74
75 EnableMenu(getConsoleIdentifier(), menuNameAdr, FALSE);
76 freeAllocatedSingleString(menuNameAdr);
77 }
78 else if (nbInputArgument(pvApiCtx) == 2)
79 {
80 // Unset a Menu a Scilab Graphic Window
81 if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)) && (checkInputArgumentType(pvApiCtx, 2, sci_strings)))
82 {
83 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfigureNumberAdr);
84 if (sciErr.iErr)
85 {
86 printError(&sciErr, 0);
87 return 1;
88 }
89
90 // Retrieve a matrix of double at position 1.
91 sciErr = getMatrixOfDouble(pvApiCtx, piAddrfigureNumberAdr, &nbRow, &nbCol, &figureNumberAdr);
92 if (sciErr.iErr)
93 {
94 printError(&sciErr, 0);
95 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
96 return 1;
97 }
98
99
100 if (nbRow * nbCol != 1)
101 {
102 Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1);
103 return FALSE;
104 }
105
106 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmenuNameAdr);
107 if (sciErr.iErr)
108 {
109 printError(&sciErr, 0);
110 return 1;
111 }
112
113 // Retrieve a matrix of double at position 2.
114 if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr))
115 {
116 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
117 return 1;
118 }
119
120 EnableMenu(getFigureFromIndex((int)*figureNumberAdr), menuNameAdr, FALSE);
121 freeAllocatedSingleString(menuNameAdr);
122 }
123 else if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)) && (checkInputArgumentType(pvApiCtx, 2, sci_matrix))) // Unset a submenu in main window
124 {
125 // Error message in not in standard mode (we need figure number)
126 if (getScilabMode() != SCILAB_STD)
127 {
128 Scierror(999, _("%s: Figure number must be given when not in '%s' mode.\n"), fname, "STD");
129 return FALSE;
130 }
131
132 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmenuNameAdr);
133 if (sciErr.iErr)
134 {
135 printError(&sciErr, 0);
136 return 1;
137 }
138
139 // Retrieve a matrix of double at position 1.
140 if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr))
141 {
142 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
143 return 1;
144 }
145
146 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrsubMenuIndexAdr);
147 if (sciErr.iErr)
148 {
149 printError(&sciErr, 0);
150 freeAllocatedSingleString(menuNameAdr);
151 return 1;
152 }
153
154 // Retrieve a matrix of double at position 2.
155 sciErr = getMatrixOfDouble(pvApiCtx, piAddrsubMenuIndexAdr, &nbRow, &nbCol, &subMenuIndexAdr);
156 if (sciErr.iErr)
157 {
158 printError(&sciErr, 0);
159 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
160 freeAllocatedSingleString(menuNameAdr);
161 return 1;
162 }
163
164
165 if (nbRow * nbCol != 1)
166 {
167 Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 2);
168 freeAllocatedSingleString(menuNameAdr);
169 return FALSE;
170 }
171
172 EnableSubMenu(getConsoleIdentifier(), menuNameAdr, (int)*subMenuIndexAdr, FALSE);
173 freeAllocatedSingleString(menuNameAdr);
174 }
175 else
176 {
177 Scierror(999, _("%s: Wrong input arguments: '%s' or '%s' expected.\n"), fname, "(button, nsub)", "(gwin, button)");
178 return FALSE;
179 }
180 }
181 else // Unset a submenu in graphics window
182 {
183 if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)))
184 {
185 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfigureNumberAdr);
186 if (sciErr.iErr)
187 {
188 printError(&sciErr, 0);
189 return 1;
190 }
191
192 // Retrieve a matrix of double at position 1.
193 sciErr = getMatrixOfDouble(pvApiCtx, piAddrfigureNumberAdr, &nbRow, &nbCol, &figureNumberAdr);
194 if (sciErr.iErr)
195 {
196 printError(&sciErr, 0);
197 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
198 return 1;
199 }
200
201
202 if (nbRow * nbCol != 1)
203 {
204 Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1);
205 return FALSE;
206 }
207 }
208 else
209 {
210 Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 1);
211 return FALSE;
212 }
213
214 if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
215 {
216 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmenuNameAdr);
217 if (sciErr.iErr)
218 {
219 printError(&sciErr, 0);
220 return 1;
221 }
222
223 // Retrieve a matrix of double at position 2.
224 if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr))
225 {
226 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
227 return 1;
228 }
229 }
230 else
231 {
232 Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
233 return FALSE;
234 }
235
236 if ((checkInputArgumentType(pvApiCtx, 3, sci_matrix)))
237 {
238 sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrsubMenuIndexAdr);
239 if (sciErr.iErr)
240 {
241 printError(&sciErr, 0);
242 freeAllocatedSingleString(menuNameAdr);
243 return 1;
244 }
245
246 // Retrieve a matrix of double at position 3.
247 sciErr = getMatrixOfDouble(pvApiCtx, piAddrsubMenuIndexAdr, &nbRow, &nbCol, &subMenuIndexAdr);
248 if (sciErr.iErr)
249 {
250 printError(&sciErr, 0);
251 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
252 freeAllocatedSingleString(menuNameAdr);
253 return 1;
254 }
255
256 if (nbRow * nbCol != 1)
257 {
258 Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 3);
259 freeAllocatedSingleString(menuNameAdr);
260 return FALSE;
261 }
262 }
263 else
264 {
265 Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 3);
266 freeAllocatedSingleString(menuNameAdr);
267 return FALSE;
268 }
269
270 EnableSubMenu(getFigureFromIndex((int)*figureNumberAdr), menuNameAdr, (int)*subMenuIndexAdr, FALSE);
271 freeAllocatedSingleString(menuNameAdr);
272 }
273
274 AssignOutputVariable(pvApiCtx, 1) = 0;
275 ReturnArguments(pvApiCtx);
276 return 0;
277 }
278 /*--------------------------------------------------------------------------*/
279