ScummVM API documentation
editable.h
1 /* ScummVM - Graphic Adventure Engine
2  *
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.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GUI_WIDGETS_EDITABLE_H
23 #define GUI_WIDGETS_EDITABLE_H
24 
25 #include "common/keyboard.h"
26 #include "common/str.h"
27 #include "gui/widget.h"
28 #include "gui/ThemeEngine.h"
29 #include "gui/object.h"
30 
31 namespace Common {
32 struct Rect;
33 }
34 
35 namespace GUI {
36 
41 class EditableWidget : public Widget, public CommandSender {
42 protected:
43  Common::U32String _editString;
44 
45  uint32 _cmd;
46 
47  bool _caretVisible;
48  uint32 _caretTime;
49  int _caretPos;
50 
51  bool _caretInverse;
52 
53  int _editScrollOffset;
54 
55  int _selCaretPos;
56  int _selOffset;
57  bool _shiftPressed;
58  bool _isDragging;
59  bool _disableSelection;
60 
61  Graphics::TextAlign _align;
62  Graphics::TextAlign _drawAlign;
63 
65 
67 
68 public:
69  EditableWidget(GuiObject *boss, int x, int y, int w, int h, bool scale, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
70  EditableWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
71  EditableWidget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
72  ~EditableWidget() override;
73 
74  void init();
75 
76  virtual void setEditString(const Common::U32String &str);
77  virtual const Common::U32String &getEditString() const { return _editString; }
78 
79  void handleTickle() override;
80  void handleMouseDown(int x, int y, int button, int clickCount) override;
81  void handleMouseUp(int x, int y, int button, int clickCount) override;
82  void handleMouseMoved(int x, int y, int button) override;
83  bool handleKeyDown(Common::KeyState state) override;
84  bool handleKeyUp(Common::KeyState state) override;
85  void handleOtherEvent(const Common::Event& evt) override;
86  void reflowLayout() override;
87 
88  void moveCaretToStart(bool shiftPressed);
89  void moveCaretToEnd(bool shiftPressed);
90  bool setCaretPos(int newPos);
91  void setSelectionOffset(int newOffset);
92 
93 protected:
94  void drawWidget() override;
95 
96  virtual void startEditMode() = 0;
97  virtual void endEditMode() = 0;
98  virtual void abortEditMode() = 0;
104  virtual Common::Rect getEditRect() const = 0;
105  virtual int getCaretOffset() const;
106  virtual int getSelectionCarretOffset() const;
107  void drawCaret(bool erase, bool useRelativeCoordinates = false);
108  bool adjustOffset();
109  void makeCaretVisible();
110 
111  void defaultKeyDownHandler(Common::KeyState &state, bool &dirty, bool &forcecaret, bool &handled);
112 
113  void setFontStyle(ThemeEngine::FontStyle font) { _font = font; }
114 
115  virtual bool isCharAllowed(Common::u32char_type_t c) const;
116  bool tryInsertChar(Common::u32char_type_t c, int pos);
117 
118  int caretVisualPos(int logicalPos) const;
119  int caretLogicalPos() const;
120 
121  void clearSelection();
122 };
123 
124 } // End of namespace GUI
125 
126 #endif
Definition: str.h:59
TextAlign
Definition: font.h:48
Definition: rect.h:144
Definition: system.h:46
Definition: object.h:60
TextInversionState
Text inversion state of the text to be draw.
Definition: ThemeEngine.h:259
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: ustr.h:57
Definition: events.h:199
Definition: algorithm.h:29
FontStyle
Font style selector.
Definition: ThemeEngine.h:274
char32_t u32char_type_t
Definition: ustr.h:41
Definition: editable.h:41
Definition: widget.h:101
Definition: keyboard.h:294
Definition: object.h:40