2 * Copyright (c) 2020 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/debug.h>
33 #include <dali-toolkit/public-api/text/rendering-backend.h>
34 #include <dali-toolkit/public-api/text/text-enumerations.h>
35 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
36 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
37 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
38 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
39 #include <dali-toolkit/public-api/visuals/visual-properties.h>
40 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
41 #include <dali-toolkit/internal/text/rendering/text-backend.h>
42 #include <dali-toolkit/internal/text/text-effects-style.h>
43 #include <dali-toolkit/internal/text/text-font-style.h>
44 #include <dali-toolkit/internal/text/text-view.h>
45 #include <dali-toolkit/internal/styling/style-manager-impl.h>
46 #include <dali-toolkit/devel-api/controls/control-devel.h>
47 #include <dali/integration-api/adaptor-framework/adaptor.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, "reservedProperty01", STRING, RESERVED_PROPERTY_01 )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "reservedProperty02", STRING, RESERVED_PROPERTY_02 )
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 )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
138 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
140 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
144 DALI_TYPE_REGISTRATION_END()
146 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
148 /// Retrieves a filename from a value that is a Property::Map
149 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
151 std::string filename;
152 const Property::Map* map = value.GetMap();
155 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
158 filenameValue->Get( filename );
166 Toolkit::TextField TextField::New()
168 // Create the implementation, temporarily owned by this handle on stack
169 IntrusivePtr< TextField > impl = new TextField();
171 // Pass ownership to CustomActor handle
172 Toolkit::TextField handle( *impl );
174 // Second-phase init of the implementation
175 // This can only be done after the CustomActor connection has been made...
181 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
183 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
185 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
190 TextField& impl( GetImpl( textField ) );
194 case Toolkit::TextField::Property::RENDERING_BACKEND:
196 int backend = value.Get< int >();
197 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
199 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
200 if( Text::RENDERING_VECTOR_BASED == backend )
202 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
205 if( impl.mRenderingBackend != backend )
207 impl.mRenderingBackend = backend;
208 impl.mRenderer.Reset();
210 if( impl.mController )
212 // When using the vector-based rendering, the size of the GLyphs are different
213 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
214 impl.mController->SetGlyphType( glyphType );
219 case Toolkit::TextField::Property::TEXT:
221 if( impl.mController )
223 const std::string& text = value.Get< std::string >();
224 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
226 impl.mController->SetText( text );
230 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
232 if( impl.mController )
234 const std::string& text = value.Get< std::string >();
235 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
237 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
241 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
243 if( impl.mController )
245 const std::string& text = value.Get< std::string >();
246 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
248 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
252 case Toolkit::TextField::Property::FONT_FAMILY:
254 if( impl.mController )
256 const std::string& fontFamily = value.Get< std::string >();
257 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
258 impl.mController->SetDefaultFontFamily( fontFamily );
262 case Toolkit::TextField::Property::FONT_STYLE:
264 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
267 case Toolkit::TextField::Property::POINT_SIZE:
269 if( impl.mController )
271 const float pointSize = value.Get< float >();
272 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
274 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
276 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
281 case Toolkit::TextField::Property::MAX_LENGTH:
283 if( impl.mController )
285 const int max = value.Get< int >();
286 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
288 impl.mController->SetMaximumNumberOfCharacters( max );
292 case Toolkit::TextField::Property::EXCEED_POLICY:
294 impl.mExceedPolicy = value.Get<int>();
296 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
298 impl.EnableClipping();
302 UnparentAndReset( impl.mStencil );
304 impl.RequestTextRelayout();
307 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
309 if( impl.mController )
311 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
312 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
314 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
315 impl.mController->SetHorizontalAlignment( alignment );
320 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
322 if( impl.mController )
324 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
325 if( GetVerticalAlignmentEnumeration( value, alignment ) )
327 impl.mController->SetVerticalAlignment( alignment );
328 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
333 case Toolkit::TextField::Property::TEXT_COLOR:
335 if( impl.mController )
337 const Vector4& textColor = value.Get< Vector4 >();
338 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 );
340 if( impl.mController->GetDefaultColor() != textColor )
342 impl.mController->SetDefaultColor( textColor );
343 impl.mController->SetInputColor( textColor );
344 impl.mRenderer.Reset();
349 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
351 if( impl.mController )
353 const Vector4& textColor = value.Get< Vector4 >();
354 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 );
356 if( impl.mController->GetPlaceholderTextColor() != textColor )
358 impl.mController->SetPlaceholderTextColor( textColor );
359 impl.mRenderer.Reset();
364 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
366 if( impl.mDecorator )
368 const Vector4& color = value.Get< Vector4 >();
369 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 );
371 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
372 impl.RequestTextRelayout();
376 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
378 if( impl.mDecorator )
380 const Vector4& color = value.Get< Vector4 >();
381 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 );
383 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
384 impl.RequestTextRelayout();
388 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
390 if( impl.mController )
392 const bool enable = value.Get< bool >();
393 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
395 impl.mController->SetEnableCursorBlink( enable );
396 impl.RequestTextRelayout();
400 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
402 if( impl.mDecorator )
404 const float interval = value.Get< float >();
405 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
407 impl.mDecorator->SetCursorBlinkInterval( interval );
411 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
413 if( impl.mDecorator )
415 const float duration = value.Get< float >();
416 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
418 impl.mDecorator->SetCursorBlinkDuration( duration );
422 case Toolkit::TextField::Property::CURSOR_WIDTH:
424 if( impl.mDecorator )
426 const int width = value.Get< int >();
427 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
429 impl.mDecorator->SetCursorWidth( width );
430 impl.mController->GetLayoutEngine().SetCursorWidth( width );
434 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
436 const std::string imageFileName = value.Get< std::string >();
437 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName );
439 if( impl.mDecorator && imageFileName.size() )
441 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
442 impl.RequestTextRelayout();
446 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
448 const std::string imageFileName = value.Get< std::string >();
449 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName );
451 if( impl.mDecorator && imageFileName.size() )
453 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
454 impl.RequestTextRelayout();
458 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
460 const float threshold = value.Get< float >();
461 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
463 if( impl.mDecorator )
465 impl.mDecorator->SetScrollThreshold( threshold );
469 case Toolkit::TextField::Property::SCROLL_SPEED:
471 const float speed = value.Get< float >();
472 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
474 if( impl.mDecorator )
476 impl.mDecorator->SetScrollSpeed( speed );
480 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
482 const std::string filename = GetImageFileNameFromPropertyValue( value );
484 if( impl.mDecorator && filename.size() )
486 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
487 impl.RequestTextRelayout();
491 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
493 const std::string filename = GetImageFileNameFromPropertyValue( value );
495 if( impl.mDecorator && filename.size() )
497 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
498 impl.RequestTextRelayout();
502 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
504 const std::string filename = GetImageFileNameFromPropertyValue( value );
506 if( impl.mDecorator && filename.size() )
508 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
509 impl.RequestTextRelayout();
513 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
515 const std::string filename = GetImageFileNameFromPropertyValue( value );
517 if( impl.mDecorator && filename.size() )
519 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
520 impl.RequestTextRelayout();
524 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
526 const std::string filename = GetImageFileNameFromPropertyValue( value );
528 if( impl.mDecorator && filename.size() )
530 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
531 impl.RequestTextRelayout();
535 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
537 const std::string filename = GetImageFileNameFromPropertyValue( value );
539 if( impl.mDecorator && filename.size() )
541 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
542 impl.RequestTextRelayout();
546 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
548 const Vector4 color = value.Get< Vector4 >();
549 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 );
551 if( impl.mDecorator )
553 impl.mDecorator->SetHighlightColor( color );
554 impl.RequestTextRelayout();
558 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
560 if( impl.mDecorator )
562 const Rect<int> box = value.Get< Rect<int> >();
563 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 );
565 impl.mDecorator->SetBoundingBox( box );
566 impl.RequestTextRelayout();
570 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
572 const Property::Map* map = value.GetMap();
575 impl.mInputMethodOptions.ApplyProperty( *map );
577 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
579 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
580 if (control == textField)
582 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
586 case Toolkit::TextField::Property::INPUT_COLOR:
588 if( impl.mController )
590 const Vector4 inputColor = value.Get< Vector4 >();
591 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 );
593 impl.mController->SetInputColor( inputColor );
597 case Toolkit::TextField::Property::ENABLE_MARKUP:
599 if( impl.mController )
601 const bool enableMarkup = value.Get<bool>();
602 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
604 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
608 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
610 if( impl.mController )
612 const std::string& fontFamily = value.Get< std::string >();
613 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
614 impl.mController->SetInputFontFamily( fontFamily );
618 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
620 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
623 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
625 if( impl.mController )
627 const float pointSize = value.Get< float >();
628 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
629 impl.mController->SetInputFontPointSize( pointSize );
633 case Toolkit::TextField::Property::UNDERLINE:
635 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
638 impl.mRenderer.Reset();
642 case Toolkit::TextField::Property::INPUT_UNDERLINE:
644 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
647 impl.mRenderer.Reset();
651 case Toolkit::TextField::Property::SHADOW:
653 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
656 impl.mRenderer.Reset();
660 case Toolkit::TextField::Property::INPUT_SHADOW:
662 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
665 impl.mRenderer.Reset();
669 case Toolkit::TextField::Property::EMBOSS:
671 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
674 impl.mRenderer.Reset();
678 case Toolkit::TextField::Property::INPUT_EMBOSS:
680 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
683 impl.mRenderer.Reset();
687 case Toolkit::TextField::Property::OUTLINE:
689 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
692 impl.mRenderer.Reset();
696 case Toolkit::TextField::Property::INPUT_OUTLINE:
698 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
701 impl.mRenderer.Reset();
705 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
707 const Property::Map* map = value.GetMap();
710 impl.mController->SetHiddenInputOption(*map);
714 case Toolkit::TextField::Property::PIXEL_SIZE:
716 if( impl.mController )
718 const float pixelSize = value.Get< float >();
719 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
721 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
723 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
728 case Toolkit::TextField::Property::ENABLE_SELECTION:
730 if( impl.mController )
732 const bool enableSelection = value.Get< bool >();
733 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
734 impl.mController->SetSelectionEnabled( enableSelection );
738 case Toolkit::TextField::Property::PLACEHOLDER:
740 const Property::Map* map = value.GetMap();
743 impl.mController->SetPlaceholderProperty( *map );
747 case Toolkit::TextField::Property::ELLIPSIS:
749 if( impl.mController )
751 const bool ellipsis = value.Get<bool>();
752 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
754 impl.mController->SetTextElideEnabled( ellipsis );
758 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
760 if( impl.mController )
762 const bool shiftSelection = value.Get<bool>();
763 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
765 impl.mController->SetShiftSelectionEnabled( shiftSelection );
769 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
771 if( impl.mController )
773 const bool grabHandleEnabled = value.Get<bool>();
774 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
776 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
780 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
782 if( impl.mController )
784 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
788 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
790 if( impl.mController )
792 const bool grabHandlePopupEnabled = value.Get<bool>();
793 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
795 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
799 case Toolkit::DevelTextField::Property::BACKGROUND:
801 if( impl.mController )
803 const Vector4 backgroundColor = value.Get< Vector4 >();
804 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p BACKGROUND %f,%f,%f,%f\n", impl.mController.Get(), backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a );
806 impl.mController->SetBackgroundEnabled( true );
807 impl.mController->SetBackgroundColor( backgroundColor );
815 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
817 Property::Value value;
819 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
823 TextField& impl( GetImpl( textField ) );
827 case Toolkit::TextField::Property::RENDERING_BACKEND:
829 value = impl.mRenderingBackend;
832 case Toolkit::TextField::Property::TEXT:
834 if( impl.mController )
837 impl.mController->GetText( text );
838 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
843 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
845 if( impl.mController )
848 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
853 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
855 if( impl.mController )
858 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
863 case Toolkit::TextField::Property::FONT_FAMILY:
865 if( impl.mController )
867 value = impl.mController->GetDefaultFontFamily();
871 case Toolkit::TextField::Property::FONT_STYLE:
873 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
876 case Toolkit::TextField::Property::POINT_SIZE:
878 if( impl.mController )
880 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
884 case Toolkit::TextField::Property::MAX_LENGTH:
886 if( impl.mController )
888 value = impl.mController->GetMaximumNumberOfCharacters();
892 case Toolkit::TextField::Property::EXCEED_POLICY:
894 value = impl.mExceedPolicy;
897 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
899 if( impl.mController )
901 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
905 value = std::string( name );
910 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
912 if( impl.mController )
914 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
918 value = std::string( name );
923 case Toolkit::TextField::Property::TEXT_COLOR:
925 if ( impl.mController )
927 value = impl.mController->GetDefaultColor();
931 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
933 if ( impl.mController )
935 value = impl.mController->GetPlaceholderTextColor();
939 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
941 if( impl.mDecorator )
943 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
947 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
949 if( impl.mDecorator )
951 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
955 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
957 value = impl.mController->GetEnableCursorBlink();
960 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
962 if( impl.mDecorator )
964 value = impl.mDecorator->GetCursorBlinkInterval();
968 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
970 if( impl.mDecorator )
972 value = impl.mDecorator->GetCursorBlinkDuration();
976 case Toolkit::TextField::Property::CURSOR_WIDTH:
978 if( impl.mDecorator )
980 value = impl.mDecorator->GetCursorWidth();
984 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
986 if( impl.mDecorator )
988 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
992 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
994 if( impl.mDecorator )
996 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
1000 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
1002 if( impl.mDecorator )
1004 value = impl.mDecorator->GetScrollThreshold();
1008 case Toolkit::TextField::Property::SCROLL_SPEED:
1010 if( impl.mDecorator )
1012 value = impl.mDecorator->GetScrollSpeed();
1016 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1018 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1021 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1023 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1026 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1028 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1031 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1033 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1036 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1038 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1041 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1043 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1046 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1048 if( impl.mDecorator )
1050 value = impl.mDecorator->GetHighlightColor();
1054 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1056 if( impl.mDecorator )
1058 Rect<int> boundingBox;
1059 impl.mDecorator->GetBoundingBox( boundingBox );
1060 value = boundingBox;
1064 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1067 impl.mInputMethodOptions.RetrieveProperty( map );
1071 case Toolkit::TextField::Property::INPUT_COLOR:
1073 if( impl.mController )
1075 value = impl.mController->GetInputColor();
1079 case Toolkit::TextField::Property::ENABLE_MARKUP:
1081 if( impl.mController )
1083 value = impl.mController->IsMarkupProcessorEnabled();
1087 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1089 if( impl.mController )
1091 value = impl.mController->GetInputFontFamily();
1095 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1097 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1100 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1102 if( impl.mController )
1104 value = impl.mController->GetInputFontPointSize();
1108 case Toolkit::TextField::Property::UNDERLINE:
1110 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1113 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1115 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1118 case Toolkit::TextField::Property::SHADOW:
1120 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1123 case Toolkit::TextField::Property::INPUT_SHADOW:
1125 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1128 case Toolkit::TextField::Property::EMBOSS:
1130 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1133 case Toolkit::TextField::Property::INPUT_EMBOSS:
1135 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1138 case Toolkit::TextField::Property::OUTLINE:
1140 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1143 case Toolkit::TextField::Property::INPUT_OUTLINE:
1145 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1148 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1151 impl.mController->GetHiddenInputOption(map);
1155 case Toolkit::TextField::Property::PIXEL_SIZE:
1157 if( impl.mController )
1159 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1163 case Toolkit::TextField::Property::ENABLE_SELECTION:
1165 if( impl.mController )
1167 value = impl.mController->IsSelectionEnabled();
1171 case Toolkit::TextField::Property::PLACEHOLDER:
1174 impl.mController->GetPlaceholderProperty( map );
1178 case Toolkit::TextField::Property::ELLIPSIS:
1180 if( impl.mController )
1182 value = impl.mController->IsTextElideEnabled();
1186 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1188 if( impl.mController )
1190 value = impl.mController->IsShiftSelectionEnabled();
1194 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1196 if( impl.mController )
1198 value = impl.mController->IsGrabHandleEnabled();
1202 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1204 if( impl.mController )
1206 value = impl.mController->IsMatchSystemLanguageDirection();
1210 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1212 if( impl.mController )
1214 value = impl.mController->IsGrabHandlePopupEnabled();
1218 case Toolkit::DevelTextField::Property::BACKGROUND:
1220 if( impl.mController )
1222 value = impl.mController->GetBackgroundColor();
1226 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1228 if( impl.mController )
1230 value = impl.mController->GetSelectedText( );
1240 void TextField::SelectWholeText()
1242 if( mController && mController->IsShowingRealText() )
1244 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1249 void TextField::SelectNone()
1251 if( mController && mController->IsShowingRealText() )
1253 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1258 InputMethodContext TextField::GetInputMethodContext()
1260 return mInputMethodContext;
1263 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1265 Dali::BaseHandle handle( object );
1267 bool connected( true );
1268 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1270 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1272 field.TextChangedSignal().Connect( tracker, functor );
1274 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1276 field.MaxLengthReachedSignal().Connect( tracker, functor );
1278 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1280 field.InputStyleChangedSignal().Connect( tracker, functor );
1284 // signalName does not match any signal
1291 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1293 return mTextChangedSignal;
1296 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1298 return mMaxLengthReachedSignal;
1301 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1303 return mInputStyleChangedSignal;
1306 void TextField::OnInitialize()
1308 Actor self = Self();
1310 mController = Text::Controller::New( this, this );
1312 // When using the vector-based rendering, the size of the GLyphs are different
1313 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1314 mController->SetGlyphType( glyphType );
1316 mDecorator = Text::Decorator::New( *mController,
1319 mInputMethodContext = InputMethodContext::New( self );
1321 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1323 // Enables the text input.
1324 mController->EnableTextInput( mDecorator, mInputMethodContext );
1326 // Enables the horizontal scrolling after the text input has been enabled.
1327 mController->SetHorizontalScrollEnabled( true );
1329 // Disables the vertical scrolling.
1330 mController->SetVerticalScrollEnabled( false );
1332 // Disable the smooth handle panning.
1333 mController->SetSmoothHandlePanEnabled( false );
1335 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1336 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1338 // Sets layoutDirection value
1339 Dali::Stage stage = Dali::Stage::GetCurrent();
1340 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1341 mController->SetLayoutDirection( layoutDirection );
1343 // Forward input events to controller
1344 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1345 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1347 self.TouchSignal().Connect( this, &TextField::OnTouched );
1349 // Set BoundingBox to stage size if not already set.
1350 Rect<int> boundingBox;
1351 mDecorator->GetBoundingBox( boundingBox );
1353 if( boundingBox.IsEmpty() )
1355 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1356 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1359 // Flip vertically the 'left' selection handle
1360 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1362 // Fill-parent area by default
1363 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1364 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1365 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1367 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1369 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1375 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1377 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1381 case StyleChange::DEFAULT_FONT_CHANGE:
1383 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1384 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1385 // Property system did not set the font so should update it.
1386 mController->UpdateAfterFontChange( newFont );
1391 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1393 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1397 case StyleChange::THEME_CHANGE:
1399 // Nothing to do, let control base class handle this
1404 // Up call to Control
1405 Control::OnStyleChange( styleManager, change );
1408 Vector3 TextField::GetNaturalSize()
1411 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1413 Vector3 naturalSize = mController->GetNaturalSize();
1414 naturalSize.width += ( padding.start + padding.end );
1415 naturalSize.height += ( padding.top + padding.bottom );
1420 float TextField::GetHeightForWidth( float width )
1423 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1424 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1427 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1429 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1431 Actor self = Self();
1434 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1436 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1438 // Support Right-To-Left of padding
1439 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1440 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1442 std::swap( padding.start, padding.end );
1447 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1451 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1454 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1456 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1459 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1462 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1464 mDecorator->Relayout( size );
1469 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1472 RenderText( updateTextType );
1476 // The text-field emits signals when the input style changes. These changes of style are
1477 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1478 // can't be emitted during the size negotiation as the callbacks may update the UI.
1479 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1480 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1482 if( Adaptor::IsAvailable() )
1484 Adaptor& adaptor = Adaptor::Get();
1486 if( NULL == mIdleCallback )
1488 // @note: The callback manager takes the ownership of the callback object.
1489 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1490 adaptor.AddIdle( mIdleCallback, false );
1496 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1498 Actor renderableActor;
1500 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1504 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1506 renderableActor = mRenderer->Render( mController->GetView(),
1508 Property::INVALID_INDEX, // Animatable property not supported
1510 DepthIndex::CONTENT );
1513 if( renderableActor != mRenderableActor )
1515 UnparentAndReset( mBackgroundActor );
1516 UnparentAndReset( mRenderableActor );
1517 mRenderableActor = renderableActor;
1519 if ( mRenderableActor )
1521 mBackgroundActor = mController->CreateBackgroundActor();
1526 if( mRenderableActor )
1528 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1530 float renderableActorPositionX, renderableActorPositionY;
1534 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1535 renderableActorPositionY = scrollOffset.y;
1540 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1542 // Support Right-To-Left of padding
1543 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1544 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1546 std::swap( padding.start, padding.end );
1549 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1550 renderableActorPositionY = scrollOffset.y + padding.top;
1553 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1555 // Make sure the actors are parented correctly with/without clipping
1556 Actor self = mStencil ? mStencil : Self();
1558 Actor highlightActor;
1560 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1561 endIt = mClippingDecorationActors.end();
1566 it->LowerToBottom();
1568 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1570 highlightActor = *it;
1573 mClippingDecorationActors.clear();
1575 self.Add( mRenderableActor );
1577 if ( mBackgroundActor )
1579 if ( mDecorator && mDecorator->IsHighlightVisible() )
1581 self.Add( mBackgroundActor );
1582 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1583 mBackgroundActor.LowerBelow( highlightActor );
1587 mRenderableActor.Add( mBackgroundActor );
1588 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1589 mBackgroundActor.LowerToBottom();
1595 void TextField::OnKeyInputFocusGained()
1597 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1598 if ( mInputMethodContext )
1600 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1602 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1604 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1606 // Notify that the text editing start.
1607 mInputMethodContext.Activate();
1609 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1610 mInputMethodContext.SetRestoreAfterFocusLost( true );
1612 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1616 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1619 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1621 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1624 void TextField::OnKeyInputFocusLost()
1626 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1627 if ( mInputMethodContext )
1629 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1630 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1631 mInputMethodContext.SetRestoreAfterFocusLost( false );
1633 // Notify that the text editing finish.
1634 mInputMethodContext.Deactivate();
1636 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1638 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1642 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1645 mController->KeyboardFocusLostEvent();
1647 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1650 void TextField::OnTap( const TapGesture& gesture )
1652 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1653 if ( mInputMethodContext )
1655 mInputMethodContext.Activate();
1657 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1659 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1660 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1665 void TextField::OnPan( const PanGesture& gesture )
1667 mController->PanEvent( gesture.state, gesture.displacement );
1670 void TextField::OnLongPress( const LongPressGesture& gesture )
1672 if ( mInputMethodContext )
1674 mInputMethodContext.Activate();
1677 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1678 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1683 bool TextField::OnKeyEvent( const KeyEvent& event )
1685 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1687 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1689 // Make sure ClearKeyInputFocus when only key is up
1690 if( event.state == KeyEvent::Up )
1692 ClearKeyInputFocus();
1697 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1699 // Do nothing when enter is comming.
1703 return mController->KeyEvent( event );
1706 void TextField::RequestTextRelayout()
1711 void TextField::TextChanged()
1713 Dali::Toolkit::TextField handle( GetOwner() );
1714 mTextChangedSignal.Emit( handle );
1717 void TextField::MaxLengthReached()
1719 Dali::Toolkit::TextField handle( GetOwner() );
1720 mMaxLengthReachedSignal.Emit( handle );
1723 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1725 Dali::Toolkit::TextField handle( GetOwner() );
1727 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1729 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1731 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1733 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1735 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1737 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1739 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1741 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1743 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1745 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1747 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1749 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1751 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1753 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1755 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1757 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1759 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1761 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1763 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1765 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1767 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1770 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1773 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1779 mClippingDecorationActors.push_back( actor );
1783 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1784 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1785 Self().Add( actor );
1786 mActiveLayer = actor;
1791 void TextField::OnStageConnect( Dali::Actor actor )
1793 if ( mHasBeenStaged )
1795 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1799 mHasBeenStaged = true;
1803 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1805 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1806 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1809 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1814 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1819 void TextField::EnableClipping()
1823 // Creates an extra control to be used as stencil buffer.
1824 mStencil = Control::New();
1825 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1826 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1828 // Creates a background visual. Even if the color is transparent it updates the stencil.
1829 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1830 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1831 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1833 // Enable the clipping property.
1834 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1835 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1837 Self().Add( mStencil );
1841 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1843 mController->PasteClipboardItemEvent();
1846 void TextField::KeyboardStatusChanged(bool keyboardShown)
1848 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1850 // Just hide the grab handle when keyboard is hidden.
1851 if (!keyboardShown )
1853 mController->KeyboardFocusLostEvent();
1857 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1861 void TextField::OnStageConnection( int depth )
1863 // Sets the depth to the visuals inside the text's decorator.
1864 mDecorator->SetTextDepth( depth );
1866 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1868 // Call the Control::OnStageConnection() to set the depth of the background.
1869 Control::OnStageConnection( depth );
1872 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1877 void TextField::OnIdleSignal()
1879 // Emits the change of input style signals.
1880 mController->ProcessInputStyleChangedSignals();
1882 // Set the pointer to null as the callback manager deletes the callback after execute it.
1883 mIdleCallback = NULL;
1886 TextField::TextField()
1887 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1888 mIdleCallback( NULL ),
1889 mAlignmentOffset( 0.f ),
1890 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1891 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1892 mHasBeenStaged( false )
1896 TextField::~TextField()
1898 UnparentAndReset( mStencil );
1900 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1902 Adaptor::Get().RemoveIdle( mIdleCallback );
1906 } // namespace Internal
1908 } // namespace Toolkit