1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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
26 /////////////////////////////////////////////////////////////////////////////
29 CEditEx::CEditEx() : _Listener(NULL
), _Type(StringType
)
38 BEGIN_MESSAGE_MAP(CEditEx
, CEdit
)
39 //{{AFX_MSG_MAP(CEditEx)
45 /////////////////////////////////////////////////////////////////////////////
46 // CEditEx message handlers
48 void CEditEx::OnSetFocus(CWnd
* pOldWnd
)
50 CEdit::OnSetFocus(pOldWnd
);
51 PostMessage(EM_SETSEL
, 0, -1);
55 sint
CEditEx::getSInt() const
57 nlassert(_Type
== SIntType
);
59 NLMISC::fromString(getString(), ret
);
63 uint
CEditEx::getUInt() const
65 nlassert(_Type
== UIntType
);
67 NLMISC::fromString(getString(), ret
);
70 float CEditEx::getFloat() const
72 nlassert(_Type
== FloatType
);
74 NLMISC::fromString(getString(), val
);
78 std::string
CEditEx::getString() const
81 GetWindowText(buf
, sizeof(buf
));
82 return NLMISC::tStrToUtf8(buf
);
85 void CEditEx::setSInt(sint value
)
87 nlassert(_Type
== SIntType
);
89 _stprintf(buf
, _T("%d"), (int) value
);
93 void CEditEx::setUInt(uint value
)
95 nlassert(_Type
== UIntType
);
97 _stprintf(buf
, _T("%d"), (int) value
);
101 void CEditEx::setFloat(float value
)
103 nlassert(_Type
== FloatType
);
105 _stprintf(buf
, _T("%g"), (double) value
);
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 ?
122 _Listener
->editExValueChanged(this);
127 MessageBox(_T("Invalid value"), _T("Error"), MB_OK
| MB_ICONEXCLAMATION
);
130 CEdit::OnKeyDown(nChar
, nRepCnt
, nFlags
);
134 bool CEditEx::isValid()
141 return NLMISC::fromString(getString(), value
);
146 return NLMISC::fromString(getString(), value
);
151 return NLMISC::fromString(getString(), value
);