2 * Copyright (c) 2017 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/object/property-helper-devel.h>
27 #include <dali/devel-api/actors/actor-devel.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/adaptors/adaptor.h>
30 #include <dali/integration-api/debug.h>
33 #include <dali-toolkit/public-api/text/rendering-backend.h>
34 #include <dali-toolkit/public-api/text/text-enumerations.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
39 #include <dali-toolkit/public-api/visuals/visual-properties.h>
40 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-font-style.h>
44 #include <dali-toolkit/internal/text/text-view.h>
45 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 using namespace Dali::Toolkit::Text;
58 namespace // unnamed namespace
61 #if defined(DEBUG_ENABLED)
62 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
65 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
66 } // unnamed namespace
73 return Toolkit::TextField::New();
76 // Setup properties, signals and actions using the type-registry.
77 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
79 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
80 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
133 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
134 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
135 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
137 DALI_TYPE_REGISTRATION_END()
141 Toolkit::TextField TextField::New()
143 // Create the implementation, temporarily owned by this handle on stack
144 IntrusivePtr< TextField > impl = new TextField();
146 // Pass ownership to CustomActor handle
147 Toolkit::TextField handle( *impl );
149 // Second-phase init of the implementation
150 // This can only be done after the CustomActor connection has been made...
156 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
158 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
160 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
165 TextField& impl( GetImpl( textField ) );
169 case Toolkit::TextField::Property::RENDERING_BACKEND:
171 int backend = value.Get< int >();
172 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
174 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
175 if( Text::RENDERING_VECTOR_BASED == backend )
177 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
180 if( impl.mRenderingBackend != backend )
182 impl.mRenderingBackend = backend;
183 impl.mRenderer.Reset();
185 if( impl.mController )
187 // When using the vector-based rendering, the size of the GLyphs are different
188 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
189 impl.mController->SetGlyphType( glyphType );
194 case Toolkit::TextField::Property::TEXT:
196 if( impl.mController )
198 const std::string& text = value.Get< std::string >();
199 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
201 impl.mController->SetText( text );
205 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
207 if( impl.mController )
209 const std::string& text = value.Get< std::string >();
210 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
212 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
216 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
218 if( impl.mController )
220 const std::string& text = value.Get< std::string >();
221 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
223 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
227 case Toolkit::TextField::Property::FONT_FAMILY:
229 if( impl.mController )
231 const std::string& fontFamily = value.Get< std::string >();
232 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
233 impl.mController->SetDefaultFontFamily( fontFamily );
237 case Toolkit::TextField::Property::FONT_STYLE:
239 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
242 case Toolkit::TextField::Property::POINT_SIZE:
244 if( impl.mController )
246 const float pointSize = value.Get< float >();
247 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
249 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
251 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
256 case Toolkit::TextField::Property::MAX_LENGTH:
258 if( impl.mController )
260 const int max = value.Get< int >();
261 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
263 impl.mController->SetMaximumNumberOfCharacters( max );
267 case Toolkit::TextField::Property::EXCEED_POLICY:
269 impl.mExceedPolicy = value.Get<int>();
271 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
273 impl.EnableClipping();
277 UnparentAndReset( impl.mStencil );
279 impl.RequestTextRelayout();
282 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
284 if( impl.mController )
286 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
287 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
289 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
290 impl.mController->SetHorizontalAlignment( alignment );
295 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
297 if( impl.mController )
299 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
300 if( GetVerticalAlignmentEnumeration( value, alignment ) )
302 impl.mController->SetVerticalAlignment( alignment );
303 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
308 case Toolkit::TextField::Property::TEXT_COLOR:
310 if( impl.mController )
312 const Vector4& textColor = value.Get< Vector4 >();
313 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 );
315 if( impl.mController->GetDefaultColor() != textColor )
317 impl.mController->SetDefaultColor( textColor );
318 impl.mController->SetInputColor( textColor );
319 impl.mRenderer.Reset();
324 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
326 if( impl.mController )
328 const Vector4& textColor = value.Get< Vector4 >();
329 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 );
331 if( impl.mController->GetPlaceholderTextColor() != textColor )
333 impl.mController->SetPlaceholderTextColor( textColor );
334 impl.mRenderer.Reset();
339 case Toolkit::TextField::Property::SHADOW_OFFSET:
341 if( impl.mController )
343 const Vector2& shadowOffset = value.Get< Vector2 >();
344 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
346 if ( impl.mController->GetShadowOffset() != shadowOffset )
348 impl.mController->SetShadowOffset( shadowOffset );
349 impl.mRenderer.Reset();
354 case Toolkit::TextField::Property::SHADOW_COLOR:
356 if( impl.mController )
358 const Vector4& shadowColor = value.Get< Vector4 >();
359 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 );
361 if ( impl.mController->GetShadowColor() != shadowColor )
363 impl.mController->SetShadowColor( shadowColor );
364 impl.mRenderer.Reset();
369 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
371 if( impl.mDecorator )
373 const Vector4& color = value.Get< Vector4 >();
374 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 );
376 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
377 impl.RequestTextRelayout();
381 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
383 if( impl.mDecorator )
385 const Vector4& color = value.Get< Vector4 >();
386 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 );
388 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
389 impl.RequestTextRelayout();
393 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
395 if( impl.mController )
397 const bool enable = value.Get< bool >();
398 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
400 impl.mController->SetEnableCursorBlink( enable );
401 impl.RequestTextRelayout();
405 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
407 if( impl.mDecorator )
409 const float interval = value.Get< float >();
410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
412 impl.mDecorator->SetCursorBlinkInterval( interval );
416 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
418 if( impl.mDecorator )
420 const float duration = value.Get< float >();
421 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
423 impl.mDecorator->SetCursorBlinkDuration( duration );
427 case Toolkit::TextField::Property::CURSOR_WIDTH:
429 if( impl.mDecorator )
431 const int width = value.Get< int >();
432 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
434 impl.mDecorator->SetCursorWidth( width );
435 impl.mController->GetLayoutEngine().SetCursorWidth( width );
439 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
441 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
442 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
444 if( impl.mDecorator )
446 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
447 impl.RequestTextRelayout();
451 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
453 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
454 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
456 if( impl.mDecorator )
458 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
459 impl.RequestTextRelayout();
463 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
465 const float threshold = value.Get< float >();
466 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
468 if( impl.mDecorator )
470 impl.mDecorator->SetScrollThreshold( threshold );
474 case Toolkit::TextField::Property::SCROLL_SPEED:
476 const float speed = value.Get< float >();
477 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
479 if( impl.mDecorator )
481 impl.mDecorator->SetScrollSpeed( speed );
485 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
487 const Image image = Scripting::NewImage( value );
489 if( impl.mDecorator && image )
491 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
492 impl.RequestTextRelayout();
496 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
498 const Image image = Scripting::NewImage( value );
500 if( impl.mDecorator && image )
502 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
503 impl.RequestTextRelayout();
507 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
509 const Image image = Scripting::NewImage( value );
511 if( impl.mDecorator && image )
513 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
514 impl.RequestTextRelayout();
518 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
520 const Image image = Scripting::NewImage( value );
522 if( impl.mDecorator && image )
524 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
525 impl.RequestTextRelayout();
529 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
531 const Image image = Scripting::NewImage( value );
533 if( impl.mDecorator && image )
535 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
536 impl.RequestTextRelayout();
540 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
542 const Image image = Scripting::NewImage( value );
544 if( impl.mDecorator && image )
546 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
547 impl.RequestTextRelayout();
551 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
553 const Vector4 color = value.Get< Vector4 >();
554 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 );
556 if( impl.mDecorator )
558 impl.mDecorator->SetHighlightColor( color );
559 impl.RequestTextRelayout();
563 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
565 if( impl.mDecorator )
567 const Rect<int> box = value.Get< Rect<int> >();
568 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 );
570 impl.mDecorator->SetBoundingBox( box );
571 impl.RequestTextRelayout();
575 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
577 const Property::Map* map = value.GetMap();
580 impl.mInputMethodOptions.ApplyProperty( *map );
582 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
584 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
585 if (control == textField)
587 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
591 case Toolkit::TextField::Property::INPUT_COLOR:
593 if( impl.mController )
595 const Vector4 inputColor = value.Get< Vector4 >();
596 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 );
598 impl.mController->SetInputColor( inputColor );
602 case Toolkit::TextField::Property::ENABLE_MARKUP:
604 if( impl.mController )
606 const bool enableMarkup = value.Get<bool>();
607 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
609 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
613 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
615 if( impl.mController )
617 const std::string& fontFamily = value.Get< std::string >();
618 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
619 impl.mController->SetInputFontFamily( fontFamily );
623 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
625 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
628 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
630 if( impl.mController )
632 const float pointSize = value.Get< float >();
633 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
634 impl.mController->SetInputFontPointSize( pointSize );
638 case Toolkit::TextField::Property::UNDERLINE:
640 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
643 impl.mRenderer.Reset();
647 case Toolkit::TextField::Property::INPUT_UNDERLINE:
649 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
652 impl.mRenderer.Reset();
656 case Toolkit::TextField::Property::SHADOW:
658 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
661 impl.mRenderer.Reset();
665 case Toolkit::TextField::Property::INPUT_SHADOW:
667 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
670 impl.mRenderer.Reset();
674 case Toolkit::TextField::Property::EMBOSS:
676 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
679 impl.mRenderer.Reset();
683 case Toolkit::TextField::Property::INPUT_EMBOSS:
685 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
688 impl.mRenderer.Reset();
692 case Toolkit::TextField::Property::OUTLINE:
694 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
697 impl.mRenderer.Reset();
701 case Toolkit::TextField::Property::INPUT_OUTLINE:
703 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
706 impl.mRenderer.Reset();
710 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
712 const Property::Map* map = value.GetMap();
715 impl.mController->SetHiddenInputOption(*map);
719 case Toolkit::TextField::Property::PIXEL_SIZE:
721 if( impl.mController )
723 const float pixelSize = value.Get< float >();
724 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
726 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
728 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
733 case Toolkit::TextField::Property::ENABLE_SELECTION:
735 if( impl.mController )
737 const bool enableSelection = value.Get< bool >();
738 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
739 impl.mController->SetSelectionEnabled( enableSelection );
743 case Toolkit::TextField::Property::PLACEHOLDER:
745 const Property::Map* map = value.GetMap();
748 impl.mController->SetPlaceholderProperty( *map );
752 case Toolkit::TextField::Property::ELLIPSIS:
754 if( impl.mController )
756 const bool ellipsis = value.Get<bool>();
757 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
759 impl.mController->SetTextElideEnabled( ellipsis );
763 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
765 if( impl.mController )
767 const bool shiftSelection = value.Get<bool>();
768 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
770 impl.mController->SetShiftSelectionEnabled( shiftSelection );
778 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
780 Property::Value value;
782 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
786 TextField& impl( GetImpl( textField ) );
790 case Toolkit::TextField::Property::RENDERING_BACKEND:
792 value = impl.mRenderingBackend;
795 case Toolkit::TextField::Property::TEXT:
797 if( impl.mController )
800 impl.mController->GetText( text );
801 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
806 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
808 if( impl.mController )
811 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
816 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
818 if( impl.mController )
821 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
826 case Toolkit::TextField::Property::FONT_FAMILY:
828 if( impl.mController )
830 value = impl.mController->GetDefaultFontFamily();
834 case Toolkit::TextField::Property::FONT_STYLE:
836 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
839 case Toolkit::TextField::Property::POINT_SIZE:
841 if( impl.mController )
843 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
847 case Toolkit::TextField::Property::MAX_LENGTH:
849 if( impl.mController )
851 value = impl.mController->GetMaximumNumberOfCharacters();
855 case Toolkit::TextField::Property::EXCEED_POLICY:
857 value = impl.mExceedPolicy;
860 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
862 if( impl.mController )
864 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
868 value = std::string( name );
873 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
875 if( impl.mController )
877 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
881 value = std::string( name );
886 case Toolkit::TextField::Property::TEXT_COLOR:
888 if ( impl.mController )
890 value = impl.mController->GetDefaultColor();
894 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
896 if ( impl.mController )
898 value = impl.mController->GetPlaceholderTextColor();
902 case Toolkit::TextField::Property::SHADOW_OFFSET:
904 if ( impl.mController )
906 value = impl.mController->GetShadowOffset();
910 case Toolkit::TextField::Property::SHADOW_COLOR:
912 if ( impl.mController )
914 value = impl.mController->GetShadowColor();
918 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
920 if( impl.mDecorator )
922 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
926 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
928 if( impl.mDecorator )
930 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
934 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
936 value = impl.mController->GetEnableCursorBlink();
939 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
941 if( impl.mDecorator )
943 value = impl.mDecorator->GetCursorBlinkInterval();
947 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
949 if( impl.mDecorator )
951 value = impl.mDecorator->GetCursorBlinkDuration();
955 case Toolkit::TextField::Property::CURSOR_WIDTH:
957 if( impl.mDecorator )
959 value = impl.mDecorator->GetCursorWidth();
963 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
965 if( impl.mDecorator )
967 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
970 value = image.GetUrl();
975 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
977 if( impl.mDecorator )
979 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
982 value = image.GetUrl();
987 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
989 if( impl.mDecorator )
991 value = impl.mDecorator->GetScrollThreshold();
995 case Toolkit::TextField::Property::SCROLL_SPEED:
997 if( impl.mDecorator )
999 value = impl.mDecorator->GetScrollSpeed();
1003 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1005 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1008 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1010 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1013 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1015 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1018 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1020 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1023 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1025 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1028 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1030 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1033 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1035 if( impl.mDecorator )
1037 value = impl.mDecorator->GetHighlightColor();
1041 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1043 if( impl.mDecorator )
1045 Rect<int> boundingBox;
1046 impl.mDecorator->GetBoundingBox( boundingBox );
1047 value = boundingBox;
1051 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1054 impl.mInputMethodOptions.RetrieveProperty( map );
1058 case Toolkit::TextField::Property::INPUT_COLOR:
1060 if( impl.mController )
1062 value = impl.mController->GetInputColor();
1066 case Toolkit::TextField::Property::ENABLE_MARKUP:
1068 if( impl.mController )
1070 value = impl.mController->IsMarkupProcessorEnabled();
1074 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1076 if( impl.mController )
1078 value = impl.mController->GetInputFontFamily();
1082 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1084 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1087 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1089 if( impl.mController )
1091 value = impl.mController->GetInputFontPointSize();
1095 case Toolkit::TextField::Property::UNDERLINE:
1097 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1100 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1102 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1105 case Toolkit::TextField::Property::SHADOW:
1107 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1110 case Toolkit::TextField::Property::INPUT_SHADOW:
1112 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1115 case Toolkit::TextField::Property::EMBOSS:
1117 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1120 case Toolkit::TextField::Property::INPUT_EMBOSS:
1122 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1125 case Toolkit::TextField::Property::OUTLINE:
1127 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1130 case Toolkit::TextField::Property::INPUT_OUTLINE:
1132 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1135 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1138 impl.mController->GetHiddenInputOption(map);
1142 case Toolkit::TextField::Property::PIXEL_SIZE:
1144 if( impl.mController )
1146 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1150 case Toolkit::TextField::Property::ENABLE_SELECTION:
1152 if( impl.mController )
1154 value = impl.mController->IsSelectionEnabled();
1158 case Toolkit::TextField::Property::PLACEHOLDER:
1161 impl.mController->GetPlaceholderProperty( map );
1165 case Toolkit::TextField::Property::ELLIPSIS:
1167 if( impl.mController )
1169 value = impl.mController->IsTextElideEnabled();
1173 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1175 if( impl.mController )
1177 value = impl.mController->IsShiftSelectionEnabled();
1187 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1189 Dali::BaseHandle handle( object );
1191 bool connected( true );
1192 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1194 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1196 field.TextChangedSignal().Connect( tracker, functor );
1198 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1200 field.MaxLengthReachedSignal().Connect( tracker, functor );
1202 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1204 field.InputStyleChangedSignal().Connect( tracker, functor );
1208 // signalName does not match any signal
1215 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1217 return mTextChangedSignal;
1220 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1222 return mMaxLengthReachedSignal;
1225 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1227 return mInputStyleChangedSignal;
1230 void TextField::OnInitialize()
1232 Actor self = Self();
1234 mController = Text::Controller::New( this, this );
1236 // When using the vector-based rendering, the size of the GLyphs are different
1237 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1238 mController->SetGlyphType( glyphType );
1240 mDecorator = Text::Decorator::New( *mController,
1243 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1245 // Enables the text input.
1246 mController->EnableTextInput( mDecorator );
1248 // Enables the horizontal scrolling after the text input has been enabled.
1249 mController->SetHorizontalScrollEnabled( true );
1251 // Disables the vertical scrolling.
1252 mController->SetVerticalScrollEnabled( false );
1254 // Disable the smooth handle panning.
1255 mController->SetSmoothHandlePanEnabled( false );
1257 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1258 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1260 // Forward input events to controller
1261 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1262 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1264 mImfManager = ImfManager::Get();
1266 self.TouchSignal().Connect( this, &TextField::OnTouched );
1268 // Set BoundingBox to stage size if not already set.
1269 Rect<int> boundingBox;
1270 mDecorator->GetBoundingBox( boundingBox );
1272 if( boundingBox.IsEmpty() )
1274 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1275 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1278 // Flip vertically the 'left' selection handle
1279 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1281 // Fill-parent area by default
1282 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1283 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1284 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1286 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1292 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1294 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1298 case StyleChange::DEFAULT_FONT_CHANGE:
1300 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1301 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1302 // Property system did not set the font so should update it.
1303 mController->UpdateAfterFontChange( newFont );
1308 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1310 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1314 case StyleChange::THEME_CHANGE:
1316 // Nothing to do, let control base class handle this
1321 // Up call to Control
1322 Control::OnStyleChange( styleManager, change );
1325 Vector3 TextField::GetNaturalSize()
1328 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1330 Vector3 naturalSize = mController->GetNaturalSize();
1331 naturalSize.width += ( padding.start + padding.end );
1332 naturalSize.height += ( padding.top + padding.bottom );
1337 float TextField::GetHeightForWidth( float width )
1340 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1341 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1344 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1346 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1348 Actor self = Self();
1351 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1353 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1355 // Support Right-To-Left of padding
1356 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1357 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1359 std::swap( padding.start, padding.end );
1364 mStencil.SetPosition( padding.start, padding.top );
1368 mActiveLayer.SetPosition( padding.start, padding.top );
1371 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
1373 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1379 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1381 mDecorator->Relayout( size );
1386 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1389 RenderText( updateTextType );
1393 // The text-field emits signals when the input style changes. These changes of style are
1394 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1395 // can't be emitted during the size negotiation as the callbacks may update the UI.
1396 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1397 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1399 if( Adaptor::IsAvailable() )
1401 Adaptor& adaptor = Adaptor::Get();
1403 if( NULL == mIdleCallback )
1405 // @note: The callback manager takes the ownership of the callback object.
1406 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1407 adaptor.AddIdle( mIdleCallback );
1413 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1415 Actor renderableActor;
1417 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1421 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1423 renderableActor = mRenderer->Render( mController->GetView(),
1425 Property::INVALID_INDEX, // Animatable property not supported
1427 DepthIndex::CONTENT );
1430 if( renderableActor != mRenderableActor )
1432 UnparentAndReset( mRenderableActor );
1433 mRenderableActor = renderableActor;
1437 if( mRenderableActor )
1439 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1443 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1448 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1450 // Support Right-To-Left of padding
1451 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1452 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1454 std::swap( padding.start, padding.end );
1457 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1461 // Make sure the actors are parented correctly with/without clipping
1462 Actor self = mStencil ? mStencil : Self();
1464 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1465 endIt = mClippingDecorationActors.end();
1470 it->LowerToBottom();
1472 mClippingDecorationActors.clear();
1474 self.Add( mRenderableActor );
1478 void TextField::OnKeyInputFocusGained()
1480 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1482 mImfManager.ApplyOptions( mInputMethodOptions );
1484 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1486 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1488 // Notify that the text editing start.
1489 mImfManager.Activate();
1491 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1492 mImfManager.SetRestoreAfterFocusLost( true );
1494 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1498 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1501 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1503 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1506 void TextField::OnKeyInputFocusLost()
1508 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1510 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1511 // The text editing is finished. Therefore the imf manager don't have restore activation.
1512 mImfManager.SetRestoreAfterFocusLost( false );
1514 // Notify that the text editing finish.
1515 mImfManager.Deactivate();
1517 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1519 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1523 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1526 mController->KeyboardFocusLostEvent();
1528 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1531 void TextField::OnTap( const TapGesture& gesture )
1533 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1535 mImfManager.Activate();
1537 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1539 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1540 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1545 void TextField::OnPan( const PanGesture& gesture )
1547 mController->PanEvent( gesture.state, gesture.displacement );
1550 void TextField::OnLongPress( const LongPressGesture& gesture )
1552 mImfManager.Activate();
1555 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1556 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1561 bool TextField::OnKeyEvent( const KeyEvent& event )
1563 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1565 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1567 // Make sure ClearKeyInputFocus when only key is up
1568 if( event.state == KeyEvent::Up )
1570 ClearKeyInputFocus();
1576 return mController->KeyEvent( event );
1579 void TextField::RequestTextRelayout()
1584 void TextField::TextChanged()
1586 Dali::Toolkit::TextField handle( GetOwner() );
1587 mTextChangedSignal.Emit( handle );
1590 void TextField::MaxLengthReached()
1592 Dali::Toolkit::TextField handle( GetOwner() );
1593 mMaxLengthReachedSignal.Emit( handle );
1596 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1598 Dali::Toolkit::TextField handle( GetOwner() );
1600 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1602 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1604 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1606 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1608 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1610 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1612 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1614 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1616 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1618 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1620 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1622 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1624 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1626 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1628 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1630 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1632 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1634 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1636 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1638 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1640 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1643 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1646 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1652 mClippingDecorationActors.push_back( actor );
1656 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1657 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1658 Self().Add( actor );
1659 mActiveLayer = actor;
1664 void TextField::OnStageConnect( Dali::Actor actor )
1666 if ( mHasBeenStaged )
1668 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1672 mHasBeenStaged = true;
1676 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1678 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1679 return mController->OnImfEvent( imfManager, imfEvent );
1682 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1686 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1691 Scripting::CreatePropertyMap( image, map );
1697 void TextField::EnableClipping()
1701 // Creates an extra control to be used as stencil buffer.
1702 mStencil = Control::New();
1703 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1704 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1706 // Creates a background visual. Even if the color is transparent it updates the stencil.
1707 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1708 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1709 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1711 // Enable the clipping property.
1712 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1713 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1715 Self().Add( mStencil );
1719 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1721 mController->PasteClipboardItemEvent();
1724 void TextField::KeyboardStatusChanged(bool keyboardShown)
1726 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1728 // Just hide the grab handle when keyboard is hidden.
1729 if (!keyboardShown )
1731 mController->KeyboardFocusLostEvent();
1735 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1739 void TextField::OnStageConnection( int depth )
1741 // Sets the depth to the visuals inside the text's decorator.
1742 mDecorator->SetTextDepth( depth );
1744 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1746 // Call the Control::OnStageConnection() to set the depth of the background.
1747 Control::OnStageConnection( depth );
1750 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1755 void TextField::OnIdleSignal()
1757 // Emits the change of input style signals.
1758 mController->ProcessInputStyleChangedSignals();
1760 // Set the pointer to null as the callback manager deletes the callback after execute it.
1761 mIdleCallback = NULL;
1764 TextField::TextField()
1765 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1766 mIdleCallback( NULL ),
1767 mAlignmentOffset( 0.f ),
1768 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1769 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1770 mHasBeenStaged( false )
1774 TextField::~TextField()
1776 UnparentAndReset( mStencil );
1778 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1780 Adaptor::Get().RemoveIdle( mIdleCallback );
1784 } // namespace Internal
1786 } // namespace Toolkit