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.
527 Property::Map map = value.Get<Property::Map>();
528 VirtualKeyboard::ApplySettings( map );
535 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
537 Property::Value value;
539 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
543 TextField& impl( GetImpl( textField ) );
547 case Toolkit::TextField::Property::RENDERING_BACKEND:
549 value = impl.mRenderingBackend;
552 case Toolkit::TextField::Property::TEXT:
554 if( impl.mController )
557 impl.mController->GetText( text );
558 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
563 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
565 if( impl.mController )
568 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
573 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
575 if( impl.mController )
578 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
583 case Toolkit::TextField::Property::EXCEED_POLICY:
585 value = impl.mExceedPolicy;
588 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
590 if( impl.mController )
592 value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
593 HORIZONTAL_ALIGNMENT_STRING_TABLE,
594 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
598 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
600 if( impl.mController )
602 value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
603 VERTICAL_ALIGNMENT_STRING_TABLE,
604 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
608 case Toolkit::TextField::Property::TEXT_COLOR:
610 if ( impl.mController )
612 value = impl.mController->GetTextColor();
616 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
618 if ( impl.mController )
620 value = impl.mController->GetPlaceholderTextColor();
624 case Toolkit::TextField::Property::SHADOW_OFFSET:
626 if ( impl.mController )
628 value = impl.mController->GetShadowOffset();
632 case Toolkit::TextField::Property::SHADOW_COLOR:
634 if ( impl.mController )
636 value = impl.mController->GetShadowColor();
640 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
642 if( impl.mDecorator )
644 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
648 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
650 if( impl.mDecorator )
652 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
656 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
658 value = impl.mController->GetEnableCursorBlink();
661 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
663 if( impl.mDecorator )
665 value = impl.mDecorator->GetCursorBlinkInterval();
669 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
671 if( impl.mDecorator )
673 value = impl.mDecorator->GetCursorBlinkDuration();
677 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
679 if( impl.mDecorator )
681 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
684 value = image.GetUrl();
689 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
691 if( impl.mDecorator )
693 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
696 value = image.GetUrl();
701 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
703 if( impl.mDecorator )
705 value = impl.mDecorator->GetScrollThreshold();
709 case Toolkit::TextField::Property::SCROLL_SPEED:
711 if( impl.mDecorator )
713 value = impl.mDecorator->GetScrollSpeed();
717 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
719 if( impl.mDecorator )
721 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
724 value = image.GetUrl();
729 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
731 if( impl.mDecorator )
733 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
736 value = image.GetUrl();
741 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
743 if( impl.mDecorator )
745 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
748 value = image.GetUrl();
753 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
755 if( impl.mDecorator )
757 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
760 value = image.GetUrl();
765 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
767 if( impl.mDecorator )
769 value = impl.mDecorator->GetHighlightColor();
773 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
775 if( impl.mDecorator )
777 value = impl.mDecorator->GetBoundingBox();
781 case Toolkit::TextField::Property::MAX_LENGTH:
783 if( impl.mController )
785 value = impl.mController->GetMaximumNumberOfCharacters();
789 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
799 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
801 Dali::BaseHandle handle( object );
803 bool connected( true );
804 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
806 if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
808 field.MaxLengthReachedSignal().Connect( tracker, functor );
812 // signalName does not match any signal
819 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
821 return mMaxLengthReachedSignal;
824 void TextField::OnInitialize()
828 mController = Text::Controller::New( *this );
830 mDecorator = Text::Decorator::New( *this, *mController );
832 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
834 mController->EnableTextInput( mDecorator );
836 // Forward input events to controller
837 EnableGestureDetection(Gesture::Tap);
838 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
839 EnableGestureDetection(Gesture::Pan);
841 self.TouchedSignal().Connect( this, &TextField::OnTouched );
843 // Set BoundingBox to stage size if not already set.
844 if ( mDecorator->GetBoundingBox().IsEmpty() )
846 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
847 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
850 // Fill-parent area by default
851 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
852 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
855 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
857 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
860 Vector3 TextField::GetNaturalSize()
862 return mController->GetNaturalSize();
865 float TextField::GetHeightForWidth( float width )
867 return mController->GetHeightForWidth( width );
870 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
872 if( mController->Relayout( size ) ||
875 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
879 mDecorator->Relayout( size );
884 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
887 RenderableActor renderableActor;
890 renderableActor = mRenderer->Render( mController->GetView() );
893 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
895 if( renderableActor != mRenderableActor )
897 UnparentAndReset( mRenderableActor );
898 mRenderableActor = renderableActor;
901 if( mRenderableActor )
903 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
905 mRenderableActor.SetPosition( offset.x, offset.y );
907 // Make sure the actor is parented correctly with/without clipping
910 mClipper->GetRootActor().Add( mRenderableActor );
914 Self().Add( mRenderableActor );
920 void TextField::OnKeyInputFocusGained()
922 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
924 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
926 ImfManager imfManager = ImfManager::Get();
930 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
932 // Notify that the text editing start.
933 imfManager.Activate();
935 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
936 imfManager.SetRestoreAfterFocusLost( true );
939 mController->KeyboardFocusGainEvent();
941 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
944 void TextField::OnKeyInputFocusLost()
946 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
948 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
950 ImfManager imfManager = ImfManager::Get();
953 // The text editing is finished. Therefore the imf manager don't have restore activation.
954 imfManager.SetRestoreAfterFocusLost( false );
956 // Notify that the text editing finish.
957 imfManager.Deactivate();
959 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
962 mController->KeyboardFocusLostEvent();
964 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
967 void TextField::OnTap( const TapGesture& gesture )
969 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
971 // Show the keyboard if it was hidden.
972 if (!VirtualKeyboard::IsVisible())
974 VirtualKeyboard::Show();
977 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
978 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
983 void TextField::OnPan( const PanGesture& gesture )
985 mController->PanEvent( gesture.state, gesture.displacement );
988 bool TextField::OnKeyEvent( const KeyEvent& event )
990 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
992 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
993 "Return" == event.keyPressedName ) // Make a Dali key code for this
995 ClearKeyInputFocus();
999 return mController->KeyEvent( event );
1002 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1004 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1006 bool update( false );
1009 unsigned int cursorPosition( 0 );
1011 switch ( imfEvent.eventName )
1013 case ImfManager::COMMIT:
1015 mController->InsertText( imfEvent.predictiveString, Text::Controller::COMMIT );
1018 case ImfManager::PREEDIT:
1020 mController->InsertText( imfEvent.predictiveString, Text::Controller::PRE_EDIT );
1024 case ImfManager::DELETESURROUNDING:
1026 mController->RemoveText( imfEvent.cursorOffset, imfEvent.numberOfChars );
1029 case ImfManager::GETSURROUNDING:
1031 mController->GetText( text );
1032 cursorPosition = mController->GetLogicalCursorPosition();
1034 imfManager.SetSurroundingText( text );
1035 imfManager.SetCursorPosition( cursorPosition );
1038 case ImfManager::VOID:
1045 if( ImfManager::GETSURROUNDING != imfEvent.eventName )
1047 mController->GetText( text );
1048 cursorPosition = mController->GetLogicalCursorPosition();
1051 ImfManager::ImfCallbackData callbackData( update, cursorPosition, text, false );
1053 return callbackData;
1056 void TextField::RequestTextRelayout()
1061 void TextField::MaxLengthReached()
1063 Dali::Toolkit::TextField handle( GetOwner() );
1064 mMaxLengthReachedSignal.Emit( handle );
1067 void TextField::EnableClipping( bool clipping, const Vector2& size )
1071 // Not worth to created clip actor if width or height is equal to zero.
1072 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1076 Actor self = Self();
1078 mClipper = Clipper::New( size );
1079 self.Add( mClipper->GetRootActor() );
1080 self.Add( mClipper->GetImageActor() );
1082 else if ( mClipper )
1084 mClipper->Refresh( size );
1090 // Note - this will automatically remove the root & image actors
1095 void TextField::KeyboardStatusChanged(bool keyboardShown)
1097 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1099 // Just hide the grab handle when keyboard is hidden.
1100 if (!keyboardShown )
1102 mController->KeyboardFocusLostEvent();
1106 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1111 TextField::TextField()
1112 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1113 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1114 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP )
1118 TextField::~TextField()
1123 } // namespace Internal
1125 } // namespace Toolkit