Changed: #1038 Implement copy/paste for Linux

This commit is contained in:
kervala 2010-10-17 16:38:43 +02:00
parent d56d0ebc1a
commit 39df4c9129
5 changed files with 188 additions and 153 deletions

View file

@ -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;

View file

@ -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;
@ -105,6 +112,7 @@ private:
NLMISC::TKey _Key;
ucchar _Char;
};
ucstring _String;
};
// ----------------------------------------------------------------------------

View file

@ -347,17 +347,26 @@ void CGroupEditBox::paste()
}
cutSelection();
}
stopParentBlink();
makeTopWindow();
ucstring sString;
if (Driver->pasteTextFromClipboard(sString))
{
sint length = (sint)sString.length();
// 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 netry type
// filter character depending on the entry type
switch (_EntryType)
{
case Text:
@ -365,15 +374,15 @@ void CGroupEditBox::paste()
{
if (_NegativeFilter.empty())
{
toAppend = sString;
toAppend = str;
}
else
{
for (sint k = 0; k < length; ++k)
{
if (!isFiltered(sString[k]))
if (!isFiltered(str[k]))
{
toAppend += sString[k];
toAppend += str[k];
}
}
}
@ -387,12 +396,12 @@ void CGroupEditBox::paste()
{
for (sint k = 0; k < length; ++k)
{
if (isdigit(sString[k]) || sString[k]== ' ' ||
(_EntryType==PositiveFloat && sString[k]=='.') )
if (isdigit(str[k]) || str[k]== ' ' ||
(_EntryType==PositiveFloat && str[k]=='.') )
{
if (!isFiltered(sString[k]))
if (!isFiltered(str[k]))
{
toAppend += sString[k];
toAppend += str[k];
}
}
}
@ -403,12 +412,12 @@ void CGroupEditBox::paste()
{
for (sint k = 0; k < length; ++k)
{
if (isdigit(sString[k]) || sString[k]== ' ' || sString[k]== '-' ||
(_EntryType==Float && sString[k]=='.') )
if (isdigit(str[k]) || str[k]== ' ' || str[k]== '-' ||
(_EntryType==Float && str[k]=='.') )
{
if (!isFiltered(sString[k]))
if (!isFiltered(str[k]))
{
toAppend += sString[k];
toAppend += str[k];
}
}
}
@ -418,11 +427,11 @@ void CGroupEditBox::paste()
{
for (sint k = 0; k < length; ++k)
{
if (isValidAlphaNumSpace(sString[k]))
if (isValidAlphaNumSpace(str[k]))
{
if (!isFiltered(sString[k]))
if (!isFiltered(str[k]))
{
toAppend += sString[k];
toAppend += str[k];
}
}
}
@ -432,11 +441,11 @@ void CGroupEditBox::paste()
{
for (sint k = 0; k < length; ++k)
{
if (isValidAlphaNum(sString[k]))
if (isValidAlphaNum(str[k]))
{
if (!isFiltered(sString[k]))
if (!isFiltered(str[k]))
{
toAppend += sString[k];
toAppend += str[k];
}
}
}
@ -446,11 +455,11 @@ void CGroupEditBox::paste()
{
for (sint k = 0; k < length; ++k)
{
if (isValidAlpha(sString[k]))
if (isValidAlpha(str[k]))
{
if (!isFiltered(sString[k]))
if (!isFiltered(str[k]))
{
toAppend += sString[k];
toAppend += str[k];
}
}
}
@ -460,11 +469,11 @@ void CGroupEditBox::paste()
{
for (sint k = 0; k < length; ++k)
{
if (isValidFilenameChar(sString[k]))
if (isValidFilenameChar(str[k]))
{
if (!isFiltered(sString[k]))
if (!isFiltered(str[k]))
{
toAppend += sString[k];
toAppend += str[k];
}
}
}
@ -474,11 +483,11 @@ void CGroupEditBox::paste()
{
for (sint k = 0; k < length; ++k)
{
if (isValidPlayerNameChar(sString[k]))
if (isValidPlayerNameChar(str[k]))
{
if (!isFiltered(sString[k]))
if (!isFiltered(str[k]))
{
toAppend += sString[k];
toAppend += str[k];
}
}
}
@ -495,7 +504,6 @@ void CGroupEditBox::paste()
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
@ -1090,7 +1107,7 @@ void CGroupEditBox::setInputStringAsInt(sint32 val)
// ***************************************************************************
sint64 CGroupEditBox::getInputStringAsInt64() const
{
sint32 value;
sint64 value;
fromString(_InputString.toString(), value);
return value;
}

View file

@ -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();

View file

@ -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) ) )