diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-02-25 23:09:41 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-02-25 23:18:36 +0100 |
commit | 34ce2c58ecfe9bfb04688af321e68f80236d104d (patch) | |
tree | e2554ccfaf2ae991a9f977caa91cad522fe8c088 | |
parent | 01152e00c2099e4f3d2029413718b48d501b153c (diff) | |
download | mana-34ce2c58ecfe9bfb04688af321e68f80236d104d.tar.gz mana-34ce2c58ecfe9bfb04688af321e68f80236d104d.tar.bz2 mana-34ce2c58ecfe9bfb04688af321e68f80236d104d.tar.xz mana-34ce2c58ecfe9bfb04688af321e68f80236d104d.zip |
Handle Ctrl+v for pasting in text fields
Reviewed-by: Jared Adams
-rw-r--r-- | src/gui/widgets/textfield.cpp | 16 | ||||
-rw-r--r-- | src/gui/widgets/textfield.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 803de396..278b4cb9 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -31,6 +31,7 @@ #include "resources/image.h" #include "resources/resourcemanager.h" +#include "utils/copynpaste.h" #include "utils/dtor.h" #include <guichan/font.hpp> @@ -250,8 +251,23 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) if (mLoseFocusOnTab) return; break; + + case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v + handlePaste(); + break; } keyEvent.consume(); fixScroll(); } + +void TextField::handlePaste() +{ + std::string text = getText(); + std::string::size_type caretPos = getCaretPosition(); + + if (RetrieveBuffer(text, caretPos)) { + setText(text); + setCaretPosition(caretPos); + } +} diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index c66139cd..58e37f5c 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -91,6 +91,8 @@ class TextField : public gcn::TextField int getValue() const; private: + void handlePaste(); + static int instances; static float mAlpha; static ImageRect skin; |