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 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 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, "text-changed", SIGNAL_TEXT_CHANGED )
123 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
125 DALI_TYPE_REGISTRATION_END()
129 Toolkit::TextField TextField::New()
131 // Create the implementation, temporarily owned by this handle on stack
132 IntrusivePtr< TextField > impl = new TextField();
134 // Pass ownership to CustomActor handle
135 Toolkit::TextField handle( *impl );
137 // Second-phase init of the implementation
138 // This can only be done after the CustomActor connection has been made...
144 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
146 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
150 TextField& impl( GetImpl( textField ) );
154 case Toolkit::TextField::Property::RENDERING_BACKEND:
156 int backend = value.Get< int >();
157 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
159 if( impl.mRenderingBackend != backend )
161 impl.mRenderingBackend = backend;
162 impl.mRenderer.Reset();
163 impl.RequestTextRelayout();
167 case Toolkit::TextField::Property::TEXT:
169 if( impl.mController )
171 const std::string text = value.Get< std::string >();
172 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
174 impl.mController->SetText( text );
178 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
180 if( impl.mController )
182 const std::string text = value.Get< std::string >();
183 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
185 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
189 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
191 if( impl.mController )
193 const std::string text = value.Get< std::string >();
194 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
196 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
200 case Toolkit::TextField::Property::FONT_FAMILY:
202 if( impl.mController )
204 const std::string fontFamily = value.Get< std::string >();
205 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
207 if( impl.mController->GetDefaultFontFamily() != fontFamily )
209 impl.mController->SetDefaultFontFamily( fontFamily );
214 case Toolkit::TextField::Property::FONT_STYLE:
216 if( impl.mController )
218 const std::string fontStyle = value.Get< std::string >();
219 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %s\n", impl.mController.Get(), fontStyle.c_str() );
221 if( impl.mController->GetDefaultFontStyle() != fontStyle )
223 impl.mController->SetDefaultFontStyle( fontStyle );
228 case Toolkit::TextField::Property::POINT_SIZE:
230 if( impl.mController )
232 const 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 );
242 case Toolkit::TextField::Property::EXCEED_POLICY:
247 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
249 if( impl.mController )
251 const std::string alignStr = value.Get< std::string >();
252 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() );
254 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
255 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
256 HORIZONTAL_ALIGNMENT_STRING_TABLE,
257 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
260 impl.mController->SetHorizontalAlignment( alignment );
265 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
267 if( impl.mController )
269 const std::string alignStr = value.Get< std::string >();
270 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %f\n", impl.mController.Get(), alignStr.c_str() );
272 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
273 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
274 VERTICAL_ALIGNMENT_STRING_TABLE,
275 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
278 impl.mController->SetVerticalAlignment( alignment );
283 case Toolkit::TextField::Property::TEXT_COLOR:
285 if( impl.mController )
287 const Vector4 textColor = value.Get< Vector4 >();
288 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 );
290 if( impl.mController->GetTextColor() != textColor )
292 impl.mController->SetTextColor( textColor );
293 impl.mRenderer.Reset();
298 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
300 if( impl.mController )
302 const Vector4 textColor = value.Get< Vector4 >();
303 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 );
305 if( impl.mController->GetPlaceholderTextColor() != textColor )
307 impl.mController->SetPlaceholderTextColor( textColor );
308 impl.mRenderer.Reset();
313 case Toolkit::TextField::Property::SHADOW_OFFSET:
315 if( impl.mController )
317 const Vector2 shadowOffset = value.Get< Vector2 >();
318 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
320 if ( impl.mController->GetShadowOffset() != shadowOffset )
322 impl.mController->SetShadowOffset( shadowOffset );
323 impl.mRenderer.Reset();
328 case Toolkit::TextField::Property::SHADOW_COLOR:
330 if( impl.mController )
332 const Vector4 shadowColor = value.Get< Vector4 >();
333 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 );
335 if ( impl.mController->GetShadowColor() != shadowColor )
337 impl.mController->SetShadowColor( shadowColor );
338 impl.mRenderer.Reset();
343 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
345 if( impl.mDecorator )
347 const Vector4 color = value.Get< Vector4 >();
348 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 );
350 impl.mDecorator->SetColor( PRIMARY_CURSOR, color );
351 impl.RequestTextRelayout();
355 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
357 if( impl.mDecorator )
359 const Vector4 color = value.Get< Vector4 >();
360 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 );
362 impl.mDecorator->SetColor( SECONDARY_CURSOR, color );
363 impl.RequestTextRelayout();
367 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
369 if( impl.mController )
371 const bool enable = value.Get< bool >();
372 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
374 impl.mController->SetEnableCursorBlink( enable );
375 impl.RequestTextRelayout();
379 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
381 if( impl.mDecorator )
383 const float interval = value.Get< float >();
384 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
386 impl.mDecorator->SetCursorBlinkInterval( interval );
390 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
392 if( impl.mDecorator )
394 const float duration = value.Get< float >();
395 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), duration );
397 impl.mDecorator->SetCursorBlinkDuration( duration );
401 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
403 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
404 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
406 if( impl.mDecorator )
408 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
409 impl.RequestTextRelayout();
413 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
415 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
416 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
418 if( impl.mDecorator )
420 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
421 impl.RequestTextRelayout();
425 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
427 const 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 const 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 const 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 );
455 impl.RequestTextRelayout();
459 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
461 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
462 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_IMAGE_RIGHT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
464 if( impl.mDecorator )
466 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
467 impl.RequestTextRelayout();
471 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
473 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
474 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_LEFT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
476 if( impl.mDecorator )
478 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
479 impl.RequestTextRelayout();
483 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
485 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
486 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SELECTION_HANDLE_PRESSED_IMAGE_RIGHT %f\n", impl.mController.Get(), image.GetUrl().c_str() );
488 if( impl.mDecorator )
490 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
491 impl.RequestTextRelayout();
495 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
497 const Vector4 color = value.Get< Vector4 >();
498 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 );
500 if( impl.mDecorator )
502 impl.mDecorator->SetHighlightColor( color );
503 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
509 if( impl.mDecorator )
511 const Rect<int> box = value.Get< Rect<int> >();
512 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 );
514 impl.mDecorator->SetBoundingBox( box );
515 impl.RequestTextRelayout();
519 case Toolkit::TextField::Property::MAX_LENGTH:
521 if( impl.mController )
523 const int max = value.Get< int >();
524 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
526 impl.mController->SetMaximumNumberOfCharacters( max );
530 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
532 const Property::Map map = value.Get<Property::Map>();
533 VirtualKeyboard::ApplySettings( map );
540 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
542 Property::Value value;
544 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
548 TextField& impl( GetImpl( textField ) );
552 case Toolkit::TextField::Property::RENDERING_BACKEND:
554 value = impl.mRenderingBackend;
557 case Toolkit::TextField::Property::TEXT:
559 if( impl.mController )
562 impl.mController->GetText( text );
563 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
568 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
570 if( impl.mController )
573 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
578 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
580 if( impl.mController )
583 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
588 case Toolkit::TextField::Property::FONT_FAMILY:
590 if( impl.mController )
592 value = impl.mController->GetDefaultFontFamily();
596 case Toolkit::TextField::Property::FONT_STYLE:
598 if( impl.mController )
600 value = impl.mController->GetDefaultFontStyle();
604 case Toolkit::TextField::Property::POINT_SIZE:
606 if( impl.mController )
608 value = impl.mController->GetDefaultPointSize();
612 case Toolkit::TextField::Property::EXCEED_POLICY:
614 value = impl.mExceedPolicy;
617 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
619 if( impl.mController )
621 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
622 HORIZONTAL_ALIGNMENT_STRING_TABLE,
623 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
626 value = std::string( name );
631 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
633 if( impl.mController )
635 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
636 VERTICAL_ALIGNMENT_STRING_TABLE,
637 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
640 value = std::string( name );
645 case Toolkit::TextField::Property::TEXT_COLOR:
647 if ( impl.mController )
649 value = impl.mController->GetTextColor();
653 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
655 if ( impl.mController )
657 value = impl.mController->GetPlaceholderTextColor();
661 case Toolkit::TextField::Property::SHADOW_OFFSET:
663 if ( impl.mController )
665 value = impl.mController->GetShadowOffset();
669 case Toolkit::TextField::Property::SHADOW_COLOR:
671 if ( impl.mController )
673 value = impl.mController->GetShadowColor();
677 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
679 if( impl.mDecorator )
681 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
685 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
687 if( impl.mDecorator )
689 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
693 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
695 value = impl.mController->GetEnableCursorBlink();
698 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
700 if( impl.mDecorator )
702 value = impl.mDecorator->GetCursorBlinkInterval();
706 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
708 if( impl.mDecorator )
710 value = impl.mDecorator->GetCursorBlinkDuration();
714 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
716 if( impl.mDecorator )
718 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
721 value = image.GetUrl();
726 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
728 if( impl.mDecorator )
730 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
733 value = image.GetUrl();
738 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
740 if( impl.mDecorator )
742 value = impl.mDecorator->GetScrollThreshold();
746 case Toolkit::TextField::Property::SCROLL_SPEED:
748 if( impl.mDecorator )
750 value = impl.mDecorator->GetScrollSpeed();
754 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
756 if( impl.mDecorator )
758 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
761 value = image.GetUrl();
766 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
768 if( impl.mDecorator )
770 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) );
773 value = image.GetUrl();
778 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
780 if( impl.mDecorator )
782 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
785 value = image.GetUrl();
790 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
792 if( impl.mDecorator )
794 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED ) );
797 value = image.GetUrl();
802 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
804 if( impl.mDecorator )
806 value = impl.mDecorator->GetHighlightColor();
810 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
812 if( impl.mDecorator )
814 value = impl.mDecorator->GetBoundingBox();
818 case Toolkit::TextField::Property::MAX_LENGTH:
820 if( impl.mController )
822 value = impl.mController->GetMaximumNumberOfCharacters();
826 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
836 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
838 Dali::BaseHandle handle( object );
840 bool connected( true );
841 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
843 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
845 field.TextChangedSignal().Connect( tracker, functor );
847 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
849 field.MaxLengthReachedSignal().Connect( tracker, functor );
853 // signalName does not match any signal
860 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
862 return mTextChangedSignal;
865 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
867 return mMaxLengthReachedSignal;
870 void TextField::OnInitialize()
874 mController = Text::Controller::New( *this );
876 mDecorator = Text::Decorator::New( *mController );
878 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
880 mController->EnableTextInput( mDecorator );
882 // Forward input events to controller
883 EnableGestureDetection(Gesture::Tap);
884 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
885 EnableGestureDetection(Gesture::Pan);
887 self.TouchedSignal().Connect( this, &TextField::OnTouched );
889 // Set BoundingBox to stage size if not already set.
890 if ( mDecorator->GetBoundingBox().IsEmpty() )
892 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
893 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
896 // Fill-parent area by default
897 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
898 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
901 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
903 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
906 Vector3 TextField::GetNaturalSize()
908 return mController->GetNaturalSize();
911 float TextField::GetHeightForWidth( float width )
913 return mController->GetHeightForWidth( width );
916 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
918 if( mController->Relayout( size ) ||
921 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
925 mDecorator->Relayout( size );
930 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
933 RenderableActor renderableActor;
936 renderableActor = mRenderer->Render( mController->GetView() );
939 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
941 if( renderableActor != mRenderableActor )
943 UnparentAndReset( mRenderableActor );
944 mRenderableActor = renderableActor;
947 if( mRenderableActor )
949 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
951 mRenderableActor.SetPosition( offset.x, offset.y );
953 // Make sure the actor is parented correctly with/without clipping
956 mClipper->GetRootActor().Add( mRenderableActor );
960 Self().Add( mRenderableActor );
964 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
965 endIt = mClippingDecorationActors.end();
973 mClipper->GetRootActor().Add( actor );
980 mClippingDecorationActors.clear();
984 void TextField::OnKeyInputFocusGained()
986 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
988 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
990 ImfManager imfManager = ImfManager::Get();
994 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
996 // Notify that the text editing start.
997 imfManager.Activate();
999 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1000 imfManager.SetRestoreAfterFocusLost( true );
1003 mController->KeyboardFocusGainEvent();
1005 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1008 void TextField::OnKeyInputFocusLost()
1010 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1012 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1014 ImfManager imfManager = ImfManager::Get();
1017 // The text editing is finished. Therefore the imf manager don't have restore activation.
1018 imfManager.SetRestoreAfterFocusLost( false );
1020 // Notify that the text editing finish.
1021 imfManager.Deactivate();
1023 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1026 mController->KeyboardFocusLostEvent();
1028 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1031 void TextField::OnTap( const TapGesture& gesture )
1033 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1035 // Show the keyboard if it was hidden.
1036 if (!VirtualKeyboard::IsVisible())
1038 VirtualKeyboard::Show();
1041 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1042 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1047 void TextField::OnPan( const PanGesture& gesture )
1049 mController->PanEvent( gesture.state, gesture.displacement );
1052 bool TextField::OnKeyEvent( const KeyEvent& event )
1054 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1056 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1057 "Return" == event.keyPressedName ) // Make a Dali key code for this
1059 ClearKeyInputFocus();
1063 return mController->KeyEvent( event );
1066 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1072 mClippingDecorationActors.push_back( actor );
1076 Self().Add( actor );
1081 void TextField::RequestTextRelayout()
1086 void TextField::TextChanged()
1088 Dali::Toolkit::TextField handle( GetOwner() );
1089 mTextChangedSignal.Emit( handle );
1092 void TextField::MaxLengthReached()
1094 Dali::Toolkit::TextField handle( GetOwner() );
1095 mMaxLengthReachedSignal.Emit( handle );
1098 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1100 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1101 return mController->OnImfEvent( imfManager, imfEvent );
1104 void TextField::EnableClipping( bool clipping, const Vector2& size )
1108 // Not worth to created clip actor if width or height is equal to zero.
1109 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1113 Actor self = Self();
1115 mClipper = Clipper::New( size );
1116 self.Add( mClipper->GetRootActor() );
1117 self.Add( mClipper->GetImageActor() );
1119 else if ( mClipper )
1121 mClipper->Refresh( size );
1127 // Note - this will automatically remove the root & image actors
1132 void TextField::KeyboardStatusChanged(bool keyboardShown)
1134 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1136 // Just hide the grab handle when keyboard is hidden.
1137 if (!keyboardShown )
1139 mController->KeyboardFocusLostEvent();
1143 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1148 TextField::TextField()
1149 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1150 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1151 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP )
1155 TextField::~TextField()
1160 } // namespace Internal
1162 } // namespace Toolkit