function hndls_toolbar = render_toolbar(hFig,ud)
%RENDER_TOOLBAR Renders the toolbar for the Filter Designer.

%   Author(s): P. Pacheco, R. Losada, P. Costa
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.5 $  $Date: 2000/06/13 21:23:35 $ 

% Inputs:
%   hFig - handle to the Filter Designer figure.
%
% Outputs:
%   hndls_toolbar - handles to the buttons (icons) on the toolbar.

% Load new, open, save and print from standard MATLAB figure
load mwtoolbaricons;

% Load the MAT-file with the icons for the Filter Designer
load filtdes_icons;

% Load the zoom button icons
load zoom_icons;

menuscbs     = menus_cbs;     % get structure of all local callback functions
help_handles = fdatool_help;  % get structure of all local callback functions


% -------- FILE PUSHBUTTONS --------
% Cell array of cdata (properties) for the toolbar icons 
% that are file pushbuttons (New, Open, Save, and Print)
pushbuttons = {...
        newdoc,...
        opendoc,...
        savedoc,...
        printdoc};

% List the corresponding tooltips
pushbuttons_tooltips= {...
        'New session',...
        'Open session',...
        'Save session',...
        'Print Current Response'};

% List tags for the pushbuttons
pushbuttons_tags = {...
        'newsession',...
        'opensession',...
        'savesession',...
        'printresp'};

% List callbacks for pushbuttons
pushbuttons_callbacks = {...
        menuscbs.new_cb,...
        menuscbs.open_cb,...
        menuscbs.save_cb,...
        menuscbs.print_cb};


% -------- ZOOM TOGGLEBUTTONS --------
% Cell array of cdata (properties) for the toolbar icons 
% that are togglebuttons (Zoom in and Zoom out)
togglebuttons = {...
        zoomplusCData,...
        zoomminusCData};

% List the corresponding tooltips 
togglebuttons_tooltips = {...
        'Zoom In',...
        'Zoom Out'};

% List index of togglebuttons with separators 
togglebuttons_separators = [1];

% List tags for the togglebuttons
togglebuttons_tags = {...
        'zoomin',...
        'zoomout'};

% List callbacks for togglebuttons
togglebuttons_callbacks = {...
        menuscbs.zoom_clickedcb,...
        menuscbs.zoom_clickedcb};

% List OnCallback functions for the togglebuttons
togglebuttons_Oncallbacks = {...
        menuscbs.zoomin_oncb,...
        menuscbs.zoomout_oncb};

% List OffCallback functions for the togglebuttons
togglebuttons_Offcallbacks = {...
        menuscbs.zoomin_offcb,...
        menuscbs.zoomout_offcb};


% -------- ANALYSIS PUSHBUTTONS --------
% Cell array of cdata for all of the toolbar icons 
% that are analysis pushbuttons
analysispushbuttons = {...
        bmp.illus,...
        bmp.mag,...
        bmp.phase,...
        bmp.magnphase,...
        bmp.grpdelay,...
        bmp.impulse,...
        bmp.step,...
        bmp.polezero,...
        bmp.coeffs,...
        bmp.whatsthis};

%        bmp.code,...

% list the corresponding tooltips 
analysispushbuttons_tooltips = {...
        'Filter Specifications',...
        'Magnitude Response',...
        'Phase Response',...
        'Magnitude and Phase Response',...
        'Group Delay',...
        'Impulse Response',...
        'Step Response',...
        'Pole/Zero Plot',...
        'Filter Coefficients',...
        '"What''s This?"'};

%        'MATLAB Code',...

% list indexes of togglebuttons with separators 
%analysispushbuttons_separators = [1 10 11];  % Includes M-code button
analysispushbuttons_separators = [1 10];

% List tags for the analysis pushbuttons
analysispushbuttons_tags = ud.tags.analysis;

% List callbacks for analysis pushbuttons
analysispushbuttons_callbacks = {...
        menuscbs.filterspecs_cb,...
        menuscbs.magresp_cb,...
        menuscbs.phaseresp_cb,...
        menuscbs.magnphaseresp_cb,...
        menuscbs.groupdelay_cb,...
        menuscbs.impresp_cb,...
        menuscbs.stepresp_cb,...
        menuscbs.pzplot_cb,...
        menuscbs.filtercoeffs_cb,...
        help_handles.HelpWhatsThis_cb};

%        menuscbs.mcode_cb,...

% -------- Create toolbar --------
ut = uitoolbar(hFig);

% Put up pushbuttons
for i = 1:length(pushbuttons),
   % The pushbutton callback code is shared with the menus. 

   hndls_toolbar(i) = uipushtool('Cdata',pushbuttons{i},...
        'Parent', ut,...
        'ClickedCallback',pushbuttons_callbacks{i},...
        'Tag',            pushbuttons_tags{i},...
        'Tooltipstring',  pushbuttons_tooltips{i});
end

% Put up zoom togglebuttons
for i = 1:length(togglebuttons),
    separator = 'off';
    if any(i == togglebuttons_separators),
        separator = 'on';
    end 

    hndls_toolbar(i+length(pushbuttons)) = ...
        uitoggletool('Cdata',togglebuttons{i},...
        'Parent',ut,...
        'Tooltipstring',   togglebuttons_tooltips{i},...
        'ClickedCallback', togglebuttons_callbacks{i},...
        'OffCallBack',     togglebuttons_Offcallbacks{i},...   
        'OnCallBack',      togglebuttons_Oncallbacks{i},...
        'Tag',             togglebuttons_tags{i},...
        'Enable','Off',...
        'Separator',separator);
end

% Put up the analysis pushbuttons
for i = 1:length(analysispushbuttons),
	 separator = 'off';
    if any(i == analysispushbuttons_separators),
        separator = 'on';
    end 
    hndls_toolbar(i+(length(pushbuttons)+length(togglebuttons))) = ...
        uipushtool('Cdata', analysispushbuttons{i},...
        'Parent',ut,...
        'Tooltipstring',    analysispushbuttons_tooltips{i},...
        'ClickedCallback',  analysispushbuttons_callbacks{i},...
        'Tag',              analysispushbuttons_tags{i},...
        'Separator',separator);
end


% [EOF] render_toolbar.m
