a863c9cccbdaa07863a079fe13a5ac8b34d43922
[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) 2020 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/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/text-controls/text-label.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/rendering/text-renderer.h>
31 #include <dali-toolkit/internal/text/text-scroller.h>
32 #include <dali-toolkit/internal/visuals/text/text-visual.h>
33
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 /**
45  * @brief A control which renders a short text string.
46  */
47 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface
48 {
49 public:
50
51   /**
52    * @copydoc Dali::Toollkit::TextLabel::New()
53    */
54   static Toolkit::TextLabel New();
55
56   // Properties
57
58   /**
59    * @brief Called when a property of an object of this type is set.
60    *
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.
64    */
65   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
66
67   /**
68    * @brief Called to retrieve a property of an object of this type.
69    *
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.
73    */
74   static Property::Value GetProperty( BaseObject* object, Property::Index index );
75
76 private: // From Control
77
78   /**
79    * @copydoc Control::OnInitialize()
80    */
81   void OnInitialize() override;
82
83   /**
84    * @copydoc Control::OnStyleChange()
85    */
86   void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
87
88   /**
89    * @copydoc Control::OnRelayout()
90    */
91   void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
92
93   /**
94    * @copydoc Control::GetNaturalSize()
95    */
96   Vector3 GetNaturalSize() override;
97
98   /**
99    * @copydoc Control::GetHeightForWidth()
100    */
101   float GetHeightForWidth( float width ) override;
102
103   /**
104    * @copydoc Control::OnPropertySet()
105    */
106   void OnPropertySet( Property::Index index, const Property::Value& propertyValue ) override ;
107
108   // From ControlInterface
109
110   /**
111    * @copydoc Text::ControlInterface::RequestTextRelayout()
112    */
113   void RequestTextRelayout() override;
114
115 private: // from TextScroller
116
117   /**
118    * @copydoc Text::ScrollerInterface::ScrollingFinished()
119    */
120   void ScrollingFinished() override;
121
122 private: // Implementation
123
124   /**
125    * Construct a new TextLabel.
126    */
127   TextLabel();
128
129   /**
130    * A reference counted object may only be deleted by calling Unreference()
131    */
132   virtual ~TextLabel();
133
134 private:
135
136   // Undefined copy constructor and assignment operators
137   TextLabel(const TextLabel&);
138   TextLabel& operator=(const TextLabel& rhs);
139
140   /**
141    * @brief Set up Autoscrolling
142    */
143   void SetUpAutoScrolling();
144
145   /**
146    * Creates a text-scroller if one has not been created.
147    * @return The text scroller.
148    */
149   Text::TextScrollerPtr GetTextScroller()
150   {
151     if( !mTextScroller )
152     {
153       mTextScroller = Text::TextScroller::New( *this );
154     }
155     return mTextScroller;
156   }
157
158 private: // Data
159
160   Text::ControllerPtr mController;
161   Text::TextScrollerPtr mTextScroller;
162
163   Toolkit::Visual::Base mVisual;
164
165   int mRenderingBackend;
166   bool mTextUpdateNeeded:1;
167 };
168
169 } // namespace Internal
170
171 // Helpers for public-api forwarding methods
172
173 inline Toolkit::Internal::TextLabel& GetImpl( Toolkit::TextLabel& textLabel )
174 {
175   DALI_ASSERT_ALWAYS(textLabel);
176
177   Dali::RefObject& handle = textLabel.GetImplementation();
178
179   return static_cast<Toolkit::Internal::TextLabel&>(handle);
180 }
181
182 inline const Toolkit::Internal::TextLabel& GetImpl( const Toolkit::TextLabel& textLabel )
183 {
184   DALI_ASSERT_ALWAYS(textLabel);
185
186   const Dali::RefObject& handle = textLabel.GetImplementation();
187
188   return static_cast<const Toolkit::Internal::TextLabel&>(handle);
189 }
190
191 } // namespace Toolkit
192
193 } // namespace Dali
194
195 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H