diff --git a/config.lib b/config.lib
--- a/config.lib
+++ b/config.lib
@@ -1498,7 +1498,7 @@ make_cflags_and_ldflags() {
LDFLAGS="$LDFLAGS -Wl,--subsystem,windows"
fi
- LIBS="$LIBS -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32"
+ LIBS="$LIBS -lws2_32 -lwinmm -lgdi32 -ldxguid -lole32 -limm32"
if [ $cc_version -ge 44 ]; then
LDFLAGS_BUILD="$LDFLAGS_BUILD -static-libgcc -static-libstdc++"
diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj
--- a/projects/openttd_vs100.vcxproj
+++ b/projects/openttd_vs100.vcxproj
@@ -131,7 +131,7 @@
0x0809
- winmm.lib;ws2_32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
+ winmm.lib;ws2_32.lib;imm32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
true
%(IgnoreSpecificDefaultLibraries)
true
@@ -176,7 +176,7 @@
0x0809
- winmm.lib;ws2_32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
+ winmm.lib;ws2_32.lib;imm32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
true
LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)
true
@@ -233,7 +233,7 @@
0x0809
- winmm.lib;ws2_32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
+ winmm.lib;ws2_32.lib;imm32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
true
%(IgnoreSpecificDefaultLibraries)
true
@@ -280,7 +280,7 @@
0x0809
- winmm.lib;ws2_32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
+ winmm.lib;ws2_32.lib;imm32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
true
LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)
true
diff --git a/projects/openttd_vs100.vcxproj.in b/projects/openttd_vs100.vcxproj.in
--- a/projects/openttd_vs100.vcxproj.in
+++ b/projects/openttd_vs100.vcxproj.in
@@ -131,7 +131,7 @@
0x0809
- winmm.lib;ws2_32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
+ winmm.lib;ws2_32.lib;imm32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
true
%(IgnoreSpecificDefaultLibraries)
true
@@ -176,7 +176,7 @@
0x0809
- winmm.lib;ws2_32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
+ winmm.lib;ws2_32.lib;imm32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
true
LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)
true
@@ -233,7 +233,7 @@
0x0809
- winmm.lib;ws2_32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
+ winmm.lib;ws2_32.lib;imm32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
true
%(IgnoreSpecificDefaultLibraries)
true
@@ -280,7 +280,7 @@
0x0809
- winmm.lib;ws2_32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
+ winmm.lib;ws2_32.lib;imm32.lib;libpng.lib;zlibstat.lib;lzo2.lib;liblzma.lib;libfreetype2.lib;icuuc.lib;icuin.lib;icudt.lib;icule.lib;iculx.lib;%(AdditionalDependencies)
true
LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)
true
diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj
--- a/projects/openttd_vs80.vcproj
+++ b/projects/openttd_vs80.vcproj
@@ -87,7 +87,7 @@
/>
SetDirty();
+ }
+ }
+
virtual void OnMouseWheel(int wheel)
{
this->Scroll(-wheel);
diff --git a/src/gfx_func.h b/src/gfx_func.h
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -71,6 +71,7 @@ extern Dimension _cur_resolution;
extern Palette _cur_palette; ///< Current palette
void HandleKeypress(uint keycode, WChar key);
+void HandleTextInput(const char *str);
void HandleCtrlChanged();
void HandleMouseEvents();
void CSleep(int milliseconds);
diff --git a/src/textbuf.cpp b/src/textbuf.cpp
--- 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()
{
diff --git a/src/textbuf_type.h b/src/textbuf_type.h
--- a/src/textbuf_type.h
+++ b/src/textbuf_type.h
@@ -52,6 +52,7 @@ struct Textbuf {
bool InsertClipboard();
bool InsertChar(uint32 key);
+ bool InsertString(const char *str);
bool DeleteChar(uint16 keycode);
bool MovePos(uint16 keycode);
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -24,6 +24,7 @@
#include "../window_func.h"
#include "win32_v.h"
#include
+#include
/* Missing define in MinGW headers. */
#ifndef MAPVK_VK_TO_CHAR
@@ -498,6 +499,33 @@ static LRESULT HandleCharMsg(uint keycod
return 0;
}
+#if !defined(WINCE) || _WIN32_WCE >= 0x400
+/** Handle WM_IME_COMPOSITION messages. */
+static LRESULT HandleIMEComposition(HWND hwnd, WPARAM wParam, LPARAM lParam)
+{
+ HIMC hIMC = ImmGetContext(hwnd);
+
+ if (hIMC != NULL) {
+ if (lParam & GCS_RESULTSTR) {
+ /* Read result string from the IME. */
+ LONG len = ImmGetCompositionString(hIMC, GCS_RESULTSTR, NULL, 0); // Length is always in bytes, even in UNICODE build.
+ TCHAR *str = (TCHAR *)_alloca(len + sizeof(TCHAR));
+ len = ImmGetCompositionString(hIMC, GCS_RESULTSTR, str, len);
+ str[len / sizeof(TCHAR)] = '\0';
+
+ /* Transmit text to windowing system. */
+ if (len > 0) HandleTextInput(FS2OTTD(str));
+
+ /* Don't pass the result string on to the default window proc. */
+ lParam &= ~(GCS_RESULTSTR | GCS_RESULTCLAUSE | GCS_RESULTREADCLAUSE | GCS_RESULTREADSTR);
+ }
+ }
+ ImmReleaseContext(hwnd, hIMC);
+
+ return lParam != 0 ? DefWindowProc(hwnd, WM_IME_COMPOSITION, wParam, lParam) : 0;
+}
+#endif
+
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static uint32 keycode = 0;
@@ -633,6 +661,9 @@ static LRESULT CALLBACK WndProcGdi(HWND
}
#if !defined(WINCE) || _WIN32_WCE >= 0x400
+ case WM_IME_COMPOSITION:
+ return HandleIMEComposition(hwnd, wParam, lParam);
+
#if !defined(UNICODE)
case WM_IME_CHAR:
if (GB(wParam, 8, 8) != 0) {
diff --git a/src/window.cpp b/src/window.cpp
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -2533,6 +2533,33 @@ void HandleCtrlChanged()
}
/**
+ * Insert a text string at the cursor position into the edit box widget.
+ * @param wid Edit box widget.
+ * @param str Text string to insert.
+ */
+/* virtual */ void Window::InsertTextString(int wid, const char *str)
+{
+ QueryString *query = this->GetQueryString(wid);
+ if (query == NULL) return;
+
+ if (query->text.InsertString(str)) {
+ this->SetWidgetDirty(wid);
+ this->OnEditboxChanged(wid);
+ }
+}
+
+/**
+ * Handle text input.
+ * @param str Text string to input.
+ */
+void HandleTextInput(const char *str)
+{
+ if (!EditBoxInGlobalFocus()) return;
+
+ _focused_window->InsertTextString(_focused_window->window_class == WC_CONSOLE ? 0 : _focused_window->nested_focus->index, str);
+}
+
+/**
* Local counter that is incremented each time an mouse input event is detected.
* The counter is used to stop auto-scrolling.
* @see HandleAutoscroll()
diff --git a/src/window_gui.h b/src/window_gui.h
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -489,6 +489,7 @@ public:
bool SetFocusedWidget(int widget_index);
EventState HandleEditBoxKey(int wid, WChar key, uint16 keycode);
+ virtual void InsertTextString(int wid, const char *str);
void HandleButtonClick(byte widget);
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height = -1) const;