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