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/devel-api/controls/control-depth-index-ranges.h>
33 #include <dali-toolkit/internal/text/rendering/text-backend.h>
34 #include <dali-toolkit/internal/text/text-font-style.h>
35 #include <dali-toolkit/internal/text/text-view.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 using namespace Dali::Toolkit::Text;
49 namespace // unnamed namespace
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
56 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
57 } // unnamed namespace
62 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
64 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
65 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
66 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
68 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
70 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
72 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
73 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
74 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
76 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
81 return Toolkit::TextField::New();
84 // Setup properties, signals and actions using the type-registry.
85 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", STRING, FONT_STYLE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", STRING, INPUT_FONT_STYLE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
127 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
128 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
130 DALI_TYPE_REGISTRATION_END()
134 Toolkit::TextField TextField::New()
136 // Create the implementation, temporarily owned by this handle on stack
137 IntrusivePtr< TextField > impl = new TextField();
139 // Pass ownership to CustomActor handle
140 Toolkit::TextField handle( *impl );
142 // Second-phase init of the implementation
143 // This can only be done after the CustomActor connection has been made...
149 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
151 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
153 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
158 TextField& impl( GetImpl( textField ) );
162 case Toolkit::TextField::Property::RENDERING_BACKEND:
164 int backend = value.Get< int >();
165 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
167 if( impl.mRenderingBackend != backend )
169 impl.mRenderingBackend = backend;
170 impl.mRenderer.Reset();
171 impl.RequestTextRelayout();
175 case Toolkit::TextField::Property::TEXT:
177 if( impl.mController )
179 const std::string text = value.Get< std::string >();
180 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
182 impl.mController->SetText( text );
186 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
188 if( impl.mController )
190 const std::string text = value.Get< std::string >();
191 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
193 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
197 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
199 if( impl.mController )
201 const std::string text = value.Get< std::string >();
202 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
204 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
208 case Toolkit::TextField::Property::FONT_FAMILY:
210 if( impl.mController )
212 const std::string fontFamily = value.Get< std::string >();
213 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
214 impl.mController->SetDefaultFontFamily( fontFamily );
218 case Toolkit::TextField::Property::FONT_STYLE:
220 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
223 case Toolkit::TextField::Property::POINT_SIZE:
225 if( impl.mController )
227 const float pointSize = value.Get< float >();
228 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
230 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
232 impl.mController->SetDefaultPointSize( pointSize );
237 case Toolkit::TextField::Property::MAX_LENGTH:
239 if( impl.mController )
241 const int max = value.Get< int >();
242 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
244 impl.mController->SetMaximumNumberOfCharacters( max );
248 case Toolkit::TextField::Property::EXCEED_POLICY:
253 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
255 if( impl.mController )
257 const std::string alignStr = value.Get< std::string >();
258 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
260 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
261 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
262 HORIZONTAL_ALIGNMENT_STRING_TABLE,
263 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
266 impl.mController->SetHorizontalAlignment( alignment );
271 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
273 if( impl.mController )
275 const std::string alignStr = value.Get< std::string >();
276 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
278 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
279 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
280 VERTICAL_ALIGNMENT_STRING_TABLE,
281 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
284 impl.mController->SetVerticalAlignment( alignment );
289 case Toolkit::TextField::Property::TEXT_COLOR:
291 if( impl.mController )
293 const Vector4 textColor = value.Get< Vector4 >();
294 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 );
296 if( impl.mController->GetTextColor() != textColor )
298 impl.mController->SetTextColor( textColor );
299 impl.mController->SetInputColor( textColor );
300 impl.mRenderer.Reset();
305 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
307 if( impl.mController )
309 const Vector4 textColor = value.Get< Vector4 >();
310 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 );
312 if( impl.mController->GetPlaceholderTextColor() != textColor )
314 impl.mController->SetPlaceholderTextColor( textColor );
315 impl.mRenderer.Reset();
320 case Toolkit::TextField::Property::SHADOW_OFFSET:
322 if( impl.mController )
324 const Vector2 shadowOffset = value.Get< Vector2 >();
325 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
327 if ( impl.mController->GetShadowOffset() != shadowOffset )
329 impl.mController->SetShadowOffset( shadowOffset );
330 impl.mRenderer.Reset();
335 case Toolkit::TextField::Property::SHADOW_COLOR:
337 if( impl.mController )
339 const Vector4 shadowColor = value.Get< Vector4 >();
340 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 );
342 if ( impl.mController->GetShadowColor() != shadowColor )
344 impl.mController->SetShadowColor( shadowColor );
345 impl.mRenderer.Reset();
350 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
352 if( impl.mDecorator )
354 const Vector4 color = value.Get< Vector4 >();
355 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 );
357 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
358 impl.RequestTextRelayout();
362 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
364 if( impl.mDecorator )
366 const Vector4 color = value.Get< Vector4 >();
367 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 );
369 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
370 impl.RequestTextRelayout();
374 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
376 if( impl.mController )
378 const bool enable = value.Get< bool >();
379 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
381 impl.mController->SetEnableCursorBlink( enable );
382 impl.RequestTextRelayout();
386 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
388 if( impl.mDecorator )
390 const float interval = value.Get< float >();
391 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
393 impl.mDecorator->SetCursorBlinkInterval( interval );
397 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
399 if( impl.mDecorator )
401 const float duration = value.Get< float >();
402 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
404 impl.mDecorator->SetCursorBlinkDuration( duration );
408 case Toolkit::TextField::Property::CURSOR_WIDTH:
410 if( impl.mDecorator )
412 const int width = value.Get< int >();
413 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
415 impl.mDecorator->SetCursorWidth( width );
416 impl.mController->GetLayoutEngine().SetCursorWidth( width );
420 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
422 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
423 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
425 if( impl.mDecorator )
427 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
428 impl.RequestTextRelayout();
432 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
434 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
435 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
437 if( impl.mDecorator )
439 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
440 impl.RequestTextRelayout();
444 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
446 const float threshold = value.Get< float >();
447 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
449 if( impl.mDecorator )
451 impl.mDecorator->SetScrollThreshold( threshold );
455 case Toolkit::TextField::Property::SCROLL_SPEED:
457 const float speed = value.Get< float >();
458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
460 if( impl.mDecorator )
462 impl.mDecorator->SetScrollSpeed( speed );
466 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
468 const Image image = Scripting::NewImage( value );
470 if( impl.mDecorator && image )
472 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
473 impl.RequestTextRelayout();
477 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
479 const Image image = Scripting::NewImage( value );
481 if( impl.mDecorator && image )
483 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
484 impl.RequestTextRelayout();
488 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
490 const Image image = Scripting::NewImage( value );
492 if( impl.mDecorator && image )
494 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
495 impl.RequestTextRelayout();
499 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
501 const Image image = Scripting::NewImage( value );
503 if( impl.mDecorator && image )
505 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
506 impl.RequestTextRelayout();
510 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
512 const Image image = Scripting::NewImage( value );
514 if( impl.mDecorator && image )
516 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
517 impl.RequestTextRelayout();
521 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
523 const Image image = Scripting::NewImage( value );
525 if( impl.mDecorator && image )
527 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
528 impl.RequestTextRelayout();
532 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
534 const Vector4 color = value.Get< Vector4 >();
535 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 );
537 if( impl.mDecorator )
539 impl.mDecorator->SetHighlightColor( color );
540 impl.RequestTextRelayout();
544 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
546 if( impl.mDecorator )
548 const Rect<int> box = value.Get< Rect<int> >();
549 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 );
551 impl.mDecorator->SetBoundingBox( box );
552 impl.RequestTextRelayout();
556 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
558 const Property::Map map = value.Get<Property::Map>();
559 VirtualKeyboard::ApplySettings( map );
562 case Toolkit::TextField::Property::INPUT_COLOR:
564 if( impl.mController )
566 const Vector4 inputColor = value.Get< Vector4 >();
567 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), inputColor.r, inputColor.g, inputColor.b, inputColor.a );
569 impl.mController->SetInputColor( inputColor );
573 case Toolkit::TextField::Property::ENABLE_MARKUP:
575 if( impl.mController )
577 const bool enableMarkup = value.Get<bool>();
578 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
580 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
584 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
586 if( impl.mController )
588 const std::string fontFamily = value.Get< std::string >();
589 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
590 impl.mController->SetInputFontFamily( fontFamily );
594 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
596 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
599 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
601 if( impl.mController )
603 const float pointSize = value.Get< float >();
604 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
605 impl.mController->SetInputFontPointSize( pointSize );
613 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
615 Property::Value value;
617 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
621 TextField& impl( GetImpl( textField ) );
625 case Toolkit::TextField::Property::RENDERING_BACKEND:
627 value = impl.mRenderingBackend;
630 case Toolkit::TextField::Property::TEXT:
632 if( impl.mController )
635 impl.mController->GetText( text );
636 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
641 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
643 if( impl.mController )
646 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
651 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
653 if( impl.mController )
656 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
661 case Toolkit::TextField::Property::FONT_FAMILY:
663 if( impl.mController )
665 value = impl.mController->GetDefaultFontFamily();
669 case Toolkit::TextField::Property::FONT_STYLE:
671 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
674 case Toolkit::TextField::Property::POINT_SIZE:
676 if( impl.mController )
678 value = impl.mController->GetDefaultPointSize();
682 case Toolkit::TextField::Property::MAX_LENGTH:
684 if( impl.mController )
686 value = impl.mController->GetMaximumNumberOfCharacters();
690 case Toolkit::TextField::Property::EXCEED_POLICY:
692 value = impl.mExceedPolicy;
695 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
697 if( impl.mController )
699 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
700 HORIZONTAL_ALIGNMENT_STRING_TABLE,
701 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
704 value = std::string( name );
709 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
711 if( impl.mController )
713 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
714 VERTICAL_ALIGNMENT_STRING_TABLE,
715 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
718 value = std::string( name );
723 case Toolkit::TextField::Property::TEXT_COLOR:
725 if ( impl.mController )
727 value = impl.mController->GetTextColor();
731 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
733 if ( impl.mController )
735 value = impl.mController->GetPlaceholderTextColor();
739 case Toolkit::TextField::Property::SHADOW_OFFSET:
741 if ( impl.mController )
743 value = impl.mController->GetShadowOffset();
747 case Toolkit::TextField::Property::SHADOW_COLOR:
749 if ( impl.mController )
751 value = impl.mController->GetShadowColor();
755 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
757 if( impl.mDecorator )
759 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
763 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
765 if( impl.mDecorator )
767 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
771 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
773 value = impl.mController->GetEnableCursorBlink();
776 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
778 if( impl.mDecorator )
780 value = impl.mDecorator->GetCursorBlinkInterval();
784 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
786 if( impl.mDecorator )
788 value = impl.mDecorator->GetCursorBlinkDuration();
792 case Toolkit::TextField::Property::CURSOR_WIDTH:
794 if( impl.mDecorator )
796 value = impl.mDecorator->GetCursorWidth();
800 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
802 if( impl.mDecorator )
804 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
807 value = image.GetUrl();
812 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
814 if( impl.mDecorator )
816 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
819 value = image.GetUrl();
824 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
826 if( impl.mDecorator )
828 value = impl.mDecorator->GetScrollThreshold();
832 case Toolkit::TextField::Property::SCROLL_SPEED:
834 if( impl.mDecorator )
836 value = impl.mDecorator->GetScrollSpeed();
840 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
842 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
845 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
847 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
850 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
852 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
855 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
857 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
860 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
862 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
865 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
867 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
870 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
872 if( impl.mDecorator )
874 value = impl.mDecorator->GetHighlightColor();
878 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
880 if( impl.mDecorator )
882 Rect<int> boundingBox;
883 impl.mDecorator->GetBoundingBox( boundingBox );
888 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
892 case Toolkit::TextField::Property::INPUT_COLOR:
894 if( impl.mController )
896 value = impl.mController->GetInputColor();
900 case Toolkit::TextField::Property::ENABLE_MARKUP:
902 if( impl.mController )
904 value = impl.mController->IsMarkupProcessorEnabled();
908 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
910 if( impl.mController )
912 value = impl.mController->GetInputFontFamily();
916 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
918 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
921 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
923 if( impl.mController )
925 value = impl.mController->GetInputFontPointSize();
935 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
937 Dali::BaseHandle handle( object );
939 bool connected( true );
940 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
942 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
944 field.TextChangedSignal().Connect( tracker, functor );
946 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
948 field.MaxLengthReachedSignal().Connect( tracker, functor );
952 // signalName does not match any signal
959 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
961 return mTextChangedSignal;
964 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
966 return mMaxLengthReachedSignal;
969 void TextField::OnInitialize()
973 mController = Text::Controller::New( *this );
975 mDecorator = Text::Decorator::New( *mController,
978 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
980 mController->EnableTextInput( mDecorator );
982 // Forward input events to controller
983 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
984 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
986 self.TouchedSignal().Connect( this, &TextField::OnTouched );
988 // Set BoundingBox to stage size if not already set.
989 Rect<int> boundingBox;
990 mDecorator->GetBoundingBox( boundingBox );
992 if( boundingBox.IsEmpty() )
994 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
995 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
998 // Flip vertically the 'left' selection handle
999 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1001 // Fill-parent area by default
1002 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1003 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1004 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1007 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1009 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1013 case StyleChange::DEFAULT_FONT_CHANGE:
1015 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1016 std::string newFont = styleManager.GetDefaultFontFamily();
1017 // Property system did not set the font so should update it.
1018 mController->UpdateAfterFontChange( newFont );
1022 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1024 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
1026 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
1028 // Property system did not set the PointSize so should update it.
1029 // todo instruct text-controller to update model
1033 case StyleChange::THEME_CHANGE:
1035 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1041 Vector3 TextField::GetNaturalSize()
1043 return mController->GetNaturalSize();
1046 float TextField::GetHeightForWidth( float width )
1048 return mController->GetHeightForWidth( width );
1051 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1053 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1055 if( mController->Relayout( size ) ||
1058 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1062 mDecorator->Relayout( size );
1067 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1070 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
1075 void TextField::RenderText()
1077 Actor self = Self();
1078 Actor renderableActor;
1081 renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
1084 if( renderableActor != mRenderableActor )
1086 UnparentAndReset( mRenderableActor );
1087 mRenderableActor = renderableActor;
1090 if( mRenderableActor )
1092 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1094 mRenderableActor.SetPosition( offset.x, offset.y );
1096 Actor clipRootActor;
1099 clipRootActor = mClipper->GetRootActor();
1102 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1103 endIt = mClippingDecorationActors.end();
1111 clipRootActor.Add( actor );
1118 mClippingDecorationActors.clear();
1120 // Make sure the actor is parented correctly with/without clipping
1123 clipRootActor.Add( mRenderableActor );
1127 self.Add( mRenderableActor );
1132 void TextField::OnKeyInputFocusGained()
1134 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1136 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1138 ImfManager imfManager = ImfManager::Get();
1142 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1144 // Notify that the text editing start.
1145 imfManager.Activate();
1147 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1148 imfManager.SetRestoreAfterFocusLost( true );
1151 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1155 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1158 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1160 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1163 void TextField::OnKeyInputFocusLost()
1165 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1167 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1169 ImfManager imfManager = ImfManager::Get();
1172 // The text editing is finished. Therefore the imf manager don't have restore activation.
1173 imfManager.SetRestoreAfterFocusLost( false );
1175 // Notify that the text editing finish.
1176 imfManager.Deactivate();
1178 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1181 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1185 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1188 mController->KeyboardFocusLostEvent();
1190 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1193 void TextField::OnTap( const TapGesture& gesture )
1195 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1197 // Show the keyboard if it was hidden.
1198 if (!VirtualKeyboard::IsVisible())
1200 VirtualKeyboard::Show();
1203 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1204 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1209 void TextField::OnPan( const PanGesture& gesture )
1211 mController->PanEvent( gesture.state, gesture.displacement );
1214 void TextField::OnLongPress( const LongPressGesture& gesture )
1216 // Show the keyboard if it was hidden.
1217 if (!VirtualKeyboard::IsVisible())
1219 VirtualKeyboard::Show();
1222 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1227 bool TextField::OnKeyEvent( const KeyEvent& event )
1229 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1231 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1232 "Return" == event.keyPressedName ) // Make a Dali key code for this
1234 ClearKeyInputFocus();
1238 return mController->KeyEvent( event );
1241 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1247 mClippingDecorationActors.push_back( actor );
1251 Self().Add( actor );
1256 void TextField::RequestTextRelayout()
1261 void TextField::TextChanged()
1263 Dali::Toolkit::TextField handle( GetOwner() );
1264 mTextChangedSignal.Emit( handle );
1267 void TextField::OnStageConnect( Dali::Actor actor )
1269 if ( mHasBeenStaged )
1275 mHasBeenStaged = true;
1279 void TextField::MaxLengthReached()
1281 Dali::Toolkit::TextField handle( GetOwner() );
1282 mMaxLengthReachedSignal.Emit( handle );
1285 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1287 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1288 return mController->OnImfEvent( imfManager, imfEvent );
1291 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1295 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1300 Scripting::CreatePropertyMap( image, map );
1306 void TextField::EnableClipping( bool clipping, const Vector2& size )
1310 // Not worth to created clip actor if width or height is equal to zero.
1311 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1315 Actor self = Self();
1317 mClipper = Clipper::New( size );
1318 self.Add( mClipper->GetRootActor() );
1319 self.Add( mClipper->GetImageActor() );
1321 else if ( mClipper )
1323 mClipper->Refresh( size );
1329 // Note - this will automatically remove the root & image actors
1334 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1336 mController->PasteClipboardItemEvent();
1339 void TextField::KeyboardStatusChanged(bool keyboardShown)
1341 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1343 // Just hide the grab handle when keyboard is hidden.
1344 if (!keyboardShown )
1346 mController->KeyboardFocusLostEvent();
1350 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1354 void TextField::OnStageConnection( int depth )
1356 // Call the Control::OnStageConnection() to set the depth of the background.
1357 Control::OnStageConnection( depth );
1359 // Sets the depth to the renderers inside the text's decorator.
1360 mDecorator->SetTextDepth( depth );
1362 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1365 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1370 TextField::TextField()
1371 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1372 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1373 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1374 mHasBeenStaged( false )
1378 TextField::~TextField()
1383 } // namespace Internal
1385 } // namespace Toolkit