MyGUI 3.5.3
MyGUI_EditBox.h
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#ifndef MYGUI_EDIT_BOX_H_
8#define MYGUI_EDIT_BOX_H_
9
10#include "MyGUI_Prerequest.h"
11#include "MyGUI_TextBox.h"
13#include "MyGUI_TextIterator.h"
14#include "MyGUI_EventPair.h"
16
17namespace MyGUI
18{
19
21
25 class MYGUI_EXPORT EditBox : public TextBox, public ScrollViewBase, public MemberObsolete<EditBox>
26 {
27 MYGUI_RTTI_DERIVED(EditBox)
28
29 public:
30 EditBox();
31
33 void setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour);
34
36 size_t getTextSelectionStart() const;
37
39 size_t getTextSelectionEnd() const;
40
42 size_t getTextSelectionLength() const;
43
45 UString getTextInterval(size_t _start, size_t _count) const;
46
51 void setTextSelection(size_t _start, size_t _end);
52
54 void deleteTextSelection();
55
57 UString getTextSelection() const;
58
60 bool isTextSelection() const;
61
63 void setTextSelectionColour(const Colour& _colour);
64
66 void setTextCursor(size_t _index);
68 size_t getTextCursor() const;
69
70
72 void setCaption(const UString& _value) override;
74 const UString& getCaption() const override;
75
77 void setOnlyText(const UString& _text);
79 UString getOnlyText() const;
80
85 size_t getTextLength() const;
86
88 void setOverflowToTheLeft(bool _value);
90 bool getOverflowToTheLeft() const;
91
93 void setMaxTextLength(size_t _value);
95 size_t getMaxTextLength() const;
96
98 void insertText(const UString& _text, size_t _index = ITEM_NONE);
100 void addText(const UString& _text);
102 void eraseText(size_t _start, size_t _count = 1);
103
108 void setEditReadOnly(bool _value);
110 bool getEditReadOnly() const;
111
118 void setEditPassword(bool _password);
120 bool getEditPassword() const;
121
127 void setEditMultiLine(bool _value);
129 bool getEditMultiLine() const;
130
135 void setEditStatic(bool _value);
137 bool getEditStatic() const;
138
140 void setPasswordChar(Char _char);
142 void setPasswordChar(const UString& _value);
144 Char getPasswordChar() const;
145
151 void setEditWordWrap(bool _value);
153 bool getEditWordWrap() const;
154
160 void setTabPrinting(bool _value);
162 bool getTabPrinting() const;
163
165 bool getInvertSelected() const;
169 void setInvertSelected(bool _value);
170
172 void setPosition(const IntPoint& _point) override;
174 void setSize(const IntSize& _size) override;
176 void setCoord(const IntCoord& _coord) override;
177
178 using Widget::setPosition;
179 using Widget::setSize;
180 using Widget::setCoord;
181
183 void setVisibleVScroll(bool _value);
185 bool isVisibleVScroll() const;
192 size_t getVScrollRange() const;
194 size_t getVScrollPosition() const;
196 void setVScrollPosition(size_t _index);
197
199 void setVisibleHScroll(bool _value);
201 bool isVisibleHScroll() const;
207 size_t getHScrollRange() const;
209 size_t getHScrollPosition() const;
211 void setHScrollPosition(size_t _index);
212
213
215 void setFontName(std::string_view _value) override;
217 void setFontHeight(int _value) override;
219 int getFontHeight() const override;
220
222 void setTextAlign(Align _value) override;
224 void setTextColour(const Colour& _value) override;
225
227 IntCoord getTextRegion() const override;
228
230 IntSize getTextSize() const override;
231
233 void setTextShadowColour(const Colour& _value) override;
234
236 void setTextShadow(bool _value) override;
237
238 /*events:*/
244
250
251 protected:
252 void initialiseOverride() override;
253 void shutdownOverride() override;
254
255 void onMouseDrag(int _left, int _top, MouseButton _id) override;
256 void onKeyLostFocus(Widget* _new) override;
257 void onKeySetFocus(Widget* _old) override;
258 void onKeyButtonPressed(KeyCode _key, Char _char) override;
259
260 // TODO: refactor these notify methods
261 void notifyMouseSetFocus(Widget* _sender, Widget* _old);
262 void notifyMouseLostFocus(Widget* _sender, Widget* _new);
263 void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
264 void notifyMouseReleased(Widget* _sender, int _left, int _top, MouseButton _id);
265 void notifyMouseDrag(Widget* _sender, int _left, int _top, MouseButton _id);
266 void notifyMouseButtonDoubleClick(Widget* _sender);
267
268 void notifyScrollChangePosition(ScrollBar* _sender, size_t _position);
269 void notifyMouseWheel(Widget* _sender, int _rel);
270
271 void updateView();
272 void updateViewWithCursor();
273
274 void eraseView();
275
276 void setPropertyOverride(std::string_view _key, std::string_view _value) override;
277
278 private:
279 void setText(const UString& _caption, bool _history);
280 bool deleteTextSelect(bool _history);
281 void insertText(const UString& _text, size_t _start, bool _history);
282 void eraseText(size_t _start, size_t _count, bool _history);
283 void setTextSelectColour(const Colour& _colour, bool _history);
284 void _setTextColour(size_t _start, size_t _count, const Colour& _colour, bool _history);
285
286 void frameEntered(float _frame);
287
288 void updateEditState();
289
290 // Update text selection based on mouse coordinates
291 void updateSelectText();
292
293 void resetSelect();
294
295 // Record position data in undo/redo history
296 void commandPosition(size_t _undo, size_t _redo, size_t _length, VectorChangeInfo* _info = nullptr);
297
298 bool commandRedo();
299 bool commandUndo();
300 // Merge last two commands in history
301 void commandMerge();
302 void commandResetRedo();
303 void commandResetHistory();
304 void saveInHistory(VectorChangeInfo* _info = nullptr);
305 void moveCursorVertical(int _delta, size_t _clampTarget);
306
307 // clipboard commands
308 void commandCut();
309 void commandCopy() const;
310 void commandPaste();
311
312 const UString& getRealString() const;
313
314 void setRealString(const UString& _caption);
315
316 void updateCursorPosition();
317
318 IntSize getContentSize() const override;
319 IntPoint getContentPosition() const override;
320 void setContentPosition(const IntPoint& _point) override;
321 IntSize getViewSize() const override;
322 size_t getVScrollPage() const override;
323 size_t getHScrollPage() const override;
324
325 Align getContentAlign() const override;
326
327 protected:
328 bool mIsPressed{false};
329 bool mIsFocus{false};
330
331 bool mCursorActive{false};
332 float mCursorTimer{0};
333 float mActionMouseTimer{0};
334
335 size_t mCursorPosition{0};
336 size_t mTextLength{0};
337
338 size_t mStartSelect{ITEM_NONE};
339 size_t mEndSelect{0};
340
341 // Undo/redo change history
342 DequeUndoRedoInfo mVectorUndoChangeInfo;
343 DequeUndoRedoInfo mVectorRedoChangeInfo;
344
345 bool mMouseLeftPressed{false};
346
347 bool mModeReadOnly{false};
348 bool mModePassword{false};
349 bool mModeMultiline{false};
350 bool mModeStatic{false};
351 bool mModeWordWrap{false};
352
353 bool mTabPrinting{false};
354
355 // Actual text hidden behind password characters
356 UString mPasswordText;
357
358 // Original pointer name for static mode (where cursor is not needed)
359 std::string mOriginalPointer;
360
361 Char mCharPassword{'*'};
362
363 bool mOverflowToTheLeft{false};
364 size_t mMaxTextLength;
365
366 ISubWidgetText* mClientText{nullptr};
367 };
368
369} // namespace MyGUI
370
371#endif // MYGUI_EDIT_BOX_H_
#define MYGUI_EXPORT
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition MyGUI_RTTI.h:67
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:26
std::vector< TextCommandInfo > VectorChangeInfo
unsigned int Char
Definition MyGUI_Types.h:49
constexpr size_t ITEM_NONE
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:35
types::TSize< int > IntSize
Definition MyGUI_Types.h:29
std::deque< VectorChangeInfo > DequeUndoRedoInfo
delegates::MultiDelegate< EditBox * > EventHandle_EditPtr