Fixes for the text controller.
[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/public-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   typedef Dali::Vector< Dali::BaseObject* > FocusStack;
48   typedef FocusStack::Iterator FocusStackIterator;
49
50   /**
51    * Construct a new KeyInputFocusManager.
52    */
53   KeyInputFocusManager();
54
55   /**
56    * @copydoc Toolkit::SetFocus
57    */
58   void SetFocus(Toolkit::Control control);
59
60   /**
61    * @copydoc Toolkit::RemoveFocus
62    */
63   void RemoveFocus(Toolkit::Control control);
64
65   /**
66    * @copydoc Toolkit::GetCurrentFocusControl
67    */
68   Toolkit::Control GetCurrentFocusControl() const;
69
70   /**
71    * @copydoc Toolkit::IsKeyboardListener
72    */
73   bool IsKeyboardListener(Toolkit::Control control) const;
74
75 public:
76
77   /**
78    * @copydoc Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignal()
79    */
80   Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignalType& KeyInputFocusChangedSignal();
81
82   /**
83    * @copydoc Toolkit::KeyInputFocusManager::UnhandledKeyEventSignal()
84    */
85   Toolkit::KeyInputFocusManager::UnhandledKeyEventSignalType& UnhandledKeyEventSignal();
86
87   /**
88    * Connects a callback function with the object's signals.
89    * @param[in] object The object providing the signal.
90    * @param[in] tracker Used to disconnect the signal.
91    * @param[in] signalName The signal to connect to.
92    * @param[in] functor A newly allocated FunctorDelegate.
93    * @return True if the signal was connected.
94    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
95    */
96   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
97
98 protected:
99
100   /**
101    * Destructor
102    */
103   virtual ~KeyInputFocusManager();
104
105 private:
106
107   /**
108    * Search for a control in the focus stack.
109    * @param[in] control The control for which to search
110    * @return An iterator to the control. If not found, this will equate to the
111    * mFocusStack.End() iterator.
112    */
113   FocusStackIterator FindFocusControlInStack( Toolkit::Control control ) const;
114
115   /**
116    * Callback for the key event when no actor in the stage has gained the key input focus
117    * @param[in] event The KeyEvent event.
118    */
119   void OnKeyEvent(const KeyEvent& event);
120
121   /**
122    * Signal handler called when a focused Control is removed from Stage.
123    * @param[in]  control  The control removed from stage.
124    */
125   void OnFocusControlStageDisconnection( Dali::Actor control );
126
127   /**
128    * Signal handler called when an actor is destroyed.
129    */
130   void OnObjectDestroyed(const Dali::RefObject* object);
131
132 private:
133
134   // Undefined
135   KeyInputFocusManager(const KeyInputFocusManager&);
136
137   KeyInputFocusManager& operator=(const KeyInputFocusManager& rhs);
138
139 private:
140
141   // The key input focus change signal
142   Toolkit::KeyInputFocusManager::KeyInputFocusChangedSignalType mKeyInputFocusChangedSignal;
143
144   // The un-handled key event signal
145   Toolkit::KeyInputFocusManager::UnhandledKeyEventSignalType mUnhandledKeyEventSignal;
146
147   // Keyboard events are sent to the current focus actor, which will be the actor on the top of the focus actors stack.
148   FocusStack mFocusStack;
149   SlotDelegate< KeyInputFocusManager > mSlotDelegate;
150   ObjectRegistry mObjectRegistry;
151 };
152
153 } // namespace Internal
154
155 inline Internal::KeyInputFocusManager& GetImpl(Dali::Toolkit::KeyInputFocusManager& obj)
156 {
157   DALI_ASSERT_ALWAYS(obj);
158
159   Dali::BaseObject& handle = obj.GetBaseObject();
160
161   return static_cast<Internal::KeyInputFocusManager&>(handle);
162 }
163
164 inline const Internal::KeyInputFocusManager& GetImpl(const Dali::Toolkit::KeyInputFocusManager& obj)
165 {
166   DALI_ASSERT_ALWAYS(obj);
167
168   const Dali::BaseObject& handle = obj.GetBaseObject();
169
170   return static_cast<const Internal::KeyInputFocusManager&>(handle);
171 }
172
173 } // namespace Toolkit
174
175 } // namespace Dali
176
177 #endif // __DALI_TOOLKIT_INTERNAL_KEYINPUT_FOCUS_MANAGER_H__