2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
27 #include <dali/devel-api/object/type-registry-helper.h>
28 #include <dali/integration-api/debug.h>
31 #include <dali-toolkit/public-api/controls/control-depth-index-ranges.h>
32 #include <dali-toolkit/public-api/text/rendering-backend.h>
33 #include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
34 #include <dali-toolkit/internal/text/rendering/text-backend.h>
35 #include <dali-toolkit/internal/text/text-view.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 using namespace Dali::Toolkit::Text;
49 namespace // unnamed namespace
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
56 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
57 } // unnamed namespace
62 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
64 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
65 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
66 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
68 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
70 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
72 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
73 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
74 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
76 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
81 return Toolkit::TextField::New();
84 // Setup properties, signals and actions using the type-registry.
85 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", STRING, FONT_STYLE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
122 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
123 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
125 DALI_TYPE_REGISTRATION_END()
129 Toolkit::TextField TextField::New()
131 // Create the implementation, temporarily owned by this handle on stack
132 IntrusivePtr< TextField > impl = new TextField();
134 // Pass ownership to CustomActor handle
135 Toolkit::TextField handle( *impl );
137 // Second-phase init of the implementation
138 // This can only be done after the CustomActor connection has been made...
144 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
146 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
148 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
153 TextField& impl( GetImpl( textField ) );
157 case Toolkit::TextField::Property::RENDERING_BACKEND:
159 int backend = value.Get< int >();
160 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
162 if( impl.mRenderingBackend != backend )
164 impl.mRenderingBackend = backend;
165 impl.mRenderer.Reset();
166 impl.RequestTextRelayout();
170 case Toolkit::TextField::Property::TEXT:
172 if( impl.mController )
174 const std::string text = value.Get< std::string >();
175 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
177 impl.mController->SetText( text );
181 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
183 if( impl.mController )
185 const std::string text = value.Get< std::string >();
186 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
188 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
192 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
194 if( impl.mController )
196 const std::string text = value.Get< std::string >();
197 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
199 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
203 case Toolkit::TextField::Property::FONT_FAMILY:
205 if( impl.mController )
207 const std::string fontFamily = value.Get< std::string >();
208 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
209 impl.mController->SetDefaultFontFamily( fontFamily );
213 case Toolkit::TextField::Property::FONT_STYLE:
215 SetFontStyleProperty( impl.mController, value );
218 case Toolkit::TextField::Property::POINT_SIZE:
220 if( impl.mController )
222 const float pointSize = value.Get< float >();
223 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
225 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
227 impl.mController->SetDefaultPointSize( pointSize );
232 case Toolkit::TextField::Property::MAX_LENGTH:
234 if( impl.mController )
236 const int max = value.Get< int >();
237 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
239 impl.mController->SetMaximumNumberOfCharacters( max );
243 case Toolkit::TextField::Property::EXCEED_POLICY:
248 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
250 if( impl.mController )
252 const std::string alignStr = value.Get< std::string >();
253 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
255 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
256 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
257 HORIZONTAL_ALIGNMENT_STRING_TABLE,
258 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
261 impl.mController->SetHorizontalAlignment( alignment );
266 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
268 if( impl.mController )
270 const std::string alignStr = value.Get< std::string >();
271 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
273 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
274 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
275 VERTICAL_ALIGNMENT_STRING_TABLE,
276 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
279 impl.mController->SetVerticalAlignment( alignment );
284 case Toolkit::TextField::Property::TEXT_COLOR:
286 if( impl.mController )
288 const Vector4 textColor = value.Get< Vector4 >();
289 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 );
291 if( impl.mController->GetTextColor() != textColor )
293 impl.mController->SetTextColor( textColor );
294 impl.mRenderer.Reset();
299 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
301 if( impl.mController )
303 const Vector4 textColor = value.Get< Vector4 >();
304 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 );
306 if( impl.mController->GetPlaceholderTextColor() != textColor )
308 impl.mController->SetPlaceholderTextColor( textColor );
309 impl.mRenderer.Reset();
314 case Toolkit::TextField::Property::SHADOW_OFFSET:
316 if( impl.mController )
318 const Vector2 shadowOffset = value.Get< Vector2 >();
319 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
321 if ( impl.mController->GetShadowOffset() != shadowOffset )
323 impl.mController->SetShadowOffset( shadowOffset );
324 impl.mRenderer.Reset();
329 case Toolkit::TextField::Property::SHADOW_COLOR:
331 if( impl.mController )
333 const Vector4 shadowColor = value.Get< Vector4 >();
334 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 );
336 if ( impl.mController->GetShadowColor() != shadowColor )
338 impl.mController->SetShadowColor( shadowColor );
339 impl.mRenderer.Reset();
344 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
346 if( impl.mDecorator )
348 const Vector4 color = value.Get< Vector4 >();
349 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 );
351 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
352 impl.RequestTextRelayout();
356 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
358 if( impl.mDecorator )
360 const Vector4 color = value.Get< Vector4 >();
361 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 );
363 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
364 impl.RequestTextRelayout();
368 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
370 if( impl.mController )
372 const bool enable = value.Get< bool >();
373 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
375 impl.mController->SetEnableCursorBlink( enable );
376 impl.RequestTextRelayout();
380 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
382 if( impl.mDecorator )
384 const float interval = value.Get< float >();
385 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
387 impl.mDecorator->SetCursorBlinkInterval( interval );
391 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
393 if( impl.mDecorator )
395 const float duration = value.Get< float >();
396 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
398 impl.mDecorator->SetCursorBlinkDuration( duration );
402 case Toolkit::TextField::Property::CURSOR_WIDTH:
404 if( impl.mDecorator )
406 const int width = value.Get< int >();
407 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
409 impl.mDecorator->SetCursorWidth( width );
410 impl.mController->GetLayoutEngine().SetCursorWidth( width );
414 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
416 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
417 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
419 if( impl.mDecorator )
421 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
422 impl.RequestTextRelayout();
426 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
428 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
429 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
431 if( impl.mDecorator )
433 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
434 impl.RequestTextRelayout();
438 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
440 const float threshold = value.Get< float >();
441 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
443 if( impl.mDecorator )
445 impl.mDecorator->SetScrollThreshold( threshold );
449 case Toolkit::TextField::Property::SCROLL_SPEED:
451 const float speed = value.Get< float >();
452 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
454 if( impl.mDecorator )
456 impl.mDecorator->SetScrollSpeed( speed );
460 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
462 const Image image = Scripting::NewImage( value );
464 if( impl.mDecorator && image )
466 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
467 impl.RequestTextRelayout();
471 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
473 const Image image = Scripting::NewImage( value );
475 if( impl.mDecorator && image )
477 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
478 impl.RequestTextRelayout();
482 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
484 const Image image = Scripting::NewImage( value );
486 if( impl.mDecorator && image )
488 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
489 impl.RequestTextRelayout();
493 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
495 const Image image = Scripting::NewImage( value );
497 if( impl.mDecorator && image )
499 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
500 impl.RequestTextRelayout();
504 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
506 const Image image = Scripting::NewImage( value );
508 if( impl.mDecorator && image )
510 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
511 impl.RequestTextRelayout();
515 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
517 const Image image = Scripting::NewImage( value );
519 if( impl.mDecorator && image )
521 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
522 impl.RequestTextRelayout();
526 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
528 const Vector4 color = value.Get< Vector4 >();
529 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 );
531 if( impl.mDecorator )
533 impl.mDecorator->SetHighlightColor( color );
534 impl.RequestTextRelayout();
538 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
540 if( impl.mDecorator )
542 const Rect<int> box = value.Get< Rect<int> >();
543 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 );
545 impl.mDecorator->SetBoundingBox( box );
546 impl.RequestTextRelayout();
550 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
552 const Property::Map map = value.Get<Property::Map>();
553 VirtualKeyboard::ApplySettings( map );
560 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
562 Property::Value value;
564 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
568 TextField& impl( GetImpl( textField ) );
572 case Toolkit::TextField::Property::RENDERING_BACKEND:
574 value = impl.mRenderingBackend;
577 case Toolkit::TextField::Property::TEXT:
579 if( impl.mController )
582 impl.mController->GetText( text );
583 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
588 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
590 if( impl.mController )
593 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
598 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
600 if( impl.mController )
603 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
608 case Toolkit::TextField::Property::FONT_FAMILY:
610 if( impl.mController )
612 value = impl.mController->GetDefaultFontFamily();
616 case Toolkit::TextField::Property::FONT_STYLE:
618 GetFontStyleProperty( impl.mController, value );
621 case Toolkit::TextField::Property::POINT_SIZE:
623 if( impl.mController )
625 value = impl.mController->GetDefaultPointSize();
629 case Toolkit::TextField::Property::MAX_LENGTH:
631 if( impl.mController )
633 value = impl.mController->GetMaximumNumberOfCharacters();
637 case Toolkit::TextField::Property::EXCEED_POLICY:
639 value = impl.mExceedPolicy;
642 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
644 if( impl.mController )
646 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
647 HORIZONTAL_ALIGNMENT_STRING_TABLE,
648 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
651 value = std::string( name );
656 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
658 if( impl.mController )
660 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
661 VERTICAL_ALIGNMENT_STRING_TABLE,
662 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
665 value = std::string( name );
670 case Toolkit::TextField::Property::TEXT_COLOR:
672 if ( impl.mController )
674 value = impl.mController->GetTextColor();
678 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
680 if ( impl.mController )
682 value = impl.mController->GetPlaceholderTextColor();
686 case Toolkit::TextField::Property::SHADOW_OFFSET:
688 if ( impl.mController )
690 value = impl.mController->GetShadowOffset();
694 case Toolkit::TextField::Property::SHADOW_COLOR:
696 if ( impl.mController )
698 value = impl.mController->GetShadowColor();
702 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
704 if( impl.mDecorator )
706 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
710 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
712 if( impl.mDecorator )
714 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
718 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
720 value = impl.mController->GetEnableCursorBlink();
723 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
725 if( impl.mDecorator )
727 value = impl.mDecorator->GetCursorBlinkInterval();
731 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
733 if( impl.mDecorator )
735 value = impl.mDecorator->GetCursorBlinkDuration();
739 case Toolkit::TextField::Property::CURSOR_WIDTH:
741 if( impl.mDecorator )
743 value = impl.mDecorator->GetCursorWidth();
747 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
749 if( impl.mDecorator )
751 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
754 value = image.GetUrl();
759 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
761 if( impl.mDecorator )
763 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
766 value = image.GetUrl();
771 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
773 if( impl.mDecorator )
775 value = impl.mDecorator->GetScrollThreshold();
779 case Toolkit::TextField::Property::SCROLL_SPEED:
781 if( impl.mDecorator )
783 value = impl.mDecorator->GetScrollSpeed();
787 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
789 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
792 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
794 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
797 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
799 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
802 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
804 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
807 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
809 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
812 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
814 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
817 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
819 if( impl.mDecorator )
821 value = impl.mDecorator->GetHighlightColor();
825 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
827 if( impl.mDecorator )
829 Rect<int> boundingBox;
830 impl.mDecorator->GetBoundingBox( boundingBox );
835 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
845 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
847 Dali::BaseHandle handle( object );
849 bool connected( true );
850 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
852 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
854 field.TextChangedSignal().Connect( tracker, functor );
856 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
858 field.MaxLengthReachedSignal().Connect( tracker, functor );
862 // signalName does not match any signal
869 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
871 return mTextChangedSignal;
874 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
876 return mMaxLengthReachedSignal;
879 void TextField::OnInitialize()
883 mController = Text::Controller::New( *this );
885 mDecorator = Text::Decorator::New( *mController,
888 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
890 mController->EnableTextInput( mDecorator );
892 // Forward input events to controller
893 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
894 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
896 self.TouchedSignal().Connect( this, &TextField::OnTouched );
898 // Set BoundingBox to stage size if not already set.
899 Rect<int> boundingBox;
900 mDecorator->GetBoundingBox( boundingBox );
902 if( boundingBox.IsEmpty() )
904 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
905 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
908 // Flip vertically the 'left' selection handle
909 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
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(), TEXT_DEPTH_INDEX );
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