fix storing of userdata address on 64 bits version
[scilab.git] / scilab / modules / graphic_objects / src / cpp / createGraphicObject.cpp
index 2be30f2..cf6d314 100644 (file)
@@ -14,6 +14,12 @@ extern "C"
 {
 #include "createGraphicObject.h"
 #include "getScilabJavaVM.h"
+#include "getGraphicObjectProperty.h"
+#include "setGraphicObjectProperty.h"
+#include "FigureModel.h"
+#include "AxesModel.h"
+#include "CurrentSubwin.h"
+#include "api_scilab.h"
 }
 
 #include "CallGraphicController.hxx"
@@ -76,19 +82,81 @@ int createLabel(int parent, int type)
 
 int createNewFigureWithAxes()
 {
-    return Builder::createNewFigureWithAxes(getScilabJavaVM());
+    int iUserDataSize = 0;
+    int* piUserDataSize = &iUserDataSize;
+    int id = 0;
+    int on = 1;
+    int off = 0;
+
+    id = Builder::createNewFigureWithAxes(getScilabJavaVM());
+
+    //clone user_data is needed
+    getGraphicObjectProperty(getFigureModel(), __GO_USER_DATA_SIZE__, jni_int, (void**)&piUserDataSize);
+    if (iUserDataSize != 0)
+    {
+        int* pUserData = NULL;
+
+        getGraphicObjectProperty(getFigureModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+
+        if(sizeof(void*) == 4) //32 bits
+        {
+            increaseValRef(NULL, (int*)*(int*)pUserData);
+        }
+        else //64 bits
+        {
+            increaseValRef(NULL, (int*)*(long long*)pUserData);
+        }
+
+        setGraphicObjectProperty(id, __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
+    }
+
+    //clone gda user_data is needed
+    getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA_SIZE__, jni_int, (void**)&piUserDataSize);
+    if (iUserDataSize != 0)
+    {
+        int* pUserData = NULL;
+        getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+        setGraphicObjectProperty(getCurrentSubWin(), __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
+    }
+
+    setGraphicObjectProperty(id, __GO_MENUBAR_VISIBLE__, (void*)&off, jni_bool, 1);
+    setGraphicObjectProperty(id, __GO_TOOLBAR_VISIBLE__, (void*)&off, jni_bool, 1);
+    setGraphicObjectProperty(id, __GO_INFOBAR_VISIBLE__, (void*)&off, jni_bool, 1);
+
+    setGraphicObjectProperty(id, __GO_MENUBAR_VISIBLE__, (void*)&on, jni_bool, 1);
+    setGraphicObjectProperty(id, __GO_TOOLBAR_VISIBLE__, (void*)&on, jni_bool, 1);
+    setGraphicObjectProperty(id, __GO_INFOBAR_VISIBLE__, (void*)&on, jni_bool, 1);
+
+    return id;
 }
 
-int createFigure(int iDockable, int iMenubarType, int iToolbarType, int iDefaultAxes, int iVisible,
-                 double* figureSize, double* axesSize, double* position, int iMenuBar, int iToolBar, int iInfoBar)
+int createFigure(int iDockable, int iMenubarType, int iToolbarType, int iDefaultAxes, int iVisible)
 {
-    return Builder::createFigure(getScilabJavaVM(), iDockable != 0, iMenubarType, iToolbarType, iDefaultAxes != 0, iVisible != 0,
-                                 figureSize, figureSize == NULL ? 0 : 2,
-                                 axesSize, axesSize == NULL ? 0 : 2,
-                                 position, position == NULL ? 0 : 2,
-                                 iMenuBar != 0,
-                                 iToolBar != 0,
-                                 iInfoBar != 0);
+    int id = 0;
+    int iUserDataSize = 0;
+    int* piUserDataSize = &iUserDataSize;
+
+    id = Builder::createFigure(getScilabJavaVM(), iDockable != 0, iMenubarType, iToolbarType, iDefaultAxes != 0, iVisible != 0);
+
+    //clone gdf user_data is needed
+    getGraphicObjectProperty(getFigureModel(), __GO_USER_DATA_SIZE__, jni_int, (void**)&piUserDataSize);
+    if (iUserDataSize != 0)
+    {
+        int* pUserData = NULL;
+        getGraphicObjectProperty(getFigureModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+        setGraphicObjectProperty(id, __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
+    }
+
+    //clone gda user_data is needed
+    getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA_SIZE__, jni_int, (void**)&piUserDataSize);
+    if (iUserDataSize != 0)
+    {
+        int* pUserData = NULL;
+        getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+        setGraphicObjectProperty(getCurrentSubWin(), __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
+    }
+
+    return id;
 }
 
 void cloneMenus(int model, int newParent)
@@ -98,12 +166,40 @@ void cloneMenus(int model, int newParent)
 
 int cloneAxesModel(int parent)
 {
-    return Builder::cloneAxesModel(getScilabJavaVM(), parent);
+    int id = Builder::cloneAxesModel(getScilabJavaVM(), parent);
+    int iUserDataSize = 0;
+    int* piUserDataSize = &iUserDataSize;
+
+    //clone user_data is needed
+    getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA_SIZE__, jni_int, (void**)&piUserDataSize);
+    if (iUserDataSize != 0)
+    {
+        int* pUserData = NULL;
+        getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+        setGraphicObjectProperty(id, __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
+    }
+
+    return id;
 }
 
 int createSubWin(int parent)
 {
-    return Builder::createSubWin(getScilabJavaVM(), parent);
+    int id = 0;
+    int iUserDataSize = 0;
+    int* piUserDataSize = &iUserDataSize;
+
+    id = Builder::createSubWin(getScilabJavaVM(), parent);
+
+    //clone user_data is needed
+    getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA_SIZE__, jni_int, (void**)&piUserDataSize);
+    if (iUserDataSize != 0)
+    {
+        int* pUserData = NULL;
+        getGraphicObjectProperty(getAxesModel(), __GO_USER_DATA__, jni_int_vector, (void**)&pUserData);
+        setGraphicObjectProperty(id, __GO_USER_DATA__, pUserData, jni_int_vector, iUserDataSize);
+    }
+
+    return id;
 }
 
 int createText(int iParentsubwinUID, char** text, int nbRow, int nbCol, double x, double y, BOOL autoSize, double* userSize, int  centerPos, int *foreground, int *background, BOOL isboxed, BOOL isline, BOOL isfilled, int align)