Merge "Implement scroll bar in the TextEditor" 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/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 private: // From Control
99
100   /**
101    * @copydoc Control::OnInitialize()
102    */
103   virtual void OnInitialize();
104
105   /**
106    * @copydoc Control::OnStyleChange()
107    */
108   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
109
110   /**
111    * @copydoc Control::GetNaturalSize()
112    */
113   virtual Vector3 GetNaturalSize();
114
115   /**
116    * @copydoc Control::GetHeightForWidth()
117    */
118   virtual float GetHeightForWidth( float width );
119
120   /**
121    * @copydoc Control::OnInitialize()
122    */
123   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
124
125   /**
126    * @copydoc Control::OnKeyInputFocusGained()
127    */
128   virtual void OnKeyInputFocusGained();
129
130   /**
131    * @copydoc Control::OnKeyInputFocusLost()
132    */
133   virtual void OnKeyInputFocusLost();
134
135   /**
136    * @copydoc Control::OnTap()
137    */
138   virtual void OnTap( const TapGesture& tap );
139
140   /**
141    * @copydoc Control::OnPan()
142    */
143   virtual void OnPan( const PanGesture& gesture );
144
145   /**
146    * @copydoc Control::OnLongPress()
147    */
148   virtual void OnLongPress( const LongPressGesture& gesture );
149
150   /**
151    * @copydoc Control::OnStageConnection()
152    */
153   virtual void OnStageConnection( int depth );
154
155   /**
156    * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
157    */
158   virtual bool OnKeyEvent(const KeyEvent& event);
159
160 // From ControlInterface
161
162   /**
163    * @copydoc Text::ControlInterface::RequestTextRelayout()
164    */
165   virtual void RequestTextRelayout();
166
167 // From EditableControlInterface
168
169   /**
170    * @copydoc Text::ControlInterface::TextChanged()
171    */
172   virtual void TextChanged();
173
174   /**
175    * @copydoc Text::ControlInterface::MaxLengthReached()
176    */
177   virtual void MaxLengthReached();
178
179   /**
180    * @copydoc Text::ControlInterface::InputStyleChanged()
181    */
182   virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
183
184   /**
185    * @copydoc Text::ControlInterface::AddDecoration()
186    */
187   virtual void AddDecoration( Actor& actor, bool needsClipping );
188
189 private: // Implementation
190
191   /**
192    * @copydoc Dali::Toolkit::Text::Controller::(ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent)
193    */
194   ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent );
195
196   /**
197    * @brief Callback when Clipboard signals an item should be pasted
198    * @param[in] clipboard handle to Clipboard Event Notifier
199    */
200   void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
201
202   /**
203    * @brief Get a Property Map for the image used for the required Handle Image
204    * @param[out] value the returned image property
205    * @param[in] handleType the type of handle
206    * @param[in] handleImageType the type of image for the given handleType
207    */
208   void GetHandleImagePropertyValue(  Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
209
210   /**
211    * @brief Callback when keyboard is shown/hidden.
212    *
213    * @param[in] keyboardShown True if keyboard is shown.
214    */
215   void KeyboardStatusChanged( bool keyboardShown );
216
217   /**
218    * @brief update scroll bar position
219    *
220    * If text scroll is occurred, create or update scroll bar position
221    */
222   void UpdateScrollBar();
223
224   /**
225    * @brief Callback when TextEditor is touched
226    *
227    * @param[in] actor TextEditor touched
228    * @param[in] touch Touch information
229    */
230   bool OnTouched( Actor actor, const TouchData& touch );
231
232   /**
233    * @brief Callbacks called on idle.
234    *
235    * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
236    */
237   void OnIdleSignal();
238
239   /**
240    * @brief set RenderActor's position with new scrollPosition
241    *
242    * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
243    */
244   void ApplyScrollPosition();
245
246   /**
247    * Construct a new TextEditor.
248    */
249   TextEditor();
250
251   /**
252    * A reference counted object may only be deleted by calling Unreference()
253    */
254   virtual ~TextEditor();
255
256   // Undefined copy constructor and assignment operators
257   TextEditor(const TextEditor&);
258   TextEditor& operator=(const TextEditor& rhs);
259
260   /**
261    * @brief Render view, create and attach actor(s) to this text editor.
262    */
263   void RenderText( Text::Controller::UpdateTextType updateTextType );
264
265   // Connection needed to re-render text, when a text editor returns to the stage.
266   void OnStageConnect( Dali::Actor actor );
267
268 private: // Data
269   // Signals
270   Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
271   Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
272
273   ImfManager          mImfManager;
274   Text::ControllerPtr mController;
275   Text::RendererPtr mRenderer;
276   Text::DecoratorPtr mDecorator;
277   Text::TextVerticalScrollerPtr mTextVerticalScroller;
278   Toolkit::Control mStencil;
279   Toolkit::ScrollBar mScrollBar;
280   Dali::Animation mAnimation;                                              ///< Scroll indicator Show/Hide Animation.
281   Dali::TimePeriod mAnimationPeriod;
282   std::vector<Actor> mClippingDecorationActors;   ///< Decoration actors which need clipping.
283
284   Actor mRenderableActor;
285   CallbackBase* mIdleCallback;
286
287   float mAlignmentOffset;
288   float mScrollAnimationDuration;
289   int mRenderingBackend;
290   bool mHasBeenStaged:1;
291   bool mScrollAnimationEnabled:1;
292   bool mScrollBarEnabled:1;
293 };
294
295 } // namespace Internal
296
297 // Helpers for public-api forwarding methods
298
299 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
300 {
301   DALI_ASSERT_ALWAYS(textEditor);
302
303   Dali::RefObject& handle = textEditor.GetImplementation();
304
305   return static_cast<Toolkit::Internal::TextEditor&>(handle);
306 }
307
308 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
309 {
310   DALI_ASSERT_ALWAYS(textEditor);
311
312   const Dali::RefObject& handle = textEditor.GetImplementation();
313
314   return static_cast<const Toolkit::Internal::TextEditor&>(handle);
315 }
316
317 } // namespace Toolkit
318
319 } // namespace Dali
320
321 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H