Merge "Add descriptions and example codes" 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) 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-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   /**
123    * @copydoc Text::ControlInterface::InputStyleChanged()
124    */
125   virtual void InputStyleChanged( Text::InputStyle::Mask inputStyleMask );
126
127 private: // from TextScroller
128
129   /**
130    * @copydoc Text::ScrollerInterface::ScrollingFinished()
131    */
132   virtual void ScrollingFinished();
133
134 private: // Implementation
135
136   /**
137    * Construct a new TextLabel.
138    */
139   TextLabel();
140
141   /**
142    * A reference counted object may only be deleted by calling Unreference()
143    */
144   virtual ~TextLabel();
145
146 private:
147
148   // Undefined copy constructor and assignment operators
149   TextLabel(const TextLabel&);
150   TextLabel& operator=(const TextLabel& rhs);
151
152   // Connection needed to re-render text, when a Text Label returns to the stage
153   void OnStageConnect( Dali::Actor actor );
154
155   /**
156    * @brief Render view, create and attach actor(s) to this Text Label
157    */
158   void RenderText();
159
160   /**
161    * @brief Set up Autoscrolling
162    */
163   void SetUpAutoScrolling();
164
165 private: // Data
166
167   Text::ControllerPtr mController;
168   Text::RendererPtr mRenderer;
169   Text::TextScrollerPtr mTextScroller;
170   Actor mRenderableActor;
171   int mRenderingBackend;
172   bool mHasBeenStaged:1;
173 };
174
175 } // namespace Internal
176
177 // Helpers for public-api forwarding methods
178
179 inline Toolkit::Internal::TextLabel& GetImpl( Toolkit::TextLabel& textLabel )
180 {
181   DALI_ASSERT_ALWAYS(textLabel);
182
183   Dali::RefObject& handle = textLabel.GetImplementation();
184
185   return static_cast<Toolkit::Internal::TextLabel&>(handle);
186 }
187
188 inline const Toolkit::Internal::TextLabel& GetImpl( const Toolkit::TextLabel& textLabel )
189 {
190   DALI_ASSERT_ALWAYS(textLabel);
191
192   const Dali::RefObject& handle = textLabel.GetImplementation();
193
194   return static_cast<const Toolkit::Internal::TextLabel&>(handle);
195 }
196
197 } // namespace Toolkit
198
199 } // namespace Dali
200
201 #endif // __DALI_TOOLKIT_INTERNAL_TEXT_LABEL_H__