1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 /*------------------------------------------------------------------------*/
17 /* file: set_figure_name_property.c                                       */
18 /* desc : function to modify in Scilab the figure_name field of           */
19 /*        a handle                                                        */
20 /*------------------------------------------------------------------------*/
21 
22 #include "Scierror.h"
23 #include "localization.h"
24 #include "SetPropertyStatus.h"
25 #include "sci_types.h"
26 #include "os_string.h"
27 
28 #include "setGraphicObjectProperty.h"
29 #include "getGraphicObjectProperty.h"
30 #include "graphicObjectProperties.h"
31 #include "LayoutType.h"
32 /*------------------------------------------------------------------------*/
set_layout_property(void * _pvCtx,int iObjUID,void * _pvData,int valueType,int nbRow,int nbCol)33 int set_layout_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
34 {
35     enum LayoutType layout = LAYOUT_NONE;
36     int iLayout = 0;
37     int* piLayout = &iLayout;
38 
39     if (valueType != sci_strings)
40     {
41         Scierror(999, _("Wrong type for '%s' property: String expected.\n"), "layout");
42         return SET_PROPERTY_ERROR;
43     }
44 
45 
46     //check if we can set layout
47     getGraphicObjectProperty(iObjUID, __GO_LAYOUT_SET__, jni_bool, (void **)&piLayout);
48     if (piLayout == NULL)
49     {
50         Scierror(999, _("'%s' property does not exist for this handle.\n"), "layout");
51         return SET_PROPERTY_ERROR;
52     }
53 
54     if (iLayout == 0)
55     {
56         Scierror(999, _("'%s' has already been set.\n"), "layout");
57         return SET_PROPERTY_ERROR;
58     }
59 
60     if (stricmp((char*)_pvData, "none") == 0)
61     {
62         layout = LAYOUT_NONE;
63     }
64     else if (stricmp((char*)_pvData, "gridbag") == 0)
65     {
66         layout = LAYOUT_GRIDBAG;
67     }
68     else if (stricmp((char*)_pvData, "grid") == 0)
69     {
70         layout = LAYOUT_GRID;
71     }
72     else if (stricmp((char*)_pvData, "border") == 0)
73     {
74         layout = LAYOUT_BORDER;
75     }
76     else
77     {
78         Scierror(999, _("Wrong value for '%s' property: %s, %s or %s expected.\n"), "layout", "'none'", "'grid'", "'gridbag'", "'border'");
79         return SET_PROPERTY_ERROR;
80     }
81 
82     if (setGraphicObjectProperty(iObjUID, __GO_LAYOUT__, &layout, jni_int, 1) == FALSE)
83     {
84         Scierror(999, _("'%s' property does not exist for this handle.\n"), "layout");
85         return SET_PROPERTY_ERROR;
86     }
87 
88     return SET_PROPERTY_SUCCEED;
89 }
90 /*------------------------------------------------------------------------*/
91