a3058806956dc7b26760d7e40a4c81498ddc564f
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
24 #include <dali-toolkit/internal/text/clipping/text-clipper.h>
25 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
26 #include <dali-toolkit/internal/text/text-control-interface.h>
27 #include <dali-toolkit/internal/text/text-controller.h>
28 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * @brief A control which renders a short text string.
41  */
42 class TextField : public Control, public Text::ControlInterface
43 {
44 public:
45
46   /**
47    * @copydoc Dali::Toollkit::TextField::New()
48    */
49   static Toolkit::TextField New();
50
51   // Properties
52
53   /**
54    * @brief Called when a property of an object of this type is set.
55    *
56    * @param[in] object The object whose property is set.
57    * @param[in] index The property index.
58    * @param[in] value The new property value.
59    */
60   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
61
62   /**
63    * @brief Called to retrieve a property of an object of this type.
64    *
65    * @param[in] object The object whose property is to be retrieved.
66    * @param[in] index The property index.
67    * @return The current value of the property.
68    */
69   static Property::Value GetProperty( BaseObject* object, Property::Index index );
70
71   /**
72    * Connects a callback function with the object's signals.
73    * @param[in] object The object providing the signal.
74    * @param[in] tracker Used to disconnect the signal.
75    * @param[in] signalName The signal to connect to.
76    * @param[in] functor A newly allocated FunctorDelegate.
77    * @return True if the signal was connected.
78    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
79    */
80   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
81
82   /**
83    * @copydoc TextField::TextChangedSignal()
84    */
85   Toolkit::TextField::TextChangedSignalType&  TextChangedSignal();
86
87   /**
88    * @copydoc TextField::MaxLengthReachedSignal()
89    */
90   Toolkit::TextField::MaxLengthReachedSignalType&  MaxLengthReachedSignal();
91
92 private: // From Control
93
94   /**
95    * @copydoc Control::OnInitialize()
96    */
97   virtual void OnInitialize();
98
99   /**
100    * @copydoc Control::OnStyleChange()
101    */
102   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
103
104   /**
105    * @copydoc Control::GetNaturalSize()
106    */
107   virtual Vector3 GetNaturalSize();
108
109   /**
110    * @copydoc Control::GetHeightForWidth()
111    */
112   virtual float GetHeightForWidth( float width );
113
114   /**
115    * @copydoc Control::OnInitialize()
116    */
117   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
118
119   /**
120    * @copydoc Control::OnKeyInputFocusGained()
121    */
122   virtual void OnKeyInputFocusGained();
123
124   /**
125    * @copydoc Control::OnKeyInputFocusLost()
126    */
127   virtual void OnKeyInputFocusLost();
128
129   /**
130    * @copydoc Control::OnTap()
131    */
132   virtual void OnTap( const TapGesture& tap );
133
134   /**
135    * @copydoc Control::OnPan()
136    */
137   virtual void OnPan( const PanGesture& gesture );
138
139   /**
140    * @copydoc Control::OnStageConnection()
141    */
142   virtual void OnStageConnection( unsigned int depth );
143
144   /**
145    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
146    */
147   virtual bool OnKeyEvent(const KeyEvent& event);
148
149   /**
150    * @copydoc Text::ControlInterface::AddDecoration()
151    */
152   virtual void AddDecoration( Actor& actor, bool needsClipping );
153
154   /**
155    * @copydoc Text::ControlInterface::RequestTextRelayout()
156    */
157   virtual void RequestTextRelayout();
158
159   /**
160    * @copydoc Text::ControlInterface::TextChanged()
161    */
162   virtual void TextChanged();
163
164   /**
165    * @copydoc Text::ControlInterface::MaxLengthReached()
166    */
167   virtual void MaxLengthReached();
168
169   /**
170    * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
171    */
172   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
173
174 private: // Implementation
175
176   /**
177    * @brief Enable or disable clipping.
178    *
179    * @param[in] clipping True if clipping should be enabled.
180    * @param[in] size The area to clip within.
181    */
182   void EnableClipping( bool clipping, const Vector2& size );
183
184   /**
185    * @brief Callback when keyboard is shown/hidden.
186    *
187    * @param[in] keyboardShown True if keyboard is shown.
188    */
189   void KeyboardStatusChanged( bool keyboardShown );
190
191   /**
192    * @brief Callback when Textfield is touched
193    *
194    * @param[in] actor TextField touched
195    * @param[in] event TouchEvent information
196    */
197   bool OnTouched( Actor actor, const TouchEvent& event );
198
199   /**
200    * Construct a new TextField.
201    */
202   TextField();
203
204   /**
205    * A reference counted object may only be deleted by calling Unreference()
206    */
207   virtual ~TextField();
208
209   // Undefined copy constructor and assignment operators
210   TextField(const TextField&);
211   TextField& operator=(const TextField& rhs);
212
213   /**
214    * @brief Render view, create and attach actor(s) to this Text Field.
215    */
216   void RenderText();
217
218   // Connection needed to re-render text, when a Text Field returns to the stage.
219   void OnStageConnect( Dali::Actor actor );
220
221 private: // Data
222
223   // Signals
224   Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
225   Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
226
227   Text::ControllerPtr mController;
228   Text::RendererPtr mRenderer;
229   Text::DecoratorPtr mDecorator;
230   Text::ClipperPtr mClipper; ///< For EXCEED_POLICY_CLIP
231   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
232
233   Actor mRenderableActor;
234
235   int mRenderingBackend;
236   int mExceedPolicy;
237   unsigned int mDepth;
238   bool mHasBeenStaged:1;
239 };
240
241 } // namespace Internal
242
243 // Helpers for public-api forwarding methods
244
245 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
246 {
247   DALI_ASSERT_ALWAYS(textField);
248
249   Dali::RefObject& handle = textField.GetImplementation();
250
251   return static_cast<Toolkit::Internal::TextField&>(handle);
252 }
253
254 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
255 {
256   DALI_ASSERT_ALWAYS(textField);
257
258   const Dali::RefObject& handle = textField.GetImplementation();
259
260   return static_cast<const Toolkit::Internal::TextField&>(handle);
261 }
262
263 } // namespace Toolkit
264
265 } // namespace Dali
266
267 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__