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/styling/style-manager-impl.h>
40 using namespace Dali::Toolkit::Text;
51 namespace // unnamed namespace
54 #if defined(DEBUG_ENABLED)
55 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
58 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
60 } // unnamed namespace
65 const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
67 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
68 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
69 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
71 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
73 const Scripting::StringEnum< Toolkit::Text::LayoutEngine::VerticalAlignment > VERTICAL_ALIGNMENT_STRING_TABLE[] =
75 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
76 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
77 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
79 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
84 return Toolkit::TextField::New();
87 // Setup properties, signals and actions using the type-registry.
88 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend", INTEGER, RENDERING_BACKEND )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text", STRING, PLACEHOLDER_TEXT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused", STRING, PLACEHOLDER_TEXT_FOCUSED )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family", STRING, FONT_FAMILY )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style", STRING, FONT_STYLE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size", FLOAT, POINT_SIZE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length", INTEGER, MAX_LENGTH )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy", INTEGER, EXCEED_POLICY )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color", VECTOR4, TEXT_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color", VECTOR4, PLACEHOLDER_TEXT_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset", VECTOR2, SHADOW_OFFSET )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color", VECTOR4, SHADOW_COLOR )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color", VECTOR4, PRIMARY_CURSOR_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color", VECTOR4, SECONDARY_CURSOR_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink", BOOLEAN, ENABLE_CURSOR_BLINK )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", VECTOR4, GRAB_HANDLE_PRESSED_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold", FLOAT, SCROLL_THRESHOLD )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed", FLOAT, SCROLL_SPEED )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", STRING, SELECTION_HANDLE_IMAGE_LEFT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right", STRING, SELECTION_HANDLE_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left", STRING, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", STRING, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", STRING, SELECTION_HIGHLIGHT_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings", MAP, INPUT_METHOD_SETTINGS )
122 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
124 DALI_TYPE_REGISTRATION_END()
128 Toolkit::TextField TextField::New()
130 // Create the implementation, temporarily owned by this handle on stack
131 IntrusivePtr< TextField > impl = new TextField();
133 // Pass ownership to CustomActor handle
134 Toolkit::TextField handle( *impl );
136 // Second-phase init of the implementation
137 // This can only be done after the CustomActor connection has been made...
143 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
145 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
149 TextField& impl( GetImpl( textField ) );
153 case Toolkit::TextField::Property::RENDERING_BACKEND:
155 int backend = value.Get< int >();
156 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
158 if( impl.mRenderingBackend != backend )
160 impl.mRenderingBackend = backend;
161 impl.mRenderer.Reset();
162 impl.RequestTextRelayout();
166 case Toolkit::TextField::Property::TEXT:
168 if( impl.mController )
170 const std::string text = value.Get< std::string >();
171 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
173 impl.mController->SetText( text );
177 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
179 if( impl.mController )
181 const std::string text = value.Get< std::string >();
182 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
184 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
188 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
190 if( impl.mController )
192 const std::string text = value.Get< std::string >();
193 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
195 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
199 case Toolkit::TextField::Property::FONT_FAMILY:
201 if( impl.mController )
203 const std::string fontFamily = value.Get< std::string >();
204 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
206 if( impl.mController->GetDefaultFontFamily() != fontFamily )
208 impl.mController->SetDefaultFontFamily( fontFamily );
213 case Toolkit::TextField::Property::FONT_STYLE:
215 if( impl.mController )
217 const std::string fontStyle = value.Get< std::string >();
218 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %s\n", impl.mController.Get(), fontStyle.c_str() );
220 if( impl.mController->GetDefaultFontStyle() != fontStyle )
222 impl.mController->SetDefaultFontStyle( fontStyle );
227 case Toolkit::TextField::Property::POINT_SIZE:
229 if( impl.mController )
231 const float pointSize = value.Get< float >();
232 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %f\n", impl.mController.Get(), pointSize );
234 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
236 impl.mController->SetDefaultPointSize( pointSize );
241 case Toolkit::TextField::Property::EXCEED_POLICY:
246 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
248 if( impl.mController )
250 const std::string alignStr = value.Get< std::string >();
251 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() );
253 const LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
254 HORIZONTAL_ALIGNMENT_STRING_TABLE,
255 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
257 impl.mController->SetHorizontalAlignment( alignment );
261 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
263 if( impl.mController )
265 const std::string alignStr = value.Get< std::string >();
266 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() );
268 LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
269 VERTICAL_ALIGNMENT_STRING_TABLE,
270 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
272 impl.mController->SetVerticalAlignment( alignment );
276 case Toolkit::TextField::Property::TEXT_COLOR:
278 if( impl.mController )
280 const Vector4 textColor = value.Get< Vector4 >();
281 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 );
283 if( impl.mController->GetTextColor() != textColor )
285 impl.mController->SetTextColor( textColor );
286 impl.mRenderer.Reset();
291 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
293 if( impl.mController )
295 const Vector4 textColor = value.Get< Vector4 >();
296 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 );
298 if( impl.mController->GetPlaceholderTextColor() != textColor )
300 impl.mController->SetPlaceholderTextColor( textColor );
301 impl.mRenderer.Reset();
306 case Toolkit::TextField::Property::SHADOW_OFFSET:
308 if( impl.mController )
310 const Vector2 shadowOffset = value.Get< Vector2 >();
311 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
313 if ( impl.mController->GetShadowOffset() != shadowOffset )
315 impl.mController->SetShadowOffset( shadowOffset );
316 impl.mRenderer.Reset();
321 case Toolkit::TextField::Property::SHADOW_COLOR:
323 if( impl.mController )
325 const Vector4 shadowColor = value.Get< Vector4 >();
326 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 );
328 if ( impl.mController->GetShadowColor() != shadowColor )
330 impl.mController->SetShadowColor( shadowColor );
331 impl.mRenderer.Reset();
336 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
338 if( impl.mDecorator )
340 const Vector4 color = value.Get< Vector4 >();
341 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
343 impl.mDecorator->SetColor( PRIMARY_CURSOR, color );
344 impl.RequestTextRelayout();
348 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
350 if( impl.mDecorator )
352 const Vector4 color = value.Get< Vector4 >();
353 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
355 impl.mDecorator->SetColor( SECONDARY_CURSOR, color );
356 impl.RequestTextRelayout();
360 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
362 if( impl.mController )
364 const bool enable = value.Get< bool >();
365 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
367 impl.mController->SetEnableCursorBlink( enable );
368 impl.RequestTextRelayout();
372 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
374 if( impl.mDecorator )
376 const float interval = value.Get< float >();
377 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
379 impl.mDecorator->SetCursorBlinkInterval( interval );
383 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
385 if( impl.mDecorator )
387 const float duration = value.Get< float >();
388 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), duration );
390 impl.mDecorator->SetCursorBlinkDuration( duration );
394 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
396 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
397 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
399 if( impl.mDecorator )
401 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
402 impl.RequestTextRelayout();
406 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
408 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
409 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
411 if( impl.mDecorator )
413 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
414 impl.RequestTextRelayout();
418 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
420 const float threshold = value.Get< float >();
421 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
423 if( impl.mDecorator )
425 impl.mDecorator->SetScrollThreshold( threshold );
429 case Toolkit::TextField::Property::SCROLL_SPEED:
431 const float speed = value.Get< float >();
432 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
434 if( impl.mDecorator )
436 impl.mDecorator->SetScrollSpeed( speed );
440 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
442 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_LEFT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
445 if( impl.mDecorator )
447 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
448 impl.RequestTextRelayout();
452 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
454 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_RIGHT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
457 if( impl.mDecorator )
459 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
460 impl.RequestTextRelayout();
464 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
466 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
467 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_LEFT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
469 if( impl.mDecorator )
471 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
472 impl.RequestTextRelayout();
476 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
478 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
479 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_RIGHT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
481 if( impl.mDecorator )
483 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
484 impl.RequestTextRelayout();
488 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
490 const Vector4 color = value.Get< Vector4 >();
491 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
493 if( impl.mDecorator )
495 impl.mDecorator->SetHighlightColor( color );
496 impl.RequestTextRelayout();
500 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
502 if( impl.mDecorator )
504 const Rect<int> box = value.Get< Rect<int> >();
505 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 );
507 impl.mDecorator->SetBoundingBox( box );
508 impl.RequestTextRelayout();
512 case Toolkit::TextField::Property::MAX_LENGTH:
514 if( impl.mController )
516 const int max = value.Get< int >();
517 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
519 impl.mController->SetMaximumNumberOfCharacters( max );
523 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
525 const Property::Map map = value.Get<Property::Map>();
526 VirtualKeyboard::ApplySettings( map );
533 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
535 Property::Value value;
537 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
541 TextField& impl( GetImpl( textField ) );
545 case Toolkit::TextField::Property::RENDERING_BACKEND:
547 value = impl.mRenderingBackend;
550 case Toolkit::TextField::Property::TEXT:
552 if( impl.mController )
555 impl.mController->GetText( text );
556 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
561 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
563 if( impl.mController )
566 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
571 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
573 if( impl.mController )
576 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
581 case Toolkit::TextField::Property::FONT_FAMILY:
583 if( impl.mController )
585 value = impl.mController->GetDefaultFontFamily();
589 case Toolkit::TextField::Property::FONT_STYLE:
591 if( impl.mController )
593 value = impl.mController->GetDefaultFontStyle();
597 case Toolkit::TextField::Property::POINT_SIZE:
599 if( impl.mController )
601 value = impl.mController->GetDefaultPointSize();
605 case Toolkit::TextField::Property::EXCEED_POLICY:
607 value = impl.mExceedPolicy;
610 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
612 if( impl.mController )
614 value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
615 HORIZONTAL_ALIGNMENT_STRING_TABLE,
616 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
620 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
622 if( impl.mController )
624 value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
625 VERTICAL_ALIGNMENT_STRING_TABLE,
626 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
630 case Toolkit::TextField::Property::TEXT_COLOR:
632 if ( impl.mController )
634 value = impl.mController->GetTextColor();
638 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
640 if ( impl.mController )
642 value = impl.mController->GetPlaceholderTextColor();
646 case Toolkit::TextField::Property::SHADOW_OFFSET:
648 if ( impl.mController )
650 value = impl.mController->GetShadowOffset();
654 case Toolkit::TextField::Property::SHADOW_COLOR:
656 if ( impl.mController )
658 value = impl.mController->GetShadowColor();
662 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
664 if( impl.mDecorator )
666 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
670 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
672 if( impl.mDecorator )
674 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
678 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
680 value = impl.mController->GetEnableCursorBlink();
683 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
685 if( impl.mDecorator )
687 value = impl.mDecorator->GetCursorBlinkInterval();
691 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
693 if( impl.mDecorator )
695 value = impl.mDecorator->GetCursorBlinkDuration();
699 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
701 if( impl.mDecorator )
703 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
706 value = image.GetUrl();
711 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
713 if( impl.mDecorator )
715 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
718 value = image.GetUrl();
723 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
725 if( impl.mDecorator )
727 value = impl.mDecorator->GetScrollThreshold();
731 case Toolkit::TextField::Property::SCROLL_SPEED:
733 if( impl.mDecorator )
735 value = impl.mDecorator->GetScrollSpeed();
739 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
741 if( impl.mDecorator )
743 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
746 value = image.GetUrl();
751 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
753 if( impl.mDecorator )
755 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
758 value = image.GetUrl();
763 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
765 if( impl.mDecorator )
767 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
770 value = image.GetUrl();
775 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
777 if( impl.mDecorator )
779 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
782 value = image.GetUrl();
787 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
789 if( impl.mDecorator )
791 value = impl.mDecorator->GetHighlightColor();
795 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
797 if( impl.mDecorator )
799 value = impl.mDecorator->GetBoundingBox();
803 case Toolkit::TextField::Property::MAX_LENGTH:
805 if( impl.mController )
807 value = impl.mController->GetMaximumNumberOfCharacters();
811 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
821 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
823 Dali::BaseHandle handle( object );
825 bool connected( true );
826 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
828 if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
830 field.MaxLengthReachedSignal().Connect( tracker, functor );
834 // signalName does not match any signal
841 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
843 return mMaxLengthReachedSignal;
846 void TextField::OnInitialize()
850 mController = Text::Controller::New( *this );
852 mDecorator = Text::Decorator::New( *this, *mController );
854 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
856 mController->EnableTextInput( mDecorator );
858 // Forward input events to controller
859 EnableGestureDetection(Gesture::Tap);
860 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
861 EnableGestureDetection(Gesture::Pan);
863 self.TouchedSignal().Connect( this, &TextField::OnTouched );
865 // Set BoundingBox to stage size if not already set.
866 if ( mDecorator->GetBoundingBox().IsEmpty() )
868 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
869 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
872 // Fill-parent area by default
873 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
874 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
877 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
879 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
882 Vector3 TextField::GetNaturalSize()
884 return mController->GetNaturalSize();
887 float TextField::GetHeightForWidth( float width )
889 return mController->GetHeightForWidth( width );
892 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
894 if( mController->Relayout( size ) ||
897 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
901 mDecorator->Relayout( size );
906 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
909 RenderableActor renderableActor;
912 renderableActor = mRenderer->Render( mController->GetView() );
915 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
917 if( renderableActor != mRenderableActor )
919 UnparentAndReset( mRenderableActor );
920 mRenderableActor = renderableActor;
923 if( mRenderableActor )
925 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
927 mRenderableActor.SetPosition( offset.x, offset.y );
929 // Make sure the actor is parented correctly with/without clipping
932 mClipper->GetRootActor().Add( mRenderableActor );
936 Self().Add( mRenderableActor );
942 void TextField::OnKeyInputFocusGained()
944 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
946 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
948 ImfManager imfManager = ImfManager::Get();
952 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
954 // Notify that the text editing start.
955 imfManager.Activate();
957 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
958 imfManager.SetRestoreAfterFocusLost( true );
961 mController->KeyboardFocusGainEvent();
963 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
966 void TextField::OnKeyInputFocusLost()
968 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
970 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
972 ImfManager imfManager = ImfManager::Get();
975 // The text editing is finished. Therefore the imf manager don't have restore activation.
976 imfManager.SetRestoreAfterFocusLost( false );
978 // Notify that the text editing finish.
979 imfManager.Deactivate();
981 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
984 mController->KeyboardFocusLostEvent();
986 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
989 void TextField::OnTap( const TapGesture& gesture )
991 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
993 // Show the keyboard if it was hidden.
994 if (!VirtualKeyboard::IsVisible())
996 VirtualKeyboard::Show();
999 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1000 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1005 void TextField::OnPan( const PanGesture& gesture )
1007 mController->PanEvent( gesture.state, gesture.displacement );
1010 bool TextField::OnKeyEvent( const KeyEvent& event )
1012 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1014 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1015 "Return" == event.keyPressedName ) // Make a Dali key code for this
1017 ClearKeyInputFocus();
1021 return mController->KeyEvent( event );
1024 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1026 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1027 return mController->OnImfEvent( imfManager, imfEvent );
1030 void TextField::RequestTextRelayout()
1035 void TextField::MaxLengthReached()
1037 Dali::Toolkit::TextField handle( GetOwner() );
1038 mMaxLengthReachedSignal.Emit( handle );
1041 void TextField::EnableClipping( bool clipping, const Vector2& size )
1045 // Not worth to created clip actor if width or height is equal to zero.
1046 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1050 Actor self = Self();
1052 mClipper = Clipper::New( size );
1053 self.Add( mClipper->GetRootActor() );
1054 self.Add( mClipper->GetImageActor() );
1056 else if ( mClipper )
1058 mClipper->Refresh( size );
1064 // Note - this will automatically remove the root & image actors
1069 void TextField::KeyboardStatusChanged(bool keyboardShown)
1071 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1073 // Just hide the grab handle when keyboard is hidden.
1074 if (!keyboardShown )
1076 mController->KeyboardFocusLostEvent();
1080 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1085 TextField::TextField()
1086 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1087 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1088 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP )
1092 TextField::~TextField()
1097 } // namespace Internal
1099 } // namespace Toolkit