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>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/public-api/common/stage.h>
27 #include <dali/public-api/images/resource-image.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
30 #include <dali/devel-api/scripting/scripting.h>
31 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/public-api/text/rendering-backend.h>
36 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
37 #include <dali-toolkit/internal/text/rendering/text-backend.h>
38 #include <dali-toolkit/internal/text/text-view.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 using namespace Dali::Toolkit::Text;
52 namespace // unnamed namespace
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
59 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
61 } // unnamed namespace
66 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
68 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
69 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
70 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
72 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
74 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
76 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
77 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
78 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
80 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
85 return Toolkit::TextField::New();
88 // Setup properties, signals and actions using the type-registry.
89 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend", INTEGER, RENDERING_BACKEND )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text", STRING, PLACEHOLDER_TEXT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused", STRING, PLACEHOLDER_TEXT_FOCUSED )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family", STRING, FONT_FAMILY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style", STRING, FONT_STYLE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size", FLOAT, POINT_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length", INTEGER, MAX_LENGTH )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy", INTEGER, EXCEED_POLICY )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color", VECTOR4, TEXT_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color", VECTOR4, PLACEHOLDER_TEXT_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset", VECTOR2, SHADOW_OFFSET )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color", VECTOR4, SHADOW_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color", VECTOR4, PRIMARY_CURSOR_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color", VECTOR4, SECONDARY_CURSOR_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink", BOOLEAN, ENABLE_CURSOR_BLINK )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", STRING, GRAB_HANDLE_PRESSED_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold", FLOAT, SCROLL_THRESHOLD )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed", FLOAT, SCROLL_SPEED )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", STRING, SELECTION_HANDLE_IMAGE_LEFT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right", STRING, SELECTION_HANDLE_IMAGE_RIGHT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left", STRING, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", STRING, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings", MAP, INPUT_METHOD_SETTINGS )
123 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "text-changed", SIGNAL_TEXT_CHANGED )
124 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
126 DALI_TYPE_REGISTRATION_END()
130 Toolkit::TextField TextField::New()
132 // Create the implementation, temporarily owned by this handle on stack
133 IntrusivePtr< TextField > impl = new TextField();
135 // Pass ownership to CustomActor handle
136 Toolkit::TextField handle( *impl );
138 // Second-phase init of the implementation
139 // This can only be done after the CustomActor connection has been made...
145 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
147 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
151 TextField& impl( GetImpl( textField ) );
155 case Toolkit::TextField::Property::RENDERING_BACKEND:
157 int backend = value.Get< int >();
158 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
160 if( impl.mRenderingBackend != backend )
162 impl.mRenderingBackend = backend;
163 impl.mRenderer.Reset();
164 impl.RequestTextRelayout();
168 case Toolkit::TextField::Property::TEXT:
170 if( impl.mController )
172 const std::string text = value.Get< std::string >();
173 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
175 impl.mController->SetText( text );
179 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
181 if( impl.mController )
183 const std::string text = value.Get< std::string >();
184 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
186 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
190 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
192 if( impl.mController )
194 const std::string text = value.Get< std::string >();
195 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
197 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
201 case Toolkit::TextField::Property::FONT_FAMILY:
203 if( impl.mController )
205 const std::string fontFamily = value.Get< std::string >();
206 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
208 if( impl.mController->GetDefaultFontFamily() != fontFamily )
210 impl.mController->SetDefaultFontFamily( fontFamily );
215 case Toolkit::TextField::Property::FONT_STYLE:
217 if( impl.mController )
219 const std::string fontStyle = value.Get< std::string >();
220 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %s\n", impl.mController.Get(), fontStyle.c_str() );
222 if( impl.mController->GetDefaultFontStyle() != fontStyle )
224 impl.mController->SetDefaultFontStyle( fontStyle );
229 case Toolkit::TextField::Property::POINT_SIZE:
231 if( impl.mController )
233 const float pointSize = value.Get< float >();
234 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %f\n", impl.mController.Get(), pointSize );
236 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
238 impl.mController->SetDefaultPointSize( pointSize );
243 case Toolkit::TextField::Property::MAX_LENGTH:
245 if( impl.mController )
247 const int max = value.Get< int >();
248 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
250 impl.mController->SetMaximumNumberOfCharacters( max );
254 case Toolkit::TextField::Property::EXCEED_POLICY:
259 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
261 if( impl.mController )
263 const std::string alignStr = value.Get< std::string >();
264 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
266 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
267 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
268 HORIZONTAL_ALIGNMENT_STRING_TABLE,
269 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
272 impl.mController->SetHorizontalAlignment( alignment );
277 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
279 if( impl.mController )
281 const std::string alignStr = value.Get< std::string >();
282 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
284 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
285 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
286 VERTICAL_ALIGNMENT_STRING_TABLE,
287 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
290 impl.mController->SetVerticalAlignment( alignment );
295 case Toolkit::TextField::Property::TEXT_COLOR:
297 if( impl.mController )
299 const Vector4 textColor = value.Get< Vector4 >();
300 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 );
302 if( impl.mController->GetTextColor() != textColor )
304 impl.mController->SetTextColor( textColor );
305 impl.mRenderer.Reset();
310 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
312 if( impl.mController )
314 const Vector4 textColor = value.Get< Vector4 >();
315 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 );
317 if( impl.mController->GetPlaceholderTextColor() != textColor )
319 impl.mController->SetPlaceholderTextColor( textColor );
320 impl.mRenderer.Reset();
325 case Toolkit::TextField::Property::SHADOW_OFFSET:
327 if( impl.mController )
329 const Vector2 shadowOffset = value.Get< Vector2 >();
330 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
332 if ( impl.mController->GetShadowOffset() != shadowOffset )
334 impl.mController->SetShadowOffset( shadowOffset );
335 impl.mRenderer.Reset();
340 case Toolkit::TextField::Property::SHADOW_COLOR:
342 if( impl.mController )
344 const Vector4 shadowColor = value.Get< Vector4 >();
345 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 );
347 if ( impl.mController->GetShadowColor() != shadowColor )
349 impl.mController->SetShadowColor( shadowColor );
350 impl.mRenderer.Reset();
355 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
357 if( impl.mDecorator )
359 const Vector4 color = value.Get< Vector4 >();
360 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 );
362 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
363 impl.RequestTextRelayout();
367 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
369 if( impl.mDecorator )
371 const Vector4 color = value.Get< Vector4 >();
372 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 );
374 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
375 impl.RequestTextRelayout();
379 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
381 if( impl.mController )
383 const bool enable = value.Get< bool >();
384 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
386 impl.mController->SetEnableCursorBlink( enable );
387 impl.RequestTextRelayout();
391 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
393 if( impl.mDecorator )
395 const float interval = value.Get< float >();
396 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
398 impl.mDecorator->SetCursorBlinkInterval( interval );
402 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
404 if( impl.mDecorator )
406 const float duration = value.Get< float >();
407 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
409 impl.mDecorator->SetCursorBlinkDuration( duration );
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 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
462 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_LEFT %s\n", impl.mController.Get(), image.GetUrl().c_str() );
464 if( impl.mDecorator )
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 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
474 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_RIGHT %s\n", impl.mController.Get(), image.GetUrl().c_str() );
476 if( impl.mDecorator )
478 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
479 impl.RequestTextRelayout();
483 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
485 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
486 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_LEFT %s\n", impl.mController.Get(), image.GetUrl().c_str() );
488 if( impl.mDecorator )
490 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
491 impl.RequestTextRelayout();
495 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
497 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
498 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_RIGHT %s\n", impl.mController.Get(), image.GetUrl().c_str() );
500 if( impl.mDecorator )
502 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
503 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
509 const Vector4 color = value.Get< Vector4 >();
510 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 );
512 if( impl.mDecorator )
514 impl.mDecorator->SetHighlightColor( color );
515 impl.RequestTextRelayout();
519 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
521 if( impl.mDecorator )
523 const Rect<int> box = value.Get< Rect<int> >();
524 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 );
526 impl.mDecorator->SetBoundingBox( box );
527 impl.RequestTextRelayout();
531 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
533 const Property::Map map = value.Get<Property::Map>();
534 VirtualKeyboard::ApplySettings( map );
541 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
543 Property::Value value;
545 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
549 TextField& impl( GetImpl( textField ) );
553 case Toolkit::TextField::Property::RENDERING_BACKEND:
555 value = impl.mRenderingBackend;
558 case Toolkit::TextField::Property::TEXT:
560 if( impl.mController )
563 impl.mController->GetText( text );
564 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
569 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
571 if( impl.mController )
574 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
579 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
581 if( impl.mController )
584 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
589 case Toolkit::TextField::Property::FONT_FAMILY:
591 if( impl.mController )
593 value = impl.mController->GetDefaultFontFamily();
597 case Toolkit::TextField::Property::FONT_STYLE:
599 if( impl.mController )
601 value = impl.mController->GetDefaultFontStyle();
605 case Toolkit::TextField::Property::POINT_SIZE:
607 if( impl.mController )
609 value = impl.mController->GetDefaultPointSize();
613 case Toolkit::TextField::Property::MAX_LENGTH:
615 if( impl.mController )
617 value = impl.mController->GetMaximumNumberOfCharacters();
621 case Toolkit::TextField::Property::EXCEED_POLICY:
623 value = impl.mExceedPolicy;
626 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
628 if( impl.mController )
630 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
631 HORIZONTAL_ALIGNMENT_STRING_TABLE,
632 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
635 value = std::string( name );
640 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
642 if( impl.mController )
644 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
645 VERTICAL_ALIGNMENT_STRING_TABLE,
646 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
649 value = std::string( name );
654 case Toolkit::TextField::Property::TEXT_COLOR:
656 if ( impl.mController )
658 value = impl.mController->GetTextColor();
662 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
664 if ( impl.mController )
666 value = impl.mController->GetPlaceholderTextColor();
670 case Toolkit::TextField::Property::SHADOW_OFFSET:
672 if ( impl.mController )
674 value = impl.mController->GetShadowOffset();
678 case Toolkit::TextField::Property::SHADOW_COLOR:
680 if ( impl.mController )
682 value = impl.mController->GetShadowColor();
686 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
688 if( impl.mDecorator )
690 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
694 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
696 if( impl.mDecorator )
698 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
702 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
704 value = impl.mController->GetEnableCursorBlink();
707 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
709 if( impl.mDecorator )
711 value = impl.mDecorator->GetCursorBlinkInterval();
715 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
717 if( impl.mDecorator )
719 value = impl.mDecorator->GetCursorBlinkDuration();
723 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
725 if( impl.mDecorator )
727 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
730 value = image.GetUrl();
735 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
737 if( impl.mDecorator )
739 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
742 value = image.GetUrl();
747 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
749 if( impl.mDecorator )
751 value = impl.mDecorator->GetScrollThreshold();
755 case Toolkit::TextField::Property::SCROLL_SPEED:
757 if( impl.mDecorator )
759 value = impl.mDecorator->GetScrollSpeed();
763 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
765 if( impl.mDecorator )
767 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
770 value = image.GetUrl();
775 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
777 if( impl.mDecorator )
779 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
782 value = image.GetUrl();
787 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
789 if( impl.mDecorator )
791 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
794 value = image.GetUrl();
799 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
801 if( impl.mDecorator )
803 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
806 value = image.GetUrl();
811 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
813 if( impl.mDecorator )
815 value = impl.mDecorator->GetHighlightColor();
819 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
821 if( impl.mDecorator )
823 value = impl.mDecorator->GetBoundingBox();
827 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
837 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
839 Dali::BaseHandle handle( object );
841 bool connected( true );
842 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
844 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
846 field.TextChangedSignal().Connect( tracker, functor );
848 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
850 field.MaxLengthReachedSignal().Connect( tracker, functor );
854 // signalName does not match any signal
861 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
863 return mTextChangedSignal;
866 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
868 return mMaxLengthReachedSignal;
871 void TextField::OnInitialize()
875 mController = Text::Controller::New( *this );
877 mDecorator = Text::Decorator::New( *mController,
880 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
882 mController->EnableTextInput( mDecorator );
884 // Forward input events to controller
885 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) );
886 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
888 self.TouchedSignal().Connect( this, &TextField::OnTouched );
890 // Set BoundingBox to stage size if not already set.
891 if ( mDecorator->GetBoundingBox().IsEmpty() )
893 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
894 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
897 // Fill-parent area by default
898 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
899 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
900 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
903 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
905 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
908 Vector3 TextField::GetNaturalSize()
910 return mController->GetNaturalSize();
913 float TextField::GetHeightForWidth( float width )
915 return mController->GetHeightForWidth( width );
918 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
920 if( mController->Relayout( size ) ||
923 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
927 mDecorator->Relayout( size );
932 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
935 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
940 void TextField::RenderText()
943 Actor renderableActor;
946 renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
949 if( renderableActor != mRenderableActor )
951 UnparentAndReset( mRenderableActor );
952 mRenderableActor = renderableActor;
955 if( mRenderableActor )
957 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
959 mRenderableActor.SetPosition( offset.x, offset.y );
964 clipRootActor = mClipper->GetRootActor();
967 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
968 endIt = mClippingDecorationActors.end();
976 clipRootActor.Add( actor );
983 mClippingDecorationActors.clear();
985 // Make sure the actor is parented correctly with/without clipping
988 clipRootActor.Add( mRenderableActor );
992 self.Add( mRenderableActor );
997 void TextField::OnKeyInputFocusGained()
999 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1001 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1003 ImfManager imfManager = ImfManager::Get();
1007 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1009 // Notify that the text editing start.
1010 imfManager.Activate();
1012 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1013 imfManager.SetRestoreAfterFocusLost( true );
1016 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1020 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1023 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1025 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1028 void TextField::OnKeyInputFocusLost()
1030 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1032 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1034 ImfManager imfManager = ImfManager::Get();
1037 // The text editing is finished. Therefore the imf manager don't have restore activation.
1038 imfManager.SetRestoreAfterFocusLost( false );
1040 // Notify that the text editing finish.
1041 imfManager.Deactivate();
1043 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1046 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1050 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1053 mController->KeyboardFocusLostEvent();
1055 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1058 void TextField::OnTap( const TapGesture& gesture )
1060 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1062 // Show the keyboard if it was hidden.
1063 if (!VirtualKeyboard::IsVisible())
1065 VirtualKeyboard::Show();
1068 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1069 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1074 void TextField::OnPan( const PanGesture& gesture )
1076 mController->PanEvent( gesture.state, gesture.displacement );
1079 void TextField::OnLongPress( const LongPressGesture& gesture )
1081 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1084 bool TextField::OnKeyEvent( const KeyEvent& event )
1086 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1088 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1089 "Return" == event.keyPressedName ) // Make a Dali key code for this
1091 ClearKeyInputFocus();
1095 return mController->KeyEvent( event );
1098 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1104 mClippingDecorationActors.push_back( actor );
1108 Self().Add( actor );
1113 void TextField::RequestTextRelayout()
1118 void TextField::TextChanged()
1120 Dali::Toolkit::TextField handle( GetOwner() );
1121 mTextChangedSignal.Emit( handle );
1124 void TextField::OnStageConnect( Dali::Actor actor )
1126 if ( mHasBeenStaged )
1132 mHasBeenStaged = true;
1136 void TextField::MaxLengthReached()
1138 Dali::Toolkit::TextField handle( GetOwner() );
1139 mMaxLengthReachedSignal.Emit( handle );
1142 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1144 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1145 return mController->OnImfEvent( imfManager, imfEvent );
1148 void TextField::EnableClipping( bool clipping, const Vector2& size )
1152 // Not worth to created clip actor if width or height is equal to zero.
1153 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1157 Actor self = Self();
1159 mClipper = Clipper::New( size );
1160 self.Add( mClipper->GetRootActor() );
1161 self.Add( mClipper->GetImageActor() );
1163 else if ( mClipper )
1165 mClipper->Refresh( size );
1171 // Note - this will automatically remove the root & image actors
1176 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1178 mController->PasteClipboardItemEvent();
1181 void TextField::KeyboardStatusChanged(bool keyboardShown)
1183 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1185 // Just hide the grab handle when keyboard is hidden.
1186 if (!keyboardShown )
1188 mController->KeyboardFocusLostEvent();
1192 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1196 void TextField::OnStageConnection( int depth )
1198 // Call the Control::OnStageConnection() to set the depth of the background.
1199 Control::OnStageConnection( depth );
1201 // Sets the depth to the renderers inside the text's decorator.
1202 mDecorator->SetTextDepth( depth );
1204 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1207 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1212 TextField::TextField()
1213 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1214 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1215 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1216 mHasBeenStaged( false )
1220 TextField::~TextField()
1225 } // namespace Internal
1227 } // namespace Toolkit