1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
5 * Copyright (c) 2022 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/atspi-interfaces/hypertext.h>
23 #include <dali/devel-api/atspi-interfaces/text.h>
24 #include <dali/public-api/object/property-map.h>
27 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
28 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
29 #include <dali-toolkit/internal/text/text-anchor-control-interface.h>
30 #include <dali-toolkit/internal/text/text-control-interface.h>
31 #include <dali-toolkit/internal/text/text-controller.h>
32 #include <dali-toolkit/internal/text/text-scroller-interface.h>
33 #include <dali-toolkit/internal/text/text-scroller.h>
34 #include <dali-toolkit/internal/visuals/text/text-visual.h>
35 #include <dali-toolkit/public-api/controls/control-impl.h>
36 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
45 * @brief A control which renders a short text string.
47 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface, public Text::AnchorControlInterface
51 * @copydoc Dali::Toollkit::TextLabel::New()
52 * @param[in] additionalBehaviour custom behavior flags for this TextLabel. Default is CONTROL_BEHAVIOUR_DEFAULT
54 static Toolkit::TextLabel New(ControlBehaviour additionalBehaviour = ControlBehaviour::CONTROL_BEHAVIOUR_DEFAULT);
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::TextLabel::AnchorClickedSignal()
79 DevelTextLabel::AnchorClickedSignalType& AnchorClickedSignal();
82 * @copydoc Dali::Toollkit::TextLabel::TextFitChangedSignal()
84 DevelTextLabel::TextFitChangedSignalType& TextFitChangedSignal();
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 * @brief Gets text controller
100 * @return The text controller
102 Text::ControllerPtr GetTextController();
105 * @brief Get the rendered size of a specific text range.
106 * if the requested text is at multilines, multiple sizes will be returned for each text located in a separate line.
107 * if a line contains characters with different directions, multiple sizes will be returned for each block of contiguous characters with the same direction.
109 * @param[in] startIndex start index of the text requested to calculate size for.
110 * @param[in] endIndex end index(included) of the text requested to calculate size for.
111 * @return list of sizes of the reuested text.
113 Vector<Vector2> GetTextSize(const uint32_t startIndex, const uint32_t endIndex) const;
116 * @brief Get the top/left rendered position of a specific text range.
117 * if the requested text is at multilines, multiple positions will be returned for each text located in a separate line.
118 * if a line contains characters with different directions, multiple positions will be returned for each block of contiguous characters with the same direction.
120 * @param[in] startIndex start index of the text requested to get position to.
121 * @param[in] endIndex end index(included) of the text requested to get position to.
122 * @return list of positions of the requested text.
124 Vector<Vector2> GetTextPosition(const uint32_t startIndex, const uint32_t endIndex) const;
126 private: // From Control
128 * @copydoc Control::OnInitialize()
130 void OnInitialize() override;
133 * @copydoc Control::OnStyleChange()
135 void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
138 * @copydoc Control::OnRelayout()
140 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
143 * @copydoc Control::OnTap()
145 void OnTap(const TapGesture& tap) override;
148 * @copydoc Control::GetNaturalSize()
150 Vector3 GetNaturalSize() override;
153 * @copydoc Control::GetHeightForWidth()
155 float GetHeightForWidth(float width) override;
158 * @copydoc Control::OnPropertySet()
160 void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
162 // From ControlInterface
165 * @copydoc Text::ControlInterface::RequestTextRelayout()
167 void RequestTextRelayout() override;
169 private: // from TextScroller
171 * @copydoc Text::ScrollerInterface::ScrollingFinished()
173 void ScrollingFinished() override;
175 public: // From AnchorControlInterface
177 * @copydoc Text::AnchorControlInterface::AnchorClicked()
179 void AnchorClicked(const std::string& href) override;
181 private: // Implementation
183 * Construct a new TextLabel.
185 * @param[in] additionalBehaviour additional behaviour flags for this TextLabel
187 TextLabel(ControlBehaviour additionalBehaviour);
190 * A reference counted object may only be deleted by calling Unreference()
192 virtual ~TextLabel();
195 // Undefined copy constructor and assignment operators
196 TextLabel(const TextLabel&);
197 TextLabel& operator=(const TextLabel& rhs);
200 * @brief Set up Autoscrolling
202 void SetUpAutoScrolling();
205 * Creates a text-scroller if one has not been created.
206 * @return The text scroller.
208 Text::TextScrollerPtr GetTextScroller()
212 mTextScroller = Text::TextScroller::New(*this);
214 return mTextScroller;
218 * @brief Callback function for when the layout is changed.
219 * @param[in] actor The actor whose layoutDirection is changed.
220 * @param[in] type The layoutDirection.
222 void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type);
225 * @brief Emits TextFitChanged signal.
227 void EmitTextFitChangedSignal();
228 void OnAccessibilityStatusChanged();
231 Text::ControllerPtr mController;
232 Text::TextScrollerPtr mTextScroller;
234 Toolkit::Visual::Base mVisual;
236 std::vector<Toolkit::TextAnchor> mAnchorActors;
239 Toolkit::DevelTextLabel::AnchorClickedSignalType mAnchorClickedSignal;
240 Toolkit::DevelTextLabel::TextFitChangedSignalType mTextFitChangedSignal;
242 int mRenderingBackend;
243 bool mTextUpdateNeeded : 1;
247 * @brief This structure is to connect TextLabel with Accessible functions.
249 struct AccessibleImpl : public DevelControl::ControlAccessible,
250 public virtual Dali::Accessibility::Text,
251 public virtual Dali::Accessibility::Hypertext
253 using DevelControl::ControlAccessible::ControlAccessible;
256 * @copydoc Dali::Accessibility::Text::GetText()
258 std::string GetText(size_t startOffset, size_t endOffset) const override;
261 * @copydoc Dali::Accessibility::Text::GetCharacterCount()
263 size_t GetCharacterCount() const override;
266 * @copydoc Dali::Accessibility::Text::GetCursorOffset()
268 size_t GetCursorOffset() const override;
271 * @copydoc Dali::Accessibility::Text::SetCursorOffset()
273 bool SetCursorOffset(size_t offset) override;
276 * @copydoc Dali::Accessibility::Text::GetTextAtOffset()
278 Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) const override;
281 * @copydoc Dali::Accessibility::Text::GetRangeOfSelection()
283 Accessibility::Range GetRangeOfSelection(size_t selectionIndex) const override;
286 * @copydoc Dali::Accessibility::Text::RemoveSelection()
288 bool RemoveSelection(size_t selectionIndex) override;
291 * @copydoc Dali::Accessibility::Text::SetRangeOfSelection()
293 bool SetRangeOfSelection(size_t selectionIndex, size_t startOffset, size_t endOffset) override;
296 * @copydoc Dali::Accessibility::Text::GetRangeExtents()
298 Rect<> GetRangeExtents(size_t startOffset, size_t endOffset, Accessibility::CoordinateType type) override;
301 * @copydoc Dali::Accessibility::Text::GetNameRaw()
303 std::string GetNameRaw() const override;
306 * @copydoc Dali::Accessibility::Text::GetNamePropertyIndex()
308 Property::Index GetNamePropertyIndex() override;
311 * @copydoc Dali::Accessibility::Hypertext::GetLink()
313 Accessibility::Hyperlink* GetLink(int32_t linkIndex) const override;
316 * @copydoc Dali::Accessibility::Hypertext::GetLinkIndex()
318 int32_t GetLinkIndex(int32_t characterOffset) const override;
321 * @copydoc Dali::Accessibility::Hypertext::GetLinkCount()
323 int32_t GetLinkCount() const override;
327 } // namespace Internal
329 // Helpers for public-api forwarding methods
331 inline Toolkit::Internal::TextLabel& GetImpl(Toolkit::TextLabel& textLabel)
333 DALI_ASSERT_ALWAYS(textLabel);
335 Dali::RefObject& handle = textLabel.GetImplementation();
337 return static_cast<Toolkit::Internal::TextLabel&>(handle);
340 inline const Toolkit::Internal::TextLabel& GetImpl(const Toolkit::TextLabel& textLabel)
342 DALI_ASSERT_ALWAYS(textLabel);
344 const Dali::RefObject& handle = textLabel.GetImplementation();
346 return static_cast<const Toolkit::Internal::TextLabel&>(handle);
349 } // namespace Toolkit
353 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H