#include "StdAfx.h"
#include "ExpandContractHelper.h"
CExpandContractHelper::~CExpandContractHelper(void)
{
}
CExpandContractHelper::CExpandContractHelper(
UINT nStart,
UINT nEnd,
CDialog *dlg
)
{
m_nStart = nStart;
m_nEnd = nEnd;
m_dlg = dlg;
}
BOOL CExpandContractHelper::IsExpand()
{
m_sExpand = "&Expand >>";
m_sContract = "<< &Contract";
CString strCaption;
m_pButton->GetWindowText( strCaption );
BOOL bExpand = ( strCaption == m_sExpand );
return bExpand;
}
void CExpandContractHelper::ExpandContract(
CButton* pButton
)
{
m_pButton = pButton;
CRect rcDialog;
m_dlg->GetWindowRect( &rcDialog );
int nNewHeight = -1;
if( IsExpand() )
{
pButton->SetWindowText( m_sContract );
CWnd* pWndLarge = m_dlg->GetDlgItem( m_nEnd );
ASSERT_VALID( pWndLarge );
CRect rcLarge;
pWndLarge->GetWindowRect( &rcLarge );
nNewHeight = rcLarge.top-rcDialog.top;
}
else
{
pButton->SetWindowText( m_sExpand );
CWnd* pWndSmall = m_dlg->GetDlgItem( m_nStart );
ASSERT_VALID( pWndSmall );
pWndSmall->ShowWindow(FALSE);
CRect rcSmall;
pWndSmall->GetWindowRect( &rcSmall );
nNewHeight = rcSmall.top-rcDialog.top;
}
ASSERT( nNewHeight > 0 );
m_dlg->SetWindowPos( NULL, 0, 0,
rcDialog.Width(), nNewHeight,
SWP_NOMOVE | SWP_NOZORDER );
CWnd* pWndControl = m_dlg->GetWindow( GW_CHILD );
while( pWndControl != NULL )
{
CRect rcControl;
pWndControl->GetWindowRect( &rcControl );
pWndControl->EnableWindow( rcControl.top <= rcDialog.top + nNewHeight );
pWndControl = pWndControl->GetWindow( GW_HWNDNEXT );
}
CWnd* pWndActiveControl = CWnd::GetFocus();
if( pWndActiveControl == NULL )
{
CWnd* pWndFirstControl = m_dlg->GetNextDlgTabItem( NULL );
ASSERT_VALID( pWndFirstControl );
ASSERT( pWndFirstControl->IsWindowEnabled() );
pWndFirstControl->SetFocus();
}
}