6cad036a9938a723d625f24fcbc4f69d5feca2f4
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / focus-manager / keyboard-focus-manager.h
1 #ifndef __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__
3
4 /*
5  * Copyright (c) 2014 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 /**
22  * @addtogroup CAPI_DALI_TOOLKIT_FOCUS_MANAGER_MODULE
23  * @{
24  */
25
26 // INTERNAL INCLUDES
27 #include <dali/dali.h>
28 #include <dali-toolkit/public-api/controls/control.h>
29
30 namespace Dali DALI_IMPORT_API
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal DALI_INTERNAL
37 {
38 class KeyboardFocusManager;
39 }
40
41 /**
42  * @brief Provides the functionality of handling keyboard navigation
43  * and maintaining the two dimensional keyboard focus chain.
44  *
45  * It provides functionality of setting the focus and moving the focus
46  * in four directions (i.e. Left, Right, Up and Down). It also draws a
47  * highlight for the focused actor and emits a signal when the focus
48  * is changed.
49  */
50 class KeyboardFocusManager : public BaseHandle
51 {
52 public:
53   //Signal Names
54   static const char* const SIGNAL_PRE_FOCUS_CHANGE; ///< name "keyboard-pre-focus-change"
55   static const char* const SIGNAL_FOCUS_CHANGED; ///< name "keyboard-focus-changed"
56   static const char* const SIGNAL_FOCUS_GROUP_CHANGED; ///< name "keyboard-focus-group-changed"
57   static const char* const SIGNAL_FOCUSED_ACTOR_ACTIVATED; ///< name "keyboard-focused-actor-activated"
58
59 public:
60
61   /// @brief Pre focus change signal
62   typedef SignalV2< Actor ( Actor, Actor, Control::KeyboardFocusNavigationDirection ) > PreFocusChangeSignalV2;
63
64   /// @brief Focus changed signal
65   typedef SignalV2< void ( Actor, Actor ) > FocusChangedSignalV2;
66
67   /// @brief Focus group changed signal
68   typedef SignalV2< void ( Actor, bool ) > FocusGroupChangedSignalV2;
69
70   /// @brief Focused actor activated signal
71   typedef SignalV2< void ( Actor ) > FocusedActorActivatedSignalV2;
72
73   /**
74    * @brief Create a KeyboardFocusManager handle; this can be initialised with KeyboardFocusManager::New().
75    *
76    * Calling member functions with an uninitialised handle is not allowed.
77    */
78   KeyboardFocusManager();
79
80   /**
81    * @brief Virtual destructor.
82    */
83   virtual ~KeyboardFocusManager();
84
85   /**
86    * @brief Get the singleton of KeyboardFocusManager object.
87    *
88    * @return A handle to the KeyboardFocusManager control.
89    */
90   static KeyboardFocusManager Get();
91
92   /**
93    * @brief Move the keyboard focus to the given actor.
94    *
95    * Only one actor can be focused at the same time.  The actor must
96    * be in the stage already and keyboard focusable.
97    *
98    * @pre The KeyboardFocusManager has been initialized.
99    * @pre The Actor has been initialized.
100    * @param actor The actor to be focused
101    * @return Whether the focus is successful or not
102    */
103   bool SetCurrentFocusActor(Actor actor);
104
105   /**
106    * @brief Get the current focused actor.
107    *
108    * @pre The KeyboardFocusManager has been initialized.
109    * @return A handle to the current focused actor or an empty handle if no actor is focused.
110    */
111   Actor GetCurrentFocusActor();
112
113   /**
114    * @brief Move the focus to the next focusable actor in the focus
115    * chain in the given direction (according to the focus traversal
116    * order).
117    *
118    * @pre The KeyboardFocusManager has been initialized.
119    * @param direction The direction of focus movement
120    * @return true if the movement was successful
121    */
122   bool MoveFocus(Control::KeyboardFocusNavigationDirection direction);
123
124   /**
125    * @brief Clear the focus from the current focused actor if any, so
126    * that no actor is focused in the focus chain.
127    *
128    * It will emit focus changed signal without current focused actor
129    * @pre The KeyboardFocusManager has been initialized.
130    */
131   void ClearFocus();
132
133   /**
134    * @brief Set whether the focus movement should be looped within the same focus group.
135    *
136    * The focus movement is not looped by default.
137    * @pre The KeyboardFocusManager has been initialized.
138    * @param enabled Whether the focus movement should be looped
139    */
140   void SetFocusGroupLoop(bool enabled);
141
142   /**
143    * @brief Get whether the focus movement should be looped within the same focus group.
144    *
145    * @pre The KeyboardFocusManager has been initialized.
146    * @return Whether the focus movement should be looped
147    */
148   bool GetFocusGroupLoop() const;
149
150   /**
151    * @brief Set whether an actor is a focus group that can limit the
152    * scope of focus movement to its child actors in the focus chain.
153    *
154    * Layout controls set themselves as focus groups by default.
155    *
156    * @pre The KeyboardFocusManager has been initialized.
157    * @pre The Actor has been initialized.
158    * @param actor The actor to be set as a focus group.
159    * @param isFocusGroup Whether to set the actor as a focus group or not.
160    */
161   void SetAsFocusGroup(Actor actor, bool isFocusGroup);
162
163   /**
164    * @brief Check whether the actor is set as a focus group or not.
165    *
166    * @pre The KeyboardFocusManager has been initialized.
167    * @pre The Actor has been initialized.
168    * @param actor The actor to be checked.
169    * @return Whether the actor is set as a focus group.
170    */
171   bool IsFocusGroup(Actor actor) const;
172
173   /**
174    * @brief Returns the closest ancestor of the given actor that is a focus group.
175    *
176    * @param actor The actor to be checked for its focus group
177    * @return The focus group the given actor belongs to or an empty handle if the given actor
178    * doesn't belong to any focus group
179    */
180   Actor GetFocusGroup(Actor actor);
181
182   /**
183    * @brief Set the focus indicator actor.
184    *
185    * This will replace the default focus indicator actor in
186    * KeyboardFocusManager and will be added to the focused actor as a
187    * highlight.
188    *
189    * @pre The KeyboardFocusManager has been initialized.
190    * @pre The indicator actor has been initialized.
191    * @param indicator The indicator actor to be added
192    */
193   void SetFocusIndicatorActor(Actor indicator);
194
195   /**
196    * @brief Get the focus indicator actor.
197    *
198    * @pre The KeyboardFocusManager has been initialized.
199    * @return A handle to the focus indicator actor
200    */
201   Actor GetFocusIndicatorActor();
202
203 public: // Signals
204
205   /**
206    * @brief This signal is emitted before the focus is going to be changed.
207    *
208    * KeyboardFocusManager makes the best guess for which actor to
209    * focus towards the given direction, but applications might want to
210    * change that. By connecting with this signal, they can check the
211    * proposed actor to focus and return a different actor if they
212    * wish.  This signal is only emitted when the navigation key is
213    * pressed and KeyboardFocusManager tries to move the focus
214    * automatically. It won't be emitted for focus movement by calling
215    * SetCurrentFocusActor directly.
216    *
217    * A callback of the following type may be connected:
218    * @code
219    *   Actor YourCallbackName(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocusNavigationDirection direction);
220    * @endcode
221    * @pre The Object has been initialized.
222    * @return The signal to connect to.
223    */
224   PreFocusChangeSignalV2& PreFocusChangeSignal();
225
226   /**
227    * @brief This signal is emitted after the current focused actor has been changed.
228    *
229    * A callback of the following type may be connected:
230    * @code
231    *   void YourCallbackName(Actor originalFocusedActor, Actor currentFocusedActor);
232    * @endcode
233    * @pre The Object has been initialized.
234    * @return The signal to connect to.
235    */
236   FocusChangedSignalV2& FocusChangedSignal();
237
238   /**
239    * @brief This signal is emitted when the focus group has been changed.
240    *
241    * If the current focus group has a parent layout control,
242    * KeyboardFocusManager will make the best guess for the next focus
243    * group to move the focus to in the given direction (forward or
244    * backward). If not, the application has to set the new focus.
245    *
246    * A callback of the following type may be connected:
247    * @code
248    *   void YourCallbackName(Actor currentFocusedActor, bool forward);
249    * @endcode
250    * @pre The Object has been initialized.
251    * @return The signal to connect to.
252    */
253   FocusGroupChangedSignalV2& FocusGroupChangedSignal();
254
255   /**
256    * @brief This signal is emitted when the current focused actor is activated.
257    *
258    * A callback of the following type may be connected:
259    * @code
260    *   void YourCallbackName(Actor activatedActor);
261    * @endcode
262    * @pre The Object has been initialized.
263    * @return The signal to connect to.
264    */
265   FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
266
267   // Not intended for application developers
268
269   /**
270    * @brief Creates a new handle from the implementation.
271    *
272    * @param[in] impl A pointer to the object.
273    */
274   explicit DALI_INTERNAL KeyboardFocusManager(Internal::KeyboardFocusManager *impl);
275
276 }; // class KeyboardFocusManager
277
278 } // namespace Toolkit
279
280 } // namespace Dali
281
282 /**
283  * @}
284  */
285 #endif // __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__