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