function installtip(this,gobjects,tipfcn,info)
%INSTALLTIP  Installs point tip on specified G-objects.

%   Author(s): P. Gahinet, John Glass
%   Copyright 1986-2004 The MathWorks, Inc.
%   $Revision: 1.1.6.2 $  $Date: 2004/04/11 00:19:38 $

% RE: TIPFCN is either '' or a MATLAB callback. The tip text is generated by evaluating the 
%     tip function according to
%        TIPTEXT = feval(@fcn,INFO,arg1,...,argN)
%     for TIPFCN = {@fcn arg1 ... argN}
if isempty(tipfcn)
   % Clear tip function
   BDF = '';
else
   BDF = {@localLineButtonDown tipfcn info};
end
set(gobjects,'ButtonDownFcn',BDF)

for ct = 1:length(gobjects)
    set(gobjects(ct),'handlevisibility','off')
    %% Get the behavior object
    hb = hggetbehavior(gobjects(ct),'DataCursor');
    if iscell(tipfcn)
        set(hb,'UpdateFcn',{tipfcn{1} info tipfcn{2:end}});
    else
        set(hb,'UpdateFcn',{tipfcn info});
    end
end

%%%%%%%%%%  Local Functions   %%%%%%%%%%  

function tip = localLineButtonDown(EventSrc,EventData,tipfcn,info)
% Creates data tip and sets its tip function
tip = [];
if info.MarginType == 1
   idx = find(handle(EventSrc)==info.View.MagPoints);
   if ~ishandle(info.View.MagTips(idx))
      % Create tip object
      tip = pointtip(EventSrc,info.TipOptions{:});
      % UDDREVISIT
      MagTips = info.View.MagTips; 
      MagTips(idx) = tip;
      info.View.MagTips = MagTips;
   end
else
   idx = find(handle(EventSrc)==info.View.PhasePoints);
   if ~ishandle(info.View.PhaseTips(idx))
      % Create tip object
      tip = pointtip(EventSrc,info.TipOptions{:});
      % UDDREVISIT
      PhaseTips = info.View.PhaseTips; 
      PhaseTips(idx) = tip;
      info.View.PhaseTips = PhaseTips;
   end
end

if ~isempty(tip)
   % Listener for the Frequency Units of Nyquist or Nichols plot objects. 
   tip.addlistener(handle.listener(info.Carrier.Parent,...
      info.Carrier.Parent.findprop('FrequencyUnits'),...
      'PropertyPostSet',{@LocalUpdateString, tip}));
end


%%% Local function to update the string if the units change.
function LocalUpdateString(EventSource,EventData,tip)
updatestring(tip)
