MyGUI  3.2.0
MyGUI_EditBox.h
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #ifndef __MYGUI_EDIT_BOX_H__
00023 #define __MYGUI_EDIT_BOX_H__
00024 
00025 #include "MyGUI_Prerequest.h"
00026 #include "MyGUI_TextBox.h"
00027 #include "MyGUI_TextChangeHistory.h"
00028 #include "MyGUI_TextIterator.h"
00029 #include "MyGUI_EventPair.h"
00030 #include "MyGUI_ScrollViewBase.h"
00031 
00032 namespace MyGUI
00033 {
00034 
00035     typedef delegates::CMultiDelegate1<EditBox*> EventHandle_EditPtr;
00036 
00037     class MYGUI_EXPORT EditBox :
00038         public TextBox,
00039         public ScrollViewBase,
00040         public MemberObsolete<EditBox>
00041     {
00042         MYGUI_RTTI_DERIVED( EditBox )
00043 
00044     public:
00045         EditBox();
00046 
00048         void setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour);
00049 
00051         size_t getTextSelectionStart() const;
00052 
00054         size_t getTextSelectionEnd() const;
00055 
00057         size_t getTextSelectionLength() const;
00058 
00059         // возвращает текст с тегами
00061         UString getTextInterval(size_t _start, size_t _count);
00062 
00067         void setTextSelection(size_t _start, size_t _end);
00068 
00070         void deleteTextSelection();
00071 
00073         UString getTextSelection();
00074 
00076         bool isTextSelection() const;
00077 
00079         void setTextSelectionColour(const Colour& _value);
00080 
00082         void setTextCursor(size_t _index);
00084         size_t getTextCursor() const;
00085 
00086 
00088         virtual void setCaption(const UString& _value);
00090         virtual const UString& getCaption();
00091 
00093         void setOnlyText(const UString& _value);
00095         UString getOnlyText();
00096 
00101         size_t getTextLength() const;
00102 
00104         void setOverflowToTheLeft(bool _value);
00106         bool getOverflowToTheLeft() const;
00107 
00109         void setMaxTextLength(size_t _value);
00111         size_t getMaxTextLength() const;
00112 
00114         void insertText(const UString& _text, size_t _index = ITEM_NONE);
00116         void addText(const UString& _text);
00118         void eraseText(size_t _start, size_t _count = 1);
00119 
00124         void setEditReadOnly(bool _value);
00126         bool getEditReadOnly() const;
00127 
00132         void setEditPassword(bool _value);
00134         bool getEditPassword() const;
00135 
00141         void setEditMultiLine(bool _value);
00143         bool getEditMultiLine() const;
00144 
00149         void setEditStatic(bool _value);
00151         bool getEditStatic() const;
00152 
00154         void setPasswordChar(Char _value);
00156         void setPasswordChar(const UString& _char);
00158         Char getPasswordChar() const;
00159 
00165         void setEditWordWrap(bool _value);
00167         bool getEditWordWrap() const;
00168 
00174         void setTabPrinting(bool _value);
00176         bool getTabPrinting() const;
00177 
00179         bool getInvertSelected();
00183         void setInvertSelected(bool _value);
00184 
00186         virtual void setPosition(const IntPoint& _value);
00188         virtual void setSize(const IntSize& _value);
00190         virtual void setCoord(const IntCoord& _value);
00191 
00193         void setPosition(int _left, int _top);
00195         void setSize(int _width, int _height);
00197         void setCoord(int _left, int _top, int _width, int _height);
00198 
00200         void setVisibleVScroll(bool _value);
00202         bool isVisibleVScroll() const;
00209         size_t getVScrollRange() const;
00211         size_t getVScrollPosition();
00213         void setVScrollPosition(size_t _index);
00214 
00216         void setVisibleHScroll(bool _value);
00218         bool isVisibleHScroll() const;
00224         size_t getHScrollRange() const;
00226         size_t getHScrollPosition();
00228         void setHScrollPosition(size_t _index);
00229 
00230 
00232         virtual void setFontName(const std::string& _value);
00234         virtual void setFontHeight(int _value);
00235 
00237         virtual void setTextAlign(Align _value);
00239         virtual void setTextColour(const Colour& _value);
00240 
00242         virtual IntCoord getTextRegion();
00243 
00245         virtual IntSize getTextSize();
00246 
00248         virtual void setTextShadowColour(const Colour& _value);
00249 
00251         virtual void setTextShadow(bool _value);
00252 
00253     /*events:*/
00258         EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr>
00259             eventEditSelectAccept;
00260 
00265         EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr>
00266             eventEditTextChange;
00267 
00268     protected:
00269         virtual void initialiseOverride();
00270         virtual void shutdownOverride();
00271 
00272         virtual void onMouseDrag(int _left, int _top, MouseButton _id);
00273         virtual void onKeyLostFocus(Widget* _new);
00274         virtual void onKeySetFocus(Widget* _old);
00275         virtual void onKeyButtonPressed(KeyCode _key, Char _char);
00276 
00277         // потом убрать все нотифи в сраку
00278         void notifyMouseSetFocus(Widget* _sender, Widget* _old);
00279         void notifyMouseLostFocus(Widget* _sender, Widget* _new);
00280         void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
00281         void notifyMouseReleased(Widget* _sender, int _left, int _top, MouseButton _id);
00282         void notifyMouseDrag(Widget* _sender, int _left, int _top, MouseButton _id);
00283         void notifyMouseButtonDoubleClick(Widget* _sender);
00284 
00285         void notifyScrollChangePosition(ScrollBar* _sender, size_t _position);
00286         void notifyMouseWheel(Widget* _sender, int _rel);
00287 
00288         // обновление представления
00289         void updateView();
00290         void updateViewWithCursor();
00291 
00292         void eraseView();
00293 
00294         virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
00295 
00296     private:
00297         // устанавливает текст
00298         void setText(const UString& _text, bool _history);
00299         // удаляет все что выделенно
00300         bool deleteTextSelect(bool _history);
00301         // вставляет текст в указанную позицию
00302         void insertText(const UString& _text, size_t _index, bool _history);
00303         // удаляет текст
00304         void eraseText(size_t _start, size_t _count, bool _history);
00305         // выделяет цветом выделение
00306         void setTextSelectColour(const Colour& _colour, bool _history);
00307         // выделяет цветом диапазон
00308         void _setTextColour(size_t _start, size_t _count, const Colour& _colour, bool _history);
00309 
00310         void frameEntered(float _frame);
00311 
00312         void updateEditState();
00313 
00314         // обновляет курсор по координате
00315         void updateSelectText();
00316 
00317         void resetSelect();
00318 
00319         // запись в историю данных о позиции
00320         void commandPosition(size_t _undo, size_t _redo, size_t _length, VectorChangeInfo* _info = nullptr);
00321 
00322         // команнды отмена и повтор
00323         bool commandRedo();
00324         bool commandUndo();
00325         // объединяет последние две комманды
00326         void commandMerge();
00327         // очистка
00328         void commandResetRedo();
00329         void commandResetHistory();
00330         void saveInHistory(VectorChangeInfo* _info = nullptr);
00331 
00332         // работа с буфером обмена
00333         void commandCut();
00334         void commandCopy();
00335         void commandPast();
00336 
00337         const UString& getRealString();
00338 
00339         void setRealString(const UString& _caption);
00340 
00341         void updateCursorPosition();
00342 
00343         // размер данных
00344         virtual IntSize getContentSize();
00345         // смещение данных
00346         virtual IntPoint getContentPosition();
00347         virtual void setContentPosition(const IntPoint& _point);
00348         // размер окна, через которые видно данные
00349         virtual IntSize getViewSize();
00350         // размер на который прокручиваются данные при щелчке по скролу
00351         virtual size_t getVScrollPage();
00352         virtual size_t getHScrollPage();
00353 
00354         virtual Align getContentAlign();
00355 
00356     protected:
00357         // нажата ли кнопка
00358         bool mIsPressed;
00359         // в фокусе ли кнопка
00360         bool mIsFocus;
00361 
00362         bool mCursorActive;
00363         float mCursorTimer;
00364         float mActionMouseTimer;
00365 
00366         // позиция курсора
00367         size_t mCursorPosition;
00368         // максимальное колличество
00369         size_t mTextLength;
00370 
00371         // выделение
00372         size_t mStartSelect;
00373         size_t mEndSelect;
00374 
00375         // списоки изменений для отмены и повтора
00376         DequeUndoRedoInfo mVectorUndoChangeInfo;
00377         DequeUndoRedoInfo mVectorRedoChangeInfo;
00378 
00379         bool mMouseLeftPressed;
00380 
00381         bool mModeReadOnly;
00382         bool mModePassword;
00383         bool mModeMultiline;
00384         bool mModeStatic;
00385         bool mModeWordWrap;
00386 
00387         bool mTabPrinting;
00388 
00389         // настоящий текст, закрытый за звездочками
00390         UString mPasswordText;
00391 
00392         // для поддержки режима статик, где курсор не нужен
00393         std::string mOriginalPointer;
00394 
00395         Char mCharPassword;
00396 
00397         bool mOverflowToTheLeft;
00398         size_t mMaxTextLength;
00399 
00400         ISubWidgetText* mClientText;
00401     };
00402 
00403 } // namespace MyGUI
00404 
00405 #endif // __MYGUI_EDIT_BOX_H__