MyGUI  3.0.1
MyGUI_Edit.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_EDIT_H__
24 #define __MYGUI_EDIT_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_StaticText.h"
29 #include "MyGUI_TextIterator.h"
30 #include "MyGUI_EventPair.h"
31 #include "MyGUI_ScrollViewBase.h"
32 
33 namespace MyGUI
34 {
35 
37 
39  public StaticText,
40  public ScrollViewBase
41  {
43 
44  public:
45  Edit();
46 
48  void setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour);
49 
51  size_t getTextSelectionStart();
52 
54  size_t getTextSelectionEnd();
55 
57  size_t getTextSelectionLength();
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();
77 
79  void setTextSelectionColour(const Colour& _value);
80 
82  void setTextCursor(size_t _index);
84  size_t getTextCursor() { return mCursorPosition; }
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 
100  size_t getTextLength() const { return mTextLength; }
101 
103  void setOverflowToTheLeft(bool _value) { mOverflowToTheLeft = _value; }
105  bool getOverflowToTheLeft() { return mOverflowToTheLeft; }
106 
108  void setMaxTextLength(size_t _value) { mMaxTextLength = _value; }
110  size_t getMaxTextLength() { return mMaxTextLength; }
111 
113  void insertText(const UString& _text, size_t _index = ITEM_NONE);
115  void addText(const UString& _text);
117  void eraseText(size_t _start, size_t _count = 1);
118 
123  void setEditReadOnly(bool _value);
125  bool getEditReadOnly() { return mModeReadOnly; }
126 
131  void setEditPassword(bool _value);
133  bool getEditPassword() { return mModePassword; }
134 
140  void setEditMultiLine(bool _value);
142  bool getEditMultiLine() { return mModeMultiline; }
143 
148  void setEditStatic(bool _value);
150  bool getEditStatic() { return mModeStatic; }
151 
153  void setPasswordChar(Char _value);
155  void setPasswordChar(const UString& _char);
157  Char getPasswordChar() { return mCharPassword; }
158 
164  void setEditWordWrap(bool _value);
166  bool getEditWordWrap() { return mModeWordWrap; }
167 
173  void setTabPrinting(bool _value) { mTabPrinting = _value; }
175  bool getTabPrinting() { return mTabPrinting; }
176 
178  bool getInvertSelected();
182  void setInvertSelected(bool _value);
183 
185  virtual void setPosition(const IntPoint& _value);
187  virtual void setSize(const IntSize& _value);
189  virtual void setCoord(const IntCoord& _value);
190 
192  void setPosition(int _left, int _top) { setPosition(IntPoint(_left, _top)); }
194  void setSize(int _width, int _height) { setSize(IntSize(_width, _height)); }
196  void setCoord(int _left, int _top, int _width, int _height) { setCoord(IntCoord(_left, _top, _width, _height)); }
197 
199  void setVisibleVScroll(bool _value);
201  bool isVisibleVScroll() { return mVisibleVScroll; }
208  size_t getVScrollRange();
210  size_t getVScrollPosition();
212  void setVScrollPosition(size_t _index);
213 
215  void setVisibleHScroll(bool _value);
217  bool isVisibleHScroll() { return mVisibleHScroll; }
223  size_t getHScrollRange();
225  size_t getHScrollPosition();
227  void setHScrollPosition(size_t _index);
228 
229 
231  virtual void setFontName(const std::string& _value);
233  virtual void setFontHeight(int _value);
234 
236  virtual void setTextAlign(Align _value);
237 
239  virtual void setProperty(const std::string& _key, const std::string& _value);
240 
241  /*event:*/
247 
253 
254  /*internal:*/
255  virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
256 
257  /*obsolete:*/
258 #ifndef MYGUI_DONT_USE_OBSOLETE
259 
260  MYGUI_OBSOLETE("use : void Edit::setVisibleVScroll(bool _visible)")
261  void showVScroll(bool _visible) { setVisibleVScroll(_visible); }
262  MYGUI_OBSOLETE("use : bool Edit::isVisibleVScroll()")
263  bool isShowVScroll() { return isVisibleVScroll(); }
264  MYGUI_OBSOLETE("use : void Edit::setVisibleHScroll(bool _visible)")
265  void showHScroll(bool _visible) { setVisibleHScroll(_visible); }
266  MYGUI_OBSOLETE("use : bool Edit::isVisibleHScroll()")
267  bool isShowHScroll() { return isVisibleHScroll(); }
268 
269  MYGUI_OBSOLETE("use : void Widget::setCoord(const IntCoord& _coord)")
270  void setPosition(const IntCoord& _coord) { setCoord(_coord); }
271  MYGUI_OBSOLETE("use : void Widget::setCoord(int _left, int _top, int _width, int _height)")
272  void setPosition(int _left, int _top, int _width, int _height) { setCoord(_left, _top, _width, _height); }
273 
274  // to avoid hiding base virtual function
275  virtual void setTextColour(const Colour& _colour) { Base::setTextColour(_colour); }
276 
277  MYGUI_OBSOLETE("use : void Edit::setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour)")
278  void setTextColour(size_t _start, size_t _count, const Colour& _colour) { setTextIntervalColour(_start, _count, _colour); }
279 
280  MYGUI_OBSOLETE("use : size_t Edit::getTextSelectionStart() , size_t getTextSelectionEnd()")
281  void getTextSelect(size_t& _start, size_t& _end);
282 
283  MYGUI_OBSOLETE("use : UString Edit::getTextInterval(size_t _start, size_t _count)")
284  UString getText(size_t _start, size_t _count) { return getTextInterval(_start, _count); }
285 
286  MYGUI_OBSOLETE("use : void Edit::setTextSelection(size_t _start, size_t _end)")
287  void setTextSelect(size_t _start, size_t _end) { setTextSelection(_start, _end); }
288 
289  MYGUI_OBSOLETE("use : void Edit::deleteTextSelection()")
290  void deleteTextSelect() { deleteTextSelection(); }
291 
292  MYGUI_OBSOLETE("use : UString Edit::getTextSelection()")
293  UString getSelectedText() { return getTextSelection(); }
294 
295  MYGUI_OBSOLETE("use : bool Edit::isTextSelection()")
296  bool isTextSelect() { return isTextSelection(); }
297 
298  MYGUI_OBSOLETE("use : void Edit::setTextSelectionColour(const Colour& _colour)")
299  void setTextSelectColour(const Colour& _colour) { setTextSelectionColour(_colour); }
300 
301 #endif // MYGUI_DONT_USE_OBSOLETE
302 
303 
304  protected:
305  virtual ~Edit();
306 
307  virtual void onMouseDrag(int _left, int _top);
308  virtual void onKeyLostFocus(Widget* _new);
309  virtual void onKeySetFocus(Widget* _old);
310  virtual void onKeyButtonPressed(KeyCode _key, Char _char);
311 
312  // потом убрать все нотифи в сраку
313  void notifyMouseSetFocus(Widget* _sender, Widget* _old);
314  void notifyMouseLostFocus(Widget* _sender, Widget* _new);
315  void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
316  void notifyMouseReleased(Widget* _sender, int _left, int _top, MouseButton _id);
317  void notifyMouseDrag(Widget* _sender, int _left, int _top);
318  void notifyMouseButtonDoubleClick(Widget* _sender);
319 
320  void notifyScrollChangePosition(VScroll* _sender, size_t _position);
321  void notifyMouseWheel(Widget* _sender, int _rel);
322 
323  // обновление представления
324  void updateView();
325  void updateViewWithCursor();
326 
327  void baseChangeWidgetSkin(ResourceSkin* _info);
328 
329  void eraseView();
330 
331  private:
332  void initialiseWidgetSkin(ResourceSkin* _info);
333  void shutdownWidgetSkin();
334 
335  private:
336  // устанавливает текст
337  void setText(const UString& _text, bool _history);
338  // удаляет все что выделенно
339  bool deleteTextSelect(bool _history);
340  // вставляет текст в указанную позицию
341  void insertText(const UString& _text, size_t _index, bool _history);
342  // удаляет текст
343  void eraseText(size_t _start, size_t _count, bool _history);
344  // выделяет цветом выделение
345  void setTextSelectColour(const Colour& _colour, bool _history);
346  // выделяет цветом диапазон
347  void _setTextColour(size_t _start, size_t _count, const Colour& _colour, bool _history);
348 
349  void frameEntered(float _frame);
350 
351  void updateEditState();
352 
353  // обновляет курсор по координате
354  void updateSelectText();
355 
356  void resetSelect();
357 
358  // запись в историю данных о позиции
359  void commandPosition(size_t _undo, size_t _redo, size_t _length, VectorChangeInfo * _info = nullptr);
360 
361  // команнды отмена и повтор
362  bool commandRedo();
363  bool commandUndo();
364  // объединяет последние две комманды
365  void commandMerge();
366  // очистка
367  void commandResetRedo() { mVectorRedoChangeInfo.clear(); }
368  void commandResetHistory() { mVectorRedoChangeInfo.clear();mVectorUndoChangeInfo.clear(); }
369  void saveInHistory(VectorChangeInfo * _info = nullptr);
370 
371  // работа с буфером обмена
372  void commandCut();
373  void commandCopy();
374  void commandPast();
375 
376  const UString& getRealString();
377 
378  void setRealString(const UString& _caption);
379 
380  void updateCursorPosition();
381 
382  // размер данных
383  virtual IntSize getContentSize();
384  // смещение данных
385  virtual IntPoint getContentPosition();
386  virtual void setContentPosition(const IntPoint& _point);
387  // размер окна, через которые видно данные
388  virtual IntSize getViewSize() const;
389  // размер на который прокручиваются данные при щелчке по скролу
390  virtual size_t getVScrollPage();
391  virtual size_t getHScrollPage();
392 
393  virtual Align getContentAlign();
394 
395  protected:
396  // нажата ли кнопка
398  // в фокусе ли кнопка
399  bool mIsFocus;
400 
404 
405  // позиция курсора
407  // максимальное колличество
408  size_t mTextLength;
409 
410  // выделение
411  size_t mStartSelect;
412  size_t mEndSelect;
413 
414  // списоки изменений для отмены и повтора
417 
419 
425 
427 
428  // настоящий текст, закрытый за звездочками
430 
431  // для поддержки режима статик, где курсор не нужен
432  std::string mOriginalPointer;
433 
435 
438 
439  };
440 
441 } // namespace MyGUI
442 
443 #endif // __MYGUI_EDIT_H__