[dali_1.0.1] Merge branch 'tizen'
[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 Destructor
82    *
83    * This is non-virtual since derived Handle types must not contain data or virtual methods.
84    */
85   ~KeyboardFocusManager();
86
87   /**
88    * @brief Get the singleton of KeyboardFocusManager object.
89    *
90    * @return A handle to the KeyboardFocusManager control.
91    */
92   static KeyboardFocusManager Get();
93
94   /**
95    * @brief Move the keyboard focus to the given actor.
96    *
97    * Only one actor can be focused at the same time.  The actor must
98    * be in the stage already and keyboard focusable.
99    *
100    * @pre The KeyboardFocusManager has been initialized.
101    * @pre The Actor has been initialized.
102    * @param actor The actor to be focused
103    * @return Whether the focus is successful or not
104    */
105   bool SetCurrentFocusActor(Actor actor);
106
107   /**
108    * @brief Get the current focused actor.
109    *
110    * @pre The KeyboardFocusManager has been initialized.
111    * @return A handle to the current focused actor or an empty handle if no actor is focused.
112    */
113   Actor GetCurrentFocusActor();
114
115   /**
116    * @brief Move the focus to the next focusable actor in the focus
117    * chain in the given direction (according to the focus traversal
118    * order).
119    *
120    * @pre The KeyboardFocusManager has been initialized.
121    * @param direction The direction of focus movement
122    * @return true if the movement was successful
123    */
124   bool MoveFocus(Control::KeyboardFocusNavigationDirection direction);
125
126   /**
127    * @brief Clear the focus from the current focused actor if any, so
128    * that no actor is focused in the focus chain.
129    *
130    * It will emit focus changed signal without current focused actor
131    * @pre The KeyboardFocusManager has been initialized.
132    */
133   void ClearFocus();
134
135   /**
136    * @brief Set whether the focus movement should be looped within the same focus group.
137    *
138    * The focus movement is not looped by default.
139    * @pre The KeyboardFocusManager has been initialized.
140    * @param enabled Whether the focus movement should be looped
141    */
142   void SetFocusGroupLoop(bool enabled);
143
144   /**
145    * @brief Get whether the focus movement should be looped within the same focus group.
146    *
147    * @pre The KeyboardFocusManager has been initialized.
148    * @return Whether the focus movement should be looped
149    */
150   bool GetFocusGroupLoop() const;
151
152   /**
153    * @brief Set whether an actor is a focus group that can limit the
154    * scope of focus movement to its child actors in the focus chain.
155    *
156    * Layout controls set themselves as focus groups by default.
157    *
158    * @pre The KeyboardFocusManager has been initialized.
159    * @pre The Actor has been initialized.
160    * @param actor The actor to be set as a focus group.
161    * @param isFocusGroup Whether to set the actor as a focus group or not.
162    */
163   void SetAsFocusGroup(Actor actor, bool isFocusGroup);
164
165   /**
166    * @brief Check whether the actor is set as a focus group or not.
167    *
168    * @pre The KeyboardFocusManager has been initialized.
169    * @pre The Actor has been initialized.
170    * @param actor The actor to be checked.
171    * @return Whether the actor is set as a focus group.
172    */
173   bool IsFocusGroup(Actor actor) const;
174
175   /**
176    * @brief Returns the closest ancestor of the given actor that is a focus group.
177    *
178    * @param actor The actor to be checked for its focus group
179    * @return The focus group the given actor belongs to or an empty handle if the given actor
180    * doesn't belong to any focus group
181    */
182   Actor GetFocusGroup(Actor actor);
183
184   /**
185    * @brief Set the focus indicator actor.
186    *
187    * This will replace the default focus indicator actor in
188    * KeyboardFocusManager and will be added to the focused actor as a
189    * highlight.
190    *
191    * @pre The KeyboardFocusManager has been initialized.
192    * @pre The indicator actor has been initialized.
193    * @param indicator The indicator actor to be added
194    */
195   void SetFocusIndicatorActor(Actor indicator);
196
197   /**
198    * @brief Get the focus indicator actor.
199    *
200    * @pre The KeyboardFocusManager has been initialized.
201    * @return A handle to the focus indicator actor
202    */
203   Actor GetFocusIndicatorActor();
204
205 public: // Signals
206
207   /**
208    * @brief This signal is emitted before the focus is going to be changed.
209    *
210    * KeyboardFocusManager makes the best guess for which actor to
211    * focus towards the given direction, but applications might want to
212    * change that. By connecting with this signal, they can check the
213    * proposed actor to focus and return a different actor if they
214    * wish.  This signal is only emitted when the navigation key is
215    * pressed and KeyboardFocusManager tries to move the focus
216    * automatically. It won't be emitted for focus movement by calling
217    * SetCurrentFocusActor directly.
218    *
219    * A callback of the following type may be connected:
220    * @code
221    *   Actor YourCallbackName(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocusNavigationDirection direction);
222    * @endcode
223    * @pre The Object has been initialized.
224    * @return The signal to connect to.
225    */
226   PreFocusChangeSignalV2& PreFocusChangeSignal();
227
228   /**
229    * @brief This signal is emitted after the current focused actor has been changed.
230    *
231    * A callback of the following type may be connected:
232    * @code
233    *   void YourCallbackName(Actor originalFocusedActor, Actor currentFocusedActor);
234    * @endcode
235    * @pre The Object has been initialized.
236    * @return The signal to connect to.
237    */
238   FocusChangedSignalV2& FocusChangedSignal();
239
240   /**
241    * @brief This signal is emitted when the focus group has been changed.
242    *
243    * If the current focus group has a parent layout control,
244    * KeyboardFocusManager will make the best guess for the next focus
245    * group to move the focus to in the given direction (forward or
246    * backward). If not, the application has to set the new focus.
247    *
248    * A callback of the following type may be connected:
249    * @code
250    *   void YourCallbackName(Actor currentFocusedActor, bool forward);
251    * @endcode
252    * @pre The Object has been initialized.
253    * @return The signal to connect to.
254    */
255   FocusGroupChangedSignalV2& FocusGroupChangedSignal();
256
257   /**
258    * @brief This signal is emitted when the current focused actor is activated.
259    *
260    * A callback of the following type may be connected:
261    * @code
262    *   void YourCallbackName(Actor activatedActor);
263    * @endcode
264    * @pre The Object has been initialized.
265    * @return The signal to connect to.
266    */
267   FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
268
269   // Not intended for application developers
270
271   /**
272    * @brief Creates a new handle from the implementation.
273    *
274    * @param[in] impl A pointer to the object.
275    */
276   explicit DALI_INTERNAL KeyboardFocusManager(Internal::KeyboardFocusManager *impl);
277
278 }; // class KeyboardFocusManager
279
280 } // namespace Toolkit
281
282 } // namespace Dali
283
284 /**
285  * @}
286  */
287 #endif // __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__