* 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. */
| 791 | * @return Top-left location of the caret, relative to the window. |
| 792 | */ |
| 793 | Point QueryString::GetCaretPosition(const Window *w, WidgetID wid) const |
| 794 | { |
| 795 | const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid); |
| 796 | |
| 797 | assert((wi->type & WWT_MASK) == WWT_EDITBOX); |
| 798 | |
| 799 | bool rtl = _current_text_dir == TD_RTL; |
| 800 | Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT); |
| 801 | int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal(); |
| 802 | |
| 803 | Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect); |
| 804 | |
| 805 | /* Clamp caret position to be inside out current width. */ |
| 806 | const Textbuf *tb = &this->text; |
| 807 | r = ScrollEditBoxTextRect(r, *tb); |
| 808 | |
| 809 | Point pt = {r.left + tb->caretxoffs, r.top}; |
| 810 | return pt; |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * Get the bounding rectangle for a range of the query string. |
nothing calls this directly
no test coverage detected