summaryrefslogtreecommitdiff
path: root/src/textbuf.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:37:06 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:37:06 +0000
commit7422120014b51f0057bb41b3e9b6405957a01b63 (patch)
tree2a56e09275b9e9e75f8be57f4ca1c0b7d39ee3c3 /src/textbuf.cpp
parent13873d2534208ddc4596a9354d23d1e4940339ac (diff)
downloadopenttd-7422120014b51f0057bb41b3e9b6405957a01b63.tar.xz
(svn r25679) -Codechange: [Win32] Get the result string of an IME input directly without a trip through the window messaging system.
Diffstat (limited to 'src/textbuf.cpp')
-rw-r--r--src/textbuf.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/textbuf.cpp b/src/textbuf.cpp
index 58f931f8a..2278be572 100644
--- a/src/textbuf.cpp
+++ b/src/textbuf.cpp
@@ -144,20 +144,18 @@ bool Textbuf::InsertChar(WChar key)
}
/**
- * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
- * and append this up to the maximum length (either absolute or screenlength). If maxlength
- * is zero, we don't care about the screenlength but only about the physical length of the string
- * @return true on successful change of Textbuf, or false otherwise
+ * Insert a string into the text buffer. If maxwidth of the Textbuf is zero,
+ * we don't care about the visual-length but only about the physical
+ * length of the string.
+ * @param str String to insert.
+ * @return True on successful change of Textbuf, or false otherwise.
*/
-bool Textbuf::InsertClipboard()
+bool Textbuf::InsertString(const char *str)
{
- char utf8_buf[512];
-
- if (!GetClipboardContents(utf8_buf, lengthof(utf8_buf))) return false;
uint16 bytes = 0, chars = 0;
WChar c;
- for (const char *ptr = utf8_buf; (c = Utf8Consume(&ptr)) != '\0';) {
+ for (const char *ptr = str; (c = Utf8Consume(&ptr)) != '\0';) {
if (!IsValidChar(c, this->afilter)) break;
byte len = Utf8CharLen(c);
@@ -171,7 +169,7 @@ bool Textbuf::InsertClipboard()
if (bytes == 0) return false;
memmove(this->buf + this->caretpos + bytes, this->buf + this->caretpos, this->bytes - this->caretpos);
- memcpy(this->buf + this->caretpos, utf8_buf, bytes);
+ memcpy(this->buf + this->caretpos, str, bytes);
this->bytes += bytes;
this->chars += chars;
@@ -187,6 +185,21 @@ bool Textbuf::InsertClipboard()
return true;
}
+/**
+ * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
+ * and append this up to the maximum length (either absolute or screenlength). If maxlength
+ * is zero, we don't care about the screenlength but only about the physical length of the string
+ * @return true on successful change of Textbuf, or false otherwise
+ */
+bool Textbuf::InsertClipboard()
+{
+ char utf8_buf[512];
+
+ if (!GetClipboardContents(utf8_buf, lengthof(utf8_buf))) return false;
+
+ return this->InsertString(utf8_buf);
+}
+
/** Update the character iter after the text has changed. */
void Textbuf::UpdateStringIter()
{