guiTextEditCtrl.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUITEXTEDITCTRL_H_
  23. #define _GUITEXTEDITCTRL_H_
  24. #ifndef _GUITYPES_H_
  25. #include "gui/core/guiTypes.h"
  26. #endif
  27. #ifndef _GUITEXTCTRL_H_
  28. #include "gui/controls/guiTextCtrl.h"
  29. #endif
  30. #ifndef _STRINGBUFFER_H_
  31. #include "core/stringBuffer.h"
  32. #endif
  33. class SFXTrack;
  34. class GuiTextEditCtrl : public GuiTextCtrl
  35. {
  36. private:
  37. typedef GuiTextCtrl Parent;
  38. protected:
  39. DECLARE_CALLBACK( void, onTabComplete, (const char* val));
  40. DECLARE_CALLBACK( void, onReturn, ());
  41. DECLARE_CALLBACK( void, onValidate, ());
  42. StringBuffer mTextBuffer;
  43. String mValidateCommand;
  44. String mEscapeCommand;
  45. SFXTrack* mDeniedSound;
  46. // for animating the cursor
  47. S32 mNumFramesElapsed;
  48. U32 mTimeLastCursorFlipped;
  49. ColorI mCursorColor;
  50. bool mCursorOn;
  51. bool mInsertOn;
  52. S32 mMouseDragStart;
  53. Point2I mTextOffset;
  54. bool mTextOffsetReset;
  55. bool mDragHit;
  56. bool mTabComplete;
  57. S32 mScrollDir;
  58. //undo members
  59. StringBuffer mUndoText;
  60. S32 mUndoBlockStart;
  61. S32 mUndoBlockEnd;
  62. S32 mUndoCursorPos;
  63. void saveUndoState();
  64. S32 mBlockStart;
  65. S32 mBlockEnd;
  66. S32 mCursorPos;
  67. virtual S32 calculateCursorPos( const Point2I &globalPos );
  68. bool mHistoryDirty;
  69. S32 mHistoryLast;
  70. S32 mHistoryIndex;
  71. S32 mHistorySize;
  72. bool mPasswordText;
  73. StringTableEntry mPasswordMask;
  74. /// If set, any non-ESC key is handled here or not at all
  75. bool mSinkAllKeyEvents;
  76. UTF16 **mHistoryBuf;
  77. void updateHistory(StringBuffer *txt, bool moveIndex);
  78. void playDeniedSound();
  79. void execConsoleCallback();
  80. bool mTextValid;
  81. virtual void handleCharInput( U16 ascii );
  82. S32 findNextWord();
  83. S32 findPrevWord();
  84. public:
  85. GuiTextEditCtrl();
  86. ~GuiTextEditCtrl();
  87. DECLARE_CONOBJECT(GuiTextEditCtrl);
  88. DECLARE_DESCRIPTION( "A control that allows to edit a single line of text. ");
  89. static void initPersistFields();
  90. bool onAdd();
  91. /// Get the contents of the control.
  92. ///
  93. /// dest should be of size GuiTextCtrl::MAX_STRING_LENGTH+1.
  94. void getText(char *dest);
  95. virtual void getRenderText(char *dest);
  96. void setText(S32 tag);
  97. virtual void setText(const UTF8* txt);
  98. virtual void setText(const UTF16* txt);
  99. S32 getCursorPos() { return( mCursorPos ); }
  100. void setCursorPos( const S32 newPos );
  101. void invalidText(bool playSound = true);
  102. void validText();
  103. bool isValidText();
  104. inline bool isPasswordText() { return mPasswordText; }
  105. bool isAllTextSelected();
  106. void selectAllText();
  107. void clearSelectedText();
  108. void forceValidateText();
  109. const char *getScriptValue();
  110. void setScriptValue(const char *value);
  111. bool getSinkAllKeys() { return mSinkAllKeyEvents; }
  112. void setSinkAllKeys(bool state) { mSinkAllKeyEvents = state; }
  113. virtual bool onKeyDown(const GuiEvent &event);
  114. virtual void onMouseDown(const GuiEvent &event);
  115. virtual void onMouseDragged(const GuiEvent &event);
  116. virtual void onMouseUp(const GuiEvent &event);
  117. void onCopy(bool andCut);
  118. void onPaste();
  119. void onUndo();
  120. virtual void setFirstResponder();
  121. virtual void onLoseFirstResponder();
  122. bool hasText();
  123. void onStaticModified(const char* slotName, const char* newValue = NULL);
  124. void onPreRender();
  125. void onRender(Point2I offset, const RectI &updateRect);
  126. virtual void drawText( const RectI &drawRect, bool isFocused );
  127. bool dealWithEnter( bool clearResponder );
  128. };
  129. #endif //_GUI_TEXTEDIT_CTRL_H