//////////////////////////////////////////////////////////////////////
//
// Разработчик: Алексей Фёдоров aka АЛьФ, mailto: alf@dorex.pro
//
//////////////////////////////////////////////////////////////////////
//
// FormExFormView.cpp : implementation file
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FormExFormView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CBkEndUI * pBkEndUI;
/////////////////////////////////////////////////////////////////////////////
// CFormExFormView

IMPLEMENT_DYNCREATE(CFormExFormView, CScrollView)

CFormExFormView::CFormExFormView()
	: CScrollView()
{
	//{{AFX_DATA_INIT(CFormExFormView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_view = NULL;
	m_frame = NULL;
	m_parentframe = NULL;
	m_doc = NULL;
	m_docAtt = NULL;
	m_tabctrl = NULL;
	m_ctrlbar = NULL;
	m_bAttached = false;
	m_bToAttrib = false;
}

CFormExFormView::~CFormExFormView()
{
	m_view = NULL;
	m_frame = NULL;
	m_parentframe = NULL;
	m_doc = NULL;
	m_docAtt = NULL;
	m_tabctrl = NULL;
	m_ctrlbar = NULL;
	m_bAttached = false;
	m_bToAttrib = false;
}

BEGIN_MESSAGE_MAP(CFormExFormView, CScrollView)
	//{{AFX_MSG_MAP(CFormExFormView)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFormExFormView diagnostics

#ifdef _DEBUG
void CFormExFormView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CFormExFormView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFormExFormView message handlers

void CFormExFormView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	//if(!m_bToAttrib)
	if((m_parentframe != NULL) & bActivate & (m_frame != NULL))
	{
		m_parentframe->SetActiveView(m_view);

		if(m_doc)
		{
			if(m_frame == m_parentframe)
				((CGetDoc7*)m_doc)->Refresh();

			if(!m_bToAttrib)
			{
				CString st;
				st = "";
				((CGetDoc7*)m_doc)->UDFCaption(st);
				m_parentframe->SetWindowText(st);
			}
		}
	}

	CScrollView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

void CFormExFormView::OnSize(UINT nType, int cx, int cy) 
{
	RECT rect;
	if((m_tabctrl != NULL) && (IsWindow(m_tabctrl->m_hWnd) == TRUE))
	{
		int tc = 0;
		if(m_doc)
		if(((CGetDoc7*)m_doc)->GetTabCtrlUsed())
		{
			tc = 4;
			m_tabctrl->GetWindowRect(&rect);
			ScreenToClient(&rect);
			rect.right = cx;
			rect.bottom = cy;
			m_tabctrl->MoveWindow(&rect);
		}
		if((m_view != NULL) && (IsWindow(m_view->m_hWnd) == TRUE))
		{
			m_view->GetWindowRect(&rect);
			ScreenToClient(&rect);
			rect.right = cx - tc;
			rect.bottom = cy - tc;
			m_view->MoveWindow(&rect);
		}
	}
	else
	if((m_view != NULL) && (IsWindow(m_view->m_hWnd) == TRUE))
	{
		m_view->GetWindowRect(&rect);
		ScreenToClient(&rect);
		rect.right = cx;
		rect.bottom = cy;
		m_view->MoveWindow(&rect);
	}
	if((m_ctrlbar != NULL) && (IsWindow(m_ctrlbar->m_hWnd) == TRUE))
	{
		m_ctrlbar->GetWindowRect(&rect);
		ScreenToClient(&rect);
		rect.right = cx;
		m_ctrlbar->MoveWindow(&rect);
	}
	if(m_bAttached && (m_frame != NULL) && (IsWindow(m_frame->m_hWnd) == TRUE))
	{
		m_frame->ShowWindow(SW_HIDE);
	}

	CScrollView::OnSize(nType, cx, cy);
}


BOOL CFormExFormView::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) 
{
	if(m_view != NULL)
		return m_view->SendChildNotifyLastMsg(); 
	else
		return CScrollView::OnChildNotify(message, wParam, lParam, pLResult);
}

BOOL CFormExFormView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	if(m_view != NULL)
		return m_view->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
	else
		return CScrollView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}


BEGIN_MESSAGE_MAP(CBaseWnd, CWnd)
	//{{AFX_MSG_MAP(CBaseWnd)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

CBaseWnd::CBaseWnd() : CWnd()
{
	m_view = NULL;
	m_frame = NULL;
	m_parentframe = NULL;
	m_doc = NULL;
	m_docAtt = NULL;
	m_tabctrl = NULL;
	m_ctrlbar = NULL;
	m_bAttached = false;
	m_bToAttrib = false;
}

/////////////////////////////////////////////////////////////////////////////
// CBaseWnd message handlers

void CBaseWnd::OnSize(UINT nType, int cx, int cy) 
{
	RECT rect;
	if((m_tabctrl != NULL) && (IsWindow(m_tabctrl->m_hWnd) == TRUE))
	{
		int tc = 0;
		if(m_doc)
		if(((CGetDoc7*)m_doc)->GetTabCtrlUsed())
		{
			tc = 4;
			m_tabctrl->GetWindowRect(&rect);
			ScreenToClient(&rect);
			rect.right = cx;
			rect.bottom = cy;
			m_tabctrl->MoveWindow(&rect);
		}
		if((m_view != NULL) && (IsWindow(m_view->m_hWnd) == TRUE))
		{
			m_view->GetWindowRect(&rect);
			ScreenToClient(&rect);
			rect.right = cx - tc;
			rect.bottom = cy - tc;
			m_view->MoveWindow(&rect);
		}
	}
	else
	if((m_view != NULL) && (IsWindow(m_view->m_hWnd) == TRUE))
	{
		m_view->GetWindowRect(&rect);
		ScreenToClient(&rect);
		rect.right = cx;
		rect.bottom = cy;
		m_view->MoveWindow(&rect);
	}
	if((m_ctrlbar != NULL) && (IsWindow(m_ctrlbar->m_hWnd) == TRUE))
	{
		m_ctrlbar->GetWindowRect(&rect);
		ScreenToClient(&rect);
		rect.right = cx;
		m_ctrlbar->MoveWindow(&rect);
	}
	if(m_bAttached && m_frame)
	{
//		m_frame->ShowWindow(SW_HIDE);
	}

	CWnd::OnSize(nType, cx, cy);
}


BOOL CBaseWnd::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) 
{
	if(m_view != NULL)
		return m_view->SendChildNotifyLastMsg(); 
	else
		return CWnd::OnChildNotify(message, wParam, lParam, pLResult);
}

BOOL CBaseWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	if(m_view != NULL)
		return m_view->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
	else
		return CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

IMPLEMENT_DYNCREATE(CFormExDockView, CScrollView)

CFormExDockView::CFormExDockView()
	: CScrollView()
{
}

BEGIN_MESSAGE_MAP(CFormExDockView, CScrollView)
	//{{AFX_MSG_MAP(CFormExDockView)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

IMPLEMENT_DYNCREATE(CFormExDockDoc, CDocument)

CFormExDockDoc::CFormExDockDoc()
	: CDocument()
{
}

BEGIN_MESSAGE_MAP(CFormExDockDoc, CDocument)
	//{{AFX_MSG_MAP(CFormExDockDoc)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
