function setDialogVerticalExtents(dp)
% Record vertical extent of visible Dialog panels, the scroll-bar
% fractional height, and whether scroll bar should be visible.
%
% Generic to DialogPresenter?
%   .DialogsTotalHeight, in pixels
%
% Specific to DPVerticalPanel:
%   .ScrollFraction
%   .ScrollFractionNewlyVisible

%   Copyright 2010 The MathWorks, Inc.

N = getNumDockedDialogs(dp);
if dp.PanelVisible && N>0
    % Panel is visible (not in "closed" auto-hide state)
    % Determine total vertical extent of all docked dialogs.
    % Add gutter between each pair of dialogs.
    dialogs_dy = sum(getDialogHeights(dp)) + ...
        (N-1)*dp.DialogVerticalGutter;
    dp.DialogsTotalHeight = dialogs_dy;
    
    % Get vertical extent of dialog panel.  This is the vertical extent
    % of the parent panel itself:
    panel_dy = dp.hParent.Position(4);
    
    % Update scroll bar info
    % - what fraction of the dialog is visible?
    %   This gets reflected in the height of the active scroll bar.
    %   This fraction is < 1 if total height of all dialogs exceeds the
    %   panel height.
    %
    % NOTE: We may hide the scroll independent of whether the scroll
    % fraction is < 1, due to auto-hide feature.
    oldFrac = dp.ScrollFraction;
    newFrac = min(1,panel_dy/dialogs_dy); % in range [0,1]
    dp.ScrollFractionNewlyVisible = (oldFrac>=1) && (newFrac<1);
    dp.ScrollFraction = newFrac; % update only AFTER we use the old value!
else
    % Dialog panel not visible or no docked dialogs.
    dp.DialogsTotalHeight = 0;
    dp.ScrollFractionNewlyVisible = false;
    if ~dp.AutoHide
        % Don't change this when AutoHide is on.
        %
        % We need consistent scroll-bar width measurements even when panel
        % is temporarily closed.
        dp.ScrollFraction = 1;
    end
end
