1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H
5 * Copyright (c) 2021 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/devel-api/controls/scroll-bar/scroll-bar.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
29 #include <dali-toolkit/internal/text/decorator/text-decorator.h>
30 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-control-interface.h>
32 #include <dali-toolkit/internal/text/text-controller.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-vertical-scroller.h>
36 #include <dali-toolkit/public-api/controls/control-impl.h>
37 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
46 * @brief A control which renders a long text string with styles.
48 class TextEditor : public Control, public Text::ControlInterface, public Text::EditableControlInterface, public Text::SelectableControlInterface
52 * @copydoc Dali::Toollkit::TextEditor::New()
54 static Toolkit::TextEditor New();
59 * @brief Called when a property of an object of this type is set.
61 * @param[in] object The object whose property is set.
62 * @param[in] index The property index.
63 * @param[in] value The new property value.
65 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
68 * @brief Called to retrieve a property of an object of this type.
70 * @param[in] object The object whose property is to be retrieved.
71 * @param[in] index The property index.
72 * @return The current value of the property.
74 static Property::Value GetProperty(BaseObject* object, Property::Index index);
77 * @copydoc Dali::Toollkit::TextEditor::GetInputMethodContext()
79 InputMethodContext GetInputMethodContext();
82 * @copydoc Dali::Toollkit::TextEditor::MaxLengthReachedSignal()
84 DevelTextEditor::MaxLengthReachedSignalType& MaxLengthReachedSignal();
87 * Connects a callback function with the object's signals.
88 * @param[in] object The object providing the signal.
89 * @param[in] tracker Used to disconnect the signal.
90 * @param[in] signalName The signal to connect to.
91 * @param[in] functor A newly allocated FunctorDelegate.
92 * @return True if the signal was connected.
93 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
95 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
98 * @copydoc TextEditor::TextChangedSignal()
100 Toolkit::TextEditor::TextChangedSignalType& TextChangedSignal();
103 * @copydoc TextEditor::TextChangedSignal()
105 Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
108 * @copydoc TextEditor::ScrollStateChangedSignal()
110 Toolkit::TextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
112 private: // From Control
114 * @copydoc Control::OnInitialize()
116 void OnInitialize() override;
119 * @copydoc Control::OnStyleChange()
121 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
124 * @copydoc Control::GetNaturalSize()
126 Vector3 GetNaturalSize() override;
129 * @copydoc Control::GetHeightForWidth()
131 float GetHeightForWidth(float width) override;
134 * @copydoc Control::OnInitialize()
136 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
139 * @copydoc Control::OnKeyInputFocusGained()
141 void OnKeyInputFocusGained() override;
144 * @copydoc Control::OnKeyInputFocusLost()
146 void OnKeyInputFocusLost() override;
149 * @copydoc Control::OnTap()
151 void OnTap(const TapGesture& tap) override;
154 * @copydoc Control::OnPan()
156 void OnPan(const PanGesture& gesture) override;
159 * @copydoc Control::OnLongPress()
161 void OnLongPress(const LongPressGesture& gesture) override;
164 * @copydoc Control::OnSceneConnection()
166 void OnSceneConnection(int depth) override;
169 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
171 bool OnKeyEvent(const KeyEvent& event) override;
173 // From ControlInterface
176 * @copydoc Text::ControlInterface::RequestTextRelayout()
178 void RequestTextRelayout() override;
180 // From EditableControlInterface
183 * @copydoc Text::EditableControlInterface::TextChanged()
185 void TextChanged(bool immediate) override;
188 * @copydoc Text::EditableControlInterface::MaxLengthReached()
190 void MaxLengthReached() override;
193 * @copydoc Text::EditableControlInterface::InputStyleChanged()
195 void InputStyleChanged(Text::InputStyle::Mask inputStyleMask) override;
198 * @copydoc Text::EditableControlInterface::AddDecoration()
200 void AddDecoration(Actor& actor, bool needsClipping) override;
203 * @copydoc Text::EditableControlInterface::GetControlBackgroundColor()
205 void GetControlBackgroundColor(Vector4& color) const override;
207 // From SelectableControlInterface
210 * @copydoc Text::SelectableControlInterface::SetTextSelectionRange()
212 void SetTextSelectionRange(const uint32_t* start, const uint32_t* end) override;
215 * @copydoc Text::SelectableControlInterface::GetTextSelectionRange()
217 Uint32Pair GetTextSelectionRange() const override;
220 * @copydoc Text::SelectableControlInterface::SelectWholeText()
222 void SelectWholeText() override;
225 * @copydoc Text::SelectableControlInterface::SelectNone()
227 void SelectNone() override;
230 * @copydoc Text::SelectableControlInterface::GetSelectedText()
232 string GetSelectedText() const override;
235 * @copydoc Text::EditableControlInterface::IsEditable()
237 bool IsEditable() const override;
240 * @copydoc Text::EditableControlInterface::SetEditable()
242 void SetEditable(bool editable) override;
244 private: // Implementation
246 * @copydoc Dali::Toolkit::Text::Controller::(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
248 InputMethodContext::CallbackData OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent);
251 * @brief Callback when Clipboard signals an item should be pasted
252 * @param[in] clipboard handle to Clipboard Event Notifier
254 void OnClipboardTextSelected(ClipboardEventNotifier& clipboard);
257 * @brief Get a Property Map for the image used for the required Handle Image
258 * @param[out] value the returned image property
259 * @param[in] handleType the type of handle
260 * @param[in] handleImageType the type of image for the given handleType
262 void GetHandleImagePropertyValue(Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType);
265 * @brief Callback when keyboard is shown/hidden.
267 * @param[in] keyboardShown True if keyboard is shown.
269 void KeyboardStatusChanged(bool keyboardShown);
272 * @brief update scroll bar position
274 * If text scroll is occurred, create or update scroll bar position
276 void UpdateScrollBar();
279 * @brief Callback when TextEditor is touched
281 * @param[in] actor TextEditor touched
282 * @param[in] touch Touch information
284 bool OnTouched(Actor actor, const TouchEvent& touch);
287 * @brief Callbacks called on idle.
289 * If there are notifications of change of input style on the queue, Toolkit::TextEditor::InputStyleChangedSignal() are emitted.
294 * @brief Emits TextChanged signal.
296 void EmitTextChangedSignal();
299 * @brief set RenderActor's position with new scrollPosition
301 * Apply updated scroll position or start scroll animation if VerticalScrollAnimation is enabled
303 void ApplyScrollPosition();
306 * @brief Callback function for ScrollBar indicator animation finished signal
308 * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
310 void OnScrollIndicatorAnimationFinished(Animation& animation);
313 * Construct a new TextEditor.
318 * A reference counted object may only be deleted by calling Unreference()
320 virtual ~TextEditor();
322 // Undefined copy constructor and assignment operators
323 TextEditor(const TextEditor&);
324 TextEditor& operator=(const TextEditor& rhs);
327 * @brief Render view, create and attach actor(s) to this text editor.
329 void RenderText(Text::Controller::UpdateTextType updateTextType);
331 // Connection needed to re-render text, when a text editor returns to the scene.
332 void OnSceneConnect(Dali::Actor actor);
336 Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
337 Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
338 Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
339 Toolkit::DevelTextEditor::MaxLengthReachedSignalType mMaxLengthReachedSignal;
341 InputMethodContext mInputMethodContext;
342 Text::ControllerPtr mController;
343 Text::RendererPtr mRenderer;
344 Text::DecoratorPtr mDecorator;
345 Text::TextVerticalScrollerPtr mTextVerticalScroller;
346 Toolkit::Control mStencil;
347 Toolkit::ScrollBar mScrollBar;
348 Dali::Animation mAnimation; ///< Scroll indicator Show/Hide Animation.
349 Dali::TimePeriod mAnimationPeriod;
350 std::vector<Actor> mClippingDecorationActors; ///< Decoration actors which need clipping.
352 Actor mRenderableActor;
354 CallbackBase* mIdleCallback;
356 float mAlignmentOffset;
357 float mScrollAnimationDuration;
359 int mRenderingBackend;
360 bool mHasBeenStaged : 1;
361 bool mScrollAnimationEnabled : 1;
362 bool mScrollBarEnabled : 1;
363 bool mScrollStarted : 1;
364 bool mTextChanged : 1; ///< If true, emits TextChangedSignal in next OnRelayout().
367 } // namespace Internal
369 // Helpers for public-api forwarding methods
371 inline Toolkit::Internal::TextEditor& GetImpl(Toolkit::TextEditor& textEditor)
373 DALI_ASSERT_ALWAYS(textEditor);
375 Dali::RefObject& handle = textEditor.GetImplementation();
377 return static_cast<Toolkit::Internal::TextEditor&>(handle);
380 inline const Toolkit::Internal::TextEditor& GetImpl(const Toolkit::TextEditor& textEditor)
382 DALI_ASSERT_ALWAYS(textEditor);
384 const Dali::RefObject& handle = textEditor.GetImplementation();
386 return static_cast<const Toolkit::Internal::TextEditor&>(handle);
389 } // namespace Toolkit
393 #endif // DALI_TOOLKIT_INTERNAL_TEXT_EDITOR_H