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