function cObj = mydoclick(cObj)
%HGBIN/MYDOCLICK

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.5 $  $Date: 2000/06/01 02:52:46 $
%   J.H. Roh & B.A. Jones 4-25-97.

figH = gcbf;
selType = get(figH,'SelectionType');
figUnits = get(figH,'Units');

children = cObj.Contents;
selectRect = Pos2Rect(rbbox);

for i = 1:length(children)
   aChild = children{i};
   alreadySelected = get(aChild,'IsSelected');
   
   oldUnits = aChild.Units;
   aChild.Units = figUnits;
   aChildRect = Pos2Rect(aChild.Position);

   inSelection = InSelectRect(aChildRect,selectRect);

   switch selType
   case 'normal'
      if inSelection ~= alreadySelected
	 set(aChild,'IsSelected',inSelection);
      end
   case 'extend'
      if InSelectRect(aChildRect,selectRect)
	 set(aChild,'IsSelected',1);
      end
   otherwise
   end
   
   aChild.Units = oldUnits;
end


function rect = Pos2Rect(pos)
% POS2RECT Local function.
rect = pos + [0 0 pos(1:2)];


function val = InSelectRect(objRect, selectRect)
hits = ((objRect(1:2) >= selectRect(1:2)) & ...
	(objRect(3:4) <= selectRect(3:4))) | ...
       ((objRect(1:2) <= selectRect(1:2)) & ...
        (objRect(3:4) >= selectRect(3:4)));
if hits
   val = 1;
else
   val = 0;
end




