Add read-only property for getting text line count
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry-helper.h>
23 #include <dali/devel-api/object/property-helper-devel.h>
24 #include <dali/integration-api/debug.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/text/rendering-backend.h>
28 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
29 #include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
30 #include <dali-toolkit/internal/text/property-string-parser.h>
31 #include <dali-toolkit/internal/text/rendering/text-backend.h>
32 #include <dali-toolkit/internal/text/text-effects-style.h>
33 #include <dali-toolkit/internal/text/text-font-style.h>
34 #include <dali-toolkit/internal/text/text-view.h>
35 #include <dali-toolkit/internal/text/text-definitions.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
37
38 using namespace Dali::Toolkit::Text;
39
40 namespace Dali
41 {
42
43 namespace Toolkit
44 {
45
46 namespace Internal
47 {
48
49 namespace
50 {
51   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
52 }
53
54 namespace
55 {
56
57 #if defined ( DEBUG_ENABLED )
58   Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
59 #endif
60
61 const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] =
62 {
63   { "IMMEDIATE", Toolkit::DevelTextLabel::AutoScrollStopMode::IMMEDIATE },
64   { "FINISH_LOOP",  Toolkit::DevelTextLabel::AutoScrollStopMode::FINISH_LOOP  },
65 };
66 const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_TABLE[0] );
67
68 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
69 {
70   { "BEGIN",  Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN  },
71   { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
72   { "END",    Toolkit::Text::Layout::HORIZONTAL_ALIGN_END    },
73 };
74 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
75
76 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
77 {
78   { "TOP",    Toolkit::Text::Layout::VERTICAL_ALIGN_TOP    },
79   { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
80   { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
81 };
82 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
83
84 // Type registration
85 BaseHandle Create()
86 {
87   return Toolkit::TextLabel::New();
88 }
89
90 // Setup properties, signals and actions using the type-registry.
91 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
92
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend",          INTEGER, RENDERING_BACKEND      )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text",                      STRING,  TEXT                   )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily",                STRING,  FONT_FAMILY            )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle",                 MAP,     FONT_STYLE             )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize",                 FLOAT,   POINT_SIZE             )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine",                 BOOLEAN, MULTI_LINE             )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment",       STRING,  HORIZONTAL_ALIGNMENT   )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment",         STRING,  VERTICAL_ALIGNMENT     )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textColor",                 VECTOR4, TEXT_COLOR             )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset",              VECTOR2, SHADOW_OFFSET          )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor",               VECTOR4, SHADOW_COLOR           )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled",          BOOLEAN, UNDERLINE_ENABLED      )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor",            VECTOR4, UNDERLINE_COLOR        )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight",           FLOAT,   UNDERLINE_HEIGHT       )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup",              BOOLEAN, ENABLE_MARKUP          )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll",          BOOLEAN, ENABLE_AUTO_SCROLL     )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed",           INTEGER, AUTO_SCROLL_SPEED      )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount",       INTEGER, AUTO_SCROLL_LOOP_COUNT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap",             FLOAT,   AUTO_SCROLL_GAP        )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing",               FLOAT,   LINE_SPACING           )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline",                 MAP,     UNDERLINE              )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow",                    MAP,     SHADOW                 )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss",                    MAP,     EMBOSS                 )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline",                   MAP,     OUTLINE                )
117 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize",           FLOAT,   PIXEL_SIZE             )
118 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis",            BOOLEAN, ELLIPSIS               )
119 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT,   AUTO_SCROLL_LOOP_DELAY )
120 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode",  STRING,  AUTO_SCROLL_STOP_MODE  )
121 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT             )
122
123 DALI_TYPE_REGISTRATION_END()
124
125 } // namespace
126
127 Toolkit::TextLabel TextLabel::New()
128 {
129   // Create the implementation, temporarily owned by this handle on stack
130   IntrusivePtr< TextLabel > impl = new TextLabel();
131
132   // Pass ownership to CustomActor handle
133   Toolkit::TextLabel handle( *impl );
134
135   // Second-phase init of the implementation
136   // This can only be done after the CustomActor connection has been made...
137   impl->Initialize();
138
139   return handle;
140 }
141
142 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
143 {
144   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
145
146   if( label )
147   {
148     TextLabel& impl( GetImpl( label ) );
149     switch( index )
150     {
151       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
152       {
153         int backend = value.Get< int >();
154
155 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
156         if( Text::RENDERING_VECTOR_BASED == backend )
157         {
158           backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
159         }
160 #endif
161         if( impl.mRenderingBackend != backend )
162         {
163           impl.mRenderingBackend = backend;
164           impl.mRenderer.Reset();
165
166           if( impl.mController )
167           {
168             // When using the vector-based rendering, the size of the GLyphs are different
169             TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
170             impl.mController->SetGlyphType( glyphType );
171           }
172         }
173         break;
174       }
175       case Toolkit::TextLabel::Property::TEXT:
176       {
177         if( impl.mController )
178         {
179           impl.mController->SetText( value.Get< std::string >() );
180         }
181         break;
182       }
183       case Toolkit::TextLabel::Property::FONT_FAMILY:
184       {
185         if( impl.mController )
186         {
187           const std::string& fontFamily = value.Get< std::string >();
188
189           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
190           impl.mController->SetDefaultFontFamily( fontFamily );
191         }
192         break;
193       }
194       case Toolkit::TextLabel::Property::FONT_STYLE:
195       {
196         SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
197         break;
198       }
199       case Toolkit::TextLabel::Property::POINT_SIZE:
200       {
201         if( impl.mController )
202         {
203           const float pointSize = value.Get< float >();
204
205           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
206           {
207             impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
208           }
209         }
210         break;
211       }
212       case Toolkit::TextLabel::Property::MULTI_LINE:
213       {
214         if( impl.mController )
215         {
216           impl.mController->SetMultiLineEnabled( value.Get< bool >() );
217         }
218         break;
219       }
220       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
221       {
222         if( impl.mController )
223         {
224           Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
225           if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
226                                                                                        HORIZONTAL_ALIGNMENT_STRING_TABLE,
227                                                                                        HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
228                                                                                        alignment ) )
229           {
230             impl.mController->SetHorizontalAlignment( alignment );
231           }
232         }
233         break;
234       }
235       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
236       {
237         if( impl.mController )
238         {
239           Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
240           if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
241                                                                                      VERTICAL_ALIGNMENT_STRING_TABLE,
242                                                                                      VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
243                                                                                      alignment ) )
244           {
245             impl.mController->SetVerticalAlignment( alignment );
246           }
247         }
248         break;
249       }
250
251       case Toolkit::TextLabel::Property::TEXT_COLOR:
252       {
253         if( impl.mController )
254         {
255           const Vector4& textColor = value.Get< Vector4 >();
256           if( impl.mController->GetDefaultColor() != textColor )
257           {
258             impl.mController->SetDefaultColor( textColor );
259             impl.mRenderer.Reset();
260           }
261         }
262         break;
263       }
264
265       case Toolkit::TextLabel::Property::SHADOW_OFFSET:
266       {
267         if( impl.mController )
268         {
269           const Vector2& shadowOffset = value.Get< Vector2 >();
270           if ( impl.mController->GetShadowOffset() != shadowOffset )
271           {
272             impl.mController->SetShadowOffset( shadowOffset );
273             impl.mRenderer.Reset();
274           }
275         }
276         break;
277       }
278       case Toolkit::TextLabel::Property::SHADOW_COLOR:
279       {
280         if( impl.mController )
281         {
282           const Vector4& shadowColor = value.Get< Vector4 >();
283           if ( impl.mController->GetShadowColor() != shadowColor )
284           {
285             impl.mController->SetShadowColor( shadowColor );
286             impl.mRenderer.Reset();
287           }
288         }
289         break;
290       }
291       case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
292       {
293         if( impl.mController )
294         {
295           const Vector4& color = value.Get< Vector4 >();
296           if ( impl.mController->GetUnderlineColor() != color )
297           {
298             impl.mController->SetUnderlineColor( color );
299             impl.mRenderer.Reset();
300           }
301         }
302         break;
303       }
304       case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
305       {
306         if( impl.mController )
307         {
308           const bool enabled = value.Get< bool >();
309           if ( impl.mController->IsUnderlineEnabled() != enabled )
310           {
311             impl.mController->SetUnderlineEnabled( enabled );
312             impl.mRenderer.Reset();
313           }
314         }
315         break;
316       }
317
318       case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
319       {
320         if( impl.mController )
321         {
322           float height = value.Get< float >();
323           if( fabsf( impl.mController->GetUnderlineHeight() - height ) > Math::MACHINE_EPSILON_1000 )
324           {
325             impl.mController->SetUnderlineHeight( height );
326             impl.mRenderer.Reset();
327           }
328         }
329         break;
330       }
331       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
332       {
333         if( impl.mController )
334         {
335           const bool enableMarkup = value.Get<bool>();
336           impl.mController->SetMarkupProcessorEnabled( enableMarkup );
337         }
338         break;
339       }
340       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
341       {
342         if( impl.mController )
343         {
344           const bool enableAutoScroll = value.Get<bool>();
345           // If request to auto scroll is the same as current state then do nothing.
346           if ( enableAutoScroll != impl.mController->IsAutoScrollEnabled() )
347           {
348              // If request is disable (false) and auto scrolling is enabled then need to stop it
349              if ( enableAutoScroll == false )
350              {
351                if( impl.mTextScroller )
352                {
353                  impl.mTextScroller->SetLoopCount( 0 ); // Causes the current animation to finish playing (0)
354                }
355              }
356              // If request is enable (true) then start autoscroll as not already running
357              else
358              {
359                impl.mController->SetTextElideEnabled( false );
360                impl.mController->SetAutoScrollEnabled( enableAutoScroll );
361              }
362           }
363         }
364         break;
365       }
366       case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
367       {
368         if( !impl.mTextScroller )
369         {
370           impl.mTextScroller = Text::TextScroller::New( impl );
371         }
372         DevelTextLabel::AutoScrollStopMode::Type stopMode = impl.mTextScroller->GetStopMode();
373         if( Scripting::GetEnumerationProperty< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( value,
374                                                                                                     AUTO_SCROLL_STOP_MODE_TABLE,
375                                                                                                     AUTO_SCROLL_STOP_MODE_TABLE_COUNT,
376                                                                                                     stopMode ) )
377         {
378             impl.mTextScroller->SetStopMode( stopMode );
379         }
380         break;
381       }
382       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
383       {
384         if( !impl.mTextScroller )
385         {
386           impl.mTextScroller = Text::TextScroller::New( impl );
387         }
388         impl.mTextScroller->SetSpeed( value.Get<int>() );
389         break;
390       }
391       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
392       {
393         if( !impl.mTextScroller )
394         {
395           impl.mTextScroller = Text::TextScroller::New( impl );
396         }
397         impl.mTextScroller->SetLoopCount( value.Get<int>() );
398         break;
399       }
400       case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
401       {
402          if( !impl.mTextScroller )
403         {
404           impl.mTextScroller = Text::TextScroller::New( impl );
405         }
406         impl.mTextScroller->SetLoopDelay( value.Get<float>() );
407         break;
408       }
409       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
410       {
411         if( !impl.mTextScroller )
412         {
413           impl.mTextScroller = Text::TextScroller::New( impl );
414         }
415         impl.mTextScroller->SetGap( value.Get<float>() );
416         break;
417       }
418       case Toolkit::TextLabel::Property::LINE_SPACING:
419       {
420         if( impl.mController )
421         {
422           const float lineSpacing = value.Get<float>();
423           impl.mController->SetDefaultLineSpacing( lineSpacing );
424           impl.mRenderer.Reset();
425         }
426         break;
427       }
428       case Toolkit::TextLabel::Property::UNDERLINE:
429       {
430         const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
431         if( update )
432         {
433           impl.mRenderer.Reset();
434         }
435         break;
436       }
437       case Toolkit::TextLabel::Property::SHADOW:
438       {
439         const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
440         if( update )
441         {
442           impl.mRenderer.Reset();
443         }
444         break;
445       }
446       case Toolkit::TextLabel::Property::EMBOSS:
447       {
448         const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
449         if( update )
450         {
451           impl.mRenderer.Reset();
452         }
453         break;
454       }
455       case Toolkit::TextLabel::Property::OUTLINE:
456       {
457         const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
458         if( update )
459         {
460           impl.mRenderer.Reset();
461         }
462         break;
463       }
464       case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
465       {
466         if( impl.mController )
467         {
468           const float pixelSize = value.Get< float >();
469           DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
470
471           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
472           {
473             impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
474           }
475         }
476         break;
477       }
478       case Toolkit::DevelTextLabel::Property::ELLIPSIS:
479       {
480         if( impl.mController )
481         {
482           const bool ellipsis = value.Get<bool>();
483           DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
484
485           impl.mController->SetTextElideEnabled( ellipsis );
486         }
487         break;
488       }
489     }
490   }
491 }
492
493 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
494 {
495   Property::Value value;
496
497   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
498
499   if( label )
500   {
501     TextLabel& impl( GetImpl( label ) );
502     switch( index )
503     {
504       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
505       {
506         value = impl.mRenderingBackend;
507         break;
508       }
509       case Toolkit::TextLabel::Property::TEXT:
510       {
511         if( impl.mController )
512         {
513           std::string text;
514           impl.mController->GetText( text );
515           value = text;
516         }
517         break;
518       }
519       case Toolkit::TextLabel::Property::FONT_FAMILY:
520       {
521         if( impl.mController )
522         {
523           value = impl.mController->GetDefaultFontFamily();
524         }
525         break;
526       }
527       case Toolkit::TextLabel::Property::FONT_STYLE:
528       {
529         GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
530         break;
531       }
532       case Toolkit::TextLabel::Property::POINT_SIZE:
533       {
534         if( impl.mController )
535         {
536           value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
537         }
538         break;
539       }
540       case Toolkit::TextLabel::Property::MULTI_LINE:
541       {
542         if( impl.mController )
543         {
544           value = impl.mController->IsMultiLineEnabled();
545         }
546         break;
547       }
548       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
549       {
550         if( impl.mController )
551         {
552           const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
553                                                                                                           HORIZONTAL_ALIGNMENT_STRING_TABLE,
554                                                                                                           HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
555           if( name )
556           {
557             value = std::string( name );
558           }
559         }
560         break;
561       }
562       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
563       {
564         if( impl.mController )
565         {
566           const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
567                                                                                                         VERTICAL_ALIGNMENT_STRING_TABLE,
568                                                                                                         VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
569           if( name )
570           {
571             value = std::string( name );
572           }
573         }
574         break;
575       }
576       case Toolkit::TextLabel::Property::TEXT_COLOR:
577       {
578         if ( impl.mController )
579         {
580           value = impl.mController->GetDefaultColor();
581         }
582         break;
583       }
584       case Toolkit::TextLabel::Property::SHADOW_OFFSET:
585       {
586         if ( impl.mController )
587         {
588           value = impl.mController->GetShadowOffset();
589         }
590         break;
591       }
592       case Toolkit::TextLabel::Property::SHADOW_COLOR:
593       {
594         if ( impl.mController )
595         {
596           value = impl.mController->GetShadowColor();
597         }
598         break;
599       }
600       case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
601       {
602         if ( impl.mController )
603         {
604           value = impl.mController->GetUnderlineColor();
605         }
606         break;
607       }
608       case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
609       {
610         if ( impl.mController )
611         {
612           value = impl.mController->IsUnderlineEnabled();
613         }
614         break;
615       }
616       case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
617       {
618         if ( impl.mController )
619         {
620           value = impl.mController->GetUnderlineHeight();
621         }
622         break;
623       }
624       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
625       {
626         if( impl.mController )
627         {
628           value = impl.mController->IsMarkupProcessorEnabled();
629         }
630         break;
631       }
632       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
633       {
634         if( impl.mController )
635         {
636           value = impl.mController->IsAutoScrollEnabled();
637         }
638         break;
639       }
640       case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
641       {
642         if( impl.mTextScroller )
643         {
644           const char* mode = Scripting::GetEnumerationName< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
645                                                                                                                  AUTO_SCROLL_STOP_MODE_TABLE,
646                                                                                                                  AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
647           if( mode )
648           {
649             value = std::string( mode );
650           }
651         }
652         break;
653       }
654       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
655       {
656         TextLabel& impl( GetImpl( label ) );
657         if ( impl.mTextScroller )
658         {
659           value = impl.mTextScroller->GetSpeed();
660         }
661         break;
662       }
663       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
664       {
665         if( impl.mController )
666         {
667           TextLabel& impl( GetImpl( label ) );
668           if ( impl.mTextScroller )
669           {
670             value = impl.mTextScroller->GetLoopCount();
671           }
672         }
673         break;
674       }
675       case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
676       {
677         if( impl.mController )
678         {
679           TextLabel& impl( GetImpl( label ) );
680           if ( impl.mTextScroller )
681           {
682             value = impl.mTextScroller->GetLoopDelay();
683           }
684         }
685         break;
686       }
687       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
688       {
689         TextLabel& impl( GetImpl( label ) );
690         if ( impl.mTextScroller )
691         {
692           value = impl.mTextScroller->GetGap();
693         }
694         break;
695       }
696       case Toolkit::TextLabel::Property::LINE_SPACING:
697       {
698         if( impl.mController )
699         {
700           value = impl.mController->GetDefaultLineSpacing();
701         }
702         break;
703       }
704       case Toolkit::TextLabel::Property::UNDERLINE:
705       {
706         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
707         break;
708       }
709       case Toolkit::TextLabel::Property::SHADOW:
710       {
711         GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
712         break;
713       }
714       case Toolkit::TextLabel::Property::EMBOSS:
715       {
716         GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
717         break;
718       }
719       case Toolkit::TextLabel::Property::OUTLINE:
720       {
721         GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
722         break;
723       }
724       case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
725       {
726         if( impl.mController )
727         {
728           value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
729         }
730         break;
731       }
732       case Toolkit::DevelTextLabel::Property::ELLIPSIS:
733       {
734         if( impl.mController )
735         {
736           value = impl.mController->IsTextElideEnabled();
737         }
738         break;
739       }
740       case Toolkit::DevelTextLabel::Property::LINE_COUNT:
741       {
742         if( impl.mController )
743         {
744           float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
745           value = impl.mController->GetLineCount( width );
746         }
747         break;
748       }
749     }
750   }
751
752   return value;
753 }
754
755 void TextLabel::OnInitialize()
756 {
757   Actor self = Self();
758
759   mController = Text::Controller::New( this );
760
761   // When using the vector-based rendering, the size of the GLyphs are different
762   TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
763   mController->SetGlyphType( glyphType );
764
765   // Use height-for-width negotiation by default
766   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
767   self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
768
769   // Enable the text ellipsis.
770   mController->SetTextElideEnabled( true );   // If false then text larger than control will overflow
771
772   Layout::Engine& engine = mController->GetLayoutEngine();
773   engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
774
775   self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
776 }
777
778 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
779 {
780   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
781
782   switch ( change )
783   {
784     case StyleChange::DEFAULT_FONT_CHANGE:
785     {
786       // Property system did not set the font so should update it.
787       const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
788       DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
789       mController->UpdateAfterFontChange( newFont );
790       RelayoutRequest();
791       break;
792     }
793     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
794     {
795       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
796       RelayoutRequest();
797       break;
798     }
799     case StyleChange::THEME_CHANGE:
800     {
801       // Nothing to do, let control base class handle this
802       break;
803     }
804   }
805
806   // Up call to Control
807   Control::OnStyleChange( styleManager, change );
808 }
809
810 Vector3 TextLabel::GetNaturalSize()
811 {
812   return mController->GetNaturalSize();
813 }
814
815 float TextLabel::GetHeightForWidth( float width )
816 {
817   return mController->GetHeightForWidth( width );
818 }
819
820 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
821 {
822   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
823
824   const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
825
826   if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
827       !mRenderer )
828   {
829     if( !mRenderer )
830     {
831       mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
832     }
833     RenderText();
834   }
835 }
836
837 void TextLabel::RequestTextRelayout()
838 {
839   RelayoutRequest();
840 }
841
842 void TextLabel::RenderText()
843 {
844   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
845
846   Actor self = Self();
847   Actor renderableActor;
848
849   float alignmentOffset = 0.f;
850   if( mRenderer )
851   {
852     renderableActor = mRenderer->Render( mController->GetView(),
853                                          alignmentOffset,
854                                          DepthIndex::CONTENT );
855   }
856
857   if( renderableActor != mRenderableActor )
858   {
859     UnparentAndReset( mRenderableActor );
860
861     if( renderableActor )
862     {
863       const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
864       renderableActor.SetPosition( scrollOffset.x + alignmentOffset, scrollOffset.y );
865
866       self.Add( renderableActor );
867     }
868     mRenderableActor = renderableActor;
869
870     if ( mController->IsAutoScrollEnabled() )
871     {
872       SetUpAutoScrolling();
873     }
874   }
875 }
876
877 void TextLabel::SetUpAutoScrolling()
878 {
879   const Size& controlSize = mController->GetView().GetControlSize();
880   const Size offScreenSize = GetNaturalSize().GetVectorXY(); // As relayout of text may not be done at this point natural size is used to get size. Single line scrolling only.
881   const float alignmentOffset = mController->GetAutoScrollLineAlignment();
882   const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
883
884   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
885                  alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
886
887   if ( !mTextScroller )
888   {
889     DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
890
891     // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
892     mTextScroller = Text::TextScroller::New( *this );
893   }
894   mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset );
895
896   Actor self = Self();
897   self.Add( mTextScroller->GetScrollingText() );
898   self.Add( mTextScroller->GetSourceCamera() );
899 }
900
901 void TextLabel::OnStageConnect( Dali::Actor actor )
902 {
903   if ( mHasBeenStaged )
904   {
905     RenderText();
906   }
907   else
908   {
909     mHasBeenStaged = true;
910   }
911 }
912
913 void TextLabel::ScrollingFinished()
914 {
915   // Pure Virtual from TextScroller Interface
916   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
917   mController->SetAutoScrollEnabled( false );
918   mController->SetTextElideEnabled( true );
919   RequestTextRelayout();
920 }
921
922 TextLabel::TextLabel()
923 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
924   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
925   mHasBeenStaged( false )
926 {
927 }
928
929 TextLabel::~TextLabel()
930 {
931 }
932
933 } // namespace Internal
934
935 } // namespace Toolkit
936
937 } // namespace Dali