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 )
138 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
139 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
140 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
142 DALI_TYPE_REGISTRATION_END()
144 const char * const IMAGE_MAP_FILENAME_STRING = "filename";
146 /// Retrieves a filename from a value that is a Property::Map
147 std::string GetImageFileNameFromPropertyValue( const Property::Value& value )
149 std::string filename;
150 const Property::Map* map = value.GetMap();
153 const Property::Value* filenameValue = map->Find( IMAGE_MAP_FILENAME_STRING );
156 filenameValue->Get( filename );
164 Toolkit::TextField TextField::New()
166 // Create the implementation, temporarily owned by this handle on stack
167 IntrusivePtr< TextField > impl = new TextField();
169 // Pass ownership to CustomActor handle
170 Toolkit::TextField handle( *impl );
172 // Second-phase init of the implementation
173 // This can only be done after the CustomActor connection has been made...
179 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
181 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
183 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
188 TextField& impl( GetImpl( textField ) );
192 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
194 int backend = value.Get< int >();
195 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
197 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
198 if( DevelText::RENDERING_VECTOR_BASED == backend )
200 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
203 if( impl.mRenderingBackend != backend )
205 impl.mRenderingBackend = backend;
206 impl.mRenderer.Reset();
208 if( impl.mController )
210 // When using the vector-based rendering, the size of the GLyphs are different
211 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
212 impl.mController->SetGlyphType( glyphType );
217 case Toolkit::TextField::Property::TEXT:
219 if( impl.mController )
221 const std::string& text = value.Get< std::string >();
222 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
224 impl.mController->SetText( text );
228 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
230 if( impl.mController )
232 const std::string& text = value.Get< std::string >();
233 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
235 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
239 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
241 if( impl.mController )
243 const std::string& text = value.Get< std::string >();
244 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
246 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
250 case Toolkit::TextField::Property::FONT_FAMILY:
252 if( impl.mController )
254 const std::string& fontFamily = value.Get< std::string >();
255 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
256 impl.mController->SetDefaultFontFamily( fontFamily );
260 case Toolkit::TextField::Property::FONT_STYLE:
262 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
265 case Toolkit::TextField::Property::POINT_SIZE:
267 if( impl.mController )
269 const float pointSize = value.Get< float >();
270 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
272 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
274 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
279 case Toolkit::TextField::Property::MAX_LENGTH:
281 if( impl.mController )
283 const int max = value.Get< int >();
284 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
286 impl.mController->SetMaximumNumberOfCharacters( max );
290 case Toolkit::TextField::Property::EXCEED_POLICY:
292 impl.mExceedPolicy = value.Get<int>();
294 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
296 impl.EnableClipping();
300 UnparentAndReset( impl.mStencil );
302 impl.RequestTextRelayout();
305 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
307 if( impl.mController )
309 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
310 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
312 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
313 impl.mController->SetHorizontalAlignment( alignment );
318 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
320 if( impl.mController )
322 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
323 if( GetVerticalAlignmentEnumeration( value, alignment ) )
325 impl.mController->SetVerticalAlignment( alignment );
326 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
331 case Toolkit::TextField::Property::TEXT_COLOR:
333 if( impl.mController )
335 const Vector4& textColor = value.Get< Vector4 >();
336 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 );
338 if( impl.mController->GetDefaultColor() != textColor )
340 impl.mController->SetDefaultColor( textColor );
341 impl.mController->SetInputColor( textColor );
342 impl.mRenderer.Reset();
347 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
349 if( impl.mController )
351 const Vector4& textColor = value.Get< Vector4 >();
352 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 );
354 if( impl.mController->GetPlaceholderTextColor() != textColor )
356 impl.mController->SetPlaceholderTextColor( textColor );
357 impl.mRenderer.Reset();
362 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
364 if( impl.mDecorator )
366 const Vector4& color = value.Get< Vector4 >();
367 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 );
369 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
370 impl.RequestTextRelayout();
374 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
376 if( impl.mDecorator )
378 const Vector4& color = value.Get< Vector4 >();
379 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 );
381 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
382 impl.RequestTextRelayout();
386 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
388 if( impl.mController )
390 const bool enable = value.Get< bool >();
391 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
393 impl.mController->SetEnableCursorBlink( enable );
394 impl.RequestTextRelayout();
398 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
400 if( impl.mDecorator )
402 const float interval = value.Get< float >();
403 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
405 impl.mDecorator->SetCursorBlinkInterval( interval );
409 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
411 if( impl.mDecorator )
413 const float duration = value.Get< float >();
414 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
416 impl.mDecorator->SetCursorBlinkDuration( duration );
420 case Toolkit::TextField::Property::CURSOR_WIDTH:
422 if( impl.mDecorator )
424 const int width = value.Get< int >();
425 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
427 impl.mDecorator->SetCursorWidth( width );
428 impl.mController->GetLayoutEngine().SetCursorWidth( width );
432 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
434 const std::string imageFileName = value.Get< std::string >();
435 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
437 if( impl.mDecorator && imageFileName.size() )
439 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, imageFileName );
440 impl.RequestTextRelayout();
444 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
446 const std::string imageFileName = value.Get< std::string >();
447 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), imageFileName.c_str() );
449 if( impl.mDecorator && imageFileName.size() )
451 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, imageFileName );
452 impl.RequestTextRelayout();
456 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
458 const float threshold = value.Get< float >();
459 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
461 if( impl.mDecorator )
463 impl.mDecorator->SetScrollThreshold( threshold );
467 case Toolkit::TextField::Property::SCROLL_SPEED:
469 const float speed = value.Get< float >();
470 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
472 if( impl.mDecorator )
474 impl.mDecorator->SetScrollSpeed( speed );
478 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
480 const std::string filename = GetImageFileNameFromPropertyValue( value );
482 if( impl.mDecorator && filename.size() )
484 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
485 impl.RequestTextRelayout();
489 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
491 const std::string filename = GetImageFileNameFromPropertyValue( value );
493 if( impl.mDecorator && filename.size() )
495 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, filename );
496 impl.RequestTextRelayout();
500 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
502 const std::string filename = GetImageFileNameFromPropertyValue( value );
504 if( impl.mDecorator && filename.size() )
506 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
507 impl.RequestTextRelayout();
511 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
513 const std::string filename = GetImageFileNameFromPropertyValue( value );
515 if( impl.mDecorator && filename.size() )
517 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, filename );
518 impl.RequestTextRelayout();
522 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
524 const std::string filename = GetImageFileNameFromPropertyValue( value );
526 if( impl.mDecorator && filename.size() )
528 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
529 impl.RequestTextRelayout();
533 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
535 const std::string filename = GetImageFileNameFromPropertyValue( value );
537 if( impl.mDecorator && filename.size() )
539 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, filename );
540 impl.RequestTextRelayout();
544 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
546 const Vector4 color = value.Get< Vector4 >();
547 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 );
549 if( impl.mDecorator )
551 impl.mDecorator->SetHighlightColor( color );
552 impl.RequestTextRelayout();
556 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
558 if( impl.mDecorator )
560 const Rect<int> box = value.Get< Rect<int> >();
561 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 );
563 impl.mDecorator->SetBoundingBox( box );
564 impl.RequestTextRelayout();
568 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
570 const Property::Map* map = value.GetMap();
573 impl.mInputMethodOptions.ApplyProperty( *map );
575 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
577 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
578 if (control == textField)
580 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
584 case Toolkit::TextField::Property::INPUT_COLOR:
586 if( impl.mController )
588 const Vector4 inputColor = value.Get< Vector4 >();
589 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 );
591 impl.mController->SetInputColor( inputColor );
595 case Toolkit::TextField::Property::ENABLE_MARKUP:
597 if( impl.mController )
599 const bool enableMarkup = value.Get<bool>();
600 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
602 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
606 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
608 if( impl.mController )
610 const std::string& fontFamily = value.Get< std::string >();
611 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
612 impl.mController->SetInputFontFamily( fontFamily );
616 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
618 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
621 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
623 if( impl.mController )
625 const float pointSize = value.Get< float >();
626 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
627 impl.mController->SetInputFontPointSize( pointSize );
631 case Toolkit::TextField::Property::UNDERLINE:
633 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
636 impl.mRenderer.Reset();
640 case Toolkit::TextField::Property::INPUT_UNDERLINE:
642 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
645 impl.mRenderer.Reset();
649 case Toolkit::TextField::Property::SHADOW:
651 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
654 impl.mRenderer.Reset();
658 case Toolkit::TextField::Property::INPUT_SHADOW:
660 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
663 impl.mRenderer.Reset();
667 case Toolkit::TextField::Property::EMBOSS:
669 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
672 impl.mRenderer.Reset();
676 case Toolkit::TextField::Property::INPUT_EMBOSS:
678 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
681 impl.mRenderer.Reset();
685 case Toolkit::TextField::Property::OUTLINE:
687 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
690 impl.mRenderer.Reset();
694 case Toolkit::TextField::Property::INPUT_OUTLINE:
696 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
699 impl.mRenderer.Reset();
703 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
705 const Property::Map* map = value.GetMap();
708 impl.mController->SetHiddenInputOption(*map);
712 case Toolkit::TextField::Property::PIXEL_SIZE:
714 if( impl.mController )
716 const float pixelSize = value.Get< float >();
717 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
719 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
721 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
726 case Toolkit::TextField::Property::ENABLE_SELECTION:
728 if( impl.mController )
730 const bool enableSelection = value.Get< bool >();
731 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
732 impl.mController->SetSelectionEnabled( enableSelection );
736 case Toolkit::TextField::Property::PLACEHOLDER:
738 const Property::Map* map = value.GetMap();
741 impl.mController->SetPlaceholderProperty( *map );
745 case Toolkit::TextField::Property::ELLIPSIS:
747 if( impl.mController )
749 const bool ellipsis = value.Get<bool>();
750 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
752 impl.mController->SetTextElideEnabled( ellipsis );
756 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
758 if( impl.mController )
760 const bool shiftSelection = value.Get<bool>();
761 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
763 impl.mController->SetShiftSelectionEnabled( shiftSelection );
767 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
769 if( impl.mController )
771 const bool grabHandleEnabled = value.Get<bool>();
772 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
774 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
778 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
780 if( impl.mController )
782 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
786 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
788 if( impl.mController )
790 const bool grabHandlePopupEnabled = value.Get<bool>();
791 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
793 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
797 case Toolkit::DevelTextField::Property::BACKGROUND:
799 if( impl.mController )
801 const Vector4 backgroundColor = value.Get< Vector4 >();
802 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 );
804 impl.mController->SetBackgroundEnabled( true );
805 impl.mController->SetBackgroundColor( backgroundColor );
813 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
815 Property::Value value;
817 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
821 TextField& impl( GetImpl( textField ) );
825 case Toolkit::DevelTextField::Property::RENDERING_BACKEND:
827 value = impl.mRenderingBackend;
830 case Toolkit::TextField::Property::TEXT:
832 if( impl.mController )
835 impl.mController->GetText( text );
836 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
841 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
843 if( impl.mController )
846 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
851 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
853 if( impl.mController )
856 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
861 case Toolkit::TextField::Property::FONT_FAMILY:
863 if( impl.mController )
865 value = impl.mController->GetDefaultFontFamily();
869 case Toolkit::TextField::Property::FONT_STYLE:
871 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
874 case Toolkit::TextField::Property::POINT_SIZE:
876 if( impl.mController )
878 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
882 case Toolkit::TextField::Property::MAX_LENGTH:
884 if( impl.mController )
886 value = impl.mController->GetMaximumNumberOfCharacters();
890 case Toolkit::TextField::Property::EXCEED_POLICY:
892 value = impl.mExceedPolicy;
895 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
897 if( impl.mController )
899 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
903 value = std::string( name );
908 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
910 if( impl.mController )
912 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
916 value = std::string( name );
921 case Toolkit::TextField::Property::TEXT_COLOR:
923 if ( impl.mController )
925 value = impl.mController->GetDefaultColor();
929 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
931 if ( impl.mController )
933 value = impl.mController->GetPlaceholderTextColor();
937 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
939 if( impl.mDecorator )
941 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
945 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
947 if( impl.mDecorator )
949 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
953 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
955 value = impl.mController->GetEnableCursorBlink();
958 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
960 if( impl.mDecorator )
962 value = impl.mDecorator->GetCursorBlinkInterval();
966 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
968 if( impl.mDecorator )
970 value = impl.mDecorator->GetCursorBlinkDuration();
974 case Toolkit::TextField::Property::CURSOR_WIDTH:
976 if( impl.mDecorator )
978 value = impl.mDecorator->GetCursorWidth();
982 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
984 if( impl.mDecorator )
986 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED );
990 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
992 if( impl.mDecorator )
994 value = impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED );
998 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
1000 if( impl.mDecorator )
1002 value = impl.mDecorator->GetScrollThreshold();
1006 case Toolkit::TextField::Property::SCROLL_SPEED:
1008 if( impl.mDecorator )
1010 value = impl.mDecorator->GetScrollSpeed();
1014 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
1016 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
1019 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
1021 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1024 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1026 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1029 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1031 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1034 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1036 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1039 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1041 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1044 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1046 if( impl.mDecorator )
1048 value = impl.mDecorator->GetHighlightColor();
1052 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1054 if( impl.mDecorator )
1056 Rect<int> boundingBox;
1057 impl.mDecorator->GetBoundingBox( boundingBox );
1058 value = boundingBox;
1062 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1065 impl.mInputMethodOptions.RetrieveProperty( map );
1069 case Toolkit::TextField::Property::INPUT_COLOR:
1071 if( impl.mController )
1073 value = impl.mController->GetInputColor();
1077 case Toolkit::TextField::Property::ENABLE_MARKUP:
1079 if( impl.mController )
1081 value = impl.mController->IsMarkupProcessorEnabled();
1085 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1087 if( impl.mController )
1089 value = impl.mController->GetInputFontFamily();
1093 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1095 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1098 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1100 if( impl.mController )
1102 value = impl.mController->GetInputFontPointSize();
1106 case Toolkit::TextField::Property::UNDERLINE:
1108 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1111 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1113 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1116 case Toolkit::TextField::Property::SHADOW:
1118 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1121 case Toolkit::TextField::Property::INPUT_SHADOW:
1123 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1126 case Toolkit::TextField::Property::EMBOSS:
1128 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1131 case Toolkit::TextField::Property::INPUT_EMBOSS:
1133 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1136 case Toolkit::TextField::Property::OUTLINE:
1138 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1141 case Toolkit::TextField::Property::INPUT_OUTLINE:
1143 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1146 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1149 impl.mController->GetHiddenInputOption(map);
1153 case Toolkit::TextField::Property::PIXEL_SIZE:
1155 if( impl.mController )
1157 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1161 case Toolkit::TextField::Property::ENABLE_SELECTION:
1163 if( impl.mController )
1165 value = impl.mController->IsSelectionEnabled();
1169 case Toolkit::TextField::Property::PLACEHOLDER:
1172 impl.mController->GetPlaceholderProperty( map );
1176 case Toolkit::TextField::Property::ELLIPSIS:
1178 if( impl.mController )
1180 value = impl.mController->IsTextElideEnabled();
1184 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1186 if( impl.mController )
1188 value = impl.mController->IsShiftSelectionEnabled();
1192 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1194 if( impl.mController )
1196 value = impl.mController->IsGrabHandleEnabled();
1200 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1202 if( impl.mController )
1204 value = impl.mController->IsMatchSystemLanguageDirection();
1208 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1210 if( impl.mController )
1212 value = impl.mController->IsGrabHandlePopupEnabled();
1216 case Toolkit::DevelTextField::Property::BACKGROUND:
1218 if( impl.mController )
1220 value = impl.mController->GetBackgroundColor();
1224 case Toolkit::DevelTextField::Property::SELECTED_TEXT:
1226 if( impl.mController )
1228 value = impl.mController->GetSelectedText( );
1238 void TextField::SelectWholeText()
1240 if( mController && mController->IsShowingRealText() )
1242 mController->SelectEvent( 0.f, 0.f, SelectionType::ALL );
1247 void TextField::SelectNone()
1249 if( mController && mController->IsShowingRealText() )
1251 mController->SelectEvent( 0.f, 0.f, SelectionType::NONE );
1256 InputMethodContext TextField::GetInputMethodContext()
1258 return mInputMethodContext;
1261 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1263 Dali::BaseHandle handle( object );
1265 bool connected( true );
1266 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1268 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1270 field.TextChangedSignal().Connect( tracker, functor );
1272 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1274 field.MaxLengthReachedSignal().Connect( tracker, functor );
1276 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1278 field.InputStyleChangedSignal().Connect( tracker, functor );
1282 // signalName does not match any signal
1289 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1291 return mTextChangedSignal;
1294 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1296 return mMaxLengthReachedSignal;
1299 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1301 return mInputStyleChangedSignal;
1304 void TextField::OnInitialize()
1306 Actor self = Self();
1308 mController = Text::Controller::New( this, this );
1310 // When using the vector-based rendering, the size of the GLyphs are different
1311 TextAbstraction::GlyphType glyphType = (DevelText::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1312 mController->SetGlyphType( glyphType );
1314 mDecorator = Text::Decorator::New( *mController,
1317 mInputMethodContext = InputMethodContext::New( self );
1319 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1321 // Enables the text input.
1322 mController->EnableTextInput( mDecorator, mInputMethodContext );
1324 // Enables the horizontal scrolling after the text input has been enabled.
1325 mController->SetHorizontalScrollEnabled( true );
1327 // Disables the vertical scrolling.
1328 mController->SetVerticalScrollEnabled( false );
1330 // Disable the smooth handle panning.
1331 mController->SetSmoothHandlePanEnabled( false );
1333 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1334 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1336 // Sets layoutDirection value
1337 Dali::Stage stage = Dali::Stage::GetCurrent();
1338 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1339 mController->SetLayoutDirection( layoutDirection );
1341 // Forward input events to controller
1342 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1343 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1345 self.TouchSignal().Connect( this, &TextField::OnTouched );
1347 // Set BoundingBox to stage size if not already set.
1348 Rect<int> boundingBox;
1349 mDecorator->GetBoundingBox( boundingBox );
1351 if( boundingBox.IsEmpty() )
1353 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1354 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1357 // Flip vertically the 'left' selection handle
1358 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1360 // Fill-parent area by default
1361 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1362 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1363 self.OnSceneSignal().Connect( this, &TextField::OnSceneConnect );
1365 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1367 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1373 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1375 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1379 case StyleChange::DEFAULT_FONT_CHANGE:
1381 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1382 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1383 // Property system did not set the font so should update it.
1384 mController->UpdateAfterFontChange( newFont );
1389 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1391 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1395 case StyleChange::THEME_CHANGE:
1397 // Nothing to do, let control base class handle this
1402 // Up call to Control
1403 Control::OnStyleChange( styleManager, change );
1406 Vector3 TextField::GetNaturalSize()
1409 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1411 Vector3 naturalSize = mController->GetNaturalSize();
1412 naturalSize.width += ( padding.start + padding.end );
1413 naturalSize.height += ( padding.top + padding.bottom );
1418 float TextField::GetHeightForWidth( float width )
1421 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1422 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1425 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1427 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1429 Actor self = Self();
1432 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1434 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1436 // Support Right-To-Left of padding
1437 Dali::LayoutDirection::Type layoutDirection;
1438 if( mController->IsMatchSystemLanguageDirection() )
1440 layoutDirection = static_cast<Dali::LayoutDirection::Type>( DevelWindow::Get( self ).GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1444 layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1446 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1448 std::swap( padding.start, padding.end );
1453 mStencil.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1457 mActiveLayer.SetProperty( Actor::Property::POSITION, Vector2( padding.start, padding.top ));
1460 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1462 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1465 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1468 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1470 mDecorator->Relayout( size );
1475 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1478 RenderText( updateTextType );
1482 // The text-field emits signals when the input style changes. These changes of style are
1483 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1484 // can't be emitted during the size negotiation as the callbacks may update the UI.
1485 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1486 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1488 if( Adaptor::IsAvailable() )
1490 Adaptor& adaptor = Adaptor::Get();
1492 if( NULL == mIdleCallback )
1494 // @note: The callback manager takes the ownership of the callback object.
1495 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1496 adaptor.AddIdle( mIdleCallback, false );
1502 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1504 Actor renderableActor;
1506 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1510 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1512 renderableActor = mRenderer->Render( mController->GetView(),
1514 Property::INVALID_INDEX, // Animatable property not supported
1516 DepthIndex::CONTENT );
1519 if( renderableActor != mRenderableActor )
1521 UnparentAndReset( mBackgroundActor );
1522 UnparentAndReset( mRenderableActor );
1523 mRenderableActor = renderableActor;
1525 if ( mRenderableActor )
1527 mBackgroundActor = mController->CreateBackgroundActor();
1532 if( mRenderableActor )
1534 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1536 float renderableActorPositionX, renderableActorPositionY;
1540 renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
1541 renderableActorPositionY = scrollOffset.y;
1546 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1548 // Support Right-To-Left of padding
1549 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1550 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1552 std::swap( padding.start, padding.end );
1555 renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
1556 renderableActorPositionY = scrollOffset.y + padding.top;
1559 mRenderableActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY ));
1561 // Make sure the actors are parented correctly with/without clipping
1562 Actor self = mStencil ? mStencil : Self();
1564 Actor highlightActor;
1566 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1567 endIt = mClippingDecorationActors.end();
1572 it->LowerToBottom();
1574 if ( it->GetProperty< std::string >( Dali::Actor::Property::NAME ) == "HighlightActor" )
1576 highlightActor = *it;
1579 mClippingDecorationActors.clear();
1581 self.Add( mRenderableActor );
1583 if ( mBackgroundActor )
1585 if ( mDecorator && mDecorator->IsHighlightVisible() )
1587 self.Add( mBackgroundActor );
1588 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( renderableActorPositionX, renderableActorPositionY) ); // In text field's coords.
1589 mBackgroundActor.LowerBelow( highlightActor );
1593 mRenderableActor.Add( mBackgroundActor );
1594 mBackgroundActor.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ) ); // In renderable actor's coords.
1595 mBackgroundActor.LowerToBottom();
1601 void TextField::OnKeyInputFocusGained()
1603 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1604 if ( mInputMethodContext )
1606 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1608 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1610 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1612 // Notify that the text editing start.
1613 mInputMethodContext.Activate();
1615 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1616 mInputMethodContext.SetRestoreAfterFocusLost( true );
1618 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1622 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1625 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1627 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1630 void TextField::OnKeyInputFocusLost()
1632 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1633 if ( mInputMethodContext )
1635 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1636 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1637 mInputMethodContext.SetRestoreAfterFocusLost( false );
1639 // Notify that the text editing finish.
1640 mInputMethodContext.Deactivate();
1642 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1644 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1648 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1651 mController->KeyboardFocusLostEvent();
1653 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1656 void TextField::OnTap( const TapGesture& gesture )
1658 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1659 if ( mInputMethodContext )
1661 mInputMethodContext.Activate();
1663 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1665 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1666 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1671 void TextField::OnPan( const PanGesture& gesture )
1673 mController->PanEvent( gesture.state, gesture.displacement );
1676 void TextField::OnLongPress( const LongPressGesture& gesture )
1678 if ( mInputMethodContext )
1680 mInputMethodContext.Activate();
1683 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1684 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1689 bool TextField::OnKeyEvent( const KeyEvent& event )
1691 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1693 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1695 // Make sure ClearKeyInputFocus when only key is up
1696 if( event.state == KeyEvent::Up )
1698 ClearKeyInputFocus();
1703 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1705 // Do nothing when enter is comming.
1709 return mController->KeyEvent( event );
1712 void TextField::RequestTextRelayout()
1717 void TextField::TextChanged()
1719 Dali::Toolkit::TextField handle( GetOwner() );
1720 mTextChangedSignal.Emit( handle );
1723 void TextField::MaxLengthReached()
1725 Dali::Toolkit::TextField handle( GetOwner() );
1726 mMaxLengthReachedSignal.Emit( handle );
1729 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1731 Dali::Toolkit::TextField handle( GetOwner() );
1733 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1735 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1737 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1739 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1741 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1743 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1745 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1747 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1749 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1751 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1753 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1755 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1757 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1759 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1761 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1763 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1765 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1767 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1769 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1771 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1773 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1776 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1779 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1785 mClippingDecorationActors.push_back( actor );
1789 actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1790 actor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1791 Self().Add( actor );
1792 mActiveLayer = actor;
1797 void TextField::OnSceneConnect( Dali::Actor actor )
1799 if ( mHasBeenStaged )
1801 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1805 mHasBeenStaged = true;
1809 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1811 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1812 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1815 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1820 map[ IMAGE_MAP_FILENAME_STRING ] = mDecorator->GetHandleImage( handleType, handleImageType );
1825 void TextField::EnableClipping()
1829 // Creates an extra control to be used as stencil buffer.
1830 mStencil = Control::New();
1831 mStencil.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1832 mStencil.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1834 // Creates a background visual. Even if the color is transparent it updates the stencil.
1835 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1836 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1837 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1839 // Enable the clipping property.
1840 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1841 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1843 Self().Add( mStencil );
1847 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1849 mController->PasteClipboardItemEvent();
1852 void TextField::KeyboardStatusChanged(bool keyboardShown)
1854 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1856 // Just hide the grab handle when keyboard is hidden.
1857 if (!keyboardShown )
1859 mController->KeyboardFocusLostEvent();
1863 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1867 void TextField::OnSceneConnection( int depth )
1869 // Sets the depth to the visuals inside the text's decorator.
1870 mDecorator->SetTextDepth( depth );
1872 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1874 // Call the Control::OnSceneConnection() to set the depth of the background.
1875 Control::OnSceneConnection( depth );
1878 bool TextField::OnTouched( Actor actor, const TouchEvent& touch )
1883 void TextField::OnIdleSignal()
1885 // Emits the change of input style signals.
1886 mController->ProcessInputStyleChangedSignals();
1888 // Set the pointer to null as the callback manager deletes the callback after execute it.
1889 mIdleCallback = NULL;
1892 TextField::TextField()
1893 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1894 mIdleCallback( NULL ),
1895 mAlignmentOffset( 0.f ),
1896 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1897 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1898 mHasBeenStaged( false )
1902 TextField::~TextField()
1904 UnparentAndReset( mStencil );
1906 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1908 Adaptor::Get().RemoveIdle( mIdleCallback );
1912 } // namespace Internal
1914 } // namespace Toolkit