~ubuntu-branches/ubuntu/trusty/scilab/trusty

« back to all changes in this revision

Viewing changes to modules/gui/src/cpp/SetUiobjectCallback.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-02 11:02:49 UTC
  • mfrom: (1.4.6)
  • Revision ID: package-import@ubuntu.com-20120802110249-0v5953emkp25geuz
Tags: 5.4.0-beta-2-1~exp1
* New upstream release
* Remove libscilab-java (remove upstream). Use libscilab2-java instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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
5
 
 * 
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
11
 
 *
12
 
 */
13
 
 
14
 
#include <cstring>
15
 
#include "SetUiobjectCallback.hxx"
16
 
 
17
 
using namespace org_scilab_modules_gui_bridge;
18
 
 
19
 
int SetUiobjectCallback(sciPointObj* sciObj, size_t stackPointer, int valueType, int nbRow, int nbCol)
20
 
{
21
 
  char * cbString = NULL;
22
 
  int cbType = 0;
23
 
 
24
 
  int strNbRow = 0, strNbCol = 0;
25
 
  int typeNbRow = 0, typeNbCol = 0;
26
 
  int typeStackPointer = 0, stringStackPointer = 0;
27
 
 
28
 
  // Label must be only one character string
29
 
  if (valueType == sci_strings)
30
 
    {
31
 
      if (nbCol != 1) {
32
 
                  Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A string expected.\n")), "Callback");
33
 
        return SET_PROPERTY_ERROR;
34
 
      }
35
 
      
36
 
      cbString = getStringFromStack(stackPointer);
37
 
    }
38
 
  else if (valueType == sci_list)
39
 
    {
40
 
      if (nbRow * nbCol != 2)
41
 
        {
42
 
                        Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: a 2-item list expected.\n")), "Callback");
43
 
          return SET_PROPERTY_ERROR;
44
 
        }
45
 
 
46
 
      GetListRhsVar((int)stackPointer, 1, MATRIX_OF_DOUBLE_DATATYPE, &typeNbRow, &typeNbCol, &typeStackPointer);
47
 
      if (typeNbRow * typeNbCol !=1)
48
 
        {
49
 
                        Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A real expected.\n")), "CallbackType");
50
 
          return SET_PROPERTY_ERROR;
51
 
        }
52
 
      else
53
 
        {
54
 
          cbType = (int) (*stk(typeStackPointer));
55
 
        }
56
 
 
57
 
      GetListRhsVar((int)stackPointer, 2, STRING_DATATYPE, &strNbRow, &strNbCol, &stringStackPointer);
58
 
      if (strNbCol !=1)
59
 
        {
60
 
                        Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A string expected.\n")), "Callback");
61
 
          return SET_PROPERTY_ERROR;
62
 
        }
63
 
      else
64
 
        {
65
 
          cbString = cstk(stringStackPointer);
66
 
        }
67
 
    }
68
 
 
69
 
  if (sciGetEntityType( sciObj ) == SCI_UIMENU)
70
 
    {
71
 
      // Send the callback to Java
72
 
      CallScilabBridge::setWidgetCallback(getScilabJavaVM(),
73
 
                                          pUIMENU_FEATURE(sciObj)->hashMapIndex,
74
 
                                          cbString,
75
 
                                          cbType);
76
 
 
77
 
      // Store the value in Scilab
78
 
      // Clear previous callback
79
 
      if (pUIMENU_FEATURE(sciObj)->callback != NULL)
80
 
        {
81
 
          delete[] (pUIMENU_FEATURE(sciObj)->callback);
82
 
        }
83
 
 
84
 
      // Set the new callback
85
 
      pUIMENU_FEATURE(sciObj)->callback = new char[strlen(cbString) + 1];
86
 
      strcpy(pUIMENU_FEATURE(sciObj)->callback, cbString);
87
 
 
88
 
      pUIMENU_FEATURE(sciObj)->callbackType = cbType;
89
 
 
90
 
      return SET_PROPERTY_SUCCEED;
91
 
    }
92
 
  else if (sciGetEntityType( sciObj ) == SCI_UICONTROL)
93
 
    {
94
 
      // Send the callback to Java
95
 
      if (pUICONTROL_FEATURE(sciObj)->style == SCI_UIFRAME) /* Frame style uicontrols */
96
 
        {
97
 
          CallScilabBridge::setFrameCallback(getScilabJavaVM(), 
98
 
                                             pUICONTROL_FEATURE(sciObj)->hashMapIndex,
99
 
                                             cbString,
100
 
                                             cbType);
101
 
        }
102
 
      else /* All other uicontrol styles */
103
 
        {
104
 
          CallScilabBridge::setWidgetCallback(getScilabJavaVM(), 
105
 
                                              pUICONTROL_FEATURE(sciObj)->hashMapIndex,
106
 
                                              cbString,
107
 
                                              cbType);
108
 
        }
109
 
 
110
 
      // Store the value in Scilab
111
 
      // Clear previous callback
112
 
      if (pUICONTROL_FEATURE(sciObj)->callback != NULL)
113
 
        {
114
 
          delete[] (pUICONTROL_FEATURE(sciObj)->callback);
115
 
        }
116
 
 
117
 
      // Set the new callback
118
 
      pUICONTROL_FEATURE(sciObj)->callback = new char[strlen(cbString) + 1];
119
 
      strcpy(pUICONTROL_FEATURE(sciObj)->callback, cbString);
120
 
 
121
 
      if (strcmp(pUICONTROL_FEATURE(sciObj)->callback, "") == 0)
122
 
        {
123
 
          pUICONTROL_FEATURE(sciObj)->callbackType = -1; /* Disabled */
124
 
        }
125
 
      else
126
 
        {
127
 
          pUICONTROL_FEATURE(sciObj)->callbackType = cbType;
128
 
        }
129
 
 
130
 
      return SET_PROPERTY_SUCCEED;
131
 
    }
132
 
  else
133
 
    {
134
 
                Scierror(999, const_cast<char*>(_("No '%s' property for this object.\n")), "Callback");
135
 
      return SET_PROPERTY_ERROR;
136
 
    }
137
 
}
138