2 * Copyright (c) 2018 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>
47 #include <dali-toolkit/devel-api/controls/control-devel.h>
49 using namespace Dali::Toolkit::Text;
60 namespace // unnamed namespace
63 #if defined(DEBUG_ENABLED)
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
67 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
68 } // unnamed namespace
75 return Toolkit::TextField::New();
78 // Setup properties, signals and actions using the type-registry.
79 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
137 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
138 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
139 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
141 DALI_TYPE_REGISTRATION_END()
145 Toolkit::TextField TextField::New()
147 // Create the implementation, temporarily owned by this handle on stack
148 IntrusivePtr< TextField > impl = new TextField();
150 // Pass ownership to CustomActor handle
151 Toolkit::TextField handle( *impl );
153 // Second-phase init of the implementation
154 // This can only be done after the CustomActor connection has been made...
160 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
162 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
164 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
169 TextField& impl( GetImpl( textField ) );
173 case Toolkit::TextField::Property::RENDERING_BACKEND:
175 int backend = value.Get< int >();
176 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
178 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
179 if( Text::RENDERING_VECTOR_BASED == backend )
181 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
184 if( impl.mRenderingBackend != backend )
186 impl.mRenderingBackend = backend;
187 impl.mRenderer.Reset();
189 if( impl.mController )
191 // When using the vector-based rendering, the size of the GLyphs are different
192 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
193 impl.mController->SetGlyphType( glyphType );
198 case Toolkit::TextField::Property::TEXT:
200 if( impl.mController )
202 const std::string& text = value.Get< std::string >();
203 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
205 impl.mController->SetText( text );
209 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
211 if( impl.mController )
213 const std::string& text = value.Get< std::string >();
214 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
216 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
220 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
222 if( impl.mController )
224 const std::string& text = value.Get< std::string >();
225 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
227 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
231 case Toolkit::TextField::Property::FONT_FAMILY:
233 if( impl.mController )
235 const std::string& fontFamily = value.Get< std::string >();
236 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
237 impl.mController->SetDefaultFontFamily( fontFamily );
241 case Toolkit::TextField::Property::FONT_STYLE:
243 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
246 case Toolkit::TextField::Property::POINT_SIZE:
248 if( impl.mController )
250 const float pointSize = value.Get< float >();
251 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
253 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
255 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
260 case Toolkit::TextField::Property::MAX_LENGTH:
262 if( impl.mController )
264 const int max = value.Get< int >();
265 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
267 impl.mController->SetMaximumNumberOfCharacters( max );
271 case Toolkit::TextField::Property::EXCEED_POLICY:
273 impl.mExceedPolicy = value.Get<int>();
275 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
277 impl.EnableClipping();
281 UnparentAndReset( impl.mStencil );
283 impl.RequestTextRelayout();
286 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
288 if( impl.mController )
290 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
291 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
293 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
294 impl.mController->SetHorizontalAlignment( alignment );
299 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
301 if( impl.mController )
303 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
304 if( GetVerticalAlignmentEnumeration( value, alignment ) )
306 impl.mController->SetVerticalAlignment( alignment );
307 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
312 case Toolkit::TextField::Property::TEXT_COLOR:
314 if( impl.mController )
316 const Vector4& textColor = value.Get< Vector4 >();
317 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
319 if( impl.mController->GetDefaultColor() != textColor )
321 impl.mController->SetDefaultColor( textColor );
322 impl.mController->SetInputColor( textColor );
323 impl.mRenderer.Reset();
328 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
330 if( impl.mController )
332 const Vector4& textColor = value.Get< Vector4 >();
333 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), textColor.r, textColor.g, textColor.b, textColor.a );
335 if( impl.mController->GetPlaceholderTextColor() != textColor )
337 impl.mController->SetPlaceholderTextColor( textColor );
338 impl.mRenderer.Reset();
343 case Toolkit::TextField::Property::SHADOW_OFFSET:
345 if( impl.mController )
347 const Vector2& shadowOffset = value.Get< Vector2 >();
348 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
350 if ( impl.mController->GetShadowOffset() != shadowOffset )
352 impl.mController->SetShadowOffset( shadowOffset );
353 impl.mRenderer.Reset();
358 case Toolkit::TextField::Property::SHADOW_COLOR:
360 if( impl.mController )
362 const Vector4& shadowColor = value.Get< Vector4 >();
363 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_COLOR %f,%f,%f,%f\n", impl.mController.Get(), shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a );
365 if ( impl.mController->GetShadowColor() != shadowColor )
367 impl.mController->SetShadowColor( shadowColor );
368 impl.mRenderer.Reset();
373 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
375 if( impl.mDecorator )
377 const Vector4& color = value.Get< Vector4 >();
378 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PRIMARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
380 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
381 impl.RequestTextRelayout();
385 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
387 if( impl.mDecorator )
389 const Vector4& color = value.Get< Vector4 >();
390 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SECONDARY_CURSOR_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
392 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
393 impl.RequestTextRelayout();
397 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
399 if( impl.mController )
401 const bool enable = value.Get< bool >();
402 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
404 impl.mController->SetEnableCursorBlink( enable );
405 impl.RequestTextRelayout();
409 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
411 if( impl.mDecorator )
413 const float interval = value.Get< float >();
414 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
416 impl.mDecorator->SetCursorBlinkInterval( interval );
420 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
422 if( impl.mDecorator )
424 const float duration = value.Get< float >();
425 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
427 impl.mDecorator->SetCursorBlinkDuration( duration );
431 case Toolkit::TextField::Property::CURSOR_WIDTH:
433 if( impl.mDecorator )
435 const int width = value.Get< int >();
436 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
438 impl.mDecorator->SetCursorWidth( width );
439 impl.mController->GetLayoutEngine().SetCursorWidth( width );
443 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
445 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
446 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
448 if( impl.mDecorator )
450 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
451 impl.RequestTextRelayout();
455 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
457 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
458 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
460 if( impl.mDecorator )
462 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
463 impl.RequestTextRelayout();
467 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
469 const float threshold = value.Get< float >();
470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
472 if( impl.mDecorator )
474 impl.mDecorator->SetScrollThreshold( threshold );
478 case Toolkit::TextField::Property::SCROLL_SPEED:
480 const float speed = value.Get< float >();
481 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
483 if( impl.mDecorator )
485 impl.mDecorator->SetScrollSpeed( speed );
489 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
491 const Image image = Scripting::NewImage( value );
493 if( impl.mDecorator && image )
495 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
496 impl.RequestTextRelayout();
500 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
502 const Image image = Scripting::NewImage( value );
504 if( impl.mDecorator && image )
506 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
507 impl.RequestTextRelayout();
511 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
513 const Image image = Scripting::NewImage( value );
515 if( impl.mDecorator && image )
517 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
518 impl.RequestTextRelayout();
522 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
524 const Image image = Scripting::NewImage( value );
526 if( impl.mDecorator && image )
528 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
529 impl.RequestTextRelayout();
533 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
535 const Image image = Scripting::NewImage( value );
537 if( impl.mDecorator && image )
539 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
540 impl.RequestTextRelayout();
544 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
546 const Image image = Scripting::NewImage( value );
548 if( impl.mDecorator && image )
550 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
551 impl.RequestTextRelayout();
555 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
557 const Vector4 color = value.Get< Vector4 >();
558 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTION_HIGHLIGHT_COLOR %f,%f,%f,%f\n", impl.mController.Get(), color.r, color.g, color.b, color.a );
560 if( impl.mDecorator )
562 impl.mDecorator->SetHighlightColor( color );
563 impl.RequestTextRelayout();
567 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
569 if( impl.mDecorator )
571 const Rect<int> box = value.Get< Rect<int> >();
572 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p DECORATION_BOUNDING_BOX %d,%d %dx%d\n", impl.mController.Get(), box.x, box.y, box.width, box.height );
574 impl.mDecorator->SetBoundingBox( box );
575 impl.RequestTextRelayout();
579 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
581 const Property::Map* map = value.GetMap();
584 impl.mInputMethodOptions.ApplyProperty( *map );
586 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
588 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
589 if (control == textField)
591 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
595 case Toolkit::TextField::Property::INPUT_COLOR:
597 if( impl.mController )
599 const Vector4 inputColor = value.Get< Vector4 >();
600 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 );
602 impl.mController->SetInputColor( inputColor );
606 case Toolkit::TextField::Property::ENABLE_MARKUP:
608 if( impl.mController )
610 const bool enableMarkup = value.Get<bool>();
611 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
613 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
617 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
619 if( impl.mController )
621 const std::string& fontFamily = value.Get< std::string >();
622 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
623 impl.mController->SetInputFontFamily( fontFamily );
627 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
629 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
632 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
634 if( impl.mController )
636 const float pointSize = value.Get< float >();
637 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
638 impl.mController->SetInputFontPointSize( pointSize );
642 case Toolkit::TextField::Property::UNDERLINE:
644 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
647 impl.mRenderer.Reset();
651 case Toolkit::TextField::Property::INPUT_UNDERLINE:
653 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
656 impl.mRenderer.Reset();
660 case Toolkit::TextField::Property::SHADOW:
662 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
665 impl.mRenderer.Reset();
669 case Toolkit::TextField::Property::INPUT_SHADOW:
671 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
674 impl.mRenderer.Reset();
678 case Toolkit::TextField::Property::EMBOSS:
680 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
683 impl.mRenderer.Reset();
687 case Toolkit::TextField::Property::INPUT_EMBOSS:
689 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
692 impl.mRenderer.Reset();
696 case Toolkit::TextField::Property::OUTLINE:
698 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
701 impl.mRenderer.Reset();
705 case Toolkit::TextField::Property::INPUT_OUTLINE:
707 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
710 impl.mRenderer.Reset();
714 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
716 const Property::Map* map = value.GetMap();
719 impl.mController->SetHiddenInputOption(*map);
723 case Toolkit::TextField::Property::PIXEL_SIZE:
725 if( impl.mController )
727 const float pixelSize = value.Get< float >();
728 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
730 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
732 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
737 case Toolkit::TextField::Property::ENABLE_SELECTION:
739 if( impl.mController )
741 const bool enableSelection = value.Get< bool >();
742 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
743 impl.mController->SetSelectionEnabled( enableSelection );
747 case Toolkit::TextField::Property::PLACEHOLDER:
749 const Property::Map* map = value.GetMap();
752 impl.mController->SetPlaceholderProperty( *map );
756 case Toolkit::TextField::Property::ELLIPSIS:
758 if( impl.mController )
760 const bool ellipsis = value.Get<bool>();
761 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
763 impl.mController->SetTextElideEnabled( ellipsis );
767 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
769 if( impl.mController )
771 const bool shiftSelection = value.Get<bool>();
772 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
774 impl.mController->SetShiftSelectionEnabled( shiftSelection );
778 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
780 if( impl.mController )
782 const bool grabHandleEnabled = value.Get<bool>();
783 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
785 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
789 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
791 if( impl.mController )
793 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
801 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
803 Property::Value value;
805 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
809 TextField& impl( GetImpl( textField ) );
813 case Toolkit::TextField::Property::RENDERING_BACKEND:
815 value = impl.mRenderingBackend;
818 case Toolkit::TextField::Property::TEXT:
820 if( impl.mController )
823 impl.mController->GetText( text );
824 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
829 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
831 if( impl.mController )
834 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
839 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
841 if( impl.mController )
844 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
849 case Toolkit::TextField::Property::FONT_FAMILY:
851 if( impl.mController )
853 value = impl.mController->GetDefaultFontFamily();
857 case Toolkit::TextField::Property::FONT_STYLE:
859 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
862 case Toolkit::TextField::Property::POINT_SIZE:
864 if( impl.mController )
866 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
870 case Toolkit::TextField::Property::MAX_LENGTH:
872 if( impl.mController )
874 value = impl.mController->GetMaximumNumberOfCharacters();
878 case Toolkit::TextField::Property::EXCEED_POLICY:
880 value = impl.mExceedPolicy;
883 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
885 if( impl.mController )
887 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
891 value = std::string( name );
896 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
898 if( impl.mController )
900 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
904 value = std::string( name );
909 case Toolkit::TextField::Property::TEXT_COLOR:
911 if ( impl.mController )
913 value = impl.mController->GetDefaultColor();
917 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
919 if ( impl.mController )
921 value = impl.mController->GetPlaceholderTextColor();
925 case Toolkit::TextField::Property::SHADOW_OFFSET:
927 if ( impl.mController )
929 value = impl.mController->GetShadowOffset();
933 case Toolkit::TextField::Property::SHADOW_COLOR:
935 if ( impl.mController )
937 value = impl.mController->GetShadowColor();
941 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
943 if( impl.mDecorator )
945 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
949 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
951 if( impl.mDecorator )
953 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
957 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
959 value = impl.mController->GetEnableCursorBlink();
962 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
964 if( impl.mDecorator )
966 value = impl.mDecorator->GetCursorBlinkInterval();
970 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
972 if( impl.mDecorator )
974 value = impl.mDecorator->GetCursorBlinkDuration();
978 case Toolkit::TextField::Property::CURSOR_WIDTH:
980 if( impl.mDecorator )
982 value = impl.mDecorator->GetCursorWidth();
986 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
988 if( impl.mDecorator )
990 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
993 value = image.GetUrl();
998 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
1000 if( impl.mDecorator )
1002 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
1005 value = image.GetUrl();
1010 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
1012 if( impl.mDecorator )
1014 value = impl.mDecorator->GetScrollThreshold();
1018 case Toolkit::TextField::Property::SCROLL_SPEED:
1020 if( impl.mDecorator )
1022 value = impl.mDecorator->GetScrollSpeed();
1026 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1028 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1031 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1033 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1036 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1038 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1041 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1043 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1046 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1048 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1051 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1053 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1056 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1058 if( impl.mDecorator )
1060 value = impl.mDecorator->GetHighlightColor();
1064 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1066 if( impl.mDecorator )
1068 Rect<int> boundingBox;
1069 impl.mDecorator->GetBoundingBox( boundingBox );
1070 value = boundingBox;
1074 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1077 impl.mInputMethodOptions.RetrieveProperty( map );
1081 case Toolkit::TextField::Property::INPUT_COLOR:
1083 if( impl.mController )
1085 value = impl.mController->GetInputColor();
1089 case Toolkit::TextField::Property::ENABLE_MARKUP:
1091 if( impl.mController )
1093 value = impl.mController->IsMarkupProcessorEnabled();
1097 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1099 if( impl.mController )
1101 value = impl.mController->GetInputFontFamily();
1105 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1107 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1110 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1112 if( impl.mController )
1114 value = impl.mController->GetInputFontPointSize();
1118 case Toolkit::TextField::Property::UNDERLINE:
1120 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1123 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1125 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1128 case Toolkit::TextField::Property::SHADOW:
1130 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1133 case Toolkit::TextField::Property::INPUT_SHADOW:
1135 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1138 case Toolkit::TextField::Property::EMBOSS:
1140 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1143 case Toolkit::TextField::Property::INPUT_EMBOSS:
1145 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1148 case Toolkit::TextField::Property::OUTLINE:
1150 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1153 case Toolkit::TextField::Property::INPUT_OUTLINE:
1155 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1158 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1161 impl.mController->GetHiddenInputOption(map);
1165 case Toolkit::TextField::Property::PIXEL_SIZE:
1167 if( impl.mController )
1169 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1173 case Toolkit::TextField::Property::ENABLE_SELECTION:
1175 if( impl.mController )
1177 value = impl.mController->IsSelectionEnabled();
1181 case Toolkit::TextField::Property::PLACEHOLDER:
1184 impl.mController->GetPlaceholderProperty( map );
1188 case Toolkit::TextField::Property::ELLIPSIS:
1190 if( impl.mController )
1192 value = impl.mController->IsTextElideEnabled();
1196 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1198 if( impl.mController )
1200 value = impl.mController->IsShiftSelectionEnabled();
1204 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1206 if( impl.mController )
1208 value = impl.mController->IsGrabHandleEnabled();
1212 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1214 if( impl.mController )
1216 value = impl.mController->IsMatchSystemLanguageDirection();
1226 InputMethodContext TextField::GetInputMethodContext()
1228 return mInputMethodContext;
1231 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1233 Dali::BaseHandle handle( object );
1235 bool connected( true );
1236 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1238 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1240 field.TextChangedSignal().Connect( tracker, functor );
1242 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1244 field.MaxLengthReachedSignal().Connect( tracker, functor );
1246 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1248 field.InputStyleChangedSignal().Connect( tracker, functor );
1252 // signalName does not match any signal
1259 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1261 return mTextChangedSignal;
1264 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1266 return mMaxLengthReachedSignal;
1269 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1271 return mInputStyleChangedSignal;
1274 void TextField::OnInitialize()
1276 Actor self = Self();
1278 mController = Text::Controller::New( this, this );
1280 // When using the vector-based rendering, the size of the GLyphs are different
1281 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1282 mController->SetGlyphType( glyphType );
1284 mDecorator = Text::Decorator::New( *mController,
1287 mInputMethodContext = InputMethodContext::New();
1289 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1291 // Enables the text input.
1292 mController->EnableTextInput( mDecorator, mInputMethodContext );
1294 // Enables the horizontal scrolling after the text input has been enabled.
1295 mController->SetHorizontalScrollEnabled( true );
1297 // Disables the vertical scrolling.
1298 mController->SetVerticalScrollEnabled( false );
1300 // Disable the smooth handle panning.
1301 mController->SetSmoothHandlePanEnabled( false );
1303 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1304 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1306 // Sets layoutDirection value
1307 Dali::Stage stage = Dali::Stage::GetCurrent();
1308 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1309 mController->SetLayoutDirection( layoutDirection );
1311 // Forward input events to controller
1312 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1313 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1315 self.TouchSignal().Connect( this, &TextField::OnTouched );
1317 // Set BoundingBox to stage size if not already set.
1318 Rect<int> boundingBox;
1319 mDecorator->GetBoundingBox( boundingBox );
1321 if( boundingBox.IsEmpty() )
1323 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1324 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1327 // Flip vertically the 'left' selection handle
1328 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1330 // Fill-parent area by default
1331 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1332 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1333 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1335 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1337 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1343 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1345 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1349 case StyleChange::DEFAULT_FONT_CHANGE:
1351 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1352 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1353 // Property system did not set the font so should update it.
1354 mController->UpdateAfterFontChange( newFont );
1359 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1361 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1365 case StyleChange::THEME_CHANGE:
1367 // Nothing to do, let control base class handle this
1372 // Up call to Control
1373 Control::OnStyleChange( styleManager, change );
1376 Vector3 TextField::GetNaturalSize()
1379 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1381 Vector3 naturalSize = mController->GetNaturalSize();
1382 naturalSize.width += ( padding.start + padding.end );
1383 naturalSize.height += ( padding.top + padding.bottom );
1388 float TextField::GetHeightForWidth( float width )
1391 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1392 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1395 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1397 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1399 Actor self = Self();
1402 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1404 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1406 // Support Right-To-Left of padding
1407 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1408 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1410 std::swap( padding.start, padding.end );
1415 mStencil.SetPosition( padding.start, padding.top );
1419 mActiveLayer.SetPosition( padding.start, padding.top );
1422 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1424 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1427 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1430 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1432 mDecorator->Relayout( size );
1437 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1440 RenderText( updateTextType );
1444 // The text-field emits signals when the input style changes. These changes of style are
1445 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1446 // can't be emitted during the size negotiation as the callbacks may update the UI.
1447 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1448 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1450 if( Adaptor::IsAvailable() )
1452 Adaptor& adaptor = Adaptor::Get();
1454 if( NULL == mIdleCallback )
1456 // @note: The callback manager takes the ownership of the callback object.
1457 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1458 adaptor.AddIdle( mIdleCallback, false );
1464 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1466 Actor renderableActor;
1468 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1472 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1474 renderableActor = mRenderer->Render( mController->GetView(),
1476 Property::INVALID_INDEX, // Animatable property not supported
1478 DepthIndex::CONTENT );
1481 if( renderableActor != mRenderableActor )
1483 UnparentAndReset( mRenderableActor );
1484 mRenderableActor = renderableActor;
1488 if( mRenderableActor )
1490 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1494 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1499 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1501 // Support Right-To-Left of padding
1502 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1503 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1505 std::swap( padding.start, padding.end );
1508 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1512 // Make sure the actors are parented correctly with/without clipping
1513 Actor self = mStencil ? mStencil : Self();
1515 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1516 endIt = mClippingDecorationActors.end();
1521 it->LowerToBottom();
1523 mClippingDecorationActors.clear();
1525 self.Add( mRenderableActor );
1529 void TextField::OnKeyInputFocusGained()
1531 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1532 if ( mInputMethodContext )
1534 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1536 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1538 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1540 // Notify that the text editing start.
1541 mInputMethodContext.Activate();
1543 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1544 mInputMethodContext.SetRestoreAfterFocusLost( true );
1546 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1550 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1553 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1555 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1558 void TextField::OnKeyInputFocusLost()
1560 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1561 if ( mInputMethodContext )
1563 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1564 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1565 mInputMethodContext.SetRestoreAfterFocusLost( false );
1567 // Notify that the text editing finish.
1568 mInputMethodContext.Deactivate();
1570 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1572 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1576 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1579 mController->KeyboardFocusLostEvent();
1581 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1584 void TextField::OnTap( const TapGesture& gesture )
1586 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1587 if ( mInputMethodContext )
1589 mInputMethodContext.Activate();
1591 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1593 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1594 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1599 void TextField::OnPan( const PanGesture& gesture )
1601 mController->PanEvent( gesture.state, gesture.displacement );
1604 void TextField::OnLongPress( const LongPressGesture& gesture )
1606 if ( mInputMethodContext )
1608 mInputMethodContext.Activate();
1611 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1612 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1617 bool TextField::OnKeyEvent( const KeyEvent& event )
1619 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1621 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1623 // Make sure ClearKeyInputFocus when only key is up
1624 if( event.state == KeyEvent::Up )
1626 ClearKeyInputFocus();
1631 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1633 // Do nothing when enter is comming.
1637 return mController->KeyEvent( event );
1640 void TextField::RequestTextRelayout()
1645 void TextField::TextChanged()
1647 Dali::Toolkit::TextField handle( GetOwner() );
1648 mTextChangedSignal.Emit( handle );
1651 void TextField::MaxLengthReached()
1653 Dali::Toolkit::TextField handle( GetOwner() );
1654 mMaxLengthReachedSignal.Emit( handle );
1657 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1659 Dali::Toolkit::TextField handle( GetOwner() );
1661 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1663 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1665 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1667 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1669 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1671 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1673 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1675 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1677 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1679 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1681 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1683 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1685 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1687 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1689 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1691 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1693 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1695 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1697 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1699 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1701 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1704 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1707 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1713 mClippingDecorationActors.push_back( actor );
1717 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1718 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1719 Self().Add( actor );
1720 mActiveLayer = actor;
1725 void TextField::OnStageConnect( Dali::Actor actor )
1727 if ( mHasBeenStaged )
1729 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1733 mHasBeenStaged = true;
1737 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1739 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1740 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1743 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1747 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1752 Scripting::CreatePropertyMap( image, map );
1758 void TextField::EnableClipping()
1762 // Creates an extra control to be used as stencil buffer.
1763 mStencil = Control::New();
1764 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1765 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1767 // Creates a background visual. Even if the color is transparent it updates the stencil.
1768 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1769 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1770 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1772 // Enable the clipping property.
1773 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1774 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1776 Self().Add( mStencil );
1780 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1782 mController->PasteClipboardItemEvent();
1785 void TextField::KeyboardStatusChanged(bool keyboardShown)
1787 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1789 // Just hide the grab handle when keyboard is hidden.
1790 if (!keyboardShown )
1792 mController->KeyboardFocusLostEvent();
1796 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1800 void TextField::OnStageConnection( int depth )
1802 // Sets the depth to the visuals inside the text's decorator.
1803 mDecorator->SetTextDepth( depth );
1805 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1807 // Call the Control::OnStageConnection() to set the depth of the background.
1808 Control::OnStageConnection( depth );
1811 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1816 void TextField::OnIdleSignal()
1818 // Emits the change of input style signals.
1819 mController->ProcessInputStyleChangedSignals();
1821 // Set the pointer to null as the callback manager deletes the callback after execute it.
1822 mIdleCallback = NULL;
1825 TextField::TextField()
1826 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1827 mIdleCallback( NULL ),
1828 mAlignmentOffset( 0.f ),
1829 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1830 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1831 mHasBeenStaged( false )
1835 TextField::~TextField()
1837 UnparentAndReset( mStencil );
1839 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1841 Adaptor::Get().RemoveIdle( mIdleCallback );
1845 } // namespace Internal
1847 } // namespace Toolkit