guiTextEditCtrl.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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/guiTypes.h"
  26. #endif
  27. #ifndef _GUITEXTCTRL_H_
  28. #include "gui/guiTextCtrl.h"
  29. #endif
  30. class GuiTextEditCtrl : public GuiTextCtrl
  31. {
  32. private:
  33. typedef GuiTextCtrl Parent;
  34. static U32 smNumAwake;
  35. protected:
  36. StringBuffer mTextBuffer;
  37. StringTableEntry mValidateCommand;
  38. StringTableEntry mEscapeCommand;
  39. AssetPtr<AudioAsset> mDeniedSound;
  40. // for animating the cursor
  41. S32 mNumFramesElapsed;
  42. U32 mTimeLastCursorFlipped;
  43. ColorI mCursorColor;
  44. bool mCursorOn;
  45. //Edit Cursor
  46. GuiCursor* mEditCursor;
  47. bool mInsertOn;
  48. S32 mMouseDragStart;
  49. Point2I mTextOffset;
  50. bool mTextOffsetReset;
  51. bool mDragHit;
  52. bool mTabComplete;
  53. S32 mScrollDir;
  54. //undo members
  55. StringBuffer mUndoText;
  56. S32 mUndoBlockStart;
  57. S32 mUndoBlockEnd;
  58. S32 mUndoCursorPos;
  59. void saveUndoState();
  60. S32 mBlockStart;
  61. S32 mBlockEnd;
  62. S32 mCursorPos;
  63. S32 setCursorPos(const Point2I &offset);
  64. bool mHistoryDirty;
  65. S32 mHistoryLast;
  66. S32 mHistoryIndex;
  67. S32 mHistorySize;
  68. bool mPasswordText;
  69. StringTableEntry mPasswordMask;
  70. /// If set, any non-ESC key is handled here or not at all
  71. bool mSinkAllKeyEvents;
  72. UTF16 **mHistoryBuf;
  73. void updateHistory(StringBuffer *txt, bool moveIndex);
  74. public:
  75. GuiTextEditCtrl();
  76. ~GuiTextEditCtrl();
  77. DECLARE_CONOBJECT(GuiTextEditCtrl);
  78. static void initPersistFields();
  79. bool onAdd();
  80. bool onWake();
  81. void onSleep();
  82. /// Get the contents of the control.
  83. ///
  84. /// dest should be of size GuiTextCtrl::MAX_STRING_LENGTH+1.
  85. void getText(char *dest);
  86. virtual void setText(const UTF8* txt);
  87. virtual void setText(const UTF16* txt);
  88. S32 getCursorPos() { return( mCursorPos ); }
  89. void reallySetCursorPos( const S32 newPos );
  90. void selectAllText();
  91. void forceValidateText();
  92. const char *getScriptValue();
  93. void setScriptValue(const char *value);
  94. bool onKeyDown(const GuiEvent &event);
  95. void onTouchDown(const GuiEvent &event);
  96. void onTouchDragged(const GuiEvent &event);
  97. void onTouchUp(const GuiEvent &event);
  98. void onCopy(bool andCut);
  99. void onPaste();
  100. void onUndo();
  101. virtual void setFirstResponder();
  102. virtual void onLoseFirstResponder();
  103. void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);
  104. bool hasText();
  105. void onStaticModified(const char* slotName);
  106. void onPreRender();
  107. void onRender(Point2I offset, const RectI &updateRect);
  108. virtual void drawText( const RectI &drawRect, GuiControlState currentState );
  109. void playDeniedSound();
  110. void execConsoleCallback();
  111. };
  112. #endif //_GUI_TEXTEDIT_CTRL_H