Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / text-actor-impl.h
1 #ifndef __DALI_INTERNAL_TEXT_ACTOR_H__
2 #define __DALI_INTERNAL_TEXT_ACTOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/object/ref-object.h>
22 #include <dali/public-api/actors/text-actor.h>
23 #include <dali/internal/event/actors/actor-declarations.h>
24 #include <dali/internal/event/actors/renderable-actor-impl.h>
25 #include <dali/internal/event/text/text-observer.h>
26 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
27 #include <dali/internal/common/text-array.h>
28
29
30 namespace Dali
31 {
32
33 namespace Internal
34 {
35
36 class Font;
37
38 /**
39  * TextActor implementation.
40  * A text actor is an actor with a TextAttachment.
41  * If no size is given to the actor, then after the font has loaded
42  * the actor will be set to the size of the text displayed.
43  *
44  */
45 class TextActor : public RenderableActor, public TextObserver
46 {
47 public:
48
49   enum TextRequestMode
50   {
51     REQUEST_NEW_TEXT,       ///< When changing font, request new text
52     DONT_REQUEST_NEW_TEXT   ///< When changing font, don't request new text
53   };
54
55   /**
56    * @copydoc Dali::TextActor::New(const Dali::Text&,bool,bool)
57    * @return A pointer to a new TextActor.
58    */
59   static TextActorPtr New(const Dali::Text& text, bool fontDetection, bool isLeftToRight);
60
61   /**
62    * @copydoc Dali::TextActor::New(const Dali::Text&,Dali::Font,bool,bool)
63    * @return A pointer to a new TextActor.
64    */
65   static TextActorPtr New(const Dali::Text& text, bool fontDetection, bool isLeftToRight, Font& font);
66
67   /**
68    * @copydoc Dali::TextActor::New(const Text&,const TextStyle&,bool,bool)
69    * @return A pointer to a new TextActor.
70    */
71   static TextActorPtr New(const Dali::Text& text, bool fontDetection, bool isLeftToRight, const Dali::TextStyle& style );
72
73   /**
74    * @copydoc Dali::Internal::Actor::OnInitialize
75    */
76   void OnInitialize();
77
78   /**
79    * @copydoc Dali::TextActor::GetText()
80    */
81   const std::string GetText() const;
82
83   /**
84    * @copydoc Dali::TextActor::SetText()
85    */
86   void SetText(const std::string& text);
87
88   /**
89    * @copydoc Dali::TextActor::SetText()
90    */
91   void SetText(const Dali::Text& text);
92
93   /**
94    * @copybrief Dali::TextActor::SetText(const std::string&)
95    * @param[in] utfCodes  An std::vector containing the UTF-32 codes
96    */
97   void SetText(const TextArray& utfCodes);
98
99   /**
100    * @copydoc Dali::TextActor::SetToNaturalSize()
101    */
102   void SetToNaturalSize();
103
104   /**
105    * @copydoc Dali::TextActor::GetFont()
106    */
107   Font* GetFont() const;
108
109   /**
110    * @copydoc Dali::TextActor::SetFont()
111    * @param TextRequestMode whether new text should be requested
112    */
113   void SetFont(Font& font, TextRequestMode mode = REQUEST_NEW_TEXT );
114
115   /**
116    * @copydoc Dali::TextActor::SetGradientColor()
117    */
118   void SetGradientColor( const Vector4& color );
119
120   /**
121    * @copydoc Dali::TextActor::GetGradientColor()
122    */
123   const Vector4& GetGradientColor() const;
124
125   /**
126    * @copydoc Dali::TextActor::SetGradientStartPoint()
127    */
128   void SetGradientStartPoint( const Vector2& position );
129
130   /**
131    * @copydoc Dali::TextActor::SetGradientStartPoint()
132    */
133   const Vector2& GetGradientStartPoint() const;
134
135   /**
136    * @copydoc Dali::TextActor::SetGradientEndPoint()
137    */
138   void SetGradientEndPoint( const Vector2& position );
139
140   /**
141    * @copydoc Dali::TextActor::GetGradientEndPoint()
142    */
143   const Vector2& GetGradientEndPoint() const;
144
145   /**
146    * @copydoc Dali::TextActor::SetTextStyle( const TextStyle& style )
147    * @param mode whether new text should be requested
148    */
149   void SetTextStyle( const TextStyle& style, TextRequestMode mode = REQUEST_NEW_TEXT );
150
151   /**
152    * @copydoc Dali::TextActor::GetTextStyle()
153    */
154   TextStyle GetTextStyle() const;
155
156   /**
157    * @copydoc Dali::TextActor::SetTextColor(const Vector4&)
158    */
159   void SetTextColor(const Vector4& color);
160
161   /**
162    * @copydoc Dali::TextActor::GetTextColor()
163    */
164   Vector4 GetTextColor() const;
165
166   /**
167    * @copydoc Dali::TextActor::SetSmoothEdge(const float)
168    */
169   void SetSmoothEdge(const float smoothEdge);
170
171   /**
172    * @copydoc Dali::TextActor::SetOutline(const bool,const Vector4&,const Vector2&)
173    */
174   void SetOutline(const bool enable, const Vector4& color, const Vector2& thickness);
175
176   /**
177    * @copydoc Dali::TextActor::SetGlow(const bool,const Vector4&,const float)
178    */
179   void SetGlow(const bool enable, const Vector4& color, const float intensity);
180
181   /**
182    * @copydoc Dali::TextActor::SetShadow(const bool,const Vector4&,const Vector2&,const float)
183    */
184   void SetShadow(const bool enable, const Vector4& color, const Vector2& offset, const float size);
185
186   /**
187    * Enable italics on the text actor, the text will be sheared by the given angle.
188    * @param[in] angle Italics angle in radians.
189    */
190   void SetItalics( const Radian& angle );
191
192   /**
193    * @copydoc Dali::TextActor::GetItalics()
194    */
195   const Radian& GetItalics() const;
196
197   /**
198    * @copydoc Dali::TextActor::SetUnderline()
199    */
200   void SetUnderline( bool enable, float thickness, float position );
201
202   /**
203    * @copydoc Dali::TextActor::GetUnderline()
204    */
205   bool GetUnderline() const;
206
207   /**
208    * @return The underline's thickness.
209    */
210   float GetUnderlineThickness() const;
211
212   /**
213    * @return The underline's position.
214    */
215   float GetUnderlinePosition() const;
216
217   /**
218    * @copydoc Dali::TextActor::SetWeight()
219    */
220   void SetWeight( TextStyle::Weight weight );
221
222   /**
223    * @copydoc Dali::TextActor::GetWeight()
224    */
225   TextStyle::Weight GetWeight() const;
226
227   /**
228    * @copydoc Dali::TextActor::SetFontDetectionAutomatic()
229    */
230   void SetFontDetectionAutomatic(bool value);
231
232   /**
233    * @copydoc Dali::TextActor::IsFontDetectionAutomatic()
234    */
235   bool IsFontDetectionAutomatic() const;
236
237 private: // from Actor
238
239   /**
240    * @copydoc Actor::OnSizeSet
241    */
242   virtual void OnSizeSet(const Vector3& targetSize);
243
244   /**
245    * @copydoc Actor::OnSizeAnimation( Animation& animation, const Vector3& targetSize )
246    */
247   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
248
249 private: // From RenderableActor
250
251   /**
252    * @copydoc RenderableActor::GetRenderableAttachment
253    */
254   virtual RenderableAttachment& GetRenderableAttachment() const;
255
256 protected:
257
258   /**
259    * Protected constructor; see also TextActor::New()
260    */
261   TextActor(bool fontDetection, bool isLeftToRight );
262
263   /**
264    * A reference counted object may only be deleted by calling Unreference()
265    */
266   virtual ~TextActor();
267
268 public:
269
270   /**
271    * @copydoc Dali::Image::GetLoadingState()
272    */
273   Dali::LoadingState GetLoadingState() const { return mLoadingState; }
274
275   /**
276    * @copydoc Dali::TextActor::TextAvailableSignal()
277    */
278   Dali::TextActor::TextSignalV2& TextAvailableSignal() { return mLoadingFinishedV2; }
279
280   /**
281    * Connects a callback function with the text actors signals.
282    * @param[in] object The object providing the signal.
283    * @param[in] tracker Used to disconnect the signal.
284    * @param[in] signalName The signal to connect to.
285    * @param[in] functor A newly allocated FunctorDelegate.
286    * @return True if the signal was connected.
287    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
288    */
289   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
290
291 public: // From TextObserver
292
293   /**
294    * @copydoc Dali::Internal::TextObserver::TextLoaded()
295    */
296   virtual void TextLoaded();
297
298 private:
299
300   /**
301    * Text has been changed observe ticket or
302    * emit text available signal
303    */
304   void TextChanged();
305
306   /**
307    * Checks whether the text is loaded or not
308    * @return true if text is loaded
309    */
310   bool CheckTextLoadState();
311
312   /**
313    * Stop observing text loads on the current font.
314    */
315   void StopObservingTextLoads();
316
317   /**
318    * Start observing text loads on the current font.
319    */
320   void StartObservingTextLoads();
321
322   // Undefined
323   TextActor(const TextActor&);
324
325   // Undefined
326   TextActor& operator=(const TextActor& rhs);
327
328 private: // ProxyObject default non-animatable properties
329   /**
330    * copydoc Dali::Internal::ProxyObject
331    */
332   virtual unsigned int GetDefaultPropertyCount() const ;
333
334   /**
335    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
336    */
337   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
338
339   /**
340    * copydoc Dali::Internal::ProxyObject
341    */
342   virtual const std::string& GetDefaultPropertyName( Property::Index index ) const ;
343
344   /**
345    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
346    */
347   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
348
349   /**
350    * copydoc Dali::Internal::ProxyObject
351    */
352   virtual bool IsDefaultPropertyWritable( Property::Index index ) const ;
353
354   /**
355    * copydoc Dali::Internal::ProxyObject
356    */
357   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const ;
358
359   /**
360    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
361    */
362   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
363
364   /**
365    * copydoc Dali::Internal::ProxyObject
366    */
367   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const ;
368
369   /**
370    * copydoc Dali::Internal::ProxyObject
371    */
372   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) ;
373
374   /**
375    * copydoc Dali::Internal::ProxyObject
376    */
377   virtual Property::Value GetDefaultProperty( Property::Index index ) const ;
378
379 protected:
380
381   TextAttachmentPtr mTextAttachment; ///< Used to display the text
382
383   Dali::LoadingState mLoadingState;
384
385 private:
386
387   Dali::TextActor::TextSignalV2 mLoadingFinishedV2;
388   bool mUsingNaturalSize:1;  ///< whether the actor is using natural size
389   bool mInternalSetSize:1;  ///< to determine when we are internally setting size
390   bool mFontDetection:1;  ///< tells whether TextActor should query platform abstraction after SetText
391   bool mIsLeftToRight:1;  ///< tells whether text is displayed from left to right or from right to left
392   bool mObserving:1;      ///< Whether the text actor is waiting for text to load
393   static bool mFirstInstance;
394   static DefaultPropertyLookup* mDefaultTextActorPropertyLookup; ///< Default properties
395 };
396
397 } // namespace Internal
398
399 // Helpers for public-api forwarding methods
400
401 inline Internal::TextActor& GetImplementation(Dali::TextActor& actor)
402 {
403   DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
404
405   BaseObject& handle = actor.GetBaseObject();
406
407   return static_cast<Internal::TextActor&>(handle);
408 }
409
410 inline const Internal::TextActor& GetImplementation(const Dali::TextActor& actor)
411 {
412   DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
413
414   const BaseObject& handle = actor.GetBaseObject();
415
416   return static_cast<const Internal::TextActor&>(handle);
417 }
418
419 } // namespace Dali
420
421 #endif // __DALI_INTERNAL_TEXT_ACTOR_H__