2
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
* Copyright (C) 2007 - INRIA - Vincent COUVERT
4
* Set the callback of an uicontrol or uimenu
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
15
#include "SetUiobjectCallback.hxx"
17
using namespace org_scilab_modules_gui_bridge;
19
int SetUiobjectCallback(sciPointObj* sciObj, size_t stackPointer, int valueType, int nbRow, int nbCol)
21
char * cbString = NULL;
24
int strNbRow = 0, strNbCol = 0;
25
int typeNbRow = 0, typeNbCol = 0;
26
int typeStackPointer = 0, stringStackPointer = 0;
28
// Label must be only one character string
29
if (valueType == sci_strings)
32
Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A string expected.\n")), "Callback");
33
return SET_PROPERTY_ERROR;
36
cbString = getStringFromStack(stackPointer);
38
else if (valueType == sci_list)
40
if (nbRow * nbCol != 2)
42
Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: a 2-item list expected.\n")), "Callback");
43
return SET_PROPERTY_ERROR;
46
GetListRhsVar((int)stackPointer, 1, MATRIX_OF_DOUBLE_DATATYPE, &typeNbRow, &typeNbCol, &typeStackPointer);
47
if (typeNbRow * typeNbCol !=1)
49
Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A real expected.\n")), "CallbackType");
50
return SET_PROPERTY_ERROR;
54
cbType = (int) (*stk(typeStackPointer));
57
GetListRhsVar((int)stackPointer, 2, STRING_DATATYPE, &strNbRow, &strNbCol, &stringStackPointer);
60
Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A string expected.\n")), "Callback");
61
return SET_PROPERTY_ERROR;
65
cbString = cstk(stringStackPointer);
69
if (sciGetEntityType( sciObj ) == SCI_UIMENU)
71
// Send the callback to Java
72
CallScilabBridge::setWidgetCallback(getScilabJavaVM(),
73
pUIMENU_FEATURE(sciObj)->hashMapIndex,
77
// Store the value in Scilab
78
// Clear previous callback
79
if (pUIMENU_FEATURE(sciObj)->callback != NULL)
81
delete[] (pUIMENU_FEATURE(sciObj)->callback);
84
// Set the new callback
85
pUIMENU_FEATURE(sciObj)->callback = new char[strlen(cbString) + 1];
86
strcpy(pUIMENU_FEATURE(sciObj)->callback, cbString);
88
pUIMENU_FEATURE(sciObj)->callbackType = cbType;
90
return SET_PROPERTY_SUCCEED;
92
else if (sciGetEntityType( sciObj ) == SCI_UICONTROL)
94
// Send the callback to Java
95
if (pUICONTROL_FEATURE(sciObj)->style == SCI_UIFRAME) /* Frame style uicontrols */
97
CallScilabBridge::setFrameCallback(getScilabJavaVM(),
98
pUICONTROL_FEATURE(sciObj)->hashMapIndex,
102
else /* All other uicontrol styles */
104
CallScilabBridge::setWidgetCallback(getScilabJavaVM(),
105
pUICONTROL_FEATURE(sciObj)->hashMapIndex,
110
// Store the value in Scilab
111
// Clear previous callback
112
if (pUICONTROL_FEATURE(sciObj)->callback != NULL)
114
delete[] (pUICONTROL_FEATURE(sciObj)->callback);
117
// Set the new callback
118
pUICONTROL_FEATURE(sciObj)->callback = new char[strlen(cbString) + 1];
119
strcpy(pUICONTROL_FEATURE(sciObj)->callback, cbString);
121
if (strcmp(pUICONTROL_FEATURE(sciObj)->callback, "") == 0)
123
pUICONTROL_FEATURE(sciObj)->callbackType = -1; /* Disabled */
127
pUICONTROL_FEATURE(sciObj)->callbackType = cbType;
130
return SET_PROPERTY_SUCCEED;
134
Scierror(999, const_cast<char*>(_("No '%s' property for this object.\n")), "Callback");
135
return SET_PROPERTY_ERROR;