// TriggerTabCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "6046dryend.h"
#include "TriggerTabCtrl.h"

#include "DlgTriggerSBP.h"
#include "DlgTriggerSSSHF.h"
#include "DlgTriggerSSSLF.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTriggerTabCtrl

CTriggerTabCtrl::CTriggerTabCtrl()
{
	m_tabPages[0]	 = new CDlgTriggerSBP;
	m_tabPages[1]	 = new CDlgTriggerSSSHF;
	m_tabPages[2]	 = new CDlgTriggerSSSLF;
}

CTriggerTabCtrl::~CTriggerTabCtrl()
{
	Cleanup();
}


BEGIN_MESSAGE_MAP(CTriggerTabCtrl, CTabCtrl)
	//{{AFX_MSG_MAP(CTriggerTabCtrl)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTriggerTabCtrl message handlers


void CTriggerTabCtrl::Init()
{
	m_tabCurrent=0;

	m_tabPages[0]->Create(IDD_DLG_TRIGGER_SBP,   this);
	m_tabPages[1]->Create(IDD_DLG_TRIGGER_SSSHF, this);
	m_tabPages[2]->Create(IDD_DLG_TRIGGER_SSSLF, this);	

	m_tabPages[0]->ShowWindow(SW_HIDE);
	m_tabPages[1]->ShowWindow(SW_HIDE);
    m_tabPages[2]->ShowWindow(SW_HIDE);

	SetRect();
}

void CTriggerTabCtrl::Cleanup()
{
	for(int nCount=0; nCount < NUM_TABSSS; nCount++)
	{
		if(m_tabPages[nCount])
		{
			m_tabPages[nCount]->DestroyWindow();
			delete m_tabPages[nCount];
			m_tabPages[nCount] = NULL;
		}
	}
}

void CTriggerTabCtrl::SetRect()
{
	CRect tabRect, itemRect;
	int nX, nY, nXc, nYc;

	GetClientRect(&tabRect);
	GetItemRect(0, &itemRect);

	nX=itemRect.left;
	nY=itemRect.bottom+1;
	nXc=tabRect.right-itemRect.left-1;
	nYc=tabRect.bottom-nY-1;

	m_tabPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
	for(int nCount=1; nCount < NUM_TABSSS; nCount++){
		m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
	}

	
}

void CTriggerTabCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CTabCtrl::OnLButtonDown(nFlags, point);
	// TODO: Add your message handler code here and/or call default
	if(m_tabCurrent != GetCurFocus()){
		m_tabPages[m_tabCurrent]->ShowWindow(SW_HIDE);
		m_tabCurrent=GetCurFocus();
		m_tabPages[m_tabCurrent]->ShowWindow(SW_SHOW);
		m_tabPages[m_tabCurrent]->SetFocus();
	}	
}