/xbmc/guilib/GUIEditControl.h

http://github.com/xbmc/xbmc · C Header · 128 lines · 84 code · 26 blank · 18 comment · 0 complexity · 33523943d9464230f62e4e39d57f799b MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2018 Team Kodi
  3. * This file is part of Kodi - https://kodi.tv
  4. *
  5. * SPDX-License-Identifier: GPL-2.0-or-later
  6. * See LICENSES/README.md for more information.
  7. */
  8. #pragma once
  9. /*!
  10. \file GUIEditControl.h
  11. \brief
  12. */
  13. #include "GUIButtonControl.h"
  14. #include "utils/Stopwatch.h"
  15. #include "utils/StringValidation.h"
  16. #include "utils/Variant.h"
  17. /*!
  18. \ingroup controls
  19. \brief
  20. */
  21. class CGUIEditControl : public CGUIButtonControl
  22. {
  23. public:
  24. enum INPUT_TYPE {
  25. INPUT_TYPE_READONLY = -1,
  26. INPUT_TYPE_TEXT = 0,
  27. INPUT_TYPE_NUMBER,
  28. INPUT_TYPE_SECONDS,
  29. INPUT_TYPE_TIME,
  30. INPUT_TYPE_DATE,
  31. INPUT_TYPE_IPADDRESS,
  32. INPUT_TYPE_PASSWORD,
  33. INPUT_TYPE_PASSWORD_MD5,
  34. INPUT_TYPE_SEARCH,
  35. INPUT_TYPE_FILTER,
  36. INPUT_TYPE_PASSWORD_NUMBER_VERIFY_NEW
  37. };
  38. CGUIEditControl(int parentID, int controlID, float posX, float posY,
  39. float width, float height, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus,
  40. const CLabelInfo& labelInfo, const std::string &text);
  41. explicit CGUIEditControl(const CGUIButtonControl &button);
  42. ~CGUIEditControl(void) override;
  43. CGUIEditControl *Clone() const override { return new CGUIEditControl(*this); };
  44. bool OnMessage(CGUIMessage &message) override;
  45. bool OnAction(const CAction &action) override;
  46. void OnClick() override;
  47. void SetLabel(const std::string &text) override;
  48. void SetLabel2(const std::string &text) override;
  49. void SetHint(const KODI::GUILIB::GUIINFO::CGUIInfoLabel& hint);
  50. std::string GetLabel2() const override;
  51. unsigned int GetCursorPosition() const;
  52. void SetCursorPosition(unsigned int iPosition);
  53. void SetInputType(INPUT_TYPE type, CVariant heading);
  54. void SetTextChangeActions(const CGUIAction& textChangeActions) { m_textChangeActions = textChangeActions; };
  55. bool HasTextChangeActions() const { return m_textChangeActions.HasActionsMeetingCondition(); };
  56. virtual bool HasInvalidInput() const { return m_invalidInput; }
  57. virtual void SetInputValidation(StringValidation::Validator inputValidator, void *data = NULL);
  58. protected:
  59. void SetFocus(bool focus) override;
  60. void ProcessText(unsigned int currentTime) override;
  61. void RenderText() override;
  62. CGUILabel::COLOR GetTextColor() const override;
  63. std::wstring GetDisplayedText() const;
  64. std::string GetDescriptionByIndex(int index) const override;
  65. bool SetStyledText(const std::wstring &text);
  66. void RecalcLabelPosition();
  67. void ValidateCursor();
  68. void UpdateText(bool sendUpdate = true);
  69. void OnPasteClipboard();
  70. void OnSMSCharacter(unsigned int key);
  71. void DefaultConstructor();
  72. virtual bool ValidateInput(const std::wstring &data) const;
  73. void ValidateInput();
  74. /*! \brief Clear out the current text input if it's an MD5 password.
  75. \return true if the password is cleared, false otherwise.
  76. */
  77. bool ClearMD5();
  78. std::wstring m_text2;
  79. std::string m_text;
  80. KODI::GUILIB::GUIINFO::CGUIInfoLabel m_hintInfo;
  81. float m_textOffset;
  82. float m_textWidth;
  83. CRect m_clipRect; ///< clipping rect for the second label
  84. static const int spaceWidth = 5;
  85. unsigned int m_cursorPos;
  86. unsigned int m_cursorBlink;
  87. std::string m_inputHeading;
  88. INPUT_TYPE m_inputType;
  89. bool m_isMD5;
  90. CGUIAction m_textChangeActions;
  91. bool m_invalidInput;
  92. StringValidation::Validator m_inputValidator;
  93. void *m_inputValidatorData;
  94. unsigned int m_smsKeyIndex;
  95. unsigned int m_smsLastKey;
  96. CStopWatch m_smsTimer;
  97. std::wstring m_edit;
  98. int m_editOffset;
  99. int m_editLength;
  100. static const char* smsLetters[10];
  101. static const unsigned int smsDelay;
  102. };