www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcwidgets/@classicTable/getCellAt.m

    function index = getCellAt(obj, x, y)
%GETCELLAT A short description of the function
%
%  INDEX = GETCELLAT(OBJ, X, Y) returns the row and column indices of the
%  cell being displayed at point (X, Y).  If no cell is beneath that point,
%  INDEX will be returned as [-1, -1].  A row or column index of 0
%  indicates that a header cell is below the point.

%  Copyright 2000-2006 The MathWorks, Inc. and Ford Global Technologies, Inc.


[index(1), index(2)] = getCellAt(obj.gridObject, x, y);

if any(index>0)
    % Convert this to central scroll area index and then to data array
    % index
        
    [rlim, clim] = size(obj.MainObjects);
    if obj.ShowColumnHeaders
        if strcmp(obj.ColumnHeaderPosition, 'top')
            % index of 1 corresponds to column headers (row 0)
            index(1) = index(1) - 1;
            if index(1) > rlim
                % index is in scrollbar region
                index(1) = 1;
            end
        else
            if index(1)==(rlim+1)
                % index is in the column header row
                index(1) = 0;
            elseif index(1) > (rlim+1)
                % index is in scrollbar region
                index(1) = -1;
            end
        end
    end      
    if obj.ShowRowHeaders
        % index of 1 corresponds to row headers (column 0)
        index(2) = index(2) - 1;
        if index(2) > clim
            % index is in scrollbar region
            index(2) = 1;
        end
    end 
    
    if any(index<0)
        % Make sure we change to all -1 if any direction is not over a
        % display cell
        index = [-1 -1];
    else
        % Add the offsets for the scrolling
        index = index + [obj.CurrentRow obj.CurrentColumn] - [1 1];
    end
    
else
    index = [-1 -1];
end