2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
23 #include <dali/public-api/adaptor-framework/key.h>
24 #include <dali/public-api/common/stage.h>
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/devel-api/object/property-helper-devel.h>
27 #include <dali/devel-api/actors/actor-devel.h>
28 #include <dali/public-api/object/type-registry-helper.h>
29 #include <dali/integration-api/adaptors/adaptor.h>
30 #include <dali/integration-api/debug.h>
33 #include <dali-toolkit/public-api/text/rendering-backend.h>
34 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
35 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
36 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
37 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
38 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
39 #include <dali-toolkit/internal/text/rendering/text-backend.h>
40 #include <dali-toolkit/internal/text/text-effects-style.h>
41 #include <dali-toolkit/internal/text/text-font-style.h>
42 #include <dali-toolkit/internal/text/text-view.h>
43 #include <dali-toolkit/internal/styling/style-manager-impl.h>
45 using namespace Dali::Toolkit::Text;
56 namespace // unnamed namespace
59 #if defined(DEBUG_ENABLED)
60 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_CONTROLS");
63 const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
64 } // unnamed namespace
69 const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
71 { "BEGIN", Toolkit::Text::Layout::HORIZONTAL_ALIGN_BEGIN },
72 { "CENTER", Toolkit::Text::Layout::HORIZONTAL_ALIGN_CENTER },
73 { "END", Toolkit::Text::Layout::HORIZONTAL_ALIGN_END },
75 const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
77 const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] =
79 { "TOP", Toolkit::Text::Layout::VERTICAL_ALIGN_TOP },
80 { "CENTER", Toolkit::Text::Layout::VERTICAL_ALIGN_CENTER },
81 { "BOTTOM", Toolkit::Text::Layout::VERTICAL_ALIGN_BOTTOM },
83 const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
88 return Toolkit::TextField::New();
91 // Setup properties, signals and actions using the type-registry.
92 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::TextField, Toolkit::Control, Create );
94 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "renderingBackend", INTEGER, RENDERING_BACKEND )
95 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "text", STRING, TEXT )
96 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderText", STRING, PLACEHOLDER_TEXT )
97 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextFocused", STRING, PLACEHOLDER_TEXT_FOCUSED )
98 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontFamily", STRING, FONT_FAMILY )
99 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "fontStyle", MAP, FONT_STYLE )
100 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "pointSize", FLOAT, POINT_SIZE )
101 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "maxLength", INTEGER, MAX_LENGTH )
102 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "exceedPolicy", INTEGER, EXCEED_POLICY )
103 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "horizontalAlignment", STRING, HORIZONTAL_ALIGNMENT )
104 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "verticalAlignment", STRING, VERTICAL_ALIGNMENT )
105 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "textColor", VECTOR4, TEXT_COLOR )
106 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR )
107 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowOffset", VECTOR2, SHADOW_OFFSET )
108 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadowColor", VECTOR4, SHADOW_COLOR )
109 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "primaryCursorColor", VECTOR4, PRIMARY_CURSOR_COLOR )
110 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "secondaryCursorColor", VECTOR4, SECONDARY_CURSOR_COLOR )
111 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableCursorBlink", BOOLEAN, ENABLE_CURSOR_BLINK )
112 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkInterval", FLOAT, CURSOR_BLINK_INTERVAL )
113 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorBlinkDuration", FLOAT, CURSOR_BLINK_DURATION )
114 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "cursorWidth", INTEGER, CURSOR_WIDTH )
115 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandleImage", STRING, GRAB_HANDLE_IMAGE )
116 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "grabHandlePressedImage", STRING, GRAB_HANDLE_PRESSED_IMAGE )
117 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollThreshold", FLOAT, SCROLL_THRESHOLD )
118 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "scrollSpeed", FLOAT, SCROLL_SPEED )
119 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageLeft", MAP, SELECTION_HANDLE_IMAGE_LEFT )
120 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleImageRight", MAP, SELECTION_HANDLE_IMAGE_RIGHT )
121 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageLeft", MAP, SELECTION_HANDLE_PRESSED_IMAGE_LEFT )
122 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandlePressedImageRight", MAP, SELECTION_HANDLE_PRESSED_IMAGE_RIGHT )
123 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageLeft", MAP, SELECTION_HANDLE_MARKER_IMAGE_LEFT )
124 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHandleMarkerImageRight", MAP, SELECTION_HANDLE_MARKER_IMAGE_RIGHT )
125 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "selectionHighlightColor", VECTOR4, SELECTION_HIGHLIGHT_COLOR )
126 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "decorationBoundingBox", RECTANGLE, DECORATION_BOUNDING_BOX )
127 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputMethodSettings", MAP, INPUT_METHOD_SETTINGS )
128 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputColor", VECTOR4, INPUT_COLOR )
129 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "enableMarkup", BOOLEAN, ENABLE_MARKUP )
130 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontFamily", STRING, INPUT_FONT_FAMILY )
131 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputFontStyle", MAP, INPUT_FONT_STYLE )
132 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputPointSize", FLOAT, INPUT_POINT_SIZE )
133 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "underline", MAP, UNDERLINE )
134 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputUnderline", MAP, INPUT_UNDERLINE )
135 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "shadow", MAP, SHADOW )
136 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputShadow", MAP, INPUT_SHADOW )
137 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "emboss", MAP, EMBOSS )
138 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputEmboss", MAP, INPUT_EMBOSS )
139 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "outline", MAP, OUTLINE )
140 DALI_PROPERTY_REGISTRATION( Toolkit, TextField, "inputOutline", MAP, INPUT_OUTLINE )
141 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "hiddenInputSettings", MAP, HIDDEN_INPUT_SETTINGS )
142 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextField, "pixelSize", FLOAT, PIXEL_SIZE )
144 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "textChanged", SIGNAL_TEXT_CHANGED )
145 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED )
146 DALI_SIGNAL_REGISTRATION( Toolkit, TextField, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED )
148 DALI_TYPE_REGISTRATION_END()
152 Toolkit::TextField TextField::New()
154 // Create the implementation, temporarily owned by this handle on stack
155 IntrusivePtr< TextField > impl = new TextField();
157 // Pass ownership to CustomActor handle
158 Toolkit::TextField handle( *impl );
160 // Second-phase init of the implementation
161 // This can only be done after the CustomActor connection has been made...
167 void TextField::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
169 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
171 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField SetProperty\n");
176 TextField& impl( GetImpl( textField ) );
180 case Toolkit::TextField::Property::RENDERING_BACKEND:
182 int backend = value.Get< int >();
183 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p RENDERING_BACKEND %d\n", impl.mController.Get(), backend );
185 #ifndef ENABLE_VECTOR_BASED_TEXT_RENDERING
186 if( Text::RENDERING_VECTOR_BASED == backend )
188 backend = TextAbstraction::BITMAP_GLYPH; // Fallback to bitmap-based rendering
191 if( impl.mRenderingBackend != backend )
193 impl.mRenderingBackend = backend;
194 impl.mRenderer.Reset();
196 if( impl.mController )
198 // When using the vector-based rendering, the size of the GLyphs are different
199 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == impl.mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
200 impl.mController->SetGlyphType( glyphType );
205 case Toolkit::TextField::Property::TEXT:
207 if( impl.mController )
209 const std::string& text = value.Get< std::string >();
210 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p TEXT %s\n", impl.mController.Get(), text.c_str() );
212 impl.mController->SetText( text );
216 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
218 if( impl.mController )
220 const std::string& text = value.Get< std::string >();
221 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT %s\n", impl.mController.Get(), text.c_str() );
223 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
227 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
229 if( impl.mController )
231 const std::string& text = value.Get< std::string >();
232 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PLACEHOLDER_TEXT_FOCUSED %s\n", impl.mController.Get(), text.c_str() );
234 impl.mController->SetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
238 case Toolkit::TextField::Property::FONT_FAMILY:
240 if( impl.mController )
242 const std::string& fontFamily = value.Get< std::string >();
243 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
244 impl.mController->SetDefaultFontFamily( fontFamily );
248 case Toolkit::TextField::Property::FONT_STYLE:
250 SetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
253 case Toolkit::TextField::Property::POINT_SIZE:
255 if( impl.mController )
257 const float pointSize = value.Get< float >();
258 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p POINT_SIZE %f\n", impl.mController.Get(), pointSize );
260 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE ), pointSize ) )
262 impl.mController->SetDefaultFontSize( pointSize, Text::Controller::POINT_SIZE );
267 case Toolkit::TextField::Property::MAX_LENGTH:
269 if( impl.mController )
271 const int max = value.Get< int >();
272 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p MAX_LENGTH %d\n", impl.mController.Get(), max );
274 impl.mController->SetMaximumNumberOfCharacters( max );
278 case Toolkit::TextField::Property::EXCEED_POLICY:
280 impl.mExceedPolicy = value.Get<int>();
282 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == impl.mExceedPolicy )
284 impl.EnableClipping();
288 UnparentAndReset( impl.mStencil );
290 impl.RequestTextRelayout();
293 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
295 if( impl.mController )
297 const std::string& alignStr = value.Get< std::string >();
298 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
300 Layout::HorizontalAlignment alignment( Layout::HORIZONTAL_ALIGN_BEGIN );
301 if( Scripting::GetEnumeration< Layout::HorizontalAlignment >( alignStr.c_str(),
302 HORIZONTAL_ALIGNMENT_STRING_TABLE,
303 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT,
306 impl.mController->SetHorizontalAlignment( alignment );
311 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
313 if( impl.mController )
315 const std::string& alignStr = value.Get< std::string >();
316 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() );
318 Layout::VerticalAlignment alignment( Layout::VERTICAL_ALIGN_BOTTOM );
319 if( Scripting::GetEnumeration< Layout::VerticalAlignment >( alignStr.c_str(),
320 VERTICAL_ALIGNMENT_STRING_TABLE,
321 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT,
324 impl.mController->SetVerticalAlignment( alignment );
329 case Toolkit::TextField::Property::TEXT_COLOR:
331 if( impl.mController )
333 const Vector4& textColor = value.Get< Vector4 >();
334 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 );
336 if( impl.mController->GetDefaultColor() != textColor )
338 impl.mController->SetDefaultColor( textColor );
339 impl.mController->SetInputColor( textColor );
340 impl.mRenderer.Reset();
345 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
347 if( impl.mController )
349 const Vector4& textColor = value.Get< Vector4 >();
350 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 );
352 if( impl.mController->GetPlaceholderTextColor() != textColor )
354 impl.mController->SetPlaceholderTextColor( textColor );
355 impl.mRenderer.Reset();
360 case Toolkit::TextField::Property::SHADOW_OFFSET:
362 if( impl.mController )
364 const Vector2& shadowOffset = value.Get< Vector2 >();
365 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_OFFSET %f,%f\n", impl.mController.Get(), shadowOffset.x, shadowOffset.y );
367 if ( impl.mController->GetShadowOffset() != shadowOffset )
369 impl.mController->SetShadowOffset( shadowOffset );
370 impl.mRenderer.Reset();
375 case Toolkit::TextField::Property::SHADOW_COLOR:
377 if( impl.mController )
379 const Vector4& shadowColor = value.Get< Vector4 >();
380 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SHADOW_COLOR %f,%f,%f,%f\n", impl.mController.Get(), shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a );
382 if ( impl.mController->GetShadowColor() != shadowColor )
384 impl.mController->SetShadowColor( shadowColor );
385 impl.mRenderer.Reset();
390 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
392 if( impl.mDecorator )
394 const Vector4& color = value.Get< Vector4 >();
395 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 );
397 impl.mDecorator->SetCursorColor( PRIMARY_CURSOR, color );
398 impl.RequestTextRelayout();
402 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
404 if( impl.mDecorator )
406 const Vector4& color = value.Get< Vector4 >();
407 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 );
409 impl.mDecorator->SetCursorColor( SECONDARY_CURSOR, color );
410 impl.RequestTextRelayout();
414 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
416 if( impl.mController )
418 const bool enable = value.Get< bool >();
419 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p ENABLE_CURSOR_BLINK %d\n", impl.mController.Get(), enable );
421 impl.mController->SetEnableCursorBlink( enable );
422 impl.RequestTextRelayout();
426 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
428 if( impl.mDecorator )
430 const float interval = value.Get< float >();
431 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_INTERVAL %f\n", impl.mController.Get(), interval );
433 impl.mDecorator->SetCursorBlinkInterval( interval );
437 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
439 if( impl.mDecorator )
441 const float duration = value.Get< float >();
442 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_BLINK_DURATION %f\n", impl.mController.Get(), duration );
444 impl.mDecorator->SetCursorBlinkDuration( duration );
448 case Toolkit::TextField::Property::CURSOR_WIDTH:
450 if( impl.mDecorator )
452 const int width = value.Get< int >();
453 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p CURSOR_WIDTH %d\n", impl.mController.Get(), width );
455 impl.mDecorator->SetCursorWidth( width );
456 impl.mController->GetLayoutEngine().SetCursorWidth( width );
460 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
462 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
463 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
465 if( impl.mDecorator )
467 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED, image );
468 impl.RequestTextRelayout();
472 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
474 const ResourceImage image = ResourceImage::New( value.Get< std::string >() );
475 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p GRAB_HANDLE_PRESSED_IMAGE %s\n", impl.mController.Get(), image.GetUrl().c_str() );
477 if( impl.mDecorator )
479 impl.mDecorator->SetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED, image );
480 impl.RequestTextRelayout();
484 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
486 const float threshold = value.Get< float >();
487 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_THRESHOLD %f\n", impl.mController.Get(), threshold );
489 if( impl.mDecorator )
491 impl.mDecorator->SetScrollThreshold( threshold );
495 case Toolkit::TextField::Property::SCROLL_SPEED:
497 const float speed = value.Get< float >();
498 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField %p SCROLL_SPEED %f\n", impl.mController.Get(), speed );
500 if( impl.mDecorator )
502 impl.mDecorator->SetScrollSpeed( speed );
506 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
508 const Image image = Scripting::NewImage( value );
510 if( impl.mDecorator && image )
512 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
513 impl.RequestTextRelayout();
517 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
519 const Image image = Scripting::NewImage( value );
521 if( impl.mDecorator && image )
523 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED, image );
524 impl.RequestTextRelayout();
528 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
530 const Image image = Scripting::NewImage( value );
532 if( impl.mDecorator && image )
534 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
535 impl.RequestTextRelayout();
539 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
541 const Image image = Scripting::NewImage( value );
543 if( impl.mDecorator && image )
545 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED, image );
546 impl.RequestTextRelayout();
550 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
552 const Image image = Scripting::NewImage( value );
554 if( impl.mDecorator && image )
556 impl.mDecorator->SetHandleImage( LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
557 impl.RequestTextRelayout();
561 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
563 const Image image = Scripting::NewImage( value );
565 if( impl.mDecorator && image )
567 impl.mDecorator->SetHandleImage( RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED, image );
568 impl.RequestTextRelayout();
572 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
574 const Vector4 color = value.Get< Vector4 >();
575 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 );
577 if( impl.mDecorator )
579 impl.mDecorator->SetHighlightColor( color );
580 impl.RequestTextRelayout();
584 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
586 if( impl.mDecorator )
588 const Rect<int> box = value.Get< Rect<int> >();
589 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 );
591 impl.mDecorator->SetBoundingBox( box );
592 impl.RequestTextRelayout();
596 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
598 const Property::Map* map = value.GetMap();
601 impl.mInputMethodOptions.ApplyProperty( *map );
603 impl.mController->SetInputModePassword( impl.mInputMethodOptions.IsPassword() );
605 Toolkit::Control control = Toolkit::KeyInputFocusManager::Get().GetCurrentFocusControl();
606 if (control == textField)
608 impl.mImfManager.ApplyOptions( impl.mInputMethodOptions );
612 case Toolkit::TextField::Property::INPUT_COLOR:
614 if( impl.mController )
616 const Vector4 inputColor = value.Get< Vector4 >();
617 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 );
619 impl.mController->SetInputColor( inputColor );
623 case Toolkit::TextField::Property::ENABLE_MARKUP:
625 if( impl.mController )
627 const bool enableMarkup = value.Get<bool>();
628 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p ENABLE_MARKUP %d\n", impl.mController.Get(), enableMarkup );
630 impl.mController->SetMarkupProcessorEnabled( enableMarkup );
634 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
636 if( impl.mController )
638 const std::string& fontFamily = value.Get< std::string >();
639 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_FONT_FAMILY %s\n", impl.mController.Get(), fontFamily.c_str() );
640 impl.mController->SetInputFontFamily( fontFamily );
644 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
646 SetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
649 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
651 if( impl.mController )
653 const float pointSize = value.Get< float >();
654 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p INPUT_POINT_SIZE %f\n", impl.mController.Get(), pointSize );
655 impl.mController->SetInputFontPointSize( pointSize );
659 case Toolkit::TextField::Property::UNDERLINE:
661 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
664 impl.mRenderer.Reset();
668 case Toolkit::TextField::Property::INPUT_UNDERLINE:
670 const bool update = SetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
673 impl.mRenderer.Reset();
677 case Toolkit::TextField::Property::SHADOW:
679 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
682 impl.mRenderer.Reset();
686 case Toolkit::TextField::Property::INPUT_SHADOW:
688 const bool update = SetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
691 impl.mRenderer.Reset();
695 case Toolkit::TextField::Property::EMBOSS:
697 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
700 impl.mRenderer.Reset();
704 case Toolkit::TextField::Property::INPUT_EMBOSS:
706 const bool update = SetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
709 impl.mRenderer.Reset();
713 case Toolkit::TextField::Property::OUTLINE:
715 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
718 impl.mRenderer.Reset();
722 case Toolkit::TextField::Property::INPUT_OUTLINE:
724 const bool update = SetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
727 impl.mRenderer.Reset();
731 case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
733 const Property::Map* map = value.GetMap();
736 impl.mController->SetHiddenInputOption(*map);
740 case Toolkit::DevelTextField::Property::PIXEL_SIZE:
742 if( impl.mController )
744 const float pixelSize = value.Get< float >();
745 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p PIXEL_SIZE %f\n", impl.mController.Get(), pixelSize );
747 if( !Equals( impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE ), pixelSize ) )
749 impl.mController->SetDefaultFontSize( pixelSize, Text::Controller::PIXEL_SIZE );
758 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
760 Property::Value value;
762 Toolkit::TextField textField = Toolkit::TextField::DownCast( Dali::BaseHandle( object ) );
766 TextField& impl( GetImpl( textField ) );
770 case Toolkit::TextField::Property::RENDERING_BACKEND:
772 value = impl.mRenderingBackend;
775 case Toolkit::TextField::Property::TEXT:
777 if( impl.mController )
780 impl.mController->GetText( text );
781 DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p returning text: %s\n", impl.mController.Get(), text.c_str() );
786 case Toolkit::TextField::Property::PLACEHOLDER_TEXT:
788 if( impl.mController )
791 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_INACTIVE, text );
796 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_FOCUSED:
798 if( impl.mController )
801 impl.mController->GetPlaceholderText( Controller::PLACEHOLDER_TYPE_ACTIVE, text );
806 case Toolkit::TextField::Property::FONT_FAMILY:
808 if( impl.mController )
810 value = impl.mController->GetDefaultFontFamily();
814 case Toolkit::TextField::Property::FONT_STYLE:
816 GetFontStyleProperty( impl.mController, value, Text::FontStyle::DEFAULT );
819 case Toolkit::TextField::Property::POINT_SIZE:
821 if( impl.mController )
823 value = impl.mController->GetDefaultFontSize( Text::Controller::POINT_SIZE );
827 case Toolkit::TextField::Property::MAX_LENGTH:
829 if( impl.mController )
831 value = impl.mController->GetMaximumNumberOfCharacters();
835 case Toolkit::TextField::Property::EXCEED_POLICY:
837 value = impl.mExceedPolicy;
840 case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
842 if( impl.mController )
844 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::HorizontalAlignment >( impl.mController->GetHorizontalAlignment(),
845 HORIZONTAL_ALIGNMENT_STRING_TABLE,
846 HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
849 value = std::string( name );
854 case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
856 if( impl.mController )
858 const char* name = Scripting::GetEnumerationName< Toolkit::Text::Layout::VerticalAlignment >( impl.mController->GetVerticalAlignment(),
859 VERTICAL_ALIGNMENT_STRING_TABLE,
860 VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
863 value = std::string( name );
868 case Toolkit::TextField::Property::TEXT_COLOR:
870 if ( impl.mController )
872 value = impl.mController->GetDefaultColor();
876 case Toolkit::TextField::Property::PLACEHOLDER_TEXT_COLOR:
878 if ( impl.mController )
880 value = impl.mController->GetPlaceholderTextColor();
884 case Toolkit::TextField::Property::SHADOW_OFFSET:
886 if ( impl.mController )
888 value = impl.mController->GetShadowOffset();
892 case Toolkit::TextField::Property::SHADOW_COLOR:
894 if ( impl.mController )
896 value = impl.mController->GetShadowColor();
900 case Toolkit::TextField::Property::PRIMARY_CURSOR_COLOR:
902 if( impl.mDecorator )
904 value = impl.mDecorator->GetColor( PRIMARY_CURSOR );
908 case Toolkit::TextField::Property::SECONDARY_CURSOR_COLOR:
910 if( impl.mDecorator )
912 value = impl.mDecorator->GetColor( SECONDARY_CURSOR );
916 case Toolkit::TextField::Property::ENABLE_CURSOR_BLINK:
918 value = impl.mController->GetEnableCursorBlink();
921 case Toolkit::TextField::Property::CURSOR_BLINK_INTERVAL:
923 if( impl.mDecorator )
925 value = impl.mDecorator->GetCursorBlinkInterval();
929 case Toolkit::TextField::Property::CURSOR_BLINK_DURATION:
931 if( impl.mDecorator )
933 value = impl.mDecorator->GetCursorBlinkDuration();
937 case Toolkit::TextField::Property::CURSOR_WIDTH:
939 if( impl.mDecorator )
941 value = impl.mDecorator->GetCursorWidth();
945 case Toolkit::TextField::Property::GRAB_HANDLE_IMAGE:
947 if( impl.mDecorator )
949 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_RELEASED ) );
952 value = image.GetUrl();
957 case Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE:
959 if( impl.mDecorator )
961 ResourceImage image = ResourceImage::DownCast( impl.mDecorator->GetHandleImage( GRAB_HANDLE, HANDLE_IMAGE_PRESSED ) );
964 value = image.GetUrl();
969 case Toolkit::TextField::Property::SCROLL_THRESHOLD:
971 if( impl.mDecorator )
973 value = impl.mDecorator->GetScrollThreshold();
977 case Toolkit::TextField::Property::SCROLL_SPEED:
979 if( impl.mDecorator )
981 value = impl.mDecorator->GetScrollSpeed();
985 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT:
987 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED );
990 case Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT:
992 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_RELEASED ) ;
995 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT:
997 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1000 case Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT:
1002 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE, HANDLE_IMAGE_PRESSED );
1005 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT:
1007 impl.GetHandleImagePropertyValue( value, LEFT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1010 case Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT:
1012 impl.GetHandleImagePropertyValue( value, RIGHT_SELECTION_HANDLE_MARKER, HANDLE_IMAGE_RELEASED );
1015 case Toolkit::TextField::Property::SELECTION_HIGHLIGHT_COLOR:
1017 if( impl.mDecorator )
1019 value = impl.mDecorator->GetHighlightColor();
1023 case Toolkit::TextField::Property::DECORATION_BOUNDING_BOX:
1025 if( impl.mDecorator )
1027 Rect<int> boundingBox;
1028 impl.mDecorator->GetBoundingBox( boundingBox );
1029 value = boundingBox;
1033 case Toolkit::TextField::Property::INPUT_METHOD_SETTINGS:
1036 impl.mInputMethodOptions.RetrieveProperty( map );
1040 case Toolkit::TextField::Property::INPUT_COLOR:
1042 if( impl.mController )
1044 value = impl.mController->GetInputColor();
1048 case Toolkit::TextField::Property::ENABLE_MARKUP:
1050 if( impl.mController )
1052 value = impl.mController->IsMarkupProcessorEnabled();
1056 case Toolkit::TextField::Property::INPUT_FONT_FAMILY:
1058 if( impl.mController )
1060 value = impl.mController->GetInputFontFamily();
1064 case Toolkit::TextField::Property::INPUT_FONT_STYLE:
1066 GetFontStyleProperty( impl.mController, value, Text::FontStyle::INPUT );
1069 case Toolkit::TextField::Property::INPUT_POINT_SIZE:
1071 if( impl.mController )
1073 value = impl.mController->GetInputFontPointSize();
1077 case Toolkit::TextField::Property::UNDERLINE:
1079 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1082 case Toolkit::TextField::Property::INPUT_UNDERLINE:
1084 GetUnderlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1087 case Toolkit::TextField::Property::SHADOW:
1089 GetShadowProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1092 case Toolkit::TextField::Property::INPUT_SHADOW:
1094 GetShadowProperties( impl.mController, value, Text::EffectStyle::INPUT );
1097 case Toolkit::TextField::Property::EMBOSS:
1099 GetEmbossProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1102 case Toolkit::TextField::Property::INPUT_EMBOSS:
1104 GetEmbossProperties( impl.mController, value, Text::EffectStyle::INPUT );
1107 case Toolkit::TextField::Property::OUTLINE:
1109 GetOutlineProperties( impl.mController, value, Text::EffectStyle::DEFAULT );
1112 case Toolkit::TextField::Property::INPUT_OUTLINE:
1114 GetOutlineProperties( impl.mController, value, Text::EffectStyle::INPUT );
1117 case Toolkit::DevelTextField::Property::HIDDEN_INPUT_SETTINGS:
1120 impl.mController->GetHiddenInputOption(map);
1124 case Toolkit::DevelTextField::Property::PIXEL_SIZE:
1126 if( impl.mController )
1128 value = impl.mController->GetDefaultFontSize( Text::Controller::PIXEL_SIZE );
1138 bool TextField::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
1140 Dali::BaseHandle handle( object );
1142 bool connected( true );
1143 Toolkit::TextField field = Toolkit::TextField::DownCast( handle );
1145 if( 0 == strcmp( signalName.c_str(), SIGNAL_TEXT_CHANGED ) )
1147 field.TextChangedSignal().Connect( tracker, functor );
1149 else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) )
1151 field.MaxLengthReachedSignal().Connect( tracker, functor );
1153 else if( 0 == strcmp( signalName.c_str(), SIGNAL_INPUT_STYLE_CHANGED ) )
1155 field.InputStyleChangedSignal().Connect( tracker, functor );
1159 // signalName does not match any signal
1166 Toolkit::TextField::TextChangedSignalType& TextField::TextChangedSignal()
1168 return mTextChangedSignal;
1171 Toolkit::TextField::MaxLengthReachedSignalType& TextField::MaxLengthReachedSignal()
1173 return mMaxLengthReachedSignal;
1176 Toolkit::TextField::InputStyleChangedSignalType& TextField::InputStyleChangedSignal()
1178 return mInputStyleChangedSignal;
1181 void TextField::OnInitialize()
1183 Actor self = Self();
1185 mController = Text::Controller::New( this, this );
1187 // When using the vector-based rendering, the size of the GLyphs are different
1188 TextAbstraction::GlyphType glyphType = (Text::RENDERING_VECTOR_BASED == mRenderingBackend) ? TextAbstraction::VECTOR_GLYPH : TextAbstraction::BITMAP_GLYPH;
1189 mController->SetGlyphType( glyphType );
1191 mDecorator = Text::Decorator::New( *mController,
1194 mController->GetLayoutEngine().SetLayout( Layout::Engine::SINGLE_LINE_BOX );
1196 // Enables the text input.
1197 mController->EnableTextInput( mDecorator );
1199 // Enables the horizontal scrolling after the text input has been enabled.
1200 mController->SetHorizontalScrollEnabled( true );
1202 // Disables the vertical scrolling.
1203 mController->SetVerticalScrollEnabled( false );
1205 // Disable the smooth handle panning.
1206 mController->SetSmoothHandlePanEnabled( false );
1208 mController->SetNoTextDoubleTapAction( Controller::NoTextTap::HIGHLIGHT );
1209 mController->SetNoTextLongPressAction( Controller::NoTextTap::HIGHLIGHT );
1211 // Forward input events to controller
1212 EnableGestureDetection( static_cast<Gesture::Type>( Gesture::Tap | Gesture::Pan | Gesture::LongPress ) );
1213 GetTapGestureDetector().SetMaximumTapsRequired( 2 );
1215 mImfManager = ImfManager::Get();
1217 self.TouchSignal().Connect( this, &TextField::OnTouched );
1219 // Set BoundingBox to stage size if not already set.
1220 Rect<int> boundingBox;
1221 mDecorator->GetBoundingBox( boundingBox );
1223 if( boundingBox.IsEmpty() )
1225 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
1226 mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
1229 // Flip vertically the 'left' selection handle
1230 mDecorator->FlipHandleVertically( LEFT_SELECTION_HANDLE, true );
1232 // Fill-parent area by default
1233 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
1234 self.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
1235 self.OnStageSignal().Connect( this, &TextField::OnStageConnect );
1237 if( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP == mExceedPolicy )
1243 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change )
1245 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange\n");
1249 case StyleChange::DEFAULT_FONT_CHANGE:
1251 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnStyleChange DEFAULT_FONT_CHANGE\n");
1252 const std::string& newFont = GetImpl( styleManager ).GetDefaultFontFamily();
1253 // Property system did not set the font so should update it.
1254 mController->UpdateAfterFontChange( newFont );
1259 case StyleChange::DEFAULT_FONT_SIZE_CHANGE:
1261 GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
1265 case StyleChange::THEME_CHANGE:
1267 // Nothing to do, let control base class handle this
1272 // Up call to Control
1273 Control::OnStyleChange( styleManager, change );
1276 Vector3 TextField::GetNaturalSize()
1278 return mController->GetNaturalSize();
1281 float TextField::GetHeightForWidth( float width )
1283 return mController->GetHeightForWidth( width );
1286 void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
1288 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField OnRelayout\n");
1290 const Text::Controller::UpdateTextType updateTextType = mController->Relayout( size );
1292 if( ( Text::Controller::NONE_UPDATED != updateTextType ) ||
1295 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnRelayout %p Displaying new contents\n", mController.Get() );
1298 ( Text::Controller::NONE_UPDATED != ( Text::Controller::DECORATOR_UPDATED & updateTextType ) ) )
1300 mDecorator->Relayout( size );
1305 mRenderer = Backend::Get().NewRenderer( mRenderingBackend );
1308 RenderText( updateTextType );
1311 // The text-field emits signals when the input style changes. These changes of style are
1312 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1313 // can't be emitted during the size negotiation as the callbacks may update the UI.
1314 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1315 if( !mController->IsInputStyleChangedSignalsQueueEmpty() )
1317 if( Adaptor::IsAvailable() )
1319 Adaptor& adaptor = Adaptor::Get();
1321 if( NULL == mIdleCallback )
1323 // @note: The callback manager takes the ownership of the callback object.
1324 mIdleCallback = MakeCallback( this, &TextField::OnIdleSignal );
1325 adaptor.AddIdle( mIdleCallback );
1331 void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
1333 Actor renderableActor;
1335 if( Text::Controller::NONE_UPDATED != ( Text::Controller::MODEL_UPDATED & updateTextType ) )
1339 renderableActor = mRenderer->Render( mController->GetView(),
1341 DepthIndex::CONTENT );
1344 if( renderableActor != mRenderableActor )
1346 UnparentAndReset( mRenderableActor );
1347 mRenderableActor = renderableActor;
1351 if( mRenderableActor )
1353 const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
1355 mRenderableActor.SetPosition( scrollOffset.x + mAlignmentOffset, scrollOffset.y );
1357 // Make sure the actors are parented correctly with/without clipping
1358 Actor self = mStencil ? mStencil : Self();
1360 for( std::vector<Actor>::const_iterator it = mClippingDecorationActors.begin(),
1361 endIt = mClippingDecorationActors.end();
1366 DevelActor::LowerToBottom(*it);
1368 mClippingDecorationActors.clear();
1370 self.Add( mRenderableActor );
1374 void TextField::OnKeyInputFocusGained()
1376 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyInputFocusGained %p\n", mController.Get() );
1378 mImfManager.ApplyOptions( mInputMethodOptions );
1380 mImfManager.StatusChangedSignal().Connect( this, &TextField::KeyboardStatusChanged );
1382 mImfManager.EventReceivedSignal().Connect( this, &TextField::OnImfEvent );
1384 // Notify that the text editing start.
1385 mImfManager.Activate();
1387 // When window gain lost focus, the imf manager is deactivated. Thus when window gain focus again, the imf manager must be activated.
1388 mImfManager.SetRestoreAfterFocusLost( true );
1390 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1394 notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected );
1397 mController->KeyboardFocusGainEvent(); // Called in the case of no virtual keyboard to trigger this event
1399 EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
1402 void TextField::OnKeyInputFocusLost()
1404 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField:OnKeyInputFocusLost %p\n", mController.Get() );
1406 mImfManager.StatusChangedSignal().Disconnect( this, &TextField::KeyboardStatusChanged );
1407 // The text editing is finished. Therefore the imf manager don't have restore activation.
1408 mImfManager.SetRestoreAfterFocusLost( false );
1410 // Notify that the text editing finish.
1411 mImfManager.Deactivate();
1413 mImfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent );
1415 ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() );
1419 notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected );
1422 mController->KeyboardFocusLostEvent();
1424 EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
1427 void TextField::OnTap( const TapGesture& gesture )
1429 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnTap %p\n", mController.Get() );
1431 mImfManager.Activate();
1433 // Deliver the tap before the focus event to controller; this allows us to detect when focus is gained due to tap-gestures
1434 mController->TapEvent( gesture.numberOfTaps, gesture.localPoint.x, gesture.localPoint.y );
1439 void TextField::OnPan( const PanGesture& gesture )
1441 mController->PanEvent( gesture.state, gesture.displacement );
1444 void TextField::OnLongPress( const LongPressGesture& gesture )
1446 mImfManager.Activate();
1448 mController->LongPressEvent( gesture.state, gesture.localPoint.x, gesture.localPoint.y );
1453 bool TextField::OnKeyEvent( const KeyEvent& event )
1455 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnKeyEvent %p keyCode %d\n", mController.Get(), event.keyCode );
1457 if( Dali::DALI_KEY_ESCAPE == event.keyCode ) // Make a Dali key code for this
1459 // Make sure ClearKeyInputFocus when only key is up
1460 if( event.state == KeyEvent::Up )
1462 ClearKeyInputFocus();
1468 return mController->KeyEvent( event );
1471 void TextField::RequestTextRelayout()
1476 void TextField::TextChanged()
1478 Dali::Toolkit::TextField handle( GetOwner() );
1479 mTextChangedSignal.Emit( handle );
1482 void TextField::MaxLengthReached()
1484 Dali::Toolkit::TextField handle( GetOwner() );
1485 mMaxLengthReachedSignal.Emit( handle );
1488 void TextField::InputStyleChanged( Text::InputStyle::Mask inputStyleMask )
1490 Dali::Toolkit::TextField handle( GetOwner() );
1492 Toolkit::TextField::InputStyle::Mask fieldInputStyleMask = Toolkit::TextField::InputStyle::NONE;
1494 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_COLOR ) )
1496 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::COLOR );
1498 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_FAMILY ) )
1500 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_FAMILY );
1502 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_POINT_SIZE ) )
1504 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::POINT_SIZE );
1506 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WEIGHT ) )
1508 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1510 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_WIDTH ) )
1512 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1514 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_FONT_SLANT ) )
1516 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::FONT_STYLE );
1518 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_UNDERLINE ) )
1520 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::UNDERLINE );
1522 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_SHADOW ) )
1524 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::SHADOW );
1526 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_EMBOSS ) )
1528 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::EMBOSS );
1530 if( InputStyle::NONE != static_cast<InputStyle::Mask>( inputStyleMask & InputStyle::INPUT_OUTLINE ) )
1532 fieldInputStyleMask = static_cast<Toolkit::TextField::InputStyle::Mask>( fieldInputStyleMask | Toolkit::TextField::InputStyle::OUTLINE );
1535 mInputStyleChangedSignal.Emit( handle, fieldInputStyleMask );
1538 void TextField::AddDecoration( Actor& actor, bool needsClipping )
1544 mClippingDecorationActors.push_back( actor );
1548 Self().Add( actor );
1553 void TextField::OnStageConnect( Dali::Actor actor )
1555 if ( mHasBeenStaged )
1557 RenderText( static_cast<Text::Controller::UpdateTextType>( Text::Controller::MODEL_UPDATED | Text::Controller::DECORATOR_UPDATED ) );
1561 mHasBeenStaged = true;
1565 ImfManager::ImfCallbackData TextField::OnImfEvent( Dali::ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent )
1567 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::OnImfEvent %p eventName %d\n", mController.Get(), imfEvent.eventName );
1568 return mController->OnImfEvent( imfManager, imfEvent );
1571 void TextField::GetHandleImagePropertyValue( Property::Value& value, Text::HandleType handleType, Text::HandleImageType handleImageType )
1575 ResourceImage image = ResourceImage::DownCast( mDecorator->GetHandleImage( handleType, handleImageType ) );
1580 Scripting::CreatePropertyMap( image, map );
1586 void TextField::EnableClipping()
1590 // Creates an extra control to be used as stencil buffer.
1591 mStencil = Control::New();
1592 mStencil.SetAnchorPoint( AnchorPoint::CENTER );
1593 mStencil.SetParentOrigin( ParentOrigin::CENTER );
1595 // Creates a background visual. Even if the color is transparent it updates the stencil.
1596 mStencil.SetProperty( Toolkit::Control::Property::BACKGROUND,
1597 Property::Map().Add( Toolkit::Visual::Property::TYPE, DevelVisual::COLOR ).
1598 Add( ColorVisual::Property::MIX_COLOR, Color::TRANSPARENT ) );
1600 // Enable the clipping property.
1601 mStencil.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
1602 mStencil.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1604 Self().Add( mStencil );
1608 void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard )
1610 mController->PasteClipboardItemEvent();
1613 void TextField::KeyboardStatusChanged(bool keyboardShown)
1615 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown );
1617 // Just hide the grab handle when keyboard is hidden.
1618 if (!keyboardShown )
1620 mController->KeyboardFocusLostEvent();
1624 mController->KeyboardFocusGainEvent(); // Initially called by OnKeyInputFocusGained
1628 void TextField::OnStageConnection( int depth )
1630 // Sets the depth to the visuals inside the text's decorator.
1631 mDecorator->SetTextDepth( depth );
1633 // The depth of the text renderer is set in the RenderText() called from OnRelayout().
1635 // Call the Control::OnStageConnection() to set the depth of the background.
1636 Control::OnStageConnection( depth );
1639 bool TextField::OnTouched( Actor actor, const TouchData& touch )
1644 void TextField::OnIdleSignal()
1646 // Emits the change of input style signals.
1647 mController->ProcessInputStyleChangedSignals();
1649 // Set the pointer to null as the callback manager deletes the callback after execute it.
1650 mIdleCallback = NULL;
1653 TextField::TextField()
1654 : Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
1655 mIdleCallback( NULL ),
1656 mAlignmentOffset( 0.f ),
1657 mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
1658 mExceedPolicy( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ),
1659 mHasBeenStaged( false )
1663 TextField::~TextField()
1665 UnparentAndReset( mStencil );
1667 if( ( NULL != mIdleCallback ) && Adaptor::IsAvailable() )
1669 Adaptor::Get().RemoveIdle( mIdleCallback );
1673 } // namespace Internal
1675 } // namespace Toolkit