2016-10-13 18:46:10 +00:00
|
|
|
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// edit_ex.cpp : implementation file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "std_afx.h"
|
|
|
|
#include "edit_ex.h"
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CEditEx
|
|
|
|
|
|
|
|
CEditEx::CEditEx() : _Listener(NULL), _Type(StringType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CEditEx::~CEditEx()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CEditEx, CEdit)
|
|
|
|
//{{AFX_MSG_MAP(CEditEx)
|
|
|
|
ON_WM_SETFOCUS()
|
|
|
|
ON_WM_KEYDOWN()
|
|
|
|
//}}AFX_MSG_MAP
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CEditEx message handlers
|
|
|
|
|
|
|
|
void CEditEx::OnSetFocus(CWnd* pOldWnd)
|
|
|
|
{
|
|
|
|
CEdit::OnSetFocus(pOldWnd);
|
|
|
|
PostMessage(EM_SETSEL, 0, -1);
|
|
|
|
Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
sint CEditEx::getSInt() const
|
|
|
|
{
|
|
|
|
nlassert(_Type == SIntType);
|
|
|
|
sint ret = 0;
|
|
|
|
NLMISC::fromString(getString(), ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint CEditEx::getUInt() const
|
|
|
|
{
|
|
|
|
nlassert(_Type == UIntType);
|
|
|
|
uint ret = 0;
|
|
|
|
NLMISC::fromString(getString(), ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
float CEditEx::getFloat() const
|
|
|
|
{
|
|
|
|
nlassert(_Type == FloatType);
|
|
|
|
float val;
|
|
|
|
NLMISC::fromString(getString(), val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CEditEx::getString() const
|
|
|
|
{
|
2016-11-20 13:51:11 +00:00
|
|
|
TCHAR buf[128];
|
2016-10-13 18:46:10 +00:00
|
|
|
GetWindowText(buf, sizeof(buf));
|
2016-11-20 13:51:11 +00:00
|
|
|
return tStrToUtf8(buf);
|
2016-10-13 18:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CEditEx::setSInt(sint value)
|
|
|
|
{
|
|
|
|
nlassert(_Type == SIntType);
|
2016-11-20 13:51:11 +00:00
|
|
|
TCHAR buf[16];
|
|
|
|
_tcprintf(buf, "%d", (int) value);
|
2016-10-13 18:46:10 +00:00
|
|
|
setString(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEditEx::setUInt(uint value)
|
|
|
|
{
|
|
|
|
nlassert(_Type == UIntType);
|
2016-11-20 13:51:11 +00:00
|
|
|
TCHAR buf[16];
|
|
|
|
_tcprintf(buf, "%d", (int) value);
|
2016-10-13 18:46:10 +00:00
|
|
|
setString(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEditEx::setFloat(float value)
|
|
|
|
{
|
|
|
|
nlassert(_Type == FloatType);
|
2016-11-20 13:51:11 +00:00
|
|
|
TCHAR buf[16];
|
|
|
|
_tcprintf(buf, "%g", (double) value);
|
2016-10-13 18:46:10 +00:00
|
|
|
setString(buf);
|
|
|
|
}
|
|
|
|
|
2016-11-20 13:51:11 +00:00
|
|
|
void CEditEx::setString(const TCHAR *value)
|
2016-10-13 18:46:10 +00:00
|
|
|
{
|
|
|
|
SetWindowText(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEditEx::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
|
|
|
|
{
|
|
|
|
if (nChar == 13) // return pressed ?
|
|
|
|
{
|
|
|
|
if (isValid())
|
|
|
|
{
|
|
|
|
if (_Listener)
|
|
|
|
{
|
|
|
|
_Listener->editExValueChanged(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-20 13:51:11 +00:00
|
|
|
MessageBox(_T("Invalid value"), _T("Error"), MB_OK | MB_ICONEXCLAMATION);
|
2016-10-13 18:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CEditEx::isValid()
|
|
|
|
{
|
|
|
|
switch(_Type)
|
|
|
|
{
|
|
|
|
case SIntType:
|
2016-11-20 13:51:11 +00:00
|
|
|
{
|
|
|
|
sint value;
|
|
|
|
return NLMISC::fromString(getString(), value);
|
|
|
|
}
|
2016-10-13 18:46:10 +00:00
|
|
|
case UIntType:
|
2016-11-20 13:51:11 +00:00
|
|
|
{
|
|
|
|
uint value;
|
|
|
|
return NLMISC::fromString(getString(), value);
|
|
|
|
}
|
2016-10-13 18:46:10 +00:00
|
|
|
case FloatType:
|
2016-11-20 13:51:11 +00:00
|
|
|
{
|
|
|
|
float value;
|
|
|
|
return NLMISC::fromString(getString(), value);
|
|
|
|
}
|
|
|
|
default: break;
|
2016-10-13 18:46:10 +00:00
|
|
|
}
|
2016-11-20 13:51:11 +00:00
|
|
|
|
|
|
|
return true;
|
2016-10-13 18:46:10 +00:00
|
|
|
}
|