summaryrefslogtreecommitdiffstats
path: root/xbmc/guilib/GUIKeyboard.h
blob: a6ca5ad00d53976cf371e5ca06122d8855bd1b0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 *  Copyright (C) 2012-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "threads/Timer.h"

#include <string>

class CGUIKeyboard;
enum FILTERING { FILTERING_NONE = 0, FILTERING_CURRENT, FILTERING_SEARCH };
typedef void (*char_callback_t) (CGUIKeyboard *ref, const std::string &typedString);

#ifdef TARGET_WINDOWS // disable 4355: 'this' used in base member initializer list
#pragma warning(push)
#pragma warning(disable: 4355)
#endif

class CGUIKeyboard : public ITimerCallback
{
  public:
    CGUIKeyboard() : m_idleTimer(this) {}
    ~CGUIKeyboard() override = default;

    // entrypoint
    /*!
     * \brief each native keyboard needs to implement this function with the following behaviour:
     *
     * \param pCallback implementation should call this on each keypress with the current whole string
     * \param initialString implementation should show that initialstring
     * \param typedstring returns the typed string after close if return is true
     * \param heading implementation should show a heading (e.x. "search for a movie")
     * \param bHiddenInput if true the implementation should obfuscate the user input (e.x. by printing "*" for each char)
     *
     * \return - true if typedstring is valid and user has confirmed input - false if typedstring is undefined and user canceled the input
     *
     */
    virtual bool ShowAndGetInput(char_callback_t pCallback,
                                 const std::string &initialString,
                                 std::string &typedString,
                                 const std::string &heading,
                                 bool bHiddenInput = false) = 0;

    /*!
    *\brief This call should cancel a currently shown keyboard dialog. The implementation should
    * return false from the modal ShowAndGetInput once anyone calls this method.
    */
    virtual void Cancel() = 0;

    virtual int GetWindowId() const {return 0;}

    // CTimer Interface for autoclose
    void OnTimeout() override
    {
      Cancel();
    }

    // helpers for autoclose function
    void startAutoCloseTimer(unsigned int autoCloseMs)
    {
      if ( autoCloseMs > 0 )
        m_idleTimer.Start(std::chrono::milliseconds(autoCloseMs), false);
    }

    void resetAutoCloseTimer()
    {
      if (m_idleTimer.IsRunning())
        m_idleTimer.Restart();
    }

    virtual bool SetTextToKeyboard(const std::string &text, bool closeKeyboard = false) { return false; }

  private:
    CTimer m_idleTimer;
};

#ifdef TARGET_WINDOWS
#pragma warning(pop)
#endif