Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectTypes/CInput.cpp
Show First 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev) | ||||
case SDL_TEXTINPUT: | case SDL_TEXTINPUT: | ||||
{ | { | ||||
if (m_Readonly) | if (m_Readonly) | ||||
return IN_PASS; | return IN_PASS; | ||||
// Text has been committed, either single key presses or through an IME | // Text has been committed, either single key presses or through an IME | ||||
std::wstring text = wstring_from_utf8(ev->ev.text.text); | std::wstring text = wstring_from_utf8(ev->ev.text.text); | ||||
// Check max length | |||||
if (m_MaxLength != 0 && m_Caption.length() + text.length() > static_cast<size_t>(m_MaxLength)) | |||||
return IN_HANDLED; | |||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
if (m_ComposingText) | if (m_ComposingText) | ||||
{ | { | ||||
ClearComposedText(); | ClearComposedText(); | ||||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode) | ||||
} | } | ||||
default: // Insert a character | default: // Insert a character | ||||
{ | { | ||||
// In SDL2, we no longer get Unicode wchars via SDL_Keysym | // In SDL2, we no longer get Unicode wchars via SDL_Keysym | ||||
// we use text input events instead and they provide UTF-8 chars | // we use text input events instead and they provide UTF-8 chars | ||||
if (cooked == 0) | if (cooked == 0) | ||||
return; | return; | ||||
// check max length | // Check max length | ||||
if (m_MaxLength != 0 && static_cast<int>(m_Caption.length()) >= m_MaxLength) | if (m_MaxLength != 0 && m_Caption.length() >= static_cast<size_t>(m_MaxLength)) | ||||
break; | break; | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | if (hotkey == "paste") | ||||
char* utf8_text = SDL_GetClipboardText(); | char* utf8_text = SDL_GetClipboardText(); | ||||
if (!utf8_text) | if (!utf8_text) | ||||
return IN_HANDLED; | return IN_HANDLED; | ||||
std::wstring text = wstring_from_utf8(utf8_text); | std::wstring text = wstring_from_utf8(utf8_text); | ||||
SDL_free(utf8_text); | SDL_free(utf8_text); | ||||
// Check max length | |||||
if (m_MaxLength != 0 && m_Caption.length() + text.length() > static_cast<size_t>(m_MaxLength)) | |||||
text = text.substr(0, static_cast<size_t>(m_MaxLength) - m_Caption.length()); | |||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
if (m_iBufferPos == static_cast<int>(m_Caption.length())) | if (m_iBufferPos == static_cast<int>(m_Caption.length())) | ||||
m_Caption += text; | m_Caption += text; | ||||
else | else | ||||
m_Caption = | m_Caption = | ||||
m_Caption.Left(m_iBufferPos) + text + | m_Caption.Left(m_iBufferPos) + text + | ||||
▲ Show 20 Lines • Show All 1,439 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator