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/devel-api/adaptor-framework/key-devel.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/devel-api/object/property-helper-devel.h>
28 #include <dali/devel-api/actors/actor-devel.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/integration-api/adaptors/adaptor.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/text/rendering-backend.h>
35 #include <dali-toolkit/public-api/text/text-enumerations.h>
36 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
48 using namespace Dali::Toolkit::Text;
59 namespace // unnamed namespace
62 #if defined(DEBUG_ENABLED)
63 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
66 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
67 } // unnamed namespace
74 return Toolkit::TextField::New();
77 // Setup properties, signals and actions using the type-registry.
78 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
80 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
135 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
136 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
137 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
139 DALI_TYPE_REGISTRATION_END()
143 Toolkit::TextField TextField::New()
145 // Create the implementation, temporarily owned by this handle on stack
146 IntrusivePtr< TextField > impl = new TextField();
148 // Pass ownership to CustomActor handle
149 Toolkit::TextField handle( *impl );
151 // Second-phase init of the implementation
152 // This can only be done after the CustomActor connection has been made...
158 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
160 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
162 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
167 TextField& impl( GetImpl( textField ) );
171 case Toolkit::TextField::Property::RENDERING_BACKEND:
173 int backend = value.Get< int >();
174 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
176 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
177 if( Text::RENDERING_VECTOR_BASED == backend )
179 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
182 if( impl.mRenderingBackend != backend )
184 impl.mRenderingBackend = backend;
185 impl.mRenderer.Reset();
187 if( impl.mController )
189 // When using the vector-based rendering, the size of the GLyphs are different
190 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
191 impl.mController->SetGlyphType( glyphType );
196 case Toolkit::TextField::Property::TEXT:
198 if( impl.mController )
200 const std::string& text = value.Get< std::string >();
201 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
203 impl.mController->SetText( text );
207 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
209 if( impl.mController )
211 const std::string& text = value.Get< std::string >();
212 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
214 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
218 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
220 if( impl.mController )
222 const std::string& text = value.Get< std::string >();
223 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
225 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
229 case Toolkit::TextField::Property::FONT_FAMILY:
231 if( impl.mController )
233 const std::string& fontFamily = value.Get< std::string >();
234 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
235 impl.mController->SetDefaultFontFamily( fontFamily );
239 case Toolkit::TextField::Property::FONT_STYLE:
241 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
244 case Toolkit::TextField::Property::POINT_SIZE:
246 if( impl.mController )
248 const float pointSize = value.Get< float >();
249 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
251 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
253 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
258 case Toolkit::TextField::Property::MAX_LENGTH:
260 if( impl.mController )
262 const int max = value.Get< int >();
263 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
265 impl.mController->SetMaximumNumberOfCharacters( max );
269 case Toolkit::TextField::Property::EXCEED_POLICY:
271 impl.mExceedPolicy = value.Get<int>();
273 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
275 impl.EnableClipping();
279 UnparentAndReset( impl.mStencil );
281 impl.RequestTextRelayout();
284 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
286 if( impl.mController )
288 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
289 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
291 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
292 impl.mController->SetHorizontalAlignment( alignment );
297 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
299 if( impl.mController )
301 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
302 if( GetVerticalAlignmentEnumeration( value, alignment ) )
304 impl.mController->SetVerticalAlignment( alignment );
305 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
310 case Toolkit::TextField::Property::TEXT_COLOR:
312 if( impl.mController )
314 const Vector4& textColor = value.Get< Vector4 >();
315 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 );
317 if( impl.mController->GetDefaultColor() != textColor )
319 impl.mController->SetDefaultColor( textColor );
320 impl.mController->SetInputColor( textColor );
321 impl.mRenderer.Reset();
326 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
328 if( impl.mController )
330 const Vector4& textColor = value.Get< Vector4 >();
331 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 );
333 if( impl.mController->GetPlaceholderTextColor() != textColor )
335 impl.mController->SetPlaceholderTextColor( textColor );
336 impl.mRenderer.Reset();
341 case Toolkit::TextField::Property::SHADOW_OFFSET:
343 if( impl.mController )
345 const Vector2& shadowOffset = value.Get< Vector2 >();
346 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
348 if ( impl.mController->GetShadowOffset() != shadowOffset )
350 impl.mController->SetShadowOffset( shadowOffset );
351 impl.mRenderer.Reset();
356 case Toolkit::TextField::Property::SHADOW_COLOR:
358 if( impl.mController )
360 const Vector4& shadowColor = value.Get< Vector4 >();
361 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 );
363 if ( impl.mController->GetShadowColor() != shadowColor )
365 impl.mController->SetShadowColor( shadowColor );
366 impl.mRenderer.Reset();
371 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
373 if( impl.mDecorator )
375 const Vector4& color = value.Get< Vector4 >();
376 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 );
378 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
379 impl.RequestTextRelayout();
383 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
385 if( impl.mDecorator )
387 const Vector4& color = value.Get< Vector4 >();
388 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 );
390 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
391 impl.RequestTextRelayout();
395 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
397 if( impl.mController )
399 const bool enable = value.Get< bool >();
400 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
402 impl.mController->SetEnableCursorBlink( enable );
403 impl.RequestTextRelayout();
407 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
409 if( impl.mDecorator )
411 const float interval = value.Get< float >();
412 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
414 impl.mDecorator->SetCursorBlinkInterval( interval );
418 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
420 if( impl.mDecorator )
422 const float duration = value.Get< float >();
423 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
425 impl.mDecorator->SetCursorBlinkDuration( duration );
429 case Toolkit::TextField::Property::CURSOR_WIDTH:
431 if( impl.mDecorator )
433 const int width = value.Get< int >();
434 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
436 impl.mDecorator->SetCursorWidth( width );
437 impl.mController->GetLayoutEngine().SetCursorWidth( width );
441 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
443 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
444 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
446 if( impl.mDecorator )
448 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
449 impl.RequestTextRelayout();
453 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
455 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
456 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
458 if( impl.mDecorator )
460 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
461 impl.RequestTextRelayout();
465 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
467 const float threshold = value.Get< float >();
468 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
470 if( impl.mDecorator )
472 impl.mDecorator->SetScrollThreshold( threshold );
476 case Toolkit::TextField::Property::SCROLL_SPEED:
478 const float speed = value.Get< float >();
479 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
481 if( impl.mDecorator )
483 impl.mDecorator->SetScrollSpeed( speed );
487 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
489 const Image image = Scripting::NewImage( value );
491 if( impl.mDecorator && image )
493 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
494 impl.RequestTextRelayout();
498 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
500 const Image image = Scripting::NewImage( value );
502 if( impl.mDecorator && image )
504 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
505 impl.RequestTextRelayout();
509 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
511 const Image image = Scripting::NewImage( value );
513 if( impl.mDecorator && image )
515 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
516 impl.RequestTextRelayout();
520 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
522 const Image image = Scripting::NewImage( value );
524 if( impl.mDecorator && image )
526 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
527 impl.RequestTextRelayout();
531 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
533 const Image image = Scripting::NewImage( value );
535 if( impl.mDecorator && image )
537 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
538 impl.RequestTextRelayout();
542 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
544 const Image image = Scripting::NewImage( value );
546 if( impl.mDecorator && image )
548 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
549 impl.RequestTextRelayout();
553 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
555 const Vector4 color = value.Get< Vector4 >();
556 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 );
558 if( impl.mDecorator )
560 impl.mDecorator->SetHighlightColor( color );
561 impl.RequestTextRelayout();
565 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
567 if( impl.mDecorator )
569 const Rect<int> box = value.Get< Rect<int> >();
570 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 );
572 impl.mDecorator->SetBoundingBox( box );
573 impl.RequestTextRelayout();
577 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
579 const Property::Map* map = value.GetMap();
582 impl.mInputMethodOptions.ApplyProperty( *map );
584 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
586 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
587 if (control == textField)
589 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
593 case Toolkit::TextField::Property::INPUT_COLOR:
595 if( impl.mController )
597 const Vector4 inputColor = value.Get< Vector4 >();
598 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 );
600 impl.mController->SetInputColor( inputColor );
604 case Toolkit::TextField::Property::ENABLE_MARKUP:
606 if( impl.mController )
608 const bool enableMarkup = value.Get<bool>();
609 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
611 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
615 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
617 if( impl.mController )
619 const std::string& fontFamily = value.Get< std::string >();
620 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
621 impl.mController->SetInputFontFamily( fontFamily );
625 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
627 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
630 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
632 if( impl.mController )
634 const float pointSize = value.Get< float >();
635 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
636 impl.mController->SetInputFontPointSize( pointSize );
640 case Toolkit::TextField::Property::UNDERLINE:
642 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
645 impl.mRenderer.Reset();
649 case Toolkit::TextField::Property::INPUT_UNDERLINE:
651 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
654 impl.mRenderer.Reset();
658 case Toolkit::TextField::Property::SHADOW:
660 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
663 impl.mRenderer.Reset();
667 case Toolkit::TextField::Property::INPUT_SHADOW:
669 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
672 impl.mRenderer.Reset();
676 case Toolkit::TextField::Property::EMBOSS:
678 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
681 impl.mRenderer.Reset();
685 case Toolkit::TextField::Property::INPUT_EMBOSS:
687 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
690 impl.mRenderer.Reset();
694 case Toolkit::TextField::Property::OUTLINE:
696 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
699 impl.mRenderer.Reset();
703 case Toolkit::TextField::Property::INPUT_OUTLINE:
705 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
708 impl.mRenderer.Reset();
712 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
714 const Property::Map* map = value.GetMap();
717 impl.mController->SetHiddenInputOption(*map);
721 case Toolkit::TextField::Property::PIXEL_SIZE:
723 if( impl.mController )
725 const float pixelSize = value.Get< float >();
726 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
728 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
730 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
735 case Toolkit::TextField::Property::ENABLE_SELECTION:
737 if( impl.mController )
739 const bool enableSelection = value.Get< bool >();
740 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
741 impl.mController->SetSelectionEnabled( enableSelection );
745 case Toolkit::TextField::Property::PLACEHOLDER:
747 const Property::Map* map = value.GetMap();
750 impl.mController->SetPlaceholderProperty( *map );
754 case Toolkit::TextField::Property::ELLIPSIS:
756 if( impl.mController )
758 const bool ellipsis = value.Get<bool>();
759 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
761 impl.mController->SetTextElideEnabled( ellipsis );
765 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
767 if( impl.mController )
769 const bool shiftSelection = value.Get<bool>();
770 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
772 impl.mController->SetShiftSelectionEnabled( shiftSelection );
776 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
778 if( impl.mController )
780 const bool grabHandleEnabled = value.Get<bool>();
781 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
783 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
791 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
793 Property::Value value;
795 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
799 TextField& impl( GetImpl( textField ) );
803 case Toolkit::TextField::Property::RENDERING_BACKEND:
805 value = impl.mRenderingBackend;
808 case Toolkit::TextField::Property::TEXT:
810 if( impl.mController )
813 impl.mController->GetText( text );
814 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
819 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
821 if( impl.mController )
824 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
829 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
831 if( impl.mController )
834 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
839 case Toolkit::TextField::Property::FONT_FAMILY:
841 if( impl.mController )
843 value = impl.mController->GetDefaultFontFamily();
847 case Toolkit::TextField::Property::FONT_STYLE:
849 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
852 case Toolkit::TextField::Property::POINT_SIZE:
854 if( impl.mController )
856 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
860 case Toolkit::TextField::Property::MAX_LENGTH:
862 if( impl.mController )
864 value = impl.mController->GetMaximumNumberOfCharacters();
868 case Toolkit::TextField::Property::EXCEED_POLICY:
870 value = impl.mExceedPolicy;
873 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
875 if( impl.mController )
877 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
881 value = std::string( name );
886 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
888 if( impl.mController )
890 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
894 value = std::string( name );
899 case Toolkit::TextField::Property::TEXT_COLOR:
901 if ( impl.mController )
903 value = impl.mController->GetDefaultColor();
907 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
909 if ( impl.mController )
911 value = impl.mController->GetPlaceholderTextColor();
915 case Toolkit::TextField::Property::SHADOW_OFFSET:
917 if ( impl.mController )
919 value = impl.mController->GetShadowOffset();
923 case Toolkit::TextField::Property::SHADOW_COLOR:
925 if ( impl.mController )
927 value = impl.mController->GetShadowColor();
931 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
933 if( impl.mDecorator )
935 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
939 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
941 if( impl.mDecorator )
943 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
947 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
949 value = impl.mController->GetEnableCursorBlink();
952 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
954 if( impl.mDecorator )
956 value = impl.mDecorator->GetCursorBlinkInterval();
960 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
962 if( impl.mDecorator )
964 value = impl.mDecorator->GetCursorBlinkDuration();
968 case Toolkit::TextField::Property::CURSOR_WIDTH:
970 if( impl.mDecorator )
972 value = impl.mDecorator->GetCursorWidth();
976 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
978 if( impl.mDecorator )
980 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
983 value = image.GetUrl();
988 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
990 if( impl.mDecorator )
992 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
995 value = image.GetUrl();
1000 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
1002 if( impl.mDecorator )
1004 value = impl.mDecorator->GetScrollThreshold();
1008 case Toolkit::TextField::Property::SCROLL_SPEED:
1010 if( impl.mDecorator )
1012 value = impl.mDecorator->GetScrollSpeed();
1016 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1018 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1021 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1023 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1026 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1028 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1031 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1033 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1036 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1038 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1041 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1043 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1046 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1048 if( impl.mDecorator )
1050 value = impl.mDecorator->GetHighlightColor();
1054 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1056 if( impl.mDecorator )
1058 Rect<int> boundingBox;
1059 impl.mDecorator->GetBoundingBox( boundingBox );
1060 value = boundingBox;
1064 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1067 impl.mInputMethodOptions.RetrieveProperty( map );
1071 case Toolkit::TextField::Property::INPUT_COLOR:
1073 if( impl.mController )
1075 value = impl.mController->GetInputColor();
1079 case Toolkit::TextField::Property::ENABLE_MARKUP:
1081 if( impl.mController )
1083 value = impl.mController->IsMarkupProcessorEnabled();
1087 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1089 if( impl.mController )
1091 value = impl.mController->GetInputFontFamily();
1095 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1097 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1100 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1102 if( impl.mController )
1104 value = impl.mController->GetInputFontPointSize();
1108 case Toolkit::TextField::Property::UNDERLINE:
1110 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1113 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1115 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1118 case Toolkit::TextField::Property::SHADOW:
1120 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1123 case Toolkit::TextField::Property::INPUT_SHADOW:
1125 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1128 case Toolkit::TextField::Property::EMBOSS:
1130 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1133 case Toolkit::TextField::Property::INPUT_EMBOSS:
1135 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1138 case Toolkit::TextField::Property::OUTLINE:
1140 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1143 case Toolkit::TextField::Property::INPUT_OUTLINE:
1145 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1148 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1151 impl.mController->GetHiddenInputOption(map);
1155 case Toolkit::TextField::Property::PIXEL_SIZE:
1157 if( impl.mController )
1159 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1163 case Toolkit::TextField::Property::ENABLE_SELECTION:
1165 if( impl.mController )
1167 value = impl.mController->IsSelectionEnabled();
1171 case Toolkit::TextField::Property::PLACEHOLDER:
1174 impl.mController->GetPlaceholderProperty( map );
1178 case Toolkit::TextField::Property::ELLIPSIS:
1180 if( impl.mController )
1182 value = impl.mController->IsTextElideEnabled();
1186 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1188 if( impl.mController )
1190 value = impl.mController->IsShiftSelectionEnabled();
1194 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1196 if( impl.mController )
1198 value = impl.mController->IsGrabHandleEnabled();
1208 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1210 Dali::BaseHandle handle( object );
1212 bool connected( true );
1213 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1215 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1217 field.TextChangedSignal().Connect( tracker, functor );
1219 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1221 field.MaxLengthReachedSignal().Connect( tracker, functor );
1223 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1225 field.InputStyleChangedSignal().Connect( tracker, functor );
1229 // signalName does not match any signal
1236 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1238 return mTextChangedSignal;
1241 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1243 return mMaxLengthReachedSignal;
1246 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1248 return mInputStyleChangedSignal;
1251 void TextField::OnInitialize()
1253 Actor self = Self();
1255 mController = Text::Controller::New( this, this );
1257 // When using the vector-based rendering, the size of the GLyphs are different
1258 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1259 mController->SetGlyphType( glyphType );
1261 mDecorator = Text::Decorator::New( *mController,
1264 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1266 // Enables the text input.
1267 mController->EnableTextInput( mDecorator );
1269 // Enables the horizontal scrolling after the text input has been enabled.
1270 mController->SetHorizontalScrollEnabled( true );
1272 // Disables the vertical scrolling.
1273 mController->SetVerticalScrollEnabled( false );
1275 // Disable the smooth handle panning.
1276 mController->SetSmoothHandlePanEnabled( false );
1278 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1279 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1281 // Forward input events to controller
1282 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1283 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1285 mImfManager = ImfManager::Get();
1287 self.TouchSignal().Connect( this, &TextField::OnTouched );
1289 // Set BoundingBox to stage size if not already set.
1290 Rect<int> boundingBox;
1291 mDecorator->GetBoundingBox( boundingBox );
1293 if( boundingBox.IsEmpty() )
1295 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1296 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1299 // Flip vertically the 'left' selection handle
1300 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1302 // Fill-parent area by default
1303 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1304 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1305 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1307 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1313 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1315 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1319 case StyleChange::DEFAULT_FONT_CHANGE:
1321 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1322 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1323 // Property system did not set the font so should update it.
1324 mController->UpdateAfterFontChange( newFont );
1329 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1331 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1335 case StyleChange::THEME_CHANGE:
1337 // Nothing to do, let control base class handle this
1342 // Up call to Control
1343 Control::OnStyleChange( styleManager, change );
1346 Vector3 TextField::GetNaturalSize()
1349 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1351 Vector3 naturalSize = mController->GetNaturalSize();
1352 naturalSize.width += ( padding.start + padding.end );
1353 naturalSize.height += ( padding.top + padding.bottom );
1358 float TextField::GetHeightForWidth( float width )
1361 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1362 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1365 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1367 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1369 Actor self = Self();
1372 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1374 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1376 // Support Right-To-Left of padding
1377 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1378 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1380 std::swap( padding.start, padding.end );
1385 mStencil.SetPosition( padding.start, padding.top );
1389 mActiveLayer.SetPosition( padding.start, padding.top );
1392 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
1394 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1397 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1400 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1402 mDecorator->Relayout( size );
1407 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1410 RenderText( updateTextType );
1414 // The text-field emits signals when the input style changes. These changes of style are
1415 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1416 // can't be emitted during the size negotiation as the callbacks may update the UI.
1417 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1418 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1420 if( Adaptor::IsAvailable() )
1422 Adaptor& adaptor = Adaptor::Get();
1424 if( NULL == mIdleCallback )
1426 // @note: The callback manager takes the ownership of the callback object.
1427 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1428 adaptor.AddIdle( mIdleCallback );
1434 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1436 Actor renderableActor;
1438 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1442 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1444 renderableActor = mRenderer->Render( mController->GetView(),
1446 Property::INVALID_INDEX, // Animatable property not supported
1448 DepthIndex::CONTENT );
1451 if( renderableActor != mRenderableActor )
1453 UnparentAndReset( mRenderableActor );
1454 mRenderableActor = renderableActor;
1458 if( mRenderableActor )
1460 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1464 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1469 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1471 // Support Right-To-Left of padding
1472 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1473 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1475 std::swap( padding.start, padding.end );
1478 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1482 // Make sure the actors are parented correctly with/without clipping
1483 Actor self = mStencil ? mStencil : Self();
1485 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1486 endIt = mClippingDecorationActors.end();
1491 it->LowerToBottom();
1493 mClippingDecorationActors.clear();
1495 self.Add( mRenderableActor );
1499 void TextField::OnKeyInputFocusGained()
1501 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1503 mImfManager.ApplyOptions( mInputMethodOptions );
1505 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1507 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1509 // Notify that the text editing start.
1510 mImfManager.Activate();
1512 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1513 mImfManager.SetRestoreAfterFocusLost( true );
1515 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1519 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1522 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1524 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1527 void TextField::OnKeyInputFocusLost()
1529 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1531 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1532 // The text editing is finished. Therefore the imf manager don't have restore activation.
1533 mImfManager.SetRestoreAfterFocusLost( false );
1535 // Notify that the text editing finish.
1536 mImfManager.Deactivate();
1538 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1540 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1544 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1547 mController->KeyboardFocusLostEvent();
1549 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1552 void TextField::OnTap( const TapGesture& gesture )
1554 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1556 mImfManager.Activate();
1558 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1560 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1561 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1566 void TextField::OnPan( const PanGesture& gesture )
1568 mController->PanEvent( gesture.state, gesture.displacement );
1571 void TextField::OnLongPress( const LongPressGesture& gesture )
1573 mImfManager.Activate();
1576 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1577 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1582 bool TextField::OnKeyEvent( const KeyEvent& event )
1584 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1586 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1588 // Make sure ClearKeyInputFocus when only key is up
1589 if( event.state == KeyEvent::Up )
1591 ClearKeyInputFocus();
1596 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1598 // Do nothing when enter is comming.
1602 return mController->KeyEvent( event );
1605 void TextField::RequestTextRelayout()
1610 void TextField::TextChanged()
1612 Dali::Toolkit::TextField handle( GetOwner() );
1613 mTextChangedSignal.Emit( handle );
1616 void TextField::MaxLengthReached()
1618 Dali::Toolkit::TextField handle( GetOwner() );
1619 mMaxLengthReachedSignal.Emit( handle );
1622 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1624 Dali::Toolkit::TextField handle( GetOwner() );
1626 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1628 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1630 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1632 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1634 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1636 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1638 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1640 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1642 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1644 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1646 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1648 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1650 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1652 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1654 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1656 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1658 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1660 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1662 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1664 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1666 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1669 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1672 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1678 mClippingDecorationActors.push_back( actor );
1682 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1683 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1684 Self().Add( actor );
1685 mActiveLayer = actor;
1690 void TextField::OnStageConnect( Dali::Actor actor )
1692 if ( mHasBeenStaged )
1694 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1698 mHasBeenStaged = true;
1702 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1704 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1705 return mController->OnImfEvent( imfManager, imfEvent );
1708 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1712 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1717 Scripting::CreatePropertyMap( image, map );
1723 void TextField::EnableClipping()
1727 // Creates an extra control to be used as stencil buffer.
1728 mStencil = Control::New();
1729 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1730 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1732 // Creates a background visual. Even if the color is transparent it updates the stencil.
1733 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1734 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1735 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1737 // Enable the clipping property.
1738 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1739 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1741 Self().Add( mStencil );
1745 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1747 mController->PasteClipboardItemEvent();
1750 void TextField::KeyboardStatusChanged(bool keyboardShown)
1752 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1754 // Just hide the grab handle when keyboard is hidden.
1755 if (!keyboardShown )
1757 mController->KeyboardFocusLostEvent();
1761 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1765 void TextField::OnStageConnection( int depth )
1767 // Sets the depth to the visuals inside the text's decorator.
1768 mDecorator->SetTextDepth( depth );
1770 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1772 // Call the Control::OnStageConnection() to set the depth of the background.
1773 Control::OnStageConnection( depth );
1776 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1781 void TextField::OnIdleSignal()
1783 // Emits the change of input style signals.
1784 mController->ProcessInputStyleChangedSignals();
1786 // Set the pointer to null as the callback manager deletes the callback after execute it.
1787 mIdleCallback = NULL;
1790 TextField::TextField()
1791 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1792 mIdleCallback( NULL ),
1793 mAlignmentOffset( 0.f ),
1794 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1795 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1796 mHasBeenStaged( false )
1800 TextField::~TextField()
1802 UnparentAndReset( mStencil );
1804 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1806 Adaptor::Get().RemoveIdle( mIdleCallback );
1810 } // namespace Internal
1812 } // namespace Toolkit