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