function ret = isUIComponentInUIFigure(hObj)
% This undocumented function may be removed in a future release.
%
% Returns true if the  object isa or is parented to a uicomponent in a uifigure

%   Copyright 2020 The MathWorks, Inc.

ret = false;
hFig = ancestor(hObj,'figure');
if matlab.ui.internal.isUIFigure(hFig) && hObj ~= hFig 
    
    %uicomponents parented directly to the figure
    if  isa(hObj,'matlab.ui.control.WebComponent')
        ret = true;
        return
    end

    % Annotations must be editable, even within uipanels (g2559268)
    if isa(hObj, 'matlab.graphics.shape.internal.ScribeObject')
        return
    end
    
    %uipnales.uitabs and etc...
    c1 = ancestor(hFig, 'matlab.ui.container.CanvasContainer');
    c2 = ancestor(hObj, 'matlab.ui.container.CanvasContainer');
    ret = c1 ~= c2;
    
end
end

