2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
22 #include <dali/public-api/images/image.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali-toolkit/public-api/text/layouts/layout-engine.h>
28 #include <dali-toolkit/public-api/text/rendering/basic/text-basic-renderer.h> // TODO - Get from RendererFactory
30 using namespace Dali::Toolkit::Text;
43 const Property::Index TextField::PROPERTY_PLACEHOLDER_TEXT( Internal::TextField::TEXTFIELD_PROPERTY_START_INDEX );
44 const Property::Index TextField::PROPERTY_TEXT( Internal::TextField::TEXTFIELD_PROPERTY_START_INDEX + 1 );
45 const Property::Index TextField::PROPERTY_CURSOR_IMAGE( Internal::TextField::TEXTFIELD_PROPERTY_START_INDEX + 2 );
46 const Property::Index TextField::PROPERTY_PRIMARY_CURSOR_COLOR( Internal::TextField::TEXTFIELD_PROPERTY_START_INDEX + 3 );
47 const Property::Index TextField::PROPERTY_SECONDARY_CURSOR_COLOR( Internal::TextField::TEXTFIELD_PROPERTY_START_INDEX + 4 );
48 const Property::Index TextField::PROPERTY_ENABLE_CURSOR_BLINK( Internal::TextField::TEXTFIELD_PROPERTY_START_INDEX + 5 );
49 const Property::Index TextField::PROPERTY_CURSOR_BLINK_INTERVAL( Internal::TextField::TEXTFIELD_PROPERTY_START_INDEX + 6 );
50 const Property::Index TextField::PROPERTY_CURSOR_BLINK_DURATION( Internal::TextField::TEXTFIELD_PROPERTY_START_INDEX + 7 );
61 return Toolkit::TextField::New();
64 TypeRegistration mType( typeid(Toolkit::TextField), typeid(Toolkit::Control), Create );
66 PropertyRegistration property1( mType, "placeholder-text", Toolkit::TextField::PROPERTY_PLACEHOLDER_TEXT, Property::STRING, &TextField::SetProperty, &TextField::GetProperty );
67 PropertyRegistration property2( mType, "text", Toolkit::TextField::PROPERTY_TEXT, Property::STRING, &TextField::SetProperty, &TextField::GetProperty );
68 PropertyRegistration property3( mType, "cursor-image", Toolkit::TextField::PROPERTY_CURSOR_IMAGE, Property::STRING, &TextField::SetProperty, &TextField::GetProperty );
69 PropertyRegistration property4( mType, "primary-cursor-color", Toolkit::TextField::PROPERTY_PRIMARY_CURSOR_COLOR, Property::VECTOR4, &TextField::SetProperty, &TextField::GetProperty );
70 PropertyRegistration property5( mType, "secondary-cursor-color", Toolkit::TextField::PROPERTY_SECONDARY_CURSOR_COLOR, Property::VECTOR4, &TextField::SetProperty, &TextField::GetProperty );
71 PropertyRegistration property6( mType, "enable-cursor-blink", Toolkit::TextField::PROPERTY_ENABLE_CURSOR_BLINK, Property::BOOLEAN, &TextField::SetProperty, &TextField::GetProperty );
72 PropertyRegistration property7( mType, "cursor-blink-interval", Toolkit::TextField::PROPERTY_CURSOR_BLINK_INTERVAL, Property::FLOAT, &TextField::SetProperty, &TextField::GetProperty );
73 PropertyRegistration property8( mType, "cursor-blink-duration", Toolkit::TextField::PROPERTY_CURSOR_BLINK_DURATION, Property::FLOAT, &TextField::SetProperty, &TextField::GetProperty );
77 Toolkit::TextField TextField::New()
79 // Create the implementation, temporarily owned by this handle on stack
80 IntrusivePtr< TextField > impl = new TextField();
82 // Pass ownership to CustomActor handle
83 Toolkit::TextField handle( *impl );
85 // Second-phase init of the implementation
86 // This can only be done after the CustomActor connection has been made...
92 void TextField::SetRenderer( Text::RendererPtr renderer )
97 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
99 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
103 TextField& impl( GetImpl( textField ) );
107 case Toolkit::TextField::PROPERTY_PLACEHOLDER_TEXT:
109 if( impl.mController )
111 //impl.mController->SetPlaceholderText( value.Get< std::string >() ); TODO
115 case Toolkit::TextField::PROPERTY_TEXT:
117 if( impl.mController )
119 impl.mController->SetText( value.Get< std::string >() );
123 case Toolkit::TextField::PROPERTY_CURSOR_IMAGE:
125 Image image = Image::New( value.Get< std::string >() );
126 //ResourceImage image = ResourceImage::New( value.Get< std::string >() );
128 if( impl.mDecorator )
130 impl.mDecorator->SetCursorImage( image );
134 case Toolkit::TextField::PROPERTY_PRIMARY_CURSOR_COLOR:
136 if( impl.mDecorator )
138 impl.mDecorator->SetColor( PRIMARY_CURSOR, value.Get< Vector4 >() );
142 case Toolkit::TextField::PROPERTY_SECONDARY_CURSOR_COLOR:
144 if( impl.mDecorator )
146 impl.mDecorator->SetColor( SECONDARY_CURSOR, value.Get< Vector4 >() );
150 case Toolkit::TextField::PROPERTY_ENABLE_CURSOR_BLINK:
152 if( impl.mController )
154 //impl.mController->SetEnableCursorBlink( value.Get< bool >() ); TODO
158 case Toolkit::TextField::PROPERTY_CURSOR_BLINK_INTERVAL:
160 if( impl.mDecorator )
162 impl.mDecorator->SetCursorBlinkInterval( value.Get< float >() );
166 case Toolkit::TextField::PROPERTY_CURSOR_BLINK_DURATION:
168 if( impl.mDecorator )
170 impl.mDecorator->SetCursorBlinkDuration( value.Get< float >() );
178 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
180 Property::Value value;
182 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
186 TextField& impl( GetImpl( textField ) );
190 case Toolkit::TextField::PROPERTY_PLACEHOLDER_TEXT:
192 DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" );
195 case Toolkit::TextField::PROPERTY_TEXT:
197 DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" );
200 case Toolkit::TextField::PROPERTY_CURSOR_IMAGE:
202 if( impl.mDecorator )
204 Image image = impl.mDecorator->GetCursorImage();
205 //ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetCursorImage() );
208 value = image.GetFilename();
209 //value = image.GetUrl();
214 case Toolkit::TextField::PROPERTY_PRIMARY_CURSOR_COLOR:
216 if( impl.mDecorator )
218 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
222 case Toolkit::TextField::PROPERTY_SECONDARY_CURSOR_COLOR:
224 if( impl.mDecorator )
226 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
230 case Toolkit::TextField::PROPERTY_ENABLE_CURSOR_BLINK:
232 //value = impl.mController->GetEnableCursorBlink(); TODO
235 case Toolkit::TextField::PROPERTY_CURSOR_BLINK_INTERVAL:
237 if( impl.mDecorator )
239 value = impl.mDecorator->GetCursorBlinkInterval();
243 case Toolkit::TextField::PROPERTY_CURSOR_BLINK_DURATION:
245 if( impl.mDecorator )
247 value = impl.mDecorator->GetCursorBlinkDuration();
257 void TextField::OnInitialize()
259 mDecorator = Text::Decorator::New( *this );
261 mController = Text::Controller::New();
262 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
263 //mController->EnableTextInput( mDecorator ); TODO
266 void TextField::OnRelayout( const Vector2& size, ActorSizeContainer& container )
268 if( mController->Relayout( size ) )
272 // TODO - Get from RendererFactory
273 mRenderer = Dali::Toolkit::Text::BasicRenderer::New();
278 Actor renderableActor = mRenderer->Render( mController->GetView() );
280 if( renderableActor )
282 Self().Add( renderableActor );
288 TextField::TextField()
289 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) )
293 TextField::~TextField()
297 } // namespace Internal
299 } // namespace Toolkit