kodi
GUIEditControl.h
Go to the documentation of this 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 
9 #pragma once
10 
16 #include "GUIButtonControl.h"
17 #include "utils/Stopwatch.h"
18 #include "utils/StringValidation.h"
19 #include "utils/Variant.h"
20 
27 {
28 public:
29  enum INPUT_TYPE {
30  INPUT_TYPE_READONLY = -1,
31  INPUT_TYPE_TEXT = 0,
32  INPUT_TYPE_NUMBER,
33  INPUT_TYPE_SECONDS,
34  INPUT_TYPE_TIME,
35  INPUT_TYPE_DATE,
36  INPUT_TYPE_IPADDRESS,
37  INPUT_TYPE_PASSWORD,
38  INPUT_TYPE_PASSWORD_MD5,
39  INPUT_TYPE_SEARCH,
40  INPUT_TYPE_FILTER,
41  INPUT_TYPE_PASSWORD_NUMBER_VERIFY_NEW
42  };
43 
44  CGUIEditControl(int parentID, int controlID, float posX, float posY,
45  float width, float height, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus,
46  const CLabelInfo& labelInfo, const std::string &text);
47  explicit CGUIEditControl(const CGUIButtonControl& button);
48  explicit CGUIEditControl(const CGUIEditControl& button);
49  ~CGUIEditControl(void) override;
50  CGUIEditControl* Clone() const override { return new CGUIEditControl(*this); }
51 
52  bool OnMessage(CGUIMessage &message) override;
53  bool OnAction(const CAction &action) override;
54  void OnClick() override;
55 
56  void SetLabel(const std::string &text) override;
57  void SetLabel2(const std::string &text) override;
58  void SetHint(const KODI::GUILIB::GUIINFO::CGUIInfoLabel& hint);
59 
60  std::string GetLabel2() const override;
61 
62  unsigned int GetCursorPosition() const;
63  void SetCursorPosition(unsigned int iPosition);
64 
65  void SetInputType(INPUT_TYPE type, const CVariant& heading);
66 
67  void SetTextChangeActions(const CGUIAction& textChangeActions)
68  {
69  m_textChangeActions = textChangeActions;
70  }
71 
72  bool HasTextChangeActions() const { return m_textChangeActions.HasActionsMeetingCondition(); }
73 
74  virtual bool HasInvalidInput() const { return m_invalidInput; }
75  virtual void SetInputValidation(StringValidation::Validator inputValidator, void *data = NULL);
76 
77 protected:
78  void SetFocus(bool focus) override;
79  void ProcessText(unsigned int currentTime) override;
80  void RenderText() override;
81  CGUILabel::COLOR GetTextColor() const override;
82  std::wstring GetDisplayedText() const;
83  std::string GetDescriptionByIndex(int index) const override;
84  bool SetStyledText(const std::wstring &text);
85 
91 
92  void ValidateCursor();
93  void UpdateText(bool sendUpdate = true);
94  void OnPasteClipboard();
95  void OnSMSCharacter(unsigned int key);
96  void DefaultConstructor();
97 
98  virtual bool ValidateInput(const std::wstring &data) const;
99  void ValidateInput();
100 
104  bool ClearMD5();
105 
109  void ComposingCursorAppendChar(std::uint32_t deadUnicodeKey);
112  void ResetCursor();
116  void CancelKeyComposition(std::uint32_t deadUnicodeKey);
120  bool IsComposingKey() const;
121 
122  std::wstring m_text2;
123  std::string m_text;
125  float m_textOffset;
127 
128  unsigned int m_cursorPos;
129  bool m_cursorBlinkEnabled{true};
130  unsigned int m_cursorBlink;
131  // visible cursor chars
132  std::vector<std::uint32_t> m_cursorChars{'|'};
133  // cursor char buffer
134  std::vector<std::uint32_t> m_cursorCharsBuffer{};
135 
136  std::string m_inputHeading;
137  INPUT_TYPE m_inputType;
138  bool m_isMD5;
139 
140  CGUIAction m_textChangeActions;
141 
142  bool m_invalidInput;
143  StringValidation::Validator m_inputValidator;
144  void *m_inputValidatorData;
145 
146  unsigned int m_smsKeyIndex;
147  unsigned int m_smsLastKey;
148  CStopWatch m_smsTimer;
149 
150  std::wstring m_edit;
151  int m_editOffset;
152  int m_editLength;
153 };
Definition: Stopwatch.h:14
Definition: GUIEditControl.h:26
bool HasActionsMeetingCondition() const
Check if there is any action that meet its condition.
Definition: GUIAction.cpp:136
Definition: GUIButtonControl.h:27
Definition: GUIInfoLabel.h:31
bool IsComposingKey() const
Check if the control is composing a key.
Definition: GUIEditControl.cpp:862
void ResetCursor()
Reset the cursor aspect to normal input (i.e. not composing a key)
Definition: GUIEditControl.cpp:855
Definition: Variant.h:31
void RecalcRightLabelPosition()
Recalculate the text offset position for the right label by updating m_textOffset and validate the cu...
Definition: GUIEditControl.cpp:426
CRect m_clipRect
clipping rect for the second label
Definition: GUIEditControl.h:126
Class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:21
void ComposingCursorAppendChar(std::uint32_t deadUnicodeKey)
Append a given char to the composing cursor.
Definition: GUIEditControl.cpp:808
void CancelKeyComposition(std::uint32_t deadUnicodeKey)
Cancel the key composition.
Definition: GUIEditControl.cpp:834
void SetInputType(INPUT_TYPE type, const CVariant &heading)
Definition: GUIEditControl.cpp:416
Definition: GUITexture.h:51
bool ClearMD5()
Clear out the current text input if it&#39;s an MD5 password.
Definition: GUIEditControl.cpp:678
Definition: GUIMessage.h:365
Definition: GUILabel.h:22
void OnClick() override
Definition: GUIEditControl.cpp:319
COLOR
allowed color categories for labels, as defined by the skin
Definition: GUILabel.h:74
Class containing vector of condition->(action/navigation route) and handling its execution.
Definition: GUIAction.h:21