Merge "Move tts-player.h from devel-api to public-api" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / focus-manager / keyinput-focus-manager.h
1 #ifndef __DALI_TOOLKIT_KEYINPUT_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_KEYINPUT_FOCUS_MANAGER_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal DALI_INTERNAL
31 {
32 class KeyInputFocusManager;
33 }
34
35 /**
36  * KeyInputFocusManager
37  * This class provides the functionality of registering for keyboard events for controls.
38  * The keyinput focus manager maintains a stack of controls, With the last added control receiving
39  * all the keyboard events first. And if the conrol doesn't consume the event it is passed to
40  * the next control in the stack. If none of the controls in the stack consume the key event then
41  * UnhandledKeyEventSignal() is emitted.
42  *
43  * Signals
44  * | %Signal Name            | Method                            |
45  * |-------------------------|-----------------------------------|
46  * | key-input-focus-changed | @ref KeyInputFocusChangedSignal() |
47  * | unhandled-key-event     | @ref UnhandledKeyEventSignal()    |
48  */
49 class DALI_IMPORT_API KeyInputFocusManager : public BaseHandle
50 {
51 public:
52
53   // KeyInputFocusChanged
54   typedef Signal< void (Control, Control) > KeyInputFocusChangedSignalType;
55
56   // Unhandled Key Event
57   typedef Signal< void (const KeyEvent&) > UnhandledKeyEventSignalType;
58
59 public:
60
61   /**
62    * Create a KeyInputFocusManager handle; this can be initialised with KeyInputFocusManager::Get()
63    * Calling member functions with an uninitialised handle is not allowed.
64    */
65   KeyInputFocusManager();
66
67   /**
68    * @brief Destructor
69    *
70    * This is non-virtual since derived Handle types must not contain data or virtual methods.
71    */
72   ~KeyInputFocusManager();
73
74   /**
75    * Get the singleton of KeyInputFocusManager object.
76    * @return A handle to the KeyInputFocusManager control.
77    */
78   static KeyInputFocusManager Get();
79
80   /**
81    * Sets keyboard focus for a control.
82    * Note: A control can be set to be in focus and still not receive all the key events if another control has over ridden it.
83    * As the key input focus mechanism works like a stack, the top most control receives all the key events, and passes on the
84    * unhandled events to the controls below in the stack. A control in the stack will regain key input focus when there are no more
85    * controls above it in the focus stack.
86    *
87    * @pre The Control is not in the focus stack. If it is allready present in the top of the stack it results in a no-op, If it is
88    * present in the stack but not on the top of the stack, then the control is moved to the top of the focus stack.
89    * @param[in] control The Control to receive keyboard input
90    */
91   void SetFocus(Control control);
92
93   /**
94    * Query for the control that is currently set to be on top of the fcous stack and receives all
95    * keyboard input events first.
96    * @return Pointer to the control set to receive keyboard inputs.
97    */
98   Control GetCurrentFocusControl() const;
99
100   /**
101    * Removes focus for the given control, The control will no longer receive events from keyboard.
102    * @param [in] control which should be removed from focus.
103    */
104   void RemoveFocus(Control control);
105
106   /**
107    * Queries whether a control is currently part of the focus stack.
108    * @param [in] control which should be queried.
109    * @return True if it is part of the foucus stack False otherwise.
110    */
111   bool IsKeyboardListener(Control control);
112
113 public: // Signals
114
115   /**
116    * This signal is emitted when the key input focus control changes.
117    * Two control parameters are sent as part of this signal, the first being the signal that now has the focus, the second
118    * being the one that has lost focus.
119    * A callback of the following type may be connected:
120    * @code
121    *   void YourCallback(Control focusGainedControl, Control focusLostActor);
122    * @endcode
123    * @return The signal to connect to.
124    */
125   KeyInputFocusChangedSignalType& KeyInputFocusChangedSignal();
126
127   /**
128    * This signal is emitted when a key event was received, and none of the focused controls on the stage have consumed it.
129    * A callback of the following type may be connected:
130    * @code
131    *   void YourCallbackName(const KeyEvent& event);
132    * @endcode
133    * @return The signal to connect to.
134    */
135   UnhandledKeyEventSignalType& UnhandledKeyEventSignal();
136
137 private:
138
139   explicit DALI_INTERNAL KeyInputFocusManager(Internal::KeyInputFocusManager *impl);
140
141 }; // class KeyInputFocusManager
142
143 } // namespace Toolkit
144
145 } // namespace Dali
146
147 #endif // __DALI_TOOLKIT_KEYINPUT_FOCUS_MANAGER_H__