diff --git a/code/ryzom/client/src/interface_v3/event_descriptor.cpp b/code/ryzom/client/src/interface_v3/event_descriptor.cpp index e2178540a..2e72c69c2 100644 --- a/code/ryzom/client/src/interface_v3/event_descriptor.cpp +++ b/code/ryzom/client/src/interface_v3/event_descriptor.cpp @@ -40,6 +40,11 @@ void CEventDescriptorKey::init(const NLMISC::CEventKey &ev) _KeyEvent = keydown; _Key = ((const NLMISC::CEventKeyDown &) ev).Key; } + else if (ev == NLMISC::EventStringId) + { + _KeyEvent = keystring; + _String = ((const NLMISC::CEventString &) ev).String; + } else { _KeyEvent = unknown; diff --git a/code/ryzom/client/src/interface_v3/event_descriptor.h b/code/ryzom/client/src/interface_v3/event_descriptor.h index 5034b940c..fc601806f 100644 --- a/code/ryzom/client/src/interface_v3/event_descriptor.h +++ b/code/ryzom/client/src/interface_v3/event_descriptor.h @@ -54,6 +54,7 @@ public: keydown = 0, // a key has been press down. The key value is stored as a TKey keyup, // a key has been released. The key value is stored as a TKey keychar, // a key has been stroke. The key is a ucchar + keystring, // a string has been sent. The string is a ucstring unknown, // uninitialized event }; CEventDescriptorKey() : _KeyEvent(unknown) @@ -80,6 +81,12 @@ public: nlassert(_KeyEvent == keychar); return _Char; } + // return the string that has been sent. The key event type MUST be 'keystring', else => assert + ucstring getString() const + { + nlassert(_KeyEvent == keystring); + return _String; + } bool getKeyCtrl() const // is CTRL pressed ? { return _CtrlState; @@ -102,9 +109,10 @@ private: bool _AltState; union { - NLMISC::TKey _Key; - ucchar _Char; + NLMISC::TKey _Key; + ucchar _Char; }; + ucstring _String; }; // ---------------------------------------------------------------------------- diff --git a/code/ryzom/client/src/interface_v3/group_editbox.cpp b/code/ryzom/client/src/interface_v3/group_editbox.cpp index a1c43d7a3..e690dfbe1 100644 --- a/code/ryzom/client/src/interface_v3/group_editbox.cpp +++ b/code/ryzom/client/src/interface_v3/group_editbox.cpp @@ -347,155 +347,163 @@ void CGroupEditBox::paste() } cutSelection(); } - stopParentBlink(); - makeTopWindow(); ucstring sString; if (Driver->pasteTextFromClipboard(sString)) { - sint length = (sint)sString.length(); - - ucstring toAppend; - // filter character depending on the netry type - switch (_EntryType) - { - case Text: - case Password: - { - if (_NegativeFilter.empty()) - { - toAppend = sString; - } - else - { - for (sint k = 0; k < length; ++k) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - // remove '\r' characters - toAppend.erase(std::remove(toAppend.begin(), toAppend.end(), (ucchar) '\r'), toAppend.end()); - - } - break; - case PositiveInteger: - case PositiveFloat: - { - for (sint k = 0; k < length; ++k) - { - if (isdigit(sString[k]) || sString[k]== ' ' || - (_EntryType==PositiveFloat && sString[k]=='.') ) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case Integer: - case Float: - { - for (sint k = 0; k < length; ++k) - { - if (isdigit(sString[k]) || sString[k]== ' ' || sString[k]== '-' || - (_EntryType==Float && sString[k]=='.') ) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case AlphaNumSpace: - { - for (sint k = 0; k < length; ++k) - { - if (isValidAlphaNumSpace(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case AlphaNum: - { - for (sint k = 0; k < length; ++k) - { - if (isValidAlphaNum(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case Alpha: - { - for (sint k = 0; k < length; ++k) - { - if (isValidAlpha(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case Filename: - { - for (sint k = 0; k < length; ++k) - { - if (isValidFilenameChar(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - break; - case PlayerName: - { - for (sint k = 0; k < length; ++k) - { - if (isValidPlayerNameChar(sString[k])) - { - if (!isFiltered(sString[k])) - { - toAppend += sString[k]; - } - } - } - } - } - length = (sint)toAppend.size(); - if ((uint) (_InputString.length() + length) > _MaxNumChar) - { - length = _MaxNumChar - (sint)_InputString.length(); - } - ucstring toAdd = toAppend.substr(0, length); - _InputString = _InputString.substr(0, _CursorPos) + toAdd + _InputString.substr(_CursorPos); - _CursorPos += (sint32)toAdd.length(); - nlinfo ("Chat input was pasted from the clipboard"); - - triggerOnChangeAH(); + // append string now + appendString(sString); } +} + +// ---------------------------------------------------------------------------- +void CGroupEditBox::appendString(const ucstring &str) +{ + stopParentBlink(); + makeTopWindow(); + + sint length = (sint)str.length(); + + ucstring toAppend; + // filter character depending on the entry type + switch (_EntryType) + { + case Text: + case Password: + { + if (_NegativeFilter.empty()) + { + toAppend = str; + } + else + { + for (sint k = 0; k < length; ++k) + { + if (!isFiltered(str[k])) + { + toAppend += str[k]; + } + } + } + // remove '\r' characters + toAppend.erase(std::remove(toAppend.begin(), toAppend.end(), (ucchar) '\r'), toAppend.end()); + + } + break; + case PositiveInteger: + case PositiveFloat: + { + for (sint k = 0; k < length; ++k) + { + if (isdigit(str[k]) || str[k]== ' ' || + (_EntryType==PositiveFloat && str[k]=='.') ) + { + if (!isFiltered(str[k])) + { + toAppend += str[k]; + } + } + } + } + break; + case Integer: + case Float: + { + for (sint k = 0; k < length; ++k) + { + if (isdigit(str[k]) || str[k]== ' ' || str[k]== '-' || + (_EntryType==Float && str[k]=='.') ) + { + if (!isFiltered(str[k])) + { + toAppend += str[k]; + } + } + } + } + break; + case AlphaNumSpace: + { + for (sint k = 0; k < length; ++k) + { + if (isValidAlphaNumSpace(str[k])) + { + if (!isFiltered(str[k])) + { + toAppend += str[k]; + } + } + } + } + break; + case AlphaNum: + { + for (sint k = 0; k < length; ++k) + { + if (isValidAlphaNum(str[k])) + { + if (!isFiltered(str[k])) + { + toAppend += str[k]; + } + } + } + } + break; + case Alpha: + { + for (sint k = 0; k < length; ++k) + { + if (isValidAlpha(str[k])) + { + if (!isFiltered(str[k])) + { + toAppend += str[k]; + } + } + } + } + break; + case Filename: + { + for (sint k = 0; k < length; ++k) + { + if (isValidFilenameChar(str[k])) + { + if (!isFiltered(str[k])) + { + toAppend += str[k]; + } + } + } + } + break; + case PlayerName: + { + for (sint k = 0; k < length; ++k) + { + if (isValidPlayerNameChar(str[k])) + { + if (!isFiltered(str[k])) + { + toAppend += str[k]; + } + } + } + } + } + length = (sint)toAppend.size(); + if ((uint) (_InputString.length() + length) > _MaxNumChar) + { + length = _MaxNumChar - (sint)_InputString.length(); + } + ucstring toAdd = toAppend.substr(0, length); + _InputString = _InputString.substr(0, _CursorPos) + toAdd + _InputString.substr(_CursorPos); + _CursorPos += (sint32)toAdd.length(); + nlinfo ("Chat input was pasted from the clipboard"); + + triggerOnChangeAH(); _CursorAtPreviousLineEnd = false; } @@ -610,6 +618,8 @@ void CGroupEditBox::handleEventChar(const CEventDescriptorKey &rEDK) if (!isValidPlayerNameChar(c)) return; break; + default: + break; } // verify integer bounds if(_EntryType==Integer && (_IntegerMinValue!=INT_MIN || _IntegerMaxValue!=INT_MAX)) @@ -658,6 +668,11 @@ void CGroupEditBox::handleEventChar(const CEventDescriptorKey &rEDK) } } +// ---------------------------------------------------------------------------- +void CGroupEditBox::handleEventString(const CEventDescriptorKey &rEDK) +{ + appendString(rEDK.getString()); +} // ---------------------------------------------------------------------------- bool CGroupEditBox::undo() @@ -720,7 +735,7 @@ bool CGroupEditBox::expand() if (_InputString[0] == '/') { makeTopWindow(); - // for french or deutch, be aware of unicode + // for french, deutsch and russian, be aware of unicode std::string command = ucstring(_InputString.substr(1)).toUtf8(); ICommand::expand(command); // then back to ucstring @@ -788,12 +803,14 @@ bool CGroupEditBox::handleEvent (const CEventDescriptor& event) switch(rEDK.getKeyEventType()) { case CEventDescriptorKey::keychar: handleEventChar(rEDK); break; + case CEventDescriptorKey::keystring: handleEventString(rEDK); break; + default: break; } // update the text setInputString(_InputString); - // if event of type char, consider handle all of them - if( rEDK.getKeyEventType()==CEventDescriptorKey::keychar ) + // if event of type char or string, consider handle all of them + if( rEDK.getKeyEventType()==CEventDescriptorKey::keychar || rEDK.getKeyEventType()==CEventDescriptorKey::keystring ) return true; // Else filter the EventKeyDown AND EventKeyUp. else @@ -1089,16 +1106,16 @@ void CGroupEditBox::setInputStringAsInt(sint32 val) // *************************************************************************** sint64 CGroupEditBox::getInputStringAsInt64() const -{ - sint32 value; +{ + sint64 value; fromString(_InputString.toString(), value); return value; } // *************************************************************************** void CGroupEditBox::setInputStringAsInt64(sint64 val) -{ - setInputString(NLMISC::toString(val)); +{ + setInputString(NLMISC::toString(val)); } // *************************************************************************** diff --git a/code/ryzom/client/src/interface_v3/group_editbox.h b/code/ryzom/client/src/interface_v3/group_editbox.h index 3b2bc7fc9..c8f8bf457 100644 --- a/code/ryzom/client/src/interface_v3/group_editbox.h +++ b/code/ryzom/client/src/interface_v3/group_editbox.h @@ -288,8 +288,10 @@ private: void setupDisplayText(); void makeTopWindow(); void handleEventChar(const CEventDescriptorKey &event); + void handleEventString(const CEventDescriptorKey &event); void setup(); void triggerOnChangeAH(); + void appendString(const ucstring &str); ucstring getSelection(); diff --git a/code/ryzom/client/src/interface_v3/input_handler_manager.cpp b/code/ryzom/client/src/interface_v3/input_handler_manager.cpp index 6fae67260..3fa53ef42 100644 --- a/code/ryzom/client/src/interface_v3/input_handler_manager.cpp +++ b/code/ryzom/client/src/interface_v3/input_handler_manager.cpp @@ -104,6 +104,7 @@ void CInputHandlerManager::addToServer(NLMISC::CEventServer * server) server->addListener(EventMouseDblClkId, this); // Keyboard + server->addListener(EventStringId, this); server->addListener(EventCharId, this); server->addListener(EventKeyDownId, this); server->addListener(EventKeyUpId, this); @@ -127,6 +128,7 @@ void CInputHandlerManager::release() _EventServer->removeListener(EventMouseDblClkId, this); // Keyboard + _EventServer->removeListener(EventStringId, this); _EventServer->removeListener(EventCharId, this); _EventServer->removeListener(EventKeyDownId, this); _EventServer->removeListener(EventKeyUpId, this); @@ -230,7 +232,8 @@ void CInputHandlerManager::operator ()(const NLMISC::CEvent &event) // **** Event Keyboard if( event == EventKeyDownId || event == EventKeyUpId || - event == EventCharId) + event == EventCharId || + event == EventStringId) { // if not handled, post to Action Manager if( !pIM->handleEvent( CEventDescriptorKey((const CEventKey &) event) ) )