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
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#include "gui/newgui.h"
|
|
|
|
|
|
|
|
namespace GUI {
|
2002-11-21 15:20:52 +00:00
|
|
|
|
2005-05-20 15:03:26 +00:00
|
|
|
EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, WidgetSize ws)
|
|
|
|
: EditableWidget(boss, x, y - 1, w, h + 2, ws) {
|
2002-11-21 15:20:52 +00:00
|
|
|
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
|
|
|
|
_type = kEditTextWidget;
|
|
|
|
|
2005-01-29 18:04:34 +00:00
|
|
|
setEditString(text);
|
|
|
|
}
|
2003-01-10 21:33:42 +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
|
|
|
}
|
|
|
|
|
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) {
|
2005-06-03 11:33:15 +00:00
|
|
|
width += g_gui.getCharWidth(_editString[i]);
|
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-01-27 15:43:23 +00:00
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), _hints, Theme::kWidgetBackgroundBorderSmall);
|
2002-11-21 15:20:52 +00:00
|
|
|
|
|
|
|
// Draw the text
|
2003-05-05 16:10:19 +00:00
|
|
|
adjustOffset();
|
2006-01-27 15:43:23 +00:00
|
|
|
g_gui.theme()->drawText(Common::Rect(_x+2,_y+2, _x+getEditRect().width()-2, _y+_h-2), _editString, Theme::kStateEnabled, Theme::kTextAlignLeft, false, -_editScrollOffset, false);
|
2005-01-29 16:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rect EditTextWidget::getEditRect() const {
|
|
|
|
Common::Rect r(2, 1, _w - 2, _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() {
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|