MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #ifndef __MYGUI_EDIT_BOX_H__ 00008 #define __MYGUI_EDIT_BOX_H__ 00009 00010 #include "MyGUI_Prerequest.h" 00011 #include "MyGUI_TextBox.h" 00012 #include "MyGUI_TextChangeHistory.h" 00013 #include "MyGUI_TextIterator.h" 00014 #include "MyGUI_EventPair.h" 00015 #include "MyGUI_ScrollViewBase.h" 00016 00017 namespace MyGUI 00018 { 00019 00020 typedef delegates::CMultiDelegate1<EditBox*> EventHandle_EditPtr; 00021 00025 class MYGUI_EXPORT EditBox : 00026 public TextBox, 00027 public ScrollViewBase, 00028 public MemberObsolete<EditBox> 00029 { 00030 MYGUI_RTTI_DERIVED( EditBox ) 00031 00032 public: 00033 EditBox(); 00034 00036 void setTextIntervalColour(size_t _start, size_t _count, const Colour& _colour); 00037 00039 size_t getTextSelectionStart() const; 00040 00042 size_t getTextSelectionEnd() const; 00043 00045 size_t getTextSelectionLength() const; 00046 00047 // возвращает текст с тегами 00049 UString getTextInterval(size_t _start, size_t _count); 00050 00055 void setTextSelection(size_t _start, size_t _end); 00056 00058 void deleteTextSelection(); 00059 00061 UString getTextSelection(); 00062 00064 bool isTextSelection() const; 00065 00067 void setTextSelectionColour(const Colour& _value); 00068 00070 void setTextCursor(size_t _index); 00072 size_t getTextCursor() const; 00073 00074 00076 virtual void setCaption(const UString& _value); 00078 virtual const UString& getCaption(); 00079 00081 void setOnlyText(const UString& _value); 00083 UString getOnlyText(); 00084 00089 size_t getTextLength() const; 00090 00092 void setOverflowToTheLeft(bool _value); 00094 bool getOverflowToTheLeft() const; 00095 00097 void setMaxTextLength(size_t _value); 00099 size_t getMaxTextLength() const; 00100 00102 void insertText(const UString& _text, size_t _index = ITEM_NONE); 00104 void addText(const UString& _text); 00106 void eraseText(size_t _start, size_t _count = 1); 00107 00112 void setEditReadOnly(bool _value); 00114 bool getEditReadOnly() const; 00115 00120 void setEditPassword(bool _value); 00122 bool getEditPassword() const; 00123 00129 void setEditMultiLine(bool _value); 00131 bool getEditMultiLine() const; 00132 00137 void setEditStatic(bool _value); 00139 bool getEditStatic() const; 00140 00142 void setPasswordChar(Char _value); 00144 void setPasswordChar(const UString& _char); 00146 Char getPasswordChar() const; 00147 00153 void setEditWordWrap(bool _value); 00155 bool getEditWordWrap() const; 00156 00162 void setTabPrinting(bool _value); 00164 bool getTabPrinting() const; 00165 00167 bool getInvertSelected(); 00171 void setInvertSelected(bool _value); 00172 00174 virtual void setPosition(const IntPoint& _value); 00176 virtual void setSize(const IntSize& _value); 00178 virtual void setCoord(const IntCoord& _value); 00179 00181 void setPosition(int _left, int _top); 00183 void setSize(int _width, int _height); 00185 void setCoord(int _left, int _top, int _width, int _height); 00186 00188 void setVisibleVScroll(bool _value); 00190 bool isVisibleVScroll() const; 00197 size_t getVScrollRange() const; 00199 size_t getVScrollPosition(); 00201 void setVScrollPosition(size_t _index); 00202 00204 void setVisibleHScroll(bool _value); 00206 bool isVisibleHScroll() const; 00212 size_t getHScrollRange() const; 00214 size_t getHScrollPosition(); 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); 00227 virtual void setTextColour(const Colour& _value); 00228 00230 virtual IntCoord getTextRegion(); 00231 00233 virtual IntSize getTextSize(); 00234 00236 virtual void setTextShadowColour(const Colour& _value); 00237 00239 virtual void setTextShadow(bool _value); 00240 00241 /*events:*/ 00246 EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr> eventEditSelectAccept; 00247 00252 EventPair<EventHandle_WidgetVoid, EventHandle_EditPtr> eventEditTextChange; 00253 00254 protected: 00255 virtual void initialiseOverride(); 00256 virtual void shutdownOverride(); 00257 00258 virtual void onMouseDrag(int _left, int _top, MouseButton _id); 00259 virtual void onKeyLostFocus(Widget* _new); 00260 virtual void onKeySetFocus(Widget* _old); 00261 virtual void onKeyButtonPressed(KeyCode _key, Char _char); 00262 00263 // потом убрать все нотифи в сраку 00264 void notifyMouseSetFocus(Widget* _sender, Widget* _old); 00265 void notifyMouseLostFocus(Widget* _sender, Widget* _new); 00266 void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id); 00267 void notifyMouseReleased(Widget* _sender, int _left, int _top, MouseButton _id); 00268 void notifyMouseDrag(Widget* _sender, int _left, int _top, MouseButton _id); 00269 void notifyMouseButtonDoubleClick(Widget* _sender); 00270 00271 void notifyScrollChangePosition(ScrollBar* _sender, size_t _position); 00272 void notifyMouseWheel(Widget* _sender, int _rel); 00273 00274 // обновление представления 00275 void updateView(); 00276 void updateViewWithCursor(); 00277 00278 void eraseView(); 00279 00280 virtual void setPropertyOverride(const std::string& _key, const std::string& _value); 00281 00282 private: 00283 // устанавливает текст 00284 void setText(const UString& _text, bool _history); 00285 // удаляет все что выделенно 00286 bool deleteTextSelect(bool _history); 00287 // вставляет текст в указанную позицию 00288 void insertText(const UString& _text, size_t _index, bool _history); 00289 // удаляет текст 00290 void eraseText(size_t _start, size_t _count, bool _history); 00291 // выделяет цветом выделение 00292 void setTextSelectColour(const Colour& _colour, bool _history); 00293 // выделяет цветом диапазон 00294 void _setTextColour(size_t _start, size_t _count, const Colour& _colour, bool _history); 00295 00296 void frameEntered(float _frame); 00297 00298 void updateEditState(); 00299 00300 // обновляет курсор по координате 00301 void updateSelectText(); 00302 00303 void resetSelect(); 00304 00305 // запись в историю данных о позиции 00306 void commandPosition(size_t _undo, size_t _redo, size_t _length, VectorChangeInfo* _info = nullptr); 00307 00308 // команнды отмена и повтор 00309 bool commandRedo(); 00310 bool commandUndo(); 00311 // объединяет последние две комманды 00312 void commandMerge(); 00313 // очистка 00314 void commandResetRedo(); 00315 void commandResetHistory(); 00316 void saveInHistory(VectorChangeInfo* _info = nullptr); 00317 00318 // работа с буфером обмена 00319 void commandCut(); 00320 void commandCopy(); 00321 void commandPast(); 00322 00323 const UString& getRealString(); 00324 00325 void setRealString(const UString& _caption); 00326 00327 void updateCursorPosition(); 00328 00329 // размер данных 00330 virtual IntSize getContentSize(); 00331 // смещение данных 00332 virtual IntPoint getContentPosition(); 00333 virtual void setContentPosition(const IntPoint& _point); 00334 // размер окна, через которые видно данные 00335 virtual IntSize getViewSize(); 00336 // размер на который прокручиваются данные при щелчке по скролу 00337 virtual size_t getVScrollPage(); 00338 virtual size_t getHScrollPage(); 00339 00340 virtual Align getContentAlign(); 00341 00342 protected: 00343 // нажата ли кнопка 00344 bool mIsPressed; 00345 // в фокусе ли кнопка 00346 bool mIsFocus; 00347 00348 bool mCursorActive; 00349 float mCursorTimer; 00350 float mActionMouseTimer; 00351 00352 // позиция курсора 00353 size_t mCursorPosition; 00354 // максимальное колличество 00355 size_t mTextLength; 00356 00357 // выделение 00358 size_t mStartSelect; 00359 size_t mEndSelect; 00360 00361 // списоки изменений для отмены и повтора 00362 DequeUndoRedoInfo mVectorUndoChangeInfo; 00363 DequeUndoRedoInfo mVectorRedoChangeInfo; 00364 00365 bool mMouseLeftPressed; 00366 00367 bool mModeReadOnly; 00368 bool mModePassword; 00369 bool mModeMultiline; 00370 bool mModeStatic; 00371 bool mModeWordWrap; 00372 00373 bool mTabPrinting; 00374 00375 // настоящий текст, закрытый за звездочками 00376 UString mPasswordText; 00377 00378 // для поддержки режима статик, где курсор не нужен 00379 std::string mOriginalPointer; 00380 00381 Char mCharPassword; 00382 00383 bool mOverflowToTheLeft; 00384 size_t mMaxTextLength; 00385 00386 ISubWidgetText* mClientText; 00387 }; 00388 00389 } // namespace MyGUI 00390 00391 #endif // __MYGUI_EDIT_BOX_H__