diff --git a/irr/src/CGUIEditBox.cpp b/irr/src/CGUIEditBox.cpp index 6c29e89a9..50f6a449a 100644 --- a/irr/src/CGUIEditBox.cpp +++ b/irr/src/CGUIEditBox.cpp @@ -234,6 +234,10 @@ bool CGUIEditBox::OnEvent(const SEvent &event) inputString(*event.StringInput.Str); return true; break; + case EET_STRING_COMPOSITION_EVENT: + composeString(*event.StringComposition.Str); + return true; + break; default: break; } @@ -1262,10 +1266,10 @@ void CGUIEditBox::inputChar(wchar_t c) inputString(s); } -void CGUIEditBox::inputString(const core::stringw &str) +bool CGUIEditBox::insertString(const core::stringw &str) { if (!isEnabled()) - return; + return false; core::stringw s; u32 len = str.size(); @@ -1324,6 +1328,13 @@ void CGUIEditBox::inputString(const core::stringw &str) } BlinkStartTime = os::Timer::getTime(); + return true; +} + +void CGUIEditBox::inputString(const core::stringw &str) +{ + if (!insertString(str)) + return; setTextMarkers(0, 0); breakText(); @@ -1331,6 +1342,17 @@ void CGUIEditBox::inputString(const core::stringw &str) sendGuiEvent(EGET_EDITBOX_CHANGED); } +void CGUIEditBox::composeString(const core::stringw &str) +{ + if (!insertString(str)) + return; + setTextMarkers(CursorPos-str.size(), CursorPos); + + breakText(); + calculateScrollPos(); + sendGuiEvent(EGET_EDITBOX_CHANGED); +} + // calculate autoscroll void CGUIEditBox::calculateScrollPos() { diff --git a/irr/src/CGUIEditBox.h b/irr/src/CGUIEditBox.h index 35ab5f73e..97fa809de 100644 --- a/irr/src/CGUIEditBox.h +++ b/irr/src/CGUIEditBox.h @@ -144,10 +144,14 @@ protected: void setTextRect(s32 line); //! returns the line number that the cursor is on s32 getLineFromPos(s32 pos); + //! inserts a string to the edit box; used by inputString and composeString + bool insertString(const core::stringw &str); //! adds a letter to the edit box void inputChar(wchar_t c); //! adds a string to the edit box void inputString(const core::stringw &str); + //! compose a string before it is added + void composeString(const core::stringw &str); //! calculates the current scroll position void calculateScrollPos(); //! calculated the FrameRect diff --git a/irr/src/CGUIEnvironment.cpp b/irr/src/CGUIEnvironment.cpp index abfa0aab9..b443c9a3b 100644 --- a/irr/src/CGUIEnvironment.cpp +++ b/irr/src/CGUIEnvironment.cpp @@ -552,6 +552,7 @@ bool CGUIEnvironment::postEventFromUser(const SEvent &event) } } } break; + case EET_STRING_COMPOSITION_EVENT: [[fallthrough]]; case EET_STRING_INPUT_EVENT: if (Focus && Focus->OnEvent(event)) return true;