📄 guihandles.cpp
字号:
// % names. If several objects have the same tag, that field in the
// % structure contains a vector of handles. Objects with hidden
// % handles are included in the structure.
// %
// % H is a handle that identifies the figure - it can be the figure
// % itself, or any object contained in the figure.
// %
// % HANDLES = GUIHANDLES returns a structure of handles for the
// % current figure.
// %
// % Example:
// %
// % Suppose an application creates a figure with handle F, containing
// % a slider and an editable text uicontrol whose tags are 'valueSlider'
// % and 'valueEdit' respectively. The following excerpts from the
// % application's M-file illustrate the use of GUIHANDLES in callbacks:
// %
// % ... excerpt from the GUI setup code ...
// %
// % f = figure;
// % uicontrol('Style','slider','Tag','valueSlider', ...);
// % uicontrol('Style','edit','Tag','valueEdit',...);
// %
// % ... excerpt from the slider's callback ...
// %
// % handles = guihandles(gcbo); % generate handles struct
// % set(handles.valueEdit, 'string',...
// % num2str(get(handles.valueSlider, 'value')));
// %
// % ... excerpt from the edit's callback ...
// %
// % handles = guihandles(gcbo);
// % val = str2double(get(handles.valueEdit,'String'));
// % if isnumeric(val) & length(val)==1 & ...
// % val >= get(handles.valueSlider, 'Min') & ...
// % val <= get(handles.valueSlider, 'Max')
// % % update the slider's value if the edit's value is OK:
// % set(handles.valueSlider, 'Value', val);
// % else
// % % flush the bad string out of the edit; replace with slider's
// % % current value:
// % set(handles.valueEdit, 'String',...
// % num2str(get(handles.valueSlider, 'Value')));
// % end
// %
// % Note that in this example, the structure of handles is created
// % each time a callback executes. See the GUIDATA help for an
// % example in which the structure is created only once, and cached
// % for subsequent use.
// %
// % See also GUIDATA, GUIDE, OPENFIG.
//
// % Damian T. Packer 6-8-2000
// % Copyright 1984-2002 The MathWorks, Inc.
// % $Revision: 1.7 $ $Date: 2002/05/30 20:42:00 $
//
// if nargin == 0 % use GCF
//
if (nargin_ == 0) {
//
// fig = gcf;
//
fig = gcf();
//
// else % nargin == 1: obtain a figure handle from H
//
} else {
//
// fig = [];
//
fig = _mxarray0_;
//
// if ishandle(h) & length(h) == 1
//
{
mwArray a_ = ishandle(mwVa(h, "h"));
if (tobool(a_) && tobool(a_ & mclLengthInt(mwVa(h, "h")) == 1)) {
//
// fig = getParentFigure(h);
//
fig = guihandles_getParentFigure(mwVa(h, "h"));
} else {
}
//
// end
//
}
//
// if isempty(fig)
//
if (tobool(isempty(mwVv(fig, "fig")))) {
//
// error('H must be the handle to a figure or figure descendent.');
//
error(mwVarargin(_mxarray1_));
//
// end
//
}
//
// end
//
}
//
//
// % the structure creation is handled in a subfunction:
// handles = createHandles(fig);
//
handles = guihandles_createHandles(mwVv(fig, "fig"));
mwValidateOutput(handles, 1, nargout_, "handles", "guihandles");
return handles;
//
//
//
//
}
//
// The function "Mguihandles_getParentFigure" is the implementation version of
// the "guihandles/getParentFigure" M-function from file
// "e:\matlab6.5\toolbox\matlab\uitools\guihandles.m" (lines 78-86). It
// contains the actual compiled code for that M-function. It is a static
// function and must only be called from one of the interface functions,
// appearing below.
//
//
// function fig = getParentFigure(fig)
//
static mwArray Mguihandles_getParentFigure(int nargout_, mwArray fig_in) {
mwLocalFunctionTable save_local_function_table_
= &_local_function_table_guihandles;
mwArray fig = mwArray::UNDEFINED;
fig.CopyInputArg(fig_in);
//
// % if the object is a figure or figure descendent, return the
// % figure. Otherwise return [].
// while ~isempty(fig) & ~strcmp('figure', get(fig,'type'))
//
for (;;) {
mwArray a_ = ~ isempty(mwVa(fig, "fig"));
if (tobool(a_)
&& tobool(
a_
& ~ strcmp(
_mxarray3_,
Nget(1, mwVarargin(mwVa(fig, "fig"), _mxarray5_))))) {
} else {
break;
}
//
// fig = get(fig,'parent');
//
fig = Nget(1, mwVarargin(mwVa(fig, "fig"), _mxarray7_));
//
// end
//
}
mwValidateOutput(fig, 1, nargout_, "fig", "guihandles/getParentFigure");
return fig;
//
//
//
//
}
//
// The function "Mguihandles_createHandles" is the implementation version of
// the "guihandles/createHandles" M-function from file
// "e:\matlab6.5\toolbox\matlab\uitools\guihandles.m" (lines 86-111). It
// contains the actual compiled code for that M-function. It is a static
// function and must only be called from one of the interface functions,
// appearing below.
//
//
// function handles = createHandles(fig)
//
static mwArray Mguihandles_createHandles(int nargout_, mwArray fig) {
mwLocalFunctionTable save_local_function_table_
= &_local_function_table_guihandles;
mwArray handles = mwArray::UNDEFINED;
mwArray prev_h = mwArray::UNDEFINED;
mwArray tag = mwArray::UNDEFINED;
mwArray this_h = mwArray::UNDEFINED;
mwArray all_h = mwArray::UNDEFINED;
//
// % Assemble a struct using all the legal tag names in the figure as
// % fieldnames. Each field contains the handles of the objects using
// % that tag.
// all_h = findall(fig);
//
all_h = findall(mwVa(fig, "fig"), mwVarargin());
//
// handles = [];
//
handles = _mxarray0_;
//
//
// % loop across all objects in figure, looking for legal tags:
// for this_h = all_h'
//
{
mwForLoopIterator viter__;
for (viter__.Start(
ctranspose(mwVv(all_h, "all_h")), mwArray::DIN, mwArray::DIN);
viter__.Next(&this_h);
) {
//
// tag = get(this_h,'tag');
//
tag = Nget(1, mwVarargin(mwVv(this_h, "this_h"), _mxarray9_));
//
// if ~isempty(tag) & isvarname(tag) % can it be used as a fieldname?
//
{
mwArray a_ = ~ isempty(mwVv(tag, "tag"));
if (tobool(a_) && tobool(a_ & isvarname(mwVv(tag, "tag")))) {
//
//
// % if a field of this name already exists, get its contents
// if isfield(handles, tag)
//
if (tobool(
isfield(
mwVv(handles, "handles"), mwVv(tag, "tag")))) {
//
// prev_h = handles.(tag);
//
prev_h
= mwVv(handles, "handles").field(mwVv(tag, "tag"));
//
// else
//
} else {
//
// prev_h = [];
//
prev_h = _mxarray0_;
//
// end
//
}
//
//
// % append our handle to whatever was there before. If nothing
// % was there before, SETFIELD will create the field.
// handles.(tag) = [prev_h this_h];
//
handles.field(mwVv(tag, "tag"))
= horzcat(
mwVarargin(
mwVv(prev_h, "prev_h"), mwVv(this_h, "this_h")));
} else {
}
//
//
// end % if legal tag
//
}
//
// end % loop
//
}
}
mwValidateOutput(
handles, 1, nargout_, "handles", "guihandles/createHandles");
return handles;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -