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 )
134 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
135 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
136 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
138 DALI_TYPE_REGISTRATION_END()
142 Toolkit::TextField TextField::New()
144 // Create the implementation, temporarily owned by this handle on stack
145 IntrusivePtr< TextField > impl = new TextField();
147 // Pass ownership to CustomActor handle
148 Toolkit::TextField handle( *impl );
150 // Second-phase init of the implementation
151 // This can only be done after the CustomActor connection has been made...
157 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
159 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
161 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
166 TextField& impl( GetImpl( textField ) );
170 case Toolkit::TextField::Property::RENDERING_BACKEND:
172 int backend = value.Get< int >();
173 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
175 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
176 if( Text::RENDERING_VECTOR_BASED == backend )
178 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
181 if( impl.mRenderingBackend != backend )
183 impl.mRenderingBackend = backend;
184 impl.mRenderer.Reset();
186 if( impl.mController )
188 // When using the vector-based rendering, the size of the GLyphs are different
189 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
190 impl.mController->SetGlyphType( glyphType );
195 case Toolkit::TextField::Property::TEXT:
197 if( impl.mController )
199 const std::string& text = value.Get< std::string >();
200 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
202 impl.mController->SetText( text );
206 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
208 if( impl.mController )
210 const std::string& text = value.Get< std::string >();
211 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
213 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
217 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
219 if( impl.mController )
221 const std::string& text = value.Get< std::string >();
222 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
224 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
228 case Toolkit::TextField::Property::FONT_FAMILY:
230 if( impl.mController )
232 const std::string& fontFamily = value.Get< std::string >();
233 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
234 impl.mController->SetDefaultFontFamily( fontFamily );
238 case Toolkit::TextField::Property::FONT_STYLE:
240 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
243 case Toolkit::TextField::Property::POINT_SIZE:
245 if( impl.mController )
247 const float pointSize = value.Get< float >();
248 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
250 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
252 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
257 case Toolkit::TextField::Property::MAX_LENGTH:
259 if( impl.mController )
261 const int max = value.Get< int >();
262 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
264 impl.mController->SetMaximumNumberOfCharacters( max );
268 case Toolkit::TextField::Property::EXCEED_POLICY:
270 impl.mExceedPolicy = value.Get<int>();
272 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
274 impl.EnableClipping();
278 UnparentAndReset( impl.mStencil );
280 impl.RequestTextRelayout();
283 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
285 if( impl.mController )
287 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
288 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
290 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
291 impl.mController->SetHorizontalAlignment( alignment );
296 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
298 if( impl.mController )
300 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
301 if( GetVerticalAlignmentEnumeration( value, alignment ) )
303 impl.mController->SetVerticalAlignment( alignment );
304 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
309 case Toolkit::TextField::Property::TEXT_COLOR:
311 if( impl.mController )
313 const Vector4& textColor = value.Get< Vector4 >();
314 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 );
316 if( impl.mController->GetDefaultColor() != textColor )
318 impl.mController->SetDefaultColor( textColor );
319 impl.mController->SetInputColor( textColor );
320 impl.mRenderer.Reset();
325 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
327 if( impl.mController )
329 const Vector4& textColor = value.Get< Vector4 >();
330 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 );
332 if( impl.mController->GetPlaceholderTextColor() != textColor )
334 impl.mController->SetPlaceholderTextColor( textColor );
335 impl.mRenderer.Reset();
340 case Toolkit::TextField::Property::SHADOW_OFFSET:
342 if( impl.mController )
344 const Vector2& shadowOffset = value.Get< Vector2 >();
345 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
347 if ( impl.mController->GetShadowOffset() != shadowOffset )
349 impl.mController->SetShadowOffset( shadowOffset );
350 impl.mRenderer.Reset();
355 case Toolkit::TextField::Property::SHADOW_COLOR:
357 if( impl.mController )
359 const Vector4& shadowColor = value.Get< Vector4 >();
360 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 );
362 if ( impl.mController->GetShadowColor() != shadowColor )
364 impl.mController->SetShadowColor( shadowColor );
365 impl.mRenderer.Reset();
370 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
372 if( impl.mDecorator )
374 const Vector4& color = value.Get< Vector4 >();
375 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 );
377 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
378 impl.RequestTextRelayout();
382 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
384 if( impl.mDecorator )
386 const Vector4& color = value.Get< Vector4 >();
387 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 );
389 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
390 impl.RequestTextRelayout();
394 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
396 if( impl.mController )
398 const bool enable = value.Get< bool >();
399 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
401 impl.mController->SetEnableCursorBlink( enable );
402 impl.RequestTextRelayout();
406 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
408 if( impl.mDecorator )
410 const float interval = value.Get< float >();
411 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
413 impl.mDecorator->SetCursorBlinkInterval( interval );
417 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
419 if( impl.mDecorator )
421 const float duration = value.Get< float >();
422 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
424 impl.mDecorator->SetCursorBlinkDuration( duration );
428 case Toolkit::TextField::Property::CURSOR_WIDTH:
430 if( impl.mDecorator )
432 const int width = value.Get< int >();
433 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
435 impl.mDecorator->SetCursorWidth( width );
436 impl.mController->GetLayoutEngine().SetCursorWidth( width );
440 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
442 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
443 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
445 if( impl.mDecorator )
447 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
448 impl.RequestTextRelayout();
452 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
454 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
457 if( impl.mDecorator )
459 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
460 impl.RequestTextRelayout();
464 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
466 const float threshold = value.Get< float >();
467 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
469 if( impl.mDecorator )
471 impl.mDecorator->SetScrollThreshold( threshold );
475 case Toolkit::TextField::Property::SCROLL_SPEED:
477 const float speed = value.Get< float >();
478 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
480 if( impl.mDecorator )
482 impl.mDecorator->SetScrollSpeed( speed );
486 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
488 const Image image = Scripting::NewImage( value );
490 if( impl.mDecorator && image )
492 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
493 impl.RequestTextRelayout();
497 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
499 const Image image = Scripting::NewImage( value );
501 if( impl.mDecorator && image )
503 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
504 impl.RequestTextRelayout();
508 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
510 const Image image = Scripting::NewImage( value );
512 if( impl.mDecorator && image )
514 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
515 impl.RequestTextRelayout();
519 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
521 const Image image = Scripting::NewImage( value );
523 if( impl.mDecorator && image )
525 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
526 impl.RequestTextRelayout();
530 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
532 const Image image = Scripting::NewImage( value );
534 if( impl.mDecorator && image )
536 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
537 impl.RequestTextRelayout();
541 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
543 const Image image = Scripting::NewImage( value );
545 if( impl.mDecorator && image )
547 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
548 impl.RequestTextRelayout();
552 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
554 const Vector4 color = value.Get< Vector4 >();
555 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 );
557 if( impl.mDecorator )
559 impl.mDecorator->SetHighlightColor( color );
560 impl.RequestTextRelayout();
564 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
566 if( impl.mDecorator )
568 const Rect<int> box = value.Get< Rect<int> >();
569 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 );
571 impl.mDecorator->SetBoundingBox( box );
572 impl.RequestTextRelayout();
576 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
578 const Property::Map* map = value.GetMap();
581 impl.mInputMethodOptions.ApplyProperty( *map );
583 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
585 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
586 if (control == textField)
588 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
592 case Toolkit::TextField::Property::INPUT_COLOR:
594 if( impl.mController )
596 const Vector4 inputColor = value.Get< Vector4 >();
597 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 );
599 impl.mController->SetInputColor( inputColor );
603 case Toolkit::TextField::Property::ENABLE_MARKUP:
605 if( impl.mController )
607 const bool enableMarkup = value.Get<bool>();
608 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
610 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
614 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
616 if( impl.mController )
618 const std::string& fontFamily = value.Get< std::string >();
619 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
620 impl.mController->SetInputFontFamily( fontFamily );
624 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
626 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
629 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
631 if( impl.mController )
633 const float pointSize = value.Get< float >();
634 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
635 impl.mController->SetInputFontPointSize( pointSize );
639 case Toolkit::TextField::Property::UNDERLINE:
641 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
644 impl.mRenderer.Reset();
648 case Toolkit::TextField::Property::INPUT_UNDERLINE:
650 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
653 impl.mRenderer.Reset();
657 case Toolkit::TextField::Property::SHADOW:
659 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
662 impl.mRenderer.Reset();
666 case Toolkit::TextField::Property::INPUT_SHADOW:
668 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
671 impl.mRenderer.Reset();
675 case Toolkit::TextField::Property::EMBOSS:
677 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
680 impl.mRenderer.Reset();
684 case Toolkit::TextField::Property::INPUT_EMBOSS:
686 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
689 impl.mRenderer.Reset();
693 case Toolkit::TextField::Property::OUTLINE:
695 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
698 impl.mRenderer.Reset();
702 case Toolkit::TextField::Property::INPUT_OUTLINE:
704 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
707 impl.mRenderer.Reset();
711 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
713 const Property::Map* map = value.GetMap();
716 impl.mController->SetHiddenInputOption(*map);
720 case Toolkit::TextField::Property::PIXEL_SIZE:
722 if( impl.mController )
724 const float pixelSize = value.Get< float >();
725 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
727 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
729 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
734 case Toolkit::TextField::Property::ENABLE_SELECTION:
736 if( impl.mController )
738 const bool enableSelection = value.Get< bool >();
739 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
740 impl.mController->SetSelectionEnabled( enableSelection );
744 case Toolkit::TextField::Property::PLACEHOLDER:
746 const Property::Map* map = value.GetMap();
749 impl.mController->SetPlaceholderProperty( *map );
753 case Toolkit::TextField::Property::ELLIPSIS:
755 if( impl.mController )
757 const bool ellipsis = value.Get<bool>();
758 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
760 impl.mController->SetTextElideEnabled( ellipsis );
764 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
766 if( impl.mController )
768 const bool shiftSelection = value.Get<bool>();
769 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
771 impl.mController->SetShiftSelectionEnabled( shiftSelection );
779 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
781 Property::Value value;
783 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
787 TextField& impl( GetImpl( textField ) );
791 case Toolkit::TextField::Property::RENDERING_BACKEND:
793 value = impl.mRenderingBackend;
796 case Toolkit::TextField::Property::TEXT:
798 if( impl.mController )
801 impl.mController->GetText( text );
802 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
807 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
809 if( impl.mController )
812 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
817 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
819 if( impl.mController )
822 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
827 case Toolkit::TextField::Property::FONT_FAMILY:
829 if( impl.mController )
831 value = impl.mController->GetDefaultFontFamily();
835 case Toolkit::TextField::Property::FONT_STYLE:
837 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
840 case Toolkit::TextField::Property::POINT_SIZE:
842 if( impl.mController )
844 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
848 case Toolkit::TextField::Property::MAX_LENGTH:
850 if( impl.mController )
852 value = impl.mController->GetMaximumNumberOfCharacters();
856 case Toolkit::TextField::Property::EXCEED_POLICY:
858 value = impl.mExceedPolicy;
861 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
863 if( impl.mController )
865 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
869 value = std::string( name );
874 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
876 if( impl.mController )
878 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
882 value = std::string( name );
887 case Toolkit::TextField::Property::TEXT_COLOR:
889 if ( impl.mController )
891 value = impl.mController->GetDefaultColor();
895 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
897 if ( impl.mController )
899 value = impl.mController->GetPlaceholderTextColor();
903 case Toolkit::TextField::Property::SHADOW_OFFSET:
905 if ( impl.mController )
907 value = impl.mController->GetShadowOffset();
911 case Toolkit::TextField::Property::SHADOW_COLOR:
913 if ( impl.mController )
915 value = impl.mController->GetShadowColor();
919 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
921 if( impl.mDecorator )
923 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
927 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
929 if( impl.mDecorator )
931 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
935 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
937 value = impl.mController->GetEnableCursorBlink();
940 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
942 if( impl.mDecorator )
944 value = impl.mDecorator->GetCursorBlinkInterval();
948 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
950 if( impl.mDecorator )
952 value = impl.mDecorator->GetCursorBlinkDuration();
956 case Toolkit::TextField::Property::CURSOR_WIDTH:
958 if( impl.mDecorator )
960 value = impl.mDecorator->GetCursorWidth();
964 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
966 if( impl.mDecorator )
968 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
971 value = image.GetUrl();
976 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
978 if( impl.mDecorator )
980 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
983 value = image.GetUrl();
988 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
990 if( impl.mDecorator )
992 value = impl.mDecorator->GetScrollThreshold();
996 case Toolkit::TextField::Property::SCROLL_SPEED:
998 if( impl.mDecorator )
1000 value = impl.mDecorator->GetScrollSpeed();
1004 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1006 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1009 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1011 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1014 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1016 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1019 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1021 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1024 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1026 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1029 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1031 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1034 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1036 if( impl.mDecorator )
1038 value = impl.mDecorator->GetHighlightColor();
1042 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1044 if( impl.mDecorator )
1046 Rect<int> boundingBox;
1047 impl.mDecorator->GetBoundingBox( boundingBox );
1048 value = boundingBox;
1052 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1055 impl.mInputMethodOptions.RetrieveProperty( map );
1059 case Toolkit::TextField::Property::INPUT_COLOR:
1061 if( impl.mController )
1063 value = impl.mController->GetInputColor();
1067 case Toolkit::TextField::Property::ENABLE_MARKUP:
1069 if( impl.mController )
1071 value = impl.mController->IsMarkupProcessorEnabled();
1075 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1077 if( impl.mController )
1079 value = impl.mController->GetInputFontFamily();
1083 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1085 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1088 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1090 if( impl.mController )
1092 value = impl.mController->GetInputFontPointSize();
1096 case Toolkit::TextField::Property::UNDERLINE:
1098 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1101 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1103 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1106 case Toolkit::TextField::Property::SHADOW:
1108 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1111 case Toolkit::TextField::Property::INPUT_SHADOW:
1113 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1116 case Toolkit::TextField::Property::EMBOSS:
1118 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1121 case Toolkit::TextField::Property::INPUT_EMBOSS:
1123 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1126 case Toolkit::TextField::Property::OUTLINE:
1128 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1131 case Toolkit::TextField::Property::INPUT_OUTLINE:
1133 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1136 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1139 impl.mController->GetHiddenInputOption(map);
1143 case Toolkit::TextField::Property::PIXEL_SIZE:
1145 if( impl.mController )
1147 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1151 case Toolkit::TextField::Property::ENABLE_SELECTION:
1153 if( impl.mController )
1155 value = impl.mController->IsSelectionEnabled();
1159 case Toolkit::TextField::Property::PLACEHOLDER:
1162 impl.mController->GetPlaceholderProperty( map );
1166 case Toolkit::TextField::Property::ELLIPSIS:
1168 if( impl.mController )
1170 value = impl.mController->IsTextElideEnabled();
1174 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1176 if( impl.mController )
1178 value = impl.mController->IsShiftSelectionEnabled();
1188 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1190 Dali::BaseHandle handle( object );
1192 bool connected( true );
1193 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1195 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1197 field.TextChangedSignal().Connect( tracker, functor );
1199 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1201 field.MaxLengthReachedSignal().Connect( tracker, functor );
1203 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1205 field.InputStyleChangedSignal().Connect( tracker, functor );
1209 // signalName does not match any signal
1216 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1218 return mTextChangedSignal;
1221 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1223 return mMaxLengthReachedSignal;
1226 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1228 return mInputStyleChangedSignal;
1231 void TextField::OnInitialize()
1233 Actor self = Self();
1235 mController = Text::Controller::New( this, this );
1237 // When using the vector-based rendering, the size of the GLyphs are different
1238 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1239 mController->SetGlyphType( glyphType );
1241 mDecorator = Text::Decorator::New( *mController,
1244 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1246 // Enables the text input.
1247 mController->EnableTextInput( mDecorator );
1249 // Enables the horizontal scrolling after the text input has been enabled.
1250 mController->SetHorizontalScrollEnabled( true );
1252 // Disables the vertical scrolling.
1253 mController->SetVerticalScrollEnabled( false );
1255 // Disable the smooth handle panning.
1256 mController->SetSmoothHandlePanEnabled( false );
1258 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1259 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1261 // Forward input events to controller
1262 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1263 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1265 mImfManager = ImfManager::Get();
1267 self.TouchSignal().Connect( this, &TextField::OnTouched );
1269 // Set BoundingBox to stage size if not already set.
1270 Rect<int> boundingBox;
1271 mDecorator->GetBoundingBox( boundingBox );
1273 if( boundingBox.IsEmpty() )
1275 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1276 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1279 // Flip vertically the 'left' selection handle
1280 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1282 // Fill-parent area by default
1283 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1284 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1285 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1287 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1293 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1295 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1299 case StyleChange::DEFAULT_FONT_CHANGE:
1301 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1302 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1303 // Property system did not set the font so should update it.
1304 mController->UpdateAfterFontChange( newFont );
1309 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1311 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1315 case StyleChange::THEME_CHANGE:
1317 // Nothing to do, let control base class handle this
1322 // Up call to Control
1323 Control::OnStyleChange( styleManager, change );
1326 Vector3 TextField::GetNaturalSize()
1329 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1331 Vector3 naturalSize = mController->GetNaturalSize();
1332 naturalSize.width += ( padding.start + padding.end );
1333 naturalSize.height += ( padding.top + padding.bottom );
1338 float TextField::GetHeightForWidth( float width )
1341 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1342 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1345 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1347 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1349 Actor self = Self();
1352 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1354 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1356 // Support Right-To-Left of padding
1357 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1358 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1360 std::swap( padding.start, padding.end );
1365 mStencil.SetPosition( padding.start, padding.top );
1369 mActiveLayer.SetPosition( padding.start, padding.top );
1372 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
1374 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1377 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1380 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1382 mDecorator->Relayout( size );
1387 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1390 RenderText( updateTextType );
1394 // The text-field emits signals when the input style changes. These changes of style are
1395 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1396 // can't be emitted during the size negotiation as the callbacks may update the UI.
1397 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1398 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1400 if( Adaptor::IsAvailable() )
1402 Adaptor& adaptor = Adaptor::Get();
1404 if( NULL == mIdleCallback )
1406 // @note: The callback manager takes the ownership of the callback object.
1407 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1408 adaptor.AddIdle( mIdleCallback );
1414 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1416 Actor renderableActor;
1418 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1422 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1424 renderableActor = mRenderer->Render( mController->GetView(),
1426 Property::INVALID_INDEX, // Animatable property not supported
1428 DepthIndex::CONTENT );
1431 if( renderableActor != mRenderableActor )
1433 UnparentAndReset( mRenderableActor );
1434 mRenderableActor = renderableActor;
1438 if( mRenderableActor )
1440 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1444 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1449 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1451 // Support Right-To-Left of padding
1452 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1453 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1455 std::swap( padding.start, padding.end );
1458 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1462 // Make sure the actors are parented correctly with/without clipping
1463 Actor self = mStencil ? mStencil : Self();
1465 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1466 endIt = mClippingDecorationActors.end();
1471 it->LowerToBottom();
1473 mClippingDecorationActors.clear();
1475 self.Add( mRenderableActor );
1479 void TextField::OnKeyInputFocusGained()
1481 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1483 mImfManager.ApplyOptions( mInputMethodOptions );
1485 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1487 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1489 // Notify that the text editing start.
1490 mImfManager.Activate();
1492 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1493 mImfManager.SetRestoreAfterFocusLost( true );
1495 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1499 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1502 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1504 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1507 void TextField::OnKeyInputFocusLost()
1509 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1511 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1512 // The text editing is finished. Therefore the imf manager don't have restore activation.
1513 mImfManager.SetRestoreAfterFocusLost( false );
1515 // Notify that the text editing finish.
1516 mImfManager.Deactivate();
1518 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1520 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1524 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1527 mController->KeyboardFocusLostEvent();
1529 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1532 void TextField::OnTap( const TapGesture& gesture )
1534 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1536 mImfManager.Activate();
1538 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1540 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1541 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1546 void TextField::OnPan( const PanGesture& gesture )
1548 mController->PanEvent( gesture.state, gesture.displacement );
1551 void TextField::OnLongPress( const LongPressGesture& gesture )
1553 mImfManager.Activate();
1556 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1557 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1562 bool TextField::OnKeyEvent( const KeyEvent& event )
1564 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1566 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1568 // Make sure ClearKeyInputFocus when only key is up
1569 if( event.state == KeyEvent::Up )
1571 ClearKeyInputFocus();
1576 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1578 // Do nothing when enter is comming.
1582 return mController->KeyEvent( event );
1585 void TextField::RequestTextRelayout()
1590 void TextField::TextChanged()
1592 Dali::Toolkit::TextField handle( GetOwner() );
1593 mTextChangedSignal.Emit( handle );
1596 void TextField::MaxLengthReached()
1598 Dali::Toolkit::TextField handle( GetOwner() );
1599 mMaxLengthReachedSignal.Emit( handle );
1602 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1604 Dali::Toolkit::TextField handle( GetOwner() );
1606 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1608 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1610 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1612 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1614 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1616 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1618 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1620 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1622 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1624 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1626 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1628 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1630 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1632 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1634 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1636 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1638 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1640 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1642 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1644 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1646 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1649 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1652 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1658 mClippingDecorationActors.push_back( actor );
1662 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1663 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1664 Self().Add( actor );
1665 mActiveLayer = actor;
1670 void TextField::OnStageConnect( Dali::Actor actor )
1672 if ( mHasBeenStaged )
1674 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1678 mHasBeenStaged = true;
1682 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1684 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1685 return mController->OnImfEvent( imfManager, imfEvent );
1688 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1692 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1697 Scripting::CreatePropertyMap( image, map );
1703 void TextField::EnableClipping()
1707 // Creates an extra control to be used as stencil buffer.
1708 mStencil = Control::New();
1709 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1710 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1712 // Creates a background visual. Even if the color is transparent it updates the stencil.
1713 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1714 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1715 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1717 // Enable the clipping property.
1718 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1719 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1721 Self().Add( mStencil );
1725 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1727 mController->PasteClipboardItemEvent();
1730 void TextField::KeyboardStatusChanged(bool keyboardShown)
1732 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1734 // Just hide the grab handle when keyboard is hidden.
1735 if (!keyboardShown )
1737 mController->KeyboardFocusLostEvent();
1741 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1745 void TextField::OnStageConnection( int depth )
1747 // Sets the depth to the visuals inside the text's decorator.
1748 mDecorator->SetTextDepth( depth );
1750 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1752 // Call the Control::OnStageConnection() to set the depth of the background.
1753 Control::OnStageConnection( depth );
1756 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1761 void TextField::OnIdleSignal()
1763 // Emits the change of input style signals.
1764 mController->ProcessInputStyleChangedSignals();
1766 // Set the pointer to null as the callback manager deletes the callback after execute it.
1767 mIdleCallback = NULL;
1770 TextField::TextField()
1771 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1772 mIdleCallback( NULL ),
1773 mAlignmentOffset( 0.f ),
1774 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1775 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1776 mHasBeenStaged( false )
1780 TextField::~TextField()
1782 UnparentAndReset( mStencil );
1784 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1786 Adaptor::Get().RemoveIdle( mIdleCallback );
1790 } // namespace Internal
1792 } // namespace Toolkit