(svn r25681) -Change: [Win32] Position the IME composition window at the caret position.
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user