www.gusucode.com > mbclayouts 工具箱 matlab 源码程序 > mbclayouts/@xregcardlayout/attach.m

    function id=attach(obj,h,card)
% ATTACH   Attach object to xregcardlayout
%
%   ID=ATTACH(OBJ,H) attaches the object H to the xregcardlayout
%   OBJ.  The returned ID may be used to reference H for future
%   xregcardlayout operations.
%
%   ID=ATTACH(OBJ,H,CARD) attaches H to the specified card index.

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


ud=obj.g.info;

if nargin<3
   card=ud.currentcard;
elseif card<1 || card>ud.numcards
   error(message('mbc:xregcardlayout:InvalidIndex'));
end

crds=ud.cards;
crds(end+1)=card;
ud.cards=crds;

isCurrent = (card==ud.currentcard);

if isCurrent && ud.visible
   set(h,'Visible','on');
else
   set(h,'Visible','off');
end

% add object to xregcontainer without repacking
el=get(obj.xregcontainer,'elements');
el(end+1)={h};
set(obj.xregcontainer,'elements',el);

ps=get(obj,'boolpackstatus');
if ~isCurrent || ~ps
    % Mark card as needing future redraw
    cdraw=ud.carddraw;
    cdraw(card)=1;
    ud.carddraw=cdraw;
else
    % Redraw additional handle
    pos=get(obj,'innerposition');
    pos(3:4)=max(pos(3:4),[1 1]);
    set(h,'Position',pos);
end

% get id and save it
id=ud.nextid;
ids=ud.id;
ids(end+1)=id;
ud.id=ids;
ud.nextid=id+1;

obj.g.info=ud;