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();
165 case Toolkit::TextField::Property::TEXT:
167 if( impl.mController )
169 std::string text = value.Get< std::string >();
170 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
172 impl.mController->SetText( text );
176 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
178 if( impl.mController )
180 std::string text = value.Get< std::string >();
181 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
183 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
187 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
189 if( impl.mController )
191 std::string text = value.Get< std::string >();
192 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
194 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
198 case Toolkit::TextField::Property::FONT_FAMILY:
200 if( impl.mController )
202 std::string fontFamily = value.Get< std::string >();
203 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
205 if( impl.mController->GetDefaultFontFamily() != fontFamily )
207 impl.mController->SetDefaultFontFamily( fontFamily );
208 impl.RequestTextRelayout();
213 case Toolkit::TextField::Property::FONT_STYLE:
215 if( impl.mController )
217 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 );
223 impl.RequestTextRelayout();
228 case Toolkit::TextField::Property::POINT_SIZE:
230 if( impl.mController )
232 float pointSize = value.Get< float >();
233 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %f\n", impl.mController.Get(), pointSize );
235 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
237 impl.mController->SetDefaultPointSize( pointSize );
238 impl.RequestTextRelayout();
243 case Toolkit::TextField::Property::EXCEED_POLICY:
248 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
250 if( impl.mController )
252 std::string alignStr = value.Get< std::string >();
253 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() );
255 LayoutEngine& engine = impl.mController->GetLayoutEngine();
256 LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
257 HORIZONTAL_ALIGNMENT_STRING_TABLE,
258 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
260 if( engine.GetHorizontalAlignment() != alignment )
262 engine.SetHorizontalAlignment( alignment );
263 impl.RequestTextRelayout();
268 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
270 if( impl.mController )
272 std::string alignStr = value.Get< std::string >();
273 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() );
275 LayoutEngine& engine = impl.mController->GetLayoutEngine();
276 LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
277 VERTICAL_ALIGNMENT_STRING_TABLE,
278 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
280 if( engine.GetVerticalAlignment() != alignment )
282 engine.SetVerticalAlignment( alignment );
283 impl.RequestTextRelayout();
288 case Toolkit::TextField::Property::TEXT_COLOR:
290 if ( impl.mController )
292 Vector4 textColor = value.Get< Vector4 >();
293 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 );
295 if ( impl.mController->GetTextColor() != textColor )
297 impl.mController->SetTextColor( textColor );
298 impl.RequestTextRelayout();
303 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
305 if ( impl.mController )
307 Vector4 textColor = value.Get< Vector4 >();
308 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 );
310 if ( impl.mController->GetPlaceholderTextColor() != textColor )
312 impl.mController->SetPlaceholderTextColor( textColor );
313 impl.RequestTextRelayout();
318 case Toolkit::TextField::Property::SHADOW_OFFSET:
320 if( impl.mController )
322 Vector2 shadowOffset = value.Get< Vector2 >();
323 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
325 if ( impl.mController->GetShadowOffset() != shadowOffset )
327 impl.mController->SetShadowOffset( shadowOffset );
328 impl.RequestTextRelayout();
333 case Toolkit::TextField::Property::SHADOW_COLOR:
335 if( impl.mController )
337 Vector4 shadowColor = value.Get< Vector4 >();
338 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 );
340 if ( impl.mController->GetShadowColor() != shadowColor )
342 impl.mController->SetShadowColor( shadowColor );
343 impl.RequestTextRelayout();
348 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
350 if( impl.mDecorator )
352 Vector4 color = value.Get< Vector4 >();
353 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 );
355 impl.mDecorator->SetColor( PRIMARY_CURSOR, color );
359 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
361 if( impl.mDecorator )
363 Vector4 color = value.Get< Vector4 >();
364 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 );
366 impl.mDecorator->SetColor( SECONDARY_CURSOR, color );
370 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
372 if( impl.mController )
374 bool enable = value.Get< bool >();
375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
377 impl.mController->SetEnableCursorBlink( enable );
381 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
383 if( impl.mDecorator )
385 float interval = value.Get< float >();
386 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
388 impl.mDecorator->SetCursorBlinkInterval( interval );
392 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
394 if( impl.mDecorator )
396 float duration = value.Get< float >();
397 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), duration );
399 impl.mDecorator->SetCursorBlinkDuration( duration );
403 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
405 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
406 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
408 if( impl.mDecorator )
410 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
414 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
416 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
417 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
419 if( impl.mDecorator )
421 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
425 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
427 float threshold = value.Get< float >();
428 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
430 if( impl.mDecorator )
432 impl.mDecorator->SetScrollThreshold( threshold );
436 case Toolkit::TextField::Property::SCROLL_SPEED:
438 float speed = value.Get< float >();
439 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
441 if( impl.mDecorator )
443 impl.mDecorator->SetScrollSpeed( speed );
447 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
449 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
450 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_LEFT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
452 if( impl.mDecorator )
454 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
458 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
460 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
461 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_RIGHT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
463 if( impl.mDecorator )
465 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
469 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
471 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
472 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_LEFT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
474 if( impl.mDecorator )
476 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
480 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
482 ResourceImage image = ResourceImage::New( value.Get< std::string >() );
483 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_RIGHT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
485 if( impl.mDecorator )
487 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
491 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
493 Vector4 color = value.Get< Vector4 >();
494 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 );
496 if( impl.mDecorator )
498 impl.mDecorator->SetHighlightColor( color );
502 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
504 if( impl.mDecorator )
506 Rect<int> box = value.Get< Rect<int> >();
507 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 );
509 impl.mDecorator->SetBoundingBox( box );
513 case Toolkit::TextField::Property::MAX_LENGTH:
515 if( impl.mController )
517 int max = value.Get< int >();
518 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
520 impl.mController->SetMaximumNumberOfCharacters( max );
524 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
526 // Empty implementation for now.
534 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
536 Property::Value value;
538 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
542 TextField& impl( GetImpl( textField ) );
546 case Toolkit::TextField::Property::RENDERING_BACKEND:
548 value = impl.mRenderingBackend;
551 case Toolkit::TextField::Property::TEXT:
553 if( impl.mController )
556 impl.mController->GetText( text );
557 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
562 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
564 if( impl.mController )
567 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
572 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
574 if( impl.mController )
577 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
582 case Toolkit::TextField::Property::EXCEED_POLICY:
584 value = impl.mExceedPolicy;
587 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
589 if( impl.mController )
591 value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
592 HORIZONTAL_ALIGNMENT_STRING_TABLE,
593 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
597 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
599 if( impl.mController )
601 value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
602 VERTICAL_ALIGNMENT_STRING_TABLE,
603 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
607 case Toolkit::TextField::Property::TEXT_COLOR:
609 if ( impl.mController )
611 value = impl.mController->GetTextColor();
615 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
617 if ( impl.mController )
619 value = impl.mController->GetPlaceholderTextColor();
623 case Toolkit::TextField::Property::SHADOW_OFFSET:
625 if ( impl.mController )
627 value = impl.mController->GetShadowOffset();
631 case Toolkit::TextField::Property::SHADOW_COLOR:
633 if ( impl.mController )
635 value = impl.mController->GetShadowColor();
639 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
641 if( impl.mDecorator )
643 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
647 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
649 if( impl.mDecorator )
651 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
655 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
657 value = impl.mController->GetEnableCursorBlink();
660 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
662 if( impl.mDecorator )
664 value = impl.mDecorator->GetCursorBlinkInterval();
668 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
670 if( impl.mDecorator )
672 value = impl.mDecorator->GetCursorBlinkDuration();
676 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
678 if( impl.mDecorator )
680 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
683 value = image.GetUrl();
688 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
690 if( impl.mDecorator )
692 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
695 value = image.GetUrl();
700 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
702 if( impl.mDecorator )
704 value = impl.mDecorator->GetScrollThreshold();
708 case Toolkit::TextField::Property::SCROLL_SPEED:
710 if( impl.mDecorator )
712 value = impl.mDecorator->GetScrollSpeed();
716 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
718 if( impl.mDecorator )
720 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
723 value = image.GetUrl();
728 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
730 if( impl.mDecorator )
732 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
735 value = image.GetUrl();
740 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
742 if( impl.mDecorator )
744 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
747 value = image.GetUrl();
752 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
754 if( impl.mDecorator )
756 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
759 value = image.GetUrl();
764 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
766 if( impl.mDecorator )
768 value = impl.mDecorator->GetHighlightColor();
772 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
774 if( impl.mDecorator )
776 value = impl.mDecorator->GetBoundingBox();
780 case Toolkit::TextField::Property::MAX_LENGTH:
782 if( impl.mController )
784 value = impl.mController->GetMaximumNumberOfCharacters();
794 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
796 Dali::BaseHandle handle( object );
798 bool connected( true );
799 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
801 if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
803 field.MaxLengthReachedSignal().Connect( tracker, functor );
807 // signalName does not match any signal
814 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
816 return mMaxLengthReachedSignal;
819 void TextField::OnInitialize()
823 mController = Text::Controller::New( *this );
825 mDecorator = Text::Decorator::New( *this, *mController );
827 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
829 mController->EnableTextInput( mDecorator );
831 // Forward input events to controller
832 EnableGestureDetection(Gesture::Tap);
833 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
834 EnableGestureDetection(Gesture::Pan);
836 // Set BoundingBox to stage size if not already set.
837 if ( mDecorator->GetBoundingBox().IsEmpty() )
839 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
840 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
843 // Fill-parent area by default
844 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
845 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
848 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
850 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
853 Vector3 TextField::GetNaturalSize()
855 return mController->GetNaturalSize();
858 float TextField::GetHeightForWidth( float width )
860 return mController->GetHeightForWidth( width );
863 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
865 if( mController->Relayout( size ) ||
868 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
872 mDecorator->Relayout( size );
877 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
880 RenderableActor renderableActor;
883 renderableActor = mRenderer->Render( mController->GetView() );
886 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
888 if( renderableActor != mRenderableActor )
890 UnparentAndReset( mRenderableActor );
891 mRenderableActor = renderableActor;
894 if( mRenderableActor )
896 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
898 mRenderableActor.SetPosition( offset.x, offset.y );
900 // Make sure the actor is parented correctly with/without clipping
903 mClipper->GetRootActor().Add( mRenderableActor );
907 Self().Add( mRenderableActor );
913 void TextField::OnKeyInputFocusGained()
915 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
917 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
919 ImfManager imfManager = ImfManager::Get();
923 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
925 // Notify that the text editing start.
926 imfManager.Activate();
928 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
929 imfManager.SetRestoreAfterFocusLost( true );
932 mController->KeyboardFocusGainEvent();
934 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
937 void TextField::OnKeyInputFocusLost()
939 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
941 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
943 ImfManager imfManager = ImfManager::Get();
946 // The text editing is finished. Therefore the imf manager don't have restore activation.
947 imfManager.SetRestoreAfterFocusLost( false );
949 // Notify that the text editing finish.
950 imfManager.Deactivate();
952 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
955 mController->KeyboardFocusLostEvent();
957 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
960 void TextField::OnTap( const TapGesture& gesture )
962 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
964 // Show the keyboard if it was hidden.
965 if (!VirtualKeyboard::IsVisible())
967 VirtualKeyboard::Show();
970 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
971 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
976 void TextField::OnPan( const PanGesture& gesture )
978 mController->PanEvent( gesture.state, gesture.displacement );
981 bool TextField::OnKeyEvent( const KeyEvent& event )
983 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
985 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
986 "Return" == event.keyPressedName ) // Make a Dali key code for this
988 ClearKeyInputFocus();
992 return mController->KeyEvent( event );
995 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
997 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
999 bool update( false );
1002 unsigned int cursorPosition( 0 );
1004 switch ( imfEvent.eventName )
1006 case ImfManager::COMMIT:
1008 mController->InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
1011 case ImfManager::PREEDIT:
1013 mController->InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
1017 case ImfManager::DELETESURROUNDING:
1019 mController->RemoveText( imfEvent.cursorOffset, imfEvent.numberOfChars );
1022 case ImfManager::GETSURROUNDING:
1024 mController->GetText( text );
1025 cursorPosition = mController->GetLogicalCursorPosition();
1027 imfManager.SetSurroundingText( text );
1028 imfManager.SetCursorPosition( cursorPosition );
1031 case ImfManager::VOID:
1038 if( ImfManager::GETSURROUNDING != imfEvent.eventName )
1040 mController->GetText( text );
1041 cursorPosition = mController->GetLogicalCursorPosition();
1044 ImfManager::ImfCallbackData callbackData( update, cursorPosition, text, false );
1046 return callbackData;
1049 void TextField::RequestTextRelayout()
1054 void TextField::MaxLengthReached()
1056 Dali::Toolkit::TextField handle( GetOwner() );
1057 mMaxLengthReachedSignal.Emit( handle );
1060 void TextField::EnableClipping( bool clipping, const Vector2& size )
1064 // Not worth to created clip actor if width or height is equal to zero.
1065 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1069 Actor self = Self();
1071 mClipper = Clipper::New( size );
1072 self.Add( mClipper->GetRootActor() );
1073 self.Add( mClipper->GetImageActor() );
1075 else if ( mClipper )
1077 mClipper->Refresh( size );
1083 // Note - this will automatically remove the root & image actors
1088 void TextField::KeyboardStatusChanged(bool keyboardShown)
1090 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1092 // Just hide the grab handle when keyboard is hidden.
1093 if (!keyboardShown )
1095 mController->KeyboardFocusLostEvent();
1099 TextField::TextField()
1100 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1101 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1102 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP )
1106 TextField::~TextField()
1111 } // namespace Internal
1113 } // namespace Toolkit