2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-11-21 12:48:50 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 02:34:20 +01:00
|
|
|
*
|
2002-11-21 12:48:50 +00:00
|
|
|
*/
|
|
|
|
|
2013-06-25 21:08:55 +10:00
|
|
|
#include "common/system.h"
|
2010-11-16 10:11:57 +00:00
|
|
|
#include "gui/widgets/edittext.h"
|
2010-11-16 10:24:16 +00:00
|
|
|
#include "gui/gui-manager.h"
|
2003-11-10 23:40:48 +00:00
|
|
|
|
2008-08-07 18:42:47 +00:00
|
|
|
#include "gui/ThemeEval.h"
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
2002-11-21 15:20:52 +00:00
|
|
|
|
2011-10-27 01:01:54 +02:00
|
|
|
EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, const char *tooltip, uint32 cmd, uint32 finishCmd)
|
2010-06-15 10:54:22 +00:00
|
|
|
: EditableWidget(boss, x, y - 1, w, h + 2, tooltip, cmd) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
|
2002-11-21 15:20:52 +00:00
|
|
|
_type = kEditTextWidget;
|
2011-04-16 16:18:59 +03:00
|
|
|
_finishCmd = finishCmd;
|
2002-11-21 15:20:52 +00:00
|
|
|
|
2006-05-19 22:41:51 +00:00
|
|
|
setEditString(text);
|
2012-02-25 18:52:04 +01:00
|
|
|
setFontStyle(ThemeEngine::kFontStyleNormal);
|
2016-06-01 11:18:17 +02:00
|
|
|
|
|
|
|
_leftPadding = _rightPadding = 0;
|
2005-01-29 18:04:34 +00:00
|
|
|
}
|
2003-01-10 21:33:42 +00:00
|
|
|
|
2011-04-16 16:18:59 +03:00
|
|
|
EditTextWidget::EditTextWidget(GuiObject *boss, const String &name, const String &text, const char *tooltip, uint32 cmd, uint32 finishCmd)
|
2010-06-15 10:54:22 +00:00
|
|
|
: EditableWidget(boss, name, tooltip, cmd) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
|
2006-03-09 05:18:00 +00:00
|
|
|
_type = kEditTextWidget;
|
2011-04-16 16:18:59 +03:00
|
|
|
_finishCmd = finishCmd;
|
2006-03-09 05:18:00 +00:00
|
|
|
|
2006-05-19 22:41:51 +00:00
|
|
|
setEditString(text);
|
2012-02-25 18:52:04 +01:00
|
|
|
setFontStyle(ThemeEngine::kFontStyleNormal);
|
2016-06-01 11:18:17 +02:00
|
|
|
|
|
|
|
_leftPadding = _rightPadding = 0;
|
2006-03-09 05:18:00 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 18:04:34 +00:00
|
|
|
void EditTextWidget::setEditString(const String &str) {
|
|
|
|
EditableWidget::setEditString(str);
|
|
|
|
_backupString = str;
|
2002-11-21 15:20:52 +00:00
|
|
|
}
|
|
|
|
|
2006-08-04 13:55:53 +00:00
|
|
|
void EditTextWidget::reflowLayout() {
|
2008-08-07 18:42:47 +00:00
|
|
|
_leftPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Left", 0);
|
|
|
|
_rightPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Right", 0);
|
2006-05-27 05:46:04 +00:00
|
|
|
|
2006-08-04 15:48:37 +00:00
|
|
|
EditableWidget::reflowLayout();
|
2006-05-18 20:53:28 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
2015-11-06 05:13:05 +01:00
|
|
|
if (!isEnabled())
|
|
|
|
return;
|
|
|
|
|
2003-05-05 16:12:45 +00:00
|
|
|
// First remove caret
|
|
|
|
if (_caretVisible)
|
|
|
|
drawCaret(true);
|
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
x += _editScrollOffset;
|
2003-05-05 16:12:45 +00:00
|
|
|
|
|
|
|
int width = 0;
|
2004-02-05 00:19:57 +00:00
|
|
|
uint i;
|
2003-05-05 16:12:45 +00:00
|
|
|
|
2012-01-08 02:33:34 +01:00
|
|
|
uint last = 0;
|
2005-01-29 16:30:51 +00:00
|
|
|
for (i = 0; i < _editString.size(); ++i) {
|
2012-01-08 02:33:34 +01:00
|
|
|
const uint cur = _editString[i];
|
|
|
|
width += g_gui.getCharWidth(cur, _font) + g_gui.getKerningOffset(last, cur, _font);
|
2003-05-05 16:12:45 +00:00
|
|
|
if (width >= x)
|
|
|
|
break;
|
2012-01-08 02:33:34 +01:00
|
|
|
last = cur;
|
2003-05-05 16:12:45 +00:00
|
|
|
}
|
2005-01-29 16:30:51 +00:00
|
|
|
if (setCaretPos(i))
|
2018-01-06 14:40:02 +01:00
|
|
|
markAsDirty();
|
2013-06-25 21:08:55 +10:00
|
|
|
}
|
2002-11-21 15:20:52 +00:00
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void EditTextWidget::drawWidget() {
|
2018-01-27 08:59:53 +01:00
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0,
|
|
|
|
ThemeEngine::kWidgetBackgroundEditText);
|
2002-11-21 15:20:52 +00:00
|
|
|
|
|
|
|
// Draw the text
|
2003-05-05 16:10:19 +00:00
|
|
|
adjustOffset();
|
2014-10-28 15:34:48 +02:00
|
|
|
|
2013-06-13 12:32:36 +00:00
|
|
|
const Common::Rect &r = Common::Rect(_x + 2 + _leftPadding, _y + 2, _x + _leftPadding + getEditRect().width() + 8, _y + _h);
|
|
|
|
setTextDrawableArea(r);
|
|
|
|
|
2018-01-27 08:59:53 +01:00
|
|
|
g_gui.theme()->drawText(
|
|
|
|
Common::Rect(_x + 2 + _leftPadding, _y + 2, _x + _leftPadding + getEditRect().width() + 2, _y + _h),
|
|
|
|
_editString, _state, Graphics::kTextAlignLeft, ThemeEngine::kTextInversionNone,
|
|
|
|
-_editScrollOffset, false, _font, ThemeEngine::kFontColorNormal, true, _textDrawableArea);
|
2005-01-29 16:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rect EditTextWidget::getEditRect() const {
|
2013-11-23 23:49:26 +01:00
|
|
|
Common::Rect r(2 + _leftPadding, 2, _w - 2 - _leftPadding - _rightPadding, _h);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
return r;
|
2003-05-05 16:10:19 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
void EditTextWidget::receivedFocusWidget() {
|
2019-02-12 23:42:50 +00:00
|
|
|
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
|
2005-01-29 16:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditTextWidget::lostFocusWidget() {
|
|
|
|
// If we loose focus, 'commit' the user changes
|
|
|
|
_backupString = _editString;
|
|
|
|
drawCaret(true);
|
2019-02-12 23:42:50 +00:00
|
|
|
|
|
|
|
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
|
2005-01-29 16:30:51 +00:00
|
|
|
}
|
2002-11-21 15:20:52 +00:00
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
void EditTextWidget::startEditMode() {
|
|
|
|
}
|
2002-11-21 15:20:52 +00:00
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
void EditTextWidget::endEditMode() {
|
|
|
|
releaseFocus();
|
2011-04-16 16:18:59 +03:00
|
|
|
|
|
|
|
sendCommand(_finishCmd, 0);
|
2005-01-29 16:30:51 +00:00
|
|
|
}
|
2002-11-21 15:20:52 +00:00
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
void EditTextWidget::abortEditMode() {
|
2005-01-29 18:04:34 +00:00
|
|
|
setEditString(_backupString);
|
2009-06-06 23:22:35 +00:00
|
|
|
sendCommand(_cmd, 0);
|
2018-08-18 09:37:59 +03:00
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
releaseFocus();
|
|
|
|
}
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|