xbmc
GUIKeyboard.h
1 /*
2  * Copyright (C) 2012-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 
11 #include "threads/Timer.h"
12 
13 #include <string>
14 
15 class CGUIKeyboard;
16 enum FILTERING { FILTERING_NONE = 0, FILTERING_CURRENT, FILTERING_SEARCH };
17 typedef void (*char_callback_t) (CGUIKeyboard *ref, const std::string &typedString);
18 
19 #ifdef TARGET_WINDOWS // disable 4355: 'this' used in base member initializer list
20 #pragma warning(push)
21 #pragma warning(disable: 4355)
22 #endif
23 
25 {
26  public:
27  CGUIKeyboard() : m_idleTimer(this) {}
28  ~CGUIKeyboard() override = default;
29 
30  // entrypoint
43  virtual bool ShowAndGetInput(char_callback_t pCallback,
44  const std::string &initialString,
45  std::string &typedString,
46  const std::string &heading,
47  bool bHiddenInput = false) = 0;
48 
53  virtual void Cancel() = 0;
54 
55  virtual int GetWindowId() const {return 0;}
56 
57  // CTimer Interface for autoclose
58  void OnTimeout() override
59  {
60  Cancel();
61  }
62 
63  // helpers for autoclose function
64  void startAutoCloseTimer(unsigned int autoCloseMs)
65  {
66  if ( autoCloseMs > 0 )
67  m_idleTimer.Start(std::chrono::milliseconds(autoCloseMs), false);
68  }
69 
70  void resetAutoCloseTimer()
71  {
72  if (m_idleTimer.IsRunning())
73  m_idleTimer.Restart();
74  }
75 
76  virtual bool SetTextToKeyboard(const std::string &text, bool closeKeyboard = false) { return false; }
77 
78  private:
79  CTimer m_idleTimer;
80 };
81 
82 #ifdef TARGET_WINDOWS
83 #pragma warning(pop)
84 #endif
virtual bool ShowAndGetInput(char_callback_t pCallback, const std::string &initialString, std::string &typedString, const std::string &heading, bool bHiddenInput=false)=0
each native keyboard needs to implement this function with the following behaviour: ...
Definition: GUIKeyboard.h:24
Definition: Timer.h:25
virtual void Cancel()=0
This call should cancel a currently shown keyboard dialog. The implementation should return false fro...
Definition: Timer.h:17