Merge pull request #4314 from MartijnKaijser/beta1
[vuplus_xbmc] / xbmc / guilib / GUIKeyboard.h
1 /*
2  *      Copyright (C) 2012-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #pragma once
22
23 #include <string>
24 #include "threads/Timer.h"
25
26 class CGUIKeyboard;
27 enum FILTERING { FILTERING_NONE = 0, FILTERING_CURRENT, FILTERING_SEARCH };
28 typedef void (*char_callback_t) (CGUIKeyboard *ref, const std::string &typedString);
29
30 #ifdef TARGET_WINDOWS // disable 4355: 'this' used in base member initializer list
31 #pragma warning(push)
32 #pragma warning(disable: 4355)
33 #endif
34
35 class CGUIKeyboard : public ITimerCallback
36 {
37   public:
38     CGUIKeyboard():m_idleTimer(this){};
39     virtual ~CGUIKeyboard(){ };
40
41     // entrypoint
42     /*!
43      * \brief each native keyboard needs to implement this function with the following behaviour:
44      *
45      * \param pCallback implementation should call this on each keypress with the current whole string
46      * \param initialString implementation should show that initialstring
47      * \param typedstring returns the typed string after close if return is true
48      * \param heading implementation should show a heading (e.x. "search for a movie")
49      * \param bHiddenInput if true the implementation should obfuscate the user input (e.x. by printing "*" for each char)
50      *
51      * \return - true if typedstring is valid and user has confirmed input - false if typedstring is undefined and user canceled the input
52      *
53      */
54     virtual bool ShowAndGetInput(char_callback_t pCallback, 
55                                  const std::string &initialString, 
56                                  std::string &typedString, 
57                                  const std::string &heading, 
58                                  bool bHiddenInput = false) = 0;
59     
60     /*!
61     *\brief This call should cancel a currently shown keyboard dialog. The implementation should 
62     * return false from the modal ShowAndGetInput once anyone calls this metohod.
63     */
64     virtual void Cancel() = 0;
65
66     virtual int GetWindowId() const {return 0;}
67
68     // CTimer Interface for autoclose
69     virtual void OnTimeout()
70     {
71       Cancel();
72     }
73
74     // helpers for autoclose function
75     void startAutoCloseTimer(unsigned int autoCloseMs)
76     {
77       if ( autoCloseMs > 0 ) 
78         m_idleTimer.Start(autoCloseMs, false);
79     }
80
81     void resetAutoCloseTimer()
82     {
83       if (m_idleTimer.IsRunning()) 
84         m_idleTimer.Restart();
85     }
86
87     virtual bool SetTextToKeyboard(const std::string &text, bool closeKeyboard = false) { return false; }
88     
89   private:
90     CTimer m_idleTimer;
91 };
92
93 #ifdef TARGET_WINDOWS
94 #pragma warning(pop)
95 #endif