1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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/devel-api/controls/text-controls/text-editor-devel.h>
31 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
32 #include <dali-toolkit/internal/text/text-control-interface.h>
33 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
34 #include <dali-toolkit/internal/text/text-controller.h>
35 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
36 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
47 * @brief A control which renders a long text string with styles.
49 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface
54 * @copydoc Dali::Toollkit::TextEditor::New()
56 static Toolkit::TextEditor New();
61 * @brief Called when a property of an object of this type is set.
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.
67 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
70 * @brief Called to retrieve a property of an object of this type.
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.
76 static Property::Value GetProperty( BaseObject* object, Property::Index index );
79 * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
81 InputMethodContext GetInputMethodContext();
84 * @copydoc Dali::Toollkit::TextEditor::MaxLengthReachedSignal()
86 DevelTextEditor::MaxLengthReachedSignalType& MaxLengthReachedSignal();
89 * Connects a callback function with the object's signals.
90 * @param[in] object The object providing the signal.
91 * @param[in] tracker Used to disconnect the signal.
92 * @param[in] signalName The signal to connect to.
93 * @param[in] functor A newly allocated FunctorDelegate.
94 * @return True if the signal was connected.
95 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
97 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
100 * @copydoc TextEditor::TextChangedSignal()
102 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
105 * @copydoc TextEditor::TextChangedSignal()
107 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
110 * @copydoc TextEditor::ScrollStateChangedSignal()
112 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
114 private: // From Control
117 * @copydoc Control::OnInitialize()
119 virtual void OnInitialize();
122 * @copydoc Control::OnStyleChange()
124 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
127 * @copydoc Control::GetNaturalSize()
129 virtual Vector3 GetNaturalSize();
132 * @copydoc Control::GetHeightForWidth()
134 virtual float GetHeightForWidth( float width );
137 * @copydoc Control::OnInitialize()
139 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
142 * @copydoc Control::OnKeyInputFocusGained()
144 virtual void OnKeyInputFocusGained();
147 * @copydoc Control::OnKeyInputFocusLost()
149 virtual void OnKeyInputFocusLost();
152 * @copydoc Control::OnTap()
154 virtual void OnTap( const TapGesture& tap );
157 * @copydoc Control::OnPan()
159 virtual void OnPan( const PanGesture& gesture );
162 * @copydoc Control::OnLongPress()
164 virtual void OnLongPress( const LongPressGesture& gesture );
167 * @copydoc Control::OnSceneConnection()
169 virtual void OnSceneConnection( int depth );
172 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
174 virtual bool OnKeyEvent(const KeyEvent& event);
176 // From ControlInterface
179 * @copydoc Text::ControlInterface::RequestTextRelayout()
181 virtual void RequestTextRelayout();
183 // From EditableControlInterface
186 * @copydoc Text::ControlInterface::TextChanged()
188 virtual void TextChanged();
191 * @copydoc Text::ControlInterface::MaxLengthReached()
193 virtual void MaxLengthReached();
196 * @copydoc Text::ControlInterface::InputStyleChanged()
198 virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
201 * @copydoc Text::ControlInterface::AddDecoration()
203 virtual void AddDecoration( Actor& actor, bool needsClipping );
205 private: // Implementation
208 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
210 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
213 * @brief Callback when Clipboard signals an item should be pasted
214 * @param[in] clipboard handle to Clipboard Event Notifier
216 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
219 * @brief Get a Property Map for the image used for the required Handle Image
220 * @param[out] value the returned image property
221 * @param[in] handleType the type of handle
222 * @param[in] handleImageType the type of image for the given handleType
224 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
227 * @brief Callback when keyboard is shown/hidden.
229 * @param[in] keyboardShown True if keyboard is shown.
231 void KeyboardStatusChanged( bool keyboardShown );
234 * @brief update scroll bar position
236 * If text scroll is occurred, create or update scroll bar position
238 void UpdateScrollBar();
241 * @brief Callback when TextEditor is touched
243 * @param[in] actor TextEditor touched
244 * @param[in] touch Touch information
246 bool OnTouched( Actor actor, const TouchEvent& touch );
249 * @brief Callbacks called on idle.
251 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
256 * @brief set RenderActor's position with new scrollPosition
258 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
260 void ApplyScrollPosition();
263 * @brief Callback function for ScrollBar indicator animation finished signal
265 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
267 void OnScrollIndicatorAnimationFinished( Animation& animation );
270 * Construct a new TextEditor.
275 * A reference counted object may only be deleted by calling Unreference()
277 virtual ~TextEditor();
279 // Undefined copy constructor and assignment operators
280 TextEditor(const TextEditor&);
281 TextEditor& operator=(const TextEditor& rhs);
284 * @brief Render view, create and attach actor(s) to this text editor.
286 void RenderText( Text::Controller::UpdateTextType updateTextType );
288 // Connection needed to re-render text, when a text editor returns to the scene.
289 void OnSceneConnect( Dali::Actor actor );
293 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
294 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
295 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
296 Toolkit::DevelTextEditor::MaxLengthReachedSignalType mMaxLengthReachedSignal;
298 InputMethodContext mInputMethodContext;
299 Text::ControllerPtr mController;
300 Text::RendererPtr mRenderer;
301 Text::DecoratorPtr mDecorator;
302 Text::TextVerticalScrollerPtr mTextVerticalScroller;
303 Toolkit::Control mStencil;
304 Toolkit::ScrollBar mScrollBar;
305 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
306 Dali::TimePeriod mAnimationPeriod;
307 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
309 Actor mRenderableActor;
311 CallbackBase* mIdleCallback;
313 float mAlignmentOffset;
314 float mScrollAnimationDuration;
316 int mRenderingBackend;
317 bool mHasBeenStaged:1;
318 bool mScrollAnimationEnabled:1;
319 bool mScrollBarEnabled:1;
320 bool mScrollStarted:1;
323 } // namespace Internal
325 // Helpers for public-api forwarding methods
327 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
329 DALI_ASSERT_ALWAYS(textEditor);
331 Dali::RefObject& handle = textEditor.GetImplementation();
333 return static_cast<Toolkit::Internal::TextEditor&>(handle);
336 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
338 DALI_ASSERT_ALWAYS(textEditor);
340 const Dali::RefObject& handle = textEditor.GetImplementation();
342 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
345 } // namespace Toolkit
349 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H