Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.8 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef PANORAMA_TEXTINPUT_H
  6. #define PANORAMA_TEXTINPUT_H
  7. #include "panorama/controls/panel2d.h"
  8. #include "panorama/input/iuiinput.h"
  9. namespace panorama
  10. {
  11. class ITextInputControl;
  12. class CTextInputHandlerSettings;
  13. // When text input finished, bool = true for Done, = false for Cancel; char const * = string that user typed
  14. // Dispatched to ITextInputControl::GetAssociatedPanel()
  15. DECLARE_PANEL_EVENT2( TextInputFinished, bool, char const * );
  16. // When the handler is up and sees gamepad right-stick input, it passes it through to the containing
  17. // control, so the control can do something with it. Dispatched to ITextInputControl::GetAssociatedPanel()
  18. DECLARE_PANEL_EVENT1( TextInputAnalogStickPassthrough, GamePadData_t );
  19. panorama::ETextInputHandlerType_t ETextInputHandlerType_tFromName( const char *pchName );
  20. const char *PchNameFromETextInputHandlerType_t( int eType );
  21. //
  22. // Input submodes for text input handlers, used also by textentry
  23. //
  24. enum ETextInputMode_t
  25. {
  26. k_ETextInputModeNormal,
  27. k_ETextInputModeNormalLower,
  28. k_ETextInputModePassword,
  29. k_ETextInputModeEmail,
  30. k_ETextInputModeNumeric,
  31. k_ETextInputModeNumericPassword,
  32. k_ETextInputModeURL,
  33. k_ETextInputModeSteamCode,
  34. k_ETextInputModePhoneNumber,
  35. };
  36. ETextInputMode_t ETextInputMode_tFromName( const char *pchName );
  37. const char *PchNameFromETextInputMode_t( int eMode );
  38. //-----------------------------------------------------------------------------
  39. // Purpose: an interface that the text input uses to feed and be fed text
  40. //-----------------------------------------------------------------------------
  41. class ITextInputControl
  42. {
  43. public:
  44. virtual ~ITextInputControl() {}
  45. virtual bool OnKeyDown( const KeyData_t &code ) = 0;
  46. virtual bool OnKeyUp( const KeyData_t & code ) = 0;
  47. virtual bool OnKeyTyped( const KeyData_t &unichar ) = 0;
  48. // return true if you own the backing store of the text and can return it immediately on request,
  49. // false otherwise (html returns false here)
  50. virtual bool BSupportsImmediateTextReturn() = 0;
  51. virtual int32 GetCursorOffset() const = 0;
  52. virtual uint GetCharCount() const = 0;
  53. virtual const char *PchGetText() const = 0;
  54. virtual const wchar_t *PwchGetText() const = 0;
  55. virtual void InsertCharacterAtCursor( const wchar_t &unichar ) = 0;
  56. virtual void InsertCharactersAtCursor( const wchar_t *pwch, size_t cwch ) = 0;
  57. virtual CPanel2D *GetAssociatedPanel() = 0;
  58. // request string the control now contains
  59. virtual void RequestControlString() = 0;
  60. };
  61. //-----------------------------------------------------------------------------
  62. // Purpose: The interface over a text input handler. Derives from CPanel2D
  63. // for convenience.
  64. //-----------------------------------------------------------------------------
  65. class CTextInputHandler : public panorama::CPanel2D
  66. {
  67. public:
  68. CTextInputHandler( panorama::IUIWindow *pParent, const char *pchID );
  69. CTextInputHandler( panorama::CPanel2D *pParent, const char *pchID );
  70. virtual ~CTextInputHandler();
  71. virtual void OpenHandler() = 0;
  72. void CloseHandler( bool bCommitText );
  73. virtual ETextInputHandlerType_t GetType() = 0;
  74. virtual ITextInputControl *GetControlInterface() = 0;
  75. virtual void SuggestWord( const wchar_t *pwch, int ich ) = 0;
  76. virtual void SetYButtonAction( const char *pchLabel, IUIEvent *pEvent ) = 0;
  77. protected:
  78. virtual void CloseHandlerImpl( bool bCommitText ) = 0;
  79. };
  80. // Factory methods
  81. CTextInputHandler *CreateTextInputHandler( panorama::IUIWindow *pParent, const CTextInputHandlerSettings &settings, ITextInputControl *pControl );
  82. CTextInputHandler *CreateTextInputHandler( panorama::CPanel2D *pParent, const CTextInputHandlerSettings &settings, ITextInputControl *pControl );
  83. } // namespace panorama
  84. #endif // PANORAMA_TEXTINPUT_H