TextVisual implementation.
[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) 2016 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/clipboard-event-notifier.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-editable-control-interface.h>
31 #include <dali-toolkit/internal/text/text-controller.h>
32 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
33
34 namespace Dali
35 {
36
37 namespace Toolkit
38 {
39
40 namespace Internal
41 {
42
43 /**
44  * @brief A control which renders a short text string.
45  */
46 class TextField : public Control, public Text::ControlInterface, public Text::EditableControlInterface
47 {
48 public:
49
50   /**
51    * @copydoc Dali::Toollkit::TextField::New()
52    */
53   static Toolkit::TextField New();
54
55   // Properties
56
57   /**
58    * @brief Called when a property of an object of this type is set.
59    *
60    * @param[in] object The object whose property is set.
61    * @param[in] index The property index.
62    * @param[in] value The new property value.
63    */
64   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
65
66   /**
67    * @brief Called to retrieve a property of an object of this type.
68    *
69    * @param[in] object The object whose property is to be retrieved.
70    * @param[in] index The property index.
71    * @return The current value of the property.
72    */
73   static Property::Value GetProperty( BaseObject* object, Property::Index index );
74
75   /**
76    * Connects a callback function with the object's signals.
77    * @param[in] object The object providing the signal.
78    * @param[in] tracker Used to disconnect the signal.
79    * @param[in] signalName The signal to connect to.
80    * @param[in] functor A newly allocated FunctorDelegate.
81    * @return True if the signal was connected.
82    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
83    */
84   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
85
86   /**
87    * @copydoc TextField::TextChangedSignal()
88    */
89   Toolkit::TextField::TextChangedSignalType&  TextChangedSignal();
90
91   /**
92    * @copydoc TextField::MaxLengthReachedSignal()
93    */
94   Toolkit::TextField::MaxLengthReachedSignalType&  MaxLengthReachedSignal();
95
96   /**
97    * @copydoc TextField::TextChangedSignal()
98    */
99   Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal();
100
101 private: // From Control
102
103   /**
104    * @copydoc Control::OnInitialize()
105    */
106   virtual void OnInitialize();
107
108   /**
109    * @copydoc Control::OnStyleChange()
110    */
111   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
112
113   /**
114    * @copydoc Control::GetNaturalSize()
115    */
116   virtual Vector3 GetNaturalSize();
117
118   /**
119    * @copydoc Control::GetHeightForWidth()
120    */
121   virtual float GetHeightForWidth( float width );
122
123   /**
124    * @copydoc Control::OnInitialize()
125    */
126   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
127
128   /**
129    * @copydoc Control::OnKeyInputFocusGained()
130    */
131   virtual void OnKeyInputFocusGained();
132
133   /**
134    * @copydoc Control::OnKeyInputFocusLost()
135    */
136   virtual void OnKeyInputFocusLost();
137
138   /**
139    * @copydoc Control::OnTap()
140    */
141   virtual void OnTap( const TapGesture& tap );
142
143   /**
144    * @copydoc Control::OnPan()
145    */
146   virtual void OnPan( const PanGesture& gesture );
147
148   /**
149    * @copydoc Control::OnLongPress()
150    */
151   virtual void OnLongPress( const LongPressGesture& gesture );
152
153   /**
154    * @copydoc Control::OnStageConnection()
155    */
156   virtual void OnStageConnection( int depth );
157
158   /**
159    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
160    */
161   virtual bool OnKeyEvent(const KeyEvent& event);
162
163 // From ControlInterface
164
165   /**
166    * @copydoc Text::ControlInterface::RequestTextRelayout()
167    */
168   virtual void RequestTextRelayout();
169
170 // From EditableControlInterface
171
172   /**
173    * @copydoc Text::ControlInterface::TextChanged()
174    */
175   virtual void TextChanged();
176
177   /**
178    * @copydoc Text::ControlInterface::MaxLengthReached()
179    */
180   virtual void MaxLengthReached();
181
182   /**
183    * @copydoc Text::ControlInterface::InputStyleChanged()
184    */
185   virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
186
187   /**
188    * @copydoc Text::ControlInterface::AddDecoration()
189    */
190   virtual void AddDecoration( Actor& actor, bool needsClipping );
191
192 private: // Implementation
193
194   /**
195    * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
196    */
197   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
198
199   /**
200    * @brief Callback when Clipboard signals an item should be pasted
201    * @param[in] clipboard handle to Clipboard Event Notifier
202    */
203   void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
204
205   /**
206    * @brief Get a Property Map for the image used for the required Handle Image
207    * @param[out] value the returned image property
208    * @param[in] handleType the type of handle
209    * @param[in] handleImageType the type of image for the given handleType
210    */
211   void GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
212
213   /**
214    * @brief Enable or disable clipping.
215    *
216    * @param[in] size The area to clip within.
217    */
218   void EnableClipping( const Vector2& size );
219
220   /**
221    * @brief Callback when keyboard is shown/hidden.
222    *
223    * @param[in] keyboardShown True if keyboard is shown.
224    */
225   void KeyboardStatusChanged( bool keyboardShown );
226
227   /**
228    * @brief Callback when TextField is touched
229    *
230    * @param[in] actor TextField touched
231    * @param[in] touch Touch information
232    */
233   bool OnTouched( Actor actor, const TouchData& touch );
234
235   /**
236    * @brief Callbacks called on idle.
237    *
238    * If there are notifications of change of input style on the queue, Toolkit::TextField::InputStyleChangedSignal() are emitted.
239    */
240   void OnIdleSignal();
241
242   /**
243    * Construct a new TextField.
244    */
245   TextField();
246
247   /**
248    * A reference counted object may only be deleted by calling Unreference()
249    */
250   virtual ~TextField();
251
252   // Undefined copy constructor and assignment operators
253   TextField(const TextField&);
254   TextField& operator=(const TextField& rhs);
255
256   /**
257    * @brief Render view, create and attach actor(s) to this Text Field.
258    */
259   void RenderText( Text::Controller::UpdateTextType updateTextType );
260
261   // Connection needed to re-render text, when a Text Field returns to the stage.
262   void OnStageConnect( Dali::Actor actor );
263
264 private: // Data
265
266   // Signals
267   Toolkit::TextField::TextChangedSignalType mTextChangedSignal;
268   Toolkit::TextField::MaxLengthReachedSignalType mMaxLengthReachedSignal;
269   Toolkit::TextField::InputStyleChangedSignalType mInputStyleChangedSignal;
270
271   Text::ControllerPtr mController;
272   Text::RendererPtr mRenderer;
273   Text::DecoratorPtr mDecorator;
274   Text::ClipperPtr mClipper; ///< For EXCEED_POLICY_CLIP
275   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
276
277   Actor mRenderableActor;
278   CallbackBase* mIdleCallback;
279
280   int mRenderingBackend;
281   int mExceedPolicy;
282   bool mHasBeenStaged:1;
283 };
284
285 } // namespace Internal
286
287 // Helpers for public-api forwarding methods
288
289 inline Toolkit::Internal::TextField& GetImpl( Toolkit::TextField& textField )
290 {
291   DALI_ASSERT_ALWAYS(textField);
292
293   Dali::RefObject& handle = textField.GetImplementation();
294
295   return static_cast<Toolkit::Internal::TextField&>(handle);
296 }
297
298 inline const Toolkit::Internal::TextField& GetImpl( const Toolkit::TextField& textField )
299 {
300   DALI_ASSERT_ALWAYS(textField);
301
302   const Dali::RefObject& handle = textField.GetImplementation();
303
304   return static_cast<const Toolkit::Internal::TextField&>(handle);
305 }
306
307 } // namespace Toolkit
308
309 } // namespace Dali
310
311 #endif // DALI_TOOLKIT_INTERNAL_TEXT_FIELD_H