summaryrefslogtreecommitdiff
path: root/src/misc_gui.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:37:14 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:37:14 +0000
commitda09fd3077c288317aaa897b4665c30150358321 (patch)
treefeadeb4b523c314216133329c14d59095591cdda /src/misc_gui.cpp
parent21126aec623c4d5a9afea786f2d57d8897a407bc (diff)
downloadopenttd-da09fd3077c288317aaa897b4665c30150358321.tar.xz
(svn r25681) -Change: [Win32] Position the IME composition window at the caret position.
Diffstat (limited to 'src/misc_gui.cpp')
-rw-r--r--src/misc_gui.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 87847ba70..37a317733 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -785,6 +785,34 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
_cur_dpi = old_dpi;
}
+/**
+ * Get the current caret position.
+ * @param w Window the edit box is in.
+ * @param wid Widget index.
+ * @return Top-left location of the caret, relative to the window.
+ */
+Point QueryString::GetCaretPosition(const Window *w, int wid) const
+{
+ const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
+
+ assert((wi->type & WWT_MASK) == WWT_EDITBOX);
+
+ bool rtl = _current_text_dir == TD_RTL;
+ Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
+ int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
+
+ int left = wi->pos_x + (rtl ? clearbtn_width : 0);
+ int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
+
+ /* Clamp caret position to be inside out current width. */
+ const Textbuf *tb = &this->text;
+ int delta = min(0, (right - left) - tb->pixels - 10);
+ if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
+
+ Point pt = {left + WD_FRAMERECT_LEFT + tb->caretxoffs + delta, wi->pos_y + WD_FRAMERECT_TOP};
+ return pt;
+}
+
void QueryString::ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed)
{
const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);