summaryrefslogtreecommitdiff
path: root/src/gui/widgets/textfield.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-01-26 10:13:40 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-01-26 10:13:40 +0100
commiteb2e62609992ab8b47f8805f2bc2cafce271b66f (patch)
tree58d6c387f910e3a3348a6528127f4216b524ec57 /src/gui/widgets/textfield.cpp
parent05dc1666dc794ed6aa7f6568b768c652f8922c4e (diff)
parent8d06606835e3d01f537ebe96de8b216e64a1f969 (diff)
downloadmana-lpc2012.tar.gz
mana-lpc2012.tar.bz2
mana-lpc2012.tar.xz
mana-lpc2012.zip
Merge branch 'master' into lpc2012lpc2012
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);
}