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