1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2013 - Gustavo Barbosa Libotte <gustavolibotte@gmail.com>
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 #include "DatatipOrientation.hxx"
17 
18 extern "C"
19 {
20 #include "api_scilab.h"
21 #include "getScilabJavaVM.h"
22 #include "localization.h"
23 #include "Scierror.h"
24 #include "gw_gui.h"
25 #include "HandleManagement.h"
26 #include "getGraphicObjectProperty.h"
27 #include "graphicObjectProperties.h"
28 #include "os_string.h"
29 }
30 
31 using namespace org_scilab_modules_gui_datatip;
32 
sci_datatip_set_orient(char * fname,void * pvApiCtx)33 int sci_datatip_set_orient(char *fname, void* pvApiCtx)
34 {
35     SciErr sciErr;
36     CheckInputArgument(pvApiCtx, 2, 2);
37     CheckOutputArgument(pvApiCtx, 0, 1);
38 
39     int iDatatipUID     = 0;
40     int* piAddr         = NULL;
41     int iRet            = 0;
42     int iErr            = 0;
43     int compVar         = 0;
44     long long llHandle  = 0;
45 
46     int iType = 0;
47     int *piType = &iType;
48 
49     if (nbInputArgument(pvApiCtx) == 2)
50     {
51         sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
52         if (sciErr.iErr)
53         {
54             printError(&sciErr, 0);
55             return 1;
56         }
57 
58         iErr = getScalarHandle(pvApiCtx, piAddr, &llHandle);
59         if (iErr)
60         {
61             Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
62             return 1;
63         }
64 
65         iDatatipUID = getObjectFromHandle((unsigned long) llHandle);
66 
67         if (checkInputArgumentType(pvApiCtx, 1, sci_handles))
68         {
69             getGraphicObjectProperty(iDatatipUID, __GO_TYPE__, jni_int, (void**) &piType);
70             if (iType == __GO_DATATIP__)
71             {
72                 if (checkInputArgumentType(pvApiCtx, 2, sci_strings))
73                 {
74                     sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
75                     if (sciErr.iErr)
76                     {
77                         printError(&sciErr, 0);
78                         return 1;
79                     }
80 
81                     if (isScalar(pvApiCtx, piAddr))
82                     {
83                         char* pstData = NULL;
84 
85                         iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
86                         if (iRet)
87                         {
88                             freeAllocatedSingleString(pstData);
89                             return iRet;
90                         }
91 
92                         compVar = stricmp(pstData, "upper left");
93                         if (compVar == 0)
94                         {
95                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 0);
96                             freeAllocatedSingleString(pstData);
97                             AssignOutputVariable(pvApiCtx, 1) = 0;
98                             ReturnArguments(pvApiCtx);
99                             return 0;
100                         }
101 
102                         compVar = stricmp(pstData, "upper right");
103                         if (compVar == 0)
104                         {
105                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 1);
106                             freeAllocatedSingleString(pstData);
107                             AssignOutputVariable(pvApiCtx, 1) = 0;
108                             ReturnArguments(pvApiCtx);
109                             return 0;
110                         }
111 
112                         compVar = stricmp(pstData, "lower left");
113                         if (compVar == 0)
114                         {
115                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 2);
116                             freeAllocatedSingleString(pstData);
117                             AssignOutputVariable(pvApiCtx, 1) = 0;
118                             ReturnArguments(pvApiCtx);
119                             return 0;
120                         }
121 
122                         compVar = stricmp(pstData, "lower right");
123                         if (compVar == 0)
124                         {
125                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 3);
126                             freeAllocatedSingleString(pstData);
127                             AssignOutputVariable(pvApiCtx, 1) = 0;
128                             ReturnArguments(pvApiCtx);
129                             return 0;
130                         }
131 
132                         compVar = stricmp(pstData, "left");
133                         if (compVar == 0)
134                         {
135                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 4);
136                             freeAllocatedSingleString(pstData);
137                             AssignOutputVariable(pvApiCtx, 1) = 0;
138                             ReturnArguments(pvApiCtx);
139                             return 0;
140                         }
141 
142                         compVar = stricmp(pstData, "right");
143                         if (compVar == 0)
144                         {
145                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 5);
146                             freeAllocatedSingleString(pstData);
147                             AssignOutputVariable(pvApiCtx, 1) = 0;
148                             ReturnArguments(pvApiCtx);
149                             return 0;
150                         }
151 
152                         compVar = stricmp(pstData, "upper");
153                         if (compVar == 0)
154                         {
155                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 6);
156                             freeAllocatedSingleString(pstData);
157                             AssignOutputVariable(pvApiCtx, 1) = 0;
158                             ReturnArguments(pvApiCtx);
159                             return 0;
160                         }
161 
162                         compVar = stricmp(pstData, "lower");
163                         if (compVar == 0)
164                         {
165                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 7);
166                             freeAllocatedSingleString(pstData);
167                             AssignOutputVariable(pvApiCtx, 1) = 0;
168                             ReturnArguments(pvApiCtx);
169                             return 0;
170                         }
171 
172                         compVar = stricmp(pstData, "automatic");
173                         if (compVar == 0)
174                         {
175                             DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, 8);
176                             freeAllocatedSingleString(pstData);
177                             AssignOutputVariable(pvApiCtx, 1) = 0;
178                             ReturnArguments(pvApiCtx);
179                             return 0;
180                         }
181 
182                         DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, -1);
183                         freeAllocatedSingleString(pstData);
184                         AssignOutputVariable(pvApiCtx, 1) = 0;
185                         ReturnArguments(pvApiCtx);
186                         return 0;
187                     }
188                     else
189                     {
190                         Scierror(999, _("%s: Wrong dimension for input argument #%d: string expected.\n"), fname, 2);
191                         return 1;
192                     }
193                 }
194                 else
195                 {
196                     Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
197                     return 1;
198                 }
199             }
200             else
201             {
202                 Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' handle expected.\n"), fname, 1, "Datatip");
203                 return 1;
204             }
205         }
206         else
207         {
208             Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' handle expected.\n"), fname, 1, "Datatip");
209             return 1;
210         }
211     }
212     else
213     {
214         Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2);
215         return 1;
216     }
217 }
218