e1d1a94c3db8ae22ebe13f8eebdd686878904af8
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / focus-manager / keyinput-focus-manager-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_KEYINPUT_FOCUS_MANAGER_H__
2 #define __DALI_TOOLKIT_INTERNAL_KEYINPUT_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 // EXTERNAL INCLUDES
22 #include <string>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/object/object-registry.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
28 #include <dali-toolkit/public-api/controls/control.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 class KeyInputFocusManager;
40
41 /**
42  * @copydoc Toolkit::KeyInputFocusManager
43  */
44 class KeyInputFocusManager : public Dali::BaseObject, public Dali::ConnectionTracker
45 {
46 public:
47   /**
48    * Construct a new KeyInputFocusManager.
49    */
50   KeyInputFocusManager();
51
52   /**
53    * @copydoc Toolkit::SetFocus
54    */
55   void SetFocus(Toolkit::Control control);
56
57   /**
58    * @copydoc Toolkit::RemoveFocus
59    */
60   void RemoveFocus(Toolkit::Control control);
61
62   /**
63    * @copydoc Toolkit::GetCurrentFocusControl
64    */
65   Toolkit::Control GetCurrentFocusControl() const;
66
67 public:
68
69   /**
70    * @copydoc Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignal()
71    */
72   Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignalType& KeyInputFocusChangedSignal();
73
74   /**
75    * Connects a callback function with the object's signals.
76    * @param[in] object The object providing the signal.
77    * @param[in] tracker Used to disconnect the signal.
78    * @param[in] signalName The signal to connect to.
79    * @param[in] functor A newly allocated FunctorDelegate.
80    * @return True if the signal was connected.
81    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
82    */
83   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
84
85 protected:
86
87   /**
88    * Destructor
89    */
90   virtual ~KeyInputFocusManager();
91
92 private:
93
94   /**
95    * Callback for the key event when no actor in the stage has gained the key input focus
96    * @param[in] event The KeyEvent event.
97    */
98   bool OnKeyEvent(const KeyEvent& event);
99
100   /**
101    * Signal handler called when a focused Control is removed from Stage.
102    * @param[in]  control  The control removed from stage.
103    */
104   void OnFocusControlStageDisconnection( Dali::Actor control );
105
106   /**
107     *  Recursively deliver events to the control and its parents, until the event is consumed or the stage is reached.
108    * @param[in]  control  The control got KeyEvent.
109    * @param[in]  event    The KeyEvent.
110    * @return True if KeyEvent is consumed.
111     */
112   bool EmitKeyEventSignal( Toolkit::Control control, const KeyEvent& event );
113
114 private:
115
116   // Undefined
117   KeyInputFocusManager(const KeyInputFocusManager&);
118
119   KeyInputFocusManager& operator=(const KeyInputFocusManager& rhs);
120
121 private:
122
123   // The key input focus change signal
124   Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignalType mKeyInputFocusChangedSignal;
125
126   SlotDelegate< KeyInputFocusManager > mSlotDelegate;
127
128   Toolkit::Control mCurrentFocusControl; ///< The current focused control
129 };
130
131 } // namespace Internal
132
133 inline Internal::KeyInputFocusManager& GetImpl(Dali::Toolkit::KeyInputFocusManager& obj)
134 {
135   DALI_ASSERT_ALWAYS(obj);
136
137   Dali::BaseObject& handle = obj.GetBaseObject();
138
139   return static_cast<Internal::KeyInputFocusManager&>(handle);
140 }
141
142 inline const Internal::KeyInputFocusManager& GetImpl(const Dali::Toolkit::KeyInputFocusManager& obj)
143 {
144   DALI_ASSERT_ALWAYS(obj);
145
146   const Dali::BaseObject& handle = obj.GetBaseObject();
147
148   return static_cast<const Internal::KeyInputFocusManager&>(handle);
149 }
150
151 } // namespace Toolkit
152
153 } // namespace Dali
154
155 #endif // __DALI_TOOLKIT_INTERNAL_KEYINPUT_FOCUS_MANAGER_H__