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.
|
2005-01-29 16:30:51 +00:00
|
|
|
*
|
2021-12-26 18:47:58 +01: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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2005-01-29 16:30:51 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-02-18 02:34:20 +01:00
|
|
|
*
|
2005-01-29 16:30:51 +00:00
|
|
|
*/
|
|
|
|
|
2010-11-16 10:11:57 +00:00
|
|
|
#ifndef GUI_WIDGETS_EDITABLE_H
|
|
|
|
#define GUI_WIDGETS_EDITABLE_H
|
2005-01-29 16:30:51 +00:00
|
|
|
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/keyboard.h"
|
2005-01-29 16:30:51 +00:00
|
|
|
#include "common/str.h"
|
|
|
|
#include "gui/widget.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "gui/ThemeEngine.h"
|
|
|
|
#include "gui/object.h"
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
struct Rect;
|
|
|
|
}
|
2005-01-29 16:30:51 +00:00
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
2005-01-29 18:04:34 +00:00
|
|
|
/**
|
|
|
|
* Base class for widgets which need to edit text, like ListWidget and
|
|
|
|
* EditTextWidget.
|
|
|
|
*/
|
2009-06-06 17:53:25 +00:00
|
|
|
class EditableWidget : public Widget, public CommandSender {
|
2005-01-29 16:30:51 +00:00
|
|
|
protected:
|
2021-11-10 15:56:44 +01:00
|
|
|
Common::U32String _editString;
|
2005-01-29 16:30:51 +00:00
|
|
|
|
2009-06-06 17:53:25 +00:00
|
|
|
uint32 _cmd;
|
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
bool _caretVisible;
|
|
|
|
uint32 _caretTime;
|
|
|
|
int _caretPos;
|
|
|
|
|
|
|
|
bool _caretInverse;
|
|
|
|
|
|
|
|
int _editScrollOffset;
|
|
|
|
|
2023-03-01 02:42:15 +05:30
|
|
|
int _selCaretPos;
|
|
|
|
int _selOffset;
|
|
|
|
bool _shiftPressed;
|
|
|
|
bool _isDragging;
|
|
|
|
bool _disableSelection;
|
|
|
|
|
2020-06-08 19:23:14 +05:30
|
|
|
Graphics::TextAlign _align;
|
|
|
|
Graphics::TextAlign _drawAlign;
|
|
|
|
|
2008-11-10 11:24:55 +00:00
|
|
|
ThemeEngine::FontStyle _font;
|
2006-05-27 05:46:04 +00:00
|
|
|
|
2010-09-14 00:15:20 +00:00
|
|
|
ThemeEngine::TextInversionState _inversion;
|
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
public:
|
2023-03-23 21:04:50 +00:00
|
|
|
EditableWidget(GuiObject *boss, int x, int y, int w, int h, bool scale, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
|
2020-11-15 18:15:58 +00:00
|
|
|
EditableWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
|
2021-11-10 15:56:44 +01:00
|
|
|
EditableWidget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
|
2020-01-05 17:48:04 +01:00
|
|
|
~EditableWidget() override;
|
2005-01-29 16:30:51 +00:00
|
|
|
|
2006-03-07 05:39:52 +00:00
|
|
|
void init();
|
|
|
|
|
2021-11-10 15:56:44 +01:00
|
|
|
virtual void setEditString(const Common::U32String &str);
|
|
|
|
virtual const Common::U32String &getEditString() const { return _editString; }
|
2005-01-29 18:04:34 +00:00
|
|
|
|
2020-01-05 17:48:04 +01:00
|
|
|
void handleTickle() override;
|
2023-03-01 02:42:15 +05:30
|
|
|
void handleMouseDown(int x, int y, int button, int clickCount) override;
|
|
|
|
void handleMouseUp(int x, int y, int button, int clickCount) override;
|
|
|
|
void handleMouseMoved(int x, int y, int button) override;
|
2020-01-05 17:48:04 +01:00
|
|
|
bool handleKeyDown(Common::KeyState state) override;
|
2023-03-01 02:42:15 +05:30
|
|
|
bool handleKeyUp(Common::KeyState state) override;
|
2020-01-05 17:48:04 +01:00
|
|
|
void reflowLayout() override;
|
2006-08-04 15:48:37 +00:00
|
|
|
|
2012-02-22 17:15:02 +02:00
|
|
|
bool setCaretPos(int newPos);
|
2023-03-01 02:42:15 +05:30
|
|
|
void setSelectionOffset(int newOffset);
|
2012-02-22 17:15:02 +02:00
|
|
|
|
2005-01-29 16:30:51 +00:00
|
|
|
protected:
|
|
|
|
virtual void startEditMode() = 0;
|
|
|
|
virtual void endEditMode() = 0;
|
2012-09-26 04:17:31 +02:00
|
|
|
virtual void abortEditMode() = 0;
|
2013-11-24 00:20:29 +01:00
|
|
|
/**
|
|
|
|
* The area where text input is being made. This should exactly match the
|
|
|
|
* rect with which the actual edit string is drawn otherwise nasty
|
|
|
|
* graphics glitches when redrawing the caret can occur.
|
|
|
|
*/
|
2005-01-29 16:30:51 +00:00
|
|
|
virtual Common::Rect getEditRect() const = 0;
|
2005-01-29 18:04:34 +00:00
|
|
|
virtual int getCaretOffset() const;
|
2023-03-01 02:42:15 +05:30
|
|
|
virtual int getSelectionCarretOffset() const;
|
2012-09-26 04:17:31 +02:00
|
|
|
void drawCaret(bool erase);
|
2005-01-29 18:04:34 +00:00
|
|
|
bool adjustOffset();
|
2006-05-27 13:17:19 +00:00
|
|
|
void makeCaretVisible();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2010-02-21 04:04:13 +00:00
|
|
|
void defaultKeyDownHandler(Common::KeyState &state, bool &dirty, bool &forcecaret, bool &handled);
|
|
|
|
|
2008-11-10 11:24:55 +00:00
|
|
|
void setFontStyle(ThemeEngine::FontStyle font) { _font = font; }
|
2006-05-27 05:46:04 +00:00
|
|
|
|
2022-11-01 08:41:39 +02:00
|
|
|
virtual bool isCharAllowed(Common::u32char_type_t c) const;
|
|
|
|
bool tryInsertChar(Common::u32char_type_t c, int pos);
|
2022-07-29 01:46:16 +03:00
|
|
|
|
|
|
|
int caretVisualPos(int logicalPos);
|
|
|
|
int caretLogicalPos() const;
|
2023-03-01 02:42:15 +05:30
|
|
|
|
|
|
|
void clearSelection();
|
2005-01-29 16:30:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace GUI
|
|
|
|
|
|
|
|
#endif
|