• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

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<EditPtr> 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() { 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 
00177         //DESCRIBEME
00178         bool getInvertSelected();
00179         //DESCRIBEME
00180         void setInvertSelected(bool _value);
00181 
00183         virtual void setPosition(const IntPoint& _value);
00185         virtual void setSize(const IntSize& _value);
00187         virtual void setCoord(const IntCoord& _value);
00188 
00190         void setPosition(int _left, int _top) { setPosition(IntPoint(_left, _top)); }
00192         void setSize(int _width, int _height) { setSize(IntSize(_width, _height)); }
00194         void setCoord(int _left, int _top, int _width, int _height) { setCoord(IntCoord(_left, _top, _width, _height)); }
00195 
00197         void setVisibleVScroll(bool _value);
00199         bool isVisibleVScroll() { return mVisibleVScroll; }
00200         //DESCRIBEME
00201         size_t getVScrollRange();
00202         //DESCRIBEME
00203         size_t getVScrollPosition();
00204         //DESCRIBEME
00205         void setVScrollPosition(size_t _index);
00206 
00208         void setVisibleHScroll(bool _value);
00210         bool isVisibleHScroll() { return mVisibleHScroll; }
00211         //DESCRIBEME
00212         size_t getHScrollRange();
00213         //DESCRIBEME
00214         size_t getHScrollPosition();
00215         //DESCRIBEME
00216         void setHScrollPosition(size_t _index);
00217 
00218 
00220         virtual void setFontName(const std::string& _value);
00222         virtual void setFontHeight(int _value);
00223 
00225         virtual void setTextAlign(Align _value);
00226 
00228         virtual void setProperty(const std::string& _key, const std::string& _value);
00229 
00230     /*event:*/
00235         EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr> eventEditSelectAccept;
00236 
00241         EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr> eventEditTextChange;
00242 
00243     /*internal:*/
00244         virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, WidgetPtr _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
00245 
00246     /*obsolete:*/
00247 #ifndef MYGUI_DONT_USE_OBSOLETE
00248 
00249         MYGUI_OBSOLETE("use : void Edit::setVisibleVScroll(bool _visible)")
00250         void showVScroll(bool _visible) { setVisibleVScroll(_visible); }
00251         MYGUI_OBSOLETE("use : bool Edit::isVisibleVScroll()")
00252         bool isShowVScroll() { return isVisibleVScroll(); }
00253         MYGUI_OBSOLETE("use : void Edit::setVisibleHScroll(bool _visible)")
00254         void showHScroll(bool _visible) { setVisibleHScroll(_visible); }
00255         MYGUI_OBSOLETE("use : bool Edit::isVisibleHScroll()")
00256         bool isShowHScroll() { return isVisibleHScroll(); }
00257 
00258         MYGUI_OBSOLETE("use : void Widget::setCoord(const IntCoord& _coord)")
00259         void setPosition(const IntCoord& _coord) { setCoord(_coord); }
00260         MYGUI_OBSOLETE("use : void Widget::setCoord(int _left, int _top, int _width, int _height)")
00261         void setPosition(int _left, int _top, int _width, int _height) { setCoord(_left, _top, _width, _height); }
00262 
00263         // to avoid hiding base virtual function
00264         virtual void setTextColour(const Colour& _colour) { Base::setTextColour(_colour); }
00265 
00266         MYGUI_OBSOLETE("use : void Edit::setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour)")
00267         void setTextColour(size_t _start, size_t _count, const Colour& _colour) { setTextIntervalColour(_start, _count, _colour); }
00268 
00269         MYGUI_OBSOLETE("use : size_t Edit::getTextSelectionStart() , size_t getTextSelectionEnd()")
00270         void getTextSelect(size_t& _start, size_t& _end);
00271 
00272         MYGUI_OBSOLETE("use : UString Edit::getTextInterval(size_t _start, size_t _count)")
00273         UString getText(size_t _start, size_t _count) { return getTextInterval(_start, _count); }
00274 
00275         MYGUI_OBSOLETE("use : void Edit::setTextSelection(size_t _start, size_t _end)")
00276         void setTextSelect(size_t _start, size_t _end) { setTextSelection(_start, _end); }
00277 
00278         MYGUI_OBSOLETE("use : void Edit::deleteTextSelection()")
00279         void deleteTextSelect() { deleteTextSelection(); }
00280 
00281         MYGUI_OBSOLETE("use : UString Edit::getTextSelection()")
00282         UString getSelectedText() { return getTextSelection(); }
00283 
00284         MYGUI_OBSOLETE("use : bool Edit::isTextSelection()")
00285         bool isTextSelect() { return isTextSelection(); }
00286 
00287         MYGUI_OBSOLETE("use : void Edit::setTextSelectionColour(const Colour& _colour)")
00288         void setTextSelectColour(const Colour& _colour) { setTextSelectionColour(_colour); }
00289 
00290 #endif // MYGUI_DONT_USE_OBSOLETE
00291 
00292 
00293     protected:
00294         virtual ~Edit();
00295 
00296         virtual void onMouseDrag(int _left, int _top);
00297         virtual void onKeyLostFocus(WidgetPtr _new);
00298         virtual void onKeySetFocus(WidgetPtr _old);
00299         virtual void onKeyButtonPressed(KeyCode _key, Char _char);
00300 
00301         // потом убрать все нотифи в сраку
00302         void notifyMouseSetFocus(WidgetPtr _sender, WidgetPtr _old);
00303         void notifyMouseLostFocus(WidgetPtr _sender, WidgetPtr _new);
00304         void notifyMousePressed(WidgetPtr _sender, int _left, int _top, MouseButton _id);
00305         void notifyMouseReleased(WidgetPtr _sender, int _left, int _top, MouseButton _id);
00306         void notifyMouseDrag(WidgetPtr _sender, int _left, int _top);
00307         void notifyMouseButtonDoubleClick(WidgetPtr _sender);
00308 
00309         void notifyScrollChangePosition(VScrollPtr _sender, size_t _position);
00310         void notifyMouseWheel(WidgetPtr _sender, int _rel);
00311 
00312         // обновление представления
00313         void updateView();
00314         void updateViewWithCursor();
00315 
00316         void baseChangeWidgetSkin(ResourceSkin* _info);
00317 
00318         void eraseView();
00319 
00320     private:
00321         void initialiseWidgetSkin(ResourceSkin* _info);
00322         void shutdownWidgetSkin();
00323 
00324     private:
00325         // устанавливает текст
00326         void setText(const UString& _text, bool _history);
00327         // удаляет все что выделенно
00328         bool deleteTextSelect(bool _history);
00329         // вставляет текст в указанную позицию
00330         void insertText(const UString& _text, size_t _index, bool _history);
00331         // удаляет текст
00332         void eraseText(size_t _start, size_t _count, bool _history);
00333         // выделяет цветом выделение
00334         void setTextSelectColour(const Colour& _colour, bool _history);
00335         // выделяет цветом диапазон
00336         void _setTextColour(size_t _start, size_t _count, const Colour& _colour, bool _history);
00337 
00338         void frameEntered(float _frame);
00339 
00340         void updateEditState();
00341 
00342         // обновляет курсор по координате
00343         void updateSelectText();
00344 
00345         void resetSelect();
00346 
00347         // запись в историю данных о позиции
00348         void commandPosition(size_t _undo, size_t _redo, size_t _length, VectorChangeInfo * _info = nullptr);
00349 
00350         // команнды отмена и повтор
00351         bool commandRedo();
00352         bool commandUndo();
00353         // объединяет последние две комманды
00354         void commandMerge();
00355         // очистка
00356         void commandResetRedo() { mVectorRedoChangeInfo.clear(); }
00357         void commandResetHistory() { mVectorRedoChangeInfo.clear();mVectorUndoChangeInfo.clear(); }
00358         void saveInHistory(VectorChangeInfo * _info = nullptr);
00359 
00360         // работа с буфером обмена
00361         void commandCut();
00362         void commandCopy();
00363         void commandPast();
00364 
00365         const UString& getRealString();
00366 
00367         void setRealString(const UString& _caption);
00368 
00369         void updateCursorPosition();
00370 
00371         // размер данных
00372         virtual IntSize getContentSize();
00373         // смещение данных
00374         virtual IntPoint getContentPosition();
00375         virtual void setContentPosition(const IntPoint& _point);
00376         // размер окна, через которые видно данные
00377         virtual IntSize getViewSize();
00378         // размер на который прокручиваются данные при щелчке по скролу
00379         virtual size_t getVScrollPage();
00380         virtual size_t getHScrollPage();
00381 
00382         virtual Align getContentAlign();
00383 
00384     protected:
00385         // нажата ли кнопка
00386         bool mIsPressed;
00387         // в фокусе ли кнопка
00388         bool mIsFocus;
00389 
00390         bool mCursorActive;
00391         float mCursorTimer;
00392         float mActionMouseTimer;
00393 
00394         // позиция курсора
00395         size_t mCursorPosition;
00396         // максимальное колличество
00397         size_t mTextLength;
00398 
00399         // выделение
00400         size_t mStartSelect;
00401         size_t mEndSelect;
00402 
00403         // списоки изменений для отмены и повтора
00404         DequeUndoRedoInfo mVectorUndoChangeInfo;
00405         DequeUndoRedoInfo mVectorRedoChangeInfo;
00406 
00407         bool mMouseLeftPressed;
00408 
00409         bool mModeReadOnly;
00410         bool mModePassword;
00411         bool mModeMultiline;
00412         bool mModeStatic;
00413         bool mModeWordWrap;
00414 
00415         bool mTabPrinting;
00416 
00417         // настоящий текст, закрытый за звездочками
00418         UString mPasswordText;
00419 
00420         // для поддержки режима статик, где курсор не нужен
00421         std::string mOriginalPointer;
00422 
00423         Char mCharPassword;
00424 
00425         bool mOverflowToTheLeft;
00426         size_t mMaxTextLength;
00427 
00428     };
00429 
00430 } // namespace MyGUI
00431 
00432 #endif // __MYGUI_EDIT_H__

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1