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