]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/private/__uiobject_split_args__.m
update packages
[CreaPhase.git] / octave_packages / m / plot / private / __uiobject_split_args__.m
1 ## Copyright (C) 2012 Michael Goffioul
2 ##
3 ## This file is part of Octave.
4 ##
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.
9 ##
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.
14 ##
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/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {[@var{p}, @var{args}] =} __uiobject_split_args__ (@var{who}, @var{args}, @var{parent_type}, @var{use_gcf})
21 ## @end deftypefn
22
23 ## Author: goffioul
24
25 function [parent, args] = __uiobject_split_args__ (who, in_args, parent_type = {}, use_gcf = 1)
26
27   parent = [];
28   args = {};
29   offset = 1;
30
31   if (! isempty (in_args))
32     if (ishandle (in_args{1}))
33       parent = in_args{1};
34       offset = 2;
35     elseif (! ischar (in_args{1}))
36       error ("%s: invalid parent handle.", who);
37     endif
38
39     args = in_args(offset:end);
40   endif
41
42   if (rem (length (args), 2))
43     error ("%s: expecting PROPERTY/VALUE pairs", who);
44   endif
45
46   if (! isempty (args))
47     i = find (strcmpi (args(1:2:end), "parent"), 1, "first");
48     if (! isempty (i) && length (args) >= 2*i)
49       parent = args{2*i};
50       if (! ishandle (parent))
51         error ("%s: invalid parent handle.", who);
52       endif
53       args([2*i-1, 2*i]) = [];
54     endif
55   endif
56
57   if (! isempty (parent))
58     if (! isempty (parent_type) && isempty (find (strcmpi (get (parent, "type"), parent_type))))
59       error ("%s: invalid parent, the parent type must be: %s", ...
60              who, sprintf ("%s, ", parent_type{:})(1:end-2));
61     endif
62   elseif (use_gcf)
63     parent = gcf ();
64   endif
65
66 endfunction