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/text/text-view.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 using namespace Dali::Toolkit::Text;
52 namespace // unnamed namespace
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
59 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
61 } // unnamed namespace
66 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
68 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
69 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
70 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
72 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
74 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
76 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
77 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
78 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
80 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
85 return Toolkit::TextField::New();
88 // Setup properties, signals and actions using the type-registry.
89 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend", INTEGER, RENDERING_BACKEND )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text", STRING, PLACEHOLDER_TEXT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused", STRING, PLACEHOLDER_TEXT_FOCUSED )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family", STRING, FONT_FAMILY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style", STRING, FONT_STYLE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size", FLOAT, POINT_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length", INTEGER, MAX_LENGTH )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy", INTEGER, EXCEED_POLICY )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color", VECTOR4, TEXT_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color", VECTOR4, PLACEHOLDER_TEXT_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset", VECTOR2, SHADOW_OFFSET )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color", VECTOR4, SHADOW_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color", VECTOR4, PRIMARY_CURSOR_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color", VECTOR4, SECONDARY_CURSOR_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink", BOOLEAN, ENABLE_CURSOR_BLINK )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-width", INTEGER, CURSOR_WIDTH )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", STRING, GRAB_HANDLE_PRESSED_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold", FLOAT, SCROLL_THRESHOLD )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed", FLOAT, SCROLL_SPEED )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", MAP, SELECTION_HANDLE_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-left", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-right", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings", MAP, INPUT_METHOD_SETTINGS )
126 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "text-changed", SIGNAL_TEXT_CHANGED )
127 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
129 DALI_TYPE_REGISTRATION_END()
133 Toolkit::TextField TextField::New()
135 // Create the implementation, temporarily owned by this handle on stack
136 IntrusivePtr< TextField > impl = new TextField();
138 // Pass ownership to CustomActor handle
139 Toolkit::TextField handle( *impl );
141 // Second-phase init of the implementation
142 // This can only be done after the CustomActor connection has been made...
148 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
150 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
154 TextField& impl( GetImpl( textField ) );
158 case Toolkit::TextField::Property::RENDERING_BACKEND:
160 int backend = value.Get< int >();
161 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
163 if( impl.mRenderingBackend != backend )
165 impl.mRenderingBackend = backend;
166 impl.mRenderer.Reset();
167 impl.RequestTextRelayout();
171 case Toolkit::TextField::Property::TEXT:
173 if( impl.mController )
175 const std::string text = value.Get< std::string >();
176 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
178 impl.mController->SetText( text );
182 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
184 if( impl.mController )
186 const std::string text = value.Get< std::string >();
187 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
189 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
193 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
195 if( impl.mController )
197 const std::string text = value.Get< std::string >();
198 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
200 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
204 case Toolkit::TextField::Property::FONT_FAMILY:
206 if( impl.mController )
208 const std::string fontFamily = value.Get< std::string >();
209 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
211 if( impl.mController->GetDefaultFontFamily() != fontFamily )
213 impl.mController->SetDefaultFontFamily( fontFamily );
218 case Toolkit::TextField::Property::FONT_STYLE:
220 if( impl.mController )
222 const std::string fontStyle = value.Get< std::string >();
223 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %s\n", impl.mController.Get(), fontStyle.c_str() );
225 if( impl.mController->GetDefaultFontStyle() != fontStyle )
227 impl.mController->SetDefaultFontStyle( fontStyle );
232 case Toolkit::TextField::Property::POINT_SIZE:
234 if( impl.mController )
236 const float pointSize = value.Get< float >();
237 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
239 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
241 impl.mController->SetDefaultPointSize( pointSize );
246 case Toolkit::TextField::Property::MAX_LENGTH:
248 if( impl.mController )
250 const int max = value.Get< int >();
251 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
253 impl.mController->SetMaximumNumberOfCharacters( max );
257 case Toolkit::TextField::Property::EXCEED_POLICY:
262 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
264 if( impl.mController )
266 const std::string alignStr = value.Get< std::string >();
267 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
269 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
270 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
271 HORIZONTAL_ALIGNMENT_STRING_TABLE,
272 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
275 impl.mController->SetHorizontalAlignment( alignment );
280 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
282 if( impl.mController )
284 const std::string alignStr = value.Get< std::string >();
285 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
287 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
288 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
289 VERTICAL_ALIGNMENT_STRING_TABLE,
290 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
293 impl.mController->SetVerticalAlignment( alignment );
298 case Toolkit::TextField::Property::TEXT_COLOR:
300 if( impl.mController )
302 const Vector4 textColor = value.Get< Vector4 >();
303 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 );
305 if( impl.mController->GetTextColor() != textColor )
307 impl.mController->SetTextColor( textColor );
308 impl.mRenderer.Reset();
313 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
315 if( impl.mController )
317 const Vector4 textColor = value.Get< Vector4 >();
318 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 );
320 if( impl.mController->GetPlaceholderTextColor() != textColor )
322 impl.mController->SetPlaceholderTextColor( textColor );
323 impl.mRenderer.Reset();
328 case Toolkit::TextField::Property::SHADOW_OFFSET:
330 if( impl.mController )
332 const Vector2 shadowOffset = value.Get< Vector2 >();
333 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
335 if ( impl.mController->GetShadowOffset() != shadowOffset )
337 impl.mController->SetShadowOffset( shadowOffset );
338 impl.mRenderer.Reset();
343 case Toolkit::TextField::Property::SHADOW_COLOR:
345 if( impl.mController )
347 const Vector4 shadowColor = value.Get< Vector4 >();
348 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 );
350 if ( impl.mController->GetShadowColor() != shadowColor )
352 impl.mController->SetShadowColor( shadowColor );
353 impl.mRenderer.Reset();
358 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
360 if( impl.mDecorator )
362 const Vector4 color = value.Get< Vector4 >();
363 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
365 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
366 impl.RequestTextRelayout();
370 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
372 if( impl.mDecorator )
374 const Vector4 color = value.Get< Vector4 >();
375 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
377 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
378 impl.RequestTextRelayout();
382 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
384 if( impl.mController )
386 const bool enable = value.Get< bool >();
387 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
389 impl.mController->SetEnableCursorBlink( enable );
390 impl.RequestTextRelayout();
394 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
396 if( impl.mDecorator )
398 const float interval = value.Get< float >();
399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
401 impl.mDecorator->SetCursorBlinkInterval( interval );
405 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
407 if( impl.mDecorator )
409 const float duration = value.Get< float >();
410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
412 impl.mDecorator->SetCursorBlinkDuration( duration );
416 case Toolkit::TextField::Property::CURSOR_WIDTH:
418 if( impl.mDecorator )
420 const int width = value.Get< int >();
421 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
423 impl.mDecorator->SetCursorWidth( width );
424 impl.mController->GetLayoutEngine().SetCursorWidth( width );
428 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
430 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
431 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
433 if( impl.mDecorator )
435 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
436 impl.RequestTextRelayout();
440 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
442 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
445 if( impl.mDecorator )
447 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
448 impl.RequestTextRelayout();
452 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
454 const float threshold = value.Get< float >();
455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
457 if( impl.mDecorator )
459 impl.mDecorator->SetScrollThreshold( threshold );
463 case Toolkit::TextField::Property::SCROLL_SPEED:
465 const float speed = value.Get< float >();
466 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
468 if( impl.mDecorator )
470 impl.mDecorator->SetScrollSpeed( speed );
474 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
476 const Image image = Scripting::NewImage( value );
478 if( impl.mDecorator )
480 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
481 impl.RequestTextRelayout();
485 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
487 const Image image = Scripting::NewImage( value );
489 if( impl.mDecorator )
491 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
492 impl.RequestTextRelayout();
496 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
498 const Image image = Scripting::NewImage( value );
500 if( impl.mDecorator )
502 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
503 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
509 const Image image = Scripting::NewImage( value );
511 if( impl.mDecorator )
513 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
514 impl.RequestTextRelayout();
518 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
520 const Image image = Scripting::NewImage( value );
521 if( impl.mDecorator )
523 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
524 impl.RequestTextRelayout();
528 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
530 const Image image = Scripting::NewImage( value );
531 if( impl.mDecorator )
533 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
534 impl.RequestTextRelayout();
538 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
540 const Vector4 color = value.Get< Vector4 >();
541 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
543 if( impl.mDecorator )
545 impl.mDecorator->SetHighlightColor( color );
546 impl.RequestTextRelayout();
550 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
552 if( impl.mDecorator )
554 const Rect<int> box = value.Get< Rect<int> >();
555 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 );
557 impl.mDecorator->SetBoundingBox( box );
558 impl.RequestTextRelayout();
562 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
564 const Property::Map map = value.Get<Property::Map>();
565 VirtualKeyboard::ApplySettings( map );
572 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
574 Property::Value value;
576 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
580 TextField& impl( GetImpl( textField ) );
584 case Toolkit::TextField::Property::RENDERING_BACKEND:
586 value = impl.mRenderingBackend;
589 case Toolkit::TextField::Property::TEXT:
591 if( impl.mController )
594 impl.mController->GetText( text );
595 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
600 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
602 if( impl.mController )
605 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
610 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
612 if( impl.mController )
615 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
620 case Toolkit::TextField::Property::FONT_FAMILY:
622 if( impl.mController )
624 value = impl.mController->GetDefaultFontFamily();
628 case Toolkit::TextField::Property::FONT_STYLE:
630 if( impl.mController )
632 value = impl.mController->GetDefaultFontStyle();
636 case Toolkit::TextField::Property::POINT_SIZE:
638 if( impl.mController )
640 value = impl.mController->GetDefaultPointSize();
644 case Toolkit::TextField::Property::MAX_LENGTH:
646 if( impl.mController )
648 value = impl.mController->GetMaximumNumberOfCharacters();
652 case Toolkit::TextField::Property::EXCEED_POLICY:
654 value = impl.mExceedPolicy;
657 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
659 if( impl.mController )
661 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
662 HORIZONTAL_ALIGNMENT_STRING_TABLE,
663 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
666 value = std::string( name );
671 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
673 if( impl.mController )
675 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
676 VERTICAL_ALIGNMENT_STRING_TABLE,
677 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
680 value = std::string( name );
685 case Toolkit::TextField::Property::TEXT_COLOR:
687 if ( impl.mController )
689 value = impl.mController->GetTextColor();
693 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
695 if ( impl.mController )
697 value = impl.mController->GetPlaceholderTextColor();
701 case Toolkit::TextField::Property::SHADOW_OFFSET:
703 if ( impl.mController )
705 value = impl.mController->GetShadowOffset();
709 case Toolkit::TextField::Property::SHADOW_COLOR:
711 if ( impl.mController )
713 value = impl.mController->GetShadowColor();
717 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
719 if( impl.mDecorator )
721 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
725 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
727 if( impl.mDecorator )
729 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
733 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
735 value = impl.mController->GetEnableCursorBlink();
738 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
740 if( impl.mDecorator )
742 value = impl.mDecorator->GetCursorBlinkInterval();
746 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
748 if( impl.mDecorator )
750 value = impl.mDecorator->GetCursorBlinkDuration();
754 case Toolkit::TextField::Property::CURSOR_WIDTH:
756 if( impl.mDecorator )
758 value = impl.mDecorator->GetCursorWidth();
762 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
764 if( impl.mDecorator )
766 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
769 value = image.GetUrl();
774 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
776 if( impl.mDecorator )
778 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
781 value = image.GetUrl();
786 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
788 if( impl.mDecorator )
790 value = impl.mDecorator->GetScrollThreshold();
794 case Toolkit::TextField::Property::SCROLL_SPEED:
796 if( impl.mDecorator )
798 value = impl.mDecorator->GetScrollSpeed();
802 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
804 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
807 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
809 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
812 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
814 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
817 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
819 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
822 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
824 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
827 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
829 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
832 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
834 if( impl.mDecorator )
836 value = impl.mDecorator->GetHighlightColor();
840 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
842 if( impl.mDecorator )
844 value = impl.mDecorator->GetBoundingBox();
848 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
858 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
860 Dali::BaseHandle handle( object );
862 bool connected( true );
863 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
865 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
867 field.TextChangedSignal().Connect( tracker, functor );
869 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
871 field.MaxLengthReachedSignal().Connect( tracker, functor );
875 // signalName does not match any signal
882 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
884 return mTextChangedSignal;
887 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
889 return mMaxLengthReachedSignal;
892 void TextField::OnInitialize()
896 mController = Text::Controller::New( *this );
898 mDecorator = Text::Decorator::New( *mController,
901 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
903 mController->EnableTextInput( mDecorator );
905 // Forward input events to controller
906 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) );
907 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
909 self.TouchedSignal().Connect( this, &TextField::OnTouched );
911 // Set BoundingBox to stage size if not already set.
912 if ( mDecorator->GetBoundingBox().IsEmpty() )
914 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
915 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
918 // Fill-parent area by default
919 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
920 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
921 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
924 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
926 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
930 case StyleChange::DEFAULT_FONT_CHANGE:
932 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_CHANGE\n");
933 if ( mController->GetDefaultFontFamily() == "" )
935 // Property system did not set the font so should update it.
936 // todo instruct text-controller to update model
941 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
943 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
945 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
947 // Property system did not set the PointSize so should update it.
948 // todo instruct text-controller to update model
952 case StyleChange::THEME_CHANGE:
954 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
960 Vector3 TextField::GetNaturalSize()
962 return mController->GetNaturalSize();
965 float TextField::GetHeightForWidth( float width )
967 return mController->GetHeightForWidth( width );
970 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
972 if( mController->Relayout( size ) ||
975 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
979 mDecorator->Relayout( size );
984 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
987 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
992 void TextField::RenderText()
995 Actor renderableActor;
998 renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
1001 if( renderableActor != mRenderableActor )
1003 UnparentAndReset( mRenderableActor );
1004 mRenderableActor = renderableActor;
1007 if( mRenderableActor )
1009 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1011 mRenderableActor.SetPosition( offset.x, offset.y );
1013 Actor clipRootActor;
1016 clipRootActor = mClipper->GetRootActor();
1019 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1020 endIt = mClippingDecorationActors.end();
1028 clipRootActor.Add( actor );
1035 mClippingDecorationActors.clear();
1037 // Make sure the actor is parented correctly with/without clipping
1040 clipRootActor.Add( mRenderableActor );
1044 self.Add( mRenderableActor );
1049 void TextField::OnKeyInputFocusGained()
1051 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1053 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1055 ImfManager imfManager = ImfManager::Get();
1059 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1061 // Notify that the text editing start.
1062 imfManager.Activate();
1064 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1065 imfManager.SetRestoreAfterFocusLost( true );
1068 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1072 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1075 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1077 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1080 void TextField::OnKeyInputFocusLost()
1082 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1084 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1086 ImfManager imfManager = ImfManager::Get();
1089 // The text editing is finished. Therefore the imf manager don't have restore activation.
1090 imfManager.SetRestoreAfterFocusLost( false );
1092 // Notify that the text editing finish.
1093 imfManager.Deactivate();
1095 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1098 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1102 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1105 mController->KeyboardFocusLostEvent();
1107 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1110 void TextField::OnTap( const TapGesture& gesture )
1112 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1114 // Show the keyboard if it was hidden.
1115 if (!VirtualKeyboard::IsVisible())
1117 VirtualKeyboard::Show();
1120 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1121 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1126 void TextField::OnPan( const PanGesture& gesture )
1128 mController->PanEvent( gesture.state, gesture.displacement );
1131 void TextField::OnLongPress( const LongPressGesture& gesture )
1133 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1136 bool TextField::OnKeyEvent( const KeyEvent& event )
1138 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1140 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1141 "Return" == event.keyPressedName ) // Make a Dali key code for this
1143 ClearKeyInputFocus();
1147 return mController->KeyEvent( event );
1150 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1156 mClippingDecorationActors.push_back( actor );
1160 Self().Add( actor );
1165 void TextField::RequestTextRelayout()
1170 void TextField::TextChanged()
1172 Dali::Toolkit::TextField handle( GetOwner() );
1173 mTextChangedSignal.Emit( handle );
1176 void TextField::OnStageConnect( Dali::Actor actor )
1178 if ( mHasBeenStaged )
1184 mHasBeenStaged = true;
1188 void TextField::MaxLengthReached()
1190 Dali::Toolkit::TextField handle( GetOwner() );
1191 mMaxLengthReachedSignal.Emit( handle );
1194 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1196 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1197 return mController->OnImfEvent( imfManager, imfEvent );
1200 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1204 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1209 Scripting::CreatePropertyMap( image, map );
1215 void TextField::EnableClipping( bool clipping, const Vector2& size )
1219 // Not worth to created clip actor if width or height is equal to zero.
1220 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1224 Actor self = Self();
1226 mClipper = Clipper::New( size );
1227 self.Add( mClipper->GetRootActor() );
1228 self.Add( mClipper->GetImageActor() );
1230 else if ( mClipper )
1232 mClipper->Refresh( size );
1238 // Note - this will automatically remove the root & image actors
1243 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1245 mController->PasteClipboardItemEvent();
1248 void TextField::KeyboardStatusChanged(bool keyboardShown)
1250 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1252 // Just hide the grab handle when keyboard is hidden.
1253 if (!keyboardShown )
1255 mController->KeyboardFocusLostEvent();
1259 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1263 void TextField::OnStageConnection( int depth )
1265 // Call the Control::OnStageConnection() to set the depth of the background.
1266 Control::OnStageConnection( depth );
1268 // Sets the depth to the renderers inside the text's decorator.
1269 mDecorator->SetTextDepth( depth );
1271 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1274 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1279 TextField::TextField()
1280 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1281 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1282 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1283 mHasBeenStaged( false )
1287 TextField::~TextField()
1292 } // namespace Internal
1294 } // namespace Toolkit