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>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
27 #include <dali/devel-api/object/type-registry-helper.h>
28 #include <dali/integration-api/debug.h>
31 #include <dali-toolkit/public-api/text/rendering-backend.h>
32 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
33 #include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
34 #include <dali-toolkit/internal/text/rendering/text-backend.h>
35 #include <dali-toolkit/internal/text/text-view.h>
36 #include <dali-toolkit/internal/styling/style-manager-impl.h>
38 using namespace Dali::Toolkit::Text;
49 namespace // unnamed namespace
52 #if defined(DEBUG_ENABLED)
53 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
56 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
57 } // unnamed namespace
62 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
64 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
65 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
66 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
68 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
70 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
72 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
73 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
74 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
76 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
81 return Toolkit::TextField::New();
84 // Setup properties, signals and actions using the type-registry.
85 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", STRING, FONT_STYLE )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
124 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
125 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
127 DALI_TYPE_REGISTRATION_END()
131 Toolkit::TextField TextField::New()
133 // Create the implementation, temporarily owned by this handle on stack
134 IntrusivePtr< TextField > impl = new TextField();
136 // Pass ownership to CustomActor handle
137 Toolkit::TextField handle( *impl );
139 // Second-phase init of the implementation
140 // This can only be done after the CustomActor connection has been made...
146 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
148 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
150 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
155 TextField& impl( GetImpl( textField ) );
159 case Toolkit::TextField::Property::RENDERING_BACKEND:
161 int backend = value.Get< int >();
162 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
164 if( impl.mRenderingBackend != backend )
166 impl.mRenderingBackend = backend;
167 impl.mRenderer.Reset();
168 impl.RequestTextRelayout();
172 case Toolkit::TextField::Property::TEXT:
174 if( impl.mController )
176 const std::string text = value.Get< std::string >();
177 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
179 impl.mController->SetText( text );
183 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
185 if( impl.mController )
187 const std::string text = value.Get< std::string >();
188 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
190 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
194 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
196 if( impl.mController )
198 const std::string text = value.Get< std::string >();
199 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
201 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
205 case Toolkit::TextField::Property::FONT_FAMILY:
207 if( impl.mController )
209 const std::string fontFamily = value.Get< std::string >();
210 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
211 impl.mController->SetDefaultFontFamily( fontFamily );
215 case Toolkit::TextField::Property::FONT_STYLE:
217 SetFontStyleProperty( impl.mController, value );
220 case Toolkit::TextField::Property::POINT_SIZE:
222 if( impl.mController )
224 const float pointSize = value.Get< float >();
225 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
227 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
229 impl.mController->SetDefaultPointSize( pointSize );
234 case Toolkit::TextField::Property::MAX_LENGTH:
236 if( impl.mController )
238 const int max = value.Get< int >();
239 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
241 impl.mController->SetMaximumNumberOfCharacters( max );
245 case Toolkit::TextField::Property::EXCEED_POLICY:
250 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
252 if( impl.mController )
254 const std::string alignStr = value.Get< std::string >();
255 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
257 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
258 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
259 HORIZONTAL_ALIGNMENT_STRING_TABLE,
260 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
263 impl.mController->SetHorizontalAlignment( alignment );
268 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
270 if( impl.mController )
272 const std::string alignStr = value.Get< std::string >();
273 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
275 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
276 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
277 VERTICAL_ALIGNMENT_STRING_TABLE,
278 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
281 impl.mController->SetVerticalAlignment( alignment );
286 case Toolkit::TextField::Property::TEXT_COLOR:
288 if( impl.mController )
290 const Vector4 textColor = value.Get< Vector4 >();
291 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 );
293 if( impl.mController->GetTextColor() != textColor )
295 impl.mController->SetTextColor( textColor );
296 impl.mController->SetInputColor( textColor );
297 impl.mRenderer.Reset();
302 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
304 if( impl.mController )
306 const Vector4 textColor = value.Get< Vector4 >();
307 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 );
309 if( impl.mController->GetPlaceholderTextColor() != textColor )
311 impl.mController->SetPlaceholderTextColor( textColor );
312 impl.mRenderer.Reset();
317 case Toolkit::TextField::Property::SHADOW_OFFSET:
319 if( impl.mController )
321 const Vector2 shadowOffset = value.Get< Vector2 >();
322 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
324 if ( impl.mController->GetShadowOffset() != shadowOffset )
326 impl.mController->SetShadowOffset( shadowOffset );
327 impl.mRenderer.Reset();
332 case Toolkit::TextField::Property::SHADOW_COLOR:
334 if( impl.mController )
336 const Vector4 shadowColor = value.Get< Vector4 >();
337 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 );
339 if ( impl.mController->GetShadowColor() != shadowColor )
341 impl.mController->SetShadowColor( shadowColor );
342 impl.mRenderer.Reset();
347 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
349 if( impl.mDecorator )
351 const Vector4 color = value.Get< Vector4 >();
352 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 );
354 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
355 impl.RequestTextRelayout();
359 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
361 if( impl.mDecorator )
363 const Vector4 color = value.Get< Vector4 >();
364 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 );
366 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
367 impl.RequestTextRelayout();
371 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
373 if( impl.mController )
375 const bool enable = value.Get< bool >();
376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
378 impl.mController->SetEnableCursorBlink( enable );
379 impl.RequestTextRelayout();
383 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
385 if( impl.mDecorator )
387 const float interval = value.Get< float >();
388 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
390 impl.mDecorator->SetCursorBlinkInterval( interval );
394 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
396 if( impl.mDecorator )
398 const float duration = value.Get< float >();
399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
401 impl.mDecorator->SetCursorBlinkDuration( duration );
405 case Toolkit::TextField::Property::CURSOR_WIDTH:
407 if( impl.mDecorator )
409 const int width = value.Get< int >();
410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
412 impl.mDecorator->SetCursorWidth( width );
413 impl.mController->GetLayoutEngine().SetCursorWidth( width );
417 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
419 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
420 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
422 if( impl.mDecorator )
424 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
425 impl.RequestTextRelayout();
429 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
431 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
432 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
434 if( impl.mDecorator )
436 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
437 impl.RequestTextRelayout();
441 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
443 const float threshold = value.Get< float >();
444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
446 if( impl.mDecorator )
448 impl.mDecorator->SetScrollThreshold( threshold );
452 case Toolkit::TextField::Property::SCROLL_SPEED:
454 const float speed = value.Get< float >();
455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
457 if( impl.mDecorator )
459 impl.mDecorator->SetScrollSpeed( speed );
463 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
465 const Image image = Scripting::NewImage( value );
467 if( impl.mDecorator && image )
469 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
470 impl.RequestTextRelayout();
474 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
476 const Image image = Scripting::NewImage( value );
478 if( impl.mDecorator && image )
480 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
481 impl.RequestTextRelayout();
485 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
487 const Image image = Scripting::NewImage( value );
489 if( impl.mDecorator && image )
491 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
492 impl.RequestTextRelayout();
496 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
498 const Image image = Scripting::NewImage( value );
500 if( impl.mDecorator && image )
502 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
503 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
509 const Image image = Scripting::NewImage( value );
511 if( impl.mDecorator && image )
513 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
514 impl.RequestTextRelayout();
518 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
520 const Image image = Scripting::NewImage( value );
522 if( impl.mDecorator && image )
524 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
525 impl.RequestTextRelayout();
529 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
531 const Vector4 color = value.Get< Vector4 >();
532 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 );
534 if( impl.mDecorator )
536 impl.mDecorator->SetHighlightColor( color );
537 impl.RequestTextRelayout();
541 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
543 if( impl.mDecorator )
545 const Rect<int> box = value.Get< Rect<int> >();
546 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 );
548 impl.mDecorator->SetBoundingBox( box );
549 impl.RequestTextRelayout();
553 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
555 const Property::Map map = value.Get<Property::Map>();
556 VirtualKeyboard::ApplySettings( map );
559 case Toolkit::TextField::Property::INPUT_COLOR:
561 if( impl.mController )
563 const Vector4 inputColor = value.Get< Vector4 >();
564 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), inputColor.r, inputColor.g, inputColor.b, inputColor.a );
566 impl.mController->SetInputColor( inputColor );
570 case Toolkit::TextField::Property::ENABLE_MARKUP:
572 if( impl.mController )
574 const bool enableMarkup = value.Get<bool>();
575 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
577 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
585 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
587 Property::Value value;
589 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
593 TextField& impl( GetImpl( textField ) );
597 case Toolkit::TextField::Property::RENDERING_BACKEND:
599 value = impl.mRenderingBackend;
602 case Toolkit::TextField::Property::TEXT:
604 if( impl.mController )
607 impl.mController->GetText( text );
608 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
613 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
615 if( impl.mController )
618 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
623 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
625 if( impl.mController )
628 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
633 case Toolkit::TextField::Property::FONT_FAMILY:
635 if( impl.mController )
637 value = impl.mController->GetDefaultFontFamily();
641 case Toolkit::TextField::Property::FONT_STYLE:
643 GetFontStyleProperty( impl.mController, value );
646 case Toolkit::TextField::Property::POINT_SIZE:
648 if( impl.mController )
650 value = impl.mController->GetDefaultPointSize();
654 case Toolkit::TextField::Property::MAX_LENGTH:
656 if( impl.mController )
658 value = impl.mController->GetMaximumNumberOfCharacters();
662 case Toolkit::TextField::Property::EXCEED_POLICY:
664 value = impl.mExceedPolicy;
667 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
669 if( impl.mController )
671 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
672 HORIZONTAL_ALIGNMENT_STRING_TABLE,
673 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
676 value = std::string( name );
681 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
683 if( impl.mController )
685 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
686 VERTICAL_ALIGNMENT_STRING_TABLE,
687 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
690 value = std::string( name );
695 case Toolkit::TextField::Property::TEXT_COLOR:
697 if ( impl.mController )
699 value = impl.mController->GetTextColor();
703 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
705 if ( impl.mController )
707 value = impl.mController->GetPlaceholderTextColor();
711 case Toolkit::TextField::Property::INPUT_COLOR:
713 if( impl.mController )
715 value = impl.mController->GetInputColor();
719 case Toolkit::TextField::Property::SHADOW_OFFSET:
721 if ( impl.mController )
723 value = impl.mController->GetShadowOffset();
727 case Toolkit::TextField::Property::SHADOW_COLOR:
729 if ( impl.mController )
731 value = impl.mController->GetShadowColor();
735 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
737 if( impl.mDecorator )
739 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
743 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
745 if( impl.mDecorator )
747 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
751 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
753 value = impl.mController->GetEnableCursorBlink();
756 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
758 if( impl.mDecorator )
760 value = impl.mDecorator->GetCursorBlinkInterval();
764 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
766 if( impl.mDecorator )
768 value = impl.mDecorator->GetCursorBlinkDuration();
772 case Toolkit::TextField::Property::CURSOR_WIDTH:
774 if( impl.mDecorator )
776 value = impl.mDecorator->GetCursorWidth();
780 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
782 if( impl.mDecorator )
784 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
787 value = image.GetUrl();
792 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
794 if( impl.mDecorator )
796 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
799 value = image.GetUrl();
804 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
806 if( impl.mDecorator )
808 value = impl.mDecorator->GetScrollThreshold();
812 case Toolkit::TextField::Property::SCROLL_SPEED:
814 if( impl.mDecorator )
816 value = impl.mDecorator->GetScrollSpeed();
820 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
822 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
825 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
827 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
830 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
832 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
835 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
837 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
840 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
842 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
845 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
847 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
850 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
852 if( impl.mDecorator )
854 value = impl.mDecorator->GetHighlightColor();
858 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
860 if( impl.mDecorator )
862 Rect<int> boundingBox;
863 impl.mDecorator->GetBoundingBox( boundingBox );
868 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
872 case Toolkit::TextField::Property::ENABLE_MARKUP:
874 if( impl.mController )
876 value = impl.mController->IsMarkupProcessorEnabled();
886 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
888 Dali::BaseHandle handle( object );
890 bool connected( true );
891 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
893 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
895 field.TextChangedSignal().Connect( tracker, functor );
897 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
899 field.MaxLengthReachedSignal().Connect( tracker, functor );
903 // signalName does not match any signal
910 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
912 return mTextChangedSignal;
915 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
917 return mMaxLengthReachedSignal;
920 void TextField::OnInitialize()
924 mController = Text::Controller::New( *this );
926 mDecorator = Text::Decorator::New( *mController,
929 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
931 mController->EnableTextInput( mDecorator );
933 // Forward input events to controller
934 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
935 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
937 self.TouchedSignal().Connect( this, &TextField::OnTouched );
939 // Set BoundingBox to stage size if not already set.
940 Rect<int> boundingBox;
941 mDecorator->GetBoundingBox( boundingBox );
943 if( boundingBox.IsEmpty() )
945 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
946 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
949 // Flip vertically the 'left' selection handle
950 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
952 // Fill-parent area by default
953 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
954 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
955 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
958 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
960 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
964 case StyleChange::DEFAULT_FONT_CHANGE:
966 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
967 std::string newFont = styleManager.GetDefaultFontFamily();
968 // Property system did not set the font so should update it.
969 mController->UpdateAfterFontChange( newFont );
973 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
975 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField::OnStyleChange StyleChange::DEFAULT_FONT_SIZE_CHANGE (%f)\n", mController->GetDefaultPointSize() );
977 if ( (mController->GetDefaultPointSize() <= 0.0f) ) // If DefaultPointSize not set by Property system it will be 0.0f
979 // Property system did not set the PointSize so should update it.
980 // todo instruct text-controller to update model
984 case StyleChange::THEME_CHANGE:
986 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
992 Vector3 TextField::GetNaturalSize()
994 return mController->GetNaturalSize();
997 float TextField::GetHeightForWidth( float width )
999 return mController->GetHeightForWidth( width );
1002 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1004 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1006 if( mController->Relayout( size ) ||
1009 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1013 mDecorator->Relayout( size );
1018 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1021 EnableClipping( (Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy), size );
1026 void TextField::RenderText()
1028 Actor self = Self();
1029 Actor renderableActor;
1032 renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
1035 if( renderableActor != mRenderableActor )
1037 UnparentAndReset( mRenderableActor );
1038 mRenderableActor = renderableActor;
1041 if( mRenderableActor )
1043 const Vector2 offset = mController->GetScrollPosition() + mController->GetAlignmentOffset();
1045 mRenderableActor.SetPosition( offset.x, offset.y );
1047 Actor clipRootActor;
1050 clipRootActor = mClipper->GetRootActor();
1053 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1054 endIt = mClippingDecorationActors.end();
1062 clipRootActor.Add( actor );
1069 mClippingDecorationActors.clear();
1071 // Make sure the actor is parented correctly with/without clipping
1074 clipRootActor.Add( mRenderableActor );
1078 self.Add( mRenderableActor );
1083 void TextField::OnKeyInputFocusGained()
1085 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1087 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1089 ImfManager imfManager = ImfManager::Get();
1093 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1095 // Notify that the text editing start.
1096 imfManager.Activate();
1098 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1099 imfManager.SetRestoreAfterFocusLost( true );
1102 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1106 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1109 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1111 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1114 void TextField::OnKeyInputFocusLost()
1116 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1118 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1120 ImfManager imfManager = ImfManager::Get();
1123 // The text editing is finished. Therefore the imf manager don't have restore activation.
1124 imfManager.SetRestoreAfterFocusLost( false );
1126 // Notify that the text editing finish.
1127 imfManager.Deactivate();
1129 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1132 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1136 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1139 mController->KeyboardFocusLostEvent();
1141 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1144 void TextField::OnTap( const TapGesture& gesture )
1146 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1148 // Show the keyboard if it was hidden.
1149 if (!VirtualKeyboard::IsVisible())
1151 VirtualKeyboard::Show();
1154 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1155 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1160 void TextField::OnPan( const PanGesture& gesture )
1162 mController->PanEvent( gesture.state, gesture.displacement );
1165 void TextField::OnLongPress( const LongPressGesture& gesture )
1167 // Show the keyboard if it was hidden.
1168 if (!VirtualKeyboard::IsVisible())
1170 VirtualKeyboard::Show();
1173 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1178 bool TextField::OnKeyEvent( const KeyEvent& event )
1180 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1182 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1183 "Return" == event.keyPressedName ) // Make a Dali key code for this
1185 ClearKeyInputFocus();
1189 return mController->KeyEvent( event );
1192 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1198 mClippingDecorationActors.push_back( actor );
1202 Self().Add( actor );
1207 void TextField::RequestTextRelayout()
1212 void TextField::TextChanged()
1214 Dali::Toolkit::TextField handle( GetOwner() );
1215 mTextChangedSignal.Emit( handle );
1218 void TextField::OnStageConnect( Dali::Actor actor )
1220 if ( mHasBeenStaged )
1226 mHasBeenStaged = true;
1230 void TextField::MaxLengthReached()
1232 Dali::Toolkit::TextField handle( GetOwner() );
1233 mMaxLengthReachedSignal.Emit( handle );
1236 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1239 return mController->OnImfEvent( imfManager, imfEvent );
1242 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1246 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1251 Scripting::CreatePropertyMap( image, map );
1257 void TextField::EnableClipping( bool clipping, const Vector2& size )
1261 // Not worth to created clip actor if width or height is equal to zero.
1262 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1266 Actor self = Self();
1268 mClipper = Clipper::New( size );
1269 self.Add( mClipper->GetRootActor() );
1270 self.Add( mClipper->GetImageActor() );
1272 else if ( mClipper )
1274 mClipper->Refresh( size );
1280 // Note - this will automatically remove the root & image actors
1285 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1287 mController->PasteClipboardItemEvent();
1290 void TextField::KeyboardStatusChanged(bool keyboardShown)
1292 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1294 // Just hide the grab handle when keyboard is hidden.
1295 if (!keyboardShown )
1297 mController->KeyboardFocusLostEvent();
1301 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1305 void TextField::OnStageConnection( int depth )
1307 // Call the Control::OnStageConnection() to set the depth of the background.
1308 Control::OnStageConnection( depth );
1310 // Sets the depth to the renderers inside the text's decorator.
1311 mDecorator->SetTextDepth( depth );
1313 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1316 bool TextField::OnTouched( Actor actor, const TouchEvent& event )
1321 TextField::TextField()
1322 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1323 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1324 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1325 mHasBeenStaged( false )
1329 TextField::~TextField()
1334 } // namespace Internal
1336 } // namespace Toolkit