MyGUI  3.2.0
MyGUI_EditBox.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_EDIT_BOX_H__
23 #define __MYGUI_EDIT_BOX_H__
24 
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_TextBox.h"
28 #include "MyGUI_TextIterator.h"
29 #include "MyGUI_EventPair.h"
30 #include "MyGUI_ScrollViewBase.h"
31 
32 namespace MyGUI
33 {
34 
36 
38  public TextBox,
39  public ScrollViewBase,
40  public MemberObsolete<EditBox>
41  {
43 
44  public:
45  EditBox();
46 
48  void setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour);
49 
51  size_t getTextSelectionStart() const;
52 
54  size_t getTextSelectionEnd() const;
55 
57  size_t getTextSelectionLength() const;
58 
59  // возвращает текст с тегами
61  UString getTextInterval(size_t _start, size_t _count);
62 
67  void setTextSelection(size_t _start, size_t _end);
68 
70  void deleteTextSelection();
71 
73  UString getTextSelection();
74 
76  bool isTextSelection() const;
77 
79  void setTextSelectionColour(const Colour& _value);
80 
82  void setTextCursor(size_t _index);
84  size_t getTextCursor() const;
85 
86 
88  virtual void setCaption(const UString& _value);
90  virtual const UString& getCaption();
91 
93  void setOnlyText(const UString& _value);
95  UString getOnlyText();
96 
101  size_t getTextLength() const;
102 
104  void setOverflowToTheLeft(bool _value);
106  bool getOverflowToTheLeft() const;
107 
109  void setMaxTextLength(size_t _value);
111  size_t getMaxTextLength() const;
112 
114  void insertText(const UString& _text, size_t _index = ITEM_NONE);
116  void addText(const UString& _text);
118  void eraseText(size_t _start, size_t _count = 1);
119 
124  void setEditReadOnly(bool _value);
126  bool getEditReadOnly() const;
127 
132  void setEditPassword(bool _value);
134  bool getEditPassword() const;
135 
141  void setEditMultiLine(bool _value);
143  bool getEditMultiLine() const;
144 
149  void setEditStatic(bool _value);
151  bool getEditStatic() const;
152 
154  void setPasswordChar(Char _value);
156  void setPasswordChar(const UString& _char);
158  Char getPasswordChar() const;
159 
165  void setEditWordWrap(bool _value);
167  bool getEditWordWrap() const;
168 
174  void setTabPrinting(bool _value);
176  bool getTabPrinting() const;
177 
179  bool getInvertSelected();
183  void setInvertSelected(bool _value);
184 
186  virtual void setPosition(const IntPoint& _value);
188  virtual void setSize(const IntSize& _value);
190  virtual void setCoord(const IntCoord& _value);
191 
193  void setPosition(int _left, int _top);
195  void setSize(int _width, int _height);
197  void setCoord(int _left, int _top, int _width, int _height);
198 
200  void setVisibleVScroll(bool _value);
202  bool isVisibleVScroll() const;
209  size_t getVScrollRange() const;
211  size_t getVScrollPosition();
213  void setVScrollPosition(size_t _index);
214 
216  void setVisibleHScroll(bool _value);
218  bool isVisibleHScroll() const;
224  size_t getHScrollRange() const;
226  size_t getHScrollPosition();
228  void setHScrollPosition(size_t _index);
229 
230 
232  virtual void setFontName(const std::string& _value);
234  virtual void setFontHeight(int _value);
235 
237  virtual void setTextAlign(Align _value);
239  virtual void setTextColour(const Colour& _value);
240 
242  virtual IntCoord getTextRegion();
243 
245  virtual IntSize getTextSize();
246 
248  virtual void setTextShadowColour(const Colour& _value);
249 
251  virtual void setTextShadow(bool _value);
252 
253  /*events:*/
259  eventEditSelectAccept;
260 
265  EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr>
266  eventEditTextChange;
267 
268  protected:
269  virtual void initialiseOverride();
270  virtual void shutdownOverride();
271 
272  virtual void onMouseDrag(int _left, int _top, MouseButton _id);
273  virtual void onKeyLostFocus(Widget* _new);
274  virtual void onKeySetFocus(Widget* _old);
275  virtual void onKeyButtonPressed(KeyCode _key, Char _char);
276 
277  // потом убрать все нотифи в сраку
278  void notifyMouseSetFocus(Widget* _sender, Widget* _old);
279  void notifyMouseLostFocus(Widget* _sender, Widget* _new);
280  void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
281  void notifyMouseReleased(Widget* _sender, int _left, int _top, MouseButton _id);
282  void notifyMouseDrag(Widget* _sender, int _left, int _top, MouseButton _id);
283  void notifyMouseButtonDoubleClick(Widget* _sender);
284 
285  void notifyScrollChangePosition(ScrollBar* _sender, size_t _position);
286  void notifyMouseWheel(Widget* _sender, int _rel);
287 
288  // обновление представления
289  void updateView();
290  void updateViewWithCursor();
291 
292  void eraseView();
293 
294  virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
295 
296  private:
297  // устанавливает текст
298  void setText(const UString& _text, bool _history);
299  // удаляет все что выделенно
300  bool deleteTextSelect(bool _history);
301  // вставляет текст в указанную позицию
302  void insertText(const UString& _text, size_t _index, bool _history);
303  // удаляет текст
304  void eraseText(size_t _start, size_t _count, bool _history);
305  // выделяет цветом выделение
306  void setTextSelectColour(const Colour& _colour, bool _history);
307  // выделяет цветом диапазон
308  void _setTextColour(size_t _start, size_t _count, const Colour& _colour, bool _history);
309 
310  void frameEntered(float _frame);
311 
312  void updateEditState();
313 
314  // обновляет курсор по координате
315  void updateSelectText();
316 
317  void resetSelect();
318 
319  // запись в историю данных о позиции
320  void commandPosition(size_t _undo, size_t _redo, size_t _length, VectorChangeInfo* _info = nullptr);
321 
322  // команнды отмена и повтор
323  bool commandRedo();
324  bool commandUndo();
325  // объединяет последние две комманды
326  void commandMerge();
327  // очистка
328  void commandResetRedo();
329  void commandResetHistory();
330  void saveInHistory(VectorChangeInfo* _info = nullptr);
331 
332  // работа с буфером обмена
333  void commandCut();
334  void commandCopy();
335  void commandPast();
336 
337  const UString& getRealString();
338 
339  void setRealString(const UString& _caption);
340 
341  void updateCursorPosition();
342 
343  // размер данных
344  virtual IntSize getContentSize();
345  // смещение данных
346  virtual IntPoint getContentPosition();
347  virtual void setContentPosition(const IntPoint& _point);
348  // размер окна, через которые видно данные
349  virtual IntSize getViewSize();
350  // размер на который прокручиваются данные при щелчке по скролу
351  virtual size_t getVScrollPage();
352  virtual size_t getHScrollPage();
353 
354  virtual Align getContentAlign();
355 
356  protected:
357  // нажата ли кнопка
358  bool mIsPressed;
359  // в фокусе ли кнопка
360  bool mIsFocus;
361 
362  bool mCursorActive;
363  float mCursorTimer;
364  float mActionMouseTimer;
365 
366  // позиция курсора
367  size_t mCursorPosition;
368  // максимальное колличество
369  size_t mTextLength;
370 
371  // выделение
372  size_t mStartSelect;
373  size_t mEndSelect;
374 
375  // списоки изменений для отмены и повтора
376  DequeUndoRedoInfo mVectorUndoChangeInfo;
377  DequeUndoRedoInfo mVectorRedoChangeInfo;
378 
379  bool mMouseLeftPressed;
380 
381  bool mModeReadOnly;
382  bool mModePassword;
383  bool mModeMultiline;
384  bool mModeStatic;
385  bool mModeWordWrap;
386 
387  bool mTabPrinting;
388 
389  // настоящий текст, закрытый за звездочками
390  UString mPasswordText;
391 
392  // для поддержки режима статик, где курсор не нужен
393  std::string mOriginalPointer;
394 
395  Char mCharPassword;
396 
397  bool mOverflowToTheLeft;
398  size_t mMaxTextLength;
399 
400  ISubWidgetText* mClientText;
401  };
402 
403 } // namespace MyGUI
404 
405 #endif // __MYGUI_EDIT_BOX_H__
std::vector< TextCommandInfo > VectorChangeInfo
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:32
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:88
#define MYGUI_EXPORT
std::deque< VectorChangeInfo > DequeUndoRedoInfo
unsigned int Char
Definition: MyGUI_Types.h:66
delegates::CMultiDelegate1< EditBox * > EventHandle_EditPtr
Definition: MyGUI_EditBox.h:35
A UTF-16 string with implicit conversion to/from std::string and std::wstring.