1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Allan CORNET
4 * Copyright (C) 2007 - INRIA - Vincent COUVERT
5 * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
6 * Copyright (C) 2011 - DIGITEO - Vincent COUVERT
7 *
8 * Copyright (C) 2012 - 2016 - Scilab Enterprises
9 *
10 * This file is hereby licensed under the terms of the GNU GPL v2.0,
11 * pursuant to article 5.3.4 of the CeCILL v.2.1.
12 * This file was originally licensed under the terms of the CeCILL v2.1,
13 * and continues to be available under such terms.
14 * For more information, see the COPYING file which you should have received
15 * along with this program.
16 *
17 */
18
19 #include <stdio.h>
20 #include "gw_gui.h"
21 /*--------------------------------------------------------------------------*/
22 #include "CreateUIControl.h"
23 #include "HandleManagement.h"
24 #include "sci_malloc.h" /* MALLOC */
25 #include "localization.h"
26 #include "SetPropertyStatus.h"
27 #include "SetHashTable.h"
28 #include "Scierror.h"
29 #include "FigureList.h" /* getFigureFromIndex */
30 #include "Widget.h" /* requestWidgetFocus */
31 #include "freeArrayOfString.h"
32 #include "setGraphicObjectProperty.h"
33 #include "getGraphicObjectProperty.h"
34 #include "graphicObjectProperties.h"
35 #include "CurrentFigure.h"
36 #include "BuildObjects.h"
37 #include "api_scilab.h"
38 #include "createGraphicObject.h"
39 #include "expandPathVariable.h"
40 #include "os_string.h"
41
42 static const char* propertiesNames[] =
43 {
44 "style",
45 "constraints",
46 "margins",
47 "parent",
48 "backgroundcolor",
49 "foregroundcolor",
50 "string",
51 "units",
52 "fontweight",
53 "min",
54 "max",
55 "tag",
56 "position",
57 "relief",
58 "horizontalalignment",
59 "verticalalignment",
60 "sliderstep",
61 "snaptoticks",
62 "fontname",
63 "callback",
64 "fontangle",
65 "fontunits",
66 "fontsize",
67 "listboxtop",
68 "user_data",
69 "value",
70 "userdata",
71 "visible",
72 "enable",
73 "callback_type",
74 "tooltipstring",
75 "layout",
76 "layout_options",
77 "border",
78 "groupname",
79 "title_position",
80 "title_scroll",
81 "scrollable",
82 "icon"
83 };
84 /*--------------------------------------------------------------------------*/
85 static int style_property = -1;
86 static int parent_property = -1;
87 static int user_data_property = -1;
88 static int userdata_property = -1;
89 static int sliderstep_property = -1;
90 static int min_property = -1;
91 static int max_property = -1;
92 static int visible_property = -1;
93 static int position_property = -1;
94 static int scrollable_property = -1;
95 static int string_property = -1;
96 static int tooltipstring_property = -1;
97 /*--------------------------------------------------------------------------*/
98 void init_property_index();
99 /*--------------------------------------------------------------------------*/
sci_uicontrol(char * fname,void * pvApiCtx)100 int sci_uicontrol(char *fname, void* pvApiCtx)
101 {
102 SciErr sciErr;
103
104 int nbRow = 0, nbCol = 0, k = 0;
105 int setStatus = SET_PROPERTY_SUCCEED;
106 int PARENT_NOT_FOUND = -2;
107 int NOT_FOUND = -1;
108 int inputIndex = 0, beginIndex = 0;
109 char *propertyName = NULL;
110 char *styleProperty = NULL;
111
112 int iPropertiesCount = sizeof(propertiesNames) / sizeof(char**);
113 unsigned long GraphicHandle = 0;
114
115 int found = 0; /* Does the property exists ? */
116
117 int *propertiesValuesIndices = NULL;
118
119 int iParentType = -1;
120 int *piParentType = &iParentType;
121 int iParentStyle = -1;
122 int *piParentStyle = &iParentStyle;
123
124 int iParentUID = 0;
125 int iUicontrol = 0;
126 int iCurrentFigure = 0;
127
128 CheckOutputArgument(pvApiCtx, 0, 1);
129
130 //init properties index
131 init_property_index();
132
133 if (nbInputArgument(pvApiCtx) == 0)
134 {
135 /* Create a pushbutton in current figure */
136
137 /* Create a new pushbutton */
138 GraphicHandle = getHandle(CreateUIControl(NULL));
139
140 /* Set current figure as parent */
141 iCurrentFigure = getCurrentFigure();
142 if (iCurrentFigure == 0)
143 {
144 iCurrentFigure = createNewFigureWithAxes();
145 }
146
147 iUicontrol = getObjectFromHandle(GraphicHandle);
148 setGraphicObjectRelationship(iCurrentFigure, iUicontrol);
149 }
150 else if (nbInputArgument(pvApiCtx) == 1)
151 {
152 /* Create a pushbutton in figure given as parameter */
153 /* Or give focus to the uicontrol given as parameter */
154 int* piAddr = NULL;
155 int iType = 0;
156
157 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
158 if (sciErr.iErr)
159 {
160 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
161 return 0;
162 }
163
164 if (isHandleType(pvApiCtx, piAddr) == FALSE && isStringType(pvApiCtx, piAddr) == FALSE)
165 {
166 OverLoad(1);
167 return FALSE;
168 }
169 #if 0 // Allow XML loading
170 else if (isStringType(pvApiCtx, piAddr))
171 {
172 char* pstXmlfile = NULL;
173 char* pstExpandedPath = NULL;
174
175 if (isScalar(pvApiCtx, piAddr) == 0)
176 {
177 Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
178 return FALSE;
179 }
180
181 if (getAllocatedSingleString(pvApiCtx, piAddr, &pstXmlfile))
182 {
183 freeAllocatedSingleString(pstXmlfile);
184 Scierror(999, _("%s: No more memory.\n"), fname);
185 return FALSE;
186 }
187
188 pstExpandedPath = expandPathVariable(pstXmlfile);
189 freeAllocatedSingleString(pstXmlfile);
190 iUicontrol = xmlload(pstExpandedPath);
191 if (iUicontrol < 1)
192 {
193 Scierror(999, _("%s: can not read file %s.\n"), fname, pstExpandedPath);
194 FREE(pstExpandedPath);
195 return 0;
196 }
197 FREE(pstExpandedPath);
198 GraphicHandle = getHandle(iUicontrol);
199
200 /* Create return variable */
201 if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle))
202 {
203 Scierror(999, _("%s: Memory allocation error.\n"), fname);
204 return 1;
205 }
206
207 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
208 ReturnArguments(pvApiCtx);
209 return TRUE;
210 }
211 #endif // Allow XML loading
212 else /* Get parent ID */
213 {
214 int* piAddr = NULL;
215 long long hParent = 0;
216 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
217 if (sciErr.iErr)
218 {
219 printError(&sciErr, 0);
220 return 1;
221 }
222
223 if (isScalar(pvApiCtx, piAddr) == 0)
224 {
225 Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
226 return FALSE;
227 }
228
229 if (getScalarHandle(pvApiCtx, piAddr, &hParent))
230 {
231 Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
232 return 1;
233 }
234
235 iParentUID = getObjectFromHandle((long)hParent);
236 if (iParentUID != 0)
237 {
238 getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
239 if (iParentType == __GO_UICONTROL__) /* Focus management */
240 {
241 int fake = 0; //no real data
242 GraphicHandle = (unsigned long)hParent;
243 setGraphicObjectProperty(iParentUID, __GO_UI_FOCUS__, &fake, jni_int, 1);
244 //requestFocus(iParentUID);
245 }
246 else if (iParentType == __GO_FIGURE__ || iParentType == __GO_UIMENU__) /* PushButton creation */
247 {
248 /* Create a new pushbutton */
249 GraphicHandle = getHandle(CreateUIControl(NULL));
250 iUicontrol = getObjectFromHandle(GraphicHandle);
251
252 /* First parameter is the parent */
253 setGraphicObjectRelationship(iParentUID, iUicontrol);
254 setStatus = callSetProperty(pvApiCtx, iUicontrol, &hParent, sci_handles, 1, 1, (char*)propertiesNames[parent_property]);
255 if (setStatus == SET_PROPERTY_ERROR)
256 {
257 Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName);
258 return FALSE;
259 }
260 }
261 else
262 {
263 Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol",
264 "Figure", "Uimenu");
265 return FALSE;
266 }
267 }
268 else
269 {
270 Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure",
271 "Uimenu");
272 return FALSE;
273 }
274 }
275 }
276 else
277 {
278 if (!checkInputArgumentType(pvApiCtx, 1, sci_handles) && !checkInputArgumentType(pvApiCtx, 1, sci_strings))
279 {
280 OverLoad(1);
281 return FALSE;
282 }
283
284 /* Allocate memory to store the position of properties in uicontrol call */
285 if ((propertiesValuesIndices = (int*)MALLOC(sizeof(int) * iPropertiesCount)) == NULL)
286 {
287 Scierror(999, _("%s: No more memory.\n"), fname);
288 return FALSE;
289 }
290
291 /* Init all positions to NOT_FOUND */
292 for (inputIndex = 0; inputIndex < iPropertiesCount; inputIndex++)
293 {
294 propertiesValuesIndices[inputIndex] = NOT_FOUND; /* Property initialized as not found */
295 }
296
297 /**
298 * Odd number of input arguments
299 * First input is the parent ID
300 * All event inputs are property names
301 * All odd (except first) inputs are property values
302 */
303 if (nbInputArgument(pvApiCtx) % 2 == 1)
304 {
305 if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
306 {
307 if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)))
308 {
309 int* piAddr = NULL;
310 double dblValue = 0;
311
312 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
313 if (sciErr.iErr)
314 {
315 printError(&sciErr, 0);
316 FREE(propertiesValuesIndices);
317 return 1;
318 }
319
320 if (isScalar(pvApiCtx, piAddr) == 0)
321 {
322 Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
323 FREE(propertiesValuesIndices);
324 return FALSE;
325 }
326
327 if (getScalarDouble(pvApiCtx, piAddr, &dblValue))
328 {
329 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
330 FREE(propertiesValuesIndices);
331 return 1;
332 }
333
334 iParentUID = getFigureFromIndex((int)dblValue);
335 }
336 else
337 {
338 Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
339 "Frame uicontrol");
340 FREE(propertiesValuesIndices);
341 return FALSE;
342 }
343 }
344 else /* Get parent ID */
345 {
346 int* piAddr = NULL;
347 long long hParent = 0;
348 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
349 if (sciErr.iErr)
350 {
351 printError(&sciErr, 0);
352 FREE(propertiesValuesIndices);
353 return 1;
354 }
355
356 if (isScalar(pvApiCtx, piAddr) == 0)
357 {
358 Scierror(999, _("%s: Wrong size for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
359 "Frame uicontrol");
360 FREE(propertiesValuesIndices);
361 return FALSE;
362 }
363
364 if (getScalarHandle(pvApiCtx, piAddr, &hParent))
365 {
366 Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
367 FREE(propertiesValuesIndices);
368 return 1;
369 }
370
371 iParentUID = getObjectFromHandle((long)hParent);
372 }
373
374 if (iParentUID == 0)
375 {
376 Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
377 "Frame uicontrol");
378 FREE(propertiesValuesIndices);
379 return FALSE;
380 }
381
382 getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
383 if (iParentType != __GO_FIGURE__)
384 {
385 getGraphicObjectProperty(iParentUID, __GO_STYLE__, jni_int, (void **)&piParentStyle);
386 if (iParentType != __GO_UICONTROL__ ||
387 (iParentStyle != __GO_UI_FRAME__ && iParentStyle != __GO_UI_TAB__ && iParentStyle != __GO_UI_LAYER__))
388 {
389 Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
390 "Frame uicontrol");
391 FREE(propertiesValuesIndices);
392 return FALSE;
393 }
394 }
395 /* First parameter is the parent */
396 propertiesValuesIndices[parent_property] = 1;
397 // First input parameter which is a property name
398 beginIndex = 2;
399 }
400 /**
401 * Even number of input arguments
402 * All odd inputs are property names
403 * All even inputs are property values
404 */
405 else
406 {
407 // First input parameter which is a property name
408 beginIndex = 1;
409 }
410
411 /* Get all properties positions */
412 for (inputIndex = beginIndex; inputIndex < Rhs; inputIndex = inputIndex + 2)
413 {
414 /* Read property name */
415 if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings)))
416 {
417 Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex);
418 FREE(propertiesValuesIndices);
419 return FALSE;
420 }
421 else
422 {
423 int* piAddr = NULL;
424 sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddr);
425 if (sciErr.iErr)
426 {
427 printError(&sciErr, 0);
428 FREE(propertiesValuesIndices);
429 return 1;
430 }
431
432 if (getAllocatedSingleString(pvApiCtx, piAddr, &propertyName))
433 {
434 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex);
435 FREE(propertiesValuesIndices);
436 return 1;
437 }
438
439
440 /* Bug 3031 */
441 /* We only want to compare propertyName along its length */
442 /* 'posi' must be matched to 'position' */
443 found = 0;
444 for (k = 0; k < iPropertiesCount ; k++)
445 {
446 if (strlen(propertyName) <= strlen(propertiesNames[k]))
447 {
448 if (strnicmp(propertyName, propertiesNames[k], strlen(propertyName)) == 0)
449 {
450 propertiesValuesIndices[k] = inputIndex + 1; /* Position of value for property */
451 found = 1;
452 break;
453 }
454 }
455 }
456
457 if (found == 0)
458 {
459 Scierror(999, _("%s: Unknown property: %s for '%s' handles.\n"), fname, propertyName, "Uicontrol");
460 freeAllocatedSingleString(propertyName);
461 FREE(propertiesValuesIndices);
462 return FALSE;
463 }
464 freeAllocatedSingleString(propertyName);
465 }
466 }
467
468 if (propertiesValuesIndices[style_property] != NOT_FOUND) /* Style found */
469 {
470 if ((checkInputArgumentType(pvApiCtx, propertiesValuesIndices[style_property], sci_strings)))
471 {
472 int* piAddr = NULL;
473 sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[style_property], &piAddr);
474 if (sciErr.iErr)
475 {
476 printError(&sciErr, 0);
477 FREE(propertiesValuesIndices);
478 return 1;
479 }
480
481 if (getAllocatedSingleString(pvApiCtx, piAddr, &styleProperty))
482 {
483 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]);
484 FREE(propertiesValuesIndices);
485 return 1;
486 }
487
488 if (strcmp(styleProperty, "frame") == 0)
489 {
490 //check scrollable property to create a scroll frame instead of normal frame
491 if (propertiesValuesIndices[scrollable_property] != NOT_FOUND)
492 {
493 char* pstScroll = NULL;
494 int iScroll = 0;
495 sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[scrollable_property], &piAddr);
496 if (sciErr.iErr)
497 {
498 printError(&sciErr, 0);
499 FREE(propertiesValuesIndices);
500 freeAllocatedSingleString(styleProperty);
501 return 1;
502 }
503
504 if (isStringType(pvApiCtx, piAddr) == 0 && isBooleanType(pvApiCtx, piAddr) == 0 && isScalar(pvApiCtx, piAddr) == 0)
505 {
506 Scierror(202, _("%s: Wrong type for argument #%d: string or boolean expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
507 FREE(propertiesValuesIndices);
508 freeAllocatedSingleString(styleProperty);
509 return 1;
510 }
511
512 if (isStringType(pvApiCtx, piAddr))
513 {
514 if (getAllocatedSingleString(pvApiCtx, piAddr, &pstScroll))
515 {
516 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
517 FREE(propertiesValuesIndices);
518 freeAllocatedSingleString(styleProperty);
519 return 1;
520 }
521
522 if (strcmp(pstScroll, "on") == 0)
523 {
524 iScroll = 1;
525 }
526
527 freeAllocatedSingleString(pstScroll);
528 }
529 else
530 {
531 if (getScalarBoolean(pvApiCtx, piAddr, &iScroll))
532 {
533 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
534 freeAllocatedSingleString(styleProperty);
535 FREE(propertiesValuesIndices);
536 return 1;
537 }
538 }
539
540 if (iScroll)
541 {
542 freeAllocatedSingleString(styleProperty);
543 styleProperty = os_strdup("framescrollable");
544 }
545
546 propertiesValuesIndices[scrollable_property] = NOT_FOUND;
547 }
548 }
549 }
550 else
551 {
552 Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]);
553 FREE(propertiesValuesIndices);
554 return FALSE;
555 }
556 }
557
558 /* Create a new uicontrol */
559 iUicontrol = CreateUIControl(styleProperty);
560 freeAllocatedSingleString(styleProperty);
561 if (iUicontrol == 0) /* Error in creation */
562 {
563 Scierror(999, _("%s: Could not create 'Uicontrol' handle.\n"), fname);
564 FREE(propertiesValuesIndices);
565 return FALSE;
566 }
567 GraphicHandle = getHandle(iUicontrol);
568
569 /* If no parent given then the current figure is the parent */
570 if (propertiesValuesIndices[parent_property] == NOT_FOUND)
571 {
572 /* Set the parent */
573 iCurrentFigure = getCurrentFigure();
574
575 if (iCurrentFigure == 0)
576 {
577 iCurrentFigure = createNewFigureWithAxes();
578 }
579
580 propertiesValuesIndices[parent_property] = PARENT_NOT_FOUND;
581 }
582
583 /* Read and set all properties */
584 for (inputIndex = 1; inputIndex < iPropertiesCount; inputIndex++) /* Style has already been set */
585 {
586 if (propertiesValuesIndices[inputIndex] == PARENT_NOT_FOUND)
587 {
588 //special case for not specified parent
589 //but set relationship at the good moment.
590 setGraphicObjectRelationship(iCurrentFigure, iUicontrol);
591 }
592 else if (propertiesValuesIndices[inputIndex] != NOT_FOUND)
593 {
594 int* piAddr = NULL;
595 sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[inputIndex], &piAddr);
596 if (sciErr.iErr)
597 {
598 printError(&sciErr, 0);
599 FREE(propertiesValuesIndices);
600 return 1;
601 }
602
603 if (inputIndex == user_data_property || inputIndex == userdata_property) /* User data settings */
604 {
605 nbRow = -1;
606 nbCol = -1;
607 setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, 0, 0, 0, (char*)propertiesNames[inputIndex]);
608 }
609 else /* All other properties */
610 {
611 /* Read property value */
612 switch (getInputArgumentType(pvApiCtx, propertiesValuesIndices[inputIndex]))
613 {
614 case sci_matrix:
615 {
616 double* pdblValue = NULL;
617 sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &pdblValue);
618 if (sciErr.iErr)
619 {
620 printError(&sciErr, 0);
621 Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, propertiesValuesIndices[inputIndex]);
622 FREE(propertiesValuesIndices);
623 return 1;
624 }
625
626 setStatus = callSetProperty(pvApiCtx, iUicontrol, pdblValue, sci_matrix, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
627 break;
628 }
629 case sci_strings:
630 /* Index for String & TooltipString properties: Can be more than one character string */
631 if ((inputIndex == string_property) || (inputIndex == tooltipstring_property))
632 {
633 char** pstValue = NULL;
634 if (getAllocatedMatrixOfString(pvApiCtx, piAddr, &nbRow, &nbCol, &pstValue))
635 {
636 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]);
637 FREE(propertiesValuesIndices);
638 return 1;
639 }
640
641 setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
642 freeAllocatedMatrixOfString(nbRow, nbCol, pstValue);
643 }
644 else
645 {
646 char* pstValue = NULL;
647 if (getAllocatedSingleString(pvApiCtx, piAddr, &pstValue))
648 {
649 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]);
650 FREE(propertiesValuesIndices);
651 return 1;
652 }
653
654 nbRow = (int)strlen(pstValue);
655 nbCol = 1;
656 setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
657 freeAllocatedSingleString(pstValue);
658 }
659 break;
660 case sci_handles:
661 {
662 long long* pHandles = NULL;
663 sciErr = getMatrixOfHandle(pvApiCtx, piAddr, &nbRow, &nbCol, &pHandles);
664 if (sciErr.iErr)
665 {
666 printError(&sciErr, 0);
667 Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, propertiesValuesIndices[inputIndex]);
668 FREE(propertiesValuesIndices);
669 return 1;
670 }
671
672 setStatus = callSetProperty(pvApiCtx, iUicontrol, pHandles, sci_handles, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
673 break;
674 }
675 case sci_tlist: //constraints and border
676 {
677 setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, sci_tlist, 1, 1, (char*)propertiesNames[inputIndex]);
678 break;
679 }
680 default:
681 Scierror(999, _("%s: Could not set property '%s'.\n"), fname, (char*)propertiesNames[inputIndex]);
682 setStatus = SET_PROPERTY_ERROR;
683 break;
684 }
685 }
686 if (setStatus == SET_PROPERTY_ERROR)
687 {
688 // comment error because the 'set_propertiesNames[inputIndex]_property' functions already returns an error.
689 //Scierror(999, _("%s: Could not set property '%s'.\n"), fname, (char*)propertiesNames[inputIndex]);
690 FREE(propertiesValuesIndices);
691 return FALSE;
692 }
693 }
694 }
695 }
696
697 if (propertiesValuesIndices != NULL
698 && (propertiesValuesIndices[sliderstep_property] == NOT_FOUND &&
699 (propertiesValuesIndices[min_property] != NOT_FOUND || propertiesValuesIndices[max_property] != NOT_FOUND))) /* SliderStep property not set */
700 {
701 /* Set SliderStep property to [1/100*(Max-Min) 1/10*(Max-Min)] */
702 double maxValue = 0;
703 double* pdblMaxValue = &maxValue;
704 double minValue = 0;
705 double* pdblMinValue = &minValue;
706 double pdblStep[2];
707
708 getGraphicObjectProperty(iUicontrol, __GO_UI_MIN__, jni_double, (void**) &pdblMinValue);
709 getGraphicObjectProperty(iUicontrol, __GO_UI_MAX__, jni_double, (void**) &pdblMaxValue);
710
711 pdblStep[0] = 0.01 * (maxValue - minValue);
712 pdblStep[1] = 0.1 * (maxValue - minValue);
713
714 setGraphicObjectProperty(iUicontrol, __GO_UI_SLIDERSTEP__, pdblStep, jni_double_vector, 2);
715 }
716
717 if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[position_property] == NOT_FOUND)) /* Position property not set */
718 {
719 double* pdblPosition = NULL;
720
721 getGraphicObjectProperty(iUicontrol, __GO_POSITION__, jni_double_vector, (void**) &pdblPosition);
722 setGraphicObjectProperty(iUicontrol, __GO_POSITION__, pdblPosition, jni_double_vector, 4);
723 releaseGraphicObjectProperty(__GO_POSITION__, pdblPosition, jni_double_vector, 4);
724 }
725
726 if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[visible_property] == NOT_FOUND)) /* Visible property not set */
727 {
728 /* Force the uicontrol to be visible because is invisible by default in the model (See bug #10346) */
729 int b = (int)TRUE;
730 setGraphicObjectProperty(iUicontrol, __GO_VISIBLE__, &b, jni_bool, 1);
731 }
732
733 FREE(propertiesValuesIndices);
734
735 /* Create return variable */
736 if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle))
737 {
738 Scierror(999, _("%s: Memory allocation error.\n"), fname);
739 return 1;
740 }
741
742 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
743 ReturnArguments(pvApiCtx);
744 return TRUE;
745 }
746 /*--------------------------------------------------------------------------*/
init_property_index()747 void init_property_index()
748 {
749 if (style_property == -1)
750 {
751 int iPropertiesCount = sizeof(propertiesNames) / sizeof(char**);
752 int i = 0;
753 for (i = 0 ; i < iPropertiesCount ; i++)
754 {
755 if (style_property == -1 && strcmp(propertiesNames[i], "style") == 0)
756 {
757 style_property = i;
758 continue;
759 }
760
761 if (parent_property == -1 && strcmp(propertiesNames[i], "parent") == 0)
762 {
763 parent_property = i;
764 continue;
765 }
766
767 if (user_data_property == -1 && strcmp(propertiesNames[i], "user_data") == 0)
768 {
769 user_data_property = i;
770 continue;
771 }
772
773 if (userdata_property == -1 && strcmp(propertiesNames[i], "userdata") == 0)
774 {
775 userdata_property = i;
776 continue;
777 }
778
779 if (sliderstep_property == -1 && strcmp(propertiesNames[i], "sliderstep") == 0)
780 {
781 sliderstep_property = i;
782 continue;
783 }
784
785 if (min_property == -1 && strcmp(propertiesNames[i], "min") == 0)
786 {
787 min_property = i;
788 continue;
789 }
790
791 if (max_property == -1 && strcmp(propertiesNames[i], "max") == 0)
792 {
793 max_property = i;
794 continue;
795 }
796
797 if (visible_property == -1 && strcmp(propertiesNames[i], "visible") == 0)
798 {
799 visible_property = i;
800 continue;
801 }
802
803 if (position_property == -1 && strcmp(propertiesNames[i], "position") == 0)
804 {
805 position_property = i;
806 continue;
807 }
808
809 if (scrollable_property == -1 && strcmp(propertiesNames[i], "scrollable") == 0)
810 {
811 scrollable_property = i;
812 continue;
813 }
814
815 if (tooltipstring_property == -1 && strcmp(propertiesNames[i], "tooltipstring") == 0)
816 {
817 tooltipstring_property = i;
818 continue;
819 }
820
821 if (string_property == -1 && strcmp(propertiesNames[i], "string") == 0)
822 {
823 string_property = i;
824 continue;
825 }
826 }
827 }
828 }
829 /*--------------------------------------------------------------------------*/
830