// LogView.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "LogView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLogView

IMPLEMENT_DYNCREATE(CLogView, CEditView)

CLogView::CLogView()
{
}

CLogView::~CLogView()
{
}


BEGIN_MESSAGE_MAP(CLogView, CEditView)
	//{{AFX_MSG_MAP(CLogView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLogView drawing

void CLogView::OnDraw(CDC* pDC)
{
	UNREFERENCED_PARAMETER(pDC);
}

/////////////////////////////////////////////////////////////////////////////
// CLogView diagnostics

#ifdef _DEBUG
void CLogView::AssertValid() const
{
	CEditView::AssertValid();
}

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

/////////////////////////////////////////////////////////////////////////////
// CLogView message handlers

BOOL CLogView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	if (!CWnd::Create(lpszClassName, lpszWindowName, dwStyle | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE, rect, pParentWnd, nID, pContext))
		return FALSE;

	GetEditCtrl().SetReadOnly(TRUE);
	return TRUE;
}

void CLogView::ClearLog()
{
    SetWindowText(L"");
}

void CLogView::AddToLog(CString str, BOOL addnewline)
{
    CString oldStr;
    GetWindowText(oldStr);

    if (addnewline && (oldStr.GetLength() > 0))
        oldStr += L"\r\n";

    oldStr += str;

    SetWindowText(oldStr);

    GetEditCtrl().LineScroll(GetEditCtrl().GetLineCount(), 0);
}
