Added aqua_speed for rite geo 50 tryker
[ryzomcore.git] / nel / tools / 3d / object_viewer / edit_ex.cpp
blob886dbd7cf02665650571ef274533cc834d514e78
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // edit_ex.cpp : implementation file
23 #include "std_afx.h"
24 #include "edit_ex.h"
26 /////////////////////////////////////////////////////////////////////////////
27 // CEditEx
29 CEditEx::CEditEx() : _Listener(NULL), _Type(StringType)
33 CEditEx::~CEditEx()
38 BEGIN_MESSAGE_MAP(CEditEx, CEdit)
39 //{{AFX_MSG_MAP(CEditEx)
40 ON_WM_SETFOCUS()
41 ON_WM_KEYDOWN()
42 //}}AFX_MSG_MAP
43 END_MESSAGE_MAP()
45 /////////////////////////////////////////////////////////////////////////////
46 // CEditEx message handlers
48 void CEditEx::OnSetFocus(CWnd* pOldWnd)
50 CEdit::OnSetFocus(pOldWnd);
51 PostMessage(EM_SETSEL, 0, -1);
52 Invalidate();
55 sint CEditEx::getSInt() const
57 nlassert(_Type == SIntType);
58 sint ret = 0;
59 NLMISC::fromString(getString(), ret);
60 return ret;
63 uint CEditEx::getUInt() const
65 nlassert(_Type == UIntType);
66 uint ret = 0;
67 NLMISC::fromString(getString(), ret);
68 return ret;
70 float CEditEx::getFloat() const
72 nlassert(_Type == FloatType);
73 float val;
74 NLMISC::fromString(getString(), val);
75 return val;
78 std::string CEditEx::getString() const
80 TCHAR buf[128];
81 GetWindowText(buf, sizeof(buf));
82 return NLMISC::tStrToUtf8(buf);
85 void CEditEx::setSInt(sint value)
87 nlassert(_Type == SIntType);
88 TCHAR buf[16];
89 _stprintf(buf, _T("%d"), (int) value);
90 setString(buf);
93 void CEditEx::setUInt(uint value)
95 nlassert(_Type == UIntType);
96 TCHAR buf[16];
97 _stprintf(buf, _T("%d"), (int) value);
98 setString(buf);
101 void CEditEx::setFloat(float value)
103 nlassert(_Type == FloatType);
104 TCHAR buf[16];
105 _stprintf(buf, _T("%g"), (double) value);
106 setString(buf);
109 void CEditEx::setString(const TCHAR *value)
111 SetWindowText(value);
114 void CEditEx::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
116 if (nChar == 13) // return pressed ?
118 if (isValid())
120 if (_Listener)
122 _Listener->editExValueChanged(this);
125 else
127 MessageBox(_T("Invalid value"), _T("Error"), MB_OK | MB_ICONEXCLAMATION);
130 CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
134 bool CEditEx::isValid()
136 switch(_Type)
138 case SIntType:
140 sint value;
141 return NLMISC::fromString(getString(), value);
143 case UIntType:
145 uint value;
146 return NLMISC::fromString(getString(), value);
148 case FloatType:
150 float value;
151 return NLMISC::fromString(getString(), value);
153 default: break;
156 return true;