IrrlichtDevice::postEventFromUser. They take the same path as mouse events. */\r
EET_KEY_INPUT_EVENT,\r
\r
- //! A touch input event.\r
+ //! A string input event.\r
+ /** This event is created when multiple characters are sent at a time (e.g. using an IME). */\r
+ EET_STRING_INPUT_EVENT,\r
+\r
+ //! A touch input event.\r
EET_TOUCH_INPUT_EVENT,\r
\r
//! A accelerometer event.\r
bool Control:1;\r
};\r
\r
- //! Any kind of touch event.\r
+ //! String input event.\r
+ struct SStringInput\r
+ {\r
+ //! The string that is entered\r
+ core::stringw *Str;\r
+ };\r
+\r
+ //! Any kind of touch event.\r
struct STouchInput\r
{\r
// Touch ID.\r
struct SGUIEvent GUIEvent;\r
struct SMouseInput MouseInput;\r
struct SKeyInput KeyInput;\r
+ struct SStringInput StringInput;\r
struct STouchInput TouchInput;\r
struct SAccelerometerEvent AccelerometerEvent;\r
struct SGyroscopeEvent GyroscopeEvent;\r
if (processMouse(event))\r
return true;\r
break;\r
+ case EET_STRING_INPUT_EVENT:\r
+ inputString(*event.StringInput.Str);\r
+ return true;\r
+ break;\r
default:\r
break;\r
}\r
\r
\r
void CGUIEditBox::inputChar(wchar_t c)\r
+{\r
+ if (c == 0)\r
+ return;\r
+ core::stringw s(&c, 1);\r
+ inputString(s);\r
+}\r
+\r
+void CGUIEditBox::inputString(const core::stringw &str)\r
{\r
if (!isEnabled())\r
return;\r
\r
- if (c != 0)\r
+ core::stringw s;\r
+ u32 len = str.size();\r
+\r
+ if (MarkBegin != MarkEnd)\r
{\r
- {\r
- core::stringw s;\r
+ // replace marked text\r
+ const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;\r
+ const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;\r
\r
- if (MarkBegin != MarkEnd)\r
+ s = Text.subString(0, realmbgn);\r
+ s.append(str);\r
+ s.append( Text.subString(realmend, Text.size()-realmend) );\r
+ Text = s;\r
+ CursorPos = realmbgn+len;\r
+ }\r
+ else if ( OverwriteMode )\r
+ {\r
+ //check to see if we are at the end of the text\r
+ if ( (u32)CursorPos+len < Text.size())\r
+ {\r
+ bool isEOL = false;\r
+ s32 EOLPos;\r
+ for (u32 i = CursorPos; i < CursorPos+len && i < Max; i++)\r
{\r
- // replace marked text\r
- const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd;\r
- const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin;\r
-\r
- s = Text.subString(0, realmbgn);\r
- s.append(c);\r
- s.append( Text.subString(realmend, Text.size()-realmend) );\r
- Text = s;\r
- CursorPos = realmbgn+1;\r
+ if (Text[i] == L'\n' || Text[i] == L'\r')\r
+ {\r
+ isEOL = true;\r
+ EOLPos = i;\r
+ break;\r
+ }\r
}\r
- else if ( OverwriteMode )\r
+ if (!isEOL || Text.size()+len <= Max || Max == 0)\r
{\r
- //check to see if we are at the end of the text\r
- if ( (u32)CursorPos != Text.size())\r
+ s = Text.subString(0, CursorPos);\r
+ s.append(str);\r
+ if ( isEOL )\r
{\r
- bool isEOL = (Text[CursorPos] == L'\n' ||Text[CursorPos] == L'\r' );\r
- if (!isEOL || Text.size() < Max || Max == 0)\r
- {\r
- s = Text.subString(0, CursorPos);\r
- s.append(c);\r
- if ( isEOL )\r
- {\r
- //just keep appending to the current line\r
- //This follows the behavior of other gui libraries behaviors\r
- s.append( Text.subString(CursorPos, Text.size()-CursorPos) );\r
- }\r
- else\r
- {\r
- //replace the next character\r
- s.append( Text.subString(CursorPos + 1,Text.size() - CursorPos + 1));\r
- }\r
- Text = s;\r
- ++CursorPos;\r
- }\r
+ //just keep appending to the current line\r
+ //This follows the behavior of other gui libraries behaviors\r
+ s.append( Text.subString(EOLPos, Text.size()-EOLPos) );\r
}\r
- else if (Text.size() < Max || Max == 0)\r
+ else\r
{\r
- // add new character because we are at the end of the string\r
- s = Text.subString(0, CursorPos);\r
- s.append(c);\r
- s.append( Text.subString(CursorPos, Text.size()-CursorPos) );\r
- Text = s;\r
- ++CursorPos;\r
+ //replace the next character\r
+ s.append( Text.subString(CursorPos + len,Text.size() - CursorPos - len));\r
}\r
- }\r
- else if (Text.size() < Max || Max == 0)\r
- {\r
- // add new character\r
- s = Text.subString(0, CursorPos);\r
- s.append(c);\r
- s.append( Text.subString(CursorPos, Text.size()-CursorPos) );\r
Text = s;\r
- ++CursorPos;\r
+ CursorPos+=len;\r
}\r
-\r
- BlinkStartTime = os::Timer::getTime();\r
- setTextMarkers(0, 0);\r
}\r
+ else if (Text.size()+len <= Max || Max == 0)\r
+ {\r
+ // add new character because we are at the end of the string\r
+ s = Text.subString(0, CursorPos);\r
+ s.append(str);\r
+ s.append( Text.subString(CursorPos+len, Text.size()-CursorPos-len) );\r
+ Text = s;\r
+ CursorPos+=len;\r
+ }\r
+ }\r
+ else if (Text.size()+len <= Max || Max == 0)\r
+ {\r
+ // add new character\r
+ s = Text.subString(0, CursorPos);\r
+ s.append(str);\r
+ s.append( Text.subString(CursorPos, Text.size()-CursorPos) );\r
+ Text = s;\r
+ CursorPos+=len;\r
}\r
+\r
+ BlinkStartTime = os::Timer::getTime();\r
+ setTextMarkers(0, 0);\r
+\r
breakText();\r
calculateScrollPos();\r
sendGuiEvent(EGET_EDITBOX_CHANGED);\r
}\r
}\r
\r
+//! Returns whether the element takes input from the IME\r
+bool CGUIEditBox::acceptsIME()\r
+{\r
+ return isEnabled();\r
+}\r
+\r
//! Writes attributes of the element.\r
void CGUIEditBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const\r
{\r
//! Updates the absolute position, splits text if required\r
virtual void updateAbsolutePosition() _IRR_OVERRIDE_;\r
\r
+ //! Returns whether the element takes input from the IME\r
+ virtual bool acceptsIME() _IRR_OVERRIDE_;\r
+\r
+\r
//! Writes attributes of the element.\r
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const _IRR_OVERRIDE_;\r
\r
s32 getLineFromPos(s32 pos);\r
//! adds a letter to the edit box\r
void inputChar(wchar_t c);\r
+ //! adds a string to the edit box\r
+ void inputString(const core::stringw &str);\r
//! calculates the current scroll position\r
void calculateScrollPos();\r
//! calculated the FrameRect\r