00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00246 EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr> eventEditSelectAccept;
00247
00252 EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr> eventEditTextChange;
00253
00254
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
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
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 }
00442
00443 #endif // __MYGUI_EDIT_H__