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