2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Vincent COUVERT
4 * Sets the position of an uicontrol object
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14 #include "SetUicontrolPosition.hxx"
16 using namespace org_scilab_modules_gui_bridge;
18 int SetUicontrolPosition(sciPointObj* sciObj, size_t stackPointer, int valueType, int nbRow, int nbCol)
20 // Position can be [x, y, width, height]
21 // or "x|y|width|height"
23 int xInt = 0, yInt = 0, widthInt = 0, heightInt, nbvalues = 0;
25 double * allValues = NULL;
27 float xDouble = 0.0, yDouble = 0.0, widthDouble = 0.0, heightDouble = 0.0;
29 int * returnValues = NULL;
31 sciPointObj *parent = NULL;
35 if (stackPointer == -1) /* Default values setting */
44 if (valueType == sci_strings)
48 Scierror(999, _("Wrong size for '%s' property: A string or a 1 x %d real row vector expected.\n"), "Position", 4);
49 return SET_PROPERTY_ERROR;
52 nbvalues = sscanf(getStringFromStack(stackPointer), "%e|%e|%e|%e", &xDouble, &yDouble, &widthDouble, &heightDouble);
56 Scierror(999, _("Wrong value for '%s' property: A string or a 1 x %d real row vector expected.\n"), "Position", 4);
57 return SET_PROPERTY_ERROR;
60 xInt = ConvertToPixel(xDouble, pUICONTROL_FEATURE(sciObj)->units, sciObj, TRUE);
61 yInt = ConvertToPixel(yDouble, pUICONTROL_FEATURE(sciObj)->units, sciObj, FALSE);
62 widthInt = ConvertToPixel(widthDouble, pUICONTROL_FEATURE(sciObj)->units, sciObj, TRUE);
63 heightInt = ConvertToPixel(heightDouble, pUICONTROL_FEATURE(sciObj)->units, sciObj, FALSE);
66 else if (valueType == sci_matrix)
68 if(nbCol != 4 || nbRow != 1)
70 Scierror(999, _("Wrong size for '%s' property: A string or a 1 x %d real row vector expected.\n"), "Position", 4);
71 return SET_PROPERTY_ERROR;
74 allValues = getDoubleMatrixFromStack(stackPointer);
75 xInt = ConvertToPixel(allValues[0], pUICONTROL_FEATURE(sciObj)->units, sciObj, TRUE);
76 yInt = ConvertToPixel(allValues[1], pUICONTROL_FEATURE(sciObj)->units, sciObj, FALSE);
77 widthInt = ConvertToPixel(allValues[2], pUICONTROL_FEATURE(sciObj)->units, sciObj, TRUE);
78 heightInt = ConvertToPixel(allValues[3], pUICONTROL_FEATURE(sciObj)->units, sciObj, FALSE);
83 Scierror(999, _("Wrong type for '%s' property: A string or a 1 x %d real row vector expected.\n"), "Position", 4);
84 return SET_PROPERTY_ERROR;
88 if (pUICONTROL_FEATURE(sciObj)->style == SCI_UIFRAME) /* Frame style uicontrols */
90 parent = sciGetParent(sciObj);
91 if (parent != NULL && sciGetEntityType(parent)==SCI_UICONTROL)
93 /* Parent is a frame and position is relative to parent */
94 returnValues = CallScilabBridge::getFramePosition(getScilabJavaVM(),
95 pUICONTROL_FEATURE(parent)->hashMapIndex);
96 xInt = returnValues[0] + xInt;
97 yInt = returnValues[1] + yInt;
100 CallScilabBridge::setFramePosition(getScilabJavaVM(),
101 pUICONTROL_FEATURE(sciObj)->hashMapIndex,
107 else if( sciGetEntityType(sciObj) == SCI_FIGURE ) /* Uicontrol figure */
109 /* disable protection since this function will call Java */
110 disableFigureSynchronization(sciObj);
111 status = sciSetDimension(sciObj, widthInt, heightInt) ;
112 enableFigureSynchronization(sciObj);
113 return (int)(sciInitScreenPosition(sciObj, xInt, yInt) & status);
114 //return (int)(sciInitScreenPosition(sciObj, xInt, yInt) & sciSetWindowDim(sciObj, widthInt, heightInt));
116 else /* All other uicontrol styles */
119 parent = sciGetParent(sciObj);
120 if (parent != NULL && sciGetEntityType(parent)==SCI_UICONTROL)
122 /* Parent is a frame and position is relative to parent */
123 returnValues = CallScilabBridge::getFramePosition(getScilabJavaVM(),
124 pUICONTROL_FEATURE(parent)->hashMapIndex);
125 xInt = returnValues[0] + xInt;
126 yInt = returnValues[1] + yInt;
127 delete [] returnValues;
130 CallScilabBridge::setWidgetPosition(getScilabJavaVM(),
131 pUICONTROL_FEATURE(sciObj)->hashMapIndex,
137 /* Special case for Sliders: set orientation */
138 if (pUICONTROL_FEATURE(sciObj)->style == SCI_SLIDER)
140 if (widthInt > heightInt) /* Horizontal ScrollBar */
142 CallScilabBridge::setSliderHorizontal(getScilabJavaVM(),
143 pUICONTROL_FEATURE(sciObj)->hashMapIndex);
145 else /* Vertical ScrollBar */
147 CallScilabBridge::setSliderVertical(getScilabJavaVM(),
148 pUICONTROL_FEATURE(sciObj)->hashMapIndex);
152 return SET_PROPERTY_SUCCEED;