2002-11-21 12:48:50 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2002-2006 The ScummVM project
|
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.
|
2002-11-21 12:48:50 +00:00
|
|
|
*
|
2006-02-11 10:08:56 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-11-21 12:48:50 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-11-10 23:40:48 +00:00
|
|
|
#include "gui/EditTextWidget.h"
|
|
|
|
#include "gui/dialog.h"
|
2006-05-18 20:53:28 +00:00
|
|
|
#include "gui/eval.h"
|
2003-11-10 23:40:48 +00:00
|
|
|
#include "gui/newgui.h"
|
|
|
|
|
|
|
|
namespace GUI {
|
2002-11-21 15:20:52 +00:00
|
|
|
|
2006-05-31 12:09:00 +00:00
|
|
|
EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text)
|
|
|
|
: EditableWidget(boss, x, y - 1, w, h + 2) {
|
2002-11-21 15:20:52 +00:00
|
|
|
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
|
|
|
|
_type = kEditTextWidget;
|
|
|
|
|
2006-05-19 22:41:51 +00:00
|
|
|
setEditString(text);
|
2005-01-29 18:04:34 +00:00
|
|
|
}
|
2003-01-10 21:33:42 +00:00
|
|
|
|
2006-06-03 13:33:39 +00:00
|
|
|
EditTextWidget::EditTextWidget(GuiObject *boss, const String &name, const String &text)
|
2006-03-09 05:18:00 +00:00
|
|
|
: EditableWidget(boss, name) {
|
|
|
|
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
|
|
|
|
_type = kEditTextWidget;
|
2006-05-18 20:53:28 +00:00
|
|
|
_hints |= THEME_HINT_USE_SHADOW;
|
2006-03-09 05:18:00 +00:00
|
|
|
|
2006-05-19 22:41:51 +00:00
|
|
|
setEditString(text);
|
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() {
|
2006-05-18 20:53:28 +00:00
|
|
|
_leftPadding = g_gui.evaluator()->getVar("EditTextWidget.leftPadding", 0);
|
|
|
|
_rightPadding = g_gui.evaluator()->getVar("EditTextWidget.rightPadding", 0);
|
2006-05-27 05:46:04 +00:00
|
|
|
|
2006-06-05 12:22:51 +00:00
|
|
|
_font = (Theme::FontStyle)g_gui.evaluator()->getVar("EditTextWidget.font", Theme::kFontStyleNormal);
|
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) {
|
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
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
for (i = 0; i < _editString.size(); ++i) {
|
2007-01-21 08:43:28 +00:00
|
|
|
width += g_gui.theme()->getCharWidth(_editString[i], _font);
|
2003-05-05 16:12:45 +00:00
|
|
|
if (width >= x)
|
|
|
|
break;
|
|
|
|
}
|
2005-01-29 16:30:51 +00:00
|
|
|
if (setCaretPos(i))
|
2003-05-05 16:12:45 +00:00
|
|
|
draw();
|
2002-11-21 15:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void EditTextWidget::drawWidget(bool hilite) {
|
2006-05-18 20:53:28 +00:00
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), _hints, Theme::kWidgetBackgroundEditText);
|
2002-11-21 15:20:52 +00:00
|
|
|
|
|
|
|
// Draw the text
|
2003-05-05 16:10:19 +00:00
|
|
|
adjustOffset();
|
2006-05-27 05:46:04 +00:00
|
|
|
g_gui.theme()->drawText(Common::Rect(_x+2+ _leftPadding,_y+2, _x+_leftPadding+getEditRect().width()+2, _y+_h-2), _editString, Theme::kStateEnabled, Theme::kTextAlignLeft, false, -_editScrollOffset, false, _font);
|
2005-01-29 16:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rect EditTextWidget::getEditRect() const {
|
2006-05-27 12:37:00 +00:00
|
|
|
Common::Rect r(2 + _leftPadding, 1, _w - 2 - _leftPadding - _rightPadding, _h-1);
|
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() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTextWidget::lostFocusWidget() {
|
|
|
|
// If we loose focus, 'commit' the user changes
|
|
|
|
_backupString = _editString;
|
|
|
|
drawCaret(true);
|
|
|
|
}
|
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();
|
|
|
|
}
|
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);
|
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
|