// FSpinBtnCtrl.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "DynamicDraw.h"
#include "UtilWin.h"		// For FFGetWindowText.
#include "UtilMath.h"		// For _w10toi64.
#include "FSpinBtnCtrl.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFCFSpinBtnCtrl

CFCFSpinBtnCtrl::CFCFSpinBtnCtrl ()
{
	m_llLower	= 0;
	m_llUpper	= 1000;
} // CFCFSpinBtnCtrl::CFCFSpinBtnCtrl.

CFCFSpinBtnCtrl::~CFCFSpinBtnCtrl ()
{
} // CFCFSpinBtnCtrl::~CFCFSpinBtnCtrl.

BEGIN_MESSAGE_MAP(CFCFSpinBtnCtrl, BASE_CLASS)
	//{{AFX_MSG_MAP(CFCFSpinBtnCtrl)
	ON_NOTIFY_REFLECT(UDN_DELTAPOS, OnDeltapos)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFCFSpinBtnCtrl _xZkqqHx_iDiGiBfLiDfFiKnGjAjE_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCFSpinBtnCtrl::SetRange
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfIiDhDiDjDiDhLiDfOiDjDiCmMiPoDiMmAiBeFiJlKiMmAjCgMiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	llLower	:_xZkqqHx_iJlKiMmAjCgMiCpAiOhHjCoIiBeC_xHqqkZx_
 *			llUpper	:_xZkqqHx_iPoDiMmAjCgMiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.02.19 Fukushiro M. _xZkqqHx_iPeDjAlD_xHqqkZx_
 *************************************************************************/
void CFCFSpinBtnCtrl::SetRange (__int64 llLower, __int64 llUpper)
{
	m_llLower = llLower;
	m_llUpper = llUpper;
	if (llLower < llUpper)	BASE_CLASS::SetRange(0, 100);
	else					BASE_CLASS::SetRange(100, 0);
} // CFCFSpinBtnCtrl::SetRange.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCFSpinBtnCtrl::GetRange
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfIiDhDiDjDiDhLiDfOiDjDiCmMiPoDiMmAiBeFiJlKiMmAjCgMiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	llLower	:_xZkqqHx_iJlKiMmAjCgMiCpAjFnEiClHiBeC_xHqqkZx_
 *			llUpper	:_xZkqqHx_iPoDiMmAjCgMiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.02.19 Fukushiro M. _xZkqqHx_iPeDjAlD_xHqqkZx_
 *************************************************************************/
void CFCFSpinBtnCtrl::GetRange (__int64 &llLower, __int64& llUpper) const
{
	llLower	= m_llLower;
	llUpper	= m_llUpper;
} // CFCFSpinBtnCtrl::GetRange.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCFSpinBtnCtrl::MovePos
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfIiDhDiDjDiDhLiDfOiDjDiCkKjFhEjBkOiClHiCoJiDeHiDgGiDeCiDgCiDgHiDfCiDjDiDgHiDiNiBfLiDiLiCmMiMlLiNnNjCgMiCpAjFmPiNfIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	nInc	:_xZkqqHx_jFmPiNfIiClHiCoJjHmKiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	00.02.19 Fukushiro M. _xZkqqHx_iPeDjAlD_xHqqkZx_
 *************************************************************************/
void CFCFSpinBtnCtrl::MovePos (int nInc)
{
	if (nInc == 0) return;

	CWnd* pBuddy = GetBuddy();
	if (pBuddy == NULL) return;

	wchar_t tcsBuf[100];
	FFGetWindowText(pBuddy, tcsBuf, 100);
	__int64 llCurPos = _w10toi64(tcsBuf);

	// _xZkqqHx_jAfGiClFiCkCiImKjChFiCpAiMhGiOfKiBeC_xHqqkZx_
	__int64 llNewPos = (llCurPos / nInc + 1) * nInc;

	if (m_llLower < m_llUpper)
	{
		if (llNewPos < m_llLower)	llNewPos = m_llLower;
		if (m_llUpper < llNewPos)	llNewPos = m_llUpper;
	} else
	{
		if (llNewPos < m_llUpper)	llNewPos = m_llUpper;
		if (m_llLower < llNewPos)	llNewPos = m_llLower;
	}
	if (llNewPos != llCurPos)
	{
//----- 02.02.23 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//		_i64towcs(llNewPos, tcsBuf, 10);
//		FFSetWindowText(pBuddy, tcsBuf);
//----- 02.02.23 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
		FFSetWindowText(pBuddy, _i64tow(llNewPos, tcsBuf, 10));
//----- 02.02.23 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
	}
} // CFCFSpinBtnCtrl::MovePos.

/////////////////////////////////////////////////////////////////////////////
// CFCFSpinBtnCtrl _xZkqqHx_iDiBiDgCiDfKiBfLiDfH_xHqqkZx_ _xZkqqHx_iDgOiDjDiDgIiDiJ_xHqqkZx_

void CFCFSpinBtnCtrl::OnDeltapos (NMHDR* pNMHDR, LRESULT* pResult)
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;

	MovePos(pNMUpDown->iDelta);

	*pResult = 0;
} // CFCFSpinBtnCtrl::OnDeltapos.
