www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xreglistctrl/redraw.m

    function obj=redraw(obj,level)
%REDRAW Redraw the list control
%
%  OBJ = REDRAW(OBJ, LEVEL) redraws the list control.  LEVEL can be either
%  'full' or 'cells'.

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


% check to see whether controls should be visible
% ObjVis=get(obj,'visible');

frame = obj.frame;
slider = obj.slider;
ud = get(slider,'UserData');
top = ud.top;
cellHeight = ud.cellHeight;
controls = ud.controls;
sliderWidth = ud.sliderwidth;
border = ud.border;
cellBorder = ud.cellBorder;
pos = ud.position;

if pos(3) < 25+sliderWidth || pos(4) < 40
    pos = [pos(1) pos(2) 25+sliderWidth 40];
end

% check level entered correctly
if nargin == 1 || ~isequal(pos,get(frame,'Position'))
    level = 'full';
end

oldPS = getBoolPackstatus(obj.layout);
setBoolPackstatus(obj.layout, false);
if strcmp(level, 'full')
    set(frame,'Position',pos);
    
    % there is an optional field to fix number of visible cells
    if isempty(ud.fixnumcells)
        % this is the normal mode = KEEP CELL HEIGHT SAME
        % see how many cells we can fit in
        numCells = floor((pos(4)-2*border)/(cellHeight+2*cellBorder));
    else
        % number of visible cells fixed = KEEP NUM CELLS SAME
        % change cell height
        numCells = ud.fixnumcells;
        ud.cellHeight = floor((pos(4)-2*border)/numCells)-2*cellBorder;
    end
    
    % heights checked on SET but just in case
    if numCells < 1
        ud.cellHeight = pos(4)-2*border - 2*cellBorder;
    end
    
    top = max(1,min(top, length(controls)-numCells+1 ));
else
    griddims = get(obj.layout, 'dimension');
    numCells = griddims(1) - 2;
end

slLength = max(length(controls)-numCells+1,1);
slstep = [1 1]/max(1,(slLength-1));
slstep = max(min(slstep,1),0);
set(slider, ...
    'Max',max(slLength,2),...
    'Min',1,...
    'SliderStep',slstep,...
    'Value',min(max(1,slLength-top+1),slLength));

els = cell(1, numCells+3);
els{end} = obj.slider;
if ~isempty(controls)
    % visible 'off' top controls
    if top > 1
        for i = 1:top-1
            set(controls{i},'Visible','off');
        end
    end
    %move the currently visible controls
    k = 2;
    for i = top:min(length(controls), top+numCells-1)
        % set visibility to agree with that of the whole ListCtrl
        set(controls{i},'Visible','on');
        els{k} = controls{i};
        k = k+1;
    end
    % visible off remaining controls
    if length(controls) >= top+numCells
        for i = top+numCells:length(controls)
            set(controls{i},'Visible','off');
        end
    end
end

setBoolPackstatus(obj.layout, oldPS);
set(obj.layout, ...
    'dimension', [numCells+2 2], ...
    'rowsizes', [ud.cellBorder repmat(ud.cellHeight, 1, numCells) -1], ...
    'border', [ud.border -1 -1 -1], ...
    'gapx', ud.cellBorder+ud.border, ...
    'gapy', 2*ud.cellBorder, ...
    'clearmerge', [], ...
    'mergeblock', {[1 numCells+2], [2 2]}, ...
    'elements', els);

ud.top = top;
set(slider,'UserData',ud);

if numCells < length(controls)
    set(slider,'Enable','on');
else
    set(slider,'Enable','off');
end