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