From 3468e2caab01027da3743dd1a49fb9bdbd9462fd Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 5 May 2003 16:12:45 +0000 Subject: Patch #732725: EditTextWidget: handleMouseDown positions caret svn-id: r7360 --- gui/EditTextWidget.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp index 4ead9a73d6..17a4abc3f6 100644 --- a/gui/EditTextWidget.cpp +++ b/gui/EditTextWidget.cpp @@ -51,9 +51,26 @@ void EditTextWidget::handleTickle() { } } -void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) { - // TODO - once we support "real editing" (i.e. caret can be at any spot), - // a mouse click should place the caret. +void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount){ + // First remove caret + if (_caretVisible) + drawCaret(true); + + NewGui *gui = _boss->getGui(); + + x += _labelOffset; + + int width = 0; + int i; + + for (i = 0; i < _label.size(); ++i) { + width += gui->getCharWidth(_label[i]); + if (width >= x) + break; + } + _pos = i; + if (adjustOffset()) + draw(); } bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) { -- cgit v1.2.3