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>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
27 #include <dali/devel-api/object/type-registry-helper.h>
28 #include <dali/integration-api/debug.h>
31 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/public-api/text/rendering-backend.h>
33 #include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
34 #include <dali-toolkit/internal/text/rendering/text-backend.h>
35 #include <dali-toolkit/internal/text/text-view.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 using namespace Dali::Toolkit::Text;
49 namespace // unnamed namespace
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
56 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
57 } // unnamed namespace
62 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
64 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
65 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
66 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
68 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
70 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
72 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
73 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
74 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
76 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
81 return Toolkit::TextField::New();
84 // Setup properties, signals and actions using the type-registry.
85 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", STRING, FONT_STYLE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
123 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
124 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
126 DALI_TYPE_REGISTRATION_END()
130 Toolkit::TextField TextField::New()
132 // Create the implementation, temporarily owned by this handle on stack
133 IntrusivePtr< TextField > impl = new TextField();
135 // Pass ownership to CustomActor handle
136 Toolkit::TextField handle( *impl );
138 // Second-phase init of the implementation
139 // This can only be done after the CustomActor connection has been made...
145 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
147 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
149 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
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() );
210 impl.mController->SetDefaultFontFamily( fontFamily );
214 case Toolkit::TextField::Property::FONT_STYLE:
216 SetFontStyleProperty( impl.mController, value );
219 case Toolkit::TextField::Property::POINT_SIZE:
221 if( impl.mController )
223 const float pointSize = value.Get< float >();
224 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
226 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
228 impl.mController->SetDefaultPointSize( pointSize );
233 case Toolkit::TextField::Property::MAX_LENGTH:
235 if( impl.mController )
237 const int max = value.Get< int >();
238 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
240 impl.mController->SetMaximumNumberOfCharacters( max );
244 case Toolkit::TextField::Property::EXCEED_POLICY:
249 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
251 if( impl.mController )
253 const std::string alignStr = value.Get< std::string >();
254 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
256 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
257 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
258 HORIZONTAL_ALIGNMENT_STRING_TABLE,
259 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
262 impl.mController->SetHorizontalAlignment( alignment );
267 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
269 if( impl.mController )
271 const std::string alignStr = value.Get< std::string >();
272 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
274 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
275 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
276 VERTICAL_ALIGNMENT_STRING_TABLE,
277 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
280 impl.mController->SetVerticalAlignment( alignment );
285 case Toolkit::TextField::Property::TEXT_COLOR:
287 if( impl.mController )
289 const Vector4 textColor = value.Get< Vector4 >();
290 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 );
292 if( impl.mController->GetTextColor() != textColor )
294 impl.mController->SetTextColor( textColor );
295 impl.mController->SetInputColor( textColor );
296 impl.mRenderer.Reset();
301 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
303 if( impl.mController )
305 const Vector4 textColor = value.Get< Vector4 >();
306 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 );
308 if( impl.mController->GetPlaceholderTextColor() != textColor )
310 impl.mController->SetPlaceholderTextColor( textColor );
311 impl.mRenderer.Reset();
316 case Toolkit::TextField::Property::SHADOW_OFFSET:
318 if( impl.mController )
320 const Vector2 shadowOffset = value.Get< Vector2 >();
321 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
323 if ( impl.mController->GetShadowOffset() != shadowOffset )
325 impl.mController->SetShadowOffset( shadowOffset );
326 impl.mRenderer.Reset();
331 case Toolkit::TextField::Property::SHADOW_COLOR:
333 if( impl.mController )
335 const Vector4 shadowColor = value.Get< Vector4 >();
336 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 );
338 if ( impl.mController->GetShadowColor() != shadowColor )
340 impl.mController->SetShadowColor( shadowColor );
341 impl.mRenderer.Reset();
346 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
348 if( impl.mDecorator )
350 const Vector4 color = value.Get< Vector4 >();
351 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 );
353 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
354 impl.RequestTextRelayout();
358 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
360 if( impl.mDecorator )
362 const Vector4 color = value.Get< Vector4 >();
363 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 );
365 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
366 impl.RequestTextRelayout();
370 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
372 if( impl.mController )
374 const bool enable = value.Get< bool >();
375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
377 impl.mController->SetEnableCursorBlink( enable );
378 impl.RequestTextRelayout();
382 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
384 if( impl.mDecorator )
386 const float interval = value.Get< float >();
387 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
389 impl.mDecorator->SetCursorBlinkInterval( interval );
393 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
395 if( impl.mDecorator )
397 const float duration = value.Get< float >();
398 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
400 impl.mDecorator->SetCursorBlinkDuration( duration );
404 case Toolkit::TextField::Property::CURSOR_WIDTH:
406 if( impl.mDecorator )
408 const int width = value.Get< int >();
409 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
411 impl.mDecorator->SetCursorWidth( width );
412 impl.mController->GetLayoutEngine().SetCursorWidth( width );
416 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
418 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
419 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
421 if( impl.mDecorator )
423 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
424 impl.RequestTextRelayout();
428 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
430 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
431 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
433 if( impl.mDecorator )
435 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
436 impl.RequestTextRelayout();
440 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
442 const float threshold = value.Get< float >();
443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
445 if( impl.mDecorator )
447 impl.mDecorator->SetScrollThreshold( threshold );
451 case Toolkit::TextField::Property::SCROLL_SPEED:
453 const float speed = value.Get< float >();
454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
456 if( impl.mDecorator )
458 impl.mDecorator->SetScrollSpeed( speed );
462 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
464 const Image image = Scripting::NewImage( value );
466 if( impl.mDecorator && image )
468 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
469 impl.RequestTextRelayout();
473 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
475 const Image image = Scripting::NewImage( value );
477 if( impl.mDecorator && image )
479 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
480 impl.RequestTextRelayout();
484 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
486 const Image image = Scripting::NewImage( value );
488 if( impl.mDecorator && image )
490 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
491 impl.RequestTextRelayout();
495 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
497 const Image image = Scripting::NewImage( value );
499 if( impl.mDecorator && image )
501 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
502 impl.RequestTextRelayout();
506 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
508 const Image image = Scripting::NewImage( value );
510 if( impl.mDecorator && image )
512 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
513 impl.RequestTextRelayout();
517 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
519 const Image image = Scripting::NewImage( value );
521 if( impl.mDecorator && image )
523 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
524 impl.RequestTextRelayout();
528 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
530 const Vector4 color = value.Get< Vector4 >();
531 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 );
533 if( impl.mDecorator )
535 impl.mDecorator->SetHighlightColor( color );
536 impl.RequestTextRelayout();
540 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
542 if( impl.mDecorator )
544 const Rect<int> box = value.Get< Rect<int> >();
545 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 );
547 impl.mDecorator->SetBoundingBox( box );
548 impl.RequestTextRelayout();
552 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
554 const Property::Map map = value.Get<Property::Map>();
555 VirtualKeyboard::ApplySettings( map );
558 case Toolkit::TextField::Property::INPUT_COLOR:
560 if( impl.mController )
562 const Vector4 inputColor = value.Get< Vector4 >();
563 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), inputColor.r, inputColor.g, inputColor.b, inputColor.a );
565 impl.mController->SetInputColor( inputColor );
573 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
575 Property::Value value;
577 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
581 TextField& impl( GetImpl( textField ) );
585 case Toolkit::TextField::Property::RENDERING_BACKEND:
587 value = impl.mRenderingBackend;
590 case Toolkit::TextField::Property::TEXT:
592 if( impl.mController )
595 impl.mController->GetText( text );
596 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
601 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
603 if( impl.mController )
606 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
611 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
613 if( impl.mController )
616 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
621 case Toolkit::TextField::Property::FONT_FAMILY:
623 if( impl.mController )
625 value = impl.mController->GetDefaultFontFamily();
629 case Toolkit::TextField::Property::FONT_STYLE:
631 GetFontStyleProperty( impl.mController, value );
634 case Toolkit::TextField::Property::POINT_SIZE:
636 if( impl.mController )
638 value = impl.mController->GetDefaultPointSize();
642 case Toolkit::TextField::Property::MAX_LENGTH:
644 if( impl.mController )
646 value = impl.mController->GetMaximumNumberOfCharacters();
650 case Toolkit::TextField::Property::EXCEED_POLICY:
652 value = impl.mExceedPolicy;
655 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
657 if( impl.mController )
659 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
660 HORIZONTAL_ALIGNMENT_STRING_TABLE,
661 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
664 value = std::string( name );
669 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
671 if( impl.mController )
673 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
674 VERTICAL_ALIGNMENT_STRING_TABLE,
675 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
678 value = std::string( name );
683 case Toolkit::TextField::Property::TEXT_COLOR:
685 if ( impl.mController )
687 value = impl.mController->GetTextColor();
691 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
693 if ( impl.mController )
695 value = impl.mController->GetPlaceholderTextColor();
699 case Toolkit::TextField::Property::INPUT_COLOR:
701 if( impl.mController )
703 value = impl.mController->GetInputColor();
707 case Toolkit::TextField::Property::SHADOW_OFFSET:
709 if ( impl.mController )
711 value = impl.mController->GetShadowOffset();
715 case Toolkit::TextField::Property::SHADOW_COLOR:
717 if ( impl.mController )
719 value = impl.mController->GetShadowColor();
723 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
725 if( impl.mDecorator )
727 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
731 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
733 if( impl.mDecorator )
735 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
739 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
741 value = impl.mController->GetEnableCursorBlink();
744 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
746 if( impl.mDecorator )
748 value = impl.mDecorator->GetCursorBlinkInterval();
752 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
754 if( impl.mDecorator )
756 value = impl.mDecorator->GetCursorBlinkDuration();
760 case Toolkit::TextField::Property::CURSOR_WIDTH:
762 if( impl.mDecorator )
764 value = impl.mDecorator->GetCursorWidth();
768 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
770 if( impl.mDecorator )
772 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
775 value = image.GetUrl();
780 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
782 if( impl.mDecorator )
784 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
787 value = image.GetUrl();
792 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
794 if( impl.mDecorator )
796 value = impl.mDecorator->GetScrollThreshold();
800 case Toolkit::TextField::Property::SCROLL_SPEED:
802 if( impl.mDecorator )
804 value = impl.mDecorator->GetScrollSpeed();
808 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
810 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
813 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
815 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
818 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
820 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
823 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
825 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
828 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
830 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
833 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
835 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
838 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
840 if( impl.mDecorator )
842 value = impl.mDecorator->GetHighlightColor();
846 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
848 if( impl.mDecorator )
850 Rect<int> boundingBox;
851 impl.mDecorator->GetBoundingBox( boundingBox );
856 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
866 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
868 Dali::BaseHandle handle( object );
870 bool connected( true );
871 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
873 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
875 field.TextChangedSignal().Connect( tracker, functor );
877 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
879 field.MaxLengthReachedSignal().Connect( tracker, functor );
883 // signalName does not match any signal
890 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
892 return mTextChangedSignal;
895 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
897 return mMaxLengthReachedSignal;
900 void TextField::OnInitialize()
904 mController = Text::Controller::New( *this );
906 mDecorator = Text::Decorator::New( *mController,
909 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
911 mController->EnableTextInput( mDecorator );
913 // Forward input events to controller
914 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
915 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
917 self.TouchedSignal().Connect( this, &TextField::OnTouched );
919 // Set BoundingBox to stage size if not already set.
920 Rect<int> boundingBox;
921 mDecorator->GetBoundingBox( boundingBox );
923 if( boundingBox.IsEmpty() )
925 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
926 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
929 // Flip vertically the 'left' selection handle
930 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
932 // Fill-parent area by default
933 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
934 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
935 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
938 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
940 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
944 case StyleChange::DEFAULT_FONT_CHANGE:
946 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
947 std::string newFont = styleManager.GetDefaultFontFamily();
948 // Property system did not set the font so should update it.
949 mController->UpdateAfterFontChange( newFont );
953 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
955 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
957 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
959 // Property system did not set the PointSize so should update it.
960 // todo instruct text-controller to update model
964 case StyleChange::THEME_CHANGE:
966 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
972 Vector3 TextField::GetNaturalSize()
974 return mController->GetNaturalSize();
977 float TextField::GetHeightForWidth( float width )
979 return mController->GetHeightForWidth( width );
982 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
984 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
986 if( mController->Relayout( size ) ||
989 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
993 mDecorator->Relayout( size );
998 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1001 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
1006 void TextField::RenderText()
1008 Actor self = Self();
1009 Actor renderableActor;
1012 renderableActor = mRenderer->Render( mController->GetView(), TEXT_DEPTH_INDEX );
1015 if( renderableActor != mRenderableActor )
1017 UnparentAndReset( mRenderableActor );
1018 mRenderableActor = renderableActor;
1021 if( mRenderableActor )
1023 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1025 mRenderableActor.SetPosition( offset.x, offset.y );
1027 Actor clipRootActor;
1030 clipRootActor = mClipper->GetRootActor();
1033 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1034 endIt = mClippingDecorationActors.end();
1042 clipRootActor.Add( actor );
1049 mClippingDecorationActors.clear();
1051 // Make sure the actor is parented correctly with/without clipping
1054 clipRootActor.Add( mRenderableActor );
1058 self.Add( mRenderableActor );
1063 void TextField::OnKeyInputFocusGained()
1065 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1067 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1069 ImfManager imfManager = ImfManager::Get();
1073 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1075 // Notify that the text editing start.
1076 imfManager.Activate();
1078 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1079 imfManager.SetRestoreAfterFocusLost( true );
1082 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1086 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1089 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1091 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1094 void TextField::OnKeyInputFocusLost()
1096 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1098 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1100 ImfManager imfManager = ImfManager::Get();
1103 // The text editing is finished. Therefore the imf manager don't have restore activation.
1104 imfManager.SetRestoreAfterFocusLost( false );
1106 // Notify that the text editing finish.
1107 imfManager.Deactivate();
1109 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1112 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1116 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1119 mController->KeyboardFocusLostEvent();
1121 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1124 void TextField::OnTap( const TapGesture& gesture )
1126 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1128 // Show the keyboard if it was hidden.
1129 if (!VirtualKeyboard::IsVisible())
1131 VirtualKeyboard::Show();
1134 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1135 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1140 void TextField::OnPan( const PanGesture& gesture )
1142 mController->PanEvent( gesture.state, gesture.displacement );
1145 void TextField::OnLongPress( const LongPressGesture& gesture )
1147 // Show the keyboard if it was hidden.
1148 if (!VirtualKeyboard::IsVisible())
1150 VirtualKeyboard::Show();
1153 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1158 bool TextField::OnKeyEvent( const KeyEvent& event )
1160 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1162 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1163 "Return" == event.keyPressedName ) // Make a Dali key code for this
1165 ClearKeyInputFocus();
1169 return mController->KeyEvent( event );
1172 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1178 mClippingDecorationActors.push_back( actor );
1182 Self().Add( actor );
1187 void TextField::RequestTextRelayout()
1192 void TextField::TextChanged()
1194 Dali::Toolkit::TextField handle( GetOwner() );
1195 mTextChangedSignal.Emit( handle );
1198 void TextField::OnStageConnect( Dali::Actor actor )
1200 if ( mHasBeenStaged )
1206 mHasBeenStaged = true;
1210 void TextField::MaxLengthReached()
1212 Dali::Toolkit::TextField handle( GetOwner() );
1213 mMaxLengthReachedSignal.Emit( handle );
1216 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1218 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1219 return mController->OnImfEvent( imfManager, imfEvent );
1222 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1226 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1231 Scripting::CreatePropertyMap( image, map );
1237 void TextField::EnableClipping( bool clipping, const Vector2& size )
1241 // Not worth to created clip actor if width or height is equal to zero.
1242 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1246 Actor self = Self();
1248 mClipper = Clipper::New( size );
1249 self.Add( mClipper->GetRootActor() );
1250 self.Add( mClipper->GetImageActor() );
1252 else if ( mClipper )
1254 mClipper->Refresh( size );
1260 // Note - this will automatically remove the root & image actors
1265 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1267 mController->PasteClipboardItemEvent();
1270 void TextField::KeyboardStatusChanged(bool keyboardShown)
1272 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1274 // Just hide the grab handle when keyboard is hidden.
1275 if (!keyboardShown )
1277 mController->KeyboardFocusLostEvent();
1281 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1285 void TextField::OnStageConnection( int depth )
1287 // Call the Control::OnStageConnection() to set the depth of the background.
1288 Control::OnStageConnection( depth );
1290 // Sets the depth to the renderers inside the text's decorator.
1291 mDecorator->SetTextDepth( depth );
1293 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1296 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1301 TextField::TextField()
1302 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1303 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1304 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1305 mHasBeenStaged( false )
1309 TextField::~TextField()
1314 } // namespace Internal
1316 } // namespace Toolkit