1 #ifndef __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @addtogroup CAPI_DALI_TOOLKIT_FOCUS_MANAGER_MODULE
27 #include <dali/dali.h>
28 #include <dali-toolkit/public-api/controls/control.h>
30 namespace Dali DALI_IMPORT_API
36 namespace Internal DALI_INTERNAL
38 class KeyboardFocusManager;
42 * @brief Provides the functionality of handling keyboard navigation
43 * and maintaining the two dimensional keyboard focus chain.
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
50 class KeyboardFocusManager : public BaseHandle
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"
61 /// @brief Pre focus change signal
62 typedef SignalV2< Actor ( Actor, Actor, Control::KeyboardFocusNavigationDirection ) > PreFocusChangeSignalV2;
64 /// @brief Focus changed signal
65 typedef SignalV2< void ( Actor, Actor ) > FocusChangedSignalV2;
67 /// @brief Focus group changed signal
68 typedef SignalV2< void ( Actor, bool ) > FocusGroupChangedSignalV2;
70 /// @brief Focused actor activated signal
71 typedef SignalV2< void ( Actor ) > FocusedActorActivatedSignalV2;
74 * @brief Create a KeyboardFocusManager handle; this can be initialised with KeyboardFocusManager::New().
76 * Calling member functions with an uninitialised handle is not allowed.
78 KeyboardFocusManager();
81 * @brief Virtual destructor.
83 virtual ~KeyboardFocusManager();
86 * @brief Get the singleton of KeyboardFocusManager object.
88 * @return A handle to the KeyboardFocusManager control.
90 static KeyboardFocusManager Get();
93 * @brief Move the keyboard focus to the given actor.
95 * Only one actor can be focused at the same time. The actor must
96 * be in the stage already and keyboard focusable.
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
103 bool SetCurrentFocusActor(Actor actor);
106 * @brief Get the current focused actor.
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.
111 Actor GetCurrentFocusActor();
114 * @brief Move the focus to the next focusable actor in the focus
115 * chain in the given direction (according to the focus traversal
118 * @pre The KeyboardFocusManager has been initialized.
119 * @param direction The direction of focus movement
120 * @return true if the movement was successful
122 bool MoveFocus(Control::KeyboardFocusNavigationDirection direction);
125 * @brief Clear the focus from the current focused actor if any, so
126 * that no actor is focused in the focus chain.
128 * It will emit focus changed signal without current focused actor
129 * @pre The KeyboardFocusManager has been initialized.
134 * @brief Set whether the focus movement should be looped within the same focus group.
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
140 void SetFocusGroupLoop(bool enabled);
143 * @brief Get whether the focus movement should be looped within the same focus group.
145 * @pre The KeyboardFocusManager has been initialized.
146 * @return Whether the focus movement should be looped
148 bool GetFocusGroupLoop() const;
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.
154 * Layout controls set themselves as focus groups by default.
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.
161 void SetAsFocusGroup(Actor actor, bool isFocusGroup);
164 * @brief Check whether the actor is set as a focus group or not.
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.
171 bool IsFocusGroup(Actor actor) const;
174 * @brief Returns the closest ancestor of the given actor that is a focus group.
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
180 Actor GetFocusGroup(Actor actor);
183 * @brief Set the focus indicator actor.
185 * This will replace the default focus indicator actor in
186 * KeyboardFocusManager and will be added to the focused actor as a
189 * @pre The KeyboardFocusManager has been initialized.
190 * @pre The indicator actor has been initialized.
191 * @param indicator The indicator actor to be added
193 void SetFocusIndicatorActor(Actor indicator);
196 * @brief Get the focus indicator actor.
198 * @pre The KeyboardFocusManager has been initialized.
199 * @return A handle to the focus indicator actor
201 Actor GetFocusIndicatorActor();
206 * @brief This signal is emitted before the focus is going to be changed.
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.
217 * A callback of the following type may be connected:
219 * Actor YourCallbackName(Actor currentFocusedActor, Actor proposedActorToFocus, Control::KeyboardFocusNavigationDirection direction);
221 * @pre The Object has been initialized.
222 * @return The signal to connect to.
224 PreFocusChangeSignalV2& PreFocusChangeSignal();
227 * @brief This signal is emitted after the current focused actor has been changed.
229 * A callback of the following type may be connected:
231 * void YourCallbackName(Actor originalFocusedActor, Actor currentFocusedActor);
233 * @pre The Object has been initialized.
234 * @return The signal to connect to.
236 FocusChangedSignalV2& FocusChangedSignal();
239 * @brief This signal is emitted when the focus group has been changed.
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.
246 * A callback of the following type may be connected:
248 * void YourCallbackName(Actor currentFocusedActor, bool forward);
250 * @pre The Object has been initialized.
251 * @return The signal to connect to.
253 FocusGroupChangedSignalV2& FocusGroupChangedSignal();
256 * @brief This signal is emitted when the current focused actor is activated.
258 * A callback of the following type may be connected:
260 * void YourCallbackName(Actor activatedActor);
262 * @pre The Object has been initialized.
263 * @return The signal to connect to.
265 FocusedActorActivatedSignalV2& FocusedActorActivatedSignal();
267 // Not intended for application developers
270 * @brief Creates a new handle from the implementation.
272 * @param[in] impl A pointer to the object.
274 explicit DALI_INTERNAL KeyboardFocusManager(Internal::KeyboardFocusManager *impl);
276 }; // class KeyboardFocusManager
278 } // namespace Toolkit
285 #endif // __DALI_TOOLKIT_KEYBOARD_FOCUS_MANAGER_H__