summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorYann Collette <yann.collette@scilab.org>2010-05-18 09:17:13 +0200
committerClément DAVID <clement.david@scilab.org>2010-05-18 16:12:05 +0200
commit670a54cca05b52993daa9cb5cac509d60ee17997 (patch)
tree0be9e5132110ed15d1a2c191d9cb67ad50242270 /scilab/modules
parent51fdbcfbcd17d4b7b0ef0fb03dd2847b849945e6 (diff)
downloadscilab-670a54cca05b52993daa9cb5cac509d60ee17997.zip
scilab-670a54cca05b52993daa9cb5cac509d60ee17997.tar.gz
allow the uicontrol function to be overloaded
Change-Id: I47cde8e66981415d93f6a6f5dd8729efe618046c
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/gui/help/en_US/uicontrol.xml24
-rw-r--r--scilab/modules/gui/sci_gateway/c/sci_uicontrol.c16
-rw-r--r--scilab/modules/gui/tests/unit_tests/uicontrol_overload.dia.ref20
-rw-r--r--scilab/modules/gui/tests/unit_tests/uicontrol_overload.tst25
4 files changed, 77 insertions, 8 deletions
diff --git a/scilab/modules/gui/help/en_US/uicontrol.xml b/scilab/modules/gui/help/en_US/uicontrol.xml
index b75cdac..c842264 100644
--- a/scilab/modules/gui/help/en_US/uicontrol.xml
+++ b/scilab/modules/gui/help/en_US/uicontrol.xml
@@ -6,10 +6,6 @@
6 xmlns:ns4="http://www.w3.org/1999/xhtml" 6 xmlns:ns4="http://www.w3.org/1999/xhtml"
7 xmlns:mml="http://www.w3.org/1998/Math/MathML" 7 xmlns:mml="http://www.w3.org/1998/Math/MathML"
8 xmlns:db="http://docbook.org/ns/docbook"> 8 xmlns:db="http://docbook.org/ns/docbook">
9 <info>
10 <pubdate>$LastChangedDate: 2008-04-24 18:08:41 +0200 (jeu, 24 avr 2008)
11 $</pubdate>
12 </info>
13 9
14 <refnamediv> 10 <refnamediv>
15 <refname>uicontrol</refname> 11 <refname>uicontrol</refname>
@@ -502,6 +498,24 @@ set(h, 'value', [1 3]);
502close(f); 498close(f);
503// close the figure 499// close the figure
504 ]]></programlisting> 500 ]]></programlisting>
501
502 <para>uicontrol function can be overloaded</para>
503 <programlisting role="example"><![CDATA[
504// create a mlist
505mymlist = mlist(['objid','A','B'],[],[]);
506
507// overload set / get for objid
508function result = %objid_uicontrol(varargin)
509 // res = uicontrol(mymlist,'A');
510 obj_tmp = varargin(1);
511 field_tmp = varargin(2);
512 printf('uicontrol on an object of type %s, field = %s\n', typeof(obj_tmp), field_tmp);
513 result = %t;
514endfunction
515
516res = uicontrol(mymlist,'property');
517 ]]></programlisting>
518
505 </refsection> 519 </refsection>
506 520
507 <refsection> 521 <refsection>
@@ -524,5 +538,7 @@ close(f);
524 <para>Bertrand Guiheneuf</para> 538 <para>Bertrand Guiheneuf</para>
525 539
526 <para>Vincent Couvert</para> 540 <para>Vincent Couvert</para>
541
542 <para>Yann Collette</para>
527 </refsection> 543 </refsection>
528</refentry> 544</refentry>
diff --git a/scilab/modules/gui/sci_gateway/c/sci_uicontrol.c b/scilab/modules/gui/sci_gateway/c/sci_uicontrol.c
index cd1f057..de1c0a5 100644
--- a/scilab/modules/gui/sci_gateway/c/sci_uicontrol.c
+++ b/scilab/modules/gui/sci_gateway/c/sci_uicontrol.c
@@ -2,6 +2,7 @@
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Allan CORNET 3 * Copyright (C) 2007 - INRIA - Allan CORNET
4 * Copyright (C) 2007 - INRIA - Vincent COUVERT 4 * Copyright (C) 2007 - INRIA - Vincent COUVERT
5 * Copyright (C) 2010 - DIGITEO - Yann COLLETTE
5 * 6 *
6 * This file must be used under the terms of the CeCILL. 7 * 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 * This source file is licensed as described in the file COPYING, which
@@ -65,10 +66,9 @@ int sci_uicontrol(char *fname, unsigned long fname_len)
65 /* DO NOT CHANGE ORDER !! */ 66 /* DO NOT CHANGE ORDER !! */
66 char propertiesNames[NBPROPERTIES][MAXPROPERTYNAMELENGTH] = {"style", "parent", "backgroundcolor", "foregroundcolor","string", "units", "fontweight", "min", "max", "tag", "position", "relief", "horizontalalignment", "verticalalignment", "sliderstep", "fontname", "callback", "fontangle", "fontunits", "fontsize", "listboxtop", "user_data", "value", "userdata", "visible", "enable"}; 67 char propertiesNames[NBPROPERTIES][MAXPROPERTYNAMELENGTH] = {"style", "parent", "backgroundcolor", "foregroundcolor","string", "units", "fontweight", "min", "max", "tag", "position", "relief", "horizontalalignment", "verticalalignment", "sliderstep", "fontname", "callback", "fontangle", "fontunits", "fontsize", "listboxtop", "user_data", "value", "userdata", "visible", "enable"};
67 int *propertiesValuesIndices = NULL; 68 int *propertiesValuesIndices = NULL;
68 69 int lw = 0;
69 char *propertyPart = NULL; 70 char *propertyPart = NULL;
70 71
71 //CheckRhs(2,2);
72 CheckLhs(0,1); 72 CheckLhs(0,1);
73 73
74 if (Rhs==0) 74 if (Rhs==0)
@@ -88,7 +88,8 @@ int sci_uicontrol(char *fname, unsigned long fname_len)
88 88
89 if (VarType(1) != sci_handles) 89 if (VarType(1) != sci_handles)
90 { 90 {
91 Scierror(999,_("%s: Wrong type for input argument #%d: A graphic handle expected.\n"),fname, 1); 91 lw = 1 + Top - Rhs;
92 C2F(overload)(&lw,"uicontrol",9);
92 return FALSE; 93 return FALSE;
93 } 94 }
94 else /* Get parent ID */ 95 else /* Get parent ID */
@@ -136,6 +137,13 @@ int sci_uicontrol(char *fname, unsigned long fname_len)
136 } 137 }
137 else 138 else
138 { 139 {
140 if ((VarType(1) != sci_handles) && (VarType(1) != sci_strings))
141 {
142 lw = 1 + Top - Rhs;
143 C2F(overload)(&lw,"uicontrol",9);
144 return FALSE;
145 }
146
139 /* Allocate memory to store the position of properties in uicontrol call */ 147 /* Allocate memory to store the position of properties in uicontrol call */
140 if((propertiesValuesIndices = (int*)MALLOC(sizeof(int)*NBPROPERTIES))==NULL) 148 if((propertiesValuesIndices = (int*)MALLOC(sizeof(int)*NBPROPERTIES))==NULL)
141 { 149 {
@@ -295,7 +303,7 @@ int sci_uicontrol(char *fname, unsigned long fname_len)
295 /* If no parent given then the current figure is the parent */ 303 /* If no parent given then the current figure is the parent */
296 if(propertiesValuesIndices[1]==NOT_FOUND) 304 if(propertiesValuesIndices[1]==NOT_FOUND)
297 { 305 {
298 sciPointObj * graphicObject = sciGetPointerFromHandle(GraphicHandle); 306 sciPointObj * graphicObject = sciGetPointerFromHandle(GraphicHandle);
299 /* Set the parent */ 307 /* Set the parent */
300 switch(pUICONTROL_FEATURE(graphicObject)->style) 308 switch(pUICONTROL_FEATURE(graphicObject)->style)
301 { 309 {
diff --git a/scilab/modules/gui/tests/unit_tests/uicontrol_overload.dia.ref b/scilab/modules/gui/tests/unit_tests/uicontrol_overload.dia.ref
new file mode 100644
index 0000000..d655dda
--- /dev/null
+++ b/scilab/modules/gui/tests/unit_tests/uicontrol_overload.dia.ref
@@ -0,0 +1,20 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Yann COLLETTE <yann.collette@scilab.org>
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// test overloading of the uicontrol functions
8// create a mlist
9mymlist = mlist(['objid','A','B'],[],[]);
10// overload set / get for objid
11function result = %objid_uicontrol(varargin)
12 // res = uicontrol(mymlist,'A');
13 obj_tmp = varargin(1);
14 field_tmp = varargin(2);
15 printf('uicontrol on an object of type %s, field = %s\n', typeof(obj_tmp), field_tmp);
16 result = %t;
17endfunction
18ierr = execstr('uicontrol(mymlist,''property'');','errcatch');
19uicontrol on an object of type objid, field = property
20if ierr then bugmes();quit;end
diff --git a/scilab/modules/gui/tests/unit_tests/uicontrol_overload.tst b/scilab/modules/gui/tests/unit_tests/uicontrol_overload.tst
new file mode 100644
index 0000000..17d845b
--- /dev/null
+++ b/scilab/modules/gui/tests/unit_tests/uicontrol_overload.tst
@@ -0,0 +1,25 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Yann COLLETTE <yann.collette@scilab.org>
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7
8// test overloading of the uicontrol functions
9
10// create a mlist
11mymlist = mlist(['objid','A','B'],[],[]);
12
13// overload set / get for objid
14function result = %objid_uicontrol(varargin)
15 // res = uicontrol(mymlist,'A');
16 obj_tmp = varargin(1);
17 field_tmp = varargin(2);
18 printf('uicontrol on an object of type %s, field = %s\n', typeof(obj_tmp), field_tmp);
19 result = %t;
20endfunction
21
22ierr = execstr('uicontrol(mymlist,''property'');','errcatch');
23
24if ierr then pause; end
25