www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@uipushtool/uipushtool.m
function obj=uipushtool(prnt,varargin) %UIPUSHTOOL Constructor for uipushtool object % % OBJ = UIPUSHTOOL(PARENT,prop,value...) % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. if isa(prnt, 'xregGui.uipushtool') obj = prnt; prnt = varargin{1}; varargin(1) = []; elseif ~isa(prnt,'xregGui.uitoolbar') % assume this is an object which can provide a toolbar... obj = xregGui.uipushtool; prnt = getToolBar(prnt); else obj = xregGui.uipushtool; end obj.Parent = prnt; if ~isempty(varargin) set(obj,varargin{:}); end obj.pSetEnable; % add listener for callback execution obj.EventListener = handle.listener(obj, 'ClickedCallback',obj.ClickedCallback); % add listeners for property changes obj.hListener=[ ... handle.listener(obj, obj.findprop('Parent'), 'PropertyPreSet', @i_setparent),... handle.listener(obj, obj.findprop('Enable'), 'PropertyPostSet', @i_setenable),... handle.listener(obj, obj.findprop('Separator'), 'PropertyPostSet', @i_setseparator),... handle.listener(obj, obj.findprop('Visible'), 'PropertyPostSet', @i_setvisible),... handle.listener(obj, obj.findprop('CData'), 'PropertyPostSet', @i_setcdata),... handle.listener(obj, obj.findprop('ClickedCallback'), 'PropertyPostSet', {@i_setcallback, obj.EventListener}),... handle.listener(obj, obj.findprop('TransparentColor'), 'PropertyPostSet', @i_settrans),... handle.listener(obj, 'ObjectBeingDestroyed', @i_delete),... ]; % Register with parent prnt.add(obj); return function i_setparent(srcobj,evt) obj = evt.AffectedObject; obj.Parent.remove(obj); evt.NewValue.add(obj); function i_setenable(srcobj,evt) % Notify toolbar that image should be redrawn obj = evt.AffectedObject; obj.pSetEnable; obj.Parent.pNotifyNewButtonImage(obj); function i_setseparator(srcobj,evt) % Notify toolbar that separator setting has altered obj = evt.AffectedObject; obj.Parent.pNotifyNewButtonSeparator(obj); function i_setvisible(srcobj,evt) % Notify toolbar that visible setting has altered obj = evt.AffectedObject; obj.Parent.pNotifyNewButtonVisible(obj); function i_setcdata(srcobj,evt) obj = evt.AffectedObject; obj.pCDataChanged; function i_setcallback(srcobj,evt, L) set(L, 'Callback', evt.NewValue); function i_settrans(srcobj,evt) % Notify toolbar that image should be redrawn obj = evt.AffectedObject; obj.Parent.pNotifyNewButtonImage(obj); function i_delete(obj,evt) if ~mbcgui.util.isBeingDestroyed(obj.Parent) obj.Parent.remove(obj); end