32a0d67283d2d34a5dc61159d4a93082adfb25f6
[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 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/imf-manager.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/text-controls/text-field.h>
27 #include <dali-toolkit/internal/text/clipping/text-clipper.h>
28 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
29 #include <dali-toolkit/internal/text/text-control-interface.h>
30 #include <dali-toolkit/internal/text/text-controller.h>
31 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 namespace Internal
40 {
41
42 /**
43  * @brief A control which renders a short text string.
44  */
45 class TextField : public Control, public Text::ControlInterface
46 {
47 public:
48
49   /**
50    * @copydoc Dali::Toollkit::TextField::New()
51    */
52   static Toolkit::TextField New();
53
54   // Properties
55
56   /**
57    * @brief Called when a property of an object of this type is set.
58    *
59    * @param[in] object The object whose property is set.
60    * @param[in] index The property index.
61    * @param[in] value The new property value.
62    */
63   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
64
65   /**
66    * @brief Called to retrieve a property of an object of this type.
67    *
68    * @param[in] object The object whose property is to be retrieved.
69    * @param[in] index The property index.
70    * @return The current value of the property.
71    */
72   static Property::Value GetProperty( BaseObject* object, Property::Index index );
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   /**
86    * @copydoc TextField::MaxLengthReachedSignal()
87    */
88   Toolkit::TextField::MaxLengthReachedSignalType&  MaxLengthReachedSignal();
89
90 private: // From Control
91
92   /**
93    * @copydoc Control::OnInitialize()
94    */
95   virtual void OnInitialize();
96
97   /**
98    * @copydoc Control::OnStyleChange()
99    */
100   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
101
102   /**
103    * @copydoc Control::GetNaturalSize()
104    */
105   virtual Vector3 GetNaturalSize();
106
107   /**
108    * @copydoc Control::GetHeightForWidth()
109    */
110   virtual float GetHeightForWidth( float width );
111
112   /**
113    * @copydoc Control::OnInitialize()
114    */
115   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
116
117   /**
118    * @copydoc Control::OnKeyInputFocusGained()
119    */
120   virtual void OnKeyInputFocusGained();
121
122   /**
123    * @copydoc Control::OnKeyInputFocusLost()
124    */
125   virtual void OnKeyInputFocusLost();
126
127   /**
128    * @copydoc Control::OnTap()
129    */
130   virtual void OnTap( const TapGesture& tap );
131
132   /**
133    * @copydoc Control::OnPan()
134    */
135   virtual void OnPan( const PanGesture& gesture );
136
137   /**
138    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
139    */
140   virtual bool OnKeyEvent(const KeyEvent& event);
141
142   /**
143    * @brief Event received from IMF manager
144    *
145    * @param[in] imfManager The IMF manager.
146    * @param[in] imfEvent The event received.
147    * @return A data struture indicating if update is needed, cursor position and current text.
148    */
149   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
150
151   /**
152    * @copydoc Text::ControlInterface::RequestTextRelayout()
153    */
154   virtual void RequestTextRelayout();
155
156   /**
157    * @copydoc Text::ControlInterface::MaxLengthReached()
158    */
159   virtual void MaxLengthReached();
160
161 private: // Implementation
162
163   /**
164    * @brief Enable or disable clipping.
165    *
166    * @param[in] clipping True if clipping should be enabled.
167    * @param[in] size The area to clip within.
168    */
169   void EnableClipping( bool clipping, const Vector2& size );
170
171   /**
172    * @brief Callback when keyboard is shown/hidden.
173    *
174    * @param[in] keyboardShown True if keyboard is shown.
175    */
176   void KeyboardStatusChanged( bool keyboardShown );
177
178   /**
179    * @brief Callback when Textfield is touched
180    *
181    * @param[in] actor TextField touched
182    * @param[in] event TouchEvent information
183    */
184   bool OnTouched( Actor actor, const TouchEvent& event );
185
186   /**
187    * Construct a new TextField.
188    */
189   TextField();
190
191   /**
192    * A reference counted object may only be deleted by calling Unreference()
193    */
194   virtual ~TextField();
195
196   // Undefined copy constructor and assignment operators
197   TextField(const TextField&);
198   TextField& operator=(const TextField& rhs);
199
200 private: // Data
201
202   // Signals
203   Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
204
205   Text::ControllerPtr mController;
206   Text::RendererPtr mRenderer;
207   Text::DecoratorPtr mDecorator;
208   Text::ClipperPtr mClipper; ///< For EXCEED_POLICY_CLIP
209
210   RenderableActor mRenderableActor;
211
212   int mRenderingBackend;
213   int mExceedPolicy;
214 };
215
216 } // namespace Internal
217
218 // Helpers for public-api forwarding methods
219
220 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
221 {
222   DALI_ASSERT_ALWAYS(textField);
223
224   Dali::RefObject& handle = textField.GetImplementation();
225
226   return static_cast<Toolkit::Internal::TextField&>(handle);
227 }
228
229 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
230 {
231   DALI_ASSERT_ALWAYS(textField);
232
233   const Dali::RefObject& handle = textField.GetImplementation();
234
235   return static_cast<const Toolkit::Internal::TextField&>(handle);
236 }
237
238 } // namespace Toolkit
239
240 } // namespace Dali
241
242 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H__