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>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/public-api/common/stage.h>
27 #include <dali/public-api/images/resource-image.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
30 #include <dali/devel-api/scripting/scripting.h>
31 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/public-api/text/rendering-backend.h>
36 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
37 #include <dali-toolkit/internal/text/rendering/text-backend.h>
38 #include <dali-toolkit/internal/styling/style-manager-impl.h>
40 using namespace Dali::Toolkit::Text;
51 namespace // unnamed namespace
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
58 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
60 } // unnamed namespace
65 const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
67 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
68 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
69 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
71 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
73 const Scripting::StringEnum< Toolkit::Text::LayoutEngine::VerticalAlignment > VERTICAL_ALIGNMENT_STRING_TABLE[] =
75 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
76 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
77 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
79 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
84 return Toolkit::TextField::New();
87 // Setup properties, signals and actions using the type-registry.
88 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend", INTEGER, RENDERING_BACKEND )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text", STRING, PLACEHOLDER_TEXT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused", STRING, PLACEHOLDER_TEXT_FOCUSED )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family", STRING, FONT_FAMILY )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style", STRING, FONT_STYLE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size", FLOAT, POINT_SIZE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length", INTEGER, MAX_LENGTH )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy", INTEGER, EXCEED_POLICY )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color", VECTOR4, TEXT_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color", VECTOR4, PLACEHOLDER_TEXT_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset", VECTOR2, SHADOW_OFFSET )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color", VECTOR4, SHADOW_COLOR )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color", VECTOR4, PRIMARY_CURSOR_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color", VECTOR4, SECONDARY_CURSOR_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink", BOOLEAN, ENABLE_CURSOR_BLINK )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", VECTOR4, GRAB_HANDLE_PRESSED_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold", FLOAT, SCROLL_THRESHOLD )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed", FLOAT, SCROLL_SPEED )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", STRING, SELECTION_HANDLE_IMAGE_LEFT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right", STRING, SELECTION_HANDLE_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left", STRING, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", STRING, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", STRING, SELECTION_HIGHLIGHT_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings", MAP, INPUT_METHOD_SETTINGS )
122 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "text-changed", SIGNAL_TEXT_CHANGED )
123 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
125 DALI_TYPE_REGISTRATION_END()
129 Toolkit::TextField TextField::New()
131 // Create the implementation, temporarily owned by this handle on stack
132 IntrusivePtr< TextField > impl = new TextField();
134 // Pass ownership to CustomActor handle
135 Toolkit::TextField handle( *impl );
137 // Second-phase init of the implementation
138 // This can only be done after the CustomActor connection has been made...
144 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
146 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
150 TextField& impl( GetImpl( textField ) );
154 case Toolkit::TextField::Property::RENDERING_BACKEND:
156 int backend = value.Get< int >();
157 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
159 if( impl.mRenderingBackend != backend )
161 impl.mRenderingBackend = backend;
162 impl.mRenderer.Reset();
163 impl.RequestTextRelayout();
167 case Toolkit::TextField::Property::TEXT:
169 if( impl.mController )
171 const std::string text = value.Get< std::string >();
172 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
174 impl.mController->SetText( text );
178 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
180 if( impl.mController )
182 const std::string text = value.Get< std::string >();
183 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
185 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
189 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
191 if( impl.mController )
193 const std::string text = value.Get< std::string >();
194 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
196 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
200 case Toolkit::TextField::Property::FONT_FAMILY:
202 if( impl.mController )
204 const std::string fontFamily = value.Get< std::string >();
205 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
207 if( impl.mController->GetDefaultFontFamily() != fontFamily )
209 impl.mController->SetDefaultFontFamily( fontFamily );
214 case Toolkit::TextField::Property::FONT_STYLE:
216 if( impl.mController )
218 const std::string fontStyle = value.Get< std::string >();
219 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %s\n", impl.mController.Get(), fontStyle.c_str() );
221 if( impl.mController->GetDefaultFontStyle() != fontStyle )
223 impl.mController->SetDefaultFontStyle( fontStyle );
228 case Toolkit::TextField::Property::POINT_SIZE:
230 if( impl.mController )
232 const float pointSize = value.Get< float >();
233 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %f\n", impl.mController.Get(), pointSize );
235 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
237 impl.mController->SetDefaultPointSize( pointSize );
242 case Toolkit::TextField::Property::EXCEED_POLICY:
247 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
249 if( impl.mController )
251 const std::string alignStr = value.Get< std::string >();
252 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() );
254 const LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
255 HORIZONTAL_ALIGNMENT_STRING_TABLE,
256 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
258 impl.mController->SetHorizontalAlignment( alignment );
262 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
264 if( impl.mController )
266 const std::string alignStr = value.Get< std::string >();
267 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() );
269 LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
270 VERTICAL_ALIGNMENT_STRING_TABLE,
271 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
273 impl.mController->SetVerticalAlignment( alignment );
277 case Toolkit::TextField::Property::TEXT_COLOR:
279 if( impl.mController )
281 const Vector4 textColor = value.Get< Vector4 >();
282 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
284 if( impl.mController->GetTextColor() != textColor )
286 impl.mController->SetTextColor( textColor );
287 impl.mRenderer.Reset();
292 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
294 if( impl.mController )
296 const Vector4 textColor = value.Get< Vector4 >();
297 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
299 if( impl.mController->GetPlaceholderTextColor() != textColor )
301 impl.mController->SetPlaceholderTextColor( textColor );
302 impl.mRenderer.Reset();
307 case Toolkit::TextField::Property::SHADOW_OFFSET:
309 if( impl.mController )
311 const Vector2 shadowOffset = value.Get< Vector2 >();
312 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
314 if ( impl.mController->GetShadowOffset() != shadowOffset )
316 impl.mController->SetShadowOffset( shadowOffset );
317 impl.mRenderer.Reset();
322 case Toolkit::TextField::Property::SHADOW_COLOR:
324 if( impl.mController )
326 const Vector4 shadowColor = value.Get< Vector4 >();
327 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_COLOR %f,%f,%f,%f\n", impl.mController.Get(), shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a );
329 if ( impl.mController->GetShadowColor() != shadowColor )
331 impl.mController->SetShadowColor( shadowColor );
332 impl.mRenderer.Reset();
337 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
339 if( impl.mDecorator )
341 const Vector4 color = value.Get< Vector4 >();
342 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
344 impl.mDecorator->SetColor( PRIMARY_CURSOR, color );
345 impl.RequestTextRelayout();
349 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
351 if( impl.mDecorator )
353 const Vector4 color = value.Get< Vector4 >();
354 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
356 impl.mDecorator->SetColor( SECONDARY_CURSOR, color );
357 impl.RequestTextRelayout();
361 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
363 if( impl.mController )
365 const bool enable = value.Get< bool >();
366 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
368 impl.mController->SetEnableCursorBlink( enable );
369 impl.RequestTextRelayout();
373 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
375 if( impl.mDecorator )
377 const float interval = value.Get< float >();
378 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
380 impl.mDecorator->SetCursorBlinkInterval( interval );
384 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
386 if( impl.mDecorator )
388 const float duration = value.Get< float >();
389 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), duration );
391 impl.mDecorator->SetCursorBlinkDuration( duration );
395 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
397 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
398 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
400 if( impl.mDecorator )
402 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
403 impl.RequestTextRelayout();
407 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
409 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
412 if( impl.mDecorator )
414 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
415 impl.RequestTextRelayout();
419 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
421 const float threshold = value.Get< float >();
422 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
424 if( impl.mDecorator )
426 impl.mDecorator->SetScrollThreshold( threshold );
430 case Toolkit::TextField::Property::SCROLL_SPEED:
432 const float speed = value.Get< float >();
433 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
435 if( impl.mDecorator )
437 impl.mDecorator->SetScrollSpeed( speed );
441 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
443 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_LEFT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
446 if( impl.mDecorator )
448 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
449 impl.RequestTextRelayout();
453 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
455 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
456 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_RIGHT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
458 if( impl.mDecorator )
460 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
461 impl.RequestTextRelayout();
465 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
467 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
468 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_LEFT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
470 if( impl.mDecorator )
472 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
473 impl.RequestTextRelayout();
477 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
479 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
480 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_RIGHT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
482 if( impl.mDecorator )
484 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
485 impl.RequestTextRelayout();
489 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
491 const Vector4 color = value.Get< Vector4 >();
492 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
494 if( impl.mDecorator )
496 impl.mDecorator->SetHighlightColor( color );
497 impl.RequestTextRelayout();
501 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
503 if( impl.mDecorator )
505 const Rect<int> box = value.Get< Rect<int> >();
506 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p DECORATION_BOUNDING_BOX %d,%d %dx%d\n", impl.mController.Get(), box.x, box.y, box.width, box.height );
508 impl.mDecorator->SetBoundingBox( box );
509 impl.RequestTextRelayout();
513 case Toolkit::TextField::Property::MAX_LENGTH:
515 if( impl.mController )
517 const int max = value.Get< int >();
518 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
520 impl.mController->SetMaximumNumberOfCharacters( max );
524 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
526 const Property::Map map = value.Get<Property::Map>();
527 VirtualKeyboard::ApplySettings( map );
534 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
536 Property::Value value;
538 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
542 TextField& impl( GetImpl( textField ) );
546 case Toolkit::TextField::Property::RENDERING_BACKEND:
548 value = impl.mRenderingBackend;
551 case Toolkit::TextField::Property::TEXT:
553 if( impl.mController )
556 impl.mController->GetText( text );
557 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
562 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
564 if( impl.mController )
567 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
572 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
574 if( impl.mController )
577 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
582 case Toolkit::TextField::Property::FONT_FAMILY:
584 if( impl.mController )
586 value = impl.mController->GetDefaultFontFamily();
590 case Toolkit::TextField::Property::FONT_STYLE:
592 if( impl.mController )
594 value = impl.mController->GetDefaultFontStyle();
598 case Toolkit::TextField::Property::POINT_SIZE:
600 if( impl.mController )
602 value = impl.mController->GetDefaultPointSize();
606 case Toolkit::TextField::Property::EXCEED_POLICY:
608 value = impl.mExceedPolicy;
611 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
613 if( impl.mController )
615 value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
616 HORIZONTAL_ALIGNMENT_STRING_TABLE,
617 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
621 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
623 if( impl.mController )
625 value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
626 VERTICAL_ALIGNMENT_STRING_TABLE,
627 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
631 case Toolkit::TextField::Property::TEXT_COLOR:
633 if ( impl.mController )
635 value = impl.mController->GetTextColor();
639 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
641 if ( impl.mController )
643 value = impl.mController->GetPlaceholderTextColor();
647 case Toolkit::TextField::Property::SHADOW_OFFSET:
649 if ( impl.mController )
651 value = impl.mController->GetShadowOffset();
655 case Toolkit::TextField::Property::SHADOW_COLOR:
657 if ( impl.mController )
659 value = impl.mController->GetShadowColor();
663 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
665 if( impl.mDecorator )
667 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
671 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
673 if( impl.mDecorator )
675 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
679 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
681 value = impl.mController->GetEnableCursorBlink();
684 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
686 if( impl.mDecorator )
688 value = impl.mDecorator->GetCursorBlinkInterval();
692 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
694 if( impl.mDecorator )
696 value = impl.mDecorator->GetCursorBlinkDuration();
700 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
702 if( impl.mDecorator )
704 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
707 value = image.GetUrl();
712 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
714 if( impl.mDecorator )
716 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
719 value = image.GetUrl();
724 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
726 if( impl.mDecorator )
728 value = impl.mDecorator->GetScrollThreshold();
732 case Toolkit::TextField::Property::SCROLL_SPEED:
734 if( impl.mDecorator )
736 value = impl.mDecorator->GetScrollSpeed();
740 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
742 if( impl.mDecorator )
744 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
747 value = image.GetUrl();
752 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
754 if( impl.mDecorator )
756 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
759 value = image.GetUrl();
764 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
766 if( impl.mDecorator )
768 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
771 value = image.GetUrl();
776 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
778 if( impl.mDecorator )
780 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
783 value = image.GetUrl();
788 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
790 if( impl.mDecorator )
792 value = impl.mDecorator->GetHighlightColor();
796 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
798 if( impl.mDecorator )
800 value = impl.mDecorator->GetBoundingBox();
804 case Toolkit::TextField::Property::MAX_LENGTH:
806 if( impl.mController )
808 value = impl.mController->GetMaximumNumberOfCharacters();
812 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
822 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
824 Dali::BaseHandle handle( object );
826 bool connected( true );
827 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
829 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
831 field.TextChangedSignal().Connect( tracker, functor );
833 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
835 field.MaxLengthReachedSignal().Connect( tracker, functor );
839 // signalName does not match any signal
846 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
848 return mTextChangedSignal;
851 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
853 return mMaxLengthReachedSignal;
856 void TextField::OnInitialize()
860 mController = Text::Controller::New( *this );
862 mDecorator = Text::Decorator::New( *this, *mController );
864 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
866 mController->EnableTextInput( mDecorator );
868 // Forward input events to controller
869 EnableGestureDetection(Gesture::Tap);
870 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
871 EnableGestureDetection(Gesture::Pan);
873 self.TouchedSignal().Connect( this, &TextField::OnTouched );
875 // Set BoundingBox to stage size if not already set.
876 if ( mDecorator->GetBoundingBox().IsEmpty() )
878 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
879 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
882 // Fill-parent area by default
883 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
884 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
887 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
889 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
892 Vector3 TextField::GetNaturalSize()
894 return mController->GetNaturalSize();
897 float TextField::GetHeightForWidth( float width )
899 return mController->GetHeightForWidth( width );
902 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
904 if( mController->Relayout( size ) ||
907 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
911 mDecorator->Relayout( size );
916 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
919 Actor renderableActor;
922 renderableActor = mRenderer->Render( mController->GetView(), mDepth );
925 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
927 if( renderableActor != mRenderableActor )
929 UnparentAndReset( mRenderableActor );
930 mRenderableActor = renderableActor;
933 if( mRenderableActor )
935 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
937 mRenderableActor.SetPosition( offset.x, offset.y );
939 // Make sure the actor is parented correctly with/without clipping
942 mClipper->GetRootActor().Add( mRenderableActor );
946 Self().Add( mRenderableActor );
952 void TextField::OnKeyInputFocusGained()
954 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
956 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
958 ImfManager imfManager = ImfManager::Get();
962 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
964 // Notify that the text editing start.
965 imfManager.Activate();
967 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
968 imfManager.SetRestoreAfterFocusLost( true );
971 mController->KeyboardFocusGainEvent();
973 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
976 void TextField::OnKeyInputFocusLost()
978 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
980 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
982 ImfManager imfManager = ImfManager::Get();
985 // The text editing is finished. Therefore the imf manager don't have restore activation.
986 imfManager.SetRestoreAfterFocusLost( false );
988 // Notify that the text editing finish.
989 imfManager.Deactivate();
991 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
994 mController->KeyboardFocusLostEvent();
996 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
999 void TextField::OnTap( const TapGesture& gesture )
1001 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1003 // Show the keyboard if it was hidden.
1004 if (!VirtualKeyboard::IsVisible())
1006 VirtualKeyboard::Show();
1009 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1010 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1015 void TextField::OnPan( const PanGesture& gesture )
1017 mController->PanEvent( gesture.state, gesture.displacement );
1020 bool TextField::OnKeyEvent( const KeyEvent& event )
1022 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1024 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1025 "Return" == event.keyPressedName ) // Make a Dali key code for this
1027 ClearKeyInputFocus();
1031 return mController->KeyEvent( event );
1034 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1036 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1037 return mController->OnImfEvent( imfManager, imfEvent );
1040 void TextField::RequestTextRelayout()
1045 void TextField::TextChanged()
1047 Dali::Toolkit::TextField handle( GetOwner() );
1048 mTextChangedSignal.Emit( handle );
1051 void TextField::MaxLengthReached()
1053 Dali::Toolkit::TextField handle( GetOwner() );
1054 mMaxLengthReachedSignal.Emit( handle );
1057 void TextField::EnableClipping( bool clipping, const Vector2& size )
1061 // Not worth to created clip actor if width or height is equal to zero.
1062 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1066 Actor self = Self();
1068 mClipper = Clipper::New( size );
1069 self.Add( mClipper->GetRootActor() );
1070 self.Add( mClipper->GetImageActor() );
1072 else if ( mClipper )
1074 mClipper->Refresh( size );
1080 // Note - this will automatically remove the root & image actors
1085 void TextField::KeyboardStatusChanged(bool keyboardShown)
1087 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1089 // Just hide the grab handle when keyboard is hidden.
1090 if (!keyboardShown )
1092 mController->KeyboardFocusLostEvent();
1096 void TextField::OnStageConnection( unsigned int depth )
1101 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1106 TextField::TextField()
1107 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1108 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1109 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1114 TextField::~TextField()
1119 } // namespace Internal
1121 } // namespace Toolkit