mirror of
https://github.com/edubart/otclient.git
synced 2025-12-02 16:06:51 +01:00
make ctrl+v works in lineEdits
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <framework/global.h>
|
||||
|
||||
//TODO: move the next enums to const.h
|
||||
enum InputKeyCode {
|
||||
KC_UNKNOWN = 0x00,
|
||||
KC_ESCAPE = 0x01,
|
||||
@@ -196,6 +197,7 @@ enum PlatformEventType {
|
||||
EventMouseWheelDown = EventMouseAction | EventMouseWheel | EventDown
|
||||
};
|
||||
|
||||
//TODO: rework platform events, make more compatible with UI events
|
||||
struct PlatformEvent {
|
||||
int type;
|
||||
Point mousePos;
|
||||
|
||||
@@ -274,8 +274,27 @@ void UILineEdit::setCursorEnabled(bool enable)
|
||||
update();
|
||||
}
|
||||
|
||||
void UILineEdit::appendText(std::string text)
|
||||
{
|
||||
if(m_cursorPos >= 0) {
|
||||
// replace characters that are now allowed
|
||||
boost::replace_all(text, "\n", "");
|
||||
boost::replace_all(text, "\r", " ");
|
||||
|
||||
if(text.length() > 0) {
|
||||
m_text.insert(m_cursorPos, text);
|
||||
m_cursorPos += text.length();
|
||||
blinkCursor();
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UILineEdit::appendCharacter(char c)
|
||||
{
|
||||
if(c == '\n' || c == '\r')
|
||||
return;
|
||||
|
||||
if(m_cursorPos >= 0) {
|
||||
std::string tmp;
|
||||
tmp = c;
|
||||
@@ -384,6 +403,8 @@ bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
|
||||
setCursorPos(0);
|
||||
else if(keyCode == KC_END) // move cursor to last character
|
||||
setCursorPos(m_text.length());
|
||||
else if(keyCode == KC_V && keyboardModifiers == Fw::KeyboardCtrlModifier)
|
||||
appendText(g_platform.getClipboardText());
|
||||
else if(keyCode == KC_TAB) {
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->focusNextChild(Fw::TabFocusReason);
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
|
||||
void clearText() { setText(""); }
|
||||
void moveCursor(bool right);
|
||||
void appendText(std::string text);
|
||||
void appendCharacter(char c);
|
||||
void removeCharacter(bool right);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user