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() );
208 impl.mController->SetDefaultFontFamily( fontFamily );
212 case Toolkit::TextField::Property::FONT_STYLE:
214 SetFontStyleProperty( impl.mController, value );
217 case Toolkit::TextField::Property::POINT_SIZE:
219 if( impl.mController )
221 const float pointSize = value.Get< float >();
222 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
224 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
226 impl.mController->SetDefaultPointSize( pointSize );
231 case Toolkit::TextField::Property::MAX_LENGTH:
233 if( impl.mController )
235 const int max = value.Get< int >();
236 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
238 impl.mController->SetMaximumNumberOfCharacters( max );
242 case Toolkit::TextField::Property::EXCEED_POLICY:
247 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
249 if( impl.mController )
251 const std::string alignStr = value.Get< std::string >();
252 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
254 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
255 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
256 HORIZONTAL_ALIGNMENT_STRING_TABLE,
257 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
260 impl.mController->SetHorizontalAlignment( alignment );
265 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
267 if( impl.mController )
269 const std::string alignStr = value.Get< std::string >();
270 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
272 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
273 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
274 VERTICAL_ALIGNMENT_STRING_TABLE,
275 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
278 impl.mController->SetVerticalAlignment( alignment );
283 case Toolkit::TextField::Property::TEXT_COLOR:
285 if( impl.mController )
287 const Vector4 textColor = value.Get< Vector4 >();
288 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 );
290 if( impl.mController->GetTextColor() != textColor )
292 impl.mController->SetTextColor( textColor );
293 impl.mRenderer.Reset();
298 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
300 if( impl.mController )
302 const Vector4 textColor = value.Get< Vector4 >();
303 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 );
305 if( impl.mController->GetPlaceholderTextColor() != textColor )
307 impl.mController->SetPlaceholderTextColor( textColor );
308 impl.mRenderer.Reset();
313 case Toolkit::TextField::Property::SHADOW_OFFSET:
315 if( impl.mController )
317 const Vector2 shadowOffset = value.Get< Vector2 >();
318 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
320 if ( impl.mController->GetShadowOffset() != shadowOffset )
322 impl.mController->SetShadowOffset( shadowOffset );
323 impl.mRenderer.Reset();
328 case Toolkit::TextField::Property::SHADOW_COLOR:
330 if( impl.mController )
332 const Vector4 shadowColor = value.Get< Vector4 >();
333 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 );
335 if ( impl.mController->GetShadowColor() != shadowColor )
337 impl.mController->SetShadowColor( shadowColor );
338 impl.mRenderer.Reset();
343 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
345 if( impl.mDecorator )
347 const Vector4 color = value.Get< Vector4 >();
348 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 );
350 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
351 impl.RequestTextRelayout();
355 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
357 if( impl.mDecorator )
359 const Vector4 color = value.Get< Vector4 >();
360 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 );
362 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
363 impl.RequestTextRelayout();
367 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
369 if( impl.mController )
371 const bool enable = value.Get< bool >();
372 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
374 impl.mController->SetEnableCursorBlink( enable );
375 impl.RequestTextRelayout();
379 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
381 if( impl.mDecorator )
383 const float interval = value.Get< float >();
384 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
386 impl.mDecorator->SetCursorBlinkInterval( interval );
390 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
392 if( impl.mDecorator )
394 const float duration = value.Get< float >();
395 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
397 impl.mDecorator->SetCursorBlinkDuration( duration );
401 case Toolkit::TextField::Property::CURSOR_WIDTH:
403 if( impl.mDecorator )
405 const int width = value.Get< int >();
406 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
408 impl.mDecorator->SetCursorWidth( width );
409 impl.mController->GetLayoutEngine().SetCursorWidth( width );
413 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
415 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
416 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
418 if( impl.mDecorator )
420 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
421 impl.RequestTextRelayout();
425 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
427 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
428 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
430 if( impl.mDecorator )
432 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
433 impl.RequestTextRelayout();
437 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
439 const float threshold = value.Get< float >();
440 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
442 if( impl.mDecorator )
444 impl.mDecorator->SetScrollThreshold( threshold );
448 case Toolkit::TextField::Property::SCROLL_SPEED:
450 const float speed = value.Get< float >();
451 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
453 if( impl.mDecorator )
455 impl.mDecorator->SetScrollSpeed( speed );
459 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
461 const Image image = Scripting::NewImage( value );
463 if( impl.mDecorator && image )
465 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
466 impl.RequestTextRelayout();
470 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
472 const Image image = Scripting::NewImage( value );
474 if( impl.mDecorator && image )
476 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
477 impl.RequestTextRelayout();
481 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
483 const Image image = Scripting::NewImage( value );
485 if( impl.mDecorator && image )
487 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
488 impl.RequestTextRelayout();
492 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
494 const Image image = Scripting::NewImage( value );
496 if( impl.mDecorator && image )
498 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
499 impl.RequestTextRelayout();
503 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
505 const Image image = Scripting::NewImage( value );
507 if( impl.mDecorator && image )
509 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
510 impl.RequestTextRelayout();
514 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
516 const Image image = Scripting::NewImage( value );
518 if( impl.mDecorator && image )
520 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
521 impl.RequestTextRelayout();
525 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
527 const Vector4 color = value.Get< Vector4 >();
528 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 );
530 if( impl.mDecorator )
532 impl.mDecorator->SetHighlightColor( color );
533 impl.RequestTextRelayout();
537 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
539 if( impl.mDecorator )
541 const Rect<int> box = value.Get< Rect<int> >();
542 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 );
544 impl.mDecorator->SetBoundingBox( box );
545 impl.RequestTextRelayout();
549 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
551 const Property::Map map = value.Get<Property::Map>();
552 VirtualKeyboard::ApplySettings( map );
559 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
561 Property::Value value;
563 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
567 TextField& impl( GetImpl( textField ) );
571 case Toolkit::TextField::Property::RENDERING_BACKEND:
573 value = impl.mRenderingBackend;
576 case Toolkit::TextField::Property::TEXT:
578 if( impl.mController )
581 impl.mController->GetText( text );
582 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
587 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
589 if( impl.mController )
592 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
597 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
599 if( impl.mController )
602 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
607 case Toolkit::TextField::Property::FONT_FAMILY:
609 if( impl.mController )
611 value = impl.mController->GetDefaultFontFamily();
615 case Toolkit::TextField::Property::FONT_STYLE:
617 GetFontStyleProperty( impl.mController, value );
620 case Toolkit::TextField::Property::POINT_SIZE:
622 if( impl.mController )
624 value = impl.mController->GetDefaultPointSize();
628 case Toolkit::TextField::Property::MAX_LENGTH:
630 if( impl.mController )
632 value = impl.mController->GetMaximumNumberOfCharacters();
636 case Toolkit::TextField::Property::EXCEED_POLICY:
638 value = impl.mExceedPolicy;
641 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
643 if( impl.mController )
645 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
646 HORIZONTAL_ALIGNMENT_STRING_TABLE,
647 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
650 value = std::string( name );
655 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
657 if( impl.mController )
659 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
660 VERTICAL_ALIGNMENT_STRING_TABLE,
661 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
664 value = std::string( name );
669 case Toolkit::TextField::Property::TEXT_COLOR:
671 if ( impl.mController )
673 value = impl.mController->GetTextColor();
677 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
679 if ( impl.mController )
681 value = impl.mController->GetPlaceholderTextColor();
685 case Toolkit::TextField::Property::SHADOW_OFFSET:
687 if ( impl.mController )
689 value = impl.mController->GetShadowOffset();
693 case Toolkit::TextField::Property::SHADOW_COLOR:
695 if ( impl.mController )
697 value = impl.mController->GetShadowColor();
701 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
703 if( impl.mDecorator )
705 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
709 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
711 if( impl.mDecorator )
713 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
717 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
719 value = impl.mController->GetEnableCursorBlink();
722 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
724 if( impl.mDecorator )
726 value = impl.mDecorator->GetCursorBlinkInterval();
730 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
732 if( impl.mDecorator )
734 value = impl.mDecorator->GetCursorBlinkDuration();
738 case Toolkit::TextField::Property::CURSOR_WIDTH:
740 if( impl.mDecorator )
742 value = impl.mDecorator->GetCursorWidth();
746 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
748 if( impl.mDecorator )
750 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
753 value = image.GetUrl();
758 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
760 if( impl.mDecorator )
762 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
765 value = image.GetUrl();
770 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
772 if( impl.mDecorator )
774 value = impl.mDecorator->GetScrollThreshold();
778 case Toolkit::TextField::Property::SCROLL_SPEED:
780 if( impl.mDecorator )
782 value = impl.mDecorator->GetScrollSpeed();
786 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
788 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
791 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
793 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
796 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
798 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
801 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
803 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
806 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
808 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
811 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
813 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
816 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
818 if( impl.mDecorator )
820 value = impl.mDecorator->GetHighlightColor();
824 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
826 if( impl.mDecorator )
828 Rect<int> boundingBox;
829 impl.mDecorator->GetBoundingBox( boundingBox );
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 Rect<int> boundingBox;
899 mDecorator->GetBoundingBox( boundingBox );
901 if( boundingBox.IsEmpty() )
903 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
904 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
907 // Flip vertically the 'left' selection handle
908 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
910 // Fill-parent area by default
911 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
912 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
913 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
916 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
918 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
922 case StyleChange::DEFAULT_FONT_CHANGE:
924 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
925 std::string newFont = styleManager.GetDefaultFontFamily();
926 // Property system did not set the font so should update it.
927 mController->UpdateAfterFontChange( newFont );
931 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
933 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
935 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
937 // Property system did not set the PointSize so should update it.
938 // todo instruct text-controller to update model
942 case StyleChange::THEME_CHANGE:
944 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
950 Vector3 TextField::GetNaturalSize()
952 return mController->GetNaturalSize();
955 float TextField::GetHeightForWidth( float width )
957 return mController->GetHeightForWidth( width );
960 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
962 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
964 if( mController->Relayout( size ) ||
967 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
971 mDecorator->Relayout( size );
976 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
979 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
984 void TextField::RenderText()
987 Actor renderableActor;
990 renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
993 if( renderableActor != mRenderableActor )
995 UnparentAndReset( mRenderableActor );
996 mRenderableActor = renderableActor;
999 if( mRenderableActor )
1001 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1003 mRenderableActor.SetPosition( offset.x, offset.y );
1005 Actor clipRootActor;
1008 clipRootActor = mClipper->GetRootActor();
1011 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1012 endIt = mClippingDecorationActors.end();
1020 clipRootActor.Add( actor );
1027 mClippingDecorationActors.clear();
1029 // Make sure the actor is parented correctly with/without clipping
1032 clipRootActor.Add( mRenderableActor );
1036 self.Add( mRenderableActor );
1041 void TextField::OnKeyInputFocusGained()
1043 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1045 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1047 ImfManager imfManager = ImfManager::Get();
1051 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1053 // Notify that the text editing start.
1054 imfManager.Activate();
1056 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1057 imfManager.SetRestoreAfterFocusLost( true );
1060 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1064 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1067 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1069 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1072 void TextField::OnKeyInputFocusLost()
1074 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1076 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1078 ImfManager imfManager = ImfManager::Get();
1081 // The text editing is finished. Therefore the imf manager don't have restore activation.
1082 imfManager.SetRestoreAfterFocusLost( false );
1084 // Notify that the text editing finish.
1085 imfManager.Deactivate();
1087 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1090 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1094 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1097 mController->KeyboardFocusLostEvent();
1099 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1102 void TextField::OnTap( const TapGesture& gesture )
1104 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1106 // Show the keyboard if it was hidden.
1107 if (!VirtualKeyboard::IsVisible())
1109 VirtualKeyboard::Show();
1112 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1113 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1118 void TextField::OnPan( const PanGesture& gesture )
1120 mController->PanEvent( gesture.state, gesture.displacement );
1123 void TextField::OnLongPress( const LongPressGesture& gesture )
1125 // Show the keyboard if it was hidden.
1126 if (!VirtualKeyboard::IsVisible())
1128 VirtualKeyboard::Show();
1131 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1136 bool TextField::OnKeyEvent( const KeyEvent& event )
1138 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1140 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1141 "Return" == event.keyPressedName ) // Make a Dali key code for this
1143 ClearKeyInputFocus();
1147 return mController->KeyEvent( event );
1150 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1156 mClippingDecorationActors.push_back( actor );
1160 Self().Add( actor );
1165 void TextField::RequestTextRelayout()
1170 void TextField::TextChanged()
1172 Dali::Toolkit::TextField handle( GetOwner() );
1173 mTextChangedSignal.Emit( handle );
1176 void TextField::OnStageConnect( Dali::Actor actor )
1178 if ( mHasBeenStaged )
1184 mHasBeenStaged = true;
1188 void TextField::MaxLengthReached()
1190 Dali::Toolkit::TextField handle( GetOwner() );
1191 mMaxLengthReachedSignal.Emit( handle );
1194 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1196 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1197 return mController->OnImfEvent( imfManager, imfEvent );
1200 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1204 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1209 Scripting::CreatePropertyMap( image, map );
1215 void TextField::EnableClipping( bool clipping, const Vector2& size )
1219 // Not worth to created clip actor if width or height is equal to zero.
1220 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1224 Actor self = Self();
1226 mClipper = Clipper::New( size );
1227 self.Add( mClipper->GetRootActor() );
1228 self.Add( mClipper->GetImageActor() );
1230 else if ( mClipper )
1232 mClipper->Refresh( size );
1238 // Note - this will automatically remove the root & image actors
1243 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1245 mController->PasteClipboardItemEvent();
1248 void TextField::KeyboardStatusChanged(bool keyboardShown)
1250 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1252 // Just hide the grab handle when keyboard is hidden.
1253 if (!keyboardShown )
1255 mController->KeyboardFocusLostEvent();
1259 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1263 void TextField::OnStageConnection( int depth )
1265 // Call the Control::OnStageConnection() to set the depth of the background.
1266 Control::OnStageConnection( depth );
1268 // Sets the depth to the renderers inside the text's decorator.
1269 mDecorator->SetTextDepth( depth );
1271 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1274 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1279 TextField::TextField()
1280 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1281 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1282 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1283 mHasBeenStaged( false )
1287 TextField::~TextField()
1292 } // namespace Internal
1294 } // namespace Toolkit