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 )
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 )
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 )
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 )
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 );
510 if( impl.mDecorator )
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 );
520 if( impl.mDecorator )
522 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
523 impl.RequestTextRelayout();
527 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
529 const Vector4 color = value.Get< Vector4 >();
530 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 );
532 if( impl.mDecorator )
534 impl.mDecorator->SetHighlightColor( color );
535 impl.RequestTextRelayout();
539 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
541 if( impl.mDecorator )
543 const Rect<int> box = value.Get< Rect<int> >();
544 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 );
546 impl.mDecorator->SetBoundingBox( box );
547 impl.RequestTextRelayout();
551 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
553 const Property::Map map = value.Get<Property::Map>();
554 VirtualKeyboard::ApplySettings( map );
561 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
563 Property::Value value;
565 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
569 TextField& impl( GetImpl( textField ) );
573 case Toolkit::TextField::Property::RENDERING_BACKEND:
575 value = impl.mRenderingBackend;
578 case Toolkit::TextField::Property::TEXT:
580 if( impl.mController )
583 impl.mController->GetText( text );
584 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
589 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
591 if( impl.mController )
594 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
599 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
601 if( impl.mController )
604 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
609 case Toolkit::TextField::Property::FONT_FAMILY:
611 if( impl.mController )
613 value = impl.mController->GetDefaultFontFamily();
617 case Toolkit::TextField::Property::FONT_STYLE:
619 GetFontStyleProperty( impl.mController, value );
622 case Toolkit::TextField::Property::POINT_SIZE:
624 if( impl.mController )
626 value = impl.mController->GetDefaultPointSize();
630 case Toolkit::TextField::Property::MAX_LENGTH:
632 if( impl.mController )
634 value = impl.mController->GetMaximumNumberOfCharacters();
638 case Toolkit::TextField::Property::EXCEED_POLICY:
640 value = impl.mExceedPolicy;
643 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
645 if( impl.mController )
647 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
648 HORIZONTAL_ALIGNMENT_STRING_TABLE,
649 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
652 value = std::string( name );
657 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
659 if( impl.mController )
661 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
662 VERTICAL_ALIGNMENT_STRING_TABLE,
663 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
666 value = std::string( name );
671 case Toolkit::TextField::Property::TEXT_COLOR:
673 if ( impl.mController )
675 value = impl.mController->GetTextColor();
679 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
681 if ( impl.mController )
683 value = impl.mController->GetPlaceholderTextColor();
687 case Toolkit::TextField::Property::SHADOW_OFFSET:
689 if ( impl.mController )
691 value = impl.mController->GetShadowOffset();
695 case Toolkit::TextField::Property::SHADOW_COLOR:
697 if ( impl.mController )
699 value = impl.mController->GetShadowColor();
703 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
705 if( impl.mDecorator )
707 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
711 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
713 if( impl.mDecorator )
715 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
719 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
721 value = impl.mController->GetEnableCursorBlink();
724 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
726 if( impl.mDecorator )
728 value = impl.mDecorator->GetCursorBlinkInterval();
732 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
734 if( impl.mDecorator )
736 value = impl.mDecorator->GetCursorBlinkDuration();
740 case Toolkit::TextField::Property::CURSOR_WIDTH:
742 if( impl.mDecorator )
744 value = impl.mDecorator->GetCursorWidth();
748 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
750 if( impl.mDecorator )
752 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
755 value = image.GetUrl();
760 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
762 if( impl.mDecorator )
764 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
767 value = image.GetUrl();
772 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
774 if( impl.mDecorator )
776 value = impl.mDecorator->GetScrollThreshold();
780 case Toolkit::TextField::Property::SCROLL_SPEED:
782 if( impl.mDecorator )
784 value = impl.mDecorator->GetScrollSpeed();
788 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
790 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
793 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
795 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
798 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
800 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
803 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
805 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
808 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
810 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
813 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
815 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
818 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
820 if( impl.mDecorator )
822 value = impl.mDecorator->GetHighlightColor();
826 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
828 if( impl.mDecorator )
830 value = impl.mDecorator->GetBoundingBox();
834 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
844 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
846 Dali::BaseHandle handle( object );
848 bool connected( true );
849 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
851 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
853 field.TextChangedSignal().Connect( tracker, functor );
855 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
857 field.MaxLengthReachedSignal().Connect( tracker, functor );
861 // signalName does not match any signal
868 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
870 return mTextChangedSignal;
873 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
875 return mMaxLengthReachedSignal;
878 void TextField::OnInitialize()
882 mController = Text::Controller::New( *this );
884 mDecorator = Text::Decorator::New( *mController,
887 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
889 mController->EnableTextInput( mDecorator );
891 // Forward input events to controller
892 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) );
893 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
895 self.TouchedSignal().Connect( this, &TextField::OnTouched );
897 // Set BoundingBox to stage size if not already set.
898 if ( mDecorator->GetBoundingBox().IsEmpty() )
900 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
901 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
904 // Fill-parent area by default
905 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
906 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
907 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
910 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
912 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
916 case StyleChange::DEFAULT_FONT_CHANGE:
918 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
919 std::string newFont = styleManager.GetDefaultFontFamily();
920 // Property system did not set the font so should update it.
921 mController->UpdateAfterFontChange( newFont );
925 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
927 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
929 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
931 // Property system did not set the PointSize so should update it.
932 // todo instruct text-controller to update model
936 case StyleChange::THEME_CHANGE:
938 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
944 Vector3 TextField::GetNaturalSize()
946 return mController->GetNaturalSize();
949 float TextField::GetHeightForWidth( float width )
951 return mController->GetHeightForWidth( width );
954 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
956 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
958 if( mController->Relayout( size ) ||
961 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
965 mDecorator->Relayout( size );
970 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
973 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
978 void TextField::RenderText()
981 Actor renderableActor;
984 renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
987 if( renderableActor != mRenderableActor )
989 UnparentAndReset( mRenderableActor );
990 mRenderableActor = renderableActor;
993 if( mRenderableActor )
995 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
997 mRenderableActor.SetPosition( offset.x, offset.y );
1002 clipRootActor = mClipper->GetRootActor();
1005 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1006 endIt = mClippingDecorationActors.end();
1014 clipRootActor.Add( actor );
1021 mClippingDecorationActors.clear();
1023 // Make sure the actor is parented correctly with/without clipping
1026 clipRootActor.Add( mRenderableActor );
1030 self.Add( mRenderableActor );
1035 void TextField::OnKeyInputFocusGained()
1037 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1039 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1041 ImfManager imfManager = ImfManager::Get();
1045 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1047 // Notify that the text editing start.
1048 imfManager.Activate();
1050 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1051 imfManager.SetRestoreAfterFocusLost( true );
1054 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1058 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1061 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1063 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1066 void TextField::OnKeyInputFocusLost()
1068 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1070 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1072 ImfManager imfManager = ImfManager::Get();
1075 // The text editing is finished. Therefore the imf manager don't have restore activation.
1076 imfManager.SetRestoreAfterFocusLost( false );
1078 // Notify that the text editing finish.
1079 imfManager.Deactivate();
1081 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1084 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1088 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1091 mController->KeyboardFocusLostEvent();
1093 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1096 void TextField::OnTap( const TapGesture& gesture )
1098 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1100 // Show the keyboard if it was hidden.
1101 if (!VirtualKeyboard::IsVisible())
1103 VirtualKeyboard::Show();
1106 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1107 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1112 void TextField::OnPan( const PanGesture& gesture )
1114 mController->PanEvent( gesture.state, gesture.displacement );
1117 void TextField::OnLongPress( const LongPressGesture& gesture )
1119 // Show the keyboard if it was hidden.
1120 if (!VirtualKeyboard::IsVisible())
1122 VirtualKeyboard::Show();
1125 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1130 bool TextField::OnKeyEvent( const KeyEvent& event )
1132 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1134 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1135 "Return" == event.keyPressedName ) // Make a Dali key code for this
1137 ClearKeyInputFocus();
1141 return mController->KeyEvent( event );
1144 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1150 mClippingDecorationActors.push_back( actor );
1154 Self().Add( actor );
1159 void TextField::RequestTextRelayout()
1164 void TextField::TextChanged()
1166 Dali::Toolkit::TextField handle( GetOwner() );
1167 mTextChangedSignal.Emit( handle );
1170 void TextField::OnStageConnect( Dali::Actor actor )
1172 if ( mHasBeenStaged )
1178 mHasBeenStaged = true;
1182 void TextField::MaxLengthReached()
1184 Dali::Toolkit::TextField handle( GetOwner() );
1185 mMaxLengthReachedSignal.Emit( handle );
1188 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1190 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1191 return mController->OnImfEvent( imfManager, imfEvent );
1194 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1198 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1203 Scripting::CreatePropertyMap( image, map );
1209 void TextField::EnableClipping( bool clipping, const Vector2& size )
1213 // Not worth to created clip actor if width or height is equal to zero.
1214 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1218 Actor self = Self();
1220 mClipper = Clipper::New( size );
1221 self.Add( mClipper->GetRootActor() );
1222 self.Add( mClipper->GetImageActor() );
1224 else if ( mClipper )
1226 mClipper->Refresh( size );
1232 // Note - this will automatically remove the root & image actors
1237 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1239 mController->PasteClipboardItemEvent();
1242 void TextField::KeyboardStatusChanged(bool keyboardShown)
1244 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1246 // Just hide the grab handle when keyboard is hidden.
1247 if (!keyboardShown )
1249 mController->KeyboardFocusLostEvent();
1253 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1257 void TextField::OnStageConnection( int depth )
1259 // Call the Control::OnStageConnection() to set the depth of the background.
1260 Control::OnStageConnection( depth );
1262 // Sets the depth to the renderers inside the text's decorator.
1263 mDecorator->SetTextDepth( depth );
1265 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1268 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1273 TextField::TextField()
1274 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1275 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1276 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1277 mHasBeenStaged( false )
1281 TextField::~TextField()
1286 } // namespace Internal
1288 } // namespace Toolkit