Merge "Change BuildRequires of dali2-toolkit to Requires" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H
3
4 /*
5  * Copyright (c) 2021 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/public-api/object/property-map.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
26 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
27 #include <dali-toolkit/internal/text/text-control-interface.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
29 #include <dali-toolkit/internal/text/text-scroller-interface.h>
30 #include <dali-toolkit/internal/text/text-scroller.h>
31 #include <dali-toolkit/internal/visuals/text/text-visual.h>
32 #include <dali-toolkit/public-api/controls/control-impl.h>
33 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
34
35 namespace Dali
36 {
37 namespace Toolkit
38 {
39 namespace Internal
40 {
41 /**
42  * @brief A control which renders a short text string.
43  */
44 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface
45 {
46 public:
47   /**
48    * @copydoc Dali::Toollkit::TextLabel::New()
49    */
50   static Toolkit::TextLabel New();
51
52   // Properties
53
54   /**
55    * @brief Called when a property of an object of this type is set.
56    *
57    * @param[in] object The object whose property is set.
58    * @param[in] index The property index.
59    * @param[in] value The new property value.
60    */
61   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
62
63   /**
64    * @brief Called to retrieve a property of an object of this type.
65    *
66    * @param[in] object The object whose property is to be retrieved.
67    * @param[in] index The property index.
68    * @return The current value of the property.
69    */
70   static Property::Value GetProperty(BaseObject* object, Property::Index index);
71
72   Text::ControllerPtr getController();
73
74 private: // From Control
75   /**
76    * @copydoc Control::OnInitialize()
77    */
78   void OnInitialize() override;
79
80   /**
81    * @copydoc Control::OnStyleChange()
82    */
83   void OnStyleChange(Toolkit::StyleManager styleManager, StyleChange::Type change) override;
84
85   /**
86    * @copydoc Control::OnRelayout()
87    */
88   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
89
90   /**
91    * @copydoc Control::GetNaturalSize()
92    */
93   Vector3 GetNaturalSize() override;
94
95   /**
96    * @copydoc Control::GetHeightForWidth()
97    */
98   float GetHeightForWidth(float width) override;
99
100   /**
101    * @copydoc Control::OnPropertySet()
102    */
103   void OnPropertySet(Property::Index index, const Property::Value& propertyValue) override;
104
105   // From ControlInterface
106
107   /**
108    * @copydoc Text::ControlInterface::RequestTextRelayout()
109    */
110   void RequestTextRelayout() override;
111
112 private: // from TextScroller
113   /**
114    * @copydoc Text::ScrollerInterface::ScrollingFinished()
115    */
116   void ScrollingFinished() override;
117
118 private: // Implementation
119   /**
120    * Construct a new TextLabel.
121    */
122   TextLabel();
123
124   /**
125    * A reference counted object may only be deleted by calling Unreference()
126    */
127   virtual ~TextLabel();
128
129 private:
130   // Undefined copy constructor and assignment operators
131   TextLabel(const TextLabel&);
132   TextLabel& operator=(const TextLabel& rhs);
133
134   /**
135    * @brief Set up Autoscrolling
136    */
137   void SetUpAutoScrolling();
138
139   /**
140    * Creates a text-scroller if one has not been created.
141    * @return The text scroller.
142    */
143   Text::TextScrollerPtr GetTextScroller()
144   {
145     if(!mTextScroller)
146     {
147       mTextScroller = Text::TextScroller::New(*this);
148     }
149     return mTextScroller;
150   }
151
152 private: // Data
153   Text::ControllerPtr   mController;
154   Text::TextScrollerPtr mTextScroller;
155
156   Toolkit::Visual::Base mVisual;
157
158   int  mRenderingBackend;
159   bool mTextUpdateNeeded : 1;
160
161 protected:
162   struct AccessibleImpl : public DevelControl::AccessibleImpl,
163                           public virtual Dali::Accessibility::Text
164   {
165     using DevelControl::AccessibleImpl::AccessibleImpl;
166
167     std::string          GetText(size_t startOffset, size_t endOffset) override;
168     size_t               GetCharacterCount() override;
169     size_t               GetCaretOffset() override;
170     bool                 SetCaretOffset(size_t offset) override;
171     Accessibility::Range GetTextAtOffset(size_t offset, Accessibility::TextBoundary boundary) override;
172     Accessibility::Range GetSelection(size_t selectionNum) override;
173     bool                 RemoveSelection(size_t selectionNum) override;
174     bool                 SetSelection(size_t selectionNum, size_t startOffset, size_t endOffset) override;
175     std::string          GetNameRaw() override;
176     Property::Index      GetNamePropertyIndex() override;
177   };
178 };
179
180 } // namespace Internal
181
182 // Helpers for public-api forwarding methods
183
184 inline Toolkit::Internal::TextLabel& GetImpl(Toolkit::TextLabel& textLabel)
185 {
186   DALI_ASSERT_ALWAYS(textLabel);
187
188   Dali::RefObject& handle = textLabel.GetImplementation();
189
190   return static_cast<Toolkit::Internal::TextLabel&>(handle);
191 }
192
193 inline const Toolkit::Internal::TextLabel& GetImpl(const Toolkit::TextLabel& textLabel)
194 {
195   DALI_ASSERT_ALWAYS(textLabel);
196
197   const Dali::RefObject& handle = textLabel.GetImplementation();
198
199   return static_cast<const Toolkit::Internal::TextLabel&>(handle);
200 }
201
202 } // namespace Toolkit
203
204 } // namespace Dali
205
206 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H