function varargout = render_zoombtns(hFig,isZoomXorZoomYNeedeed)
%RENDER_ZOOMBTNS Render the Zoom In and Zoom Out toggle buttons.
%
%   Input:
%     hut - Handle to the Toolbar
%     cbstruct - Structure of function handles for the CallBacks.
%
%   Output:
%     htoolbar - Vector containing handles to the zoom buttons.

%   Author(s): P. Costa 
%   Copyright 1988-2017 The MathWorks, Inc.

if nargin < 2
    isZoomXorZoomYNeedeed = true;
end

hut  = findall(hFig,'type','uitoolbar');

if isempty(hut)
    hut = uitoolbar(hFig);
end

% Load the MAT-file with the icons 
icons = load('zoom_icons.mat');

% Install factory toolbars.
hbtns = uitoolfactory(hut, 'Exploration.ZoomIn');
if isZoomXorZoomYNeedeed
    hbtns = [hbtns, uitoolfactory(hut, 'Exploration.ZoomX')];
    hbtns = [hbtns, uitoolfactory(hut, 'Exploration.ZoomY')];
end
hbtns = [hbtns, uipushtool('Parent', hut, ...
    'CData',           icons.fullviewCData, ...
    'ClickedCallback', @(h, ev) defaultView(hFig), ...
    'Tag',             'defaultview', ...
    'TooltipString',   getString(message('signal:sigtools:render_zoommenus:RestoreDefaultView')))];

% Use the new zoom icons instead of ones in uitoolfactory
set(hbtns(1), ...
    'CData', icons.zoomplusCData, ...
    'Separator', 'on');
if isZoomXorZoomYNeedeed
    set(hbtns(2), ...
        'CData', icons.zoomxCData);
    set(hbtns(3), ...
        'CData', icons.zoomyCData);
end
if nargout>0
    varargout{1} = hbtns;
end

%% ------------------------------------------------------------------------
function defaultView(hFig)

hAxes = findall(hFig, 'type', 'axes');

for indx = 1:length(hAxes)
    if ~strcmpi(getappdata(hAxes(indx), 'zoomable'), 'off') && ...
            ~strcmpi(get(hAxes(indx), 'Tag'), 'legend') && ...
            ~strcmpi(get(hAxes(indx), 'Tag'), 'scribeOverlay')
        zoom(hAxes(indx), 'out');
    end
end

% [EOF]
