[dali_1.2.51] Merge branch 'devel/master'
[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 const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] =
85 {
86   { "WRAP_MODE_WORD",      Toolkit::Text::Layout::LineWrap::WORD  },
87   { "WRAP_MODE_CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER }
88 };
89 const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] );
90
91 // Type registration
92 BaseHandle Create()
93 {
94   return Toolkit::TextLabel::New();
95 }
96
97 // Setup properties, signals and actions using the type-registry.
98 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextLabel, Toolkit::Control, Create );
99
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "renderingBackend",          INTEGER, RENDERING_BACKEND      )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "text",                      STRING,  TEXT                   )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontFamily",                STRING,  FONT_FAMILY            )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "fontStyle",                 MAP,     FONT_STYLE             )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pointSize",                 FLOAT,   POINT_SIZE             )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "multiLine",                 BOOLEAN, MULTI_LINE             )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "horizontalAlignment",       STRING,  HORIZONTAL_ALIGNMENT   )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "verticalAlignment",         STRING,  VERTICAL_ALIGNMENT     )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "textColor",                 VECTOR4, TEXT_COLOR             )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowOffset",              VECTOR2, SHADOW_OFFSET          )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadowColor",               VECTOR4, SHADOW_COLOR           )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineEnabled",          BOOLEAN, UNDERLINE_ENABLED      )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineColor",            VECTOR4, UNDERLINE_COLOR        )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underlineHeight",           FLOAT,   UNDERLINE_HEIGHT       )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableMarkup",              BOOLEAN, ENABLE_MARKUP          )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "enableAutoScroll",          BOOLEAN, ENABLE_AUTO_SCROLL     )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollSpeed",           INTEGER, AUTO_SCROLL_SPEED      )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopCount",       INTEGER, AUTO_SCROLL_LOOP_COUNT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollGap",             FLOAT,   AUTO_SCROLL_GAP        )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineSpacing",               FLOAT,   LINE_SPACING           )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "underline",                 MAP,     UNDERLINE              )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "shadow",                    MAP,     SHADOW                 )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "emboss",                    MAP,     EMBOSS                 )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "outline",                   MAP,     OUTLINE                )
124 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "pixelSize",           FLOAT,   PIXEL_SIZE             )
125 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis",            BOOLEAN, ELLIPSIS               )
126 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT,   AUTO_SCROLL_LOOP_DELAY )
127 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode",  STRING,  AUTO_SCROLL_STOP_MODE  )
128 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT             )
129 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode",        STRING,  LINE_WRAP_MODE         )
130 DALI_DEVEL_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColorAnimatable", Color::WHITE, TEXT_COLOR_ANIMATABLE )
131 DALI_TYPE_REGISTRATION_END()
132
133 } // namespace
134
135 Toolkit::TextLabel TextLabel::New()
136 {
137   // Create the implementation, temporarily owned by this handle on stack
138   IntrusivePtr< TextLabel > impl = new TextLabel();
139
140   // Pass ownership to CustomActor handle
141   Toolkit::TextLabel handle( *impl );
142
143   // Second-phase init of the implementation
144   // This can only be done after the CustomActor connection has been made...
145   impl->Initialize();
146
147   return handle;
148 }
149
150 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
151 {
152   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
153
154   if( label )
155   {
156     TextLabel& impl( GetImpl( label ) );
157     switch( index )
158     {
159       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
160       {
161         int backend = value.Get< int >();
162
163 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
164         if( Text::RENDERING_VECTOR_BASED == backend )
165         {
166           backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
167         }
168 #endif
169         if( impl.mRenderingBackend != backend )
170         {
171           impl.mRenderingBackend = backend;
172           impl.mRenderer.Reset();
173
174           if( impl.mController )
175           {
176             // When using the vector-based rendering, the size of the GLyphs are different
177             TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
178             impl.mController->SetGlyphType( glyphType );
179           }
180         }
181         break;
182       }
183       case Toolkit::TextLabel::Property::TEXT:
184       {
185         if( impl.mController )
186         {
187           impl.mController->SetText( value.Get< std::string >() );
188         }
189         break;
190       }
191       case Toolkit::TextLabel::Property::FONT_FAMILY:
192       {
193         if( impl.mController )
194         {
195           const std::string& fontFamily = value.Get< std::string >();
196
197           DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::SetProperty Property::FONT_FAMILY newFont(%s)\n", fontFamily.c_str() );
198           impl.mController->SetDefaultFontFamily( fontFamily );
199         }
200         break;
201       }
202       case Toolkit::TextLabel::Property::FONT_STYLE:
203       {
204         SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
205         break;
206       }
207       case Toolkit::TextLabel::Property::POINT_SIZE:
208       {
209         if( impl.mController )
210         {
211           const float pointSize = value.Get< float >();
212
213           if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
214           {
215             impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
216           }
217         }
218         break;
219       }
220       case Toolkit::TextLabel::Property::MULTI_LINE:
221       {
222         if( impl.mController )
223         {
224           impl.mController->SetMultiLineEnabled( value.Get< bool >() );
225         }
226         break;
227       }
228       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
229       {
230         if( impl.mController )
231         {
232           Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
233           if( Scripting::GetEnumeration< Toolkit::Text::Layout::HorizontalAlignment >( value.Get< std::string >().c_str(),
234                                                                                        HORIZONTAL_ALIGNMENT_STRING_TABLE,
235                                                                                        HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
236                                                                                        alignment ) )
237           {
238             impl.mController->SetHorizontalAlignment( alignment );
239           }
240         }
241         break;
242       }
243       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
244       {
245         if( impl.mController )
246         {
247           Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
248           if( Scripting::GetEnumeration< Toolkit::Text::Layout::VerticalAlignment >( value.Get< std::string >().c_str(),
249                                                                                      VERTICAL_ALIGNMENT_STRING_TABLE,
250                                                                                      VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
251                                                                                      alignment ) )
252           {
253             impl.mController->SetVerticalAlignment( alignment );
254           }
255         }
256         break;
257       }
258
259       case Toolkit::TextLabel::Property::TEXT_COLOR:
260       {
261         SetProperty( object, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, value );
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->StopScrolling();
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       case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
490       {
491         const std::string& wrapModeStr = value.Get< std::string >();
492         DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() );
493
494         Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD );
495         if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(),
496                                                                  LINE_WRAP_MODE_STRING_TABLE,
497                                                                  LINE_WRAP_MODE_STRING_TABLE_COUNT,
498                                                                  lineWrapMode ) )
499         {
500           impl.mController->SetLineWrapMode( lineWrapMode );
501         }
502         break;
503       }
504     }
505   }
506 }
507
508 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
509 {
510   Property::Value value;
511
512   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
513
514   if( label )
515   {
516     TextLabel& impl( GetImpl( label ) );
517     switch( index )
518     {
519       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
520       {
521         value = impl.mRenderingBackend;
522         break;
523       }
524       case Toolkit::TextLabel::Property::TEXT:
525       {
526         if( impl.mController )
527         {
528           std::string text;
529           impl.mController->GetText( text );
530           value = text;
531         }
532         break;
533       }
534       case Toolkit::TextLabel::Property::FONT_FAMILY:
535       {
536         if( impl.mController )
537         {
538           value = impl.mController->GetDefaultFontFamily();
539         }
540         break;
541       }
542       case Toolkit::TextLabel::Property::FONT_STYLE:
543       {
544         GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
545         break;
546       }
547       case Toolkit::TextLabel::Property::POINT_SIZE:
548       {
549         if( impl.mController )
550         {
551           value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
552         }
553         break;
554       }
555       case Toolkit::TextLabel::Property::MULTI_LINE:
556       {
557         if( impl.mController )
558         {
559           value = impl.mController->IsMultiLineEnabled();
560         }
561         break;
562       }
563       case Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT:
564       {
565         if( impl.mController )
566         {
567           const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
568                                                                                                           HORIZONTAL_ALIGNMENT_STRING_TABLE,
569                                                                                                           HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
570           if( name )
571           {
572             value = std::string( name );
573           }
574         }
575         break;
576       }
577       case Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT:
578       {
579         if( impl.mController )
580         {
581           const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
582                                                                                                         VERTICAL_ALIGNMENT_STRING_TABLE,
583                                                                                                         VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
584           if( name )
585           {
586             value = std::string( name );
587           }
588         }
589         break;
590       }
591       case Toolkit::TextLabel::Property::TEXT_COLOR:
592       case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
593       {
594         if ( impl.mController )
595         {
596           value = impl.mController->GetDefaultColor();
597         }
598         break;
599       }
600       case Toolkit::TextLabel::Property::SHADOW_OFFSET:
601       {
602         if ( impl.mController )
603         {
604           value = impl.mController->GetShadowOffset();
605         }
606         break;
607       }
608       case Toolkit::TextLabel::Property::SHADOW_COLOR:
609       {
610         if ( impl.mController )
611         {
612           value = impl.mController->GetShadowColor();
613         }
614         break;
615       }
616       case Toolkit::TextLabel::Property::UNDERLINE_COLOR:
617       {
618         if ( impl.mController )
619         {
620           value = impl.mController->GetUnderlineColor();
621         }
622         break;
623       }
624       case Toolkit::TextLabel::Property::UNDERLINE_ENABLED:
625       {
626         if ( impl.mController )
627         {
628           value = impl.mController->IsUnderlineEnabled();
629         }
630         break;
631       }
632       case Toolkit::TextLabel::Property::UNDERLINE_HEIGHT:
633       {
634         if ( impl.mController )
635         {
636           value = impl.mController->GetUnderlineHeight();
637         }
638         break;
639       }
640       case Toolkit::TextLabel::Property::ENABLE_MARKUP:
641       {
642         if( impl.mController )
643         {
644           value = impl.mController->IsMarkupProcessorEnabled();
645         }
646         break;
647       }
648       case Toolkit::TextLabel::Property::ENABLE_AUTO_SCROLL:
649       {
650         if( impl.mController )
651         {
652           value = impl.mController->IsAutoScrollEnabled();
653         }
654         break;
655       }
656       case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_STOP_MODE:
657       {
658         if( impl.mTextScroller )
659         {
660           const char* mode = Scripting::GetEnumerationName< Toolkit::DevelTextLabel::AutoScrollStopMode::Type >( impl.mTextScroller->GetStopMode(),
661                                                                                                                  AUTO_SCROLL_STOP_MODE_TABLE,
662                                                                                                                  AUTO_SCROLL_STOP_MODE_TABLE_COUNT );
663           if( mode )
664           {
665             value = std::string( mode );
666           }
667         }
668         break;
669       }
670       case Toolkit::TextLabel::Property::AUTO_SCROLL_SPEED:
671       {
672         TextLabel& impl( GetImpl( label ) );
673         if ( impl.mTextScroller )
674         {
675           value = impl.mTextScroller->GetSpeed();
676         }
677         break;
678       }
679       case Toolkit::TextLabel::Property::AUTO_SCROLL_LOOP_COUNT:
680       {
681         if( impl.mController )
682         {
683           TextLabel& impl( GetImpl( label ) );
684           if ( impl.mTextScroller )
685           {
686             value = impl.mTextScroller->GetLoopCount();
687           }
688         }
689         break;
690       }
691       case Toolkit::DevelTextLabel::Property::AUTO_SCROLL_LOOP_DELAY:
692       {
693         if( impl.mController )
694         {
695           TextLabel& impl( GetImpl( label ) );
696           if ( impl.mTextScroller )
697           {
698             value = impl.mTextScroller->GetLoopDelay();
699           }
700         }
701         break;
702       }
703       case Toolkit::TextLabel::Property::AUTO_SCROLL_GAP:
704       {
705         TextLabel& impl( GetImpl( label ) );
706         if ( impl.mTextScroller )
707         {
708           value = impl.mTextScroller->GetGap();
709         }
710         break;
711       }
712       case Toolkit::TextLabel::Property::LINE_SPACING:
713       {
714         if( impl.mController )
715         {
716           value = impl.mController->GetDefaultLineSpacing();
717         }
718         break;
719       }
720       case Toolkit::TextLabel::Property::UNDERLINE:
721       {
722         GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
723         break;
724       }
725       case Toolkit::TextLabel::Property::SHADOW:
726       {
727         GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
728         break;
729       }
730       case Toolkit::TextLabel::Property::EMBOSS:
731       {
732         GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
733         break;
734       }
735       case Toolkit::TextLabel::Property::OUTLINE:
736       {
737         GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
738         break;
739       }
740       case Toolkit::DevelTextLabel::Property::PIXEL_SIZE:
741       {
742         if( impl.mController )
743         {
744           value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
745         }
746         break;
747       }
748       case Toolkit::DevelTextLabel::Property::ELLIPSIS:
749       {
750         if( impl.mController )
751         {
752           value = impl.mController->IsTextElideEnabled();
753         }
754         break;
755       }
756       case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE:
757       {
758         if( impl.mController )
759         {
760           value = impl.mController->GetLineWrapMode();
761         }
762         break;
763       }
764       case Toolkit::DevelTextLabel::Property::LINE_COUNT:
765       {
766         if( impl.mController )
767         {
768           float width = label.GetProperty( Actor::Property::SIZE_WIDTH ).Get<float>();
769           value = impl.mController->GetLineCount( width );
770         }
771         break;
772       }
773     }
774   }
775
776   return value;
777 }
778
779 void TextLabel::OnInitialize()
780 {
781   Actor self = Self();
782
783   mController = Text::Controller::New( this );
784
785   // When using the vector-based rendering, the size of the GLyphs are different
786   TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
787   mController->SetGlyphType( glyphType );
788
789   // Use height-for-width negotiation by default
790   self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
791   self.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
792
793   // Enable the text ellipsis.
794   mController->SetTextElideEnabled( true );   // If false then text larger than control will overflow
795
796   Layout::Engine& engine = mController->GetLayoutEngine();
797   engine.SetCursorWidth( 0u ); // Do not layout space for the cursor.
798
799   self.OnStageSignal().Connect( this, &TextLabel::OnStageConnect );
800 }
801
802 void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
803 {
804   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnStyleChange\n");
805
806   switch ( change )
807   {
808     case StyleChange::DEFAULT_FONT_CHANGE:
809     {
810       // Property system did not set the font so should update it.
811       const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
812       DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE newFont(%s)\n", newFont.c_str() );
813       mController->UpdateAfterFontChange( newFont );
814       RelayoutRequest();
815       break;
816     }
817     case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
818     {
819       GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
820       RelayoutRequest();
821       break;
822     }
823     case StyleChange::THEME_CHANGE:
824     {
825       // Nothing to do, let control base class handle this
826       break;
827     }
828   }
829
830   // Up call to Control
831   Control::OnStyleChange( styleManager, change );
832 }
833
834 Vector3 TextLabel::GetNaturalSize()
835 {
836   return mController->GetNaturalSize();
837 }
838
839 float TextLabel::GetHeightForWidth( float width )
840 {
841   Padding padding;
842   Self().GetPadding( padding );
843   return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
844 }
845
846 void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
847 {
848   DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
849
850   switch ( index )
851   {
852     case Toolkit::TextLabel::Property::TEXT_COLOR:
853     case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
854     {
855       const Vector4& textColor = propertyValue.Get< Vector4 >();
856       if( mController->GetDefaultColor() != textColor )
857       {
858          mController->SetDefaultColor( textColor );
859          mRenderer.Reset();
860       }
861       break;
862     }
863     default:
864     {
865       Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
866       break;
867     }
868   }
869 }
870
871 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
872 {
873   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
874
875   Padding padding;
876   Self().GetPadding( padding );
877   Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
878
879
880   const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
881
882   if( ( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) ) ||
883       !mRenderer )
884   {
885     if( !mRenderer )
886     {
887       mRenderer = Text::Backend::Get().NewRenderer( mRenderingBackend );
888     }
889     RenderText();
890   }
891 }
892
893 void TextLabel::RequestTextRelayout()
894 {
895   RelayoutRequest();
896 }
897
898 void TextLabel::RenderText()
899 {
900   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::RenderText IsAutoScrollEnabled[%s] [%p]\n", ( mController->IsAutoScrollEnabled())?"true":"false", this );
901
902   Actor self = Self();
903   Actor renderableActor;
904
905   float alignmentOffset = 0.f;
906   if( mRenderer )
907   {
908
909     Dali::Toolkit::TextLabel handle = Dali::Toolkit::TextLabel( GetOwner() );
910
911     renderableActor = mRenderer->Render( mController->GetView(),
912                                          handle,
913                                          Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE,
914                                          alignmentOffset,
915                                          DepthIndex::CONTENT );
916   }
917
918   if( renderableActor != mRenderableActor )
919   {
920     UnparentAndReset( mRenderableActor );
921
922     if( renderableActor )
923     {
924       const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
925       Padding padding;
926       self.GetPadding( padding );
927       renderableActor.SetPosition( scrollOffset.x + alignmentOffset + padding.left, scrollOffset.y + padding.top );
928
929       self.Add( renderableActor );
930     }
931     mRenderableActor = renderableActor;
932
933     if ( mController->IsAutoScrollEnabled() )
934     {
935       SetUpAutoScrolling();
936     }
937   }
938 }
939
940 void TextLabel::SetUpAutoScrolling()
941 {
942   const Size& controlSize = mController->GetView().GetControlSize();
943   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.
944   const float alignmentOffset = mController->GetAutoScrollLineAlignment();
945   const Text::CharacterDirection direction = mController->GetAutoScrollDirection();
946
947   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling alignmentOffset[%f] offScreenSize[%f,%f] controlSize[%f,%f]\n",
948                  alignmentOffset, offScreenSize.x,offScreenSize.y , controlSize.x,controlSize.y );
949
950   if ( !mTextScroller )
951   {
952     DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::SetUpAutoScrolling Creating default TextScoller\n" );
953
954     // If speed, loopCount or gap not set via property system then will need to create a TextScroller with defaults
955     mTextScroller = Text::TextScroller::New( *this );
956   }
957   mTextScroller->SetParameters( mRenderableActor, controlSize, offScreenSize, direction, alignmentOffset, mController->GetHorizontalAlignment() );
958
959   Actor self = Self();
960   self.Add( mTextScroller->GetScrollingText() );
961   self.Add( mTextScroller->GetSourceCamera() );
962 }
963
964 void TextLabel::OnStageConnect( Dali::Actor actor )
965 {
966   if ( mHasBeenStaged )
967   {
968     RenderText();
969   }
970   else
971   {
972     mHasBeenStaged = true;
973   }
974 }
975
976 void TextLabel::ScrollingFinished()
977 {
978   // Pure Virtual from TextScroller Interface
979   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::ScrollingFinished\n");
980   mController->SetAutoScrollEnabled( false );
981   mController->SetTextElideEnabled( true );
982   RequestTextRelayout();
983 }
984
985 TextLabel::TextLabel()
986 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
987   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
988   mHasBeenStaged( false )
989 {
990 }
991
992 TextLabel::~TextLabel()
993 {
994 }
995
996 } // namespace Internal
997
998 } // namespace Toolkit
999
1000 } // namespace Dali