My Project
GUIEdit.h
1 #pragma once
2 #include "GUIBase.h"
3 #include "GUIUniBuffer.h"
4 #include "GUIIMEDelegate.h"
5 
6 namespace ParaEngine
7 {
8  class CGUIBase;
9  struct TextureEntity;
10  struct AssetEntity;
11  struct GUIFontElement;
12 
13 
14  //-----------------------------------------------------------------------------
15  // EditBox control
16  //-----------------------------------------------------------------------------
17  class CGUIEditBox : public CGUIBase, public GUIIMEDelegate
18  {
19  public:
21  // implementation of IAttributeFields
22 
24  virtual int GetAttributeClassID(){return ATTRIBUTE_CLASSID_CGUIEditBox;}
26  virtual const char* GetAttributeClassName(){static const char name[] = "CGUIEditBox"; return name;}
28  virtual const char* GetAttributeClassDescription(){static const char desc[] = ""; return desc;}
30  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
31 
32  ATTRIBUTE_METHOD1(CGUIEditBox, GetCaretColor_s, DWORD*) {*p1 = cls->GetCaretColor(); return S_OK;}
33  ATTRIBUTE_METHOD1(CGUIEditBox, SetCaretColor_s, DWORD) {cls->SetCaretColor(p1); return S_OK;}
34 
35  ATTRIBUTE_METHOD1(CGUIEditBox, GetSelectedBackColor_s, DWORD*) {*p1 = cls->GetSelectedBackColor(); return S_OK;}
36  ATTRIBUTE_METHOD1(CGUIEditBox, SetSelectedBackColor_s, DWORD) {cls->SetSelectedBackColor(p1); return S_OK;}
37 
38  ATTRIBUTE_METHOD1(CGUIEditBox, GetEmptyText_s, const char**) { *p1 = cls->GetEmptyText().c_str(); return S_OK; }
39  ATTRIBUTE_METHOD1(CGUIEditBox, SetEmptytext_s, const char*) { cls->SetEmptytext(p1); return S_OK; }
40 
41  public:
42  CGUIEditBox();
43  virtual ~CGUIEditBox();
44 
45  //virtual bool MsgProc(CGUIEvent *event=NULL);
46  virtual bool MsgProc(MSG *event);
47 
48  void OnSelectStart();
49 
50  virtual void UpdateRects();
51  virtual bool CanHaveFocus() { return (m_bIsVisible && m_bIsEnabled && m_bCanHasFocus); }
52  virtual HRESULT Render(GUIState* pGUIState ,float fElapsedTime);
53  virtual bool OnFocusIn();
54  virtual bool OnFocusOut();
55  virtual bool OnMouseEnter();
56  virtual bool OnMouseLeave();
57  virtual bool OnChange(const char* code=NULL);
58  virtual void InitObject(const char * strObjectName, const char * alignment, int x, int y, int width, int height);
59  virtual string ToScript(int option=0);
60  virtual void Reset();
61 
64  virtual bool HasClickEvent();
65 
71  void SetTextA( LPCSTR szText, bool bSelected );
72 
77  virtual void SetTextA(const char* szText) { SetTextA(szText, false);};
83  virtual void SetText(const char16_t* wszText);
90  virtual int GetTextA(std::string& out);
96  virtual const char16_t* GetText(){ return m_Buffer.GetBuffer(); };
97 
102  int GetFirstVisibleCharIndex(){return m_nFirstVisible;};
103 
104 
106  void GetPriorWordPos( int nCP, int *pPrior );
107 
109  void GetNextWordPos( int nCP, int *pNext );
110 
112  HRESULT CPtoXY( int nCP, BOOL bTrail, int *pX, int *pY, bool absolute = false);
113 
115  HRESULT XYtoCP( int nX, int nY, int *pCP,int *pnTrail, bool absolute = false);
116 
117  void GetTextLineSize(int* width, int* height);
118 
122  int GetCaretPosition();
123 
128  void SetCaretPosition(int nCharacterPos);
129 
131  virtual bool IsHideCaret() { return false;};
132 
136  int GetTextSize();
137 
138  HRESULT GetTextCopy( std::u16string& out );
139  void ClearText();
140  virtual void SetTextColor( Color Color ); // Text color
141  void SetSelectedTextColor( Color Color ); // Selected text color
142  void SetSelectedBackColor( Color Color ); // Selected background color
143  Color GetSelectedBackColor();
144  void SetCaretColor( Color Color ); // Caret color
145  Color GetCaretColor();
146  void SetBorderWidth( int nBorder ) { m_nBorder = nBorder; UpdateRects(); } // Border of the window
147  const std::string& GetEmptyText();
148  void SetEmptytext(const char* utf8Text);
149 
150  void SetTextFloatArray( const float *pNumbers, int nCount );
151  bool GetReadOnly()const{return m_bReadOnly; }
152  void SetReadOnly(bool readonly){m_bReadOnly=readonly;}
153 
154  virtual IObject* Clone()const;
155  virtual void Clone(IObject* pobj)const;
156  virtual const IType* GetType()const{return m_type;}
161  static void StaticInit();
162  bool IsModified()const{return m_bIsModified;}
163 
165  virtual int OnHandleWinMsgChars(const std::wstring& sChars);
166 
176  void SetPasswordChar(char PasswordChar);
177  char GetPasswordChar();
178 
180  void SetCaretVisible(bool bVisible);
181 
183  bool IsCaretVisible();
184 
185 #ifdef PARAENGINE_MOBILE
186  // ime delegate implementation.
187  public:
188  virtual bool attachWithIME();
189  virtual bool detachWithIME();
190  protected:
191  virtual bool canAttachWithIME();
192  virtual void didAttachWithIME();
193  virtual bool canDetachWithIME();
194  virtual void didDetachWithIME();
195  virtual void insertText(const char * text, size_t len);
196  virtual void deleteBackward();
197  virtual const std::string& getContentText();
198 #endif
199  protected:
200  static const IType* m_type;
201  void PlaceCaret( int nCP );
202  void DeleteSelectionText();
203  void ResetCaretBlink();
204  void CopyToClipboard();
205  void PasteFromClipboard();
206  //index =-1 means insert into the current caret
207  void InsertChar( WCHAR wChar, int index=-1);
208  void InsertCharA( CHAR Char, int index=-1);
209 
210  CUniBuffer m_Buffer; // Buffer to hold text
211  int m_nBorder; // Border of the window
212 
213  //RECT m_rcText; // Bounding rectangle for the text
214  //RECT m_rcRender[9]; // Convenient rectangles for rendering elements
215  double m_dfBlink; // Caret blink time in milliseconds
216  double m_dfLastBlink; // Last timestamp of caret blink
217  bool m_bCaretOn; // Flag to indicate whether caret is currently visible
218  int m_nCaret; // Caret position, in characters
219  bool m_bInsertMode; // If true, control is in insert mode. Else, overwrite mode.
220  int m_nSelStart; // Starting position of the selection. The caret marks the end.
221  int m_nFirstVisible;// First visible character in the edit control
222  Color m_SelBkColor; // Selected background color
223  Color m_CaretColor; // Caret color
224  bool m_bMultipleLine;// if allow multiple line, false by default
225  bool m_bIsModified;
226  // Mouse-specific
227  bool m_bMouseDrag; // True to indicate drag in progress
228  bool m_bReadOnly;
229 
230  // key
231  double m_last_keytime;
232  DWORD m_last_key;//for holding key
233  DWORD m_key_state; //0:not pressed; 1:pressed; 2:holding a key
237  std::u16string m_empty_text;
238  std::string m_empty_text_utf8;
239  };
240 }
HRESULT CPtoXY(int nCP, BOOL bTrail, int *pX, int *pY, bool absolute=false)
Character position to X,Y in pixel.
Definition: GUIEdit.cpp:1289
void SetPasswordChar(char PasswordChar)
The PasswordChar property specifies the character displayed in the text box.
Definition: GUIEdit.cpp:1246
IType is for type information and validating It contains type information of an object.
Definition: Type.h:75
virtual bool HasClickEvent()
return true, if this control can be clicked.
Definition: GUIEdit.cpp:1821
static void StaticInit()
Initialize the event mapping for the default CGUIEdit class All its inheritances should have a Static...
Definition: GUIEdit.cpp:132
void GetPriorWordPos(int nCP, int *pPrior)
get the prior word position
Definition: GUIEdit.cpp:1279
int GetTextSize()
return the text size in Unicode character count.
Definition: GUIEdit.cpp:1273
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: GUIEdit.h:28
char m_PasswordChar
The PasswordChar, by default it is '\0'.
Definition: GUIEdit.h:235
virtual bool MsgProc(MSG *event)
the procedure that handles all the events.
Definition: GUIEdit.cpp:896
virtual void didDetachWithIME()
When the delegate detaches from the IME, this method is called by IMEDispatcher.
Definition: GUIIMEDelegate.h:37
Definition: EventBinding.h:22
virtual void didAttachWithIME()
When the delegate detaches from the IME, this method is called by IMEDispatcher.
Definition: GUIIMEDelegate.h:27
different physics engine has different winding order.
Definition: EventBinding.h:32
void SetTextA(LPCSTR szText, bool bSelected)
set the text.
Definition: GUIEdit.cpp:605
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object's name
Definition: GUIEdit.h:26
Definition: GUIEdit.h:17
int GetFirstVisibleCharIndex()
if the text is longer than the edit box, the returned value is the index of the first visible charact...
Definition: GUIEdit.h:102
bool IsCaretVisible()
Flag to indicate whether caret is currently visible.
Definition: GUIEdit.cpp:513
int GetCaretPosition()
return Caret position in characters
Definition: GUIEdit.cpp:1255
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: GUIEdit.h:24
void GetTextLineSize(int *width, int *height)
get the text line size in pixels, supposing the current font and text will be rendered in a single li...
Definition: GUIEdit.cpp:1369
base object for all 2D GUI objects (1) 2D GUI object are not tested against view frustum, instead it is controlled by visibility tag automatically or through user input.
Definition: GUIBase.h:54
virtual void SetTextA(const char *szText)
Set the text of this object.
Definition: GUIEdit.h:77
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
virtual bool canAttachWithIME()
Decide if the delegate instance is ready to receive an IME message.
Definition: GUIIMEDelegate.h:22
virtual int OnHandleWinMsgChars(const std::wstring &sChars)
this function is called to handle window's latest WM_CHAR message, when the control got key focus...
Definition: GUIEdit.cpp:1771
virtual void Reset()
Resets the objects states.
Definition: GUIEdit.cpp:884
virtual int GetTextA(std::string &out)
get the text of the control
Definition: GUIEdit.cpp:1826
HRESULT XYtoCP(int nX, int nY, int *pCP, int *pnTrail, bool absolute=false)
X,Y in pixel to character position.
Definition: GUIEdit.cpp:1395
virtual void SetText(const char16_t *wszText)
Set the text of this object The control internally store everything in Unicode.
Definition: GUIEdit.cpp:615
virtual IObject * Clone() const
Clone the object's contains and return a pointer to the newly created object.
Definition: GUIEdit.cpp:125
It's used as parameter to Render method of each GUI object.
Definition: GUIState.h:16
virtual bool canDetachWithIME()
Decide if the delegate instance can stop receiving IME messages.
Definition: GUIIMEDelegate.h:32
virtual void deleteBackward()
Called by IMEDispatcher after the user clicks the backward key.
Definition: GUIIMEDelegate.h:47
void SetCaretPosition(int nCharacterPos)
Set Caret position in characters.
Definition: GUIEdit.cpp:1261
base interface for cross-platform IME and also null implementation under win32 client.
Definition: GUIIMEDelegate.h:10
Definition: inftrees.h:24
virtual const std::string & getContentText()
Called by IMEDispatcher for text stored in delegate.
Definition: GUIIMEDelegate.h:52
virtual bool IsHideCaret()
whether caret is hidden.
Definition: GUIEdit.h:131
virtual const char16_t * GetText()
get the text of the control The control internally store everything in Unicode.
Definition: GUIEdit.h:96
Null implementation.
Definition: GUIUniBuffer.h:176
void GetNextWordPos(int nCP, int *pNext)
get the next word position
Definition: GUIEdit.cpp:1284
std::u16string m_empty_text
text to show when text is empty: this is usually something like "click to enter text" ...
Definition: GUIEdit.h:237
virtual void UpdateRects()
Definition: GUIEdit.cpp:652
Definition: ParaColor.h:275
void SetCaretVisible(bool bVisible)
Flag to indicate whether caret is currently visible.
Definition: GUIEdit.cpp:508
virtual void insertText(const char *text, size_t len)
Called by IMEDispatcher when text input received from the IME.
Definition: GUIIMEDelegate.h:42
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: GUIEdit.cpp:1925