Torque3D Documentation / _generateds / guiTextEditCtrl.h

guiTextEditCtrl.h

Engine/source/gui/controls/guiTextEditCtrl.h

More...

Classes:

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   S32                  mDoubleClickTimeMS;
 90   S32                  mMouseUpTime;
 91
 92   StringTableEntry     mPlaceholderText;
 93
 94   /// If set, any non-ESC key is handled here or not at all
 95   bool    mSinkAllKeyEvents;   
 96   UTF16   **mHistoryBuf;
 97   void updateHistory(StringBuffer *txt, bool moveIndex);
 98
 99   void playDeniedSound();
100   void execConsoleCallback();
101
102   bool mTextValid;
103
104   virtual void handleCharInput( U16 ascii );
105
106   S32 findNextWord();   
107   S32 findPrevWord();   
108
109public:
110   GuiTextEditCtrl();
111   ~GuiTextEditCtrl();
112   DECLARE_CONOBJECT(GuiTextEditCtrl);
113   DECLARE_DESCRIPTION( "A control that allows to edit a single line of text. ");
114   static void initPersistFields();
115
116   bool onAdd();
117
118   /// Get the contents of the control.
119   ///
120   /// dest should be of size GuiTextCtrl::MAX_STRING_LENGTH+1.
121   void getText(char *dest);
122   virtual void getRenderText(char *dest);
123
124   void setText(S32 tag);
125   virtual void setText(const UTF8* txt);
126   virtual void setText(const UTF16* txt);
127   S32   getCursorPos()   { return( mCursorPos ); }
128   void  setCursorPos( const S32 newPos );
129   
130   void invalidText(bool playSound = true);
131   void validText();
132   bool isValidText();
133   inline bool isPasswordText() { return mPasswordText; }
134
135   bool isAllTextSelected();
136   void selectAllText();
137   void clearSelectedText();
138
139   void forceValidateText();
140   const char *getScriptValue();
141   void setScriptValue(const char *value);
142
143   bool getSinkAllKeys() { return mSinkAllKeyEvents; }
144   void setSinkAllKeys(bool state) { mSinkAllKeyEvents = state; }
145
146   virtual bool onKeyDown(const GuiEvent &event);
147   virtual void onMouseDown(const GuiEvent &event);
148   virtual void onMouseDragged(const GuiEvent &event);
149   virtual void onMouseUp(const GuiEvent &event);
150   
151   void onCopy(bool andCut);
152   void onPaste();
153   void onUndo();
154
155   virtual void setFirstResponder();
156   virtual void onLoseFirstResponder();
157
158   bool hasText();
159
160   void onStaticModified(const char* slotName, const char* newValue = NULL);
161
162   void onPreRender();
163   void onRender(Point2I offset, const RectI &updateRect);
164   virtual void drawText( const RectI &drawRect, bool isFocused );
165
166   bool dealWithEnter( bool clearResponder );
167
168   static bool setPlaceholderText(void* object, const char* index, const char* data)
169   {
170      static_cast<GuiTextEditCtrl*>(object)->setPlaceholderText(data); return true;
171   }
172   static const char* getPlaceholderText(void* obj, const char* data)
173   {
174      return static_cast<GuiTextEditCtrl*>(obj)->getPlaceholderText();
175   }
176
177   virtual void setPlaceholderText(const char* txt = NULL)
178   {
179      mPlaceholderText = StringTable->insert(txt, true);
180   }
181
182   const char* getPlaceholderText() { return (const char*)mPlaceholderText; }
183};
184
185#endif //_GUI_TEXTEDIT_CTRL_H
186