MyGUI  3.0.1
MyGUI_Edit.h
Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #ifndef __MYGUI_EDIT_H__
00024 #define __MYGUI_EDIT_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_StaticText.h"
00028 #include "MyGUI_TextChangeHistory.h"
00029 #include "MyGUI_TextIterator.h"
00030 #include "MyGUI_EventPair.h"
00031 #include "MyGUI_ScrollViewBase.h"
00032 
00033 namespace MyGUI
00034 {
00035 
00036     typedef delegates::CDelegate1<Edit*> EventHandle_EditPtr;
00037 
00038     class MYGUI_EXPORT Edit :
00039         public StaticText,
00040         public ScrollViewBase
00041     {
00042         MYGUI_RTTI_DERIVED( Edit )
00043 
00044     public:
00045         Edit();
00046 
00048         void setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour);
00049 
00051         size_t getTextSelectionStart();
00052 
00054         size_t getTextSelectionEnd();
00055 
00057         size_t getTextSelectionLength();
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();
00077 
00079         void setTextSelectionColour(const Colour& _value);
00080 
00082         void setTextCursor(size_t _index);
00084         size_t getTextCursor() { return mCursorPosition; }
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 
00100         size_t getTextLength() const { return mTextLength; }
00101 
00103         void setOverflowToTheLeft(bool _value) { mOverflowToTheLeft = _value; }
00105         bool getOverflowToTheLeft() { return mOverflowToTheLeft; }
00106 
00108         void setMaxTextLength(size_t _value) { mMaxTextLength = _value; }
00110         size_t getMaxTextLength() { return mMaxTextLength; }
00111 
00113         void insertText(const UString& _text, size_t _index = ITEM_NONE);
00115         void addText(const UString& _text);
00117         void eraseText(size_t _start, size_t _count = 1);
00118 
00123         void setEditReadOnly(bool _value);
00125         bool getEditReadOnly() { return mModeReadOnly; }
00126 
00131         void setEditPassword(bool _value);
00133         bool getEditPassword() { return mModePassword; }
00134 
00140         void setEditMultiLine(bool _value);
00142         bool getEditMultiLine() { return mModeMultiline; }
00143 
00148         void setEditStatic(bool _value);
00150         bool getEditStatic() { return mModeStatic; }
00151 
00153         void setPasswordChar(Char _value);
00155         void setPasswordChar(const UString& _char);
00157         Char getPasswordChar() { return mCharPassword; }
00158 
00164         void setEditWordWrap(bool _value);
00166         bool getEditWordWrap() { return mModeWordWrap; }
00167 
00173         void setTabPrinting(bool _value) { mTabPrinting = _value; }
00175         bool getTabPrinting() { return mTabPrinting; }
00176 
00178         bool getInvertSelected();
00182         void setInvertSelected(bool _value);
00183 
00185         virtual void setPosition(const IntPoint& _value);
00187         virtual void setSize(const IntSize& _value);
00189         virtual void setCoord(const IntCoord& _value);
00190 
00192         void setPosition(int _left, int _top) { setPosition(IntPoint(_left, _top)); }
00194         void setSize(int _width, int _height) { setSize(IntSize(_width, _height)); }
00196         void setCoord(int _left, int _top, int _width, int _height) { setCoord(IntCoord(_left, _top, _width, _height)); }
00197 
00199         void setVisibleVScroll(bool _value);
00201         bool isVisibleVScroll() { return mVisibleVScroll; }
00208         size_t getVScrollRange();
00210         size_t getVScrollPosition();
00212         void setVScrollPosition(size_t _index);
00213 
00215         void setVisibleHScroll(bool _value);
00217         bool isVisibleHScroll() { return mVisibleHScroll; }
00223         size_t getHScrollRange();
00225         size_t getHScrollPosition();
00227         void setHScrollPosition(size_t _index);
00228 
00229 
00231         virtual void setFontName(const std::string& _value);
00233         virtual void setFontHeight(int _value);
00234 
00236         virtual void setTextAlign(Align _value);
00237 
00239         virtual void setProperty(const std::string& _key, const std::string& _value);
00240 
00241     /*event:*/
00246         EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr> eventEditSelectAccept;
00247 
00252         EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr> eventEditTextChange;
00253 
00254     /*internal:*/
00255         virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
00256 
00257     /*obsolete:*/
00258 #ifndef MYGUI_DONT_USE_OBSOLETE
00259 
00260         MYGUI_OBSOLETE("use : void Edit::setVisibleVScroll(bool _visible)")
00261         void showVScroll(bool _visible) { setVisibleVScroll(_visible); }
00262         MYGUI_OBSOLETE("use : bool Edit::isVisibleVScroll()")
00263         bool isShowVScroll() { return isVisibleVScroll(); }
00264         MYGUI_OBSOLETE("use : void Edit::setVisibleHScroll(bool _visible)")
00265         void showHScroll(bool _visible) { setVisibleHScroll(_visible); }
00266         MYGUI_OBSOLETE("use : bool Edit::isVisibleHScroll()")
00267         bool isShowHScroll() { return isVisibleHScroll(); }
00268 
00269         MYGUI_OBSOLETE("use : void Widget::setCoord(const IntCoord& _coord)")
00270         void setPosition(const IntCoord& _coord) { setCoord(_coord); }
00271         MYGUI_OBSOLETE("use : void Widget::setCoord(int _left, int _top, int _width, int _height)")
00272         void setPosition(int _left, int _top, int _width, int _height) { setCoord(_left, _top, _width, _height); }
00273 
00274         // to avoid hiding base virtual function
00275         virtual void setTextColour(const Colour& _colour) { Base::setTextColour(_colour); }
00276 
00277         MYGUI_OBSOLETE("use : void Edit::setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour)")
00278         void setTextColour(size_t _start, size_t _count, const Colour& _colour) { setTextIntervalColour(_start, _count, _colour); }
00279 
00280         MYGUI_OBSOLETE("use : size_t Edit::getTextSelectionStart() , size_t getTextSelectionEnd()")
00281         void getTextSelect(size_t& _start, size_t& _end);
00282 
00283         MYGUI_OBSOLETE("use : UString Edit::getTextInterval(size_t _start, size_t _count)")
00284         UString getText(size_t _start, size_t _count) { return getTextInterval(_start, _count); }
00285 
00286         MYGUI_OBSOLETE("use : void Edit::setTextSelection(size_t _start, size_t _end)")
00287         void setTextSelect(size_t _start, size_t _end) { setTextSelection(_start, _end); }
00288 
00289         MYGUI_OBSOLETE("use : void Edit::deleteTextSelection()")
00290         void deleteTextSelect() { deleteTextSelection(); }
00291 
00292         MYGUI_OBSOLETE("use : UString Edit::getTextSelection()")
00293         UString getSelectedText() { return getTextSelection(); }
00294 
00295         MYGUI_OBSOLETE("use : bool Edit::isTextSelection()")
00296         bool isTextSelect() { return isTextSelection(); }
00297 
00298         MYGUI_OBSOLETE("use : void Edit::setTextSelectionColour(const Colour& _colour)")
00299         void setTextSelectColour(const Colour& _colour) { setTextSelectionColour(_colour); }
00300 
00301 #endif // MYGUI_DONT_USE_OBSOLETE
00302 
00303 
00304     protected:
00305         virtual ~Edit();
00306 
00307         virtual void onMouseDrag(int _left, int _top);
00308         virtual void onKeyLostFocus(Widget* _new);
00309         virtual void onKeySetFocus(Widget* _old);
00310         virtual void onKeyButtonPressed(KeyCode _key, Char _char);
00311 
00312         // потом убрать все нотифи в сраку
00313         void notifyMouseSetFocus(Widget* _sender, Widget* _old);
00314         void notifyMouseLostFocus(Widget* _sender, Widget* _new);
00315         void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
00316         void notifyMouseReleased(Widget* _sender, int _left, int _top, MouseButton _id);
00317         void notifyMouseDrag(Widget* _sender, int _left, int _top);
00318         void notifyMouseButtonDoubleClick(Widget* _sender);
00319 
00320         void notifyScrollChangePosition(VScroll* _sender, size_t _position);
00321         void notifyMouseWheel(Widget* _sender, int _rel);
00322 
00323         // обновление представления
00324         void updateView();
00325         void updateViewWithCursor();
00326 
00327         void baseChangeWidgetSkin(ResourceSkin* _info);
00328 
00329         void eraseView();
00330 
00331     private:
00332         void initialiseWidgetSkin(ResourceSkin* _info);
00333         void shutdownWidgetSkin();
00334 
00335     private:
00336         // устанавливает текст
00337         void setText(const UString& _text, bool _history);
00338         // удаляет все что выделенно
00339         bool deleteTextSelect(bool _history);
00340         // вставляет текст в указанную позицию
00341         void insertText(const UString& _text, size_t _index, bool _history);
00342         // удаляет текст
00343         void eraseText(size_t _start, size_t _count, bool _history);
00344         // выделяет цветом выделение
00345         void setTextSelectColour(const Colour& _colour, bool _history);
00346         // выделяет цветом диапазон
00347         void _setTextColour(size_t _start, size_t _count, const Colour& _colour, bool _history);
00348 
00349         void frameEntered(float _frame);
00350 
00351         void updateEditState();
00352 
00353         // обновляет курсор по координате
00354         void updateSelectText();
00355 
00356         void resetSelect();
00357 
00358         // запись в историю данных о позиции
00359         void commandPosition(size_t _undo, size_t _redo, size_t _length, VectorChangeInfo * _info = nullptr);
00360 
00361         // команнды отмена и повтор
00362         bool commandRedo();
00363         bool commandUndo();
00364         // объединяет последние две комманды
00365         void commandMerge();
00366         // очистка
00367         void commandResetRedo() { mVectorRedoChangeInfo.clear(); }
00368         void commandResetHistory() { mVectorRedoChangeInfo.clear();mVectorUndoChangeInfo.clear(); }
00369         void saveInHistory(VectorChangeInfo * _info = nullptr);
00370 
00371         // работа с буфером обмена
00372         void commandCut();
00373         void commandCopy();
00374         void commandPast();
00375 
00376         const UString& getRealString();
00377 
00378         void setRealString(const UString& _caption);
00379 
00380         void updateCursorPosition();
00381 
00382         // размер данных
00383         virtual IntSize getContentSize();
00384         // смещение данных
00385         virtual IntPoint getContentPosition();
00386         virtual void setContentPosition(const IntPoint& _point);
00387         // размер окна, через которые видно данные
00388         virtual IntSize getViewSize() const;
00389         // размер на который прокручиваются данные при щелчке по скролу
00390         virtual size_t getVScrollPage();
00391         virtual size_t getHScrollPage();
00392 
00393         virtual Align getContentAlign();
00394 
00395     protected:
00396         // нажата ли кнопка
00397         bool mIsPressed;
00398         // в фокусе ли кнопка
00399         bool mIsFocus;
00400 
00401         bool mCursorActive;
00402         float mCursorTimer;
00403         float mActionMouseTimer;
00404 
00405         // позиция курсора
00406         size_t mCursorPosition;
00407         // максимальное колличество
00408         size_t mTextLength;
00409 
00410         // выделение
00411         size_t mStartSelect;
00412         size_t mEndSelect;
00413 
00414         // списоки изменений для отмены и повтора
00415         DequeUndoRedoInfo mVectorUndoChangeInfo;
00416         DequeUndoRedoInfo mVectorRedoChangeInfo;
00417 
00418         bool mMouseLeftPressed;
00419 
00420         bool mModeReadOnly;
00421         bool mModePassword;
00422         bool mModeMultiline;
00423         bool mModeStatic;
00424         bool mModeWordWrap;
00425 
00426         bool mTabPrinting;
00427 
00428         // настоящий текст, закрытый за звездочками
00429         UString mPasswordText;
00430 
00431         // для поддержки режима статик, где курсор не нужен
00432         std::string mOriginalPointer;
00433 
00434         Char mCharPassword;
00435 
00436         bool mOverflowToTheLeft;
00437         size_t mMaxTextLength;
00438 
00439     };
00440 
00441 } // namespace MyGUI
00442 
00443 #endif // __MYGUI_EDIT_H__