xbmc
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  ~CGUIEditControl(void) override;
49  CGUIEditControl* Clone() const override { return new CGUIEditControl(*this); }
50 
51  bool OnMessage(CGUIMessage &message) override;
52  bool OnAction(const CAction &action) override;
53  void OnClick() override;
54 
55  void SetLabel(const std::string &text) override;
56  void SetLabel2(const std::string &text) override;
57  void SetHint(const KODI::GUILIB::GUIINFO::CGUIInfoLabel& hint);
58 
59  std::string GetLabel2() const override;
60 
61  unsigned int GetCursorPosition() const;
62  void SetCursorPosition(unsigned int iPosition);
63 
64  void SetInputType(INPUT_TYPE type, const CVariant& heading);
65 
66  void SetTextChangeActions(const CGUIAction& textChangeActions)
67  {
68  m_textChangeActions = textChangeActions;
69  }
70 
71  bool HasTextChangeActions() const { return m_textChangeActions.HasActionsMeetingCondition(); }
72 
73  virtual bool HasInvalidInput() const { return m_invalidInput; }
74  virtual void SetInputValidation(StringValidation::Validator inputValidator, void *data = NULL);
75 
76 protected:
77  void SetFocus(bool focus) override;
78  void ProcessText(unsigned int currentTime) override;
79  void RenderText() override;
80  CGUILabel::COLOR GetTextColor() const override;
81  std::wstring GetDisplayedText() const;
82  std::string GetDescriptionByIndex(int index) const override;
83  bool SetStyledText(const std::wstring &text);
84  void RecalcLabelPosition();
85  void ValidateCursor();
86  void UpdateText(bool sendUpdate = true);
87  void OnPasteClipboard();
88  void OnSMSCharacter(unsigned int key);
89  void DefaultConstructor();
90 
91  virtual bool ValidateInput(const std::wstring &data) const;
92  void ValidateInput();
93 
97  bool ClearMD5();
98 
99  std::wstring m_text2;
100  std::string m_text;
102  float m_textOffset;
103  float m_textWidth;
105 
106  static const int spaceWidth = 5;
107 
108  unsigned int m_cursorPos;
109  unsigned int m_cursorBlink;
110 
111  std::string m_inputHeading;
112  INPUT_TYPE m_inputType;
113  bool m_isMD5;
114 
115  CGUIAction m_textChangeActions;
116 
117  bool m_invalidInput;
118  StringValidation::Validator m_inputValidator;
119  void *m_inputValidatorData;
120 
121  unsigned int m_smsKeyIndex;
122  unsigned int m_smsLastKey;
123  CStopWatch m_smsTimer;
124 
125  std::wstring m_edit;
126  int m_editOffset;
127  int m_editLength;
128 
129  static const char* smsLetters[10];
130  static const unsigned int smsDelay;
131 };
Definition: Stopwatch.h:14
Definition: GUIEditControl.h:26
bool HasActionsMeetingCondition() const
Check if there is any action that meet its condition.
Definition: GUIAction.cpp:124
Definition: GUIButtonControl.h:27
Definition: GUIInfoLabel.h:31
Definition: Variant.h:29
CRect m_clipRect
clipping rect for the second label
Definition: GUIEditControl.h:104
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
void SetInputType(INPUT_TYPE type, const CVariant &heading)
Definition: GUIEditControl.cpp:372
Definition: GUITexture.h:51
bool ClearMD5()
Clear out the current text input if it's an MD5 password.
Definition: GUIEditControl.cpp:615
Definition: GUIMessage.h:365
Definition: GUILabel.h:22
void OnClick() override
Definition: GUIEditControl.cpp:275
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