summaryrefslogtreecommitdiff
path: root/modules/gui/src/cpp/SetUicontrolString.cpp
blob: 770d2a821a00b3d49b1380821990b5cf05a0cb3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2007 - INRIA - Vincent COUVERT
 * Copyright (C) 2011 - DIGITEO - Vincent COUVERT
 * Set the string property of an uicontrol
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at
 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 *
 */

extern "C"
{
#include "SetUicontrol.h"
}

int SetUicontrolString(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    BOOL status = FALSE;
    int objectStyle = -1;
    int *piObjectStyle = &objectStyle;
    int type = -1;
    int *piType = &type;

    // Check type
    getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void**) &piType);
    if (type != __GO_UICONTROL__)
    {
        Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "String");
        return SET_PROPERTY_ERROR;
    }

    //[]
    if (valueType == sci_matrix && nbRow == 0 && nbCol == 0)
    {
        if (setGraphicObjectProperty(iObjUID, __GO_UI_STRING__, (char**)NULL, jni_string_vector, 0) == FALSE)
        {
            Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "String");
            return SET_PROPERTY_ERROR;
        }
        return SET_PROPERTY_SUCCEED;
    }

    // Label must be a character string
    if (valueType != sci_strings)
    {
        Scierror(999, const_cast<char*>(_("Wrong type for '%s' property: A string expected.\n")), "String");
        return SET_PROPERTY_ERROR;
    }

    // Check size according to uicontrol style
    getGraphicObjectProperty(iObjUID, __GO_STYLE__, jni_int, (void**) &piObjectStyle);

    switch (objectStyle)
    {
        case __GO_UI_EDIT__ :
        {
            // Value can be string or a string vector
            if (nbCol > 1 && nbRow > 1)
            {
                Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A string or a vector of strings expected.\n")), "String");
                return SET_PROPERTY_ERROR;
            }
            break;
        }
        case __GO_UI_TABLE__ :
        {
            break;
        }
        case __GO_UI_LISTBOX__ :
        case __GO_UI_POPUPMENU__ :
        {
            //combo and list color

            // ["white",    "#FFFFFF";
            //  "black",    "#000000";
            //  "red",      "#FF0000";
            //  "green",    "#00FF00";
            //  "blue",     "#0000FF"]

            //Matrix must be n*2
            if (nbCol == 2)
            {
                if (setGraphicObjectProperty(iObjUID, __GO_UI_STRING_COLNB__, &nbCol, jni_int, 1) == FALSE)
                {
                    Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "String");
                    return SET_PROPERTY_ERROR;
                }

                if (setGraphicObjectProperty(iObjUID, __GO_UI_STRING__, (char**)_pvData, jni_string_vector, nbRow * nbCol) == FALSE)
                {
                    Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "String");
                    return SET_PROPERTY_ERROR;
                }

                if (setGraphicObjectProperty(iObjUID, __GO_UI_VALUE__, (double**)NULL, jni_double_vector, 0) == FALSE)
                {
                    Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "String");
                    return SET_PROPERTY_ERROR;
                }

                return SET_PROPERTY_SUCCEED;
            }
            break;
        }
        default:
        {
            // Value must be only one string
            if (nbCol * nbRow > 1)
            {
                Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A string expected.\n")), "String");
                return SET_PROPERTY_ERROR;
            }
            break;
        }
    }

    if (setGraphicObjectProperty(iObjUID, __GO_UI_STRING_COLNB__, &nbCol, jni_int, 1) == FALSE)
    {
        Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "String");
        return SET_PROPERTY_ERROR;
    }

    if (setGraphicObjectProperty(iObjUID, __GO_UI_STRING__, (char**)_pvData, jni_string_vector, nbRow * nbCol) == FALSE)
    {
        Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "String");
        return SET_PROPERTY_ERROR;
    }

    //reinit value for popupmenu and listbox after setString.
    if (objectStyle == __GO_UI_POPUPMENU__ || objectStyle == __GO_UI_LISTBOX__)
    {
        if (setGraphicObjectProperty(iObjUID, __GO_UI_VALUE__, (double**)NULL, jni_double_vector, 0) == FALSE)
        {
            Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "String");
            return SET_PROPERTY_ERROR;
        }
    }
    return SET_PROPERTY_SUCCEED;
}