function [pos,unit] = get_size_in(obj,unit)

% get_size_in - get position of object in specified units
% -------------------------------------------------------
%
% [pos,unit] = get_size_in(obj,unit)
%
% Input:
% ------
%  obj - object handle
%  unit - desired unit
%
% Output:
% -------
%  pos - position
%  unit - position unit

%--------------------------------
% Author: Harold Figueroa
%--------------------------------
% $Revision: 498 $
% $Date: 2005-02-03 19:53:25 -0500 (Thu, 03 Feb 2005) $
%--------------------------------

% TODO: rename and extend to multiple handle input

%-----------------------
% HANDLE INPUT
%-----------------------

%--
% check handle input
%--

if (~ishandle(obj))
	error('Input must be a handle.');
end

types = {'root','figure','axes','uicontrol'}; type = lower(get(obj,'type'));

if (~ismember(type,types))
	error(['Input handle type ''', type, ''' is not supported.']);
end

%--
% get position in current units if no units input
%--

if ((nargin < 2) || isempty(unit))
	pos = get(obj,'position'); unit = get(obj,'units'); return;
end

%--
% check units input
%--

if (~ischar(unit))
	error('Units must be specified as a string.');
end

% NOTE: expand some unit abbreviations

switch (lower(unit))
	case ('cm')
		unit = 'centimeters';
	case ('in')
		unit = 'inches';
	case ('px')
		unit = 'pixels';
end

units = set(obj,'units');

if (~ismember(unit,units))
	error(['Input units ''', unit, ''' are not valid units for input object.']);
end

%-----------------------
% GET POSITION
%-----------------------

% NOTE: root is screen, the 'position' is screensize

if (obj == 0)
	prop = 'screensize';
else
	prop = 'position';
end

init = get(obj,'units'); set(obj,'units',unit); pos = get(obj,prop); set(obj,'units',init);

