2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006 - INRIA - Fabrice Leray
4 * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
5 * Copyright (C) 2007 - INRIA - Vincent Couvert
7 * This file must be used under the terms of the CeCILL.
8 * This source file is licensed as described in the file COPYING, which
9 * you should have received as part of this distribution. The terms
10 * are also available at
11 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
15 /*------------------------------------------------------------------------*/
16 /* file: sci_xclick.c */
17 /* desc : interface for xclick routine */
18 /*------------------------------------------------------------------------*/
21 #include "gw_graphics.h"
22 #include "api_scilab.h"
24 #include "localization.h"
25 #include "CallJxclick.h"
26 #include "GetProperty.h"
27 #include "FigureList.h"
28 #include "axesScale.h"
29 #include "HandleManagement.h"
30 #include "BuildObjects.h"
31 #include "CurrentSubwin.h"
33 #include "graphicObjectProperties.h"
34 #include "getGraphicObjectProperty.h"
36 /*--------------------------------------------------------------------------*/
37 int sci_xclick(char *fname, void *pvApiCtx)
42 int one = 1, three = 3;
46 int mouseButtonNumber = 0;
47 char * menuCallback = NULL;
50 double userCoords2D[2];
53 int *piFigureId = &iFigureId;
55 CheckInputArgument(pvApiCtx, -1, 1);
56 CheckOutputArgument(pvApiCtx, 1, 5);
58 //iflag = (nbInputArgument(pvApiCtx) >= 1) ? 1 :0;
60 // Select current figure or create it
61 getOrCreateDefaultSubwin();
67 mouseButtonNumber = getJxclickMouseButtonNumber();
68 pixelCoords[0] = (int) getJxclickXCoordinate();
69 pixelCoords[1] = (int) getJxclickYCoordinate();
70 iWindowUID = getJxclickWindowID();
71 menuCallback = getJxclickMenuCallback();
73 // Convert pixel coordinates to user coordinates
74 // Conversion is not done if the user clicked on a menu (pixelCoords[*] == -1)
75 if (pixelCoords[0] != -1 && pixelCoords[1] != -1)
77 int iClickedSubwinUID = getCurrentSubWin();
78 sciGet2dViewCoordFromPixel(iClickedSubwinUID, pixelCoords, userCoords2D);
82 userCoords2D[0] = pixelCoords[0];
83 userCoords2D[1] = pixelCoords[1];
86 if (nbOutputArgument(pvApiCtx) == 1)
88 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
90 sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, one, three, &rep);
93 printError(&sciErr, 0);
94 Scierror(999, _("%s: Memory allocation error.\n"), fname);
98 rep[0] = (double) mouseButtonNumber;
99 rep[1] = userCoords2D[0];
100 rep[2] = userCoords2D[1];
104 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
106 sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, one, one, &rep);
109 printError(&sciErr, 0);
110 Scierror(999, _("%s: Memory allocation error.\n"), fname);
114 rep[0] = (double) mouseButtonNumber;
117 if (nbOutputArgument(pvApiCtx) >= 2)
119 AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
121 sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, one, one, &rep);
124 printError(&sciErr, 0);
125 Scierror(999, _("%s: Memory allocation error.\n"), fname);
129 rep[0] = userCoords2D[0];
132 if (nbOutputArgument(pvApiCtx) >= 3)
134 AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
135 // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int rep".
136 sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, one, one, &rep);
139 printError(&sciErr, 0);
140 Scierror(999, _("%s: Memory allocation error.\n"), fname);
144 rep[0] = userCoords2D[1];
147 if (nbOutputArgument(pvApiCtx) >= 4)
149 AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
151 sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 4, one, one, &rep);
154 printError(&sciErr, 0);
155 Scierror(999, _("%s: Memory allocation error.\n"), fname);
159 getGraphicObjectProperty(iWindowUID, __GO_ID__, jni_int, (void**)&piFigureId);
160 rep[0] = (double) iFigureId;
163 if (nbOutputArgument(pvApiCtx) >= 5)
166 AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
167 istr = (int)strlen(menuCallback);
169 if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 5, istr * one, &strRep))
171 Scierror(999, _("%s: Memory allocation error.\n"), fname);
174 strncpy(strRep, menuCallback, istr);
177 deleteJxclickString(menuCallback);
179 ReturnArguments(pvApiCtx);
183 /*--------------------------------------------------------------------------*/