// GridCellNumeric.cpp: implementation of the CGridCellNumeric class.
//
// Written by Andrew Truckle [ajtruckle@wsatkins.co.uk]
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GridCellNumeric.h"
#include "InPlaceNumericEdit.h"
#include "GridCtrl.h"

IMPLEMENT_DYNCREATE(CGridCellNumeric, CGridCell)

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGridCellNumeric::CGridCellNumeric():
	m_digitPlaces(1),
	m_decimalPlaces(1)
{
}

// Create a control to do the editing
BOOL CGridCellNumeric::Edit(int nRow, int nCol, CRect rect, CPoint /* point */, UINT nID, UINT nChar)
{
    m_bEditing = TRUE;
    
	CInPlaceNumericEdit* inPlace;
	
	inPlace = new CInPlaceNumericEdit(GetGrid(), rect, WS_CHILD | WS_VISIBLE, nID, nRow, nCol,
		wcstod(GetText(), NULL), nChar, m_digitPlaces, m_decimalPlaces);

	((CAMSEdit::NumericBehavior*)inPlace)->SetSeparators(decimalSeparator_, groupSeparator_);

    // CInPlaceEdit auto-deletes itself
    m_pEditWnd = inPlace;
	
	return TRUE;
}

// Cancel the editing.
void CGridCellNumeric::EndEdit()
{
    if (m_pEditWnd)
        ((CInPlaceNumericEdit*)m_pEditWnd)->EndEdit();
}

void CGridCellNumeric::SetFormat(int digitPlaces, int decimalPlaces)
{
	m_digitPlaces = digitPlaces;
	m_decimalPlaces = decimalPlaces;
}

void CGridCellNumeric::SetSeparators(TCHAR decimal, TCHAR group)
{
	decimalSeparator_ = decimal;
	groupSeparator_ = group;
}
