2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007-2008 - INRIA - Vincent COUVERT
4 * Copyright (C) 2007-2008 - INRIA - Allan CORNET
5 * Copyright (C) 2008 - Yung-Jang Lee
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 #include "InitUIMenu.hxx"
16 #include "CallScilabBridge.hxx"
20 #include "sci_types.h"
22 #include "getScilabJavaVM.h"
23 #include "GetProperty.h"
24 #include "SetPropertyStatus.h"
25 #include "getPropertyAssignedValue.h"
26 #include "localization.h"
28 #include "HandleManagement.h"
29 #include "setGraphicObjectProperty.h"
30 #include "getGraphicObjectProperty.h"
31 #include "getConsoleIdentifier.h"
32 #include "graphicObjectProperties.h"
33 #include "CurrentFigure.h"
34 #include "BuildObjects.h"
35 #include "scilabmode.h"
38 using namespace org_scilab_modules_gui_bridge;
40 int setMenuParent(int iObjUID, void* pvData, int valueType, int nbRow, int nbCol)
42 int iCurrentFigure = 0;
44 int *piParentType = &parentType;
49 /* Special case to set current figure for parent */
52 // Set the parent property
53 iCurrentFigure = getCurrentFigure();
54 if (iCurrentFigure == 0)
56 iCurrentFigure = createNewFigureWithAxes();
58 setGraphicObjectRelationship(iCurrentFigure, iObjUID);
59 return SET_PROPERTY_SUCCEED;
62 if (nbRow * nbCol != 1)
64 // Parent must be a single value
65 return SET_PROPERTY_ERROR;
68 /* Check parent type */
69 if (getScilabMode() == SCILAB_STD)
71 /* Figure, uimenu or Console can be the parent */
72 if ((valueType != sci_handles) && (valueType != sci_matrix))
74 Scierror(999, const_cast < char *>(_("%s: Wrong type for parent: A handle or 0 expected.\n")), "SetMenuParent");
81 /* Figure, uimenu can be the parent */
82 if (valueType == sci_matrix)
84 Scierror(999, const_cast < char *>(_("%s: can not add a menu into the console in this mode.\n")), "SetMenuParent");
87 else if (valueType != sci_handles)
89 Scierror(999, const_cast < char *>(_("%s: Wrong type for parent: A handle expected.\n")), "SetMenuParent");
94 if (valueType == sci_handles)
96 iParentUID = getObjectFromHandle((long)((long long*)pvData)[0]);
99 getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
100 if (parentType == __GO_FIGURE__ || parentType == __GO_UIMENU__
101 || parentType == __GO_UICONTEXTMENU__)
103 setGraphicObjectRelationship(iParentUID, iObjUID);
107 Scierror(999, const_cast < char *>(_("%s: Wrong type for parent: Figure or uimenu handle expected.\n")), "SetMenuParent");
108 return SET_PROPERTY_ERROR;
113 Scierror(999, const_cast < char *>(_("%s: Wrong type for parent: Figure or uimenu handle expected.\n")), "SetMenuParent");
115 return SET_PROPERTY_ERROR;
119 if (valueType == sci_matrix)
121 // The parent is Scilab Main window (Console Tab)
122 value = (double*)pvData;
125 Scierror(999, const_cast < char *>(_("%s: Wrong value for parent: 0 expected.\n")), "SetMenuParent");
127 return SET_PROPERTY_ERROR;
129 setGraphicObjectRelationship(getConsoleIdentifier(), iObjUID);
132 return SET_PROPERTY_SUCCEED;
135 void EnableMenu(int iParentId, char *name, BOOL status)
137 CallScilabBridge::setMenuEnabled(getScilabJavaVM(), iParentId, name, BOOLtobool(status));
140 void EnableSubMenu(int iParentId, char *name, int position, BOOL status)
142 CallScilabBridge::setSubMenuEnabled(getScilabJavaVM(), iParentId, name, position, BOOLtobool(status));
145 void DeleteMenuWithName(int iParentId, char *name)
147 CallScilabBridge::removeMenu(getScilabJavaVM(), iParentId, name);