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/public-api/common/dali-common.h>
25 #include <dali/devel-api/adaptor-framework/key-devel.h>
26 #include <dali/devel-api/adaptor-framework/window-devel.h>
27 #include <dali/devel-api/common/stage.h>
28 #include <dali/devel-api/object/property-helper-devel.h>
29 #include <dali/devel-api/actors/actor-devel.h>
30 #include <dali/public-api/object/type-registry-helper.h>
31 #include <dali/integration-api/debug.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/text/rendering-backend.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 #include <dali-toolkit/devel-api/controls/control-devel.h>
48 #include <dali/integration-api/adaptor-framework/adaptor.h>
50 using namespace Dali::Toolkit::Text;
61 namespace // unnamed namespace
64 #if defined(DEBUG_ENABLED)
65 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
68 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::DevelText::DEFAULT_RENDERING_BACKEND;
69 } // unnamed namespace
76 return Toolkit::TextField::New();
79 // Setup properties, signals and actions using the type-registry.
80 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
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, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
131 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
132 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "textBackground", VECTOR4, BACKGROUND )
136 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextField, "selectedText", STRING, SELECTED_TEXT )
137 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
138 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextStart", INTEGER, SELECTED_TEXT_START )
139 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "selectedTextEnd", INTEGER, SELECTED_TEXT_END )
141 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
142 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
143 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
145 DALI_TYPE_REGISTRATION_END()
147 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
149 /// Retrieves a filename from a value that is a Property::Map
150 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
152 std::string filename;
153 const Property::Map* map = value.GetMap();
156 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
159 filenameValue->Get( filename );
167 Toolkit::TextField TextField::New()
169 // Create the implementation, temporarily owned by this handle on stack
170 IntrusivePtr< TextField > impl = new TextField();
172 // Pass ownership to CustomActor handle
173 Toolkit::TextField handle( *impl );
175 // Second-phase init of the implementation
176 // This can only be done after the CustomActor connection has been made...
182 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
184 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
186 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
190 TextField& impl( GetImpl( textField ) );
191 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
192 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
196 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
198 int backend = value.Get< int >();
199 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
201 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
202 if( DevelText::RENDERING_VECTOR_BASED == backend )
204 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
207 if( impl.mRenderingBackend != backend )
209 impl.mRenderingBackend = backend;
210 impl.mRenderer.Reset();
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 );
218 case Toolkit::TextField::Property::TEXT:
220 const std::string& text = value.Get< std::string >();
221 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
223 impl.mController->SetText( text );
226 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
228 const std::string& text = value.Get< std::string >();
229 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
231 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
234 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
236 const std::string& text = value.Get< std::string >();
237 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
239 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
242 case Toolkit::TextField::Property::FONT_FAMILY:
244 const std::string& fontFamily = value.Get< std::string >();
245 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
246 impl.mController->SetDefaultFontFamily( fontFamily );
249 case Toolkit::TextField::Property::FONT_STYLE:
251 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
254 case Toolkit::TextField::Property::POINT_SIZE:
256 const float pointSize = value.Get< float >();
257 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
259 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
261 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
265 case Toolkit::TextField::Property::MAX_LENGTH:
267 const int max = value.Get< int >();
268 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
270 impl.mController->SetMaximumNumberOfCharacters( max );
273 case Toolkit::TextField::Property::EXCEED_POLICY:
275 impl.mExceedPolicy = value.Get<int>();
277 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
279 impl.EnableClipping();
283 UnparentAndReset( impl.mStencil );
285 impl.RequestTextRelayout();
288 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
290 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
291 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
293 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
294 impl.mController->SetHorizontalAlignment( alignment );
298 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
300 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
301 if( GetVerticalAlignmentEnumeration( value, alignment ) )
303 impl.mController->SetVerticalAlignment( alignment );
304 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
308 case Toolkit::TextField::Property::TEXT_COLOR:
310 const Vector4& textColor = value.Get< Vector4 >();
311 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 );
313 if( impl.mController->GetDefaultColor() != textColor )
315 impl.mController->SetDefaultColor( textColor );
316 impl.mController->SetInputColor( textColor );
317 impl.mRenderer.Reset();
321 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
323 const Vector4& textColor = value.Get< Vector4 >();
324 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 );
326 if( impl.mController->GetPlaceholderTextColor() != textColor )
328 impl.mController->SetPlaceholderTextColor( textColor );
329 impl.mRenderer.Reset();
333 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
335 const Vector4& color = value.Get< Vector4 >();
336 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 );
338 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
339 impl.RequestTextRelayout();
342 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
344 const Vector4& color = value.Get< Vector4 >();
345 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 );
347 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
348 impl.RequestTextRelayout();
351 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
353 const bool enable = value.Get< bool >();
354 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
356 impl.mController->SetEnableCursorBlink( enable );
357 impl.RequestTextRelayout();
360 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
362 const float interval = value.Get< float >();
363 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
365 impl.mDecorator->SetCursorBlinkInterval( interval );
368 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
370 const float duration = value.Get< float >();
371 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
373 impl.mDecorator->SetCursorBlinkDuration( duration );
376 case Toolkit::TextField::Property::CURSOR_WIDTH:
378 const int width = value.Get< int >();
379 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
381 impl.mDecorator->SetCursorWidth( width );
382 impl.mController->GetLayoutEngine().SetCursorWidth( width );
385 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
387 const std::string imageFileName = value.Get< std::string >();
388 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
390 if( imageFileName.size() )
392 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
393 impl.RequestTextRelayout();
397 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
399 const std::string imageFileName = value.Get< std::string >();
400 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
402 if( imageFileName.size() )
404 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
405 impl.RequestTextRelayout();
409 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
411 const float threshold = value.Get< float >();
412 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
414 impl.mDecorator->SetScrollThreshold( threshold );
417 case Toolkit::TextField::Property::SCROLL_SPEED:
419 const float speed = value.Get< float >();
420 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
422 impl.mDecorator->SetScrollSpeed( speed );
425 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
427 const std::string filename = GetImageFileNameFromPropertyValue( value );
429 if( filename.size() )
431 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
432 impl.RequestTextRelayout();
436 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
438 const std::string filename = GetImageFileNameFromPropertyValue( value );
440 if( filename.size() )
442 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
443 impl.RequestTextRelayout();
447 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
449 const std::string filename = GetImageFileNameFromPropertyValue( value );
451 if( filename.size() )
453 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
454 impl.RequestTextRelayout();
458 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
460 const std::string filename = GetImageFileNameFromPropertyValue( value );
462 if( filename.size() )
464 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
465 impl.RequestTextRelayout();
469 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
471 const std::string filename = GetImageFileNameFromPropertyValue( value );
473 if( filename.size() )
475 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
476 impl.RequestTextRelayout();
480 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
482 const std::string filename = GetImageFileNameFromPropertyValue( value );
484 if( filename.size() )
486 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
487 impl.RequestTextRelayout();
491 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
493 const Vector4 color = value.Get< Vector4 >();
494 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 );
496 impl.mDecorator->SetHighlightColor( color );
497 impl.RequestTextRelayout();
500 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
502 const Rect<int> box = value.Get< Rect<int> >();
503 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 );
505 impl.mDecorator->SetBoundingBox( box );
506 impl.RequestTextRelayout();
509 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
511 const Property::Map* map = value.GetMap();
514 impl.mInputMethodOptions.ApplyProperty( *map );
516 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
518 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
519 if (control == textField)
521 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
525 case Toolkit::TextField::Property::INPUT_COLOR:
527 const Vector4 inputColor = value.Get< Vector4 >();
528 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 );
530 impl.mController->SetInputColor( inputColor );
533 case Toolkit::TextField::Property::ENABLE_MARKUP:
535 const bool enableMarkup = value.Get<bool>();
536 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
538 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
541 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
543 const std::string& fontFamily = value.Get< std::string >();
544 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
545 impl.mController->SetInputFontFamily( fontFamily );
548 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
550 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
553 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
555 const float pointSize = value.Get< float >();
556 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
557 impl.mController->SetInputFontPointSize( pointSize );
560 case Toolkit::TextField::Property::UNDERLINE:
562 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
565 impl.mRenderer.Reset();
569 case Toolkit::TextField::Property::INPUT_UNDERLINE:
571 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
574 impl.mRenderer.Reset();
578 case Toolkit::TextField::Property::SHADOW:
580 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
583 impl.mRenderer.Reset();
587 case Toolkit::TextField::Property::INPUT_SHADOW:
589 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
592 impl.mRenderer.Reset();
596 case Toolkit::TextField::Property::EMBOSS:
598 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
601 impl.mRenderer.Reset();
605 case Toolkit::TextField::Property::INPUT_EMBOSS:
607 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
610 impl.mRenderer.Reset();
614 case Toolkit::TextField::Property::OUTLINE:
616 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
619 impl.mRenderer.Reset();
623 case Toolkit::TextField::Property::INPUT_OUTLINE:
625 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
628 impl.mRenderer.Reset();
632 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
634 const Property::Map* map = value.GetMap();
637 impl.mController->SetHiddenInputOption(*map);
641 case Toolkit::TextField::Property::PIXEL_SIZE:
643 const float pixelSize = value.Get< float >();
644 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
646 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
648 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
652 case Toolkit::TextField::Property::ENABLE_SELECTION:
654 const bool enableSelection = value.Get< bool >();
655 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
656 impl.mController->SetSelectionEnabled( enableSelection );
659 case Toolkit::TextField::Property::PLACEHOLDER:
661 const Property::Map* map = value.GetMap();
664 impl.mController->SetPlaceholderProperty( *map );
668 case Toolkit::TextField::Property::ELLIPSIS:
670 const bool ellipsis = value.Get<bool>();
671 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
673 impl.mController->SetTextElideEnabled( ellipsis );
676 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
678 const bool shiftSelection = value.Get<bool>();
679 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
681 impl.mController->SetShiftSelectionEnabled( shiftSelection );
684 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
686 const bool grabHandleEnabled = value.Get<bool>();
687 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
689 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
692 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
694 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
697 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
699 const bool grabHandlePopupEnabled = value.Get<bool>();
700 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
702 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
705 case Toolkit::DevelTextField::Property::BACKGROUND:
707 const Vector4 backgroundColor = value.Get< Vector4 >();
708 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 );
710 impl.mController->SetBackgroundEnabled( true );
711 impl.mController->SetBackgroundColor( backgroundColor );
714 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
716 if( impl.mController )
718 uint32_t start = static_cast<uint32_t>(value.Get< int >());
719 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start );
720 impl.SetTextSelectionRange( &start, nullptr );
724 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
726 if( impl.mController )
728 uint32_t end = static_cast<uint32_t>(value.Get< int >());
729 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end );
730 impl.SetTextSelectionRange( nullptr, &end );
738 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
740 Property::Value value;
742 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
746 TextField& impl( GetImpl( textField ) );
747 DALI_ASSERT_DEBUG( impl.mController && "No text contoller" );
748 DALI_ASSERT_DEBUG( impl.mDecorator && "No text decorator" );
752 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
754 value = impl.mRenderingBackend;
757 case Toolkit::TextField::Property::TEXT:
760 impl.mController->GetText( text );
761 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
765 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
768 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
772 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
775 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
779 case Toolkit::TextField::Property::FONT_FAMILY:
781 value = impl.mController->GetDefaultFontFamily();
784 case Toolkit::TextField::Property::FONT_STYLE:
786 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
789 case Toolkit::TextField::Property::POINT_SIZE:
791 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
794 case Toolkit::TextField::Property::MAX_LENGTH:
796 value = impl.mController->GetMaximumNumberOfCharacters();
799 case Toolkit::TextField::Property::EXCEED_POLICY:
801 value = impl.mExceedPolicy;
804 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
806 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
810 value = std::string( name );
814 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
816 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
820 value = std::string( name );
824 case Toolkit::TextField::Property::TEXT_COLOR:
826 value = impl.mController->GetDefaultColor();
829 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
831 value = impl.mController->GetPlaceholderTextColor();
834 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
836 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
839 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
841 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
844 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
846 value = impl.mController->GetEnableCursorBlink();
849 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
851 value = impl.mDecorator->GetCursorBlinkInterval();
854 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
856 value = impl.mDecorator->GetCursorBlinkDuration();
859 case Toolkit::TextField::Property::CURSOR_WIDTH:
861 value = impl.mDecorator->GetCursorWidth();
864 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
866 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
869 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
871 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
874 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
876 value = impl.mDecorator->GetScrollThreshold();
879 case Toolkit::TextField::Property::SCROLL_SPEED:
881 value = impl.mDecorator->GetScrollSpeed();
884 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
886 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
889 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
891 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
894 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
896 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
899 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
901 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
904 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
906 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
909 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
911 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
914 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
916 value = impl.mDecorator->GetHighlightColor();
919 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
921 Rect<int> boundingBox;
922 impl.mDecorator->GetBoundingBox( boundingBox );
926 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
929 impl.mInputMethodOptions.RetrieveProperty( map );
933 case Toolkit::TextField::Property::INPUT_COLOR:
935 value = impl.mController->GetInputColor();
938 case Toolkit::TextField::Property::ENABLE_MARKUP:
940 value = impl.mController->IsMarkupProcessorEnabled();
943 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
945 value = impl.mController->GetInputFontFamily();
948 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
950 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
953 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
955 value = impl.mController->GetInputFontPointSize();
958 case Toolkit::TextField::Property::UNDERLINE:
960 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
963 case Toolkit::TextField::Property::INPUT_UNDERLINE:
965 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
968 case Toolkit::TextField::Property::SHADOW:
970 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
973 case Toolkit::TextField::Property::INPUT_SHADOW:
975 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
978 case Toolkit::TextField::Property::EMBOSS:
980 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
983 case Toolkit::TextField::Property::INPUT_EMBOSS:
985 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
988 case Toolkit::TextField::Property::OUTLINE:
990 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
993 case Toolkit::TextField::Property::INPUT_OUTLINE:
995 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
998 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1001 impl.mController->GetHiddenInputOption(map);
1005 case Toolkit::TextField::Property::PIXEL_SIZE:
1007 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1010 case Toolkit::TextField::Property::ENABLE_SELECTION:
1012 value = impl.mController->IsSelectionEnabled();
1015 case Toolkit::TextField::Property::PLACEHOLDER:
1018 impl.mController->GetPlaceholderProperty( map );
1022 case Toolkit::TextField::Property::ELLIPSIS:
1024 value = impl.mController->IsTextElideEnabled();
1027 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1029 value = impl.mController->IsShiftSelectionEnabled();
1032 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1034 value = impl.mController->IsGrabHandleEnabled();
1037 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1039 value = impl.mController->IsMatchSystemLanguageDirection();
1042 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1044 value = impl.mController->IsGrabHandlePopupEnabled();
1047 case Toolkit::DevelTextField::Property::BACKGROUND:
1049 value = impl.mController->GetBackgroundColor();
1052 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1054 value = impl.mController->GetSelectedText( );
1057 case Toolkit::DevelTextField::Property::SELECTED_TEXT_START:
1059 Uint32Pair range = impl.GetTextSelectionRange( );
1060 value = static_cast<int>(range.first);
1063 case Toolkit::DevelTextField::Property::SELECTED_TEXT_END:
1065 Uint32Pair range = impl.GetTextSelectionRange( );
1066 value = static_cast<int>(range.second);
1075 void TextField::SelectWholeText()
1077 if( mController && mController->IsShowingRealText() )
1079 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1084 void TextField::SelectNone()
1086 if( mController && mController->IsShowingRealText() )
1088 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1093 void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end)
1095 if( mController && mController->IsShowingRealText() )
1097 mController->SetTextSelectionRange( start, end );
1102 Uint32Pair TextField::GetTextSelectionRange() const
1105 if( mController && mController->IsShowingRealText() )
1107 range = mController->GetTextSelectionRange();
1113 InputMethodContext TextField::GetInputMethodContext()
1115 return mInputMethodContext;
1118 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1120 Dali::BaseHandle handle( object );
1122 bool connected( true );
1123 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1125 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1127 field.TextChangedSignal().Connect( tracker, functor );
1129 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1131 field.MaxLengthReachedSignal().Connect( tracker, functor );
1133 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1135 field.InputStyleChangedSignal().Connect( tracker, functor );
1139 // signalName does not match any signal
1146 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1148 return mTextChangedSignal;
1151 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1153 return mMaxLengthReachedSignal;
1156 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1158 return mInputStyleChangedSignal;
1161 void TextField::OnInitialize()
1163 Actor self = Self();
1165 mController = Text::Controller::New( this, this ,this);
1167 // When using the vector-based rendering, the size of the GLyphs are different
1168 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1169 mController->SetGlyphType( glyphType );
1171 mDecorator = Text::Decorator::New( *mController,
1174 mInputMethodContext = InputMethodContext::New( self );
1176 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1178 // Enables the text input.
1179 mController->EnableTextInput( mDecorator, mInputMethodContext );
1181 // Enables the horizontal scrolling after the text input has been enabled.
1182 mController->SetHorizontalScrollEnabled( true );
1184 // Disables the vertical scrolling.
1185 mController->SetVerticalScrollEnabled( false );
1187 // Disable the smooth handle panning.
1188 mController->SetSmoothHandlePanEnabled( false );
1190 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1191 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1193 // Sets layoutDirection value
1194 Dali::Stage stage = Dali::Stage::GetCurrent();
1195 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1196 mController->SetLayoutDirection( layoutDirection );
1198 // Forward input events to controller
1199 EnableGestureDetection( static_cast<GestureType::Value>( GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS ) );
1200 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1202 self.TouchedSignal().Connect( this, &TextField::OnTouched );
1204 // Set BoundingBox to stage size if not already set.
1205 Rect<int> boundingBox;
1206 mDecorator->GetBoundingBox( boundingBox );
1208 if( boundingBox.IsEmpty() )
1210 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1211 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1214 // Flip vertically the 'left' selection handle
1215 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1217 // Fill-parent area by default
1218 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1219 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1220 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1222 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1224 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1230 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1232 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1236 case StyleChange::DEFAULT_FONT_CHANGE:
1238 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1239 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1240 // Property system did not set the font so should update it.
1241 mController->UpdateAfterFontChange( newFont );
1246 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1248 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1252 case StyleChange::THEME_CHANGE:
1254 // Nothing to do, let control base class handle this
1259 // Up call to Control
1260 Control::OnStyleChange( styleManager, change );
1263 Vector3 TextField::GetNaturalSize()
1266 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1268 Vector3 naturalSize = mController->GetNaturalSize();
1269 naturalSize.width += ( padding.start + padding.end );
1270 naturalSize.height += ( padding.top + padding.bottom );
1275 float TextField::GetHeightForWidth( float width )
1278 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1279 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1282 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1284 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1286 Actor self = Self();
1289 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1291 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1293 // Support Right-To-Left of padding
1294 Dali::LayoutDirection::Type layoutDirection;
1295 if( mController->IsMatchSystemLanguageDirection() )
1297 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1301 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1303 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1305 std::swap( padding.start, padding.end );
1310 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1314 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1317 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1319 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1322 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1325 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1327 mDecorator->Relayout( size );
1332 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1335 RenderText( updateTextType );
1339 // The text-field emits signals when the input style changes. These changes of style are
1340 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1341 // can't be emitted during the size negotiation as the callbacks may update the UI.
1342 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1343 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1345 if( Adaptor::IsAvailable() )
1347 Adaptor& adaptor = Adaptor::Get();
1349 if( NULL == mIdleCallback )
1351 // @note: The callback manager takes the ownership of the callback object.
1352 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1353 adaptor.AddIdle( mIdleCallback, false );
1359 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1361 Actor renderableActor;
1363 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1367 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1369 renderableActor = mRenderer->Render( mController->GetView(),
1371 Property::INVALID_INDEX, // Animatable property not supported
1373 DepthIndex::CONTENT );
1376 if( renderableActor != mRenderableActor )
1378 UnparentAndReset( mBackgroundActor );
1379 UnparentAndReset( mRenderableActor );
1380 mRenderableActor = renderableActor;
1382 if ( mRenderableActor )
1384 mBackgroundActor = mController->CreateBackgroundActor();
1389 if( mRenderableActor )
1391 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1393 float renderableActorPositionX, renderableActorPositionY;
1397 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1398 renderableActorPositionY = scrollOffset.y;
1403 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1405 // Support Right-To-Left of padding
1406 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1407 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1409 std::swap( padding.start, padding.end );
1412 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1413 renderableActorPositionY = scrollOffset.y + padding.top;
1416 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1418 // Make sure the actors are parented correctly with/without clipping
1419 Actor self = mStencil ? mStencil : Self();
1421 Actor highlightActor;
1423 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1424 endIt = mClippingDecorationActors.end();
1429 it->LowerToBottom();
1431 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1433 highlightActor = *it;
1436 mClippingDecorationActors.clear();
1438 self.Add( mRenderableActor );
1440 if ( mBackgroundActor )
1442 if ( mDecorator && mDecorator->IsHighlightVisible() )
1444 self.Add( mBackgroundActor );
1445 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1446 mBackgroundActor.LowerBelow( highlightActor );
1450 mRenderableActor.Add( mBackgroundActor );
1451 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1452 mBackgroundActor.LowerToBottom();
1458 void TextField::OnKeyInputFocusGained()
1460 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1461 if ( mInputMethodContext )
1463 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1465 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1467 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1469 // Notify that the text editing start.
1470 mInputMethodContext.Activate();
1472 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1473 mInputMethodContext.SetRestoreAfterFocusLost( true );
1475 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1479 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1482 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1484 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1487 void TextField::OnKeyInputFocusLost()
1489 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1490 if ( mInputMethodContext )
1492 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1493 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1494 mInputMethodContext.SetRestoreAfterFocusLost( false );
1496 // Notify that the text editing finish.
1497 mInputMethodContext.Deactivate();
1499 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1501 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1505 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1508 mController->KeyboardFocusLostEvent();
1510 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1513 void TextField::OnTap( const TapGesture& gesture )
1515 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1516 if ( mInputMethodContext )
1518 mInputMethodContext.Activate();
1520 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1522 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1523 const Vector2& localPoint = gesture.GetLocalPoint();
1524 mController->TapEvent( gesture.GetNumberOfTaps(), localPoint.x - padding.start, localPoint.y - padding.top );
1529 void TextField::OnPan( const PanGesture& gesture )
1531 mController->PanEvent( gesture.GetState(), gesture.GetDisplacement() );
1534 void TextField::OnLongPress( const LongPressGesture& gesture )
1536 if ( mInputMethodContext )
1538 mInputMethodContext.Activate();
1541 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1542 const Vector2& localPoint = gesture.GetLocalPoint();
1543 mController->LongPressEvent( gesture.GetState(), localPoint.x - padding.start, localPoint.y - padding.top );
1548 bool TextField::OnKeyEvent( const KeyEvent& event )
1550 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.GetKeyCode() );
1552 if( Dali::DALI_KEY_ESCAPE == event.GetKeyCode() && mController->ShouldClearFocusOnEscape() )
1554 // Make sure ClearKeyInputFocus when only key is up
1555 if( event.GetState() == KeyEvent::UP )
1557 ClearKeyInputFocus();
1562 else if( Dali::DevelKey::DALI_KEY_RETURN == event.GetKeyCode() )
1564 // Do nothing when enter is comming.
1568 return mController->KeyEvent( event );
1571 void TextField::RequestTextRelayout()
1576 void TextField::TextChanged()
1578 Dali::Toolkit::TextField handle( GetOwner() );
1579 mTextChangedSignal.Emit( handle );
1582 void TextField::MaxLengthReached()
1584 Dali::Toolkit::TextField handle( GetOwner() );
1585 mMaxLengthReachedSignal.Emit( handle );
1588 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1590 Dali::Toolkit::TextField handle( GetOwner() );
1592 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1594 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1596 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1598 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1600 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1602 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1604 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1606 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1608 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1610 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1612 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1614 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1616 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1618 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1620 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1622 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1624 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1626 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1628 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1630 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1632 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1635 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1638 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1644 mClippingDecorationActors.push_back( actor );
1648 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1649 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1650 Self().Add( actor );
1651 mActiveLayer = actor;
1656 void TextField::OnSceneConnect( Dali::Actor actor )
1658 if ( mHasBeenStaged )
1660 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1664 mHasBeenStaged = true;
1668 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1670 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1671 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1674 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1679 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1684 void TextField::EnableClipping()
1688 // Creates an extra control to be used as stencil buffer.
1689 mStencil = Control::New();
1690 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1691 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1693 // Creates a background visual. Even if the color is transparent it updates the stencil.
1694 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1695 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1696 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1698 // Enable the clipping property.
1699 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1700 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1702 Self().Add( mStencil );
1706 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1708 mController->PasteClipboardItemEvent();
1711 void TextField::KeyboardStatusChanged(bool keyboardShown)
1713 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1715 // Just hide the grab handle when keyboard is hidden.
1716 if (!keyboardShown )
1718 mController->KeyboardFocusLostEvent();
1722 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1726 void TextField::OnSceneConnection( int depth )
1728 // Sets the depth to the visuals inside the text's decorator.
1729 mDecorator->SetTextDepth( depth );
1731 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1733 // Call the Control::OnSceneConnection() to set the depth of the background.
1734 Control::OnSceneConnection( depth );
1737 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1742 void TextField::OnIdleSignal()
1744 // Emits the change of input style signals.
1745 mController->ProcessInputStyleChangedSignals();
1747 // Set the pointer to null as the callback manager deletes the callback after execute it.
1748 mIdleCallback = NULL;
1751 TextField::TextField()
1752 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1753 mIdleCallback( NULL ),
1754 mAlignmentOffset( 0.f ),
1755 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1756 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1757 mHasBeenStaged( false )
1761 TextField::~TextField()
1763 UnparentAndReset( mStencil );
1765 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1767 Adaptor::Get().RemoveIdle( mIdleCallback );
1771 } // namespace Internal
1773 } // namespace Toolkit