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

%   Author(s):  
%   Copyright 1986-2004 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $  $Date: 2004/12/26 21:37:40 $

% 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}

%% Overloaded to add a context menu to the datatip for event deletion.
%% Implementation of datatips prevents this context menu from being added
%% directly to the pointChar.

if isempty(tipfcn)
   % Clear tip function
   BDF = '';
else
   BDF = {@LocalButtonDownFcn 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 = LocalButtonDownFcn(EventSrc,EventData,tipfcn,info)
% Creates data tip and sets its tip function

if ~isa(info.View.PointTips{info.Row,info.Col},'tippack.linetip') 
    %% Create the datatip
    tip = pointtip(EventSrc,info.TipOptions{:});
    PointTips = info.View.PointTips; 
    PointTips{info.Row,info.Col} = tip;
    info.View.PointTips = PointTips;
    %% Add right click menu for event deletion
    info.View.addMenu(info.Data);
else
    tip = [];
end
