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-selectable-control-interface.h>
35 #include <dali-toolkit/internal/text/text-controller.h>
36 #include <dali-toolkit/internal/text/text-vertical-scroller.h>
37 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
48 * @brief A control which renders a long text string with styles.
50 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
55 * @copydoc Dali::Toollkit::TextEditor::New()
57 static Toolkit::TextEditor New();
62 * @brief Called when a property of an object of this type is set.
64 * @param[in] object The object whose property is set.
65 * @param[in] index The property index.
66 * @param[in] value The new property value.
68 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
71 * @brief Called to retrieve a property of an object of this type.
73 * @param[in] object The object whose property is to be retrieved.
74 * @param[in] index The property index.
75 * @return The current value of the property.
77 static Property::Value GetProperty( BaseObject* object, Property::Index index );
80 * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
82 InputMethodContext GetInputMethodContext();
85 * @copydoc Dali::Toollkit::TextEditor::MaxLengthReachedSignal()
87 DevelTextEditor::MaxLengthReachedSignalType& MaxLengthReachedSignal();
90 * Connects a callback function with the object's signals.
91 * @param[in] object The object providing the signal.
92 * @param[in] tracker Used to disconnect the signal.
93 * @param[in] signalName The signal to connect to.
94 * @param[in] functor A newly allocated FunctorDelegate.
95 * @return True if the signal was connected.
96 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
98 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
101 * @copydoc TextEditor::TextChangedSignal()
103 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
106 * @copydoc TextEditor::TextChangedSignal()
108 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
111 * @copydoc TextEditor::ScrollStateChangedSignal()
113 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
115 private: // From Control
118 * @copydoc Control::OnInitialize()
120 void OnInitialize() override;
123 * @copydoc Control::OnStyleChange()
125 void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
128 * @copydoc Control::GetNaturalSize()
130 Vector3 GetNaturalSize() override;
133 * @copydoc Control::GetHeightForWidth()
135 float GetHeightForWidth( float width ) override;
138 * @copydoc Control::OnInitialize()
140 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
143 * @copydoc Control::OnKeyInputFocusGained()
145 void OnKeyInputFocusGained() override;
148 * @copydoc Control::OnKeyInputFocusLost()
150 void OnKeyInputFocusLost() override;
153 * @copydoc Control::OnTap()
155 void OnTap( const TapGesture& tap ) override;
158 * @copydoc Control::OnPan()
160 void OnPan( const PanGesture& gesture ) override;
163 * @copydoc Control::OnLongPress()
165 void OnLongPress( const LongPressGesture& gesture ) override;
168 * @copydoc Control::OnSceneConnection()
170 void OnSceneConnection( int depth ) override;
173 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
175 bool OnKeyEvent(const KeyEvent& event) override;
177 // From ControlInterface
180 * @copydoc Text::ControlInterface::RequestTextRelayout()
182 void RequestTextRelayout() override;
184 // From EditableControlInterface
187 * @copydoc Text::EditableControlInterface::TextChanged()
189 void TextChanged() override;
192 * @copydoc Text::EditableControlInterface::MaxLengthReached()
194 void MaxLengthReached() override;
197 * @copydoc Text::EditableControlInterface::InputStyleChanged()
199 void InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) override;
202 * @copydoc Text::EditableControlInterface::AddDecoration()
204 void AddDecoration( Actor& actor, bool needsClipping ) override;
206 // From SelectableControlInterface
209 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
211 void SetTextSelectionRange(const uint32_t *start, const uint32_t *end) override;
214 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
216 Uint32Pair GetTextSelectionRange() const override;
219 * @copydoc Text::SelectableControlInterface::SelectWholeText()
221 void SelectWholeText() override;
224 * @copydoc Text::SelectableControlInterface::SelectNone()
226 void SelectNone() override;
229 * @copydoc Dali::Toolkit::DevelTextEditor::ScrollBy()
231 void ScrollBy(Vector2 Scroll);
234 * @brief Get Horizontal scroll position of TextEditor.
236 * @return Horizontal scroll position (in pixels) of TextEditor.
238 float GetHorizontalScrollPosition();
241 * @brief Get Vertical scroll position of TextEditor.
243 * @return Vertical scroll position (in pixels) of TextEditor.
245 float GetVerticalScrollPosition();
248 * @copydoc Text::SelectableControlInterface::GetSelectedText()
250 string GetSelectedText() const override;
253 * @copydoc Text::EditableControlInterface::IsEditable()
255 bool IsEditable() const override;
258 * @copydoc Text::EditableControlInterface::SetEditable()
260 void SetEditable( bool editable ) override;
262 private: // Implementation
265 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
267 InputMethodContext::CallbackData OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent );
270 * @brief Callback when Clipboard signals an item should be pasted
271 * @param[in] clipboard handle to Clipboard Event Notifier
273 void OnClipboardTextSelected( ClipboardEventNotifier& clipboard );
276 * @brief Get a Property Map for the image used for the required Handle Image
277 * @param[out] value the returned image property
278 * @param[in] handleType the type of handle
279 * @param[in] handleImageType the type of image for the given handleType
281 void GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType );
284 * @brief Callback when keyboard is shown/hidden.
286 * @param[in] keyboardShown True if keyboard is shown.
288 void KeyboardStatusChanged( bool keyboardShown );
291 * @brief update scroll bar position
293 * If text scroll is occurred, create or update scroll bar position
295 void UpdateScrollBar();
298 * @brief Callback when TextEditor is touched
300 * @param[in] actor TextEditor touched
301 * @param[in] touch Touch information
303 bool OnTouched( Actor actor, const TouchEvent& touch );
306 * @brief Callbacks called on idle.
308 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
313 * @brief set RenderActor's position with new scrollPosition
315 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
317 void ApplyScrollPosition();
320 * @brief Callback function for ScrollBar indicator animation finished signal
322 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
324 void OnScrollIndicatorAnimationFinished( Animation& animation );
327 * Construct a new TextEditor.
332 * A reference counted object may only be deleted by calling Unreference()
334 virtual ~TextEditor();
336 // Undefined copy constructor and assignment operators
337 TextEditor(const TextEditor&);
338 TextEditor& operator=(const TextEditor& rhs);
341 * @brief Render view, create and attach actor(s) to this text editor.
343 void RenderText( Text::Controller::UpdateTextType updateTextType );
345 // Connection needed to re-render text, when a text editor returns to the scene.
346 void OnSceneConnect( Dali::Actor actor );
350 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
351 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
352 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
353 Toolkit::DevelTextEditor::MaxLengthReachedSignalType mMaxLengthReachedSignal;
355 InputMethodContext mInputMethodContext;
356 Text::ControllerPtr mController;
357 Text::RendererPtr mRenderer;
358 Text::DecoratorPtr mDecorator;
359 Text::TextVerticalScrollerPtr mTextVerticalScroller;
360 Toolkit::Control mStencil;
361 Toolkit::ScrollBar mScrollBar;
362 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
363 Dali::TimePeriod mAnimationPeriod;
364 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
366 Actor mRenderableActor;
368 CallbackBase* mIdleCallback;
370 float mAlignmentOffset;
371 float mScrollAnimationDuration;
373 int mRenderingBackend;
374 bool mHasBeenStaged:1;
375 bool mScrollAnimationEnabled:1;
376 bool mScrollBarEnabled:1;
377 bool mScrollStarted:1;
380 } // namespace Internal
382 // Helpers for public-api forwarding methods
384 inline Toolkit::Internal::TextEditor& GetImpl( Toolkit::TextEditor& textEditor )
386 DALI_ASSERT_ALWAYS(textEditor);
388 Dali::RefObject& handle = textEditor.GetImplementation();
390 return static_cast<Toolkit::Internal::TextEditor&>(handle);
393 inline const Toolkit::Internal::TextEditor& GetImpl( const Toolkit::TextEditor& textEditor )
395 DALI_ASSERT_ALWAYS(textEditor);
397 const Dali::RefObject& handle = textEditor.GetImplementation();
399 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
402 } // namespace Toolkit
406 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H