2 * Copyright (c) 2016 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/public-api/object/type-registry-helper.h>
28 #include <dali/integration-api/adaptors/adaptor.h>
29 #include <dali/integration-api/debug.h>
32 #include <dali-toolkit/public-api/text/rendering-backend.h>
33 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
34 #include <dali-toolkit/internal/text/rendering/text-backend.h>
35 #include <dali-toolkit/internal/text/text-effects-style.h>
36 #include <dali-toolkit/internal/text/text-font-style.h>
37 #include <dali-toolkit/internal/text/text-view.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;
59 } // unnamed namespace
64 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
66 { "BEGIN", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN },
67 { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
68 { "END", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END },
70 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
72 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
74 { "TOP", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP },
75 { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
76 { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
78 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
83 return Toolkit::TextField::New();
86 // Setup properties, signals and actions using the type-registry.
87 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", STRING, FONT_STYLE )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", STRING, INPUT_FONT_STYLE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", STRING, UNDERLINE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", STRING, INPUT_UNDERLINE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", STRING, SHADOW )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", STRING, INPUT_SHADOW )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", STRING, EMBOSS )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", STRING, INPUT_EMBOSS )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", STRING, OUTLINE )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", STRING, INPUT_OUTLINE )
137 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
138 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
139 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
141 DALI_TYPE_REGISTRATION_END()
145 Toolkit::TextField TextField::New()
147 // Create the implementation, temporarily owned by this handle on stack
148 IntrusivePtr< TextField > impl = new TextField();
150 // Pass ownership to CustomActor handle
151 Toolkit::TextField handle( *impl );
153 // Second-phase init of the implementation
154 // This can only be done after the CustomActor connection has been made...
160 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
162 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
164 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
169 TextField& impl( GetImpl( textField ) );
173 case Toolkit::TextField::Property::RENDERING_BACKEND:
175 int backend = value.Get< int >();
176 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
178 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
179 if( Text::RENDERING_VECTOR_BASED == backend )
181 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
184 if( impl.mRenderingBackend != backend )
186 impl.mRenderingBackend = backend;
187 impl.mRenderer.Reset();
189 if( impl.mController )
191 // When using the vector-based rendering, the size of the GLyphs are different
192 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
193 impl.mController->SetGlyphType( glyphType );
198 case Toolkit::TextField::Property::TEXT:
200 if( impl.mController )
202 const std::string text = value.Get< std::string >();
203 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
205 impl.mController->SetText( text );
209 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
211 if( impl.mController )
213 const std::string text = value.Get< std::string >();
214 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
216 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
220 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
222 if( impl.mController )
224 const std::string text = value.Get< std::string >();
225 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
227 impl.mController->SetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
231 case Toolkit::TextField::Property::FONT_FAMILY:
233 if( impl.mController )
235 const std::string fontFamily = value.Get< std::string >();
236 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
237 impl.mController->SetDefaultFontFamily( fontFamily );
241 case Toolkit::TextField::Property::FONT_STYLE:
243 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
246 case Toolkit::TextField::Property::POINT_SIZE:
248 if( impl.mController )
250 const float pointSize = value.Get< float >();
251 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
253 if( !Equals( impl.mController->GetDefaultPointSize(), pointSize ) )
255 impl.mController->SetDefaultPointSize( pointSize );
260 case Toolkit::TextField::Property::MAX_LENGTH:
262 if( impl.mController )
264 const int max = value.Get< int >();
265 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
267 impl.mController->SetMaximumNumberOfCharacters( max );
271 case Toolkit::TextField::Property::EXCEED_POLICY:
276 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
278 if( impl.mController )
280 const std::string alignStr = value.Get< std::string >();
281 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
283 LayoutEngine::HorizontalAlignment alignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN );
284 if( Scripting::GetEnumeration< LayoutEngine::HorizontalAlignment >( alignStr.c_str(),
285 HORIZONTAL_ALIGNMENT_STRING_TABLE,
286 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
289 impl.mController->SetHorizontalAlignment( alignment );
294 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
296 if( impl.mController )
298 const std::string alignStr = value.Get< std::string >();
299 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
301 LayoutEngine::VerticalAlignment alignment( LayoutEngine::VERTICAL_ALIGN_BOTTOM );
302 if( Scripting::GetEnumeration< LayoutEngine::VerticalAlignment >( alignStr.c_str(),
303 VERTICAL_ALIGNMENT_STRING_TABLE,
304 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
307 impl.mController->SetVerticalAlignment( alignment );
312 case Toolkit::TextField::Property::TEXT_COLOR:
314 if( impl.mController )
316 const Vector4 textColor = value.Get< Vector4 >();
317 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 );
319 if( impl.mController->GetTextColor() != textColor )
321 impl.mController->SetTextColor( textColor );
322 impl.mController->SetInputColor( textColor );
323 impl.mRenderer.Reset();
328 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
330 if( impl.mController )
332 const Vector4 textColor = value.Get< Vector4 >();
333 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 );
335 if( impl.mController->GetPlaceholderTextColor() != textColor )
337 impl.mController->SetPlaceholderTextColor( textColor );
338 impl.mRenderer.Reset();
343 case Toolkit::TextField::Property::SHADOW_OFFSET:
345 if( impl.mController )
347 const Vector2 shadowOffset = value.Get< Vector2 >();
348 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
350 if ( impl.mController->GetShadowOffset() != shadowOffset )
352 impl.mController->SetShadowOffset( shadowOffset );
353 impl.mRenderer.Reset();
358 case Toolkit::TextField::Property::SHADOW_COLOR:
360 if( impl.mController )
362 const Vector4 shadowColor = value.Get< Vector4 >();
363 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 );
365 if ( impl.mController->GetShadowColor() != shadowColor )
367 impl.mController->SetShadowColor( shadowColor );
368 impl.mRenderer.Reset();
373 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
375 if( impl.mDecorator )
377 const Vector4 color = value.Get< Vector4 >();
378 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 );
380 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
381 impl.RequestTextRelayout();
385 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
387 if( impl.mDecorator )
389 const Vector4 color = value.Get< Vector4 >();
390 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 );
392 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
393 impl.RequestTextRelayout();
397 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
399 if( impl.mController )
401 const bool enable = value.Get< bool >();
402 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
404 impl.mController->SetEnableCursorBlink( enable );
405 impl.RequestTextRelayout();
409 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
411 if( impl.mDecorator )
413 const float interval = value.Get< float >();
414 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
416 impl.mDecorator->SetCursorBlinkInterval( interval );
420 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
422 if( impl.mDecorator )
424 const float duration = value.Get< float >();
425 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
427 impl.mDecorator->SetCursorBlinkDuration( duration );
431 case Toolkit::TextField::Property::CURSOR_WIDTH:
433 if( impl.mDecorator )
435 const int width = value.Get< int >();
436 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
438 impl.mDecorator->SetCursorWidth( width );
439 impl.mController->GetLayoutEngine().SetCursorWidth( width );
443 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
445 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
446 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
448 if( impl.mDecorator )
450 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
451 impl.RequestTextRelayout();
455 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
457 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
460 if( impl.mDecorator )
462 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
463 impl.RequestTextRelayout();
467 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
469 const float threshold = value.Get< float >();
470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
472 if( impl.mDecorator )
474 impl.mDecorator->SetScrollThreshold( threshold );
478 case Toolkit::TextField::Property::SCROLL_SPEED:
480 const float speed = value.Get< float >();
481 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
483 if( impl.mDecorator )
485 impl.mDecorator->SetScrollSpeed( speed );
489 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
491 const Image image = Scripting::NewImage( value );
493 if( impl.mDecorator && image )
495 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
496 impl.RequestTextRelayout();
500 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
502 const Image image = Scripting::NewImage( value );
504 if( impl.mDecorator && image )
506 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
507 impl.RequestTextRelayout();
511 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
513 const Image image = Scripting::NewImage( value );
515 if( impl.mDecorator && image )
517 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
518 impl.RequestTextRelayout();
522 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
524 const Image image = Scripting::NewImage( value );
526 if( impl.mDecorator && image )
528 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
529 impl.RequestTextRelayout();
533 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
535 const Image image = Scripting::NewImage( value );
537 if( impl.mDecorator && image )
539 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
540 impl.RequestTextRelayout();
544 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
546 const Image image = Scripting::NewImage( value );
548 if( impl.mDecorator && image )
550 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
551 impl.RequestTextRelayout();
555 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
557 const Vector4 color = value.Get< Vector4 >();
558 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 );
560 if( impl.mDecorator )
562 impl.mDecorator->SetHighlightColor( color );
563 impl.RequestTextRelayout();
567 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
569 if( impl.mDecorator )
571 const Rect<int> box = value.Get< Rect<int> >();
572 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 );
574 impl.mDecorator->SetBoundingBox( box );
575 impl.RequestTextRelayout();
579 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
581 const Property::Map map = value.Get<Property::Map>();
582 VirtualKeyboard::ApplySettings( map );
585 case Toolkit::TextField::Property::INPUT_COLOR:
587 if( impl.mController )
589 const Vector4 inputColor = value.Get< Vector4 >();
590 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 );
592 impl.mController->SetInputColor( inputColor );
596 case Toolkit::TextField::Property::ENABLE_MARKUP:
598 if( impl.mController )
600 const bool enableMarkup = value.Get<bool>();
601 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
603 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
607 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
609 if( impl.mController )
611 const std::string fontFamily = value.Get< std::string >();
612 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
613 impl.mController->SetInputFontFamily( fontFamily );
617 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
619 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
622 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
624 if( impl.mController )
626 const float pointSize = value.Get< float >();
627 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
628 impl.mController->SetInputFontPointSize( pointSize );
632 case Toolkit::TextField::Property::UNDERLINE:
634 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
637 impl.mRenderer.Reset();
641 case Toolkit::TextField::Property::INPUT_UNDERLINE:
643 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
646 impl.mRenderer.Reset();
650 case Toolkit::TextField::Property::SHADOW:
652 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
655 impl.mRenderer.Reset();
659 case Toolkit::TextField::Property::INPUT_SHADOW:
661 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
664 impl.mRenderer.Reset();
668 case Toolkit::TextField::Property::EMBOSS:
670 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
673 impl.mRenderer.Reset();
677 case Toolkit::TextField::Property::INPUT_EMBOSS:
679 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
682 impl.mRenderer.Reset();
686 case Toolkit::TextField::Property::OUTLINE:
688 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
691 impl.mRenderer.Reset();
695 case Toolkit::TextField::Property::INPUT_OUTLINE:
697 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
700 impl.mRenderer.Reset();
708 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
710 Property::Value value;
712 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
716 TextField& impl( GetImpl( textField ) );
720 case Toolkit::TextField::Property::RENDERING_BACKEND:
722 value = impl.mRenderingBackend;
725 case Toolkit::TextField::Property::TEXT:
727 if( impl.mController )
730 impl.mController->GetText( text );
731 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
736 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
738 if( impl.mController )
741 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_INACTIVE, text );
746 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
748 if( impl.mController )
751 impl.mController->GetPlaceholderText( PLACEHOLDER_TYPE_ACTIVE, text );
756 case Toolkit::TextField::Property::FONT_FAMILY:
758 if( impl.mController )
760 value = impl.mController->GetDefaultFontFamily();
764 case Toolkit::TextField::Property::FONT_STYLE:
766 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
769 case Toolkit::TextField::Property::POINT_SIZE:
771 if( impl.mController )
773 value = impl.mController->GetDefaultPointSize();
777 case Toolkit::TextField::Property::MAX_LENGTH:
779 if( impl.mController )
781 value = impl.mController->GetMaximumNumberOfCharacters();
785 case Toolkit::TextField::Property::EXCEED_POLICY:
787 value = impl.mExceedPolicy;
790 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
792 if( impl.mController )
794 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
795 HORIZONTAL_ALIGNMENT_STRING_TABLE,
796 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
799 value = std::string( name );
804 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
806 if( impl.mController )
808 const char* name = Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
809 VERTICAL_ALIGNMENT_STRING_TABLE,
810 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
813 value = std::string( name );
818 case Toolkit::TextField::Property::TEXT_COLOR:
820 if ( impl.mController )
822 value = impl.mController->GetTextColor();
826 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
828 if ( impl.mController )
830 value = impl.mController->GetPlaceholderTextColor();
834 case Toolkit::TextField::Property::SHADOW_OFFSET:
836 if ( impl.mController )
838 value = impl.mController->GetShadowOffset();
842 case Toolkit::TextField::Property::SHADOW_COLOR:
844 if ( impl.mController )
846 value = impl.mController->GetShadowColor();
850 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
852 if( impl.mDecorator )
854 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
858 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
860 if( impl.mDecorator )
862 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
866 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
868 value = impl.mController->GetEnableCursorBlink();
871 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
873 if( impl.mDecorator )
875 value = impl.mDecorator->GetCursorBlinkInterval();
879 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
881 if( impl.mDecorator )
883 value = impl.mDecorator->GetCursorBlinkDuration();
887 case Toolkit::TextField::Property::CURSOR_WIDTH:
889 if( impl.mDecorator )
891 value = impl.mDecorator->GetCursorWidth();
895 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
897 if( impl.mDecorator )
899 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
902 value = image.GetUrl();
907 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
909 if( impl.mDecorator )
911 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
914 value = image.GetUrl();
919 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
921 if( impl.mDecorator )
923 value = impl.mDecorator->GetScrollThreshold();
927 case Toolkit::TextField::Property::SCROLL_SPEED:
929 if( impl.mDecorator )
931 value = impl.mDecorator->GetScrollSpeed();
935 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
937 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
940 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
942 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
945 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
947 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
950 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
952 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
955 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
957 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
960 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
962 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
965 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
967 if( impl.mDecorator )
969 value = impl.mDecorator->GetHighlightColor();
973 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
975 if( impl.mDecorator )
977 Rect<int> boundingBox;
978 impl.mDecorator->GetBoundingBox( boundingBox );
983 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
987 case Toolkit::TextField::Property::INPUT_COLOR:
989 if( impl.mController )
991 value = impl.mController->GetInputColor();
995 case Toolkit::TextField::Property::ENABLE_MARKUP:
997 if( impl.mController )
999 value = impl.mController->IsMarkupProcessorEnabled();
1003 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1005 if( impl.mController )
1007 value = impl.mController->GetInputFontFamily();
1011 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1013 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1016 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1018 if( impl.mController )
1020 value = impl.mController->GetInputFontPointSize();
1024 case Toolkit::TextField::Property::UNDERLINE:
1026 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1029 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1031 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1034 case Toolkit::TextField::Property::SHADOW:
1036 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1039 case Toolkit::TextField::Property::INPUT_SHADOW:
1041 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1044 case Toolkit::TextField::Property::EMBOSS:
1046 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1049 case Toolkit::TextField::Property::INPUT_EMBOSS:
1051 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1054 case Toolkit::TextField::Property::OUTLINE:
1056 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1059 case Toolkit::TextField::Property::INPUT_OUTLINE:
1061 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1070 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1072 Dali::BaseHandle handle( object );
1074 bool connected( true );
1075 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1077 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1079 field.TextChangedSignal().Connect( tracker, functor );
1081 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1083 field.MaxLengthReachedSignal().Connect( tracker, functor );
1085 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1087 field.InputStyleChangedSignal().Connect( tracker, functor );
1091 // signalName does not match any signal
1098 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1100 return mTextChangedSignal;
1103 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1105 return mMaxLengthReachedSignal;
1108 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1110 return mInputStyleChangedSignal;
1113 void TextField::OnInitialize()
1115 Actor self = Self();
1117 mController = Text::Controller::New( *this );
1119 // When using the vector-based rendering, the size of the GLyphs are different
1120 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1121 mController->SetGlyphType( glyphType );
1123 mDecorator = Text::Decorator::New( *mController,
1126 mController->GetLayoutEngine().SetLayout( LayoutEngine::SINGLE_LINE_BOX );
1128 // Enables the text input.
1129 mController->EnableTextInput( mDecorator );
1131 // Enables the horizontal scrolling after the text input has been enabled.
1132 mController->SetHorizontalScrollEnabled( true );
1134 // Disables the vertical scrolling.
1135 mController->SetVerticalScrollEnabled( false );
1137 // Disable the smooth handle panning.
1138 mController->SetSmoothHandlePanEnabled( false );
1140 // Forward input events to controller
1141 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1142 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1144 self.TouchSignal().Connect( this, &TextField::OnTouched );
1146 // Set BoundingBox to stage size if not already set.
1147 Rect<int> boundingBox;
1148 mDecorator->GetBoundingBox( boundingBox );
1150 if( boundingBox.IsEmpty() )
1152 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1153 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1156 // Flip vertically the 'left' selection handle
1157 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1159 // Fill-parent area by default
1160 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1161 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1162 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1165 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1167 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1171 case StyleChange::DEFAULT_FONT_CHANGE:
1173 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1174 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1175 // Property system did not set the font so should update it.
1176 mController->UpdateAfterFontChange( newFont );
1180 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1182 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1185 case StyleChange::THEME_CHANGE:
1187 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1193 Vector3 TextField::GetNaturalSize()
1195 return mController->GetNaturalSize();
1198 float TextField::GetHeightForWidth( float width )
1200 return mController->GetHeightForWidth( width );
1203 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1205 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1207 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1209 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1212 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1215 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1217 mDecorator->Relayout( size );
1222 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1225 EnableClipping( ( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy ), size );
1226 RenderText( updateTextType );
1229 // The text-field emits signals when the input style changes. These changes of style are
1230 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1231 // can't be emitted during the size negotiation as the callbacks may update the UI.
1232 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1233 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1235 if( Adaptor::IsAvailable() )
1237 Adaptor& adaptor = Adaptor::Get();
1239 if( NULL == mIdleCallback )
1241 // @note: The callback manager takes the ownership of the callback object.
1242 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1243 adaptor.AddIdle( mIdleCallback );
1249 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1251 Actor self = Self();
1252 Actor renderableActor;
1254 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1258 renderableActor = mRenderer->Render( mController->GetView(), DepthIndex::TEXT );
1261 if( renderableActor != mRenderableActor )
1263 UnparentAndReset( mRenderableActor );
1264 mRenderableActor = renderableActor;
1268 if( mRenderableActor )
1270 const Vector2& scrollOffset = mController->GetScrollPosition();
1272 mRenderableActor.SetPosition( scrollOffset.x, scrollOffset.y );
1274 Actor clipRootActor;
1277 clipRootActor = mClipper->GetRootActor();
1280 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1281 endIt = mClippingDecorationActors.end();
1289 clipRootActor.Add( actor );
1296 mClippingDecorationActors.clear();
1298 // Make sure the actor is parented correctly with/without clipping
1301 clipRootActor.Add( mRenderableActor );
1305 self.Add( mRenderableActor );
1310 void TextField::OnKeyInputFocusGained()
1312 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1314 VirtualKeyboard::StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1316 ImfManager imfManager = ImfManager::Get();
1320 imfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1322 // Notify that the text editing start.
1323 imfManager.Activate();
1325 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1326 imfManager.SetRestoreAfterFocusLost( true );
1329 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1333 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1336 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1338 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1341 void TextField::OnKeyInputFocusLost()
1343 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1345 VirtualKeyboard::StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1347 ImfManager imfManager = ImfManager::Get();
1350 // The text editing is finished. Therefore the imf manager don't have restore activation.
1351 imfManager.SetRestoreAfterFocusLost( false );
1353 // Notify that the text editing finish.
1354 imfManager.Deactivate();
1356 imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1359 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1363 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1366 mController->KeyboardFocusLostEvent();
1368 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1371 void TextField::OnTap( const TapGesture& gesture )
1373 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1375 // Show the keyboard if it was hidden.
1376 if (!VirtualKeyboard::IsVisible())
1378 VirtualKeyboard::Show();
1381 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1382 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1387 void TextField::OnPan( const PanGesture& gesture )
1389 mController->PanEvent( gesture.state, gesture.displacement );
1392 void TextField::OnLongPress( const LongPressGesture& gesture )
1394 // Show the keyboard if it was hidden.
1395 if (!VirtualKeyboard::IsVisible())
1397 VirtualKeyboard::Show();
1400 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1405 bool TextField::OnKeyEvent( const KeyEvent& event )
1407 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1409 if( Dali::DALI_KEY_ESCAPE == event.keyCode ||
1410 "Return" == event.keyPressedName ) // Make a Dali key code for this
1412 ClearKeyInputFocus();
1416 return mController->KeyEvent( event );
1419 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1425 mClippingDecorationActors.push_back( actor );
1429 Self().Add( actor );
1434 void TextField::RequestTextRelayout()
1439 void TextField::TextChanged()
1441 Dali::Toolkit::TextField handle( GetOwner() );
1442 mTextChangedSignal.Emit( handle );
1445 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1447 Dali::Toolkit::TextField handle( GetOwner() );
1449 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1451 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1453 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1455 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1457 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1459 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1461 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1463 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1465 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1467 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1469 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1471 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1473 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1475 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1477 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1479 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1481 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1483 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1485 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1487 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1489 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1492 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1495 void TextField::OnStageConnect( Dali::Actor actor )
1497 if ( mHasBeenStaged )
1499 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1503 mHasBeenStaged = true;
1507 void TextField::MaxLengthReached()
1509 Dali::Toolkit::TextField handle( GetOwner() );
1510 mMaxLengthReachedSignal.Emit( handle );
1513 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1515 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1516 return mController->OnImfEvent( imfManager, imfEvent );
1519 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1523 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1528 Scripting::CreatePropertyMap( image, map );
1534 void TextField::EnableClipping( bool clipping, const Vector2& size )
1538 // Not worth to created clip actor if width or height is equal to zero.
1539 if( size.width > Math::MACHINE_EPSILON_1000 && size.height > Math::MACHINE_EPSILON_1000 )
1543 Actor self = Self();
1545 mClipper = Clipper::New( size );
1546 self.Add( mClipper->GetRootActor() );
1547 self.Add( mClipper->GetImageView() );
1549 else if ( mClipper )
1551 mClipper->Refresh( size );
1557 // Note - this will automatically remove the root actor & the image view
1562 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1564 mController->PasteClipboardItemEvent();
1567 void TextField::KeyboardStatusChanged(bool keyboardShown)
1569 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1571 // Just hide the grab handle when keyboard is hidden.
1572 if (!keyboardShown )
1574 mController->KeyboardFocusLostEvent();
1578 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1582 void TextField::OnStageConnection( int depth )
1584 // Call the Control::OnStageConnection() to set the depth of the background.
1585 Control::OnStageConnection( depth );
1587 // Sets the depth to the visuals inside the text's decorator.
1588 mDecorator->SetTextDepth( depth );
1590 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1593 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1598 void TextField::OnIdleSignal()
1600 // Emits the change of input style signals.
1601 mController->ProcessInputStyleChangedSignals();
1603 // Set the pointer to null as the callback manager deletes the callback after execute it.
1604 mIdleCallback = NULL;
1607 TextField::TextField()
1608 : Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
1609 mIdleCallback( NULL ),
1610 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1611 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1612 mHasBeenStaged( false )
1616 TextField::~TextField()
1620 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1622 Adaptor::Get().RemoveIdle( mIdleCallback );
1626 } // namespace Internal
1628 } // namespace Toolkit