summaryrefslogtreecommitdiff
path: root/src/gui/widgets/textfield.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/textfield.cpp')
-rw-r--r--src/gui/widgets/textfield.cpp46
1 files changed, 14 insertions, 32 deletions
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index ec57f1c7..35ce09c5 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -24,7 +24,6 @@
#include "configuration.h"
#include "graphics.h"
-#include "gui/palette.h"
#include "gui/sdlinput.h"
#include "resources/image.h"
@@ -36,6 +35,8 @@
#include <guichan/font.hpp>
+#include <SDL.h>
+
#undef DELETE //Win32 compatibility hack
int TextField::instances = 0;
@@ -84,7 +85,7 @@ TextField::~TextField()
instances--;
if (instances == 0)
- for_each(skin.grid, skin.grid + 9, dtor<Image*>());
+ std::for_each(skin.grid, skin.grid + 9, dtor<Image*>());
}
void TextField::updateAlpha()
@@ -162,33 +163,7 @@ int TextField::getValue() const
void TextField::keyPressed(gcn::KeyEvent &keyEvent)
{
- int val = keyEvent.getKey().getValue();
-
- if (val >= 32)
- {
- int l;
- if (val < 128) l = 1; // 0xxxxxxx
- else if (val < 0x800) l = 2; // 110xxxxx 10xxxxxx
- else if (val < 0x10000) l = 3; // 1110xxxx 10xxxxxx 10xxxxxx
- else l = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-
- char buf[4];
- for (int i = 0; i < l; ++i)
- {
- buf[i] = val >> (6 * (l - i - 1));
- if (i > 0) buf[i] = (buf[i] & 63) | 128;
- }
-
- if (l > 1) buf[0] |= 255 << (8 - l);
-
- mText.insert(mCaretPosition, std::string(buf, buf + l));
- mCaretPosition += l;
- }
-
- /* In UTF-8, 10xxxxxx is only used for inner parts of characters. So skip
- them when processing key presses. */
-
- switch (val)
+ switch (keyEvent.getKey().getValue())
{
case Key::LEFT:
{
@@ -302,8 +277,9 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
return;
break;
- case 22: // Control code 22, SYNCHRONOUS IDLE, sent on Ctrl+v
- handlePaste();
+ case SDLK_v:
+ if (keyEvent.isControlPressed())
+ handlePaste();
break;
}
@@ -311,6 +287,12 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
fixScroll();
}
+void TextField::textInput(const TextInput &textInput)
+{
+ mText.insert(mCaretPosition, textInput.getText());
+ mCaretPosition += textInput.getText().length();
+}
+
void TextField::autoComplete()
{
if (mAutoComplete && mText.size() > 0)
@@ -383,7 +365,7 @@ void TextField::handlePaste()
std::string text = getText();
std::string::size_type caretPos = getCaretPosition();
- if (RetrieveBuffer(text, caretPos)) {
+ if (insertFromClipboard(text, caretPos)) {
setText(text);
setCaretPosition(caretPos);
}