1
/* ScummVM - Graphic Adventure Engine
3
* ScummVM is the legal property of its developers, whose names
4
* are too numerous to list here. Please refer to the COPYRIGHT
5
* file distributed with this source distribution.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/gui/EditTextWidget.cpp $
22
* $Id: EditTextWidget.cpp 52716 2010-09-14 00:15:20Z lordhoto $
25
#include "gui/EditTextWidget.h"
26
#include "gui/dialog.h"
27
#include "gui/GuiManager.h"
29
#include "gui/ThemeEval.h"
33
EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, const char *tooltip, uint32 cmd)
34
: EditableWidget(boss, x, y - 1, w, h + 2, tooltip, cmd) {
35
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
36
_type = kEditTextWidget;
41
EditTextWidget::EditTextWidget(GuiObject *boss, const String &name, const String &text, const char *tooltip, uint32 cmd)
42
: EditableWidget(boss, name, tooltip, cmd) {
43
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE);
44
_type = kEditTextWidget;
49
void EditTextWidget::setEditString(const String &str) {
50
EditableWidget::setEditString(str);
54
void EditTextWidget::reflowLayout() {
55
_leftPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Left", 0);
56
_rightPadding = g_gui.xmlEval()->getVar("Globals.EditTextWidget.Padding.Right", 0);
58
EditableWidget::reflowLayout();
62
void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {
67
x += _editScrollOffset;
72
for (i = 0; i < _editString.size(); ++i) {
73
width += g_gui.theme()->getCharWidth(_editString[i], _font);
82
void EditTextWidget::drawWidget() {
83
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x+_w, _y+_h), 0, ThemeEngine::kWidgetBackgroundEditText);
87
g_gui.theme()->drawText(Common::Rect(_x+2+ _leftPadding,_y+2, _x+_leftPadding+getEditRect().width()+2, _y+_h-2), _editString, _state, Graphics::kTextAlignLeft, ThemeEngine::kTextInversionNone, -_editScrollOffset, false, _font);
90
Common::Rect EditTextWidget::getEditRect() const {
91
Common::Rect r(2 + _leftPadding, 2, _w - 2 - _leftPadding - _rightPadding, _h-1);
96
void EditTextWidget::receivedFocusWidget() {
99
void EditTextWidget::lostFocusWidget() {
100
// If we loose focus, 'commit' the user changes
101
_backupString = _editString;
105
void EditTextWidget::startEditMode() {
108
void EditTextWidget::endEditMode() {
112
void EditTextWidget::abortEditMode() {
113
setEditString(_backupString);
114
sendCommand(_cmd, 0);
118
} // End of namespace GUI