Changed: #1038 Implement copy/paste for Linux
This commit is contained in:
parent
d56d0ebc1a
commit
39df4c9129
5 changed files with 188 additions and 153 deletions
|
@ -40,6 +40,11 @@ void CEventDescriptorKey::init(const NLMISC::CEventKey &ev)
|
||||||
_KeyEvent = keydown;
|
_KeyEvent = keydown;
|
||||||
_Key = ((const NLMISC::CEventKeyDown &) ev).Key;
|
_Key = ((const NLMISC::CEventKeyDown &) ev).Key;
|
||||||
}
|
}
|
||||||
|
else if (ev == NLMISC::EventStringId)
|
||||||
|
{
|
||||||
|
_KeyEvent = keystring;
|
||||||
|
_String = ((const NLMISC::CEventString &) ev).String;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_KeyEvent = unknown;
|
_KeyEvent = unknown;
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
keydown = 0, // a key has been press down. The key value is stored as a TKey
|
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
|
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
|
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
|
unknown, // uninitialized event
|
||||||
};
|
};
|
||||||
CEventDescriptorKey() : _KeyEvent(unknown)
|
CEventDescriptorKey() : _KeyEvent(unknown)
|
||||||
|
@ -80,6 +81,12 @@ public:
|
||||||
nlassert(_KeyEvent == keychar);
|
nlassert(_KeyEvent == keychar);
|
||||||
return _Char;
|
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 ?
|
bool getKeyCtrl() const // is CTRL pressed ?
|
||||||
{
|
{
|
||||||
return _CtrlState;
|
return _CtrlState;
|
||||||
|
@ -105,6 +112,7 @@ private:
|
||||||
NLMISC::TKey _Key;
|
NLMISC::TKey _Key;
|
||||||
ucchar _Char;
|
ucchar _Char;
|
||||||
};
|
};
|
||||||
|
ucstring _String;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -347,17 +347,26 @@ void CGroupEditBox::paste()
|
||||||
}
|
}
|
||||||
cutSelection();
|
cutSelection();
|
||||||
}
|
}
|
||||||
stopParentBlink();
|
|
||||||
makeTopWindow();
|
|
||||||
|
|
||||||
ucstring sString;
|
ucstring sString;
|
||||||
|
|
||||||
if (Driver->pasteTextFromClipboard(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;
|
ucstring toAppend;
|
||||||
// filter character depending on the netry type
|
// filter character depending on the entry type
|
||||||
switch (_EntryType)
|
switch (_EntryType)
|
||||||
{
|
{
|
||||||
case Text:
|
case Text:
|
||||||
|
@ -365,15 +374,15 @@ void CGroupEditBox::paste()
|
||||||
{
|
{
|
||||||
if (_NegativeFilter.empty())
|
if (_NegativeFilter.empty())
|
||||||
{
|
{
|
||||||
toAppend = sString;
|
toAppend = str;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (sint k = 0; k < length; ++k)
|
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)
|
for (sint k = 0; k < length; ++k)
|
||||||
{
|
{
|
||||||
if (isdigit(sString[k]) || sString[k]== ' ' ||
|
if (isdigit(str[k]) || str[k]== ' ' ||
|
||||||
(_EntryType==PositiveFloat && sString[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)
|
for (sint k = 0; k < length; ++k)
|
||||||
{
|
{
|
||||||
if (isdigit(sString[k]) || sString[k]== ' ' || sString[k]== '-' ||
|
if (isdigit(str[k]) || str[k]== ' ' || str[k]== '-' ||
|
||||||
(_EntryType==Float && sString[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)
|
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)
|
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)
|
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)
|
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)
|
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");
|
nlinfo ("Chat input was pasted from the clipboard");
|
||||||
|
|
||||||
triggerOnChangeAH();
|
triggerOnChangeAH();
|
||||||
}
|
|
||||||
|
|
||||||
_CursorAtPreviousLineEnd = false;
|
_CursorAtPreviousLineEnd = false;
|
||||||
}
|
}
|
||||||
|
@ -610,6 +618,8 @@ void CGroupEditBox::handleEventChar(const CEventDescriptorKey &rEDK)
|
||||||
if (!isValidPlayerNameChar(c))
|
if (!isValidPlayerNameChar(c))
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// verify integer bounds
|
// verify integer bounds
|
||||||
if(_EntryType==Integer && (_IntegerMinValue!=INT_MIN || _IntegerMaxValue!=INT_MAX))
|
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()
|
bool CGroupEditBox::undo()
|
||||||
|
@ -720,7 +735,7 @@ bool CGroupEditBox::expand()
|
||||||
if (_InputString[0] == '/')
|
if (_InputString[0] == '/')
|
||||||
{
|
{
|
||||||
makeTopWindow();
|
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();
|
std::string command = ucstring(_InputString.substr(1)).toUtf8();
|
||||||
ICommand::expand(command);
|
ICommand::expand(command);
|
||||||
// then back to ucstring
|
// then back to ucstring
|
||||||
|
@ -788,12 +803,14 @@ bool CGroupEditBox::handleEvent (const CEventDescriptor& event)
|
||||||
switch(rEDK.getKeyEventType())
|
switch(rEDK.getKeyEventType())
|
||||||
{
|
{
|
||||||
case CEventDescriptorKey::keychar: handleEventChar(rEDK); break;
|
case CEventDescriptorKey::keychar: handleEventChar(rEDK); break;
|
||||||
|
case CEventDescriptorKey::keystring: handleEventString(rEDK); break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
// update the text
|
// update the text
|
||||||
setInputString(_InputString);
|
setInputString(_InputString);
|
||||||
|
|
||||||
// if event of type char, consider handle all of them
|
// if event of type char or string, consider handle all of them
|
||||||
if( rEDK.getKeyEventType()==CEventDescriptorKey::keychar )
|
if( rEDK.getKeyEventType()==CEventDescriptorKey::keychar || rEDK.getKeyEventType()==CEventDescriptorKey::keystring )
|
||||||
return true;
|
return true;
|
||||||
// Else filter the EventKeyDown AND EventKeyUp.
|
// Else filter the EventKeyDown AND EventKeyUp.
|
||||||
else
|
else
|
||||||
|
@ -1090,7 +1107,7 @@ void CGroupEditBox::setInputStringAsInt(sint32 val)
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
sint64 CGroupEditBox::getInputStringAsInt64() const
|
sint64 CGroupEditBox::getInputStringAsInt64() const
|
||||||
{
|
{
|
||||||
sint32 value;
|
sint64 value;
|
||||||
fromString(_InputString.toString(), value);
|
fromString(_InputString.toString(), value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,8 +288,10 @@ private:
|
||||||
void setupDisplayText();
|
void setupDisplayText();
|
||||||
void makeTopWindow();
|
void makeTopWindow();
|
||||||
void handleEventChar(const CEventDescriptorKey &event);
|
void handleEventChar(const CEventDescriptorKey &event);
|
||||||
|
void handleEventString(const CEventDescriptorKey &event);
|
||||||
void setup();
|
void setup();
|
||||||
void triggerOnChangeAH();
|
void triggerOnChangeAH();
|
||||||
|
void appendString(const ucstring &str);
|
||||||
|
|
||||||
ucstring getSelection();
|
ucstring getSelection();
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@ void CInputHandlerManager::addToServer(NLMISC::CEventServer * server)
|
||||||
server->addListener(EventMouseDblClkId, this);
|
server->addListener(EventMouseDblClkId, this);
|
||||||
|
|
||||||
// Keyboard
|
// Keyboard
|
||||||
|
server->addListener(EventStringId, this);
|
||||||
server->addListener(EventCharId, this);
|
server->addListener(EventCharId, this);
|
||||||
server->addListener(EventKeyDownId, this);
|
server->addListener(EventKeyDownId, this);
|
||||||
server->addListener(EventKeyUpId, this);
|
server->addListener(EventKeyUpId, this);
|
||||||
|
@ -127,6 +128,7 @@ void CInputHandlerManager::release()
|
||||||
_EventServer->removeListener(EventMouseDblClkId, this);
|
_EventServer->removeListener(EventMouseDblClkId, this);
|
||||||
|
|
||||||
// Keyboard
|
// Keyboard
|
||||||
|
_EventServer->removeListener(EventStringId, this);
|
||||||
_EventServer->removeListener(EventCharId, this);
|
_EventServer->removeListener(EventCharId, this);
|
||||||
_EventServer->removeListener(EventKeyDownId, this);
|
_EventServer->removeListener(EventKeyDownId, this);
|
||||||
_EventServer->removeListener(EventKeyUpId, this);
|
_EventServer->removeListener(EventKeyUpId, this);
|
||||||
|
@ -230,7 +232,8 @@ void CInputHandlerManager::operator ()(const NLMISC::CEvent &event)
|
||||||
// **** Event Keyboard
|
// **** Event Keyboard
|
||||||
if( event == EventKeyDownId ||
|
if( event == EventKeyDownId ||
|
||||||
event == EventKeyUpId ||
|
event == EventKeyUpId ||
|
||||||
event == EventCharId)
|
event == EventCharId ||
|
||||||
|
event == EventStringId)
|
||||||
{
|
{
|
||||||
// if not handled, post to Action Manager
|
// if not handled, post to Action Manager
|
||||||
if( !pIM->handleEvent( CEventDescriptorKey((const CEventKey &) event) ) )
|
if( !pIM->handleEvent( CEventDescriptorKey((const CEventKey &) event) ) )
|
||||||
|
|
Loading…
Reference in a new issue