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