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