c9287639481fa81674edbf42950b6fe65d6f6dca
[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) 2016 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
24 #include <dali-toolkit/internal/text/text-control-interface.h>
25 #include <dali-toolkit/internal/text/text-controller.h>
26 #include <dali-toolkit/internal/text/text-scroller-interface.h>
27 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
28 #include <dali-toolkit/internal/text/text-scroller.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 /**
40  * @brief A control which renders a short text string.
41  */
42 class TextLabel : public Control, public Text::ControlInterface, public Text::ScrollerInterface
43 {
44 public:
45
46   /**
47    * @copydoc Dali::Toollkit::TextLabel::New()
48    */
49   static Toolkit::TextLabel New();
50
51   // Properties
52
53   /**
54    * @brief Called when a property of an object of this type is set.
55    *
56    * @param[in] object The object whose property is set.
57    * @param[in] index The property index.
58    * @param[in] value The new property value.
59    */
60   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
61
62   /**
63    * @brief Called to retrieve a property of an object of this type.
64    *
65    * @param[in] object The object whose property is to be retrieved.
66    * @param[in] index The property index.
67    * @return The current value of the property.
68    */
69   static Property::Value GetProperty( BaseObject* object, Property::Index index );
70
71 private: // From Control
72
73   /**
74    * @copydoc Control::OnInitialize()
75    */
76   virtual void OnInitialize();
77
78   /**
79    * @copydoc Control::OnStyleChange()
80    */
81   virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
82
83   /**
84    * @copydoc Control::OnRelayout()
85    */
86   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
87
88   /**
89    * @copydoc Control::GetNaturalSize()
90    */
91   virtual Vector3 GetNaturalSize();
92
93   /**
94    * @copydoc Control::GetHeightForWidth()
95    */
96   virtual float GetHeightForWidth( float width );
97
98   /**
99    * @copydoc Control::OnStageConnection()
100    */
101   virtual void OnStageConnection( int depth );
102
103 // From ControlInterface
104
105   /**
106    * @copydoc Text::ControlInterface::RequestTextRelayout()
107    */
108   virtual void RequestTextRelayout();
109
110 private: // from TextScroller
111
112   /**
113    * @copydoc Text::ScrollerInterface::ScrollingFinished()
114    */
115   virtual void ScrollingFinished();
116
117 private: // Implementation
118
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
131   // Undefined copy constructor and assignment operators
132   TextLabel(const TextLabel&);
133   TextLabel& operator=(const TextLabel& rhs);
134
135   // Connection needed to re-render text, when a Text Label returns to the stage
136   void OnStageConnect( Dali::Actor actor );
137
138   /**
139    * @brief Render view, create and attach actor(s) to this Text Label
140    */
141   void RenderText();
142
143   /**
144    * @brief Set up Autoscrolling
145    */
146   void SetUpAutoScrolling();
147
148 private: // Data
149
150   Text::ControllerPtr mController;
151   Text::RendererPtr mRenderer;
152   Text::TextScrollerPtr mTextScroller;
153   Actor mRenderableActor;
154   int mRenderingBackend;
155   bool mHasBeenStaged:1;
156 };
157
158 } // namespace Internal
159
160 // Helpers for public-api forwarding methods
161
162 inline Toolkit::Internal::TextLabel& GetImpl( Toolkit::TextLabel& textLabel )
163 {
164   DALI_ASSERT_ALWAYS(textLabel);
165
166   Dali::RefObject& handle = textLabel.GetImplementation();
167
168   return static_cast<Toolkit::Internal::TextLabel&>(handle);
169 }
170
171 inline const Toolkit::Internal::TextLabel& GetImpl( const Toolkit::TextLabel& textLabel )
172 {
173   DALI_ASSERT_ALWAYS(textLabel);
174
175   const Dali::RefObject& handle = textLabel.GetImplementation();
176
177   return static_cast<const Toolkit::Internal::TextLabel&>(handle);
178 }
179
180 } // namespace Toolkit
181
182 } // namespace Dali
183
184 #endif // DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H