2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
25 #include <dali/public-api/adaptor-framework/key.h>
26 #include <dali/public-api/common/stage.h>
27 #include <dali/public-api/images/resource-image.h>
28 #include <dali/public-api/object/type-registry.h>
29 #include <dali/devel-api/object/type-registry-helper.h>
30 #include <dali/devel-api/scripting/scripting.h>
31 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
32 #include <dali/integration-api/debug.h>
35 #include <dali-toolkit/public-api/text/rendering-backend.h>
36 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
37 #include <dali-toolkit/internal/text/rendering/text-backend.h>
38 #include <dali-toolkit/internal/text/text-view.h>
39 #include <dali-toolkit/internal/styling/style-manager-impl.h>
41 using namespace Dali::Toolkit::Text;
52 namespace // unnamed namespace
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
59 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
61 } // unnamed namespace
66 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
68 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
69 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
70 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
72 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
74 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
76 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
77 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
78 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
80 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
85 return Toolkit::TextField::New();
88 // Setup properties, signals and actions using the type-registry.
89 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "rendering-backend", INTEGER, RENDERING_BACKEND )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text", STRING, PLACEHOLDER_TEXT )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-focused", STRING, PLACEHOLDER_TEXT_FOCUSED )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-family", STRING, FONT_FAMILY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "font-style", STRING, FONT_STYLE )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "point-size", FLOAT, POINT_SIZE )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "max-length", INTEGER, MAX_LENGTH )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceed-policy", INTEGER, EXCEED_POLICY )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontal-alignment", STRING, HORIZONTAL_ALIGNMENT )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "vertical-alignment", STRING, VERTICAL_ALIGNMENT )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text-color", VECTOR4, TEXT_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder-text-color", VECTOR4, PLACEHOLDER_TEXT_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-offset", VECTOR2, SHADOW_OFFSET )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow-color", VECTOR4, SHADOW_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primary-cursor-color", VECTOR4, PRIMARY_CURSOR_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondary-cursor-color", VECTOR4, SECONDARY_CURSOR_COLOR )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enable-cursor-blink", BOOLEAN, ENABLE_CURSOR_BLINK )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-interval", FLOAT, CURSOR_BLINK_INTERVAL )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-blink-duration", FLOAT, CURSOR_BLINK_DURATION )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursor-width", INTEGER, CURSOR_WIDTH )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-image", STRING, GRAB_HANDLE_IMAGE )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grab-handle-pressed-image", STRING, GRAB_HANDLE_PRESSED_IMAGE )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-threshold", FLOAT, SCROLL_THRESHOLD )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scroll-speed", FLOAT, SCROLL_SPEED )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-left", MAP, SELECTION_HANDLE_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-image-right", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-left", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-pressed-image-right", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-left", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-handle-marker-image-right", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selection-highlight-color", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "input-method-settings", MAP, INPUT_METHOD_SETTINGS )
126 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "text-changed", SIGNAL_TEXT_CHANGED )
127 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "max-length-reached", SIGNAL_MAX_LENGTH_REACHED )
129 DALI_TYPE_REGISTRATION_END()
133 Toolkit::TextField TextField::New()
135 // Create the implementation, temporarily owned by this handle on stack
136 IntrusivePtr< TextField > impl = new TextField();
138 // Pass ownership to CustomActor handle
139 Toolkit::TextField handle( *impl );
141 // Second-phase init of the implementation
142 // This can only be done after the CustomActor connection has been made...
148 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
150 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
152 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
157 TextField& impl( GetImpl( textField ) );
161 case Toolkit::TextField::Property::RENDERING_BACKEND:
163 int backend = value.Get< int >();
164 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
166 if( impl.mRenderingBackend != backend )
168 impl.mRenderingBackend = backend;
169 impl.mRenderer.Reset();
170 impl.RequestTextRelayout();
174 case Toolkit::TextField::Property::TEXT:
176 if( impl.mController )
178 const std::string text = value.Get< std::string >();
179 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
181 impl.mController->SetText( text );
185 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
187 if( impl.mController )
189 const std::string text = value.Get< std::string >();
190 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
192 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
196 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
198 if( impl.mController )
200 const std::string text = value.Get< std::string >();
201 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
203 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
207 case Toolkit::TextField::Property::FONT_FAMILY:
209 if( impl.mController )
211 const std::string fontFamily = value.Get< std::string >();
212 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
214 if( impl.mController->GetDefaultFontFamily() != fontFamily )
216 impl.mController->SetDefaultFontFamily( fontFamily, true ); // "true" as SetProperty means user defined font so don't change when system font changes.
221 case Toolkit::TextField::Property::FONT_STYLE:
223 if( impl.mController )
225 const std::string fontStyle = value.Get< std::string >();
226 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %s\n", impl.mController.Get(), fontStyle.c_str() );
228 if( impl.mController->GetDefaultFontStyle() != fontStyle )
230 impl.mController->SetDefaultFontStyle( fontStyle );
235 case Toolkit::TextField::Property::POINT_SIZE:
237 if( impl.mController )
239 const float pointSize = value.Get< float >();
240 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
242 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
244 impl.mController->SetDefaultPointSize( pointSize );
249 case Toolkit::TextField::Property::MAX_LENGTH:
251 if( impl.mController )
253 const int max = value.Get< int >();
254 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
256 impl.mController->SetMaximumNumberOfCharacters( max );
260 case Toolkit::TextField::Property::EXCEED_POLICY:
265 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
267 if( impl.mController )
269 const std::string alignStr = value.Get< std::string >();
270 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
272 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
273 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
274 HORIZONTAL_ALIGNMENT_STRING_TABLE,
275 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
278 impl.mController->SetHorizontalAlignment( alignment );
283 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
285 if( impl.mController )
287 const std::string alignStr = value.Get< std::string >();
288 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
290 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
291 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
292 VERTICAL_ALIGNMENT_STRING_TABLE,
293 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
296 impl.mController->SetVerticalAlignment( alignment );
301 case Toolkit::TextField::Property::TEXT_COLOR:
303 if( impl.mController )
305 const Vector4 textColor = value.Get< Vector4 >();
306 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 );
308 if( impl.mController->GetTextColor() != textColor )
310 impl.mController->SetTextColor( textColor );
311 impl.mRenderer.Reset();
316 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
318 if( impl.mController )
320 const Vector4 textColor = value.Get< Vector4 >();
321 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 );
323 if( impl.mController->GetPlaceholderTextColor() != textColor )
325 impl.mController->SetPlaceholderTextColor( textColor );
326 impl.mRenderer.Reset();
331 case Toolkit::TextField::Property::SHADOW_OFFSET:
333 if( impl.mController )
335 const Vector2 shadowOffset = value.Get< Vector2 >();
336 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
338 if ( impl.mController->GetShadowOffset() != shadowOffset )
340 impl.mController->SetShadowOffset( shadowOffset );
341 impl.mRenderer.Reset();
346 case Toolkit::TextField::Property::SHADOW_COLOR:
348 if( impl.mController )
350 const Vector4 shadowColor = value.Get< Vector4 >();
351 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 );
353 if ( impl.mController->GetShadowColor() != shadowColor )
355 impl.mController->SetShadowColor( shadowColor );
356 impl.mRenderer.Reset();
361 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
363 if( impl.mDecorator )
365 const Vector4 color = value.Get< Vector4 >();
366 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
368 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
369 impl.RequestTextRelayout();
373 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
375 if( impl.mDecorator )
377 const Vector4 color = value.Get< Vector4 >();
378 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
380 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
381 impl.RequestTextRelayout();
385 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
387 if( impl.mController )
389 const bool enable = value.Get< bool >();
390 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
392 impl.mController->SetEnableCursorBlink( enable );
393 impl.RequestTextRelayout();
397 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
399 if( impl.mDecorator )
401 const float interval = value.Get< float >();
402 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
404 impl.mDecorator->SetCursorBlinkInterval( interval );
408 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
410 if( impl.mDecorator )
412 const float duration = value.Get< float >();
413 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
415 impl.mDecorator->SetCursorBlinkDuration( duration );
419 case Toolkit::TextField::Property::CURSOR_WIDTH:
421 if( impl.mDecorator )
423 const int width = value.Get< int >();
424 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
426 impl.mDecorator->SetCursorWidth( width );
427 impl.mController->GetLayoutEngine().SetCursorWidth( width );
431 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
433 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
434 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
436 if( impl.mDecorator )
438 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
439 impl.RequestTextRelayout();
443 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
445 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
446 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
448 if( impl.mDecorator )
450 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
451 impl.RequestTextRelayout();
455 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
457 const float threshold = value.Get< float >();
458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
460 if( impl.mDecorator )
462 impl.mDecorator->SetScrollThreshold( threshold );
466 case Toolkit::TextField::Property::SCROLL_SPEED:
468 const float speed = value.Get< float >();
469 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
471 if( impl.mDecorator )
473 impl.mDecorator->SetScrollSpeed( speed );
477 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
479 const Image image = Scripting::NewImage( value );
481 if( impl.mDecorator )
483 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
484 impl.RequestTextRelayout();
488 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
490 const Image image = Scripting::NewImage( value );
492 if( impl.mDecorator )
494 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
495 impl.RequestTextRelayout();
499 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
501 const Image image = Scripting::NewImage( value );
503 if( impl.mDecorator )
505 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
506 impl.RequestTextRelayout();
510 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
512 const Image image = Scripting::NewImage( value );
514 if( impl.mDecorator )
516 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
517 impl.RequestTextRelayout();
521 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
523 const Image image = Scripting::NewImage( value );
524 if( impl.mDecorator )
526 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
527 impl.RequestTextRelayout();
531 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
533 const Image image = Scripting::NewImage( value );
534 if( impl.mDecorator )
536 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
537 impl.RequestTextRelayout();
541 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
543 const Vector4 color = value.Get< Vector4 >();
544 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
546 if( impl.mDecorator )
548 impl.mDecorator->SetHighlightColor( color );
549 impl.RequestTextRelayout();
553 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
555 if( impl.mDecorator )
557 const Rect<int> box = value.Get< Rect<int> >();
558 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 );
560 impl.mDecorator->SetBoundingBox( box );
561 impl.RequestTextRelayout();
565 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
567 const Property::Map map = value.Get<Property::Map>();
568 VirtualKeyboard::ApplySettings( map );
575 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
577 Property::Value value;
579 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
583 TextField& impl( GetImpl( textField ) );
587 case Toolkit::TextField::Property::RENDERING_BACKEND:
589 value = impl.mRenderingBackend;
592 case Toolkit::TextField::Property::TEXT:
594 if( impl.mController )
597 impl.mController->GetText( text );
598 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
603 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
605 if( impl.mController )
608 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
613 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
615 if( impl.mController )
618 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
623 case Toolkit::TextField::Property::FONT_FAMILY:
625 if( impl.mController )
627 value = impl.mController->GetDefaultFontFamily();
631 case Toolkit::TextField::Property::FONT_STYLE:
633 if( impl.mController )
635 value = impl.mController->GetDefaultFontStyle();
639 case Toolkit::TextField::Property::POINT_SIZE:
641 if( impl.mController )
643 value = impl.mController->GetDefaultPointSize();
647 case Toolkit::TextField::Property::MAX_LENGTH:
649 if( impl.mController )
651 value = impl.mController->GetMaximumNumberOfCharacters();
655 case Toolkit::TextField::Property::EXCEED_POLICY:
657 value = impl.mExceedPolicy;
660 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
662 if( impl.mController )
664 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
665 HORIZONTAL_ALIGNMENT_STRING_TABLE,
666 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
669 value = std::string( name );
674 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
676 if( impl.mController )
678 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
679 VERTICAL_ALIGNMENT_STRING_TABLE,
680 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
683 value = std::string( name );
688 case Toolkit::TextField::Property::TEXT_COLOR:
690 if ( impl.mController )
692 value = impl.mController->GetTextColor();
696 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
698 if ( impl.mController )
700 value = impl.mController->GetPlaceholderTextColor();
704 case Toolkit::TextField::Property::SHADOW_OFFSET:
706 if ( impl.mController )
708 value = impl.mController->GetShadowOffset();
712 case Toolkit::TextField::Property::SHADOW_COLOR:
714 if ( impl.mController )
716 value = impl.mController->GetShadowColor();
720 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
722 if( impl.mDecorator )
724 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
728 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
730 if( impl.mDecorator )
732 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
736 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
738 value = impl.mController->GetEnableCursorBlink();
741 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
743 if( impl.mDecorator )
745 value = impl.mDecorator->GetCursorBlinkInterval();
749 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
751 if( impl.mDecorator )
753 value = impl.mDecorator->GetCursorBlinkDuration();
757 case Toolkit::TextField::Property::CURSOR_WIDTH:
759 if( impl.mDecorator )
761 value = impl.mDecorator->GetCursorWidth();
765 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
767 if( impl.mDecorator )
769 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
772 value = image.GetUrl();
777 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
779 if( impl.mDecorator )
781 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
784 value = image.GetUrl();
789 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
791 if( impl.mDecorator )
793 value = impl.mDecorator->GetScrollThreshold();
797 case Toolkit::TextField::Property::SCROLL_SPEED:
799 if( impl.mDecorator )
801 value = impl.mDecorator->GetScrollSpeed();
805 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
807 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
810 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
812 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
815 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
817 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
820 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
822 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
825 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
827 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
830 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
832 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
835 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
837 if( impl.mDecorator )
839 value = impl.mDecorator->GetHighlightColor();
843 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
845 if( impl.mDecorator )
847 value = impl.mDecorator->GetBoundingBox();
851 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
861 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
863 Dali::BaseHandle handle( object );
865 bool connected( true );
866 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
868 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
870 field.TextChangedSignal().Connect( tracker, functor );
872 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
874 field.MaxLengthReachedSignal().Connect( tracker, functor );
878 // signalName does not match any signal
885 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
887 return mTextChangedSignal;
890 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
892 return mMaxLengthReachedSignal;
895 void TextField::OnInitialize()
899 mController = Text::Controller::New( *this );
901 mDecorator = Text::Decorator::New( *mController,
904 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
906 mController->EnableTextInput( mDecorator );
908 // Forward input events to controller
909 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan |Gesture::LongPress ) );
910 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
912 self.TouchedSignal().Connect( this, &TextField::OnTouched );
914 // Set BoundingBox to stage size if not already set.
915 if ( mDecorator->GetBoundingBox().IsEmpty() )
917 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
918 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
921 // Fill-parent area by default
922 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
923 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
924 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
927 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
929 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
933 case StyleChange::DEFAULT_FONT_CHANGE:
935 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
936 std::string newFont = styleManager.GetDefaultFontFamily();
937 // Property system did not set the font so should update it.
938 mController->UpdateAfterFontChange( newFont );
942 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
944 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
946 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
948 // Property system did not set the PointSize so should update it.
949 // todo instruct text-controller to update model
953 case StyleChange::THEME_CHANGE:
955 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
961 Vector3 TextField::GetNaturalSize()
963 return mController->GetNaturalSize();
966 float TextField::GetHeightForWidth( float width )
968 return mController->GetHeightForWidth( width );
971 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
973 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
975 if( mController->Relayout( size ) ||
978 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
982 mDecorator->Relayout( size );
987 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
990 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
995 void TextField::RenderText()
998 Actor renderableActor;
1001 renderableActor = mRenderer->Render( mController->GetView(), self.GetHierarchyDepth() );
1004 if( renderableActor != mRenderableActor )
1006 UnparentAndReset( mRenderableActor );
1007 mRenderableActor = renderableActor;
1010 if( mRenderableActor )
1012 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1014 mRenderableActor.SetPosition( offset.x, offset.y );
1016 Actor clipRootActor;
1019 clipRootActor = mClipper->GetRootActor();
1022 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1023 endIt = mClippingDecorationActors.end();
1031 clipRootActor.Add( actor );
1038 mClippingDecorationActors.clear();
1040 // Make sure the actor is parented correctly with/without clipping
1043 clipRootActor.Add( mRenderableActor );
1047 self.Add( mRenderableActor );
1052 void TextField::OnKeyInputFocusGained()
1054 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1056 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1058 ImfManager imfManager = ImfManager::Get();
1062 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1064 // Notify that the text editing start.
1065 imfManager.Activate();
1067 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1068 imfManager.SetRestoreAfterFocusLost( true );
1071 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1075 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1078 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1080 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1083 void TextField::OnKeyInputFocusLost()
1085 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1087 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1089 ImfManager imfManager = ImfManager::Get();
1092 // The text editing is finished. Therefore the imf manager don't have restore activation.
1093 imfManager.SetRestoreAfterFocusLost( false );
1095 // Notify that the text editing finish.
1096 imfManager.Deactivate();
1098 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1101 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1105 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1108 mController->KeyboardFocusLostEvent();
1110 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1113 void TextField::OnTap( const TapGesture& gesture )
1115 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1117 // Show the keyboard if it was hidden.
1118 if (!VirtualKeyboard::IsVisible())
1120 VirtualKeyboard::Show();
1123 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1124 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1129 void TextField::OnPan( const PanGesture& gesture )
1131 mController->PanEvent( gesture.state, gesture.displacement );
1134 void TextField::OnLongPress( const LongPressGesture& gesture )
1136 // Show the keyboard if it was hidden.
1137 if (!VirtualKeyboard::IsVisible())
1139 VirtualKeyboard::Show();
1142 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1147 bool TextField::OnKeyEvent( const KeyEvent& event )
1149 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1151 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1152 "Return" == event.keyPressedName ) // Make a Dali key code for this
1154 ClearKeyInputFocus();
1158 return mController->KeyEvent( event );
1161 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1167 mClippingDecorationActors.push_back( actor );
1171 Self().Add( actor );
1176 void TextField::RequestTextRelayout()
1181 void TextField::TextChanged()
1183 Dali::Toolkit::TextField handle( GetOwner() );
1184 mTextChangedSignal.Emit( handle );
1187 void TextField::OnStageConnect( Dali::Actor actor )
1189 if ( mHasBeenStaged )
1195 mHasBeenStaged = true;
1199 void TextField::MaxLengthReached()
1201 Dali::Toolkit::TextField handle( GetOwner() );
1202 mMaxLengthReachedSignal.Emit( handle );
1205 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1207 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1208 return mController->OnImfEvent( imfManager, imfEvent );
1211 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1215 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1220 Scripting::CreatePropertyMap( image, map );
1226 void TextField::EnableClipping( bool clipping, const Vector2& size )
1230 // Not worth to created clip actor if width or height is equal to zero.
1231 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1235 Actor self = Self();
1237 mClipper = Clipper::New( size );
1238 self.Add( mClipper->GetRootActor() );
1239 self.Add( mClipper->GetImageActor() );
1241 else if ( mClipper )
1243 mClipper->Refresh( size );
1249 // Note - this will automatically remove the root & image actors
1254 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1256 mController->PasteClipboardItemEvent();
1259 void TextField::KeyboardStatusChanged(bool keyboardShown)
1261 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1263 // Just hide the grab handle when keyboard is hidden.
1264 if (!keyboardShown )
1266 mController->KeyboardFocusLostEvent();
1270 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1274 void TextField::OnStageConnection( int depth )
1276 // Call the Control::OnStageConnection() to set the depth of the background.
1277 Control::OnStageConnection( depth );
1279 // Sets the depth to the renderers inside the text's decorator.
1280 mDecorator->SetTextDepth( depth );
1282 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1285 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1290 TextField::TextField()
1291 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1292 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1293 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1294 mHasBeenStaged( false )
1298 TextField::~TextField()
1303 } // namespace Internal
1305 } // namespace Toolkit