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/public-api/visuals/visual-properties.h>
39 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
40 #include <dali-toolkit/internal/text/rendering/text-backend.h>
41 #include <dali-toolkit/internal/text/text-effects-style.h>
42 #include <dali-toolkit/internal/text/text-font-style.h>
43 #include <dali-toolkit/internal/text/text-view.h>
44 #include <dali-toolkit/internal/styling/style-manager-impl.h>
46 using namespace Dali::Toolkit::Text;
57 namespace // unnamed namespace
60 #if defined(DEBUG_ENABLED)
61 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
64 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
65 } // unnamed namespace
72 return Toolkit::TextField::New();
75 // Setup properties, signals and actions using the type-registry.
76 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
78 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
79 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
80 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
131 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
132 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
133 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
135 DALI_TYPE_REGISTRATION_END()
139 Toolkit::TextField TextField::New()
141 // Create the implementation, temporarily owned by this handle on stack
142 IntrusivePtr< TextField > impl = new TextField();
144 // Pass ownership to CustomActor handle
145 Toolkit::TextField handle( *impl );
147 // Second-phase init of the implementation
148 // This can only be done after the CustomActor connection has been made...
154 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
156 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
158 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
163 TextField& impl( GetImpl( textField ) );
167 case Toolkit::TextField::Property::RENDERING_BACKEND:
169 int backend = value.Get< int >();
170 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
172 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
173 if( Text::RENDERING_VECTOR_BASED == backend )
175 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
178 if( impl.mRenderingBackend != backend )
180 impl.mRenderingBackend = backend;
181 impl.mRenderer.Reset();
183 if( impl.mController )
185 // When using the vector-based rendering, the size of the GLyphs are different
186 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
187 impl.mController->SetGlyphType( glyphType );
192 case Toolkit::TextField::Property::TEXT:
194 if( impl.mController )
196 const std::string& text = value.Get< std::string >();
197 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
199 impl.mController->SetText( text );
203 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
205 if( impl.mController )
207 const std::string& text = value.Get< std::string >();
208 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
210 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
214 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
216 if( impl.mController )
218 const std::string& text = value.Get< std::string >();
219 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
221 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
225 case Toolkit::TextField::Property::FONT_FAMILY:
227 if( impl.mController )
229 const std::string& fontFamily = value.Get< std::string >();
230 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
231 impl.mController->SetDefaultFontFamily( fontFamily );
235 case Toolkit::TextField::Property::FONT_STYLE:
237 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
240 case Toolkit::TextField::Property::POINT_SIZE:
242 if( impl.mController )
244 const float pointSize = value.Get< float >();
245 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
247 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
249 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
254 case Toolkit::TextField::Property::MAX_LENGTH:
256 if( impl.mController )
258 const int max = value.Get< int >();
259 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
261 impl.mController->SetMaximumNumberOfCharacters( max );
265 case Toolkit::TextField::Property::EXCEED_POLICY:
267 impl.mExceedPolicy = value.Get<int>();
269 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
271 impl.EnableClipping();
275 UnparentAndReset( impl.mStencil );
277 impl.RequestTextRelayout();
280 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
282 if( impl.mController )
284 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
285 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
287 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
288 impl.mController->SetHorizontalAlignment( alignment );
293 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
295 if( impl.mController )
297 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
298 if( GetVerticalAlignmentEnumeration( value, alignment ) )
300 impl.mController->SetVerticalAlignment( alignment );
301 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
306 case Toolkit::TextField::Property::TEXT_COLOR:
308 if( impl.mController )
310 const Vector4& textColor = value.Get< Vector4 >();
311 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 );
313 if( impl.mController->GetDefaultColor() != textColor )
315 impl.mController->SetDefaultColor( textColor );
316 impl.mController->SetInputColor( textColor );
317 impl.mRenderer.Reset();
322 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
324 if( impl.mController )
326 const Vector4& textColor = value.Get< Vector4 >();
327 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 );
329 if( impl.mController->GetPlaceholderTextColor() != textColor )
331 impl.mController->SetPlaceholderTextColor( textColor );
332 impl.mRenderer.Reset();
337 case Toolkit::TextField::Property::SHADOW_OFFSET:
339 if( impl.mController )
341 const Vector2& shadowOffset = value.Get< Vector2 >();
342 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
344 if ( impl.mController->GetShadowOffset() != shadowOffset )
346 impl.mController->SetShadowOffset( shadowOffset );
347 impl.mRenderer.Reset();
352 case Toolkit::TextField::Property::SHADOW_COLOR:
354 if( impl.mController )
356 const Vector4& shadowColor = value.Get< Vector4 >();
357 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 );
359 if ( impl.mController->GetShadowColor() != shadowColor )
361 impl.mController->SetShadowColor( shadowColor );
362 impl.mRenderer.Reset();
367 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
369 if( impl.mDecorator )
371 const Vector4& color = value.Get< Vector4 >();
372 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 );
374 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
375 impl.RequestTextRelayout();
379 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
381 if( impl.mDecorator )
383 const Vector4& color = value.Get< Vector4 >();
384 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 );
386 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
387 impl.RequestTextRelayout();
391 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
393 if( impl.mController )
395 const bool enable = value.Get< bool >();
396 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
398 impl.mController->SetEnableCursorBlink( enable );
399 impl.RequestTextRelayout();
403 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
405 if( impl.mDecorator )
407 const float interval = value.Get< float >();
408 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
410 impl.mDecorator->SetCursorBlinkInterval( interval );
414 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
416 if( impl.mDecorator )
418 const float duration = value.Get< float >();
419 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
421 impl.mDecorator->SetCursorBlinkDuration( duration );
425 case Toolkit::TextField::Property::CURSOR_WIDTH:
427 if( impl.mDecorator )
429 const int width = value.Get< int >();
430 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
432 impl.mDecorator->SetCursorWidth( width );
433 impl.mController->GetLayoutEngine().SetCursorWidth( width );
437 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
439 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
440 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
442 if( impl.mDecorator )
444 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
445 impl.RequestTextRelayout();
449 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
451 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
452 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
454 if( impl.mDecorator )
456 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
457 impl.RequestTextRelayout();
461 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
463 const float threshold = value.Get< float >();
464 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
466 if( impl.mDecorator )
468 impl.mDecorator->SetScrollThreshold( threshold );
472 case Toolkit::TextField::Property::SCROLL_SPEED:
474 const float speed = value.Get< float >();
475 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
477 if( impl.mDecorator )
479 impl.mDecorator->SetScrollSpeed( speed );
483 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
485 const Image image = Scripting::NewImage( value );
487 if( impl.mDecorator && image )
489 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
490 impl.RequestTextRelayout();
494 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
496 const Image image = Scripting::NewImage( value );
498 if( impl.mDecorator && image )
500 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
501 impl.RequestTextRelayout();
505 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
507 const Image image = Scripting::NewImage( value );
509 if( impl.mDecorator && image )
511 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
512 impl.RequestTextRelayout();
516 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
518 const Image image = Scripting::NewImage( value );
520 if( impl.mDecorator && image )
522 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
523 impl.RequestTextRelayout();
527 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
529 const Image image = Scripting::NewImage( value );
531 if( impl.mDecorator && image )
533 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
534 impl.RequestTextRelayout();
538 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
540 const Image image = Scripting::NewImage( value );
542 if( impl.mDecorator && image )
544 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
545 impl.RequestTextRelayout();
549 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
551 const Vector4 color = value.Get< Vector4 >();
552 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 );
554 if( impl.mDecorator )
556 impl.mDecorator->SetHighlightColor( color );
557 impl.RequestTextRelayout();
561 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
563 if( impl.mDecorator )
565 const Rect<int> box = value.Get< Rect<int> >();
566 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 );
568 impl.mDecorator->SetBoundingBox( box );
569 impl.RequestTextRelayout();
573 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
575 const Property::Map* map = value.GetMap();
578 impl.mInputMethodOptions.ApplyProperty( *map );
580 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
582 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
583 if (control == textField)
585 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
589 case Toolkit::TextField::Property::INPUT_COLOR:
591 if( impl.mController )
593 const Vector4 inputColor = value.Get< Vector4 >();
594 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 );
596 impl.mController->SetInputColor( inputColor );
600 case Toolkit::TextField::Property::ENABLE_MARKUP:
602 if( impl.mController )
604 const bool enableMarkup = value.Get<bool>();
605 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
607 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
611 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
613 if( impl.mController )
615 const std::string& fontFamily = value.Get< std::string >();
616 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
617 impl.mController->SetInputFontFamily( fontFamily );
621 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
623 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
626 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
628 if( impl.mController )
630 const float pointSize = value.Get< float >();
631 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
632 impl.mController->SetInputFontPointSize( pointSize );
636 case Toolkit::TextField::Property::UNDERLINE:
638 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
641 impl.mRenderer.Reset();
645 case Toolkit::TextField::Property::INPUT_UNDERLINE:
647 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
650 impl.mRenderer.Reset();
654 case Toolkit::TextField::Property::SHADOW:
656 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
659 impl.mRenderer.Reset();
663 case Toolkit::TextField::Property::INPUT_SHADOW:
665 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
668 impl.mRenderer.Reset();
672 case Toolkit::TextField::Property::EMBOSS:
674 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
677 impl.mRenderer.Reset();
681 case Toolkit::TextField::Property::INPUT_EMBOSS:
683 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
686 impl.mRenderer.Reset();
690 case Toolkit::TextField::Property::OUTLINE:
692 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
695 impl.mRenderer.Reset();
699 case Toolkit::TextField::Property::INPUT_OUTLINE:
701 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
704 impl.mRenderer.Reset();
708 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
710 const Property::Map* map = value.GetMap();
713 impl.mController->SetHiddenInputOption(*map);
717 case Toolkit::TextField::Property::PIXEL_SIZE:
719 if( impl.mController )
721 const float pixelSize = value.Get< float >();
722 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
724 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
726 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
731 case Toolkit::TextField::Property::ENABLE_SELECTION:
733 if( impl.mController )
735 const bool enableSelection = value.Get< bool >();
736 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
737 impl.mController->SetSelectionEnabled( enableSelection );
741 case Toolkit::TextField::Property::PLACEHOLDER:
743 const Property::Map* map = value.GetMap();
746 impl.mController->SetPlaceholderProperty( *map );
750 case Toolkit::TextField::Property::ELLIPSIS:
752 if( impl.mController )
754 const bool ellipsis = value.Get<bool>();
755 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
757 impl.mController->SetTextElideEnabled( ellipsis );
765 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
767 Property::Value value;
769 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
773 TextField& impl( GetImpl( textField ) );
777 case Toolkit::TextField::Property::RENDERING_BACKEND:
779 value = impl.mRenderingBackend;
782 case Toolkit::TextField::Property::TEXT:
784 if( impl.mController )
787 impl.mController->GetText( text );
788 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
793 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
795 if( impl.mController )
798 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
803 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
805 if( impl.mController )
808 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
813 case Toolkit::TextField::Property::FONT_FAMILY:
815 if( impl.mController )
817 value = impl.mController->GetDefaultFontFamily();
821 case Toolkit::TextField::Property::FONT_STYLE:
823 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
826 case Toolkit::TextField::Property::POINT_SIZE:
828 if( impl.mController )
830 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
834 case Toolkit::TextField::Property::MAX_LENGTH:
836 if( impl.mController )
838 value = impl.mController->GetMaximumNumberOfCharacters();
842 case Toolkit::TextField::Property::EXCEED_POLICY:
844 value = impl.mExceedPolicy;
847 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
849 if( impl.mController )
851 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
855 value = std::string( name );
860 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
862 if( impl.mController )
864 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
868 value = std::string( name );
873 case Toolkit::TextField::Property::TEXT_COLOR:
875 if ( impl.mController )
877 value = impl.mController->GetDefaultColor();
881 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
883 if ( impl.mController )
885 value = impl.mController->GetPlaceholderTextColor();
889 case Toolkit::TextField::Property::SHADOW_OFFSET:
891 if ( impl.mController )
893 value = impl.mController->GetShadowOffset();
897 case Toolkit::TextField::Property::SHADOW_COLOR:
899 if ( impl.mController )
901 value = impl.mController->GetShadowColor();
905 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
907 if( impl.mDecorator )
909 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
913 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
915 if( impl.mDecorator )
917 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
921 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
923 value = impl.mController->GetEnableCursorBlink();
926 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
928 if( impl.mDecorator )
930 value = impl.mDecorator->GetCursorBlinkInterval();
934 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
936 if( impl.mDecorator )
938 value = impl.mDecorator->GetCursorBlinkDuration();
942 case Toolkit::TextField::Property::CURSOR_WIDTH:
944 if( impl.mDecorator )
946 value = impl.mDecorator->GetCursorWidth();
950 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
952 if( impl.mDecorator )
954 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
957 value = image.GetUrl();
962 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
964 if( impl.mDecorator )
966 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
969 value = image.GetUrl();
974 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
976 if( impl.mDecorator )
978 value = impl.mDecorator->GetScrollThreshold();
982 case Toolkit::TextField::Property::SCROLL_SPEED:
984 if( impl.mDecorator )
986 value = impl.mDecorator->GetScrollSpeed();
990 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
992 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
995 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
997 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1000 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1002 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1005 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1007 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1010 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1012 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1015 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1017 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1020 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1022 if( impl.mDecorator )
1024 value = impl.mDecorator->GetHighlightColor();
1028 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1030 if( impl.mDecorator )
1032 Rect<int> boundingBox;
1033 impl.mDecorator->GetBoundingBox( boundingBox );
1034 value = boundingBox;
1038 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1041 impl.mInputMethodOptions.RetrieveProperty( map );
1045 case Toolkit::TextField::Property::INPUT_COLOR:
1047 if( impl.mController )
1049 value = impl.mController->GetInputColor();
1053 case Toolkit::TextField::Property::ENABLE_MARKUP:
1055 if( impl.mController )
1057 value = impl.mController->IsMarkupProcessorEnabled();
1061 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1063 if( impl.mController )
1065 value = impl.mController->GetInputFontFamily();
1069 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1071 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1074 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1076 if( impl.mController )
1078 value = impl.mController->GetInputFontPointSize();
1082 case Toolkit::TextField::Property::UNDERLINE:
1084 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1087 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1089 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1092 case Toolkit::TextField::Property::SHADOW:
1094 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1097 case Toolkit::TextField::Property::INPUT_SHADOW:
1099 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1102 case Toolkit::TextField::Property::EMBOSS:
1104 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1107 case Toolkit::TextField::Property::INPUT_EMBOSS:
1109 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1112 case Toolkit::TextField::Property::OUTLINE:
1114 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1117 case Toolkit::TextField::Property::INPUT_OUTLINE:
1119 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1122 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1125 impl.mController->GetHiddenInputOption(map);
1129 case Toolkit::TextField::Property::PIXEL_SIZE:
1131 if( impl.mController )
1133 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1137 case Toolkit::TextField::Property::ENABLE_SELECTION:
1139 if( impl.mController )
1141 value = impl.mController->IsSelectionEnabled();
1145 case Toolkit::TextField::Property::PLACEHOLDER:
1148 impl.mController->GetPlaceholderProperty( map );
1152 case Toolkit::TextField::Property::ELLIPSIS:
1154 if( impl.mController )
1156 value = impl.mController->IsTextElideEnabled();
1166 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1168 Dali::BaseHandle handle( object );
1170 bool connected( true );
1171 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1173 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1175 field.TextChangedSignal().Connect( tracker, functor );
1177 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1179 field.MaxLengthReachedSignal().Connect( tracker, functor );
1181 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1183 field.InputStyleChangedSignal().Connect( tracker, functor );
1187 // signalName does not match any signal
1194 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1196 return mTextChangedSignal;
1199 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1201 return mMaxLengthReachedSignal;
1204 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1206 return mInputStyleChangedSignal;
1209 void TextField::OnInitialize()
1211 Actor self = Self();
1213 mController = Text::Controller::New( this, this );
1215 // When using the vector-based rendering, the size of the GLyphs are different
1216 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1217 mController->SetGlyphType( glyphType );
1219 mDecorator = Text::Decorator::New( *mController,
1222 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1224 // Enables the text input.
1225 mController->EnableTextInput( mDecorator );
1227 // Enables the horizontal scrolling after the text input has been enabled.
1228 mController->SetHorizontalScrollEnabled( true );
1230 // Disables the vertical scrolling.
1231 mController->SetVerticalScrollEnabled( false );
1233 // Disable the smooth handle panning.
1234 mController->SetSmoothHandlePanEnabled( false );
1236 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1237 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1239 // Forward input events to controller
1240 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1241 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1243 mImfManager = ImfManager::Get();
1245 self.TouchSignal().Connect( this, &TextField::OnTouched );
1247 // Set BoundingBox to stage size if not already set.
1248 Rect<int> boundingBox;
1249 mDecorator->GetBoundingBox( boundingBox );
1251 if( boundingBox.IsEmpty() )
1253 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1254 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1257 // Flip vertically the 'left' selection handle
1258 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1260 // Fill-parent area by default
1261 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1262 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1263 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1265 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1271 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1273 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1277 case StyleChange::DEFAULT_FONT_CHANGE:
1279 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1280 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1281 // Property system did not set the font so should update it.
1282 mController->UpdateAfterFontChange( newFont );
1287 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1289 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1293 case StyleChange::THEME_CHANGE:
1295 // Nothing to do, let control base class handle this
1300 // Up call to Control
1301 Control::OnStyleChange( styleManager, change );
1304 Vector3 TextField::GetNaturalSize()
1306 return mController->GetNaturalSize();
1309 float TextField::GetHeightForWidth( float width )
1312 Self().GetPadding( padding );
1313 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1316 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1318 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1320 Actor self = Self();
1323 self.GetPadding( padding );
1324 Vector2 contentSize( size.x - ( padding.left + padding.right ), size.y - ( padding.top + padding.bottom ) );
1328 mStencil.SetPosition( padding.left , padding.top );
1332 mActiveLayer.SetPosition( padding.left , padding.top );
1335 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
1337 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1340 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1343 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1345 mDecorator->Relayout( size );
1350 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1353 RenderText( updateTextType );
1357 // The text-field emits signals when the input style changes. These changes of style are
1358 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1359 // can't be emitted during the size negotiation as the callbacks may update the UI.
1360 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1361 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1363 if( Adaptor::IsAvailable() )
1365 Adaptor& adaptor = Adaptor::Get();
1367 if( NULL == mIdleCallback )
1369 // @note: The callback manager takes the ownership of the callback object.
1370 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1371 adaptor.AddIdle( mIdleCallback );
1377 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1379 Actor renderableActor;
1381 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1385 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1387 renderableActor = mRenderer->Render( mController->GetView(),
1389 Property::INVALID_INDEX, // Animatable property not supported
1391 DepthIndex::CONTENT );
1394 if( renderableActor != mRenderableActor )
1396 UnparentAndReset( mRenderableActor );
1397 mRenderableActor = renderableActor;
1401 if( mRenderableActor )
1403 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1407 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1412 Self().GetPadding( padding );
1413 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.left, scrollOffset.y + padding.top );
1417 // Make sure the actors are parented correctly with/without clipping
1418 Actor self = mStencil ? mStencil : Self();
1420 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1421 endIt = mClippingDecorationActors.end();
1426 it->LowerToBottom();
1428 mClippingDecorationActors.clear();
1430 self.Add( mRenderableActor );
1434 void TextField::OnKeyInputFocusGained()
1436 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1438 mImfManager.ApplyOptions( mInputMethodOptions );
1440 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1442 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1444 // Notify that the text editing start.
1445 mImfManager.Activate();
1447 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1448 mImfManager.SetRestoreAfterFocusLost( true );
1450 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1454 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1457 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1459 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1462 void TextField::OnKeyInputFocusLost()
1464 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1466 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1467 // The text editing is finished. Therefore the imf manager don't have restore activation.
1468 mImfManager.SetRestoreAfterFocusLost( false );
1470 // Notify that the text editing finish.
1471 mImfManager.Deactivate();
1473 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1475 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1479 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1482 mController->KeyboardFocusLostEvent();
1484 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1487 void TextField::OnTap( const TapGesture& gesture )
1489 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1491 mImfManager.Activate();
1493 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1495 Self().GetPadding( padding );
1496 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.left, gesture.localPoint.y - padding.top );
1501 void TextField::OnPan( const PanGesture& gesture )
1503 mController->PanEvent( gesture.state, gesture.displacement );
1506 void TextField::OnLongPress( const LongPressGesture& gesture )
1508 mImfManager.Activate();
1511 Self().GetPadding( padding );
1512 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.left, gesture.localPoint.y - padding.top );
1517 bool TextField::OnKeyEvent( const KeyEvent& event )
1519 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1521 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1523 // Make sure ClearKeyInputFocus when only key is up
1524 if( event.state == KeyEvent::Up )
1526 ClearKeyInputFocus();
1532 return mController->KeyEvent( event );
1535 void TextField::RequestTextRelayout()
1540 void TextField::TextChanged()
1542 Dali::Toolkit::TextField handle( GetOwner() );
1543 mTextChangedSignal.Emit( handle );
1546 void TextField::MaxLengthReached()
1548 Dali::Toolkit::TextField handle( GetOwner() );
1549 mMaxLengthReachedSignal.Emit( handle );
1552 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1554 Dali::Toolkit::TextField handle( GetOwner() );
1556 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1558 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1560 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1562 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1564 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1566 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1568 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1570 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1572 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1574 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1576 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1578 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1580 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1582 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1584 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1586 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1588 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1590 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1592 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1594 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1596 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1599 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1602 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1608 mClippingDecorationActors.push_back( actor );
1612 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1613 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1614 Self().Add( actor );
1615 mActiveLayer = actor;
1620 void TextField::OnStageConnect( Dali::Actor actor )
1622 if ( mHasBeenStaged )
1624 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1628 mHasBeenStaged = true;
1632 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1634 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1635 return mController->OnImfEvent( imfManager, imfEvent );
1638 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1642 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1647 Scripting::CreatePropertyMap( image, map );
1653 void TextField::EnableClipping()
1657 // Creates an extra control to be used as stencil buffer.
1658 mStencil = Control::New();
1659 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1660 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1662 // Creates a background visual. Even if the color is transparent it updates the stencil.
1663 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1664 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1665 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1667 // Enable the clipping property.
1668 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1669 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1671 Self().Add( mStencil );
1675 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1677 mController->PasteClipboardItemEvent();
1680 void TextField::KeyboardStatusChanged(bool keyboardShown)
1682 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1684 // Just hide the grab handle when keyboard is hidden.
1685 if (!keyboardShown )
1687 mController->KeyboardFocusLostEvent();
1691 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1695 void TextField::OnStageConnection( int depth )
1697 // Sets the depth to the visuals inside the text's decorator.
1698 mDecorator->SetTextDepth( depth );
1700 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1702 // Call the Control::OnStageConnection() to set the depth of the background.
1703 Control::OnStageConnection( depth );
1706 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1711 void TextField::OnIdleSignal()
1713 // Emits the change of input style signals.
1714 mController->ProcessInputStyleChangedSignals();
1716 // Set the pointer to null as the callback manager deletes the callback after execute it.
1717 mIdleCallback = NULL;
1720 TextField::TextField()
1721 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1722 mIdleCallback( NULL ),
1723 mAlignmentOffset( 0.f ),
1724 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1725 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1726 mHasBeenStaged( false )
1730 TextField::~TextField()
1732 UnparentAndReset( mStencil );
1734 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1736 Adaptor::Get().RemoveIdle( mIdleCallback );
1740 } // namespace Internal
1742 } // namespace Toolkit