84a0d2a0ff278f513e56dadaa49fe7f43b0c0991
[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, "automatic");
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                         DatatipOrientation::datatipSetOrientation(getScilabJavaVM(), iDatatipUID, (char*)pstData, -1);
140                         freeAllocatedSingleString(pstData);
141                         AssignOutputVariable(pvApiCtx, 1) = 0;
142                         ReturnArguments(pvApiCtx);
143                         return 0;
144                     }
145                     else
146                     {
147                         Scierror(999, _("%s: Wrong dimension for input argument #%d: A string expected.\n"), fname, 2);
148                         return 1;
149                     }
150                 }
151                 else
152                 {
153                     Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
154                     return 1;
155                 }
156             }
157             else
158             {
159                 Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' handle expected.\n"), fname, 1, "Datatip");
160                 return 1;
161             }
162         }
163         else
164         {
165             Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' handle expected.\n"), fname, 1, "Datatip");
166             return 1;
167         }
168     }
169     else
170     {
171         Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2);
172         return 1;
173     }
174 }