TextBox.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #pragma once
  7. #ifndef GWEN_CONTROLS_TEXTBOX_H
  8. #define GWEN_CONTROLS_TEXTOBX_H
  9. #include "Gwen/BaseRender.h"
  10. #include "Gwen/Controls/Base.h"
  11. #include "Gwen/Controls/Label.h"
  12. #include "Gwen/Controls/ScrollControl.h"
  13. namespace Gwen
  14. {
  15. namespace Controls
  16. {
  17. class GWEN_EXPORT TextBox : public Label
  18. {
  19. GWEN_CONTROL( TextBox, Label );
  20. virtual void Render( Skin::Base* skin );
  21. virtual void RenderFocus( Gwen::Skin::Base* /*skin*/){};
  22. virtual void Layout( Skin::Base* skin );
  23. virtual bool OnChar( Gwen::UnicodeChar c );
  24. virtual void InsertText( const Gwen::UnicodeString& str );
  25. virtual void DeleteText( int iStartPos, int iLength );
  26. virtual void RefreshCursorBounds();
  27. virtual bool OnKeyReturn( bool bDown );
  28. virtual bool OnKeyBackspace( bool bDown );
  29. virtual bool OnKeyDelete( bool bDown );
  30. virtual bool OnKeyRight( bool bDown );
  31. virtual bool OnKeyLeft( bool bDown );
  32. virtual bool OnKeyHome( bool bDown );
  33. virtual bool OnKeyEnd( bool bDown );
  34. virtual bool AccelOnlyFocus() { return true; }
  35. virtual void OnPaste( Gwen::Controls::Base* pCtrl );
  36. virtual void OnCopy( Gwen::Controls::Base* pCtrl );
  37. virtual void OnCut( Gwen::Controls::Base* pCtrl );
  38. virtual void OnSelectAll( Gwen::Controls::Base* pCtrl );
  39. virtual void OnMouseDoubleClickLeft( int x, int y );
  40. virtual void EraseSelection();
  41. virtual bool HasSelection();
  42. virtual UnicodeString GetSelection();
  43. virtual void SetCursorPos( int i );
  44. virtual void SetCursorEnd( int i );
  45. virtual void OnMouseClickLeft( int x, int y, bool bDown );
  46. virtual void OnMouseMoved( int x, int y, int deltaX, int deltaY );
  47. virtual void SetSelectAllOnFocus( bool b ){ m_bSelectAll = b; if ( b ) OnSelectAll( this ); }
  48. virtual void MakeCaratVisible();
  49. virtual void OnEnter();
  50. virtual bool NeedsInputChars(){ return true; }
  51. Event::Caller onTextChanged;
  52. Event::Caller onReturnPressed;
  53. protected:
  54. virtual void OnTextChanged();
  55. virtual bool IsTextAllowed( const Gwen::UnicodeString& /*str*/, int /*iPos*/ ){ return true; }
  56. bool m_bSelectAll;
  57. int m_iCursorPos;
  58. int m_iCursorEnd;
  59. Gwen::Rect m_rectSelectionBounds;
  60. Gwen::Rect m_rectCaretBounds;
  61. float m_fLastInputTime;
  62. };
  63. class GWEN_EXPORT TextBoxNumeric : public TextBox
  64. {
  65. public:
  66. GWEN_CONTROL( TextBoxNumeric, TextBox );
  67. virtual float GetFloatFromText();
  68. private:
  69. virtual bool IsTextAllowed( const Gwen::UnicodeString& str, int iPos );
  70. };
  71. }
  72. }
  73. #endif