// ChildFrm.cpp : implementation of the CChildFrame class
//
#include "stdafx.h"
#include "INKS.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "INKSView.h"
#include "INKSDoc.h"

#include "MouseTracker.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CChildFrame

IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
	ON_WM_MDIACTIVATE()
END_MESSAGE_MAP()


// CChildFrame construction/destruction
CChildFrame* CChildFrame::GetChildFrame()
{
	return (CChildFrame*)((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActive();
}

CINKSDoc* CChildFrame::GetChildDocument()
{
      CMDIChildWnd * pChild =
          ((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActive();

      if ( !pChild )
          return NULL;

      CDocument * pDoc = pChild->GetActiveDocument();

      if ( !pDoc )
         return NULL;

      // Fail if doc is of wrong kind
      if ( ! pDoc->IsKindOf( RUNTIME_CLASS(CINKSDoc) ) )
         return NULL;

      return (CINKSDoc *) pDoc;
}

CINKSView* CChildFrame::GetChildView()
{
	return NULL;
}

CChildFrame::CChildFrame() : m_nMouseTrackerMode(CMouseTracker::ModeNone), m_nMouseTrackerCreate(CMouseTracker::NoCreate)
{
	// TODO: add member initialization code here
}

CChildFrame::~CChildFrame()
{
}


BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs
	if( !CMDIChildWnd::PreCreateWindow(cs) )
		return FALSE;

	return TRUE;
}


// CChildFrame diagnostics

#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
	CMDIChildWnd::AssertValid();
}

void CChildFrame::Dump(CDumpContext& dc) const
{
	CMDIChildWnd::Dump(dc);
}

#endif //_DEBUG

void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd *pActivateWnd, CWnd *pDeactivateWnd)
{
	CMainFrame *pMainFrame = DYNAMIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
	CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
	if(bActivate){
		// update list of read xml objects
		if(GetChildDocument()->m_bNeedReload){
			int i=0;
		}
		pMainFrame->UpdateCreateBar(m_nMouseTrackerMode, m_nMouseTrackerCreate);
	}
	else{
		m_nMouseTrackerMode = pMainFrame->m_nMouseTrackerMode;
		m_nMouseTrackerCreate = pMainFrame->m_nMouseTrackerCreate;
	}

	// update TreeBar - highlight newly selected document/view
	if(bActivate){
		pMainFrame->UpdateTreeBar(GetChildDocument()->GetTitle());
	}
}


// CChildFrame message handlers