Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
1 /*
2  * Copyright (c) 2015 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.h>
23 #include <dali/integration-api/debug.h>
24
25 namespace
26 {
27
28 } // namespace
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 const Property::Index TextLabel::PROPERTY_TEXT( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX );
37
38 namespace Internal
39 {
40
41 namespace
42 {
43
44 // Type registration
45 BaseHandle Create()
46 {
47   return Toolkit::TextLabel::New();
48 }
49
50 TypeRegistration mType( typeid(Toolkit::TextLabel), typeid(Toolkit::Control), Create );
51
52 PropertyRegistration property1( mType, "text", Toolkit::TextLabel::PROPERTY_TEXT, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty );
53
54 } // namespace
55
56 Toolkit::TextLabel TextLabel::New()
57 {
58   // Create the implementation, temporarily owned by this handle on stack
59   IntrusivePtr< TextLabel > impl = new TextLabel();
60
61   // Pass ownership to CustomActor handle
62   Toolkit::TextLabel handle( *impl );
63
64   // Second-phase init of the implementation
65   // This can only be done after the CustomActor connection has been made...
66   impl->Initialize();
67
68   return handle;
69 }
70
71 void TextLabel::SetRenderer( Text::RendererPtr renderer )
72 {
73   mRenderer = renderer;
74 }
75
76 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
77 {
78   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
79
80   if( label )
81   {
82     TextLabel& labelImpl( GetImpl( label ) );
83     switch( index )
84     {
85       case Toolkit::TextLabel::PROPERTY_TEXT:
86       {
87         labelImpl.SetText( value.Get< std::string >() );
88         break;
89       }
90     }
91   }
92 }
93
94 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
95 {
96   Property::Value value;
97
98   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
99
100   if( label )
101   {
102     switch( index )
103     {
104       case Toolkit::TextLabel::PROPERTY_TEXT:
105       {
106         DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" );
107         break;
108       }
109     }
110   }
111
112   return value;
113 }
114
115 void TextLabel::OnInitialize()
116 {
117   mController = Text::Controller::New();
118 }
119
120 void TextLabel::SetText( const std::string& text )
121 {
122   if( mController )
123   {
124     // The Controller updates the View for the renderer
125     mController->SetText( text );
126
127     if( mRenderer )
128     {
129       Actor renderableActor = mRenderer->Render( mController->GetView() );
130
131       if( renderableActor )
132       {
133         Self().Add( renderableActor );
134       }
135     }
136   }
137 }
138
139 TextLabel::TextLabel()
140 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) )
141 {
142 }
143
144 TextLabel::~TextLabel()
145 {
146 }
147
148 } // namespace Internal
149
150 } // namespace Toolkit
151
152 } // namespace Dali