2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/devel-api/adaptor-framework/key-devel.h>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/images/resource-image.h>
27 #include <dali/devel-api/object/property-helper-devel.h>
28 #include <dali/devel-api/actors/actor-devel.h>
29 #include <dali/public-api/object/type-registry-helper.h>
30 #include <dali/integration-api/adaptors/adaptor.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/public-api/text/rendering-backend.h>
35 #include <dali-toolkit/public-api/text/text-enumerations.h>
36 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
37 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
38 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
39 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
40 #include <dali-toolkit/public-api/visuals/visual-properties.h>
41 #include <dali-toolkit/internal/text/text-enumerations-impl.h>
42 #include <dali-toolkit/internal/text/rendering/text-backend.h>
43 #include <dali-toolkit/internal/text/text-effects-style.h>
44 #include <dali-toolkit/internal/text/text-font-style.h>
45 #include <dali-toolkit/internal/text/text-view.h>
46 #include <dali-toolkit/internal/styling/style-manager-impl.h>
47 #include <dali-toolkit/devel-api/controls/control-devel.h>
49 using namespace Dali::Toolkit::Text;
60 namespace // unnamed namespace
63 #if defined(DEBUG_ENABLED)
64 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
67 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
68 } // unnamed namespace
75 return Toolkit::TextField::New();
78 // Setup properties, signals and actions using the type-registry.
79 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
81 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
82 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
83 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
84 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
85 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
86 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
87 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
88 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
89 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
90 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
91 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
92 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
93 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "reservedProperty01", STRING, RESERVED_PROPERTY_01 )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "reservedProperty02", STRING, RESERVED_PROPERTY_02 )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableSelection", BOOLEAN, ENABLE_SELECTION )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholder", MAP, PLACEHOLDER )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "ellipsis", BOOLEAN, ELLIPSIS )
133 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableShiftSelection", BOOLEAN, ENABLE_SHIFT_SELECTION )
134 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE )
135 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION )
136 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "enableGrabHandlePopup", BOOLEAN, ENABLE_GRAB_HANDLE_POPUP )
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()
146 Toolkit::TextField TextField::New()
148 // Create the implementation, temporarily owned by this handle on stack
149 IntrusivePtr< TextField > impl = new TextField();
151 // Pass ownership to CustomActor handle
152 Toolkit::TextField handle( *impl );
154 // Second-phase init of the implementation
155 // This can only be done after the CustomActor connection has been made...
161 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
163 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
165 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
170 TextField& impl( GetImpl( textField ) );
174 case Toolkit::TextField::Property::RENDERING_BACKEND:
176 int backend = value.Get< int >();
177 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
179 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
180 if( Text::RENDERING_VECTOR_BASED == backend )
182 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
185 if( impl.mRenderingBackend != backend )
187 impl.mRenderingBackend = backend;
188 impl.mRenderer.Reset();
190 if( impl.mController )
192 // When using the vector-based rendering, the size of the GLyphs are different
193 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
194 impl.mController->SetGlyphType( glyphType );
199 case Toolkit::TextField::Property::TEXT:
201 if( impl.mController )
203 const std::string& text = value.Get< std::string >();
204 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
206 impl.mController->SetText( text );
210 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
212 if( impl.mController )
214 const std::string& text = value.Get< std::string >();
215 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
217 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
221 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
223 if( impl.mController )
225 const std::string& text = value.Get< std::string >();
226 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
228 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
232 case Toolkit::TextField::Property::FONT_FAMILY:
234 if( impl.mController )
236 const std::string& fontFamily = value.Get< std::string >();
237 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
238 impl.mController->SetDefaultFontFamily( fontFamily );
242 case Toolkit::TextField::Property::FONT_STYLE:
244 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
247 case Toolkit::TextField::Property::POINT_SIZE:
249 if( impl.mController )
251 const float pointSize = value.Get< float >();
252 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
254 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
256 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
261 case Toolkit::TextField::Property::MAX_LENGTH:
263 if( impl.mController )
265 const int max = value.Get< int >();
266 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
268 impl.mController->SetMaximumNumberOfCharacters( max );
272 case Toolkit::TextField::Property::EXCEED_POLICY:
274 impl.mExceedPolicy = value.Get<int>();
276 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
278 impl.EnableClipping();
282 UnparentAndReset( impl.mStencil );
284 impl.RequestTextRelayout();
287 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
289 if( impl.mController )
291 Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
292 if( GetHorizontalAlignmentEnumeration( value, alignment ) )
294 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
295 impl.mController->SetHorizontalAlignment( alignment );
300 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
302 if( impl.mController )
304 Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set
305 if( GetVerticalAlignmentEnumeration( value, alignment ) )
307 impl.mController->SetVerticalAlignment( alignment );
308 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment );
313 case Toolkit::TextField::Property::TEXT_COLOR:
315 if( impl.mController )
317 const Vector4& textColor = value.Get< Vector4 >();
318 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 );
320 if( impl.mController->GetDefaultColor() != textColor )
322 impl.mController->SetDefaultColor( textColor );
323 impl.mController->SetInputColor( textColor );
324 impl.mRenderer.Reset();
329 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
331 if( impl.mController )
333 const Vector4& textColor = value.Get< Vector4 >();
334 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 );
336 if( impl.mController->GetPlaceholderTextColor() != textColor )
338 impl.mController->SetPlaceholderTextColor( textColor );
339 impl.mRenderer.Reset();
344 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
346 if( impl.mDecorator )
348 const Vector4& color = value.Get< Vector4 >();
349 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 );
351 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
352 impl.RequestTextRelayout();
356 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
358 if( impl.mDecorator )
360 const Vector4& color = value.Get< Vector4 >();
361 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 );
363 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
364 impl.RequestTextRelayout();
368 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
370 if( impl.mController )
372 const bool enable = value.Get< bool >();
373 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
375 impl.mController->SetEnableCursorBlink( enable );
376 impl.RequestTextRelayout();
380 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
382 if( impl.mDecorator )
384 const float interval = value.Get< float >();
385 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
387 impl.mDecorator->SetCursorBlinkInterval( interval );
391 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
393 if( impl.mDecorator )
395 const float duration = value.Get< float >();
396 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
398 impl.mDecorator->SetCursorBlinkDuration( duration );
402 case Toolkit::TextField::Property::CURSOR_WIDTH:
404 if( impl.mDecorator )
406 const int width = value.Get< int >();
407 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
409 impl.mDecorator->SetCursorWidth( width );
410 impl.mController->GetLayoutEngine().SetCursorWidth( width );
414 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
416 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
417 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
419 if( impl.mDecorator )
421 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
422 impl.RequestTextRelayout();
426 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
428 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
429 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
431 if( impl.mDecorator )
433 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
434 impl.RequestTextRelayout();
438 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
440 const float threshold = value.Get< float >();
441 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
443 if( impl.mDecorator )
445 impl.mDecorator->SetScrollThreshold( threshold );
449 case Toolkit::TextField::Property::SCROLL_SPEED:
451 const float speed = value.Get< float >();
452 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
454 if( impl.mDecorator )
456 impl.mDecorator->SetScrollSpeed( speed );
460 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
462 const Image image = Scripting::NewImage( value );
464 if( impl.mDecorator && image )
466 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
467 impl.RequestTextRelayout();
471 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
473 const Image image = Scripting::NewImage( value );
475 if( impl.mDecorator && image )
477 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
478 impl.RequestTextRelayout();
482 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
484 const Image image = Scripting::NewImage( value );
486 if( impl.mDecorator && image )
488 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
489 impl.RequestTextRelayout();
493 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
495 const Image image = Scripting::NewImage( value );
497 if( impl.mDecorator && image )
499 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
500 impl.RequestTextRelayout();
504 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
506 const Image image = Scripting::NewImage( value );
508 if( impl.mDecorator && image )
510 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
511 impl.RequestTextRelayout();
515 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
517 const Image image = Scripting::NewImage( value );
519 if( impl.mDecorator && image )
521 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
522 impl.RequestTextRelayout();
526 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
528 const Vector4 color = value.Get< Vector4 >();
529 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 );
531 if( impl.mDecorator )
533 impl.mDecorator->SetHighlightColor( color );
534 impl.RequestTextRelayout();
538 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
540 if( impl.mDecorator )
542 const Rect<int> box = value.Get< Rect<int> >();
543 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 );
545 impl.mDecorator->SetBoundingBox( box );
546 impl.RequestTextRelayout();
550 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
552 const Property::Map* map = value.GetMap();
555 impl.mInputMethodOptions.ApplyProperty( *map );
557 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
559 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
560 if (control == textField)
562 impl.mInputMethodContext.ApplyOptions( impl.mInputMethodOptions );
566 case Toolkit::TextField::Property::INPUT_COLOR:
568 if( impl.mController )
570 const Vector4 inputColor = value.Get< Vector4 >();
571 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 );
573 impl.mController->SetInputColor( inputColor );
577 case Toolkit::TextField::Property::ENABLE_MARKUP:
579 if( impl.mController )
581 const bool enableMarkup = value.Get<bool>();
582 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
584 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
588 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
590 if( impl.mController )
592 const std::string& fontFamily = value.Get< std::string >();
593 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
594 impl.mController->SetInputFontFamily( fontFamily );
598 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
600 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
603 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
605 if( impl.mController )
607 const float pointSize = value.Get< float >();
608 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
609 impl.mController->SetInputFontPointSize( pointSize );
613 case Toolkit::TextField::Property::UNDERLINE:
615 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
618 impl.mRenderer.Reset();
622 case Toolkit::TextField::Property::INPUT_UNDERLINE:
624 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
627 impl.mRenderer.Reset();
631 case Toolkit::TextField::Property::SHADOW:
633 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
636 impl.mRenderer.Reset();
640 case Toolkit::TextField::Property::INPUT_SHADOW:
642 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
645 impl.mRenderer.Reset();
649 case Toolkit::TextField::Property::EMBOSS:
651 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
654 impl.mRenderer.Reset();
658 case Toolkit::TextField::Property::INPUT_EMBOSS:
660 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
663 impl.mRenderer.Reset();
667 case Toolkit::TextField::Property::OUTLINE:
669 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
672 impl.mRenderer.Reset();
676 case Toolkit::TextField::Property::INPUT_OUTLINE:
678 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
681 impl.mRenderer.Reset();
685 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
687 const Property::Map* map = value.GetMap();
690 impl.mController->SetHiddenInputOption(*map);
694 case Toolkit::TextField::Property::PIXEL_SIZE:
696 if( impl.mController )
698 const float pixelSize = value.Get< float >();
699 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
701 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
703 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
708 case Toolkit::TextField::Property::ENABLE_SELECTION:
710 if( impl.mController )
712 const bool enableSelection = value.Get< bool >();
713 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SELECTION %d\n", impl.mController.Get(), enableSelection );
714 impl.mController->SetSelectionEnabled( enableSelection );
718 case Toolkit::TextField::Property::PLACEHOLDER:
720 const Property::Map* map = value.GetMap();
723 impl.mController->SetPlaceholderProperty( *map );
727 case Toolkit::TextField::Property::ELLIPSIS:
729 if( impl.mController )
731 const bool ellipsis = value.Get<bool>();
732 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ELLIPSIS %d\n", impl.mController.Get(), ellipsis );
734 impl.mController->SetTextElideEnabled( ellipsis );
738 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
740 if( impl.mController )
742 const bool shiftSelection = value.Get<bool>();
743 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_SHIFT_SELECTION %d\n", impl.mController.Get(), shiftSelection );
745 impl.mController->SetShiftSelectionEnabled( shiftSelection );
749 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
751 if( impl.mController )
753 const bool grabHandleEnabled = value.Get<bool>();
754 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE %d\n", impl.mController.Get(), grabHandleEnabled );
756 impl.mController->SetGrabHandleEnabled( grabHandleEnabled );
760 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
762 if( impl.mController )
764 impl.mController->SetMatchSystemLanguageDirection(value.Get< bool >());
768 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
770 if (impl.mController)
772 const bool grabHandlePopupEnabled = value.Get<bool>();
773 DALI_LOG_INFO(gLogFilter, Debug::General, "TextField %p ENABLE_GRAB_HANDLE_POPUP %d\n", impl.mController.Get(), grabHandlePopupEnabled);
775 impl.mController->SetGrabHandlePopupEnabled(grabHandlePopupEnabled);
783 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
785 Property::Value value;
787 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
791 TextField& impl( GetImpl( textField ) );
795 case Toolkit::TextField::Property::RENDERING_BACKEND:
797 value = impl.mRenderingBackend;
800 case Toolkit::TextField::Property::TEXT:
802 if( impl.mController )
805 impl.mController->GetText( text );
806 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
811 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
813 if( impl.mController )
816 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
821 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
823 if( impl.mController )
826 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
831 case Toolkit::TextField::Property::FONT_FAMILY:
833 if( impl.mController )
835 value = impl.mController->GetDefaultFontFamily();
839 case Toolkit::TextField::Property::FONT_STYLE:
841 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
844 case Toolkit::TextField::Property::POINT_SIZE:
846 if( impl.mController )
848 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
852 case Toolkit::TextField::Property::MAX_LENGTH:
854 if( impl.mController )
856 value = impl.mController->GetMaximumNumberOfCharacters();
860 case Toolkit::TextField::Property::EXCEED_POLICY:
862 value = impl.mExceedPolicy;
865 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
867 if( impl.mController )
869 const char* name = Text::GetHorizontalAlignmentString( impl.mController->GetHorizontalAlignment() );
873 value = std::string( name );
878 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
880 if( impl.mController )
882 const char* name = Text::GetVerticalAlignmentString( impl.mController->GetVerticalAlignment() );
886 value = std::string( name );
891 case Toolkit::TextField::Property::TEXT_COLOR:
893 if ( impl.mController )
895 value = impl.mController->GetDefaultColor();
899 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
901 if ( impl.mController )
903 value = impl.mController->GetPlaceholderTextColor();
907 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
909 if( impl.mDecorator )
911 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
915 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
917 if( impl.mDecorator )
919 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
923 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
925 value = impl.mController->GetEnableCursorBlink();
928 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
930 if( impl.mDecorator )
932 value = impl.mDecorator->GetCursorBlinkInterval();
936 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
938 if( impl.mDecorator )
940 value = impl.mDecorator->GetCursorBlinkDuration();
944 case Toolkit::TextField::Property::CURSOR_WIDTH:
946 if( impl.mDecorator )
948 value = impl.mDecorator->GetCursorWidth();
952 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
954 if( impl.mDecorator )
956 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
959 value = image.GetUrl();
964 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
966 if( impl.mDecorator )
968 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
971 value = image.GetUrl();
976 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
978 if( impl.mDecorator )
980 value = impl.mDecorator->GetScrollThreshold();
984 case Toolkit::TextField::Property::SCROLL_SPEED:
986 if( impl.mDecorator )
988 value = impl.mDecorator->GetScrollSpeed();
992 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
994 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
997 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
999 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
1002 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
1004 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1007 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1009 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1012 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1014 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1017 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1019 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1022 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1024 if( impl.mDecorator )
1026 value = impl.mDecorator->GetHighlightColor();
1030 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1032 if( impl.mDecorator )
1034 Rect<int> boundingBox;
1035 impl.mDecorator->GetBoundingBox( boundingBox );
1036 value = boundingBox;
1040 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1043 impl.mInputMethodOptions.RetrieveProperty( map );
1047 case Toolkit::TextField::Property::INPUT_COLOR:
1049 if( impl.mController )
1051 value = impl.mController->GetInputColor();
1055 case Toolkit::TextField::Property::ENABLE_MARKUP:
1057 if( impl.mController )
1059 value = impl.mController->IsMarkupProcessorEnabled();
1063 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1065 if( impl.mController )
1067 value = impl.mController->GetInputFontFamily();
1071 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1073 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1076 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1078 if( impl.mController )
1080 value = impl.mController->GetInputFontPointSize();
1084 case Toolkit::TextField::Property::UNDERLINE:
1086 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1089 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1091 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1094 case Toolkit::TextField::Property::SHADOW:
1096 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1099 case Toolkit::TextField::Property::INPUT_SHADOW:
1101 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1104 case Toolkit::TextField::Property::EMBOSS:
1106 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1109 case Toolkit::TextField::Property::INPUT_EMBOSS:
1111 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1114 case Toolkit::TextField::Property::OUTLINE:
1116 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1119 case Toolkit::TextField::Property::INPUT_OUTLINE:
1121 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1124 case Toolkit::TextField::Property::HIDDEN_INPUT_SETTINGS:
1127 impl.mController->GetHiddenInputOption(map);
1131 case Toolkit::TextField::Property::PIXEL_SIZE:
1133 if( impl.mController )
1135 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1139 case Toolkit::TextField::Property::ENABLE_SELECTION:
1141 if( impl.mController )
1143 value = impl.mController->IsSelectionEnabled();
1147 case Toolkit::TextField::Property::PLACEHOLDER:
1150 impl.mController->GetPlaceholderProperty( map );
1154 case Toolkit::TextField::Property::ELLIPSIS:
1156 if( impl.mController )
1158 value = impl.mController->IsTextElideEnabled();
1162 case Toolkit::DevelTextField::Property::ENABLE_SHIFT_SELECTION:
1164 if( impl.mController )
1166 value = impl.mController->IsShiftSelectionEnabled();
1170 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE:
1172 if( impl.mController )
1174 value = impl.mController->IsGrabHandleEnabled();
1178 case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION:
1180 if( impl.mController )
1182 value = impl.mController->IsMatchSystemLanguageDirection();
1186 case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP:
1188 if (impl.mController)
1190 value = impl.mController->IsGrabHandlePopupEnabled();
1200 void TextField::SelectWholeText()
1202 if( mController && mController->IsShowingRealText() )
1204 mController->SelectEvent( 0.f, 0.f, true );
1209 InputMethodContext TextField::GetInputMethodContext()
1211 return mInputMethodContext;
1214 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1216 Dali::BaseHandle handle( object );
1218 bool connected( true );
1219 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1221 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1223 field.TextChangedSignal().Connect( tracker, functor );
1225 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1227 field.MaxLengthReachedSignal().Connect( tracker, functor );
1229 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1231 field.InputStyleChangedSignal().Connect( tracker, functor );
1235 // signalName does not match any signal
1242 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1244 return mTextChangedSignal;
1247 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1249 return mMaxLengthReachedSignal;
1252 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1254 return mInputStyleChangedSignal;
1257 void TextField::OnInitialize()
1259 Actor self = Self();
1261 mController = Text::Controller::New( this, this );
1263 // When using the vector-based rendering, the size of the GLyphs are different
1264 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1265 mController->SetGlyphType( glyphType );
1267 mDecorator = Text::Decorator::New( *mController,
1270 mInputMethodContext = InputMethodContext::New( self );
1272 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1274 // Enables the text input.
1275 mController->EnableTextInput( mDecorator, mInputMethodContext );
1277 // Enables the horizontal scrolling after the text input has been enabled.
1278 mController->SetHorizontalScrollEnabled( true );
1280 // Disables the vertical scrolling.
1281 mController->SetVerticalScrollEnabled( false );
1283 // Disable the smooth handle panning.
1284 mController->SetSmoothHandlePanEnabled( false );
1286 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1287 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1289 // Sets layoutDirection value
1290 Dali::Stage stage = Dali::Stage::GetCurrent();
1291 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( stage.GetRootLayer().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1292 mController->SetLayoutDirection( layoutDirection );
1294 // Forward input events to controller
1295 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1296 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1298 self.TouchSignal().Connect( this, &TextField::OnTouched );
1300 // Set BoundingBox to stage size if not already set.
1301 Rect<int> boundingBox;
1302 mDecorator->GetBoundingBox( boundingBox );
1304 if( boundingBox.IsEmpty() )
1306 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1307 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1310 // Flip vertically the 'left' selection handle
1311 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1313 // Fill-parent area by default
1314 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1315 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1316 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1318 DevelControl::SetInputMethodContext( *this, mInputMethodContext );
1320 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1326 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1328 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1332 case StyleChange::DEFAULT_FONT_CHANGE:
1334 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1335 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1336 // Property system did not set the font so should update it.
1337 mController->UpdateAfterFontChange( newFont );
1342 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1344 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1348 case StyleChange::THEME_CHANGE:
1350 // Nothing to do, let control base class handle this
1355 // Up call to Control
1356 Control::OnStyleChange( styleManager, change );
1359 Vector3 TextField::GetNaturalSize()
1362 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1364 Vector3 naturalSize = mController->GetNaturalSize();
1365 naturalSize.width += ( padding.start + padding.end );
1366 naturalSize.height += ( padding.top + padding.bottom );
1371 float TextField::GetHeightForWidth( float width )
1374 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1375 return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
1378 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1380 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1382 Actor self = Self();
1385 padding = self.GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1387 Vector2 contentSize( size.x - ( padding.start + padding.end ), size.y - ( padding.top + padding.bottom ) );
1389 // Support Right-To-Left of padding
1390 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( self.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1391 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1393 std::swap( padding.start, padding.end );
1398 mStencil.SetPosition( padding.start, padding.top );
1402 mActiveLayer.SetPosition( padding.start, padding.top );
1405 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( contentSize, layoutDirection );
1407 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1410 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1413 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1415 mDecorator->Relayout( size );
1420 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1423 RenderText( updateTextType );
1427 // The text-field emits signals when the input style changes. These changes of style are
1428 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1429 // can't be emitted during the size negotiation as the callbacks may update the UI.
1430 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1431 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1433 if( Adaptor::IsAvailable() )
1435 Adaptor& adaptor = Adaptor::Get();
1437 if( NULL == mIdleCallback )
1439 // @note: The callback manager takes the ownership of the callback object.
1440 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1441 adaptor.AddIdle( mIdleCallback, false );
1447 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1449 Actor renderableActor;
1451 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1455 Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
1457 renderableActor = mRenderer->Render( mController->GetView(),
1459 Property::INVALID_INDEX, // Animatable property not supported
1461 DepthIndex::CONTENT );
1464 if( renderableActor != mRenderableActor )
1466 UnparentAndReset( mRenderableActor );
1467 mRenderableActor = renderableActor;
1471 if( mRenderableActor )
1473 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1477 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1482 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1484 // Support Right-To-Left of padding
1485 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>( Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
1486 if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
1488 std::swap( padding.start, padding.end );
1491 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset + padding.start, scrollOffset.y + padding.top );
1495 // Make sure the actors are parented correctly with/without clipping
1496 Actor self = mStencil ? mStencil : Self();
1498 for( std::vector<Actor>::iterator it = mClippingDecorationActors.begin(),
1499 endIt = mClippingDecorationActors.end();
1504 it->LowerToBottom();
1506 mClippingDecorationActors.clear();
1508 self.Add( mRenderableActor );
1512 void TextField::OnKeyInputFocusGained()
1514 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1515 if ( mInputMethodContext )
1517 mInputMethodContext.ApplyOptions( mInputMethodOptions );
1519 mInputMethodContext.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1521 mInputMethodContext.EventReceivedSignal().Connect( this, &TextField::OnInputMethodContextEvent );
1523 // Notify that the text editing start.
1524 mInputMethodContext.Activate();
1526 // When window gain lost focus, the inputMethodContext is deactivated. Thus when window gain focus again, the inputMethodContext must be activated.
1527 mInputMethodContext.SetRestoreAfterFocusLost( true );
1529 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1533 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1536 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1538 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1541 void TextField::OnKeyInputFocusLost()
1543 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1544 if ( mInputMethodContext )
1546 mInputMethodContext.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1547 // The text editing is finished. Therefore the inputMethodContext don't have restore activation.
1548 mInputMethodContext.SetRestoreAfterFocusLost( false );
1550 // Notify that the text editing finish.
1551 mInputMethodContext.Deactivate();
1553 mInputMethodContext.EventReceivedSignal().Disconnect( this, &TextField::OnInputMethodContextEvent );
1555 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1559 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1562 mController->KeyboardFocusLostEvent();
1564 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1567 void TextField::OnTap( const TapGesture& gesture )
1569 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1570 if ( mInputMethodContext )
1572 mInputMethodContext.Activate();
1574 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1576 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1577 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1582 void TextField::OnPan( const PanGesture& gesture )
1584 mController->PanEvent( gesture.state, gesture.displacement );
1587 void TextField::OnLongPress( const LongPressGesture& gesture )
1589 if ( mInputMethodContext )
1591 mInputMethodContext.Activate();
1594 padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
1595 mController->LongPressEvent( gesture.state, gesture.localPoint.x - padding.start, gesture.localPoint.y - padding.top );
1600 bool TextField::OnKeyEvent( const KeyEvent& event )
1602 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1604 if( Dali::DALI_KEY_ESCAPE == event.keyCode && mController->ShouldClearFocusOnEscape() )
1606 // Make sure ClearKeyInputFocus when only key is up
1607 if( event.state == KeyEvent::Up )
1609 ClearKeyInputFocus();
1614 else if( Dali::DevelKey::DALI_KEY_RETURN == event.keyCode )
1616 // Do nothing when enter is comming.
1620 return mController->KeyEvent( event );
1623 void TextField::RequestTextRelayout()
1628 void TextField::TextChanged()
1630 Dali::Toolkit::TextField handle( GetOwner() );
1631 mTextChangedSignal.Emit( handle );
1634 void TextField::MaxLengthReached()
1636 Dali::Toolkit::TextField handle( GetOwner() );
1637 mMaxLengthReachedSignal.Emit( handle );
1640 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1642 Dali::Toolkit::TextField handle( GetOwner() );
1644 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1646 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1648 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1650 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1652 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1654 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1656 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1658 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1660 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1662 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1664 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1666 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1668 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1670 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1672 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1674 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1676 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1678 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1680 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1682 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1684 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1687 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1690 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1696 mClippingDecorationActors.push_back( actor );
1700 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1701 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1702 Self().Add( actor );
1703 mActiveLayer = actor;
1708 void TextField::OnStageConnect( Dali::Actor actor )
1710 if ( mHasBeenStaged )
1712 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1716 mHasBeenStaged = true;
1720 InputMethodContext::CallbackData TextField::OnInputMethodContextEvent( Dali::InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent )
1722 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnInputMethodContextEvent %p eventName %d\n", mController.Get(), inputMethodContextEvent.eventName );
1723 return mController->OnInputMethodContextEvent( inputMethodContext, inputMethodContextEvent );
1726 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1730 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1735 Scripting::CreatePropertyMap( image, map );
1741 void TextField::EnableClipping()
1745 // Creates an extra control to be used as stencil buffer.
1746 mStencil = Control::New();
1747 mStencil.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1748 mStencil.SetParentOrigin( ParentOrigin::TOP_LEFT );
1750 // Creates a background visual. Even if the color is transparent it updates the stencil.
1751 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1752 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::COLOR ).
1753 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1755 // Enable the clipping property.
1756 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX );
1757 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1759 Self().Add( mStencil );
1763 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1765 mController->PasteClipboardItemEvent();
1768 void TextField::KeyboardStatusChanged(bool keyboardShown)
1770 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1772 // Just hide the grab handle when keyboard is hidden.
1773 if (!keyboardShown )
1775 mController->KeyboardFocusLostEvent();
1779 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1783 void TextField::OnStageConnection( int depth )
1785 // Sets the depth to the visuals inside the text's decorator.
1786 mDecorator->SetTextDepth( depth );
1788 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1790 // Call the Control::OnStageConnection() to set the depth of the background.
1791 Control::OnStageConnection( depth );
1794 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1799 void TextField::OnIdleSignal()
1801 // Emits the change of input style signals.
1802 mController->ProcessInputStyleChangedSignals();
1804 // Set the pointer to null as the callback manager deletes the callback after execute it.
1805 mIdleCallback = NULL;
1808 TextField::TextField()
1809 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1810 mIdleCallback( NULL ),
1811 mAlignmentOffset( 0.f ),
1812 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1813 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1814 mHasBeenStaged( false )
1818 TextField::~TextField()
1820 UnparentAndReset( mStencil );
1822 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1824 Adaptor::Get().RemoveIdle( mIdleCallback );
1828 } // namespace Internal
1830 } // namespace Toolkit