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>
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 )
136 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
137 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
138 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
140 DALI_TYPE_REGISTRATION_END()
144 Toolkit::TextField TextField::New()
146 // Create the implementation, temporarily owned by this handle on stack
147 IntrusivePtr< TextField > impl = new TextField();
149 // Pass ownership to CustomActor handle
150 Toolkit::TextField handle( *impl );
152 // Second-phase init of the implementation
153 // This can only be done after the CustomActor connection has been made...
159 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
161 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
163 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
168 TextField& impl( GetImpl( textField ) );
172 case Toolkit::TextField::Property::RENDERING_BACKEND:
174 int backend = value.Get< int >();
175 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
177 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
178 if( Text::RENDERING_VECTOR_BASED == backend )
180 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
183 if( impl.mRenderingBackend != backend )
185 impl.mRenderingBackend = backend;
186 impl.mRenderer.Reset();
188 if( impl.mController )
190 // When using the vector-based rendering, the size of the GLyphs are different
191 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
192 impl.mController->SetGlyphType( glyphType );
197 case Toolkit::TextField::Property::TEXT:
199 if( impl.mController )
201 const std::string& text = value.Get< std::string >();
202 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
204 impl.mController->SetText( text );
208 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
210 if( impl.mController )
212 const std::string& text = value.Get< std::string >();
213 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
215 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
219 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
221 if( impl.mController )
223 const std::string& text = value.Get< std::string >();
224 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
226 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
230 case Toolkit::TextField::Property::FONT_FAMILY:
232 if( impl.mController )
234 const std::string& fontFamily = value.Get< std::string >();
235 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
236 impl.mController->SetDefaultFontFamily( fontFamily );
240 case Toolkit::TextField::Property::FONT_STYLE:
242 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
245 case Toolkit::TextField::Property::POINT_SIZE:
247 if( impl.mController )
249 const float pointSize = value.Get< float >();
250 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
252 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
254 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
259 case Toolkit::TextField::Property::MAX_LENGTH:
261 if( impl.mController )
263 const int max = value.Get< int >();
264 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
266 impl.mController->SetMaximumNumberOfCharacters( max );
270 case Toolkit::TextField::Property::EXCEED_POLICY:
272 impl.mExceedPolicy = value.Get<int>();
274 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
276 impl.EnableClipping();
280 UnparentAndReset( impl.mStencil );
282 impl.RequestTextRelayout();
285 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
287 if( impl.mController )
289 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
290 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
292 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
293 impl.mController->SetHorizontalAlignment( alignment );
298 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
300 if( impl.mController )
302 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
303 if( GetVerticalAlignmentEnumeration( value, alignment ) )
305 impl.mController->SetVerticalAlignment( alignment );
306 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
311 case Toolkit::TextField::Property::TEXT_COLOR:
313 if( impl.mController )
315 const Vector4& textColor = value.Get< Vector4 >();
316 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 );
318 if( impl.mController->GetDefaultColor() != textColor )
320 impl.mController->SetDefaultColor( textColor );
321 impl.mController->SetInputColor( textColor );
322 impl.mRenderer.Reset();
327 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
329 if( impl.mController )
331 const Vector4& textColor = value.Get< Vector4 >();
332 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 );
334 if( impl.mController->GetPlaceholderTextColor() != textColor )
336 impl.mController->SetPlaceholderTextColor( textColor );
337 impl.mRenderer.Reset();
342 case Toolkit::TextField::Property::SHADOW_OFFSET:
344 if( impl.mController )
346 const Vector2& shadowOffset = value.Get< Vector2 >();
347 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
349 if ( impl.mController->GetShadowOffset() != shadowOffset )
351 impl.mController->SetShadowOffset( shadowOffset );
352 impl.mRenderer.Reset();
357 case Toolkit::TextField::Property::SHADOW_COLOR:
359 if( impl.mController )
361 const Vector4& shadowColor = value.Get< Vector4 >();
362 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 );
364 if ( impl.mController->GetShadowColor() != shadowColor )
366 impl.mController->SetShadowColor( shadowColor );
367 impl.mRenderer.Reset();
372 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
374 if( impl.mDecorator )
376 const Vector4& color = value.Get< Vector4 >();
377 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 );
379 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
380 impl.RequestTextRelayout();
384 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
386 if( impl.mDecorator )
388 const Vector4& color = value.Get< Vector4 >();
389 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 );
391 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
392 impl.RequestTextRelayout();
396 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
398 if( impl.mController )
400 const bool enable = value.Get< bool >();
401 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
403 impl.mController->SetEnableCursorBlink( enable );
404 impl.RequestTextRelayout();
408 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
410 if( impl.mDecorator )
412 const float interval = value.Get< float >();
413 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
415 impl.mDecorator->SetCursorBlinkInterval( interval );
419 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
421 if( impl.mDecorator )
423 const float duration = value.Get< float >();
424 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
426 impl.mDecorator->SetCursorBlinkDuration( duration );
430 case Toolkit::TextField::Property::CURSOR_WIDTH:
432 if( impl.mDecorator )
434 const int width = value.Get< int >();
435 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
437 impl.mDecorator->SetCursorWidth( width );
438 impl.mController->GetLayoutEngine().SetCursorWidth( width );
442 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
444 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
445 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
447 if( impl.mDecorator )
449 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
450 impl.RequestTextRelayout();
454 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
456 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
457 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
459 if( impl.mDecorator )
461 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
462 impl.RequestTextRelayout();
466 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
468 const float threshold = value.Get< float >();
469 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
471 if( impl.mDecorator )
473 impl.mDecorator->SetScrollThreshold( threshold );
477 case Toolkit::TextField::Property::SCROLL_SPEED:
479 const float speed = value.Get< float >();
480 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
482 if( impl.mDecorator )
484 impl.mDecorator->SetScrollSpeed( speed );
488 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
490 const Image image = Scripting::NewImage( value );
492 if( impl.mDecorator && image )
494 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
495 impl.RequestTextRelayout();
499 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
501 const Image image = Scripting::NewImage( value );
503 if( impl.mDecorator && image )
505 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
506 impl.RequestTextRelayout();
510 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
512 const Image image = Scripting::NewImage( value );
514 if( impl.mDecorator && image )
516 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
517 impl.RequestTextRelayout();
521 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
523 const Image image = Scripting::NewImage( value );
525 if( impl.mDecorator && image )
527 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
528 impl.RequestTextRelayout();
532 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
534 const Image image = Scripting::NewImage( value );
536 if( impl.mDecorator && image )
538 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
539 impl.RequestTextRelayout();
543 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
545 const Image image = Scripting::NewImage( value );
547 if( impl.mDecorator && image )
549 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
550 impl.RequestTextRelayout();
554 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
556 const Vector4 color = value.Get< Vector4 >();
557 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 );
559 if( impl.mDecorator )
561 impl.mDecorator->SetHighlightColor( color );
562 impl.RequestTextRelayout();
566 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
568 if( impl.mDecorator )
570 const Rect<int> box = value.Get< Rect<int> >();
571 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 );
573 impl.mDecorator->SetBoundingBox( box );
574 impl.RequestTextRelayout();
578 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
580 const Property::Map* map = value.GetMap();
583 impl.mInputMethodOptions.ApplyProperty( *map );
585 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
587 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
588 if (control == textField)
590 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
594 case Toolkit::TextField::Property::INPUT_COLOR:
596 if( impl.mController )
598 const Vector4 inputColor = value.Get< Vector4 >();
599 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 );
601 impl.mController->SetInputColor( inputColor );
605 case Toolkit::TextField::Property::ENABLE_MARKUP:
607 if( impl.mController )
609 const bool enableMarkup = value.Get<bool>();
610 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
612 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
616 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
618 if( impl.mController )
620 const std::string& fontFamily = value.Get< std::string >();
621 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
622 impl.mController->SetInputFontFamily( fontFamily );
626 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
628 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
631 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
633 if( impl.mController )
635 const float pointSize = value.Get< float >();
636 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
637 impl.mController->SetInputFontPointSize( pointSize );
641 case Toolkit::TextField::Property::UNDERLINE:
643 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
646 impl.mRenderer.Reset();
650 case Toolkit::TextField::Property::INPUT_UNDERLINE:
652 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
655 impl.mRenderer.Reset();
659 case Toolkit::TextField::Property::SHADOW:
661 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
664 impl.mRenderer.Reset();
668 case Toolkit::TextField::Property::INPUT_SHADOW:
670 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
673 impl.mRenderer.Reset();
677 case Toolkit::TextField::Property::EMBOSS:
679 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
682 impl.mRenderer.Reset();
686 case Toolkit::TextField::Property::INPUT_EMBOSS:
688 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
691 impl.mRenderer.Reset();
695 case Toolkit::TextField::Property::OUTLINE:
697 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
700 impl.mRenderer.Reset();
704 case Toolkit::TextField::Property::INPUT_OUTLINE:
706 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
709 impl.mRenderer.Reset();
713 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
715 const Property::Map* map = value.GetMap();
718 impl.mController->SetHiddenInputOption(*map);
722 case Toolkit::TextField::Property::PIXEL_SIZE:
724 if( impl.mController )
726 const float pixelSize = value.Get< float >();
727 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
729 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
731 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
736 case Toolkit::TextField::Property::ENABLE_SELECTION:
738 if( impl.mController )
740 const bool enableSelection = value.Get< bool >();
741 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
742 impl.mController->SetSelectionEnabled( enableSelection );
746 case Toolkit::TextField::Property::PLACEHOLDER:
748 const Property::Map* map = value.GetMap();
751 impl.mController->SetPlaceholderProperty( *map );
755 case Toolkit::TextField::Property::ELLIPSIS:
757 if( impl.mController )
759 const bool ellipsis = value.Get<bool>();
760 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
762 impl.mController->SetTextElideEnabled( ellipsis );
766 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
768 if( impl.mController )
770 const bool shiftSelection = value.Get<bool>();
771 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
773 impl.mController->SetShiftSelectionEnabled( shiftSelection );
777 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
779 if( impl.mController )
781 const bool grabHandleEnabled = value.Get<bool>();
782 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
784 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
792 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
794 Property::Value value;
796 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
800 TextField& impl( GetImpl( textField ) );
804 case Toolkit::TextField::Property::RENDERING_BACKEND:
806 value = impl.mRenderingBackend;
809 case Toolkit::TextField::Property::TEXT:
811 if( impl.mController )
814 impl.mController->GetText( text );
815 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
820 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
822 if( impl.mController )
825 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
830 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
832 if( impl.mController )
835 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
840 case Toolkit::TextField::Property::FONT_FAMILY:
842 if( impl.mController )
844 value = impl.mController->GetDefaultFontFamily();
848 case Toolkit::TextField::Property::FONT_STYLE:
850 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
853 case Toolkit::TextField::Property::POINT_SIZE:
855 if( impl.mController )
857 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
861 case Toolkit::TextField::Property::MAX_LENGTH:
863 if( impl.mController )
865 value = impl.mController->GetMaximumNumberOfCharacters();
869 case Toolkit::TextField::Property::EXCEED_POLICY:
871 value = impl.mExceedPolicy;
874 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
876 if( impl.mController )
878 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
882 value = std::string( name );
887 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
889 if( impl.mController )
891 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
895 value = std::string( name );
900 case Toolkit::TextField::Property::TEXT_COLOR:
902 if ( impl.mController )
904 value = impl.mController->GetDefaultColor();
908 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
910 if ( impl.mController )
912 value = impl.mController->GetPlaceholderTextColor();
916 case Toolkit::TextField::Property::SHADOW_OFFSET:
918 if ( impl.mController )
920 value = impl.mController->GetShadowOffset();
924 case Toolkit::TextField::Property::SHADOW_COLOR:
926 if ( impl.mController )
928 value = impl.mController->GetShadowColor();
932 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
934 if( impl.mDecorator )
936 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
940 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
942 if( impl.mDecorator )
944 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
948 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
950 value = impl.mController->GetEnableCursorBlink();
953 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
955 if( impl.mDecorator )
957 value = impl.mDecorator->GetCursorBlinkInterval();
961 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
963 if( impl.mDecorator )
965 value = impl.mDecorator->GetCursorBlinkDuration();
969 case Toolkit::TextField::Property::CURSOR_WIDTH:
971 if( impl.mDecorator )
973 value = impl.mDecorator->GetCursorWidth();
977 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
979 if( impl.mDecorator )
981 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
984 value = image.GetUrl();
989 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
991 if( impl.mDecorator )
993 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
996 value = image.GetUrl();
1001 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
1003 if( impl.mDecorator )
1005 value = impl.mDecorator->GetScrollThreshold();
1009 case Toolkit::TextField::Property::SCROLL_SPEED:
1011 if( impl.mDecorator )
1013 value = impl.mDecorator->GetScrollSpeed();
1017 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1019 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1022 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1024 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1027 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1029 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1032 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1034 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1037 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1039 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1042 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1044 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1047 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1049 if( impl.mDecorator )
1051 value = impl.mDecorator->GetHighlightColor();
1055 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1057 if( impl.mDecorator )
1059 Rect<int> boundingBox;
1060 impl.mDecorator->GetBoundingBox( boundingBox );
1061 value = boundingBox;
1065 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1068 impl.mInputMethodOptions.RetrieveProperty( map );
1072 case Toolkit::TextField::Property::INPUT_COLOR:
1074 if( impl.mController )
1076 value = impl.mController->GetInputColor();
1080 case Toolkit::TextField::Property::ENABLE_MARKUP:
1082 if( impl.mController )
1084 value = impl.mController->IsMarkupProcessorEnabled();
1088 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1090 if( impl.mController )
1092 value = impl.mController->GetInputFontFamily();
1096 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1098 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1101 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1103 if( impl.mController )
1105 value = impl.mController->GetInputFontPointSize();
1109 case Toolkit::TextField::Property::UNDERLINE:
1111 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1114 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1116 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1119 case Toolkit::TextField::Property::SHADOW:
1121 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1124 case Toolkit::TextField::Property::INPUT_SHADOW:
1126 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1129 case Toolkit::TextField::Property::EMBOSS:
1131 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1134 case Toolkit::TextField::Property::INPUT_EMBOSS:
1136 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1139 case Toolkit::TextField::Property::OUTLINE:
1141 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1144 case Toolkit::TextField::Property::INPUT_OUTLINE:
1146 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1149 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1152 impl.mController->GetHiddenInputOption(map);
1156 case Toolkit::TextField::Property::PIXEL_SIZE:
1158 if( impl.mController )
1160 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1164 case Toolkit::TextField::Property::ENABLE_SELECTION:
1166 if( impl.mController )
1168 value = impl.mController->IsSelectionEnabled();
1172 case Toolkit::TextField::Property::PLACEHOLDER:
1175 impl.mController->GetPlaceholderProperty( map );
1179 case Toolkit::TextField::Property::ELLIPSIS:
1181 if( impl.mController )
1183 value = impl.mController->IsTextElideEnabled();
1187 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1189 if( impl.mController )
1191 value = impl.mController->IsShiftSelectionEnabled();
1195 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1197 if( impl.mController )
1199 value = impl.mController->IsGrabHandleEnabled();
1209 InputMethodContext TextField::GetInputMethodContext()
1211 return mInputMethodContext;
1214 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1216 Dali::BaseHandle handle( object );
1218 bool connected( true );
1219 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1221 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1223 field.TextChangedSignal().Connect( tracker, functor );
1225 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1227 field.MaxLengthReachedSignal().Connect( tracker, functor );
1229 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1231 field.InputStyleChangedSignal().Connect( tracker, functor );
1235 // signalName does not match any signal
1242 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1244 return mTextChangedSignal;
1247 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1249 return mMaxLengthReachedSignal;
1252 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1254 return mInputStyleChangedSignal;
1257 void TextField::OnInitialize()
1259 Actor self = Self();
1261 mController = Text::Controller::New( this, this );
1263 // When using the vector-based rendering, the size of the GLyphs are different
1264 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1265 mController->SetGlyphType( glyphType );
1267 mDecorator = Text::Decorator::New( *mController,
1270 mInputMethodContext = InputMethodContext::New();
1272 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1274 // Enables the text input.
1275 mController->EnableTextInput( mDecorator, mInputMethodContext );
1277 // Enables the horizontal scrolling after the text input has been enabled.
1278 mController->SetHorizontalScrollEnabled( true );
1280 // Disables the vertical scrolling.
1281 mController->SetVerticalScrollEnabled( false );
1283 // Disable the smooth handle panning.
1284 mController->SetSmoothHandlePanEnabled( false );
1286 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1287 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1289 // Forward input events to controller
1290 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1291 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1293 self.TouchSignal().Connect( this, &TextField::OnTouched );
1295 // Set BoundingBox to stage size if not already set.
1296 Rect<int> boundingBox;
1297 mDecorator->GetBoundingBox( boundingBox );
1299 if( boundingBox.IsEmpty() )
1301 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1302 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1305 // Flip vertically the 'left' selection handle
1306 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1308 // Fill-parent area by default
1309 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1310 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1311 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1313 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1315 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1321 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1323 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1327 case StyleChange::DEFAULT_FONT_CHANGE:
1329 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1330 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1331 // Property system did not set the font so should update it.
1332 mController->UpdateAfterFontChange( newFont );
1337 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1339 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1343 case StyleChange::THEME_CHANGE:
1345 // Nothing to do, let control base class handle this
1350 // Up call to Control
1351 Control::OnStyleChange( styleManager, change );
1354 Vector3 TextField::GetNaturalSize()
1357 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1359 Vector3 naturalSize = mController->GetNaturalSize();
1360 naturalSize.width += ( padding.start + padding.end );
1361 naturalSize.height += ( padding.top + padding.bottom );
1366 float TextField::GetHeightForWidth( float width )
1369 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1370 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1373 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1377 Actor self = Self();
1380 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1382 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1384 // Support Right-To-Left of padding
1385 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1386 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1388 std::swap( padding.start, padding.end );
1393 mStencil.SetPosition( padding.start, padding.top );
1397 mActiveLayer.SetPosition( padding.start, padding.top );
1400 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize );
1402 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1405 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1408 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1410 mDecorator->Relayout( size );
1415 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1418 RenderText( updateTextType );
1422 // The text-field emits signals when the input style changes. These changes of style are
1423 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1424 // can't be emitted during the size negotiation as the callbacks may update the UI.
1425 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1426 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1428 if( Adaptor::IsAvailable() )
1430 Adaptor& adaptor = Adaptor::Get();
1432 if( NULL == mIdleCallback )
1434 // @note: The callback manager takes the ownership of the callback object.
1435 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1436 adaptor.AddIdle( mIdleCallback, false );
1442 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1444 Actor renderableActor;
1446 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1450 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1452 renderableActor = mRenderer->Render( mController->GetView(),
1454 Property::INVALID_INDEX, // Animatable property not supported
1456 DepthIndex::CONTENT );
1459 if( renderableActor != mRenderableActor )
1461 UnparentAndReset( mRenderableActor );
1462 mRenderableActor = renderableActor;
1466 if( mRenderableActor )
1468 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1472 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1477 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1479 // Support Right-To-Left of padding
1480 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1481 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1483 std::swap( padding.start, padding.end );
1486 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1490 // Make sure the actors are parented correctly with/without clipping
1491 Actor self = mStencil ? mStencil : Self();
1493 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1494 endIt = mClippingDecorationActors.end();
1499 it->LowerToBottom();
1501 mClippingDecorationActors.clear();
1503 self.Add( mRenderableActor );
1507 void TextField::OnKeyInputFocusGained()
1509 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1510 if ( mInputMethodContext )
1512 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1514 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1516 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1518 // Notify that the text editing start.
1519 mInputMethodContext.Activate();
1521 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1522 mInputMethodContext.SetRestoreAfterFocusLost( true );
1524 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1528 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1531 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1533 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1536 void TextField::OnKeyInputFocusLost()
1538 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1539 if ( mInputMethodContext )
1541 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1542 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1543 mInputMethodContext.SetRestoreAfterFocusLost( false );
1545 // Notify that the text editing finish.
1546 mInputMethodContext.Deactivate();
1548 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1550 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1554 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1557 mController->KeyboardFocusLostEvent();
1559 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1562 void TextField::OnTap( const TapGesture& gesture )
1564 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1565 if ( mInputMethodContext )
1567 mInputMethodContext.Activate();
1569 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1571 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1572 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1577 void TextField::OnPan( const PanGesture& gesture )
1579 mController->PanEvent( gesture.state, gesture.displacement );
1582 void TextField::OnLongPress( const LongPressGesture& gesture )
1584 if ( mInputMethodContext )
1586 mInputMethodContext.Activate();
1589 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1590 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1595 bool TextField::OnKeyEvent( const KeyEvent& event )
1597 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1599 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1601 // Make sure ClearKeyInputFocus when only key is up
1602 if( event.state == KeyEvent::Up )
1604 ClearKeyInputFocus();
1609 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1611 // Do nothing when enter is comming.
1615 return mController->KeyEvent( event );
1618 void TextField::RequestTextRelayout()
1623 void TextField::TextChanged()
1625 Dali::Toolkit::TextField handle( GetOwner() );
1626 mTextChangedSignal.Emit( handle );
1629 void TextField::MaxLengthReached()
1631 Dali::Toolkit::TextField handle( GetOwner() );
1632 mMaxLengthReachedSignal.Emit( handle );
1635 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1637 Dali::Toolkit::TextField handle( GetOwner() );
1639 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1641 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1643 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1645 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1647 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1649 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1651 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1653 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1655 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1657 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1659 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1661 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1663 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1665 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1667 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1669 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1671 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1673 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1675 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1677 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1679 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1682 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1685 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1691 mClippingDecorationActors.push_back( actor );
1695 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1696 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1697 Self().Add( actor );
1698 mActiveLayer = actor;
1703 void TextField::OnStageConnect( Dali::Actor actor )
1705 if ( mHasBeenStaged )
1707 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1711 mHasBeenStaged = true;
1715 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1717 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1718 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1721 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1725 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1730 Scripting::CreatePropertyMap( image, map );
1736 void TextField::EnableClipping()
1740 // Creates an extra control to be used as stencil buffer.
1741 mStencil = Control::New();
1742 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1743 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1745 // Creates a background visual. Even if the color is transparent it updates the stencil.
1746 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1747 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1748 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1750 // Enable the clipping property.
1751 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1752 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1754 Self().Add( mStencil );
1758 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1760 mController->PasteClipboardItemEvent();
1763 void TextField::KeyboardStatusChanged(bool keyboardShown)
1765 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1767 // Just hide the grab handle when keyboard is hidden.
1768 if (!keyboardShown )
1770 mController->KeyboardFocusLostEvent();
1774 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1778 void TextField::OnStageConnection( int depth )
1780 // Sets the depth to the visuals inside the text's decorator.
1781 mDecorator->SetTextDepth( depth );
1783 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1785 // Call the Control::OnStageConnection() to set the depth of the background.
1786 Control::OnStageConnection( depth );
1789 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1794 void TextField::OnIdleSignal()
1796 // Emits the change of input style signals.
1797 mController->ProcessInputStyleChangedSignals();
1799 // Set the pointer to null as the callback manager deletes the callback after execute it.
1800 mIdleCallback = NULL;
1803 TextField::TextField()
1804 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1805 mIdleCallback( NULL ),
1806 mAlignmentOffset( 0.f ),
1807 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1808 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1809 mHasBeenStaged( false )
1813 TextField::~TextField()
1815 UnparentAndReset( mStencil );
1817 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1819 Adaptor::Get().RemoveIdle( mIdleCallback );
1823 } // namespace Internal
1825 } // namespace Toolkit