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/devel-api/adaptor-framework/window-devel.h>
26 #include <dali/devel-api/common/stage.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/text-enumerations.h>
34 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
35 #include <dali-toolkit/devel-api/text/rendering-backend.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::DevelText::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, "text", STRING, TEXT )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
130 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
135 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
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::DevelTextField::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( DevelText::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 = (DevelText::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.c_str() );
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.c_str() );
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 );
811 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
813 if( impl.mController )
815 uint32_t start = static_cast<uint32_t>(value.Get< int >());
816 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
817 impl.SetTextSelectionRange( &start, nullptr );
821 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
823 if( impl.mController )
825 uint32_t end = static_cast<uint32_t>(value.Get< int >());
826 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
827 impl.SetTextSelectionRange( nullptr, &end );
835 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
837 Property::Value value;
839 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
843 TextField& impl( GetImpl( textField ) );
847 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
849 value = impl.mRenderingBackend;
852 case Toolkit::TextField::Property::TEXT:
854 if( impl.mController )
857 impl.mController->GetText( text );
858 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
863 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
865 if( impl.mController )
868 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
873 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
875 if( impl.mController )
878 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
883 case Toolkit::TextField::Property::FONT_FAMILY:
885 if( impl.mController )
887 value = impl.mController->GetDefaultFontFamily();
891 case Toolkit::TextField::Property::FONT_STYLE:
893 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
896 case Toolkit::TextField::Property::POINT_SIZE:
898 if( impl.mController )
900 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
904 case Toolkit::TextField::Property::MAX_LENGTH:
906 if( impl.mController )
908 value = impl.mController->GetMaximumNumberOfCharacters();
912 case Toolkit::TextField::Property::EXCEED_POLICY:
914 value = impl.mExceedPolicy;
917 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
919 if( impl.mController )
921 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
925 value = std::string( name );
930 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
932 if( impl.mController )
934 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
938 value = std::string( name );
943 case Toolkit::TextField::Property::TEXT_COLOR:
945 if ( impl.mController )
947 value = impl.mController->GetDefaultColor();
951 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
953 if ( impl.mController )
955 value = impl.mController->GetPlaceholderTextColor();
959 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
961 if( impl.mDecorator )
963 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
967 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
969 if( impl.mDecorator )
971 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
975 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
977 value = impl.mController->GetEnableCursorBlink();
980 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
982 if( impl.mDecorator )
984 value = impl.mDecorator->GetCursorBlinkInterval();
988 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
990 if( impl.mDecorator )
992 value = impl.mDecorator->GetCursorBlinkDuration();
996 case Toolkit::TextField::Property::CURSOR_WIDTH:
998 if( impl.mDecorator )
1000 value = impl.mDecorator->GetCursorWidth();
1004 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
1006 if( impl.mDecorator )
1008 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
1012 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
1014 if( impl.mDecorator )
1016 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
1020 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
1022 if( impl.mDecorator )
1024 value = impl.mDecorator->GetScrollThreshold();
1028 case Toolkit::TextField::Property::SCROLL_SPEED:
1030 if( impl.mDecorator )
1032 value = impl.mDecorator->GetScrollSpeed();
1036 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1038 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1041 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1043 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1046 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1048 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1051 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1053 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1056 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1058 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1061 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1063 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1066 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1068 if( impl.mDecorator )
1070 value = impl.mDecorator->GetHighlightColor();
1074 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1076 if( impl.mDecorator )
1078 Rect<int> boundingBox;
1079 impl.mDecorator->GetBoundingBox( boundingBox );
1080 value = boundingBox;
1084 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1087 impl.mInputMethodOptions.RetrieveProperty( map );
1091 case Toolkit::TextField::Property::INPUT_COLOR:
1093 if( impl.mController )
1095 value = impl.mController->GetInputColor();
1099 case Toolkit::TextField::Property::ENABLE_MARKUP:
1101 if( impl.mController )
1103 value = impl.mController->IsMarkupProcessorEnabled();
1107 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1109 if( impl.mController )
1111 value = impl.mController->GetInputFontFamily();
1115 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1117 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1120 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1122 if( impl.mController )
1124 value = impl.mController->GetInputFontPointSize();
1128 case Toolkit::TextField::Property::UNDERLINE:
1130 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1133 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1135 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1138 case Toolkit::TextField::Property::SHADOW:
1140 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1143 case Toolkit::TextField::Property::INPUT_SHADOW:
1145 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1148 case Toolkit::TextField::Property::EMBOSS:
1150 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1153 case Toolkit::TextField::Property::INPUT_EMBOSS:
1155 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1158 case Toolkit::TextField::Property::OUTLINE:
1160 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1163 case Toolkit::TextField::Property::INPUT_OUTLINE:
1165 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1168 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1171 impl.mController->GetHiddenInputOption(map);
1175 case Toolkit::TextField::Property::PIXEL_SIZE:
1177 if( impl.mController )
1179 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1183 case Toolkit::TextField::Property::ENABLE_SELECTION:
1185 if( impl.mController )
1187 value = impl.mController->IsSelectionEnabled();
1191 case Toolkit::TextField::Property::PLACEHOLDER:
1194 impl.mController->GetPlaceholderProperty( map );
1198 case Toolkit::TextField::Property::ELLIPSIS:
1200 if( impl.mController )
1202 value = impl.mController->IsTextElideEnabled();
1206 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1208 if( impl.mController )
1210 value = impl.mController->IsShiftSelectionEnabled();
1214 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1216 if( impl.mController )
1218 value = impl.mController->IsGrabHandleEnabled();
1222 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1224 if( impl.mController )
1226 value = impl.mController->IsMatchSystemLanguageDirection();
1230 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1232 if( impl.mController )
1234 value = impl.mController->IsGrabHandlePopupEnabled();
1238 case Toolkit::DevelTextField::Property::BACKGROUND:
1240 if( impl.mController )
1242 value = impl.mController->GetBackgroundColor();
1246 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1248 if( impl.mController )
1250 value = impl.mController->GetSelectedText( );
1254 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1256 Uint32Pair range = impl.GetTextSelectionRange( );
1257 value = static_cast<int>(range.first);
1260 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1262 Uint32Pair range = impl.GetTextSelectionRange( );
1263 value = static_cast<int>(range.second);
1272 void TextField::SelectWholeText()
1274 if( mController && mController->IsShowingRealText() )
1276 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1281 void TextField::SelectNone()
1283 if( mController && mController->IsShowingRealText() )
1285 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1290 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1292 if( mController && mController->IsShowingRealText() )
1294 mController->SetTextSelectionRange( start, end );
1299 Uint32Pair TextField::GetTextSelectionRange() const
1302 if( mController && mController->IsShowingRealText() )
1304 range = mController->GetTextSelectionRange();
1310 InputMethodContext TextField::GetInputMethodContext()
1312 return mInputMethodContext;
1315 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1317 Dali::BaseHandle handle( object );
1319 bool connected( true );
1320 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1322 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1324 field.TextChangedSignal().Connect( tracker, functor );
1326 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1328 field.MaxLengthReachedSignal().Connect( tracker, functor );
1330 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1332 field.InputStyleChangedSignal().Connect( tracker, functor );
1336 // signalName does not match any signal
1343 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1345 return mTextChangedSignal;
1348 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1350 return mMaxLengthReachedSignal;
1353 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1355 return mInputStyleChangedSignal;
1358 void TextField::OnInitialize()
1360 Actor self = Self();
1362 mController = Text::Controller::New( this, this ,this);
1364 // When using the vector-based rendering, the size of the GLyphs are different
1365 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1366 mController->SetGlyphType( glyphType );
1368 mDecorator = Text::Decorator::New( *mController,
1371 mInputMethodContext = InputMethodContext::New( self );
1373 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1375 // Enables the text input.
1376 mController->EnableTextInput( mDecorator, mInputMethodContext );
1378 // Enables the horizontal scrolling after the text input has been enabled.
1379 mController->SetHorizontalScrollEnabled( true );
1381 // Disables the vertical scrolling.
1382 mController->SetVerticalScrollEnabled( false );
1384 // Disable the smooth handle panning.
1385 mController->SetSmoothHandlePanEnabled( false );
1387 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1388 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1390 // Sets layoutDirection value
1391 Dali::Stage stage = Dali::Stage::GetCurrent();
1392 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1393 mController->SetLayoutDirection( layoutDirection );
1395 // Forward input events to controller
1396 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1397 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1399 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1401 // Set BoundingBox to stage size if not already set.
1402 Rect<int> boundingBox;
1403 mDecorator->GetBoundingBox( boundingBox );
1405 if( boundingBox.IsEmpty() )
1407 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1408 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1411 // Flip vertically the 'left' selection handle
1412 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1414 // Fill-parent area by default
1415 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1416 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1417 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1419 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1421 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1427 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1429 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1433 case StyleChange::DEFAULT_FONT_CHANGE:
1435 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1436 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1437 // Property system did not set the font so should update it.
1438 mController->UpdateAfterFontChange( newFont );
1443 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1445 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1449 case StyleChange::THEME_CHANGE:
1451 // Nothing to do, let control base class handle this
1456 // Up call to Control
1457 Control::OnStyleChange( styleManager, change );
1460 Vector3 TextField::GetNaturalSize()
1463 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1465 Vector3 naturalSize = mController->GetNaturalSize();
1466 naturalSize.width += ( padding.start + padding.end );
1467 naturalSize.height += ( padding.top + padding.bottom );
1472 float TextField::GetHeightForWidth( float width )
1475 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1476 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1479 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1481 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1483 Actor self = Self();
1486 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1488 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1490 // Support Right-To-Left of padding
1491 Dali::LayoutDirection::Type layoutDirection;
1492 if( mController->IsMatchSystemLanguageDirection() )
1494 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1498 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1500 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1502 std::swap( padding.start, padding.end );
1507 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1511 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1514 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1516 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1519 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1522 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1524 mDecorator->Relayout( size );
1529 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1532 RenderText( updateTextType );
1536 // The text-field emits signals when the input style changes. These changes of style are
1537 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1538 // can't be emitted during the size negotiation as the callbacks may update the UI.
1539 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1540 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1542 if( Adaptor::IsAvailable() )
1544 Adaptor& adaptor = Adaptor::Get();
1546 if( NULL == mIdleCallback )
1548 // @note: The callback manager takes the ownership of the callback object.
1549 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1550 adaptor.AddIdle( mIdleCallback, false );
1556 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1558 Actor renderableActor;
1560 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1564 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1566 renderableActor = mRenderer->Render( mController->GetView(),
1568 Property::INVALID_INDEX, // Animatable property not supported
1570 DepthIndex::CONTENT );
1573 if( renderableActor != mRenderableActor )
1575 UnparentAndReset( mBackgroundActor );
1576 UnparentAndReset( mRenderableActor );
1577 mRenderableActor = renderableActor;
1579 if ( mRenderableActor )
1581 mBackgroundActor = mController->CreateBackgroundActor();
1586 if( mRenderableActor )
1588 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1590 float renderableActorPositionX, renderableActorPositionY;
1594 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1595 renderableActorPositionY = scrollOffset.y;
1600 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1602 // Support Right-To-Left of padding
1603 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1604 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1606 std::swap( padding.start, padding.end );
1609 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1610 renderableActorPositionY = scrollOffset.y + padding.top;
1613 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1615 // Make sure the actors are parented correctly with/without clipping
1616 Actor self = mStencil ? mStencil : Self();
1618 Actor highlightActor;
1620 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1621 endIt = mClippingDecorationActors.end();
1626 it->LowerToBottom();
1628 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1630 highlightActor = *it;
1633 mClippingDecorationActors.clear();
1635 self.Add( mRenderableActor );
1637 if ( mBackgroundActor )
1639 if ( mDecorator && mDecorator->IsHighlightVisible() )
1641 self.Add( mBackgroundActor );
1642 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1643 mBackgroundActor.LowerBelow( highlightActor );
1647 mRenderableActor.Add( mBackgroundActor );
1648 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1649 mBackgroundActor.LowerToBottom();
1655 void TextField::OnKeyInputFocusGained()
1657 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1658 if ( mInputMethodContext )
1660 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1662 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1664 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1666 // Notify that the text editing start.
1667 mInputMethodContext.Activate();
1669 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1670 mInputMethodContext.SetRestoreAfterFocusLost( true );
1672 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1676 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1679 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1681 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1684 void TextField::OnKeyInputFocusLost()
1686 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1687 if ( mInputMethodContext )
1689 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1690 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1691 mInputMethodContext.SetRestoreAfterFocusLost( false );
1693 // Notify that the text editing finish.
1694 mInputMethodContext.Deactivate();
1696 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1698 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1702 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1705 mController->KeyboardFocusLostEvent();
1707 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1710 void TextField::OnTap( const TapGesture& gesture )
1712 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1713 if ( mInputMethodContext )
1715 mInputMethodContext.Activate();
1717 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1719 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1720 const Vector2& localPoint = gesture.GetLocalPoint();
1721 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1726 void TextField::OnPan( const PanGesture& gesture )
1728 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1731 void TextField::OnLongPress( const LongPressGesture& gesture )
1733 if ( mInputMethodContext )
1735 mInputMethodContext.Activate();
1738 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1739 const Vector2& localPoint = gesture.GetLocalPoint();
1740 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1745 bool TextField::OnKeyEvent( const KeyEvent& event )
1747 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1749 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1751 // Make sure ClearKeyInputFocus when only key is up
1752 if( event.GetState() == KeyEvent::UP )
1754 ClearKeyInputFocus();
1759 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1761 // Do nothing when enter is comming.
1765 return mController->KeyEvent( event );
1768 void TextField::RequestTextRelayout()
1773 void TextField::TextChanged()
1775 Dali::Toolkit::TextField handle( GetOwner() );
1776 mTextChangedSignal.Emit( handle );
1779 void TextField::MaxLengthReached()
1781 Dali::Toolkit::TextField handle( GetOwner() );
1782 mMaxLengthReachedSignal.Emit( handle );
1785 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1787 Dali::Toolkit::TextField handle( GetOwner() );
1789 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1791 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1793 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1795 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1797 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1799 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1801 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1803 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1805 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1807 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1809 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1811 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1813 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1815 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1817 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1819 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1821 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1823 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1825 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1827 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1829 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1832 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1835 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1841 mClippingDecorationActors.push_back( actor );
1845 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1846 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1847 Self().Add( actor );
1848 mActiveLayer = actor;
1853 void TextField::OnSceneConnect( Dali::Actor actor )
1855 if ( mHasBeenStaged )
1857 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1861 mHasBeenStaged = true;
1865 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1867 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1868 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1871 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1876 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1881 void TextField::EnableClipping()
1885 // Creates an extra control to be used as stencil buffer.
1886 mStencil = Control::New();
1887 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1888 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1890 // Creates a background visual. Even if the color is transparent it updates the stencil.
1891 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1892 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1893 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1895 // Enable the clipping property.
1896 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1897 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1899 Self().Add( mStencil );
1903 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1905 mController->PasteClipboardItemEvent();
1908 void TextField::KeyboardStatusChanged(bool keyboardShown)
1910 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1912 // Just hide the grab handle when keyboard is hidden.
1913 if (!keyboardShown )
1915 mController->KeyboardFocusLostEvent();
1919 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1923 void TextField::OnSceneConnection( int depth )
1925 // Sets the depth to the visuals inside the text's decorator.
1926 mDecorator->SetTextDepth( depth );
1928 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1930 // Call the Control::OnSceneConnection() to set the depth of the background.
1931 Control::OnSceneConnection( depth );
1934 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1939 void TextField::OnIdleSignal()
1941 // Emits the change of input style signals.
1942 mController->ProcessInputStyleChangedSignals();
1944 // Set the pointer to null as the callback manager deletes the callback after execute it.
1945 mIdleCallback = NULL;
1948 TextField::TextField()
1949 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1950 mIdleCallback( NULL ),
1951 mAlignmentOffset( 0.f ),
1952 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1953 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1954 mHasBeenStaged( false )
1958 TextField::~TextField()
1960 UnparentAndReset( mStencil );
1962 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1964 Adaptor::Get().RemoveIdle( mIdleCallback );
1968 } // namespace Internal
1970 } // namespace Toolkit