summaryrefslogtreecommitdiff
path: root/src/textbuf.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:37:25 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:37:25 +0000
commit0883cf76e34527f3bf4d8a19c6f68b655969798c (patch)
tree2626bc344a106a36aa31fca834a40c1bb74f9472 /src/textbuf.cpp
parent64d2fc4d1e4124a55ccee8c4a4c6e43d1c2ae9fe (diff)
downloadopenttd-0883cf76e34527f3bf4d8a19c6f68b655969798c.tar.xz
(svn r25684) -Change: [Win32] Draw the composition string ourselves if possible.
Diffstat (limited to 'src/textbuf.cpp')
-rw-r--r--src/textbuf.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/textbuf.cpp b/src/textbuf.cpp
index aea7c4918..e99e89662 100644
--- a/src/textbuf.cpp
+++ b/src/textbuf.cpp
@@ -151,10 +151,17 @@ bool Textbuf::InsertChar(WChar key)
* we don't care about the visual-length but only about the physical
* length of the string.
* @param str String to insert.
+ * @param marked Replace the currently marked text with the new text.
+ * @param caret Move the caret to this point in the insertion string.
* @return True on successful change of Textbuf, or false otherwise.
*/
-bool Textbuf::InsertString(const char *str)
+bool Textbuf::InsertString(const char *str, bool marked, const char *caret)
{
+ uint16 insertpos = (marked && this->marklength != 0) ? this->markpos : this->caretpos;
+
+ if (marked) this->DiscardMarkedText(str == NULL);
+
+ if (str == NULL) return false;
uint16 bytes = 0, chars = 0;
WChar c;
@@ -167,16 +174,24 @@ bool Textbuf::InsertString(const char *str)
bytes += len;
chars++;
+
+ /* Move caret if needed. */
+ if (ptr == caret) this->caretpos = insertpos + bytes;
}
if (bytes == 0) return false;
- memmove(this->buf + this->caretpos + bytes, this->buf + this->caretpos, this->bytes - this->caretpos);
- memcpy(this->buf + this->caretpos, str, bytes);
+ if (marked) {
+ this->markpos = insertpos;
+ this->markend = insertpos + bytes;
+ }
+
+ memmove(this->buf + insertpos + bytes, this->buf + insertpos, this->bytes - insertpos);
+ memcpy(this->buf + insertpos, str, bytes);
this->bytes += bytes;
this->chars += chars;
- this->caretpos += bytes;
+ if (!marked && caret == NULL) this->caretpos += bytes;
assert(this->bytes <= this->max_bytes);
assert(this->chars <= this->max_chars);
this->buf[this->bytes - 1] = '\0'; // terminating zero
@@ -201,7 +216,7 @@ bool Textbuf::InsertClipboard()
if (!GetClipboardContents(utf8_buf, lengthof(utf8_buf))) return false;
- return this->InsertString(utf8_buf);
+ return this->InsertString(utf8_buf, false);
}
/**