TextVisual - Fix a memory leak issue.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / text / text-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_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 // EXTERNAL INCLUDES
22 #include <dali/devel-api/object/weak-handle.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
28 #include <dali-toolkit/internal/text/text-controller.h>
29 #include <dali-toolkit/internal/text/text-scroller.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 class TextVisual;
41 typedef IntrusivePtr< TextVisual > TextVisualPtr;
42
43 /**
44  * The visual which renders text
45  *
46  * The following properties are optional:
47  *
48  * | %Property Name      | Type    |
49  * |---------------------|---------|
50  * | renderingBackend    | INTEGER |
51  * | text                | STRING  |
52  * | fontFamily          | STRING  |
53  * | fontStyle           | STRING  |
54  * | pointSize           | FLOAT   |
55  * | multiLine           | BOOLEAN |
56  * | horizontalAlignment | STRING  |
57  * | verticalAlignment   | STRING  |
58  * | textColor           | VECTOR4 |
59  * | enableMarkup        | BOOLEAN |
60  * | enableAutoScroll    | BOOLEAN |
61  * | autoScrollSpeed     | INTEGER |
62  * | autoScrollLoopCount | INTEGER |
63  * | autoScrollGap       | INTEGER |
64  * | lineSpacing         | FLOAT   |
65  * | underline           | STRING  |
66  * | shadow              | STRING  |
67  * | outline             | STRING  |
68  * | batchingEnabled     | BOOLEAN |
69  *
70  */
71 class TextVisual : public Visual::Base
72 {
73 public:
74
75   /**
76    * @brief Create a new text visual.
77    *
78    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
79    * @return A smart-pointer to the newly allocated visual.
80    */
81   static TextVisualPtr New( VisualFactoryCache& factoryCache );
82
83   /**
84    * @brief Sets the text control interface which is needed to communicate with a control.
85    * @param[in] controlInterface Pointer to the control-interface.
86    */
87   void SetTextControlInterface( Text::ControlInterface* controlInterface );
88
89 public: // from Visual::Base
90
91   /**
92    * @copydoc Visual::Base::GetHeightForWidth()
93    */
94   float GetHeightForWidth( float width ) const;
95
96   /**
97    * @copydoc Visual::Base::GetNaturalSize()
98    */
99   virtual void SetSize( const Vector2& size );
100
101   /**
102    * @copydoc Visual::Base::GetNaturalSize()
103    */
104   virtual void GetNaturalSize( Vector2& naturalSize ) const;
105
106   /**
107    * @copydoc Visual::Base::CreatePropertyMap()
108    */
109   virtual void DoCreatePropertyMap( Property::Map& map ) const;
110
111 protected:
112
113   /**
114    * @brief Constructor.
115    *
116    * @param[in] factoryCache The VisualFactoryCache object
117    */
118   TextVisual( VisualFactoryCache& factoryCache );
119
120   /**
121    * @brief A reference counted object may only be deleted by calling Unreference().
122    */
123   virtual ~TextVisual();
124
125   // from Visual::Base
126
127   /**
128    * @copydoc Visual::Base::DoSetProperties()
129    */
130   virtual void DoSetProperties( const Property::Map& propertyMap );
131
132   /**
133    * @copydoc Visual::Base::DoSetOnStage()
134    */
135   virtual void DoSetOnStage( Actor& actor );
136
137   /**
138    * @copydoc Visual::Base::DoSetOffStage()
139    */
140   virtual void DoSetOffStage( Actor& actor );
141
142   /**
143    *@copydoc Visual::Base::DoSetProperty
144    */
145   virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
146
147   /**
148    * @copydoc Visual::Base::DoGetProperty
149    */
150   virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
151
152 private:
153
154   /**
155    * @brief Render view, create and attach actor(s) to this TextView.
156    * @todo In a next patch a new text render back-end won't add extra actors.
157    */
158   void RenderText();
159
160   /**
161    * @brief Stops the text auto scroll.
162    */
163   void StopTextAutoScrolling();
164
165   /**
166    * @brief Set up Autoscrolling.
167    */
168   void SetUpAutoScrolling();
169
170 private:
171   Text::ControllerPtr          mController;               ///< The text's controller.
172   WeakHandle<Actor>            mSelf;
173
174   Text::RendererPtr            mRenderer;
175   Text::TextScrollerPtr        mTextScroller;
176   Actor                        mRenderableActor;
177
178   int mRenderingBackend;
179   bool mHasBeenStaged           : 1;
180 };
181
182 } // namespace Internal
183
184 } // namespace Toolkit
185
186 } // namespace Dali
187
188 #endif /* DALI_TOOLKIT_INTERNAL_TEXT_VISUAL_H */