[guilib] fix labelcontrols with auto width always being marked as dirty if they speci...
[vuplus_xbmc] / xbmc / guilib / GUIEditControl.h
1 /*!
2 \file GUIEditControl.h
3 \brief
4 */
5
6 #ifndef GUILIB_GUIEditControl_H
7 #define GUILIB_GUIEditControl_H
8
9 #pragma once
10
11 /*
12  *      Copyright (C) 2005-2013 Team XBMC
13  *      http://xbmc.org
14  *
15  *  This Program is free software; you can redistribute it and/or modify
16  *  it under the terms of the GNU General Public License as published by
17  *  the Free Software Foundation; either version 2, or (at your option)
18  *  any later version.
19  *
20  *  This Program is distributed in the hope that it will be useful,
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  *  GNU General Public License for more details.
24  *
25  *  You should have received a copy of the GNU General Public License
26  *  along with XBMC; see the file COPYING.  If not, see
27  *  <http://www.gnu.org/licenses/>.
28  *
29  */
30
31 #include "GUIButtonControl.h"
32 #include "utils/Stopwatch.h"
33 #include "utils/StringValidation.h"
34
35 /*!
36  \ingroup controls
37  \brief
38  */
39
40 class CGUIEditControl : public CGUIButtonControl
41 {
42 public:
43   enum INPUT_TYPE {
44                     INPUT_TYPE_READONLY = -1,
45                     INPUT_TYPE_TEXT = 0,
46                     INPUT_TYPE_NUMBER,
47                     INPUT_TYPE_SECONDS,
48                     INPUT_TYPE_TIME,
49                     INPUT_TYPE_DATE,
50                     INPUT_TYPE_IPADDRESS,
51                     INPUT_TYPE_PASSWORD,
52                     INPUT_TYPE_PASSWORD_MD5,
53                     INPUT_TYPE_SEARCH,
54                     INPUT_TYPE_FILTER,
55                     INPUT_TYPE_PASSWORD_NUMBER_VERIFY_NEW
56                   };
57
58   CGUIEditControl(int parentID, int controlID, float posX, float posY,
59                   float width, float height, const CTextureInfo &textureFocus, const CTextureInfo &textureNoFocus,
60                   const CLabelInfo& labelInfo, const std::string &text);
61   CGUIEditControl(const CGUIButtonControl &button);
62   virtual ~CGUIEditControl(void);
63   virtual CGUIEditControl *Clone() const { return new CGUIEditControl(*this); };
64
65   virtual bool OnMessage(CGUIMessage &message);
66   virtual bool OnAction(const CAction &action);
67   virtual void OnClick();
68
69   virtual void SetLabel(const std::string &text);
70   virtual void SetLabel2(const std::string &text);
71   void SetHint(const CGUIInfoLabel& hint);
72
73   virtual CStdString GetLabel2() const;
74
75   unsigned int GetCursorPosition() const;
76   void SetCursorPosition(unsigned int iPosition);
77
78   void SetInputType(INPUT_TYPE type, int heading);
79
80   void SetTextChangeActions(const CGUIAction& textChangeActions) { m_textChangeActions = textChangeActions; };
81
82   bool HasTextChangeActions() const { return m_textChangeActions.HasActionsMeetingCondition(); };
83
84   virtual bool HasInvalidInput() const { return m_invalidInput; }
85   virtual void SetInputValidation(StringValidation::Validator inputValidator, void *data = NULL);
86
87 protected:
88   virtual void ProcessText(unsigned int currentTime);
89   virtual void RenderText();
90   virtual CGUILabel::COLOR GetTextColor() const;
91   CStdStringW GetDisplayedText() const;
92   void RecalcLabelPosition();
93   void ValidateCursor();
94   void UpdateText(bool sendUpdate = true);
95   void OnPasteClipboard();
96   void OnSMSCharacter(unsigned int key);
97   void DefaultConstructor();  
98
99   virtual bool ValidateInput(const CStdStringW &data) const;
100   void ValidateInput();
101
102   /*! \brief Clear out the current text input if it's an MD5 password.
103    \return true if the password is cleared, false otherwise.
104    */
105   bool ClearMD5();
106   
107   CStdStringW m_text2;
108   CStdString  m_text;
109   CGUIInfoLabel m_hintInfo;
110   float m_textOffset;
111   float m_textWidth;
112   CRect m_clipRect; ///< clipping rect for the second label
113
114   static const int spaceWidth = 5;
115
116   unsigned int m_cursorPos;
117   unsigned int m_cursorBlink;
118
119   int m_inputHeading;
120   INPUT_TYPE m_inputType;
121   bool m_isMD5;
122
123   CGUIAction m_textChangeActions;
124
125   bool m_invalidInput;
126   StringValidation::Validator m_inputValidator;
127   void *m_inputValidatorData;
128
129   unsigned int m_smsKeyIndex;
130   unsigned int m_smsLastKey;
131   CStopWatch   m_smsTimer;
132
133   static const char*        smsLetters[10];
134   static const unsigned int smsDelay;
135 };
136 #endif