1 ## Copyright (C) 2008-2012 David Bateman
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{hlink} =} linkprop (@var{h}, @var{prop})
21 ## Link graphics object properties, such that a change in one is
22 ## propagated to the others. The properties to link are given as a
23 ## string of cell string array by @var{prop} and the objects containing
24 ## these properties by the handle array @var{h}.
26 ## An example of the use of linkprop is
32 ## h1 = plot (x, sin (x));
34 ## h2 = plot (x, cos (x));
35 ## hlink = linkprop ([h1, h2], @{"color","linestyle"@});
36 ## set (h1, "color", "green");
37 ## set (h2, "linestyle", "--");
43 function hlink = linkprop (h, prop)
46 elseif (!iscellstr (prop))
47 error ("linkprop: properties must be a string or cell string array");
51 for j = 1 : numel (prop)
52 addlistener (h(i), prop{j}, {@update_prop, h, prop{j}});
56 ## This should be an object that when destroyed removes the links
57 ## The below is not quite right. As when you call "clear hlink" the
58 ## hggroup continues to exist.
60 set (hlink, "deletefcn", {@delete_prop, h, prop});
63 function update_prop (h, d, hlist, prop)
64 persistent recursion = false;
66 ## Don't allow recursion
73 oldval = get (hh, prop);
74 if (! isequal (val, oldval))
79 unwind_protect_cleanup
85 function delete_prop (h, d, hlist, prop)
86 ## FIXME. Actually need to delete the linked properties.
87 ## However, only warn if the graphics objects aren't being deleted.
90 if (ishandle (h) && !strcmpi (get (h, "beingdeleted"), "on"))
96 warning ("linkprop: can not remove linked properties");