0784852d78a166770ea377635a627d5c6b269634
[scilab.git] / scilab / modules / graphics / src / c / getHandleProperty / get_children_property.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2004-2006 - INRIA - Fabrice Leray
4  * Copyright (C) 2006 - INRIA - Allan Cornet
5  * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
6  * Copyright (C) 2011 - DIGITEO - Vincent Couvert
7  *
8  * This file must be used under the terms of the CeCILL.
9  * This source file is licensed as described in the file COPYING, which
10  * you should have received as part of this distribution.  The terms
11  * are also available at
12  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13  *
14  */
15
16 /*------------------------------------------------------------------------*/
17 /* file: get_children_property.c                                          */
18 /* desc : function to retrieve in Scilab the children field of a          */
19 /*        handle                                                          */
20 /*------------------------------------------------------------------------*/
21
22 #include "getHandleProperty.h"
23 #include "GetProperty.h"
24 #include "returnProperty.h"
25 #include "MALLOC.h"
26 #include "Scierror.h"
27 #include "localization.h"
28 #include "HandleManagement.h"
29 #include "getConsoleIdentifier.h"
30
31 #include "getGraphicObjectProperty.h"
32 #include "graphicObjectProperties.h"
33
34 /*--------------------------------------------------------------------------*/
35 int get_children_property(void* _pvCtx, char* pobjUID)
36 {
37     int i = 0;
38     int status = 0;
39     long *plChildren = NULL;
40     char **pstChildrenUID;
41     int iHidden = 0;
42     int *piHidden = &iHidden;
43     int iNotHiddenChildrenNumber = 0;
44     int iChildIndex = 0;
45     int iShowHiddenHandles = 0;
46     int *piShowHiddenHandles = &iShowHiddenHandles;
47
48     // All Graphic Objects have __GO_CHILDREN__ & __GO_CHILDREN_COUNT__ properties.
49     int iChildrenCount = 0;
50     int *piChildrenCount = &iChildrenCount;
51
52     getGraphicObjectProperty(pobjUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&piChildrenCount);
53
54     if (piChildrenCount[0] == 0)
55     {
56         // No Child
57         return sciReturnEmptyMatrix(_pvCtx);
58     }
59
60     getGraphicObjectProperty(pobjUID, __GO_CHILDREN__, jni_string_vector, (void **)&pstChildrenUID);
61
62     getGraphicObjectProperty(getConsoleIdentifier(), __GO_SHOWHIDDENHANDLES__, jni_bool, (void **)&piShowHiddenHandles);
63
64     if (iShowHiddenHandles == 0)
65     {
66         // Find number of not hidden children
67         for (i = 0; i < piChildrenCount[0]; ++i)
68         {
69             getGraphicObjectProperty(pstChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
70             if (iHidden == 0)
71             {
72                 iNotHiddenChildrenNumber++;
73             }
74         }
75
76         if (iNotHiddenChildrenNumber == 0)
77         {
78             // No Child
79             return sciReturnEmptyMatrix(_pvCtx);
80         }
81     }
82     else
83     {
84         iNotHiddenChildrenNumber = piChildrenCount[0];
85     }
86
87     plChildren = MALLOC(iNotHiddenChildrenNumber * sizeof(long));
88
89     for (i = 0; i < piChildrenCount[0]; ++i)
90     {
91         getGraphicObjectProperty(pstChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
92         if (iHidden == 0 || iShowHiddenHandles == 1)
93         {
94             plChildren[iChildIndex++] = getHandle(pstChildrenUID[i]);
95         }
96     }
97
98     status = sciReturnColHandleVector(_pvCtx, plChildren, iNotHiddenChildrenNumber);
99     FREE(plChildren);
100
101     return status;
102 }
103
104 /*--------------------------------------------------------------------------*/