Text Renderer base class & TextLabel skeleton
[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 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23
24 namespace
25 {
26
27 } // namespace
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 const Property::Index TextLabel::PROPERTY_TEXT( Internal::TextLabel::TEXTLABEL_PROPERTY_START_INDEX );
36
37 namespace Internal
38 {
39
40 namespace
41 {
42
43 // Type registration
44 BaseHandle Create()
45 {
46   return Toolkit::TextLabel::New();
47 }
48
49 TypeRegistration mType( typeid(Toolkit::TextLabel), typeid(Toolkit::Control), Create );
50
51 PropertyRegistration property1( mType, "text", Toolkit::TextLabel::PROPERTY_TEXT, Property::STRING, &TextLabel::SetProperty, &TextLabel::GetProperty );
52
53 } // namespace
54
55 Toolkit::TextLabel TextLabel::New()
56 {
57   // Create the implementation, temporarily owned by this handle on stack
58   IntrusivePtr< TextLabel > impl = new TextLabel();
59
60   // Pass ownership to CustomActor handle
61   Toolkit::TextLabel handle( *impl );
62
63   // Second-phase init of the implementation
64   // This can only be done after the CustomActor connection has been made...
65   impl->Initialize();
66
67   return handle;
68 }
69
70 void TextLabel::SetRenderer( Text::RendererPtr renderer )
71 {
72   mRenderer = renderer;
73 }
74
75 void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
76 {
77   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
78
79   if( label )
80   {
81     TextLabel& labelImpl( GetImpl( label ) );
82     switch( index )
83     {
84       case Toolkit::TextLabel::PROPERTY_TEXT:
85       {
86         labelImpl.mText = value.Get< std::string >();
87
88         // TODO - Update Model etc.
89         break;
90       }
91     }
92   }
93 }
94
95 Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index index )
96 {
97   Property::Value value;
98
99   Toolkit::TextLabel label = Toolkit::TextLabel::DownCast( Dali::BaseHandle( object ) );
100
101   if( label )
102   {
103     TextLabel& labelImpl( GetImpl( label ) );
104     switch( index )
105     {
106       case Toolkit::TextLabel::PROPERTY_TEXT:
107       {
108         value = labelImpl.mText;
109         break;
110       }
111     }
112   }
113
114   return value;
115 }
116
117 void TextLabel::OnInitialize()
118 {
119 }
120
121 TextLabel::TextLabel()
122 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) )
123 {
124 }
125
126 TextLabel::~TextLabel()
127 {
128 }
129
130 } // namespace Internal
131
132 } // namespace Toolkit
133
134 } // namespace Dali