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/text/rendering-backend.h>
32 #include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
33 #include <dali-toolkit/internal/text/rendering/text-backend.h>
34 #include <dali-toolkit/internal/text/text-view.h>
35 #include <dali-toolkit/internal/styling/style-manager-impl.h>
37 using namespace Dali::Toolkit::Text;
48 namespace // unnamed namespace
51 #if defined(DEBUG_ENABLED)
52 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
55 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
56 } // unnamed namespace
61 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
63 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
64 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
65 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
67 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
69 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
71 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
72 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
73 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
75 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
80 return Toolkit::TextField::New();
83 // Setup properties, signals and actions using the type-registry.
84 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend", INTEGER, RENDERING_BACKEND )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text", STRING, PLACEHOLDER_TEXT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused", STRING, PLACEHOLDER_TEXT_FOCUSED )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family", STRING, FONT_FAMILY )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style", STRING, FONT_STYLE )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size", FLOAT, POINT_SIZE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length", INTEGER, MAX_LENGTH )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy", INTEGER, EXCEED_POLICY )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color", VECTOR4, TEXT_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color", VECTOR4, PLACEHOLDER_TEXT_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset", VECTOR2, SHADOW_OFFSET )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color", VECTOR4, SHADOW_COLOR )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color", VECTOR4, PRIMARY_CURSOR_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color", VECTOR4, SECONDARY_CURSOR_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink", BOOLEAN, ENABLE_CURSOR_BLINK )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-width", INTEGER, CURSOR_WIDTH )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", STRING, GRAB_HANDLE_PRESSED_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold", FLOAT, SCROLL_THRESHOLD )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed", FLOAT, SCROLL_SPEED )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", MAP, SELECTION_HANDLE_IMAGE_LEFT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-left", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-right", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings", MAP, INPUT_METHOD_SETTINGS )
121 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "text-changed", SIGNAL_TEXT_CHANGED )
122 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
124 DALI_TYPE_REGISTRATION_END()
128 Toolkit::TextField TextField::New()
130 // Create the implementation, temporarily owned by this handle on stack
131 IntrusivePtr< TextField > impl = new TextField();
133 // Pass ownership to CustomActor handle
134 Toolkit::TextField handle( *impl );
136 // Second-phase init of the implementation
137 // This can only be done after the CustomActor connection has been made...
143 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
145 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
147 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
152 TextField& impl( GetImpl( textField ) );
156 case Toolkit::TextField::Property::RENDERING_BACKEND:
158 int backend = value.Get< int >();
159 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
161 if( impl.mRenderingBackend != backend )
163 impl.mRenderingBackend = backend;
164 impl.mRenderer.Reset();
165 impl.RequestTextRelayout();
169 case Toolkit::TextField::Property::TEXT:
171 if( impl.mController )
173 const std::string text = value.Get< std::string >();
174 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
176 impl.mController->SetText( text );
180 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
182 if( impl.mController )
184 const std::string text = value.Get< std::string >();
185 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
187 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
191 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
193 if( impl.mController )
195 const std::string text = value.Get< std::string >();
196 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
198 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
202 case Toolkit::TextField::Property::FONT_FAMILY:
204 if( impl.mController )
206 const std::string fontFamily = value.Get< std::string >();
207 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
209 if( impl.mController->GetDefaultFontFamily() != fontFamily )
211 impl.mController->SetDefaultFontFamily( fontFamily, true ); // "true" as SetProperty means user defined font so don't change when system font changes.
216 case Toolkit::TextField::Property::FONT_STYLE:
218 SetFontStyleProperty( impl.mController, value );
221 case Toolkit::TextField::Property::POINT_SIZE:
223 if( impl.mController )
225 const float pointSize = value.Get< float >();
226 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
228 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
230 impl.mController->SetDefaultPointSize( pointSize );
235 case Toolkit::TextField::Property::MAX_LENGTH:
237 if( impl.mController )
239 const int max = value.Get< int >();
240 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
242 impl.mController->SetMaximumNumberOfCharacters( max );
246 case Toolkit::TextField::Property::EXCEED_POLICY:
251 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
253 if( impl.mController )
255 const std::string alignStr = value.Get< std::string >();
256 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
258 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
259 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
260 HORIZONTAL_ALIGNMENT_STRING_TABLE,
261 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
264 impl.mController->SetHorizontalAlignment( alignment );
269 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
271 if( impl.mController )
273 const std::string alignStr = value.Get< std::string >();
274 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
276 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
277 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
278 VERTICAL_ALIGNMENT_STRING_TABLE,
279 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
282 impl.mController->SetVerticalAlignment( alignment );
287 case Toolkit::TextField::Property::TEXT_COLOR:
289 if( impl.mController )
291 const Vector4 textColor = value.Get< Vector4 >();
292 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 );
294 if( impl.mController->GetTextColor() != textColor )
296 impl.mController->SetTextColor( textColor );
297 impl.mRenderer.Reset();
302 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
304 if( impl.mController )
306 const Vector4 textColor = value.Get< Vector4 >();
307 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 );
309 if( impl.mController->GetPlaceholderTextColor() != textColor )
311 impl.mController->SetPlaceholderTextColor( textColor );
312 impl.mRenderer.Reset();
317 case Toolkit::TextField::Property::SHADOW_OFFSET:
319 if( impl.mController )
321 const Vector2 shadowOffset = value.Get< Vector2 >();
322 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
324 if ( impl.mController->GetShadowOffset() != shadowOffset )
326 impl.mController->SetShadowOffset( shadowOffset );
327 impl.mRenderer.Reset();
332 case Toolkit::TextField::Property::SHADOW_COLOR:
334 if( impl.mController )
336 const Vector4 shadowColor = value.Get< Vector4 >();
337 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 );
339 if ( impl.mController->GetShadowColor() != shadowColor )
341 impl.mController->SetShadowColor( shadowColor );
342 impl.mRenderer.Reset();
347 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
349 if( impl.mDecorator )
351 const Vector4 color = value.Get< Vector4 >();
352 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 );
354 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
355 impl.RequestTextRelayout();
359 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
361 if( impl.mDecorator )
363 const Vector4 color = value.Get< Vector4 >();
364 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 );
366 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
367 impl.RequestTextRelayout();
371 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
373 if( impl.mController )
375 const bool enable = value.Get< bool >();
376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
378 impl.mController->SetEnableCursorBlink( enable );
379 impl.RequestTextRelayout();
383 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
385 if( impl.mDecorator )
387 const float interval = value.Get< float >();
388 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
390 impl.mDecorator->SetCursorBlinkInterval( interval );
394 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
396 if( impl.mDecorator )
398 const float duration = value.Get< float >();
399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
401 impl.mDecorator->SetCursorBlinkDuration( duration );
405 case Toolkit::TextField::Property::CURSOR_WIDTH:
407 if( impl.mDecorator )
409 const int width = value.Get< int >();
410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
412 impl.mDecorator->SetCursorWidth( width );
413 impl.mController->GetLayoutEngine().SetCursorWidth( width );
417 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
419 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
420 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
422 if( impl.mDecorator )
424 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
425 impl.RequestTextRelayout();
429 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
431 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
432 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
434 if( impl.mDecorator )
436 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
437 impl.RequestTextRelayout();
441 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
443 const float threshold = value.Get< float >();
444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
446 if( impl.mDecorator )
448 impl.mDecorator->SetScrollThreshold( threshold );
452 case Toolkit::TextField::Property::SCROLL_SPEED:
454 const float speed = value.Get< float >();
455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
457 if( impl.mDecorator )
459 impl.mDecorator->SetScrollSpeed( speed );
463 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
465 const Image image = Scripting::NewImage( value );
467 if( impl.mDecorator && image )
469 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
470 impl.RequestTextRelayout();
474 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
476 const Image image = Scripting::NewImage( value );
478 if( impl.mDecorator && image )
480 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
481 impl.RequestTextRelayout();
485 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
487 const Image image = Scripting::NewImage( value );
489 if( impl.mDecorator && image )
491 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
492 impl.RequestTextRelayout();
496 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
498 const Image image = Scripting::NewImage( value );
500 if( impl.mDecorator && image )
502 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
503 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
509 const Image image = Scripting::NewImage( value );
511 if( impl.mDecorator && image )
513 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
514 impl.RequestTextRelayout();
518 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
520 const Image image = Scripting::NewImage( value );
522 if( impl.mDecorator && image )
524 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
525 impl.RequestTextRelayout();
529 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
531 const Vector4 color = value.Get< Vector4 >();
532 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 );
534 if( impl.mDecorator )
536 impl.mDecorator->SetHighlightColor( color );
537 impl.RequestTextRelayout();
541 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
543 if( impl.mDecorator )
545 const Rect<int> box = value.Get< Rect<int> >();
546 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 );
548 impl.mDecorator->SetBoundingBox( box );
549 impl.RequestTextRelayout();
553 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
555 const Property::Map map = value.Get<Property::Map>();
556 VirtualKeyboard::ApplySettings( map );
563 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
565 Property::Value value;
567 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
571 TextField& impl( GetImpl( textField ) );
575 case Toolkit::TextField::Property::RENDERING_BACKEND:
577 value = impl.mRenderingBackend;
580 case Toolkit::TextField::Property::TEXT:
582 if( impl.mController )
585 impl.mController->GetText( text );
586 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
591 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
593 if( impl.mController )
596 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
601 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
603 if( impl.mController )
606 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
611 case Toolkit::TextField::Property::FONT_FAMILY:
613 if( impl.mController )
615 value = impl.mController->GetDefaultFontFamily();
619 case Toolkit::TextField::Property::FONT_STYLE:
621 GetFontStyleProperty( impl.mController, value );
624 case Toolkit::TextField::Property::POINT_SIZE:
626 if( impl.mController )
628 value = impl.mController->GetDefaultPointSize();
632 case Toolkit::TextField::Property::MAX_LENGTH:
634 if( impl.mController )
636 value = impl.mController->GetMaximumNumberOfCharacters();
640 case Toolkit::TextField::Property::EXCEED_POLICY:
642 value = impl.mExceedPolicy;
645 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
647 if( impl.mController )
649 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
650 HORIZONTAL_ALIGNMENT_STRING_TABLE,
651 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
654 value = std::string( name );
659 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
661 if( impl.mController )
663 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
664 VERTICAL_ALIGNMENT_STRING_TABLE,
665 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
668 value = std::string( name );
673 case Toolkit::TextField::Property::TEXT_COLOR:
675 if ( impl.mController )
677 value = impl.mController->GetTextColor();
681 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
683 if ( impl.mController )
685 value = impl.mController->GetPlaceholderTextColor();
689 case Toolkit::TextField::Property::SHADOW_OFFSET:
691 if ( impl.mController )
693 value = impl.mController->GetShadowOffset();
697 case Toolkit::TextField::Property::SHADOW_COLOR:
699 if ( impl.mController )
701 value = impl.mController->GetShadowColor();
705 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
707 if( impl.mDecorator )
709 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
713 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
715 if( impl.mDecorator )
717 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
721 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
723 value = impl.mController->GetEnableCursorBlink();
726 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
728 if( impl.mDecorator )
730 value = impl.mDecorator->GetCursorBlinkInterval();
734 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
736 if( impl.mDecorator )
738 value = impl.mDecorator->GetCursorBlinkDuration();
742 case Toolkit::TextField::Property::CURSOR_WIDTH:
744 if( impl.mDecorator )
746 value = impl.mDecorator->GetCursorWidth();
750 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
752 if( impl.mDecorator )
754 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
757 value = image.GetUrl();
762 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
764 if( impl.mDecorator )
766 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
769 value = image.GetUrl();
774 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
776 if( impl.mDecorator )
778 value = impl.mDecorator->GetScrollThreshold();
782 case Toolkit::TextField::Property::SCROLL_SPEED:
784 if( impl.mDecorator )
786 value = impl.mDecorator->GetScrollSpeed();
790 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
792 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
795 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
797 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
800 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
802 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
805 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
807 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
810 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
812 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
815 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
817 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
820 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
822 if( impl.mDecorator )
824 value = impl.mDecorator->GetHighlightColor();
828 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
830 if( impl.mDecorator )
832 Rect<int> boundingBox;
833 impl.mDecorator->GetBoundingBox( boundingBox );
838 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
848 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
850 Dali::BaseHandle handle( object );
852 bool connected( true );
853 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
855 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
857 field.TextChangedSignal().Connect( tracker, functor );
859 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
861 field.MaxLengthReachedSignal().Connect( tracker, functor );
865 // signalName does not match any signal
872 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
874 return mTextChangedSignal;
877 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
879 return mMaxLengthReachedSignal;
882 void TextField::OnInitialize()
886 mController = Text::Controller::New( *this );
888 mDecorator = Text::Decorator::New( *mController,
891 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
893 mController->EnableTextInput( mDecorator );
895 // Forward input events to controller
896 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) );
897 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
899 self.TouchedSignal().Connect( this, &TextField::OnTouched );
901 // Set BoundingBox to stage size if not already set.
902 Rect<int> boundingBox;
903 mDecorator->GetBoundingBox( boundingBox );
905 if( boundingBox.IsEmpty() )
907 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
908 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
911 // Fill-parent area by default
912 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
913 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
914 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
917 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
919 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
923 case StyleChange::DEFAULT_FONT_CHANGE:
925 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
926 std::string newFont = styleManager.GetDefaultFontFamily();
927 // Property system did not set the font so should update it.
928 mController->UpdateAfterFontChange( newFont );
932 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
934 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
936 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
938 // Property system did not set the PointSize so should update it.
939 // todo instruct text-controller to update model
943 case StyleChange::THEME_CHANGE:
945 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
951 Vector3 TextField::GetNaturalSize()
953 return mController->GetNaturalSize();
956 float TextField::GetHeightForWidth( float width )
958 return mController->GetHeightForWidth( width );
961 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
963 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
965 if( mController->Relayout( size ) ||
968 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
972 mDecorator->Relayout( size );
977 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
980 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
985 void TextField::RenderText()
988 Actor renderableActor;
991 renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
994 if( renderableActor != mRenderableActor )
996 UnparentAndReset( mRenderableActor );
997 mRenderableActor = renderableActor;
1000 if( mRenderableActor )
1002 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1004 mRenderableActor.SetPosition( offset.x, offset.y );
1006 Actor clipRootActor;
1009 clipRootActor = mClipper->GetRootActor();
1012 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1013 endIt = mClippingDecorationActors.end();
1021 clipRootActor.Add( actor );
1028 mClippingDecorationActors.clear();
1030 // Make sure the actor is parented correctly with/without clipping
1033 clipRootActor.Add( mRenderableActor );
1037 self.Add( mRenderableActor );
1042 void TextField::OnKeyInputFocusGained()
1044 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1046 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1048 ImfManager imfManager = ImfManager::Get();
1052 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1054 // Notify that the text editing start.
1055 imfManager.Activate();
1057 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1058 imfManager.SetRestoreAfterFocusLost( true );
1061 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1065 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1068 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1070 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1073 void TextField::OnKeyInputFocusLost()
1075 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1077 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1079 ImfManager imfManager = ImfManager::Get();
1082 // The text editing is finished. Therefore the imf manager don't have restore activation.
1083 imfManager.SetRestoreAfterFocusLost( false );
1085 // Notify that the text editing finish.
1086 imfManager.Deactivate();
1088 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1091 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1095 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1098 mController->KeyboardFocusLostEvent();
1100 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1103 void TextField::OnTap( const TapGesture& gesture )
1105 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1107 // Show the keyboard if it was hidden.
1108 if (!VirtualKeyboard::IsVisible())
1110 VirtualKeyboard::Show();
1113 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1114 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1119 void TextField::OnPan( const PanGesture& gesture )
1121 mController->PanEvent( gesture.state, gesture.displacement );
1124 void TextField::OnLongPress( const LongPressGesture& gesture )
1126 // Show the keyboard if it was hidden.
1127 if (!VirtualKeyboard::IsVisible())
1129 VirtualKeyboard::Show();
1132 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1137 bool TextField::OnKeyEvent( const KeyEvent& event )
1139 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1141 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1142 "Return" == event.keyPressedName ) // Make a Dali key code for this
1144 ClearKeyInputFocus();
1148 return mController->KeyEvent( event );
1151 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1157 mClippingDecorationActors.push_back( actor );
1161 Self().Add( actor );
1166 void TextField::RequestTextRelayout()
1171 void TextField::TextChanged()
1173 Dali::Toolkit::TextField handle( GetOwner() );
1174 mTextChangedSignal.Emit( handle );
1177 void TextField::OnStageConnect( Dali::Actor actor )
1179 if ( mHasBeenStaged )
1185 mHasBeenStaged = true;
1189 void TextField::MaxLengthReached()
1191 Dali::Toolkit::TextField handle( GetOwner() );
1192 mMaxLengthReachedSignal.Emit( handle );
1195 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1197 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1198 return mController->OnImfEvent( imfManager, imfEvent );
1201 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1205 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1210 Scripting::CreatePropertyMap( image, map );
1216 void TextField::EnableClipping( bool clipping, const Vector2& size )
1220 // Not worth to created clip actor if width or height is equal to zero.
1221 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1225 Actor self = Self();
1227 mClipper = Clipper::New( size );
1228 self.Add( mClipper->GetRootActor() );
1229 self.Add( mClipper->GetImageActor() );
1231 else if ( mClipper )
1233 mClipper->Refresh( size );
1239 // Note - this will automatically remove the root & image actors
1244 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1246 mController->PasteClipboardItemEvent();
1249 void TextField::KeyboardStatusChanged(bool keyboardShown)
1251 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1253 // Just hide the grab handle when keyboard is hidden.
1254 if (!keyboardShown )
1256 mController->KeyboardFocusLostEvent();
1260 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1264 void TextField::OnStageConnection( int depth )
1266 // Call the Control::OnStageConnection() to set the depth of the background.
1267 Control::OnStageConnection( depth );
1269 // Sets the depth to the renderers inside the text's decorator.
1270 mDecorator->SetTextDepth( depth );
1272 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1275 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1280 TextField::TextField()
1281 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1282 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1283 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1284 mHasBeenStaged( false )
1288 TextField::~TextField()
1293 } // namespace Internal
1295 } // namespace Toolkit