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