function update_toolbar(fcn,varargin)
%UPDATE_TOOLBAR Updates the ToolBar for FDATool.
%
% Inputs:
%   fcn   - Update function (for the Toolbar).
%   hFig  - Handle to the Filter Design GUI figure.

%   Author(s): P. Costa
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.5 $  $Date: 2000/06/13 21:41:03 $ 

feval(fcn,varargin{:});

%-------------------------------------------------------------------------
function update_all(hFig);
%UPDATE_ALL Calls all the update functions to update the toolbar.

update_zoomtbstate(hFig);      % Update the zoom togglebuttons state.
update_zoomenable(hFig);       % Update the zoom toggelbuttons enable property.
update_filterspecenable(hFig); % Update the Filter Specifications enable icon.

%-------------------------------------------------------------------------
function update_zoomtbstate(hFig)
%UPDATE_ZOOMTBSTATE Update the state of the "Zoom" ToggleButton
%                   portion of the Toolbar.
%
%  Input:
%    hFig - Handle to the Filter Designer GUI

% Get the userdata structure
ud = get(hFig,'Userdata');
h_toolbar = ud.h.toolbar; 

% h_toolbar is a vector of handles to all toolbar icons.
% The handles to the Zoom in and Zoom out icons are the fifth 
% and sixth entries in the array.
h_zoomin = h_toolbar(5);
h_zoomout = h_toolbar(6);

% Get the current state of the zoom buttons and set the zoom mode.
currentZoom = ud.toolbar.zoom;

switch currentZoom,
case 'none'
    set(h_zoomin,'State','Off');
    set(h_zoomout,'State','Off');
case 'zoomin'
    set(h_zoomout,'State','Off');
case 'zoomout'
    set(h_zoomin,'State','Off'); 
end

%-------------------------------------------------------------------------
function update_zoomenable(hFig)
%UPDATE_ZOOMENABLE Update the 'Enable' property of the "Zoom in" and 
%                  "Zoom out" togglebuttons.
%
%  Input:
%    hFig - Handle to the Filter Designer GUI

% Get the userdata structure
ud = get(hFig,'Userdata');
h_toolbar = ud.h.toolbar; 

% h_toolbar is a vector of handles to all toolbar icons.
% The handles to the Zoom in and Zoom out icons are the fifth 
% and sixth entries in the array.
h_zoomin = h_toolbar(5);
h_zoomout = h_toolbar(6);
h_zoomicons = [h_zoomin h_zoomout];

% Both Zoom buttons are enabled by default
enablestate = 'on';

% Disable Zoom buttons for both "Filter Specifications" and "Filter 
% Coefficients" analyses.
analysisPlot = ud.toolbar.analysis;
if strcmpi(analysisPlot,'filterresponsespecs') | ...
        strcmpi(analysisPlot,'filtercoeffs'),    
    enablestate = 'off';

    % If Zoom buttons are disabled, turn zoom off.
    figzoomstate = 'off';
end

% If Zoom buttons are enabled, check their 'State'
if strcmpi(enablestate,'on'), 
   figzoomstate = chkstateifenabled(h_zoomin, h_zoomout);
end

% Set the Zoom buttons' enable property.
set(h_zoomicons,'Enable',enablestate);

% Set the figure's zoom state
zoom(hFig,figzoomstate);

%-------------------------------------------------------------------------
function update_filterspecenable(hFig)
%UPDATE_FILTERSPECENABLE Update the enable property of the "Filter
%                        Specifications" Pushbutton on the Toolbar. 
%
%  Input:
%    hFig - Handle to the Filter Designer GUI

% Get the userdata structure
ud = get(hFig,'Userdata');
h_toolbar = ud.h.toolbar; 

% h_toolbar is a vector of handles to all toolbar icons.
% The "Filter Specifications" pushbutton is the seventh entry
% in this array.
h_filterspecs = h_toolbar(7);

% fdatool can be in one of the following three modes:
%    1 - Filter Design Mode [default]
%    2 - Import Mode
%    3 - Quantize Mode
currentmode = ud.mode.current;

% The "Filter Specifications" pushbutton will be not be enabled 
% for both the Import and Quantized mode
if isequal(currentmode,2) | isequal(currentmode,3)
    set(h_filterspecs,'Enable','Off');
else
    set(h_filterspecs,'Enable','On');
end


%-------------------------------------------------------------------
%                       Utility Function
%-------------------------------------------------------------------
function figzoomstate = chkstateifenabled(h_zoomin, h_zoomout)
% CHKSTATEIFENABLED Check button state if the Zoom buttons are enabled
%
% Inputs:
%   h_zoomin  - Handle to the Zoom in togglebutton
%   h_zoomout - Handle to the Zoom out togglebutton
%
%   figzoomstate - String with the current zoom state for the figure.

% If Zoom buttons are enabled, but not selected (i.e. 'State' = 'Off')
% Leave zoom off
figzoomstate = 'off';

zoominstate = get(h_zoomin,'State');
if strcmp(zoominstate,'on'),
    figzoomstate = 'inmode';  %zoom(hFig,'inmode');
end

zoomoutstate = get(h_zoomout,'State');
if strcmpi(zoomoutstate,'on'),
    figzoomstate = 'outmode'; %zoom(hFig,'outmode');
end


% [EOF] update_toolbar.m
