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